def rf_stream(stream, stats, method='P', window=(-20, 100), downsample=None, filter=None, #@ReservedAssignment rotate='ZNE->LQT', angles='stats', signoise=None, deconvolve='time', **deconvolve_kwargs): st = stream assert len(st) == 3 if method != 'P': raise NotImplementedError for tr in st: tr.stats.update(stats) if filter: st.filter(filter) st.trim(stats.onset + window[0], stats.onset + window[1]) if downsample and downsample <= st[0].stats.sampling_rate: st.decimate(int(st[0].stats.sampling_rate) // downsample) if angles == 'polar': raise NotImplementedError st.rotate(rotate) src_comp = rotate.split('->')[-1][0] if signoise: raise NotImplementedError if deconvolve: deconv(st, src_comp, method=deconvolve, **deconvolve_kwargs) # multiply -1 on Q and T component for tr in st: if tr.stats.channel[-1] != src_comp: tr.data = -tr.data
def deconvolve(self, method='P', deconvolve_method='time', **kwargs): """ Deconvolve source component of stream from other components. All args and kwargs are passed to the function :func:`~rf.deconvolve.deconv`. """ if len(self) % 3 != 0: raise ValueError('For deconvolution a 3 component stream is needed' '. The provied stream is not divisible by 3.') i = 0 while i < len(self): comps = ''.join(tr.stats.channel[-1] for tr in self[i:i + 3]) if i == 0: comps0 = comps elif comps != comps0: raise ValueError('Error') # set standard parameters for deconvolution stats = self[i].stats lensec = stats.endtime - stats.starttime onset = stats.onset - stats.starttime if method == 'P' and deconvolve_method == 'time': def_kwargs = {'winsrc': (-10, 30, 5), 'winrsp': (-onset, lensec - onset), 'winrf': (-onset, lensec - onset)} elif method == 'S' and deconvolve_method == 'time': def_kwargs = {'winsrc': (-10, 30, 5), 'winrsp': (onset - lensec, onset), 'winrf': (onset - lensec, onset)} elif method == 'P': def_kwargs = {'winsrc': (-onset + 5, lensec - onset - 5, 5), 'tshift': onset} else: def_kwargs = {'winsrc': (onset - lensec + 5, onset - 5), 'tshift': lensec - onset} nkwargs = kwargs.copy() for k in def_kwargs: if k not in kwargs: nkwargs[k] = def_kwargs[k] try: deconv(self[i:i + 3], method=deconvolve_method, **nkwargs) except Exception as ex: print(ex) print('error while calculating the deconvolution') for tr in self[i:i + 3]: self.remove(tr) continue i += 3
def deconvolve(self, *args, **kwargs): """ Deconvolve source component of stream from other components. All args and kwargs are passed to the function :func:`~rf.deconvolve.deconv`. """ if len(self) % 3 != 0: raise ValueError('For deconvolution a 3 component stream is needed' '. The provied stream is not divisible by 3.') i = 0 while i < len(self): comps = ''.join(tr.stats.channel[-1] for tr in self[i:i + 3]) if i == 0: comps0 = comps elif comps != comps0: raise ValueError('Error') deconv(self[i:i + 3], *args, **kwargs) i += 3