Exemplo n.º 1
0
 def test_obspy_scanner(self):
     scanner = Scanner("MSEED")
     scanner.parse(TestMseed.root_path)
     print(scanner.data.keys())
     print(scanner.data)
     scanner.analyze_parsed_data(True)
     scanner.plot()
Exemplo n.º 2
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]]