def test_stream_windkey_2d(): """ Test the ``windkey`` method of the Stream class for 2D data. """ # Create two-dimensionnal data of size '(nr,ns)' nr = 100 ns = 1000 dt = 0.001 data = np.ones((nr, ns), dtype=np.float32) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' without options. object.create(data, dt=dt) # Windowing vmin = 10 vmax = 20 object.windkey(key='tracf', vmin=vmin, vmax=vmax) # Attempted result nrnew = vmax - vmin + 1 # Testing the stream object members initialization np.testing.assert_equal(object.header[0]['ns'], ns) np.testing.assert_equal(object.header[0]['tracf'], 1) np.testing.assert_equal(object.header[0]['tracl'], 10) np.testing.assert_equal(np.size(object.traces, axis=0), nrnew) np.testing.assert_equal(np.size(object.traces, axis=1), ns)
def test_stream_stack_weight_2d(): """ Test the ``stack`` method of the Stream class for 2D data. """ # Create one-dimensionnal data of size 'ns' ns = 1000 nr = 100 dt = 0.001 data = np.ones((nr, ns), dtype=np.float32) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' without options. object.create(data, dt=dt) # Stacking weight = np.zeros(nr, dtype=np.float32) weight[:] = 10. object.stack(weight=weight) # Attempted result dstack = np.ones(ns, dtype=np.float32) dstack *= 1000. # Testing the stream object members initialization np.testing.assert_equal(np.size(object.header, axis=0), 1) np.testing.assert_equal(object.header[0]['ns'], ns) np.testing.assert_equal(object.traces, dstack)
def test_stream_kill_multi_traces_2d(): """ Test the ``kill`` method of the Stream class for 2D data. """ # Create two-dimensionnal data of size '(nr,ns)' nr = 100 ns = 1000 dt = 0.001 data = np.ones((nr, ns), dtype=np.float32) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' without options. object.create(data, dt=dt) # Killing object.kill(key='tracf', a=10, count=10) # Attempted result dkill = np.zeros((10, ns), dtype=np.float32) # Testing the stream object members initialization np.testing.assert_equal(object.traces[9:19, :], dkill)
def test_stream_wind_2d(): """ Test the ``wind`` method of the Stream class for 2D data. """ # Create two-dimensionnal data of size '(nr,ns)' nr = 100 ns = 1000 dt = 0.001 data = np.ones((nr, ns), dtype=np.float32) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' without options. object.create(data, dt=dt) # Windowing object.wind(tmin=0.1, tmax=0.2) # Attempted result itmin = int(0.1 / dt) itmax = int(0.2 / dt) nsnew = itmax - itmin + 1 # Testing the stream object members initialization np.testing.assert_equal(object.header[0]['ns'], nsnew) np.testing.assert_equal(np.size(object.traces, axis=0), nr) np.testing.assert_equal(np.size(object.traces, axis=1), nsnew)
def test_stream_create_2d(): """ Test the ``create`` method of the Stream class for 2D data. """ # Create two-dimensionnal data of size 'ns'x'nr' ns = 256 nr = 64 data = np.ones((nr, ns)) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' without options. object.create(data) # Testing the stream object members initialization np.testing.assert_equal(object.header[:]['trid'], np.ones(nr, dtype=np.int16)) np.testing.assert_equal(object.header[:]['tracl'], np.linspace(1, nr, nr, dtype=np.int32)) np.testing.assert_equal(object.header[:]['tracr'], np.linspace(1, nr, nr, dtype=np.int32)) np.testing.assert_equal(object.header[:]['tracf'], np.linspace(1, nr, nr, dtype=np.int32)) np.testing.assert_equal(object.header[0]['ns'], ns) np.testing.assert_equal(object.header[0]['dt'], 0.01 * 1000000.)
def test_stream_gethdr_count_2d(): """ Test the Stream.gethdr method for 2D data """ # Create two-dimensionnal data of size 'ns'x'nr' ns = 256 nr = 64 data = np.ones((nr, ns)) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' without options. object.create(data, dt=0.01) # Set header values object.header[:]['sx'] = 10 object.header[:]['scalco'] = 1 # Get header values sx = object.gethdr(key='sx', imin=0, count=1) # Create an equivalent of attempted result sx_att = 10. np.testing.assert_equal(sx, sx_att)
def test_stream_gethdr_1d(): """ Test the Stream.gethdr method for 1D data. """ # Create one-dimensional data of size 'ns' ns = 256 data = np.ones(ns) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' with option. object.create(data, dt=0.01) # Get header value dt = object.gethdr(key='dt') np.testing.assert_equal(dt, 0.01)
def test_stream_copy(): """ Test the Stream.copy method. """ # Create one-dimensionnal data of size 'ns' ns = 256 data = np.ones(ns) # Create a new Stream object object1 = Stream() # Create SU-like data structure from 'data' without options. object1.create(data) # Copy the Stream object object2 = object1.copy() np.testing.assert_equal(object1.header, object2.header) np.testing.assert_equal(object1.traces, object2.traces)
def test_taper_sine_1d(): """ signal.tapering.time_taper testing for sine taper. """ # Create initial data trace ns = 128 # number of time sample dt = 0.01 data = np.ones((ns), dtype=np.float32) # Create Stream object object = Stream() object.create(data, dt=0.01) # Define the taper tbeg = float(16 * dt) * 1000. tend = float(16 * dt) * 1000. # Tapering object.taper(tbeg=tbeg, tend=tend, type='sine') # Attempted output output = np.array([ 0., 0.09226836, 0.18374951, 0.27366298, 0.36124167, 0.44573835, 0.52643216, 0.60263461, 0.67369562, 0.7390089, 0.7980172, 0.85021716, 0.8951633, 0.93247223, 0.96182567, 0.9829731, 0.99573416, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0.99573416, 0.9829731, 0.96182567, 0.93247223, 0.8951633, 0.85021716, 0.7980172, 0.7390089, 0.67369562, 0.60263461, 0.52643216, 0.44573835, 0.36124167, 0.27366298, 0.18374951, 0.09226836, 0. ], dtype=np.float32) # Testing np.testing.assert_allclose(object.traces, output, atol=1.e-4)
def test_stream_taper_linear_1d(): """ signal.tapering.time_taper testing for linear taper. """ # Create initial data trace ns = 128 # number of time sample dt = 0.01 data = np.ones((ns), dtype=np.float32) # Create Stream object object = Stream() object.create(data, dt=0.01) # Define the taper tbeg = float(16 * dt) * 1000. tend = float(16 * dt) * 1000. # Tapering object.taper(tbeg=tbeg, tend=tend, type='linear') # Attempted output output = np.array([ 0., 0.05882353, 0.11764706, 0.17647059, 0.23529412, 0.29411766, 0.35294119, 0.41176471, 0.47058824, 0.52941179, 0.58823532, 0.64705884, 0.70588237, 0.7647059, 0.82352942, 0.88235295, 0.94117647, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0.94117647, 0.88235295, 0.82352942, 0.7647059, 0.70588237, 0.64705884, 0.58823532, 0.52941179, 0.47058824, 0.41176471, 0.35294119, 0.29411766, 0.23529412, 0.17647059, 0.11764706, 0.05882353, 0. ], dtype=np.float32) # Testing np.testing.assert_allclose(object.traces, output, atol=1.e-4)
def test_taper_cosine_1d(): """ signal.tapering.time_taper testing for cosine taper. """ # Create initial data trace ns = 128 # number of time sample dt = 0.01 data = np.ones((ns), dtype=np.float32) # Create Stream object object = Stream() object.create(data, dt=0.01) # Define the taper tbeg = float(16 * dt) * 1000. tend = float(16 * dt) * 1000. # Tapering object.taper(tbeg=tbeg, tend=tend, type='cosine') # Attempted output output = np.array([ 0., 0.00851345, 0.03376389, 0.07489143, 0.13049555, 0.19868268, 0.27713081, 0.36316851, 0.45386583, 0.54613417, 0.63683152, 0.72286916, 0.80131733, 0.86950445, 0.92510855, 0.96623611, 0.99148655, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0.99148655, 0.96623611, 0.92510855, 0.86950445, 0.80131733, 0.72286916, 0.63683152, 0.54613417, 0.45386583, 0.36316851, 0.27713081, 0.19868268, 0.13049555, 0.07489143, 0.03376389, 0.00851345, 0. ], dtype=np.float32) # Testing np.testing.assert_allclose(object.traces, output, atol=1.e-4)
def test_stream_create_1d(): """ Test the ``create`` method of the Stream class for 1D data. """ # Create one-dimensionnal data of size 'ns' ns = 256 data = np.ones(ns) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' without options. object.create(data) # Testing the stream object members initialization np.testing.assert_equal(object.header['trid'], 1) np.testing.assert_equal(object.header['tracl'], 1) np.testing.assert_equal(object.header['tracr'], 1) np.testing.assert_equal(object.header['tracf'], 1) np.testing.assert_equal(object.header['ns'], ns) np.testing.assert_equal(object.header['dt'], 0.01 * 1000000.)
def test_stream_gethdr_2d(): """ Test the Stream.gethdr method for 2D data """ # Create two-dimensionnal data of size 'ns'x'nr' ns = 256 nr = 64 data = np.ones((nr, ns)) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' without options. object.create(data, dt=0.01) # Get header values dt = object.gethdr(key='dt') # Create an equivalent of attempted result dt_att = np.zeros(nr, dtype=np.float32) dt_att[:] = 0.01 np.testing.assert_equal(dt, dt_att)