def test_datasets(self):
        # this routine tests:
        #     dataset input into setup
        #     the function fdc_quantize_data
        #     the flux calculations of function fdc_flux_and_wind

        # expected values were calculated using matlab test code for a cutoff frequency
        # of 1/12.0
        # the first row are the uw, vw, wT flux values for the 1st dataset, etc.
        xpctd_fluxes = np.array([[-0.350371566926, 0.115496951668, -0.008274161328],
                                 [-0.410571629711, 0.092164914869, -0.006687641111],
                                 [-0.080418722438, -0.001432879153, -0.004455583513]])

        # the agreement is good for datasets 1 and 2, not so good for 3 because when
        # goodcompass calculates to 1 (True), filtfilt is executed with the ahi2 and
        # bhi2 filter coeffs, the matlab v. scipy results of which barely agree (the
        # calculation is not robust).
        reltol = np.array([1.e-9, 1.e-9, 0.0, 0.0])
        abstol = np.array([0.0, 0.0, 1.e-5, 1.e-5])

        ### NOTE that the variables parsed out from 'array' are not column vectors;
        ### they are python 1D arrays which is what these DPAs expect from CI.
        for ii in range(4):
            array = np.copy(self.Ldata[ii])
            timestamps = array[:, 0]
            windX = array[:, 1]
            windY = array[:, 2]
            windZ = array[:, 3]
            sound = array[:, 4]    # (temperature proxy)
            rateX = array[:, 5]
            rateY = array[:, 6]
            rateZ = array[:, 7]
            accelX = array[:, 8]
            accelY = array[:, 9]
            accelZ = array[:, 10]
            roll = array[:, 11]    # (not used by DPA)
            pitch = array[:, 12]   # (not used by DPA)
            heading = array[:, 13]
            lat = array[:, 14]

            if ii < 3:  # single datasets
                calc_fluxes, _ = fd.fdc_flux_and_wind(timestamps,
                                                      windX, windY, windZ,
                                                      sound, heading,
                                                      rateX, rateY, rateZ,
                                                      accelX, accelY, accelZ, lat)
                calc_fluxes = np.asarray(calc_fluxes).flatten()
                np.testing.assert_allclose(calc_fluxes, xpctd_fluxes[ii, :],
                                           rtol=reltol[ii], atol=abstol[ii])

            if ii == 3:  # multiple
                calc_fluxes, _ = fd.fdc_flux_and_wind(timestamps,
                                                      windX, windY, windZ,
                                                      sound, heading,
                                                      rateX, rateY, rateZ,
                                                      accelX, accelY, accelZ, lat)
                calc_fluxes = np.asarray(calc_fluxes).transpose()
                np.testing.assert_allclose(calc_fluxes, xpctd_fluxes,
                                           rtol=reltol[ii], atol=abstol[ii])
    def test_extrapolation_fault(self):
        # this routine tests whether nans are output for the flux products, as occurs when
        # running the matlab test code, when the interpolation routine in the despikesimple
        # function encounters an extrapolation case. the original python coding was changed
        # to accommodate this behavior to avoid a series of runtime execution errors.
        for ii in (5, 8):
            array = np.copy(self.Ldata[0])
            array[0, ii] = 99999.9
            timestamps = array[:, 0]
            windX = array[:, 1]
            windY = array[:, 2]
            windZ = array[:, 3]
            sound = array[:, 4]  # (temperature proxy)
            rateX = array[:, 5]
            rateY = array[:, 6]
            rateZ = array[:, 7]
            accelX = array[:, 8]
            accelY = array[:, 9]
            accelZ = array[:, 10]
            roll = array[:, 11]  # (not used by DPA)
            pitch = array[:, 12]  # (not used by DPA)
            heading = array[:, 13]
            lat = array[:, 14]

            calc_fluxes, _ = fd.fdc_flux_and_wind(timestamps, windX, windY,
                                                  windZ, sound, heading, rateX,
                                                  rateY, rateZ, accelX, accelY,
                                                  accelZ, lat)
            calc_fluxes = np.asarray(calc_fluxes).flatten()
            np.testing.assert_allclose(calc_fluxes,
                                       np.array([np.nan, np.nan, np.nan]))
    def test_extrapolation_fault(self):
        # this routine tests whether nans are output for the flux products, as occurs when
        # running the matlab test code, when the interpolation routine in the despikesimple
        # function encounters an extrapolation case. the original python coding was changed
        # to accommodate this behavior to avoid a series of runtime execution errors.
        for ii in (5, 8):
            array = np.copy(self.Ldata[0])
            array[0, ii] = 99999.9
            timestamps = array[:, 0]
            windX = array[:, 1]
            windY = array[:, 2]
            windZ = array[:, 3]
            sound = array[:, 4]    # (temperature proxy)
            rateX = array[:, 5]
            rateY = array[:, 6]
            rateZ = array[:, 7]
            accelX = array[:, 8]
            accelY = array[:, 9]
            accelZ = array[:, 10]
            roll = array[:, 11]    # (not used by DPA)
            pitch = array[:, 12]   # (not used by DPA)
            heading = array[:, 13]
            lat = array[:, 14]

            calc_fluxes, _ = fd.fdc_flux_and_wind(timestamps,
                                                  windX, windY, windZ,
                                                  sound, heading,
                                                  rateX, rateY, rateZ,
                                                  accelX, accelY, accelZ, lat)
            calc_fluxes = np.asarray(calc_fluxes).flatten()
            np.testing.assert_allclose(calc_fluxes, np.array([np.nan, np.nan, np.nan]))
    def test_datasets(self):
        # this routine tests:
        #     dataset input into setup
        #     the function fdc_quantize_data
        #     the flux calculations of function fdc_flux_and_wind

        # expected values were calculated using matlab test code for a cutoff frequency
        # of 1/12.0
        # the first row are the uw, vw, wT flux values for the 1st dataset, etc.
        xpctd_fluxes = np.array(
            [[-0.350371566926, 0.115496951668, -0.008274161328],
             [-0.410571629711, 0.092164914869, -0.006687641111],
             [-0.080418722438, -0.001432879153, -0.004455583513]])

        # the agreement is good for datasets 1 and 2, not so good for 3 because when
        # goodcompass calculates to 1 (True), filtfilt is executed with the ahi2 and
        # bhi2 filter coeffs, the matlab v. scipy results of which barely agree (the
        # calculation is not robust).
        reltol = np.array([1.e-4, 1.e-4, 0.0, 0.0])
        abstol = np.array([0.0, 0.0, 1.e-4, 1.e-4])

        ### NOTE that the variables parsed out from 'array' are not column vectors;
        ### they are python 1D arrays which is what these DPAs expect from CI.
        for ii in range(4):
            array = np.copy(self.Ldata[ii])
            timestamps = array[:, 0]
            windX = array[:, 1]
            windY = array[:, 2]
            windZ = array[:, 3]
            sound = array[:, 4]  # (temperature proxy)
            rateX = array[:, 5]
            rateY = array[:, 6]
            rateZ = array[:, 7]
            accelX = array[:, 8]
            accelY = array[:, 9]
            accelZ = array[:, 10]
            roll = array[:, 11]  # (not used by DPA)
            pitch = array[:, 12]  # (not used by DPA)
            heading = array[:, 13]
            lat = array[:, 14]

            if ii < 3:  # single datasets
                calc_fluxes, _ = fd.fdc_flux_and_wind(timestamps, windX, windY,
                                                      windZ, sound, heading,
                                                      rateX, rateY, rateZ,
                                                      accelX, accelY, accelZ,
                                                      lat)
                calc_fluxes = np.asarray(calc_fluxes).flatten()
                np.testing.assert_allclose(calc_fluxes,
                                           xpctd_fluxes[ii, :],
                                           rtol=reltol[ii],
                                           atol=abstol[ii])

            if ii == 3:  # multiple
                calc_fluxes, _ = fd.fdc_flux_and_wind(timestamps, windX, windY,
                                                      windZ, sound, heading,
                                                      rateX, rateY, rateZ,
                                                      accelX, accelY, accelZ,
                                                      lat)
                calc_fluxes = np.asarray(calc_fluxes).transpose()
                np.testing.assert_allclose(calc_fluxes,
                                           xpctd_fluxes,
                                           rtol=reltol[ii],
                                           atol=abstol[ii])