Ejemplo n.º 1
0
    def test_svcorrect_module(self):
        dset = load_dataset(RealFqpr())
        multibeam = dset.raw_ping[0].isel(time=0).expand_dims('time')
        cast = json.loads(multibeam.profile_1495599960)
        beam_azimuth = xr.DataArray(data=expected_beam_azimuth,
                                    dims=['time', 'beam'],
                                    coords={
                                        'time': multibeam.time.values,
                                        'beam': multibeam.beam.values
                                    })
        beam_angle = xr.DataArray(data=expected_corrected_beam_angles,
                                  dims=['time', 'beam'],
                                  coords={
                                      'time': multibeam.time.values,
                                      'beam': multibeam.beam.values
                                  })
        traveltime = multibeam.traveltime
        surface_ss = multibeam.soundspeed

        installation_params_time = list(dset.xyzrph['tx_r'].keys())[0]
        waterline = float(dset.xyzrph['waterline'][installation_params_time])
        additional_offsets = np.array([[0], [0], [0]])

        alongtrack, acrosstrack, depth = run_ray_trace_v2(
            cast, beam_azimuth, beam_angle, traveltime, surface_ss, waterline,
            additional_offsets)
        assert np.array_equal(alongtrack, expected_alongtrack)
        assert np.array_equal(acrosstrack, expected_acrosstrack)
        assert np.array_equal(depth, expected_depth)
    def test_orientation_module(self):
        dset = load_dataset(RealFqpr())
        raw_attitude = dset.raw_att
        # expand_dims required to maintain the time dimension metadata when you select only one value
        multibeam = dset.raw_ping[0].isel(time=0).expand_dims('time')
        traveltime = multibeam.traveltime
        delay = multibeam.delay
        timestamps = multibeam.time

        installation_params_time = list(dset.xyzrph['tx_r'].keys())[0]
        tx_orientation = [
            np.array(
                [1, 0,
                 0]),  # starting vector for the tx transducer (points forward)
            dset.xyzrph['tx_r']
            [installation_params_time],  # roll mounting angle for tx
            dset.xyzrph['tx_p']
            [installation_params_time],  # pitch mounting angle for tx
            dset.xyzrph['tx_h']
            [installation_params_time],  # yaw mounting angle for tx
            installation_params_time
        ]  # time stamp for the installation parameters record
        rx_orientation = [
            np.array([0, 1, 0]),  # same but for the receiver
            dset.xyzrph['rx_r'][installation_params_time],
            dset.xyzrph['rx_p'][installation_params_time],
            dset.xyzrph['rx_h'][installation_params_time],
            installation_params_time
        ]
        latency = 0  # no latency applied for this test

        calc_tx_vector, calc_rx_vector = build_orientation_vectors(
            raw_attitude, traveltime, delay, timestamps, tx_orientation,
            rx_orientation, latency)

        try:
            assert np.array_equal(calc_tx_vector.values, expected_tx_vector)
        except AssertionError:
            print(
                'Falling back to approx, should only be seen in TravisCI environment in my experience'
            )
            # use approx here, I get ever so slightly different answers in the Travis CI environment
            assert calc_tx_vector.values == pytest.approx(
                expected_tx_vector, 0.000001)
        try:
            assert np.array_equal(calc_rx_vector.values, expected_rx_vector)
        except AssertionError:
            print(
                'Falling back to approx, should only be seen in TravisCI environment in my experience'
            )
            # use approx here, I get ever so slightly different answers in the Travis CI environment
            assert calc_rx_vector.values == pytest.approx(
                expected_rx_vector, 0.000001)
    def test_beampointingvector_module(self):
        dset = load_dataset(RealFqpr())
        raw_attitude = dset.raw_att
        heading = raw_attitude.heading

        multibeam = dset.raw_ping[0].isel(time=0).expand_dims('time')
        beampointingangle = multibeam.beampointingangle
        tiltangle = multibeam.tiltangle
        ping_time_heading = heading.interp_like(beampointingangle)

        tx_vecs = xr.DataArray(data=expected_tx_vector,
                               dims=['time', 'beam', 'xyz'],
                               coords={
                                   'time': multibeam.time.values,
                                   'beam': multibeam.beam.values,
                                   'xyz': ['x', 'y', 'z']
                               })
        rx_vecs = xr.DataArray(data=expected_rx_vector,
                               dims=['time', 'beam', 'xyz'],
                               coords={
                                   'time': multibeam.time.values,
                                   'beam': multibeam.beam.values,
                                   'xyz': ['x', 'y', 'z']
                               })

        tx_reversed = False
        rx_reversed = False

        beam_azimuth, corrected_beam_angle = build_beam_pointing_vectors(
            ping_time_heading, beampointingangle, tiltangle, tx_vecs, rx_vecs,
            tx_reversed, rx_reversed)

        try:
            assert np.array_equal(beam_azimuth.values, expected_beam_azimuth)
        except AssertionError:
            print(
                'Falling back to approx, should only be seen in TravisCI environment in my experience'
            )
            # use approx here, I get ever so slightly different answers in the Travis CI environment
            assert beam_azimuth.values == pytest.approx(
                expected_beam_azimuth, 0.000001)
        try:
            assert np.array_equal(corrected_beam_angle.values,
                                  expected_corrected_beam_angles)
        except AssertionError:
            print(
                'Falling back to approx, should only be seen in TravisCI environment in my experience'
            )
            # use approx here, I get ever so slightly different answers in the Travis CI environment
            assert corrected_beam_angle.values == pytest.approx(
                expected_corrected_beam_angles, 0.000001)
Ejemplo n.º 4
0
    def test_tpu(self):
        dset = load_dataset(RealFqpr())
        multibeam = dset.raw_ping[0].isel(time=0).expand_dims('time')
        qf = multibeam.qualityfactor
        tpu = dset.return_tpu_parameters(
            list(dset.xyzrph['waterline'].keys())[0])

        surface_ss = multibeam.soundspeed
        beampointingangle = multibeam.beampointingangle
        corr_beam_angle = xr.DataArray(data=expected_corrected_beam_angles,
                                       dims=['time', 'beam'],
                                       coords={
                                           'time': multibeam.time.values,
                                           'beam': multibeam.beam.values
                                       })
        x = xr.DataArray(data=expected_alongtrack,
                         dims=['time', 'beam'],
                         coords={
                             'time': multibeam.time.values,
                             'beam': multibeam.beam.values
                         })
        z = xr.DataArray(data=expected_depth,
                         dims=['time', 'beam'],
                         coords={
                             'time': multibeam.time.values,
                             'beam': multibeam.beam.values
                         })

        raw_attitude = dset.raw_att
        roll = raw_attitude['roll'].interp_like(beampointingangle)

        tvu, thu = calculate_tpu(roll,
                                 beampointingangle,
                                 corr_beam_angle,
                                 x,
                                 z,
                                 surface_ss,
                                 tpu_dict=tpu,
                                 quality_factor=qf,
                                 vert_ref='waterline')
        assert np.array_equal(thu, expected_thu)
        assert np.array_equal(tvu, expected_tvu)
    def test_interp_across_chunks(self):
        synth = load_dataset(RealFqpr(), skip_dask=False)
        # 11 attitude values, chunking by 4 gives us three chunks
        # att.chunks
        # Out[10]: Frozen(SortedKeysDict({'time': (4, 4, 3)}))
        att = synth.raw_att.chunk(4)
        times_interp_to = xr.DataArray(
            np.array([1495563084.455, 1495563084.490, 1495563084.975]),
            dims={'time'},
            coords={
                'time':
                np.array([1495563084.455, 1495563084.490, 1495563084.975])
            })
        dask_interp_att = interp_across_chunks(att,
                                               times_interp_to,
                                               dimname='time',
                                               daskclient=synth.client)
        interp_att = interp_across_chunks(att, times_interp_to, dimname='time')

        expected_att = xr.Dataset(
            {
                'heading':
                (['time'],
                 np.array([
                     307.8539977551496, 307.90348427192055, 308.6139892100822
                 ])),
                'heave': (['time'],
                          np.array([
                              0.009999999776482582, 0.009608692733222632,
                              -0.009999999776482582
                          ])),
                'roll': (['time'],
                         np.array([
                             0.4400004684929343, 0.07410809820512047,
                             -4.433999538421631
                         ])),
                'pitch':
                (['time'],
                 np.array([-0.5, -0.5178477924436871, -0.3760000467300415]))
            },
            coords={
                'time':
                np.array([1495563084.455, 1495563084.49, 1495563084.975])
            })

        # make sure the dask/non-dask methods line up
        assert dask_interp_att.time.values == approx(interp_att.time.values,
                                                     0.001)
        assert dask_interp_att.heading.values == approx(
            interp_att.heading.values, 0.001)
        assert dask_interp_att.heave.values == approx(interp_att.heave.values,
                                                      0.001)
        assert dask_interp_att.pitch.values == approx(interp_att.pitch.values,
                                                      0.001)
        assert dask_interp_att['roll'].values == approx(
            interp_att['roll'].values, 0.001)

        # make sure the values line up with what we would expect
        assert dask_interp_att.time.values == approx(expected_att.time.values,
                                                     0.001)
        assert dask_interp_att.heading.values == approx(
            expected_att.heading.values, 0.001)
        assert dask_interp_att.heave.values == approx(
            expected_att.heave.values, 0.001)
        assert dask_interp_att.pitch.values == approx(
            expected_att.pitch.values, 0.001)
        assert dask_interp_att['roll'].values == approx(
            expected_att['roll'].values, 0.001)

        print('Passed: interp_across_chunks')
Ejemplo n.º 6
0
 def setUpClass(cls) -> None:
     cls.dset = load_dataset(RealFqpr())