def test_loading_from_file(manually_crafted_segy_file): """ Test the method for loading SEG-Y files. """ segy = SegY.load(manually_crafted_segy_file) # repeat tests for TFH assert repr(segy.tfh)[0:800] == ' ' * 800 assert repr(segy.tfh)[800:880] == 'Alle warten auf das Licht'.ljust(80) assert repr( segy.tfh)[880:960] == 'fürchtet euch fürchtet euch nicht'.ljust(80) assert repr( segy.tfh)[960:1040] == 'die Sonne scheint mir aus den Augen'.ljust(80) assert repr( segy.tfh)[1040:1120] == 'sie wird heut Nacht nicht untergehen'.ljust( 80) assert repr( segy.tfh)[1120:1200] == 'und die Welt zählt laut bis zehn'.ljust(80) assert repr(segy.tfh)[1200:1280] == 'Eins'.ljust(80) assert repr(segy.tfh)[1280:1360] == 'Hier kommt die Sonne'.ljust(80) assert repr(segy.tfh)[1360:] == ' ' * 1840 # repeat tests for BFH assert segy.bfh['job_id'] == 666 assert segy.bfh['sample_interval'] == 500 assert segy.bfh['samples_per_trace'] == 512 assert segy.bfh['sample_format'] == 3 # repeat tests for Geometry assert np.alltrue(segy.g.loc[:, 'TRACENO'] == np.arange(1, 25, 1)) assert np.alltrue(segy.g.loc[:, 'fTRACENO'] == np.arange(1, 25, 1)) assert np.alltrue(segy.g.loc[:, 'FFID'] == 375) assert np.alltrue(segy.g.loc[:, 'ELEVSC'] == -100) assert np.alltrue(segy.g.loc[:, 'COORDSC'] == -100) assert np.alltrue(segy.g.loc[:, 'NUMSMP'] == 512) assert np.alltrue(segy.g.loc[:, 'DT'] == 500) assert np.alltrue(segy.g.loc[:, 'YEAR'] == 1984) assert np.alltrue(segy.g.loc[:, 'HOUR'] == 10) assert np.alltrue(segy.g.loc[:, 'MINUTE'] == 51) assert np.alltrue(segy.g.loc[:, 'SOU_X'] == 50) assert np.alltrue(segy.g.loc[:, 'SOU_Y'] == 75) assert np.alltrue(segy.g.loc[:, 'REC_X'] == np.arange(0, 48, 2)) assert np.alltrue(segy.g.loc[:, 'REC_Y'] == -1) assert np.alltrue(segy.g.loc[:, 'CDP_X'] == np.arange(25, 49, 1)) assert np.alltrue(segy.g.loc[:, 'CDP_Y'] == 37) assert np.all(segy.g._df.notna()) # repeat tests for DataMatrix # check the matrix itself, in the _m property of the DM assert segy.dm._m.shape == (24, 512) assert segy.dm._m.dtype == np.int16 assert np.alltrue( segy.dm._m == np.repeat(np.arange(1, 25)[:, np.newaxis], 512, axis=1)) assert segy.dm.dt == 500 assert np.alltrue(segy.dm.t == np.arange(0, 256, 0.5)) # keep the name of the file assert segy.file == manually_crafted_segy_file.split('/')[-1] # empty BFH values are filled automatically assert segy.bfh['no_traces'] == 24
def test_filter(manually_crafted_segy_file): """ Test the filter method of the DataMatrix. """ segy = SegY.load(manually_crafted_segy_file) dm = segy.dm assert isinstance(dm._headers, Geometry) assert dm._m.shape == (24, 512) assert np.alltrue(dm._headers.loc[:, 'REC_X'] == np.arange(0, 48, 2)) new = dm.filter('REC_X', 10, 40, 2) assert isinstance(new._headers, Geometry) assert new._m.shape == (16, 512) assert np.alltrue(new._headers.loc[:, 'REC_X'] == np.arange(10, 42, 2)) new = dm.filter('REC_X', 0, 24, 4) assert isinstance(new._headers, Geometry) # assert new._m.shape == (7, 512) assert np.alltrue(new._headers.loc[:, 'REC_X'] == np.arange(0, 28, 4))
def test_loading_from_little_endian_file( manually_crafted_little_endian_segy_file): """ Test the method for loading SEG-Y files with little-endian byte-order. """ segy = SegY.load(manually_crafted_little_endian_segy_file) assert segy.bfh['job_id'] == 666 assert segy.bfh['sample_interval'] == 500 assert segy.bfh['samples_per_trace'] == 512 assert segy.bfh['sample_format'] == 3 assert np.alltrue(segy.g.loc[:, 'TRACENO'] == np.arange(1, 25, 1)) assert np.alltrue(segy.g.loc[:, 'fTRACENO'] == np.arange(1, 25, 1)) assert np.alltrue(segy.g.loc[:, 'FFID'] == 375) assert np.alltrue(segy.g.loc[:, 'ELEVSC'] == -100) assert np.alltrue(segy.g.loc[:, 'COORDSC'] == -100) assert np.alltrue(segy.g.loc[:, 'NUMSMP'] == 512) assert np.alltrue(segy.g.loc[:, 'DT'] == 500) assert np.alltrue(segy.g.loc[:, 'YEAR'] == 1984) assert np.alltrue(segy.g.loc[:, 'HOUR'] == 10) assert np.alltrue(segy.g.loc[:, 'MINUTE'] == 51) assert np.alltrue(segy.g.loc[:, 'SOU_X'] == 50) assert np.alltrue(segy.g.loc[:, 'SOU_Y'] == 75) assert np.alltrue(segy.g.loc[:, 'REC_X'] == np.arange(0, 48, 2)) assert np.alltrue(segy.g.loc[:, 'REC_Y'] == -1) assert np.alltrue(segy.g.loc[:, 'CDP_X'] == np.arange(25, 49, 1)) assert np.alltrue(segy.g.loc[:, 'CDP_Y'] == 37) assert np.all(segy.g._df.notna()) # repeat tests for DataMatrix # check the matrix itself, in the _m property of the DM assert segy.dm._m.shape == (24, 512) assert segy.dm._m.dtype == np.int16 assert np.alltrue(segy.dm._m == np.repeat( np.arange(1, 48, 2)[:, np.newaxis], 512, axis=1)) assert segy.dm.dt == 500 assert np.alltrue(segy.dm.t == np.arange(0, 256, 0.5)) # keep the name of the file assert segy.file == manually_crafted_little_endian_segy_file.split('/')[-1] # empty BFH values are filled automatically assert segy.bfh['no_traces'] == 24
def test_crop(manually_crafted_segy_file): """ Test the crop method of the DataMatrix. """ segy = SegY.load(manually_crafted_segy_file) dm = segy.dm assert np.alltrue(dm.t == np.arange(0, 256, 0.5)) assert dm._m.shape == (24, 512) new = dm.crop(128) assert np.alltrue(new.t == np.arange(0, 128.5, 0.5)) assert new._m.shape == (24, 257) new = dm.crop(100) assert np.alltrue(new.t == np.arange(0, 100.5, 0.5)) assert new._m.shape == (24, 201) dm.crop(128, inplace=True) assert np.alltrue(dm.t == np.arange(0, 128.5, 0.5)) assert dm._m.shape == (24, 257)
def test_resample(manually_crafted_segy_file): """ Test the resample method of the DataMatrix. """ segy = SegY.load(manually_crafted_segy_file) dm = segy.dm assert repr(dm) == 'DataMatrix: 24 traces, 512 samples, dt=500' assert dm._m.shape == (24, 512) assert np.alltrue(dm.t == np.arange(0, 256, 0.5)) new = dm.resample(1000) assert repr(new) == 'DataMatrix: 24 traces, 256 samples, dt=1000' assert new._m.shape == (24, 256) assert np.alltrue(new.t == np.arange(0, 256, 1)) new = dm.resample(2000) assert repr(new) == 'DataMatrix: 24 traces, 128 samples, dt=2000' assert new._m.shape == (24, 128) assert np.alltrue(new.t == np.arange(0, 256, 2)) with pytest.raises(ValueError): new = dm.resample(256)