コード例 #1
0
def get_earthdata_stream(path=""):
    """
    A function used with Earth Data state of health miniseed files.
    Parameter specific scaling function is applied to the raw data.

    :type path: str
    :param path: path to miniseed file
    :rtype: :class:`~obspy.core.stream.Stream` or None
    :return: seismic data stream
    """
    st = fileutils.get_stream(path=path)
    scale_funcs = {
        "AEP": lambda x: x,
        "AE1": lambda x: (x * 10.9 / 2700.0) + 5.0,  # to Volts
        "AE2": lambda x: x * 22.0 / 170.0,  # to Amperes
        "AE3": lambda x: (x / 10.0) - 50.0,  # to Degrees of Celcius
        "AE4": lambda x: (x * 10.9 / 2700.0) + 5.0,  # to Volts
        "AE5": lambda x: x / 1000.0,  # to Volts
        "AE6": lambda x: x / 1000.0,  # to Volts
        "AE7": lambda x: x / 1000.0,  # to Volts
        "AE8": lambda x: x / 1000.0,  # to Volts, Not in use
    }
    for tr in st:
        channel = tr.stats.channel
        if channel in scale_funcs:
            scale_func = scale_funcs[channel]
            tr.data = scale_func(tr.data)
    return st
コード例 #2
0
def _data_timestamp_error(pathfunc, times, flags, funckwargs={}, **kwargs):
    """
    Calculates the time difference (in seconds) between current program
    starttime and timestamp of the last datapoint in the data file. The
    difference is positive if datapoint's timestamp is lesser of the two.

    [\*] see the documentation of
    :func:`~polyfemos.back.seismic.lumberjack._data_coverage`.

    :type pathfunc: func
    :param pathfunc: [\*]
    :type times: list
    :param times: [\*]
    :type flags: dict
    :param flags: [\*]
    :type funckwargs: dict, optional
    :param funckwargs: defaults to empty dict,
    """
    time_ = times[:][-1]
    path = pathfunc(julday=time_.julday, year=time_.year)
    st = fileutils.get_stream(path)
    if st is None or len(st) < 1:
        yield time_, None
    else:
        pklfile = flags["execution_time_file"]
        timedict = fileutils.load_obj(pklfile)
        programstarttime = timedict["thisstarttime"]
        endtime = sorted([tr.stats.endtime.timestamp for tr in st])[-1]
        datapoint = programstarttime.timestamp - endtime
        if 'scale' in funckwargs:
            datapoint = funckwargs['scale'](datapoint)
        yield programstarttime, [[programstarttime, datapoint]]
コード例 #3
0
def data_timing_quality_obspy_daily(path="",
                                    key="",
                                    scale=lambda x: x,
                                    **kwargs):
    """
    Extract timing quality flags from given miniseed file. One value per
    file, which means one value per day.

    :type path: str
    :param path: path to miniseed file
    :type key: str
    :param key: key available with :func:`~obspy.io.mseed.util.get_flags` and
        ``timinig_quality`` key.
    :type scale: func, optional
    :param scale: defaults to identity function,
        scaling function applied to data values
    :rtype: list or None
    :return: list of lists containing timestamp (as
        :class:`~obspy.core.utcdatetime.UTCDateTime` instance) and data value.
    """
    dtq = get_flags(path)["timing_quality"]
    if key not in dtq:
        return None
    data_value = scale(dtq[key])
    st = fileutils.get_stream(path)
    st.sort(keys=["starttime"])
    time_ = st[-1].stats.endtime
    return [[time_, data_value]]
コード例 #4
0
def data_coverage(paths=[],
                  starttime=None,
                  endtime=None,
                  scale=lambda x: x,
                  invalid_value=0.0):
    """
    Calculates the datacoverage percentage between ``starttime`` and
    ``endtime``.

    See :class:`~obspy.imaging.scripts.scan.Scanner` and
    :meth:`~obspy.imaging.scripts.scan.Scanner.analyze_parsed_data`
    for more information.

    :type paths: list
    :param paths: list of filepaths (as string values)
        to the datefiles to be scanned
    :type starttime: :class:`~obspy.core.utcdatetime.UTCDateTime`
    :param starttime:
    :type endtime: :class:`~obspy.core.utcdatetime.UTCDateTime`
    :param endtime:
    :type scale: func, optional
    :param scale: defaults to identity function,
        scaling function applied to data values
    :type invalid_value: float, optional
    :param invalid_value: default to ``0.0``
    :rtype: list or None
    :return: list of lists containing timestamp (as
        :class:`~obspy.core.utcdatetime.UTCDateTime` instance), data value,
        and additional z value as string.
    """
    if starttime is None or endtime is None:
        return None

    if starttime > endtime:
        starttime, endtime = endtime, starttime

    st0 = Stream()
    for path in paths:
        st = fileutils.get_stream(path)
        if st is None:
            continue
        st0 += st

    percentage = invalid_value
    # Arbitrary z_value as string following python dictionary syntax
    z_value = "{{'starttime':'{}'}}".format(str(starttime))

    if len(st0) > 0:
        scanner = Scanner()
        scanner.add_stream(st0)
        scanner.analyze_parsed_data(starttime=starttime, endtime=endtime)
        percentage = scanner._info[st0[0].id]['percentage']
        percentage = invalid_value if percentage is None else percentage
        percentage = scale(percentage)

    return [[endtime, percentage, z_value]]
コード例 #5
0
def centaur_mseed(path="", scale=lambda x: x, **kwargs):
    """
    :type path: str
    :param path: path to miniseed file
    :type scale: func, optional
    :param scale: defaults to identity function,
        scaling function applied to data values
    :rtype: list or None
    :return: list of lists containing timestamp (as
        :class:`~obspy.core.utcdatetime.UTCDateTime` instance) and data value.
    """
    st = fileutils.get_stream(path)
    return stream_to_xy_data(st, scale=scale)