def test_files_created(self, tmpdir): """ ensure a file is created for each event in default events, and the bank index as well. """ cat = obspy.read_events() path = Path(tmpdir) catalog_to_directory(cat, tmpdir) qml_files = list(path.rglob("*.xml")) assert len(qml_files) == len(cat) ebank = obsplus.EventBank(path) assert Path(ebank.index_path).exists()
def ebank_with_bad_files(tmpdir): """ create an event bank with bad files, ensure it doesn't choke indexer. """ path = Path(tmpdir) cat = obspy.read_events() catalog_to_directory(cat, path) # add stream file st = obspy.read() st.write(str(path / "not_an_event.xml"), "mseed") bank = EventBank(path) # should issue warning with pytest.warns(UserWarning): bank.update_index() return bank
def test_get_events_empty_bank(self, tmp_path): """ Calling get_waveforms on an empty bank should update index. """ cat1 = obspy.read_events() catalog_to_directory(cat1, tmp_path, event_bank_index=False) cat1_dict = {str(x.resource_id): x for x in cat1} # get a bank, ensure it has no index and call get events bank = obsplus.EventBank(tmp_path) index = Path(bank.index_path) if index.exists(): index.unlink() # now get events and assert equal to input (although order can change) cat2 = bank.get_events() cat2_dict = {str(x.resource_id): x for x in cat2} assert cat2_dict == cat1_dict
def test_from_path(self, tmpdir): """ catalog_to_directory should work with a path to a events. """ cat = obspy.read_events() path = Path(tmpdir) / "events.xml" path_out1 = path.parent / "catalog_dir1" path_out2 = path.parent / "catalog_dir2" # a slightly invalid uri is used, just ignore with warnings.catch_warnings(): warnings.simplefilter("ignore") cat.write(str(path), "quakeml") # test works with a Path instance catalog_to_directory(path, path_out1) assert path_out1.exists() assert not obsplus.EventBank(path_out1).read_index().empty # tests with a string catalog_to_directory(str(path), path_out2) assert path_out2.exists() assert not obsplus.EventBank(path_out2).read_index().empty
def test_events_different_time_same_id_not_duplicated(self, tmpdir): """ events with different times but the same id should not be duplicated; the old path should be used when detected. """ cat = obspy.read_events() path = Path(tmpdir) catalog_to_directory(cat, path) first_event_path = get_event_path(cat[0], str(path)) file_event_count = list(path.rglob("*.xml")) # modify first event preferred origin time slightly event = cat[0] origin = get_preferred(event, "origin") origin.time += 10 # save to disk again catalog_to_directory(cat, path) # ensure event count didnt change assert len(file_event_count) == len(list(path.rglob("*.xml"))) assert Path(first_event_path).exists() # read first path and make sure origin time was updated cat2 = obspy.read_events(str(first_event_path)) assert len(cat2) == 1 assert get_preferred(cat2[0], "origin").time == origin.time
def download_events(self): """ Simply copy events from base directory. """ cat = obspy.read_events(str(self.source_path / "events.xml")) catalog_to_directory(cat, self.event_path)
def download_events(self): """ Simply copy events from base directory. """ cat_path = self.source_path / "events.xml" assert cat_path.exists(), "this should ship with obsplus" cat = obspy.read_events(str(cat_path)) catalog_to_directory(cat, self.event_path)
def download_events(self): """ Just copy the events into a directory. """ cat = obspy.read_events(str(self.source_path / "events.xml")) catalog_to_directory(cat, self.event_path)