示例#1
0
    def test_symmetric_output(self):
        converter = XArrayConverter()
        signal_length = 1000
        sampling_rate = 20.0
        center_index = int(signal_length * sampling_rate) // 2
        stream = create_sinsoidal_trace(sampling_rate=sampling_rate,
                                        duration=signal_length,
                                        period=2)
        stream1 = create_sinsoidal_trace(sampling_rate=sampling_rate,
                                         duration=signal_length,
                                         period=0.5)
        stream[0].data += stream1[0].data

        stream[0].data += np.random.uniform(-0.01, 0.01, stream[0].data.shape)
        converter = XArrayConverter()
        xarray = converter(stream)
        center = True
        whitening_op = XArrayWhiten(taper=0.1,
                                    window=0.05,
                                    whiten_type='cross_component',
                                    freqmax=20.0,
                                    freqmin=0.01,
                                    center=center,
                                    order=2)
        whitened_array = whitening_op(xarray)
        xarray_squeezed = whitened_array[0, 0, :].data.squeeze()
        difference = xarray_squeezed[:center_index] - xarray_squeezed[
            -center_index:]
        cumdiff = abs(
            np.cumsum(difference)[-1] / (signal_length * sampling_rate))
        assert pytest.approx(0, abs=1e-4) == cumdiff
示例#2
0
    def test_jupyter_tutorial_tapers(self):
        client = Client("IRIS")
        t = UTCDateTime("2018-12-25 12:00:00").timestamp
        st = client.get_waveforms("UU",
                                  "SPU",
                                  "*",
                                  "H*",
                                  t,
                                  t + 10 * 60,
                                  attach_response=True)
        pre_filt = (0.01, 0.03, 40.0, 45.0)
        st = anxcor_utils.remove_response(st,
                                          output='DISP',
                                          pre_filt=pre_filt,
                                          zero_mean=True,
                                          taper=True)
        converter = XArrayConverter()
        resampler = XArrayResample(target_rate=10.0)
        rmmean_trend = XArrayRemoveMeanTrend()

        xarray = converter(st)
        resampled_array = resampler(xarray)
        rmm_array = rmmean_trend(resampled_array)
        whitening_op = XArrayWhiten(taper=0.05,
                                    whiten_type='cross_component',
                                    freqmax=3.0,
                                    freqmin=0.01,
                                    smoothing_window_ratio=0.01)

        whitened_array = whitening_op(rmm_array)
        assert whitened_array.data[0, 0, 0] == pytest.approx(0, abs=1e-2)
示例#3
0
 def test_symmetric_output(self):
     converter = XArrayConverter()
     signal_length = 1000
     sampling_rate = 20.0
     center_index = int(signal_length * sampling_rate) // 2
     stream = create_sinsoidal_trace(sampling_rate=sampling_rate,
                                     duration=signal_length,
                                     period=2)
     stream1 = create_sinsoidal_trace(sampling_rate=sampling_rate,
                                      duration=signal_length,
                                      period=0.5)
     stream[0].data += stream1[0].data
     xarray = converter(stream)
     t_norm_op = XArrayTemporalNorm(t_norm_type='reduce_metric',
                                    taper=0.1,
                                    freqmin=0.02,
                                    freqmax=3.0,
                                    window=5.0,
                                    rolling_procedure='mean',
                                    reduce_metric='max')
     t_normed_array = t_norm_op(xarray)
     xarray_squeezed = t_normed_array[0, 0, :].data.squeeze()
     difference = xarray_squeezed[:center_index] - xarray_squeezed[
         -center_index:]
     cumdiff = abs(
         np.cumsum(difference)[-1] / (signal_length * sampling_rate))
     assert pytest.approx(0, abs=1e-2) == cumdiff
示例#4
0
    def test_phase_shift(self):
        stream = create_sinsoidal_trace(sampling_rate=40.0,
                                        duration=1000.0,
                                        period=20)

        stream[0].data += np.random.uniform(-0.01, 0.01, stream[0].data.shape)
        converter = XArrayConverter()
        xarray = converter(stream)
        taper = 0.1
        center = False
        ratio = 0.01
        whitening_op = XArrayWhiten(taper=0.1,
                                    window=0.05,
                                    whiten_type='cross_component',
                                    freqmax=20.0,
                                    freqmin=0.01,
                                    center=center,
                                    order=2)

        whitened_array = whitening_op(xarray)
        a = whitened_array.data[0, 0, :].squeeze()
        b = xarray.data[0, 0, :].squeeze()
        xcorr = correlate(a, b)

        # delta time array to match xcorr
        dt = np.arange(1 - a.shape[-1], a.shape[-1])

        recovered_time_shift = dt[xcorr.argmax()]

        assert recovered_time_shift == 0
示例#5
0
 def test_jupyter_example(self):
     client = Client("IRIS")
     t = UTCDateTime("2018-12-25 12:00:00").timestamp
     st = client.get_waveforms("UU",
                               "SPU",
                               "*",
                               "H*",
                               t,
                               t + 10 * 60,
                               attach_response=True)
     pre_filt = (0.01, 0.03, 40.0, 45.0)
     st = anxcor_utils.remove_response(st,
                                       output='DISP',
                                       pre_filt=pre_filt,
                                       zero_mean=True,
                                       taper=True)
     converter = XArrayConverter()
     resampler = XArrayResample(target_rate=10.0)
     rmmean_trend = XArrayRemoveMeanTrend()
     temp_normalizer = XArrayTemporalNorm(t_norm_type='reduce_metric',
                                          freqmin=0.001,
                                          freqmax=0.1,
                                          time_window=2.0,
                                          rolling_procedure='mean',
                                          reduce_metric='max')
     xarray = converter(st)
     resampled_array = resampler(xarray)
     rmm_array = rmmean_trend(resampled_array)
     t_normed_array = temp_normalizer(rmm_array)
     assert True
示例#6
0
    def test_conversion_correlation(self):
        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(None, interpolation_method='nearest')
        stream_source = anxcor_main._get_task('data')(starttime=starttime,
                                                      station='DV.1')
        xarray_src = XArrayConverter()(stream_source, starttime=starttime)
        stream_source = convert_to_stream(xarray_src)
        stream_target = get_dv().trim(starttime_utc, endtime_utc)

        np.testing.assert_allclose(stream_source[0].data,
                                   stream_target[0].data)
示例#7
0
 def __init__(self, window_length=None, **kwargs):
     self._single_station_include = []
     self._station_pair_include = []
     self._station_pair_exclude = []
     self._single_station_exclude = []
     self._window_length = window_length
     self._tasks = {
         'data': DataLoader(**kwargs),
         'xconvert': XArrayConverter(),
         'process': {},
         'crosscorrelate': XArrayXCorrelate(),
         'post-correlate': NullTask('post-correlate'),
         'combine': XArrayCombine(),
         'post-combine': NullTask('post-combine'),
         'pre-stack': NullDualTask('pre-stack'),
         'stack': XArrayStack(),
         'post-stack': NullTask('post-stack')
     }
     self._process_order = []
示例#8
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)
    def test_phase_shift(self):
        stream   = create_sinsoidal_trace(sampling_rate=40.0, duration = 2000.0,
                                                               period=0.3)
        converter = XArrayConverter()
        xarray = converter(stream)
        t_norm_op = XArrayTemporalNorm(t_norm_type='reduce_metric',
                                             lower_frequency=0.001, upper_frequency=4,
                                             time_window=2.0, rolling_procedure='mean',
                                             reduce_metric='max')

        whitened_array = t_norm_op(xarray)
        a = whitened_array.data[0,0,:].squeeze()
        b = xarray.data[0,0,:].squeeze()
        xcorr = correlate(a, b)
        dt = np.arange(1 - a.shape[-1], a.shape[-1])

        recovered_time_shift = dt[xcorr.argmax()]

        assert recovered_time_shift==0
示例#10
0
import unittest
from tests.synthetic_trace_factory import create_random_trace, create_sinsoidal_trace_w_decay
#from synthetic_trace_factory import create_random_trace, create_sinsoidal_trace_w_decay
from anxcor.xarray_routines import XArrayXCorrelate, XArrayConverter
import numpy as np

converter = XArrayConverter()


class TestCorrelation(unittest.TestCase):
    def test_convert_is_accurate(self):
        max_tau_shift = None
        correlator = XArrayXCorrelate(max_tau_shift=max_tau_shift)

        e2 = create_sinsoidal_trace_w_decay(decay=0.8,
                                            station='k',
                                            network='v',
                                            channel='e',
                                            duration=20)
        n2 = create_random_trace(station='k',
                                 network='v',
                                 channel='n',
                                 duration=20)
        z2 = create_sinsoidal_trace_w_decay(decay=0.3,
                                            station='k',
                                            network='v',
                                            channel='z',
                                            duration=20)
        b2 = create_random_trace(station='k',
                                 network='v',
                                 channel='b',
示例#11
0
 def test_basic_read_conversion_functionality(self):
     stream = read()
     xarray = XArrayConverter()(stream)
     assert True