Exemple #1
0
 def test_filter_frequency_in_band(self):
     process = XArrayBandpass(freqmin=0.5, freqmax=20.0)
     trace = converter(create_random_trace(sampling_rate=100))
     trace = process(trace, starttime=0, station=0)
     source = self._get_frequency_of_trace(trace, sample_point=5)
     target = 0.1
     assert source > target, "bandpass filter removing desired frequency"
    def test_passband_3_obspy_equivalent(self):
        freqmin = 1.0
        freqmax = 2.5
        tau = None
        starttime = UTCDateTime("2017-10-01 06:00:00").timestamp
        starttime_utc = UTCDateTime("2017-10-01 06:00:00")
        endtime_utc = UTCDateTime("2017-10-01 06:10:00")
        anxcor_main = build_anxcor(tau, interpolation_method='nearest')

        target_stream = get_obspy_correlation(starttime_utc, endtime_utc)
        target_stream = numpy_2_stream(target_stream)
        target_stream.filter('bandpass',
                             freqmin=freqmin,
                             freqmax=freqmax,
                             corners=4,
                             zerophase=True)

        result = anxcor_main.process([starttime])
        bp = XArrayBandpass(freqmin=freqmin,
                            freqmax=freqmax,
                            order=4,
                            zerophase=True)
        result = bp(result)
        source_bp_array = convert_xarray_to_np_array(
            result, variable='src:BB rec:Nodal')
        source_stream = numpy_2_stream(source_bp_array)

        source_stream.normalize()
        target_stream.normalize()

        np.testing.assert_allclose(source_stream[0].data,
                                   target_stream[0].data,
                                   atol=1e-5)
Exemple #3
0
 def test_filter_frequency_out_of_band(self):
     process = XArrayBandpass(freqmin=0.5, freqmax=20.0)
     trace = converter(create_random_trace(sampling_rate=100))
     trace = process(trace, starttime=0, station=0)
     source = self._get_frequency_of_trace(trace, sample_point=40.0)
     target = 0
     assert round(abs(source - target), 1) == 0, "frequency not removed"
Exemple #4
0
 def test_bandpass_result(self):
     bp = XArrayBandpass(freqmin=0.1, freqmax=10.0)
     anxcor = Anxcor()
     anxcor.set_window_length(120.0)
     times = anxcor.get_starttimes(starttime_stamp, endtime_stamp, 0.5)
     bank = WavebankWrapper(source_dir)
     anxcor.add_dataset(bank, 'nodals')
     result = anxcor.process(times)
     bp_result = bp(result)
     assert isinstance(bp_result, xr.Dataset)
Exemple #5
0
 def test_phase_shift_not_introduced(self):
     process = XArrayBandpass(freqmin=0.5, freqmax=20.0)
     trace_initial = converter(
         create_sinsoidal_trace(sampling_rate=100, period=0.25,
                                duration=10))
     trace_processed = process(trace_initial.copy(), starttime=0, station=0)
     source_1 = np.argmax(
         signal.correlate(trace_initial.data, trace_processed.data))
     correction = source_1 - (trace_initial.data.shape[2] * 2 - 1) // 2
     target = 0
     assert correction == target, "filter introduced phase shift"
Exemple #6
0
    def test_obspy_equivalent(self):
        stream = read()
        del stream[-1]
        del stream[-1]

        source_stream = stream.copy()
        stream.filter('bandpass',
                      freqmin=0.1,
                      freqmax=1.0,
                      zerophase=True,
                      corners=4)

        converter = XArrayConverter()
        bp = XArrayBandpass(freqmin=0.1, freqmax=1.0, order=4, zerophase=True)
        bp_data = bp(converter(source_stream))

        source_stream[0].data = bp_data.data.squeeze()

        np.testing.assert_allclose(source_stream[0].data, stream[0].data)
Exemple #7
0
 def test_nonetype_in_out(self):
     process = XArrayBandpass()
     result = process(None, None, starttime=0, station=0)
     assert result == None