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()
def test_scan_save_load_npz(self): """ Run obspy-scan on selected tests/data directories, saving/loading to/from npz. Tests both the command line script and the Scanner class. """ 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) # save via command line obspy_scan([os.curdir, '--write', 'scan.npz']) # save via Python scanner.parse(os.curdir) scanner.save_npz('scanner.npz') scanner = Scanner() # version string of '0.0.0+archive' raises UserWarning - ignore with warnings.catch_warnings(record=True): warnings.simplefilter('ignore', UserWarning) # load via Python scanner.load_npz('scanner.npz') with ImageComparison(self.path, 'scan.png') as ic: scanner.plot(ic.name) # load via command line with ImageComparison(self.path, 'scan.png') as ic: obspy_scan(['--load', 'scan.npz', '--output', ic.name])
def get_data_coverage_figure(station_ids, channel_codes, startdate, enddate, datafilepathfunc): """ :type station_ids: list :param station_ids: station ids as a list of strings :type channel_codes: list :param channel_codes: data channel codes as a list of strings :type startdate: :class:`~obspy.core.utcdatetime.UTCDateTime` :param startdate: scanning startdate :type enddate: :class:`~obspy.core.utcdatetime.UTCDateTime` :param enddate: scanning enddate :type filepathfunc: func :param filepathfunc: A dynamic filepath, wildcards can be used since :func:`~glob.glob` is use to process filepaths after the arguments are filled in. :rtype: :class:`~matplotlib.figure.Figure` :return: scanner plot """ scanner = Scanner() paths = [] pathkwargs = {} pathkwargs["location_code"] = "*" network_and_station_codes = (s.split(".") for s in station_ids) combinations = \ list(itertools.product(network_and_station_codes, channel_codes)) date = startdate added_channels = set() while date <= enddate: pathkwargs["year"] = date.year pathkwargs["julday"] = date.julday for (network_code, station_code), channel_code in combinations: pathkwargs["network_code"] = network_code pathkwargs["station_code"] = station_code pathkwargs["channel_code"] = channel_code trace_key = network_code + station_code + channel_code paths = datafilepathfunc(**pathkwargs) for path in glob.glob(paths): scanner.parse(path) added_channels.add(trace_key) date += 86400 count = len(added_channels) if count: height = 1.0 + count * 0.5 height = min(height, 655.35) fig = scanner.plot(show=False, starttime=startdate, endtime=enddate) fig.set_size_inches(20.0, height) fig.set_facecolor(colors.WHITE) fig.tight_layout() return fig return null_figure()
def test_scan_function_and_scanner_class(self, all_files, image_path): """ Test scan function and Scanner class (in one test to keep overhead of copying files down) """ scanner = Scanner() path1 = image_path.parent / 'scan1.png' path2 = image_path.parent / 'scan2.png' # Copy files to a temp folder to avoid wildcard scans. with TemporaryWorkingDirectory(): for filename in all_files: shutil.copy(filename, os.curdir) scanner.parse(os.curdir) scan(paths=os.curdir, plot=path1) scanner.plot(path2)
def test_scan_function_and_scanner_class(self): """ Test scan function and Scanner class (in one test to keep overhead of copying files down) """ 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) scanner.parse(os.curdir) with ImageComparison(self.path, 'scan.png') as ic: scan(paths=os.curdir, plot=ic.name) with ImageComparison(self.path, 'scan.png') as ic: scanner.plot(ic.name)
def test_scan_plot_by_id_with_wildcard(self): """ Test selecting what to plot after scanning with wildcards in selected SEED IDs """ files = [ "BW.UH1._.EHZ.D.2010.147.a.slist.gz", "BW.UH1._.EHZ.D.2010.147.b.slist.gz", "BW.UH1._.SHZ.D.2010.147.cut.slist.gz", "BW.UH2._.SHZ.D.2010.147.cut.slist.gz", "BW.UH3._.SHE.D.2010.147.cut.slist.gz", "BW.UH3._.SHN.D.2010.147.cut.slist.gz", "BW.UH3._.SHZ.D.2010.147.cut.slist.gz", "BW.UH4._.EHZ.D.2010.147.cut.slist.gz", "IUANMO.seed"] scanner = Scanner() for filename in files: scanner.parse(get_example_file(filename)) expected = [ ('*.UH[12]*', ['BW.UH2..SHZ\n100.0%', 'BW.UH1..SHZ\n100.0%', 'BW.UH1..EHZ\n10.7%']), ('*Z', ['IU.ANMO.00.LHZ\n100.0%', 'BW.UH4..EHZ\n100.0%', 'BW.UH3..SHZ\n100.0%', 'BW.UH2..SHZ\n100.0%', 'BW.UH1..SHZ\n100.0%', 'BW.UH1..EHZ\n10.7%'])] for seed_id, expected_labels in expected: fig, ax = plt.subplots() fig = scanner.plot(fig=fig, show=False, seed_ids=[seed_id]) got = [label.get_text() for label in ax.get_yticklabels()] self.assertEqual(got, expected_labels) plt.close(fig)
def test_scan_save_load_npz(self): """ Run obspy-scan on selected tests/data directories, saving/loading to/from npz. Tests both the command line script and the Scanner class. """ 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) obspy_scan([os.curdir, '--write', 'scan.npz', '--quiet']) scanner.parse(os.curdir) scanner.save_npz('scanner.npz') scanner = Scanner() scanner.load_npz('scanner.npz') with ImageComparison(self.path, 'scan.png') as ic: obspy_scan(['--load', 'scan.npz', '--output', ic.name, '--quiet']) with ImageComparison(self.path, 'scan.png') as ic: scanner.plot(ic.name)
def test_scan_save_load_npz(self): """ Run obspy-scan on selected tests/data directories, saving/loading to/from npz. Tests both the command line script and the Scanner class. """ 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) obspy_scan([os.curdir, '--write', 'scan.npz', '--quiet']) scanner.parse(os.curdir) scanner.save_npz('scanner.npz') scanner = Scanner() scanner.load_npz('scanner.npz') with ImageComparison(self.path, 'scan.png') as ic: obspy_scan( ['--load', 'scan.npz', '--output', ic.name, '--quiet']) with ImageComparison(self.path, 'scan.png') as ic: scanner.plot(ic.name)