def test_trace_path(self): """test the basics of trace conversions""" struc = "waveforms/{year}/{month}/{day}/{network}/{station}/{channel}" tr = obspy.read()[0] expected = "waveforms/2009/08/24/BW/RJOB/EHZ/2009-08-24T00-20-03.mseed" # expected_str = _expected.replace('/', os.sep) out = _summarize_trace(tr, path_struct=struc)["path"] assert out.replace(os.sep, "/") == expected
def put_waveforms(self, stream: Union[obspy.Stream, obspy.Trace], name=None, update_index=True): """ Add the waveforms in a waveforms to the bank. Parameters ---------- stream An obspy waveforms object to add to the bank name Name of file, if None it will be determined based on contents update_index Flag to indicate whether or not to update the waveform index after writing the new events. Default is True. """ self.ensure_bank_path_exists(create=True) st_dic = defaultdict(lambda: []) # make sure we have a trace iterable stream = [stream] if isinstance(stream, obspy.Trace) else stream # iter the waveforms and group by common paths paths = [] for tr in stream: summary = _summarize_trace( tr, name=name, path_struct=self.path_structure, name_struct=self.name_structure, ) path = self.bank_path / summary["path"] st_dic[path].append(tr) # iter all the unique paths and save for path, tr_list in st_dic.items(): # make the parent directories if they dont exist path.parent.mkdir(exist_ok=True, parents=True) stream = obspy.Stream(traces=tr_list) # load the waveforms if the file already exists if path.exists(): st_existing = obspy.read(str(path)) stream += st_existing # polish streams and write stream.merge(method=1) stream.write(str(path), format="mseed") paths.append(path) # update the index as the contents have changed if st_dic and update_index: self.update_index(paths=paths)
def output(self, struct_string, waveform_cache_trace): """init a bank_structure class from the structure strings""" return _summarize_trace(waveform_cache_trace, path_struct=struct_string)