Exemplo n.º 1
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]]
Exemplo n.º 2
0
    def test_scanner_manually_add_streams(self, all_files, image_path):
        """
        Test Scanner class, manually adding streams of read data files
        """
        scanner = Scanner()
        # Copy files to a temp folder to avoid wildcard scans.
        with TemporaryWorkingDirectory():
            for filename in all_files:
                shutil.copy(filename, os.curdir)

            for file_ in os.listdir(os.curdir):
                # some files used in the test cases actually can not
                # be read with obspy..
                if file_ in ('STA2.testlines_out', 'STA2.testlines',
                             'seism-shorter.sac', 'seism-longer.sac'):
                    continue
                st = read(file_, headonly=True)
                scanner.add_stream(st)

        scanner.plot(str(image_path))
Exemplo n.º 3
0
    def test_scanner_manually_add_streams(self):
        """
        Test Scanner class, manually adding streams of read data files
        """
        scanner = Scanner()
        # Copy files to a temp folder to avoid wildcard scans.
        with TemporaryWorkingDirectory():
            for filename in self.all_files:
                shutil.copy(filename, os.curdir)

            for file_ in os.listdir(os.curdir):
                # some files used in the test cases actually can not
                # be read with obspy..
                if file_ in ('STA2.testlines_out', 'STA2.testlines',
                             'seism-shorter.sac', 'seism-longer.sac'):
                    continue
                st = read(file_, headonly=True)
                scanner.add_stream(st)

        with ImageComparison(self.path, 'scan.png') as ic:
            scanner.plot(ic.name)