def test_stream_wind_1d(): """ Test the ``wind`` method of the Stream class for 1D data. """ # Create one-dimensionnal data of size 'ns' ns = 1000 dt = 0.001 data = np.ones(ns) # Create a new Stream object object = Stream() # Create SU-like data structure from 'data' without options. object.create(data, dt=dt) object.graph() # Windowing object.wind(tmin=0.1, tmax=0.2) object.graph() # 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), nsnew)
def seg2scan(fname): """ Scan the SEG-2 file and return the file header and trace headers. """ scalco = 1 scalel = 1 try: # Try to open file fpointer = open(fname, 'rb') # Create a Stream object seg2stream = Stream() # File format seg2stream.format = 'seg-2' # Read the file header endian, seg2stream.revision, trace_pointer, seg2stream.file_descriptor, string_term_char, line_term_char = _read_file_descriptor( fpointer) # Read trace descriptor and data blocks _read_traces(seg2stream, fpointer, endian, trace_pointer, string_term_char, line_term_char, scalco, scalel) return seg2stream.file_descriptor, seg2stream.trace_descriptor except FileNotFoundError: pass
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_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_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_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_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 seg2read(fname, **options): """ Read SEG-2 files and store in NESSI data structure. :param fname: SEG-2 filename and path .. rubric:: Basic usage >>> # Import seg2read from nessi package >>> from nessi.io import seg2read >>> # Read SEG-2 file >>> sdata = seg2read('NESSI_TEST_DATA.seg2') """ # Get options scalco = options.get('scalco', 1) scalel = options.get('scalel', 1) try: # Try to open file fpointer = open(fname, 'rb') # Create a Stream object seg2stream = Stream() # File format seg2stream.format = 'seg-2' # Read the file header endian, seg2stream.revision, trace_pointer, seg2stream.file_descriptor, string_term_char, line_term_char = _read_file_descriptor( fpointer) # Read trace descriptor and data blocks _read_traces(seg2stream, fpointer, endian, trace_pointer, string_term_char, line_term_char, scalco, scalel) return seg2stream except FileNotFoundError: pass
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)
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 suread(fname): """ Read Seismic Unix files and store in NESSI data structure. :param fname: Seismic Unix filename and path .. rubric:: Basic usage >>> # Import suread from nessi package >>> from nessi.io import suread >>> # Read Seismic Unix file >>> sdata = suread('NESSI_TEST_DATA.su') """ # Test if file exist # Check file endian, ns, ntrac = _check_format(fname) # Initialize stream sudata = Stream() sudata.origin = fname sudata.header.resize(ntrac) #, dtype=sudata.sutype) sudata.endian = endian if ntrac == 1: sudata.traces = np.zeros(ns, dtype=np.float32, order='C') else: sudata.traces = np.zeros((ntrac, ns), dtype=np.float32, order='C') #, dtype=np.float32) # Endianess parameters if sudata.endian == 'b': # Big endian sudtype = _sutype().newbyteorder() npdtype = '>f4' if sudata.endian == 'l': # Little endian sudtype = _sutype() npdtype = '<f4' # Open the file to read file = open(fname, 'rb') if ntrac == 1: # Get header bhdr = file.read(240) sudata.header[0] = np.frombuffer(bhdr, dtype=sudtype, count=1)[0] # Get data btrc = file.read(ns * 4) sudata.traces[:] = np.frombuffer(btrc, dtype=(npdtype, ns), count=1)[0] # TRID default value (=1 seismic data) if sudata.header[0]['trid'] == 0: sudata.header[0]['trid'] = 1 # NS keyword header value sudata.header[0]['ns'] = ns # DT default value (=0.04s) if sudata.header[0]['dt'] == 0: # Time sampling (default dt=0.04s) sudata.header[0]['dt'] = int(0.04 * 1000000.) else: # Loop over traces for itrac in range(0, ntrac): # Get header bhdr = file.read(240) sudata.header[itrac] = np.frombuffer(bhdr, dtype=sudtype, count=1)[0] # Get data btrc = file.read(ns * 4) sudata.traces[itrac, :] = np.frombuffer(btrc, dtype=(npdtype, ns), count=1)[0] # TRID default value (=1 seismic data) if sudata.header[itrac]['trid'] == 0: sudata.header[itrac]['trid'] = 1 # NS keyword header value sudata.header[itrac]['ns'] = ns # DT default value (=0.04s) if sudata.header[itrac]['dt'] == 0: # Time sampling (default dt=0.04s) sudata.header[itrac]['dt'] = int(0.04 * 1000000.) if endian == 'b': sudata.header.newbyteorder() # Close the file file.close() return sudata