Example #1
0
    def put_waveforms(self,
                      stream: obspy.Stream,
                      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: [])
        # iter the waveforms and group by common paths
        for tr in stream:
            summary = _summarize_trace(
                tr,
                name=name,
                path_struct=self.path_structure,
                name_struct=self.name_structure,
            )
            path = os.path.join(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 dir structure of it doesn't exist
            if not os.path.exists(os.path.dirname(path)):
                os.makedirs(os.path.dirname(path))
            stream = obspy.Stream(traces=tr_list)
            # load the waveforms if the file already exists
            if os.path.exists(path):
                st_existing = obspy.read(path)
                stream += st_existing
            # polish streams and write
            stream.merge(method=1)
            stream.write(path, format="mseed")
        # update the index as the contents have changed
        if st_dic and update_index:
            self.update_index()
Example #2
0
 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"
     assert _summarize_trace(tr, path_struct=struc)["path"] == expected
Example #3
0
 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)