コード例 #1
0
 def test_pathlib_object(self, tmp_ta_dir):
     """ ensure a pathlib object can be passed as first arg """
     bank = WaveBank(pathlib.Path(tmp_ta_dir) / "waveforms")
     ind = bank.read_index()
     min_start = ind.starttime.min()
     st = bank.get_waveforms(starttime=min_start, endtime=min_start + 600)
     assert isinstance(st, obspy.Stream)
コード例 #2
0
ファイル: fetcher.py プロジェクト: niowniow/obsplus
    def download_event_waveforms(
        self,
        time_before_origin: float,
        time_after_origin: float,
        path: str = EVENT_WAVEFORM_PATH_STRUCTURE,
    ) -> None:
        """
        Download waveforms corresponding to events in waveforms from client.

        Parameters
        ----------
        time_before_origin
            The number of seconds before the reported origin to include in the
            event waveforms
        time_after_origin
            The number of seconds after the reported origin to include in the
            event waveforms
        path
            A string that specifies the directory structure. See the
            path_structure argument of :class: `~obsplus.Sbank` for more info.
        """
        # setup banks and fetcher
        bank = WaveBank(path)
        # iter events and save to disk
        t1, t2 = time_before_origin, time_after_origin
        for event_id, stream in self.yield_event_waveforms(t1, t2):
            bank.put_waveforms(stream, name=event_id)
コード例 #3
0
ファイル: fetcher.py プロジェクト: niowniow/obsplus
    def download_waveforms(
        self,
        starttime: UTCDateTime,
        endtime: UTCDateTime,
        duration: float,
        overlap: float = 0,
        path: str = WAVEFORM_STRUCTURE,
    ) -> None:
        """
        Download contiguous waveform data and save in directory.

        Parameters
        ----------
        starttime
            The start time of the data  to download
        endtime
            The end time of the data to download
        duration
            The duration of each chunk of data in seconds
        overlap
            The overlap, added to the end of each waveforms, for the data
        path
            A string that specifies the directory structure. See the
            path_structure argument of :class: `~obsplus.Sbank` for more info
        """
        bank = WaveBank(path)
        # iter events and save to disk
        t1, t2 = starttime, endtime
        for stream in self.yield_waveforms(t1, t2, duration, overlap):
            bank.put_waveforms(stream)
コード例 #4
0
ファイル: test_wavebank.py プロジェクト: niowniow/obsplus
 def gappy_bank(self, gappy_dir):
     """ init a sbank on the gappy data """
     bank = WaveBank(gappy_dir)
     # make sure index is updated after gaps are introduced
     if os.path.exists(bank.index_path):
         os.remove(bank.index_path)
     bank.update_index()
     return bank
コード例 #5
0
def default_wbank(tmpdir):
    """ create a  directory out of the traces in default waveforms, init bank """
    base = Path(tmpdir)
    st = obspy.read()
    for num, tr in enumerate(st):
        name = base / f"{(num)}.mseed"
        tr.write(str(name), "mseed")
    bank = WaveBank(base)
    bank.update_index()
    return bank
コード例 #6
0
 def bank_null_loc_codes(self, tmpdir):
     """ create a bank that has nullish location codes in its streams. """
     st = obspy.read()
     path = Path(tmpdir)
     for tr in st:
         tr.stats.location = "--"
         time = str(get_reference_time(tr))
         name = time.split(".")[0].replace(":", "-") + f"_{tr.id}"
         tr.write(str(path / name) + ".mseed", "mseed")
     bank = WaveBank(path)
     bank.update_index()
     return bank
コード例 #7
0
 def bank_3(self, tmpdir_factory):
     """ Create a bank with several different types of streams. """
     td = tmpdir_factory.mktemp("waveforms")
     t1, t2 = self.t1, self.t2
     bulk3 = [
         ("TA", "M11A", "01", "CHZ", t1, t2),
         ("RR", "BOB", "", "HHZ", t1, t2),
         ("BB", "BOB", "02", "ENZ", t1, t2),
         ("UU", "SRU", "--", "HHN", t1, t2),
     ]
     ArchiveDirectory(str(td)).create_directory_from_bulk_args(bulk3)
     bank = WaveBank(str(td))
     bank.update_index()
     return bank
コード例 #8
0
ファイル: test_wavebank.py プロジェクト: niowniow/obsplus
 def test_min_version_new_bank_recreates_index(self, default_bank_low_version):
     """
     A new bank should delete the old index and getting data from the bank
     should recreate it.
     """
     bank = default_bank_low_version
     assert bank._index_version == self.low_version_str
     # initing a new bank should warn and delete the old index
     with pytest.warns(UserWarning):
         bank2 = WaveBank(bank.bank_path)
     assert not Path(bank2.index_path).exists()
     bank2.get_waveforms()
     assert bank2._index_version != self.low_version_str
     assert bank2._index_version == obsplus.__version__
     assert Path(bank2.index_path).exists()
コード例 #9
0
ファイル: test_wavebank.py プロジェクト: niowniow/obsplus
 def concurrent_bank(self, tmpdir):
     """ Make a temporary bank and index it. """
     st = obspy.read()
     st.write(str(Path(tmpdir) / "test.mseed"), "mseed")
     wbank = WaveBank(str(tmpdir)).update_index()
     self.func(wbank)
     return wbank
コード例 #10
0
 def test_put_waveforms_to_crandall_copy(self, tmpdir):
     """ ran into issue in docs where putting data into the crandall
     copy didn't work. """
     ds = obsplus.datasets.utils.copy_dataset(dataset="crandall",
                                              destination=Path(tmpdir))
     bank = WaveBank(ds.waveform_client)
     bank.read_index()  # this sets cache
     st = obspy.read()
     bank.put_waveforms(st)
     bank.update_index()
     df = bank.read_index(station="RJOB")
     assert len(df) == len(st)
     assert set(df.station) == {"RJOB"}
コード例 #11
0
 def gappy_and_contiguous_bank(self, tmp_path):
     """ Create a directory with gaps and continuous data """
     # first create directory with gaps
     self._make_gappy_archive(tmp_path)
     # first write data with no gaps
     st = obspy.read()
     for num, tr in enumerate(st):
         tr.stats.station = "GOOD"
         tr.write(str(tmp_path / f"good_{num}.mseed"), "mseed")
     return WaveBank(tmp_path).update_index()
コード例 #12
0
 def test_empty_bank_raises(self, tmpdir):
     """
     Test that an empty bank can be inited, but that an error is
     raised when trying to read its index.
     """
     path = Path(tmpdir) / "new"
     bank = WaveBank(path)
     # test that touching the index/meta data raises
     with pytest.raises(BankDoesNotExistError):
         bank.read_index()
     bank.put_waveforms(obspy.read())
     assert len(bank.read_index()) == 3
コード例 #13
0
 def concurrent_bank(self, tmpdir):
     """ Make a temporary bank and index it. """
     wbank = WaveBank(str(tmpdir), concurrent_updates=True)
     self.func(wbank)
     return wbank
コード例 #14
0
 def bank(self, multichannel_bank):
     """ return a wavefetcher using multichannel bank """
     return WaveBank(multichannel_bank)
コード例 #15
0
def empty_bank():
    """ init a bank with an empty directory, return """
    with tempfile.TemporaryDirectory() as td:
        yield WaveBank(td)
コード例 #16
0
 def bank(self, df_index, ta_archive):
     """ return a bank with monkeypatched index """
     sbank = WaveBank(ta_archive)
     sbank.update_index = lambda: None
     sbank._index_cache = lambda *args, **kwargs: df_index
     return sbank
コード例 #17
0
 def empty_bank(self):
     """ create a Sbank object initated on an empty directory """
     with tempfile.TemporaryDirectory() as td:
         bank = WaveBank(td)
         yield bank
コード例 #18
0
 def bank(self):
     """ return an empty bank for depositing waveforms """
     bd = dict(path_structure="streams/network", name_structure="time")
     with tempfile.TemporaryDirectory() as tempdir:
         out = os.path.join(tempdir, "temp")
         yield WaveBank(out, **bd)
コード例 #19
0
 def test_file_lock(self, concurrent_bank):
     """ Tests for the file locking mechanism. """
     newbank = WaveBank(concurrent_bank)
     with concurrent_bank.lock_index():
         with pytest.raises(BankIndexLockError):
             newbank.block_on_index_lock(0.01, 1)