예제 #1
0
    def test_plot_spectrogram(self, mock_show):
        # 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_spectrogram(dat, (0., 5.0))
        plot.plot_spectrogram(dat, (0., 5.0), fig=fig)
        plot.plot_spectrogram(dat, (0., 5.0), fig=fig, ax=ax)
        plot.plot_spectrogram(dat, (0., 5.0), window='hamming')
        plot.plot_spectrogram(dat, (0., 5.0), scaling='density')

        # no error if freq high
        plot.plot_spectrogram(dat, 100)

        # freq too low
        with self.assertRaises(ValueError):
            plot.plot_spectrogram(dat, (0., -100))

        with self.assertRaises(ValueError):
            plot.plot_spectrogram(dat, (0., 5), scaling='dummy')

        with self.assertRaises(ValueError):
            plot.plot_spectrogram(dat, (0., 5), window='dummy')
예제 #2
0
    def test_plot_radargram_flattenlayer(self, mock_show):
        dat = NoInitRadarData(big=True)
        dat.picks = Picks(dat)
        dat.picks.add_pick(10)
        dat.picks.power[:] = 10
        dat.picks.samp1[:] = 0
        dat.picks.samp2[:] = 1  # make sure no bugs if this is actually constant
        dat.picks.samp3[:] = 3
        # works with constant power
        fig, ax = plot.plot_radargram(dat, flatten_layer=10)

        # make sure we can actually follow a variable layer
        dat.picks.samp2[:, 1:] = 2
        dat.picks.samp2[:, -1] = 4
        # works with constant power
        fig, ax = plot.plot_radargram(dat, flatten_layer=10)

        dat.picks.samp2[:] = 0  # make sure no bugs if this is at the top
        fig, ax = plot.plot_radargram(dat, flatten_layer=10)

        dat.picks.samp2[:] = dat.data.shape[
            0] - 1  # make sure no bugs if this is at the bottom
        fig, ax = plot.plot_radargram(dat, flatten_layer=10)

        dat.picks.samp2[:,
                        1] = np.NaN  # make sure no bugs if this is at the bottom
        fig, ax = plot.plot_radargram(dat, flatten_layer=10)

        with self.assertRaises(ValueError):
            fig, ax = plot.plot_radargram(dat, flatten_layer=1)
예제 #3
0
    def test_plot_power(self, mock_show):
        # Only checking that these do not throw errors
        dat = NoInitRadarData(big=True)
        with self.assertRaises(TypeError):
            plot.plot_power(dat, [12, 14])
        with self.assertRaises(ValueError):
            plot.plot_power(dat, 0)

        dat.picks = Picks(dat)
        dat.picks.add_pick(10)
        dat.picks.power[:] = 10.5
        # works with constant power
        fig, ax = plot.plot_power(dat, 10)

        # works with various inputs
        fig, ax = plt.subplots()
        plot.plot_power(dat, 10, fig=fig)
        plot.plot_power(dat, 10, fig=fig, ax=ax)
        plot.plot_power(dat, 10, clims=(-100, 100), fig=fig, ax=ax)

        # works with multiple inputs
        plot.plot_power([dat, dat], 10, fig=fig, ax=ax)

        # works with projected coordinates
        dat.x_coord = np.arange(dat.data.shape[1])
        dat.y_coord = np.arange(dat.data.shape[1])
        plot.plot_power(dat, 10, fig=fig, ax=ax)
        plot.plot_power([dat, dat], 10, fig=fig, ax=ax)

        with self.assertRaises(ValueError):
            plot.plot_power(dat, 0, fig=fig, ax=ax)

        # gets ok lims with variable power?
        dat.picks.power[:, 0] = 1
        plot.plot_power(dat, 10, fig=fig, ax=ax)
예제 #4
0
 def test_failure_3(self):
     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)))
     with self.assertRaises(AttributeError):
         plot.plot_specdense(dat, 'bad')
예제 #5
0
 def test_plot_picks_via_radargram(self, mock_show):
     """We want to be able to call this via plot_radargram"""
     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)))
     dat.picks.picknums = [0, 9]
     plot.plot_radargram(dat, pick_colors='mgm')
예제 #6
0
    def test_constant_space_real(self):
        # Basic check where there is movement every step
        distlims = (self.data.dist[0], self.data.dist[-1])
        space = 100.
        targ_size = np.ceil((distlims[-1] - distlims[0]) * 1000. / space)
        self.data.constant_space(space)
        self.assertTrue(self.data.data.shape == (20, targ_size))
        self.assertTrue(self.data.x_coord.shape == (targ_size, ))
        self.assertTrue(self.data.y_coord.shape == (targ_size, ))
        self.assertTrue(self.data.lat.shape == (targ_size, ))
        self.assertTrue(self.data.long.shape == (targ_size, ))
        self.assertTrue(self.data.elev.shape == (targ_size, ))
        self.assertTrue(self.data.decday.shape == (targ_size, ))

        # Make sure we can have some bad values from no movement
        # This will delete some distance so, be careful with checks
        self.setUp()
        self.data.constant_space(space, min_movement=35.)
        self.assertEqual(self.data.data.shape[0], 20)
        self.assertLessEqual(self.data.data.shape[1], targ_size)
        self.assertLessEqual(self.data.x_coord.shape[0], targ_size)
        self.assertLessEqual(self.data.y_coord.shape[0], targ_size)
        self.assertLessEqual(self.data.lat.shape[0], targ_size)
        self.assertLessEqual(self.data.long.shape[0], targ_size)
        self.assertLessEqual(self.data.elev.shape[0], targ_size)
        self.assertLessEqual(self.data.decday.shape[0], targ_size)

        # do not fail because flags structure is weird from matlab
        self.setUp()
        self.data.flags.interp = False
        self.data.constant_space(space)
        self.assertTrue(self.data.flags.interp.shape == (2, ))
        self.assertTrue(self.data.flags.interp[0])
        self.assertEqual(self.data.flags.interp[1], space)

        # Want to be able to do picks too
        self.setUp()
        self.data.pick = Picks(self.data)
        self.data.picks.samp1 = np.ones((2, self.data.tnum))
        self.data.picks.samp2 = np.ones((2, self.data.tnum))
        self.data.picks.samp3 = np.ones((2, self.data.tnum))
        self.data.picks.power = np.ones((2, self.data.tnum))
        self.data.picks.time = np.ones((2, self.data.tnum))
        self.data.constant_space(space)
        self.assertTrue(self.data.data.shape == (20, targ_size))
        self.assertTrue(self.data.x_coord.shape == (targ_size, ))
        self.assertTrue(self.data.y_coord.shape == (targ_size, ))
        self.assertTrue(self.data.lat.shape == (targ_size, ))
        self.assertTrue(self.data.long.shape == (targ_size, ))
        self.assertTrue(self.data.elev.shape == (targ_size, ))
        self.assertTrue(self.data.decday.shape == (targ_size, ))
        self.assertTrue(self.data.picks.samp1.shape == (2, targ_size))
        self.assertTrue(self.data.picks.samp2.shape == (2, targ_size))
        self.assertTrue(self.data.picks.samp3.shape == (2, targ_size))
        self.assertTrue(self.data.picks.power.shape == (2, targ_size))
        self.assertTrue(self.data.picks.time.shape == (2, targ_size))
예제 #7
0
 def testWriteWithPicksFull(self):
     rd = NoInitRadarData()
     rd.picks = Picks(rd)
     rd.picks.add_pick()
     rd.save(os.path.join(THIS_DIR, 'input_data', 'test_out.mat'))
     data = RadarData(os.path.join(THIS_DIR, 'input_data', 'test_out.mat'))
     self.assertTrue(data.picks is not None)
     self.assertTrue(data.picks.lasttrace is not None)
     self.assertTrue(data.picks.samp1 is not None)
     self.assertTrue(data.picks.samp2 is not None)
     self.assertTrue(data.picks.samp3 is not None)
예제 #8
0
    def test_output_csv(self):
        # Make sure that we are selecting the proper output format
        rd = NoInitRadarData()
        rd.nmo_depth = np.arange(len(rd.travel_time)) * 1.1
        rd.elev = np.arange(rd.tnum) * 1001
        rd.picks = Picks(rd)
        rd.picks.add_pick()

        # First, export with NaNs
        rd.picks.samp2[:] = np.nan
        rd.output_csv(os.path.join(THIS_DIR, 'input_data', 'test.csv'))
        with open(os.path.join(THIS_DIR, 'input_data', 'test.csv')) as fin:
            lines = fin.readlines()
            # we should have four entries: lat, lon, trace, and the one pick in header and data
            self.assertEqual(len(lines[0].split(',')), 4)
            self.assertEqual(len(lines[1].split(',')), 4)

            # we should have a row per trace, plus a header
            self.assertEqual(len(lines), rd.tnum + 1)

            # The final header should be in terms of depth
            self.assertTrue(lines[0].index('depth') > 0)

        # Fill in NaNs
        rd.picks.samp2[:] = 1
        rd.output_csv(os.path.join(THIS_DIR, 'input_data', 'test.csv'))
        with open(os.path.join(THIS_DIR, 'input_data', 'test.csv')) as fin:
            lines = fin.readlines()
            # we should have four entries: lat, lon, trace, and the one pick in header and data
            self.assertEqual(len(lines[0].split(',')), 4)
            self.assertEqual(len(lines[1].split(',')), 4)

            # we should have a row per trace, plus a header
            self.assertEqual(len(lines), rd.tnum + 1)

            # The final header should be in terms of depth
            self.assertTrue(lines[0].index('depth') > 0)

        # Check output target for elevation, which is the only weird one
        rd.output_csv(os.path.join(THIS_DIR, 'input_data', 'test.csv'),
                      target_out='elev')
        with open(os.path.join(THIS_DIR, 'input_data', 'test.csv')) as fin:
            lines = fin.readlines()
            # we should have four entries: lat, lon, trace, and the one pick in header and data
            self.assertEqual(len(lines[0].split(',')), 4)
            self.assertEqual(len(lines[1].split(',')), 4)

            # we should have a row per trace, plus a header
            self.assertEqual(len(lines), rd.tnum + 1)

            # The final header should be in terms of elev
            self.assertTrue(lines[0].index('elev') > 0)
예제 #9
0
    def test_plot_power(self):
        # Only checking that these do not throw errors
        dat = NoInitRadarData(big=True)
        with self.assertRaises(TypeError):
            fig, ax = plot.plot_power(dat, [12, 14])
        with self.assertRaises(ValueError):
            fig, ax = plot.plot_power(dat, 0)

        dat.picks = Picks(dat)
        dat.picks.add_pick(10)
        dat.picks.power[:] = 10
        # works with constant power
        fig, ax = plot.plot_power(dat, 10)

        with self.assertRaises(ValueError):
            fig, ax = plot.plot_power(dat, 0)

        # gets ok lims with variable power?
        dat.picks.power[:, 0] = 1
        fig, ax = plot.plot_power(dat, 10)
예제 #10
0
    def test_output_shp_picks(self):
        # Make sure that we are selecting the proper output format
        rd = NoInitRadarData()
        rd.nmo_depth = np.arange(len(rd.travel_time)) * 1.1
        rd.elev = np.arange(rd.tnum) * 1001
        rd.picks = Picks(rd)
        rd.picks.add_pick()

        # First, export with NaNs, both with normal field (depth) and elev
        rd.picks.samp2[:] = np.nan
        rd.output_shp(os.path.join(THIS_DIR, 'input_data', 'test0.shp'))
        rd.output_shp(os.path.join(THIS_DIR, 'input_data', 'test1.shp'), target_out='elev')

        # Fill in NaNs
        rd.picks.samp2[:] = 1
        rd.output_shp(os.path.join(THIS_DIR, 'input_data', 'test2.shp'))
        rd.output_shp(os.path.join(THIS_DIR, 'input_data', 'test3.shp'), target_out='elev')

        # Check geometry
        rd.output_shp(os.path.join(THIS_DIR, 'input_data', 'test4.shp'), t_srs=3413)
예제 #11
0
    def test_plot_picks(self):
        # 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.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)
        fig, ax = plot.plot_picks(dat,
                                  np.arange(int(dat.tnum)),
                                  dat.travel_time,
                                  colors='g')
        fig, ax = plot.plot_picks(dat,
                                  np.arange(int(dat.tnum)),
                                  dat.travel_time,
                                  colors='gmm')
        fig, ax = plot.plot_picks(dat,
                                  np.arange(int(dat.tnum)),
                                  dat.travel_time,
                                  colors=['c', 'g'])
        fig, ax = plot.plot_picks(dat,
                                  np.arange(int(dat.tnum)),
                                  dat.travel_time,
                                  colors=['cmy', 'brb'])
        fig, ax = plot.plot_picks(dat,
                                  np.arange(int(dat.tnum)),
                                  dat.travel_time,
                                  colors=['cm', 'br'])
        with self.assertRaises(ValueError):
            fig, ax = plot.plot_picks(dat,
                                      np.arange(int(dat.tnum)),
                                      dat.travel_time,
                                      colors=['c', 'm', 'b'])
예제 #12
0
    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')
예제 #13
0
    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)