def test_magnetic_correction(self):
        """
        Test magentic_correction function.

        Input values based on those defined in DPS; output values calculated to
            more significant figures using matlab code specified in the DPS.

        OOI (2012). Data Product Specification for Velocity Profile and Echo
            Intensity. Document Control Number 1341-00750.
            https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
            >> Controlled >> 1000 System Level >>
            1341-00750_Data_Product_SPEC_VELPROF_OOI.pdf)

        Implemented by Christopher Wingard, April 2013
        Modified by Russell Desiderio, April 07, 2014. Changed the rtol values
            from 1e4 to 1e-4 to get a fair test. Changed the output values by
            adding more significant figures.
        """
        # apply the magnetic declination correction.
        uu_cor, vv_cor = gfunc.magnetic_correction(16.9604, np.array([0.4413]),
                                                   np.array([0.1719]))

        # test the transform
        self.assertTrue(np.allclose(uu_cor, 0.472251, rtol=1e-4, atol=0))
        self.assertTrue(np.allclose(vv_cor, 0.035692, rtol=1e-4, atol=0))
def adcp_earth_northward(u, v, z, lat, lon, dt):
    """
    Wrapper function to compute the Northward Velocity Profile (VELPROF-VLN)
    from the Earth coordinate transformed data.
    """
    # force shapes of inputs to arrays of the correct dimensions
    u = np.atleast_2d(u)
    v = np.atleast_2d(v)
    z = np.atleast_1d(z) / 10.  # scale decimeter depth input to meters
    lat = np.atleast_1d(lat)
    lon = np.atleast_1d(lon)
    dt = np.atleast_1d(dt)

    # calculate the magnetic declination using the WWM2010 model
    theta = magnetic_declination(lat, lon, dt, z)

    # iterate through arrays for processing multiple records
    vv_cor = np.empty(u.shape)
    for indx in range(u.shape[0]):
        # apply the magnetic variation correction
        ucor, vv_cor[indx, :] = magnetic_correction(theta[indx], u[indx, :], v[indx, :])

    # scale northward velocity to m/s
    vv_cor = vv_cor / 1000.  # mm/s -> m/s

    # return the Northward Velocity Profile
    return vv_cor
Exemple #3
0
    def test_magnetic_correction(self):
        """
        Test magentic_correction function.

        Input values based on those defined in DPS; output values calculated to
            more significant figures using matlab code specified in the DPS.

        OOI (2012). Data Product Specification for Velocity Profile and Echo
            Intensity. Document Control Number 1341-00750.
            https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
            >> Controlled >> 1000 System Level >>
            1341-00750_Data_Product_SPEC_VELPROF_OOI.pdf)

        Implemented by Christopher Wingard, April 2013
        Modified by Russell Desiderio, April 07, 2014. Changed the rtol values
            from 1e4 to 1e-4 to get a fair test. Changed the output values by
            adding more significant figures.
        """
        # apply the magnetic declination correction.
        uu_cor, vv_cor = gfunc.magnetic_correction(16.9604, np.array([0.4413]),
                                                   np.array([0.1719]))

        # test the transform
        self.assertTrue(np.allclose(uu_cor, 0.472251, rtol=1e-4, atol=0))
        self.assertTrue(np.allclose(vv_cor, 0.035692, rtol=1e-4, atol=0))
    def test_magnetic_correction(self):
        """
        Test magentic_correction function.

        Values based on those defined in DPS:

        OOI (2012). Data Product Specification for Velocity Profile and Echo
            Intensity. Document Control Number 1341-00750.
            https://alfresco.oceanobservatories.org/ (See: Company Home >> OOI
            >> Controlled >> 1000 System Level >>
            1341-00750_Data_Product_SPEC_VELPROF_OOI.pdf)

        Implemented by Christopher Wingard, April 2013
        """
        # apply the magnetic declination correction.
        uu_cor, vv_cor = gfunc.magnetic_correction(16.9604, np.array([0.4413]),
                                                   np.array([0.1719]))

        # test the transform
        self.assertTrue(np.allclose(uu_cor, 0.4722, rtol=1e4, atol=0))
        self.assertTrue(np.allclose(vv_cor, 0.0357, rtol=1e4, atol=0))
def adcp_beam_northward(b1, b2, b3, b4, h, p, r, vf, lat, lon, z, dt):
    """
    Description:

        Wrapper function to compute the Eastward Velocity Profile (VELPROF-VLN)
        from beam coordinate transformed velocity profiles as defined in the
        Data Product Specification for Velocity Profile and Echo Intensity -
        DCN 1341-00750.

    Implemented by:

        2013-04-10: Christopher Wingard. Initial code.
        2014-02-03: Christopher Wingard. Formatting and adjusting to use
                    magnetic declination values calulated use the WMM 2010.

    Usage:

        uu_cor = adcp_beam_eastward(b1, b2, b3, b4, h, p, r, vf, lat, lon, z, dt)

            where

        uu_corr = east velocity profiles in Earth coordinates corrected for the
                  magnetic declination (VELPROF-VLE_L1) [mm s-1]

        b1 = "beam 1" velocity profiles in beam coordinates (VELPROF-B1_L0) [mm s-1]
        b2 = "beam 2" velocity profiles in beam coordinates (VELPROF-B2_L0) [mm s-1]
        b3 = "beam 3" velocity profiles in beam coordinates (VELPROF-B3_L0) [mm s-1]
        b4 = "beam 4" velocity profiles in beam coordinates (VELPROF-B4_L0) [mm s-1]
        h = instrument's uncorrected magnetic heading [degrees]
        p = instrument pitch [degrees]
        r = instrument roll [degrees]
        vf = instrument's vertical orientation (0 = downward looking and
            1 = upward looking)
        lat = instrument's deployment latitude [decimal degrees]
        lon = instrument's deployment longitude [decimal degrees]
        z = instrument's pressure sensor reading (depth) [dm]
        dt = sample date and time value [seconds since 1900-01-01]
    """
    # force shapes of inputs to arrays of the correct dimensions
    b1 = np.atleast_2d(b1)
    b2 = np.atleast_2d(b2)
    b3 = np.atleast_2d(b3)
    b4 = np.atleast_2d(b4)
    h = np.atleast_1d(h)
    p = np.atleast_1d(p)
    r = np.atleast_1d(r)
    vf = np.atleast_1d(vf)
    z = np.atleast_1d(z) / 10.  # scale decimeter depth input to meters
    lat = np.atleast_1d(lat)
    lon = np.atleast_1d(lon)
    dt = np.atleast_1d(dt)

    # compute the beam to instrument transform
    u, v, w, e = adcp_beam2ins(b1, b2, b3, b4)

    # calculate the magnetic declination using the WWM2010 model
    theta = magnetic_declination(lat, lon, dt, z)

    # iterate through arrays for processing multiple records
    vv_cor = np.empty((b1.shape))
    for indx in range(b1.shape[0]):
        # compute the instrument to earth beam transform
        uu, vv, ww = adcp_ins2earth(u[indx, :], v[indx, :], w[indx, :],
                                    h[indx], p[indx], r[indx], vf[indx])

        # apply the magnetic variation correction
        ucor, vv_cor[indx, :] = magnetic_correction(theta[indx], uu, vv)

    # scale northward velocity to m/s
    vv_cor = vv_cor / 1000.  # mm/s -> m/s

    # return the Northward Velocity Profile
    return vv_cor