def test_can_put_to_empty_bank(self, tmpdir):
     """ An empty bank should be init'able created when an event is
     put into it """
     path = Path(tmpdir) / "new_bank"
     bank = EventBank(path)
     assert not path.exists()
     cat = obspy.read_events()
     bank.put_events(cat)
     assert path.exists()
     assert len(bank.read_index()) == 3
Beispiel #2
0
def bing_ebank(bingham_dataset, tmpdir_factory):
    """
    Create a copy of the bingham_test data set. Then return an inited event bank
    using the temporary bingham_test bank
    """
    new = Path(str(tmpdir_factory.mktemp("bingham_test")))
    copy_dataset("bingham_test", new)
    path = new / "bingham_test" / "events"
    ebank = EventBank(path)
    ebank.update_index()
    return ebank
Beispiel #3
0
 def ebank_low_version(self, tmpdir, monkeypatch):
     """ return the default bank with a negative version number. """
     # monkey patch obsplus version so that a low version is saved to disk
     monkeypatch.setattr(obsplus, "__last_version__", self.low_version_str)
     cat = obspy.read_events()
     ebank = EventBank(tmpdir).put_events(cat, update_index=False)
     # write index with negative version
     with suppress_warnings():
         ebank.update_index()
     monkeypatch.undo()
     assert ebank._index_version == self.low_version_str
     assert obsplus.__last_version__ != self.low_version_str
     return ebank
def ebank(tmpdir):
    """ Create a bank from the default catalog. """
    path = Path(tmpdir) / "events"
    # get catalog, add event descriptions to it
    cat = obspy.read_events()
    descs = ["LR", "LR", "SomeSillyEvent"]
    for event, desc_txt in zip(cat, descs):
        desc = ev.EventDescription(desc_txt)
        event.event_descriptions.insert(0, desc)
    obsplus.events.utils.catalog_to_directory(cat, path)
    ebank = EventBank(path)
    ebank.update_index()
    return ebank
Beispiel #5
0
 def test_get_events_recreates_index(self, ebank_low_version):
     """
     Not just updating the index but also initing a new bank and using it.
     """
     ebank = ebank_low_version
     # The index should not yet have been updated
     assert ebank._index_version == self.low_version_str
     with pytest.warns(UserWarning):
         ebank2 = EventBank(ebank.bank_path)
     _ = ebank2.get_events(limit=1)
     # but after creating a new bank it should
     assert ebank._index_version == obsplus.__version__
     assert ebank2._index_version == obsplus.__version__
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
Beispiel #7
0
 def test_path_structure(self, tmpdir):
     """
     Ensure that it is possible to not use a path structure (see #178)
     """
     path = Path(tmpdir) / "path_structure"
     bank = EventBank(path, path_structure="")
     assert bank.path_structure == ""
Beispiel #8
0
 def test_from_path(self, tmpdir):
     """Put events should work with a path to a directory of events."""
     cat = obspy.read_events()
     event_path = Path(tmpdir) / "events.xml"
     bank1 = EventBank(event_path.parent / "catalog_dir1")
     bank2 = EventBank(event_path.parent / "catalog_dir2")
     # a slightly invalid uri is used, just ignore
     with suppress_warnings():
         cat.write(str(event_path), "quakeml")
     # test works with a Path instance
     bank1.put_events(event_path)
     assert Path(bank1.bank_path).exists()
     assert not bank1.read_index().empty
     # tests with a string
     bank2.put_events(str(event_path))
     assert Path(bank2.bank_path).exists()
     assert not bank2.read_index().empty
Beispiel #9
0
 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()
     bank = EventBank(Path(tmpdir)).put_events(cat)
     qml_files = list(Path(bank.bank_path).rglob("*.xml"))
     assert len(qml_files) == len(cat)
     assert Path(bank.index_path).exists()
Beispiel #10
0
def ebank_with_bad_files(tmpdir):
    """
    Create an event bank with bad files, ensure it doesn't choke indexer.
    """
    bank = EventBank(Path(tmpdir))
    cat = obspy.read_events()
    bank.put_events(cat)
    # add stream file
    st = obspy.read()
    stream_path = Path(bank.bank_path)
    st.write(str(stream_path / "not_an_event.xml"), "mseed")
    bank = EventBank(stream_path)
    # should issue warning
    with pytest.warns(UserWarning):
        bank.update_index()
    return bank
Beispiel #11
0
 def test_limit_index(self, tmpdir):
     """ Test to run the logic for limiting index memory usage. """
     # This tests is a bit invasive but I cant think of a better way
     cat = obspy.read_events()
     # create temporary directory of event files
     td = Path(tmpdir)
     bank = EventBank(td).put_events(cat)
     # instrument bank, delete index, create new index
     with instrument_methods(bank) as ibank:
         os.remove(bank.index_path)
         ibank._max_events_in_memory = 1
         ibank.update_index()
         counter = ibank._counter
     # count the number of _write_update calls
     assert counter["update_index"] == 1
     assert counter["_write_update"] == 3
Beispiel #12
0
 def test_limit_index(self, tmpdir):
     """ Test to run the logic for limiting index memory usage. """
     # This tests is a bit invasive but I cant think of a better way
     cat = obspy.read_events()
     # create temporary directory of event files
     td = Path(tmpdir)
     kwargs = dict(cat=cat,
                   path=td,
                   event_bank_index=False,
                   check_duplicates=False)
     obsplus.events.utils.catalog_to_directory(**kwargs)
     # init bank and add index
     bank = EventBank(td).update_index()
     # instrument bank, delete index, create new index
     with instrument_methods(bank) as ibank:
         os.remove(bank.index_path)
         ibank._max_events_in_memory = 1
         ibank.update_index()
         counter = ibank._counter
     # count the number of _write_update calls
     assert counter["update_index"] == 1
     assert counter["_write_update"] == 3
Beispiel #13
0
def ebank(tmpdir, cat_with_descs):
    """ Create a bank from the default catalog. """
    cat = cat_with_descs
    path = Path(tmpdir) / "events"
    return EventBank(path).put_events(cat, update_index=True)
Beispiel #14
0
 def multiple_event_file(self, tmp_path_factory, crandall_dataset):
     """ Create a bank from a single file with multiple events """
     path = tmp_path_factory.mktemp("crandall_bank")
     cat_name = path / "event_bank.xml"
     crandall_dataset.event_client.write(cat_name, "QuakeML")
     return EventBank(path)
Beispiel #15
0
 def test_init_bank_with_bank(self, bing_ebank):
     """ ensure an EventBank can be init'ed with an event bank. """
     ebank2 = EventBank(bing_ebank)
     assert isinstance(ebank2, EventBank)
 def test_eventbank(self, bingham_dataset):
     ebank = EventBank(bingham_dataset.event_path)
     assert isinstance(ebank, EventClient)
     assert issubclass(EventBank, EventClient)
Beispiel #17
0
 def test_eventbank(self, bingham_dataset):
     """Ensure eventbank meets event client interface."""
     ebank = EventBank(bingham_dataset.event_path)
     assert isinstance(ebank, EventClient)
     assert issubclass(EventBank, EventClient)
Beispiel #18
0
def dateline_eventbank(dateline_catalog, tmp_path):
    """Add the dateline catalog to a temporary path."""
    ebank = EventBank(tmp_path)
    ebank.put_events(dateline_catalog)
    return ebank