def test_bandpass(_data): trace = _data['mseed'][0] res = bandpass(trace, 2, 3) assert not np.array_equal(trace.data, res.data) assert trace.stats.starttime == res.stats.starttime assert trace.stats.endtime == res.stats.endtime assert trace.stats.npts == res.stats.npts assert len(trace.data) == len(res.data)
def __bandpass_remresp(segment, config, trace, inventory): """Applies a pre-process on the given segment waveform by filtering the signal and removing the instrumental response. DOES modify the segment stream in-place (see below) The filter algorithm has the following steps: 1. Sets the max frequency to 0.9 of the Nyquist frequency (sampling rate /2) (slightly less than Nyquist seems to avoid artifacts) 2. Offset removal (subtract the mean from the signal) 3. Tapering . Pad data with zeros at the END in order to accommodate the filter transient nf['bandpass_freq_max'] 5. Apply bandpass filter, where the lower frequency is set according to the magnitude 6. Remove padded elements 7. Remove the instrumental response IMPORTANT NOTES: - Being decorated with '@gui.preprocess', this function: * returns the *base* stream used by all plots whenever the relative check-box is on * must return either a Trace or Stream object - In this implementation THIS FUNCTION DOES MODIFY `segment.stream()` IN-PLACE: from within `main`, further calls to `segment.stream()` will return the stream returned by this function. However, In any case, you can use `segment.stream().copy()` before this call to keep the old "raw" stream :return: a Trace object. """ # define some parameters: evt = segment.event conf = config['preprocess'] freq_max = conf['bandpass_freq_max'] if is_accelerometer(segment): # accelerometer freq_min = mag2freq(evt.magnitude) else: # velocimeter freq_min = conf['velocimeter_freq_min'] # note: bandpass here below copied the trace! important! trace = bandpass(trace, freq_min=freq_min, freq_max=freq_max, max_nyquist_ratio=conf['bandpass_max_nyquist_ratio'], corners=conf['bandpass_corners'], copy=False) trace.remove_response(inventory=inventory, output=conf['remove_response_output'], water_level=conf['remove_response_water_level']) return trace
def bandpass_remresp(segment, config): """{{ PROCESS_PY_BANDPASSFUNC | indent }} """ stream = segment.stream() assert1trace(stream) # raise and return if stream has more than one trace trace = stream[0] inventory = segment.inventory() # define some parameters: evt = segment.event conf = config['preprocess'] # note: bandpass here below copied the trace! important! trace = bandpass(trace, mag2freq(evt.magnitude), freq_max=conf['bandpass_freq_max'], max_nyquist_ratio=conf['bandpass_max_nyquist_ratio'], corners=conf['bandpass_corners'], copy=False) trace.remove_response(inventory=inventory, output=conf['remove_response_output'], water_level=conf['remove_response_water_level']) return trace