def test_plot_traces(self): # Only checking that these do not throw errors dat = NoInitRadarData(big=True) fig, ax = plot.plot_traces(dat, 0) fig, ax = plot.plot_traces(dat, [1, 1]) fig, ax = plot.plot_traces(dat, [1, 18]) with self.assertRaises(ValueError): fig, ax = plot.plot_traces(dat, np.arange(10)) with self.assertRaises(IndexError): fig, ax = plot.plot_traces(dat, 999) # no nmo fig, ax = plot.plot_traces(dat, 0, ydat='depth') # with nmo dat.nmo_depth = np.arange(10) fig, ax = plot.plot_traces(dat, 0, ydat='depth') with self.assertRaises(ValueError): fig, ax = plot.plot_traces(dat, 0, ydat='dum') # Make sure we handle axes rescaling ok dat.data[:, 0] = 10 dat.data[:, 1] = -10 fig, ax = plot.plot_traces(dat, (0, 2))
def test_plot_specdense(self): # Only checking that these do not throw errors dat = NoInitRadarData(big=True) dat.picks = Picks(dat) dat.picks.samp1 = np.ones((2, len(dat.lat))) dat.picks.samp2 = np.ones((2, len(dat.lat))) dat.picks.samp3 = np.ones((2, len(dat.lat))) fig, ax = plot.plot_specdense(dat, 3.0e-7) plot.plot_specdense(dat, 3.0e-7, fig=fig) plot.plot_specdense(dat, 3.0e-7, fig=fig, ax=ax) plot.plot_specdense(dat, 3.0e-7, window='hamming') plot.plot_specdense(dat, 3.0e-7, scaling='density') # freq too low with self.assertRaises(ValueError): plot.plot_specdense(dat, -100) with self.assertRaises(ValueError): plot.plot_specdense(dat, 3.0e-7, scaling='dummy') with self.assertRaises(ValueError): plot.plot_specdense(dat, 3.0e-7, window='dummy')
def test_Kirchoff_cython(self): data = NoInitRadarData(big=True) data = mig_cython.migrationKirchhoff(data)
def testWriteWithFlags(self): rd = NoInitRadarData() rd.flags = RadarFlags() rd.save(os.path.join(THIS_DIR, 'input_data', 'test_out.mat'))
def test_output_shp_nolayers_nogdal(self): rd = NoInitRadarData() with self.assertRaises(ImportError): rd.output_shp(os.path.join(THIS_DIR, 'input_data', 'test.shp'))
def test_sustolt(self): data = NoInitRadarData(big=True) data.dt = 1.0e-9 data.travel_time = data.travel_time * 1.0e-9 data.fn = os.path.join(THIS_DIR, 'input_data', 'rectangle_sustolt.mat') migrationlib.migrationSeisUnix(data)
def test_PhaseShiftConstant(self): data = NoInitRadarData(big=True) data = migrationlib.migrationPhaseShift(data)
def test_Stolt(self): data = NoInitRadarData(big=True) data = migrationlib.migrationStolt(data)
def test_kinematic_gps_control(self): dats = [NoInitRadarData(big=True)] gpslib.kinematic_gps_control(dats, np.arange(0, 2.0, 0.1), np.arange(40, 60., 1.), np.arange(0., 2000., 100.), np.arange(0., 20., 1.), guess_offset=False) self.assertTrue(np.allclose(np.arange(0, 2.0, 0.1), dats[0].lat)) self.assertTrue(np.allclose(np.arange(40, 60, 1), dats[0].long)) self.assertTrue(np.allclose(np.arange(0, 2000, 100), dats[0].elev)) with self.assertRaises(ValueError): gpslib.kinematic_gps_control(dats, np.arange(0, 2.0, 0.1), np.arange(0, 200, 10), np.arange(0, 2000, 100), np.arange(0, 20, 1), guess_offset=True) dat = NoInitRadarData(big=True) gpslib.kinematic_gps_control(dat, np.arange(0, 2.0, 0.1), np.arange(40, 60, 1), np.arange(0, 2000, 100), np.arange(0, 20, 1), guess_offset=False) self.assertTrue(np.allclose(np.arange(0, 2.0, 0.1), dat.lat)) self.assertTrue(np.allclose(np.arange(40, 60, 1), dat.long)) self.assertTrue(np.allclose(np.arange(0, 2000, 100), dat.elev)) # We should be allowed to be off by 360 in longitude dat = NoInitRadarData(big=True) gpslib.kinematic_gps_control(dat, np.arange(0, 2.0, 0.1), np.arange(40, 60, 1) - 360., np.arange(0, 2000, 100), np.arange(0, 20, 1), guess_offset=False) self.assertTrue(np.allclose(np.arange(0, 2.0, 0.1), dats[0].lat)) self.assertTrue(np.allclose(np.arange(40, 60, 1), dats[0].long)) self.assertTrue(np.allclose(np.arange(0, 2000, 100), dats[0].elev)) # and off the other way dat = NoInitRadarData(big=True) dat.long = dat.long - 360. gpslib.kinematic_gps_control(dat, np.arange(0, 2.0, 0.1), np.arange(40, 60, 1), np.arange(0, 2000, 100), np.arange(0, 20, 1), guess_offset=False) self.assertTrue(np.allclose(np.arange(0, 2.0, 0.1), dats[0].lat)) self.assertTrue(np.allclose(np.arange(40, 60, 1), dats[0].long)) self.assertTrue(np.allclose(np.arange(0, 2000, 100), dats[0].elev)) dat = NoInitRadarData(big=True) gpslib.kinematic_gps_control(dat, np.arange(-1.0, 3.0, 0.1), np.arange(20, 60, 1), np.arange(-1000, 3000, 100), np.arange(-10, 30, 1), guess_offset=True) # Multiple inputs dats = [NoInitRadarData(big=True), NoInitRadarData(big=True)] gpslib.kinematic_gps_control(dats, np.arange(-1.0, 3.0, 0.1), np.arange(40, 80, 1), np.arange(-1000, 3000, 100), np.arange(-10, 30, 1), guess_offset=True) # Bad timing dat = NoInitRadarData(big=True) dat.decday = dat.decday + 10 with self.assertRaises(ValueError): gpslib.kinematic_gps_control(dat, np.arange(0, 2.0, 0.1), np.arange(0, 20, 1), np.arange(0, 2000, 100), np.arange(0, 20, 1))
def test_HfiltRun(self): radardata = NoInitRadarData() radardata.horizontalfilt(0, 100) # We taper in the hfilt, so this is not just zeros self.assertTrue( np.all(radardata.data == radardata.hfilt_target_output))
def test_AdaptiveRun(self): radardata = NoInitRadarData() radardata.adaptivehfilt() # since we subtract average trace and all traces are identical, we should get zeros out self.assertTrue(np.all(radardata.data <= 1.))
def test_process_vbp(self): radardata = NoInitRadarData() process.process([radardata], vbp=(0.1, 100.)) # The filter is not too good, so we have lots of residual self.assertTrue(np.all(np.abs(radardata.data) < 1.0e-4))
def test_process_hfilt(self): radardata = NoInitRadarData() process.process([radardata], hfilt=(0, 100)) # We taper in the hfilt, so this is not just zeros self.assertTrue( np.all(radardata.data == radardata.hfilt_target_output))
def test_process_ahfilt(self): radardata = NoInitRadarData() process.process([radardata], ahfilt=True) # We taper in the hfilt, so this is not just zeros self.assertTrue(np.all(radardata.data <= 1.))
def test_vbp_badftype(self): radardata = NoInitRadarData() with self.assertRaises(ValueError): radardata.vertical_band_pass(0.1, 100., filttype='dummy')
def test_HighPassNotspaced(self): radardata = NoInitRadarData() with self.assertRaises(ImpdarError): # We have a screwed up filter here because of sampling vs. frequency used radardata.highpass(1000.0)
def test_WinAvgExp(self): radardata = NoInitRadarData() radardata.winavg_hfilt(11, taper='full') self.assertTrue( np.all(radardata.data == radardata.hfilt_target_output))
def test_SaveFails(self): print(SEGY) data = NoInitRadarData() with self.assertRaises(ImportError): data.save_as_segy(os.path.join(THIS_DIR, 'input_data', 'shots0001_0200_resave.segy'))
def test_WinAvgExpBadwinavg(self): # Tests the check on whether win_avg < tnum radardata = NoInitRadarData() radardata.winavg_hfilt(data_dummy.shape[1] + 10, taper='full') self.assertTrue( np.all(radardata.data == radardata.hfilt_target_output))
def test_Kirchhoff(self): data = NoInitRadarData(big=True) data = migrationlib.migrationKirchhoff(data)
def test_WinAvgPexp(self): radardata = NoInitRadarData() radardata.winavg_hfilt(11, taper='pexp', filtdepth=-1) self.assertTrue(np.all(radardata.data == radardata.pexp_target_output))
def test_PhaseShiftLateral(self): data = NoInitRadarData(big=True) data = migrationlib.migrationPhaseShift(data, vel_fn=os.path.join( THIS_DIR, 'input_data', 'velocity_lateral.txt'))
def test_WinAvgbadtaper(self): radardata = NoInitRadarData() with self.assertRaises(ValueError): radardata.winavg_hfilt(11, taper='not_a_taper', filtdepth=-1)
def test_output_shp_nolayers(self): rd = NoInitRadarData() rd.output_shp(os.path.join(THIS_DIR, 'input_data', 'test.shp'))
def test_vbp_butter(self): radardata = NoInitRadarData() radardata.vertical_band_pass(0.1, 100., filttype='butter') # The filter is not too good, so we have lots of residual self.assertTrue(np.all(np.abs(radardata.data) < 1.0e-4))
def test_WriteNoFLags(self): rd = NoInitRadarData() rd.save(os.path.join(THIS_DIR, 'input_data', 'test_out.mat')) os.remove(os.path.join(THIS_DIR, 'input_data', 'test_out.mat'))
def test_plot_picks(self, mock_show): # Only checking that these do not throw errors dat = NoInitRadarData(big=True) fig, ax = plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time) dat.picks = Picks(dat) dat.picks.picknums = [2, 10] dat.picks.samp1 = np.ones((2, len(dat.lat))) dat.picks.samp2 = np.ones((2, len(dat.lat))) dat.picks.samp3 = np.ones((2, len(dat.lat))) fig, ax = plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, fig=fig) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, fig=fig, ax=ax) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, colors='g', fig=fig, ax=ax) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, colors='gmm', fig=fig, ax=ax) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, colors=['c', 'g'], fig=fig, ax=ax) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, colors=['cmy', 'brb'], fig=fig, ax=ax) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, colors=['cm', 'br'], fig=fig, ax=ax) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, colors=True, fig=fig, ax=ax) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, colors=False, fig=fig, ax=ax) plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, colors=['c', 'm', 'b'], just_middle=False, fig=fig, ax=ax) with self.assertRaises(ValueError): plot.plot_picks(dat, np.arange(int(dat.tnum)), dat.travel_time, colors=['c', 'm', 'b'], just_middle=True, fig=fig, ax=ax)
def test_WriteRead(self): # We are going to create a really bad file (most info missing) and see if we recover it or get an error rd = NoInitRadarData() rd.save(os.path.join(THIS_DIR, 'input_data', 'test_out.mat')) RadarData(os.path.join(THIS_DIR, 'input_data', 'test_out.mat'))
def test_TimeWavenumber(self): data = NoInitRadarData(big=True) data = mig_python.migrationTimeWavenumber(data)