Exemple #1
0
    def test_calculate_internal_single_deployment(self):
        ctd_ds = xr.open_dataset(os.path.join(DATA_DIR, self.ctdpf_fn),
                                 decode_times=False)
        ctd_ds = ctd_ds[[
            'obs', 'time', 'deployment', 'temperature', 'pressure',
            'pressure_temp', 'conductivity', 'ext_volt0'
        ]]

        ctd_stream_dataset = StreamDataset(self.ctdpf_sk, {}, [], 'UNIT')
        ctd_stream_dataset.events = self.ctd_events
        ctd_stream_dataset._insert_dataset(ctd_ds)
        ctd_stream_dataset.calculate_all()

        for deployment in ctd_stream_dataset.datasets:
            ds = ctd_stream_dataset.datasets[deployment]
            tempwat = ctd_sbe16plus_tempwat(
                ds.temperature,
                ctd_stream_dataset.events.get_cal('CC_a0', deployment)[0][2],
                ctd_stream_dataset.events.get_cal('CC_a1', deployment)[0][2],
                ctd_stream_dataset.events.get_cal('CC_a2', deployment)[0][2],
                ctd_stream_dataset.events.get_cal('CC_a3', deployment)[0][2])
            np.testing.assert_array_equal(ds.seawater_temperature, tempwat)

            pracsal = ctd_pracsal(ds.seawater_conductivity,
                                  ds.seawater_temperature,
                                  ds.seawater_pressure)
            np.testing.assert_array_equal(ds.practical_salinity, pracsal)
Exemple #2
0
    def test_calculate_internal_multiple_deployments(self):
        ctd_ds = xr.open_dataset(os.path.join(DATA_DIR, self.ctdpf_fn),
                                 decode_times=False)
        ctd_ds = ctd_ds[[
            'obs', 'time', 'deployment', 'temperature', 'pressure',
            'pressure_temp', 'conductivity', 'ext_volt0'
        ]]

        # remap times to make this two separate deployments
        dep1_start = self.ctd_events.deps[1].ntp_start
        dep2_stop = self.ctd_events.deps[2].ntp_start + 864000
        ctd_ds.time.values = np.linspace(dep1_start + 1,
                                         dep2_stop - 1,
                                         num=ctd_ds.time.shape[0])

        ctd_stream_dataset = StreamDataset(self.ctdpf_sk, {}, [], 'UNIT')
        ctd_stream_dataset.events = self.ctd_events
        ctd_stream_dataset._insert_dataset(ctd_ds)
        ctd_stream_dataset.calculate_all()

        for deployment in ctd_stream_dataset.datasets:
            ds = ctd_stream_dataset.datasets[deployment]
            tempwat = ctd_sbe16plus_tempwat(
                ds.temperature,
                ctd_stream_dataset.events.get_cal('CC_a0', deployment)[0][2],
                ctd_stream_dataset.events.get_cal('CC_a1', deployment)[0][2],
                ctd_stream_dataset.events.get_cal('CC_a2', deployment)[0][2],
                ctd_stream_dataset.events.get_cal('CC_a3', deployment)[0][2])
            np.testing.assert_array_equal(ds.seawater_temperature, tempwat)

            pracsal = ctd_pracsal(ds.seawater_conductivity,
                                  ds.seawater_temperature,
                                  ds.seawater_pressure)
            np.testing.assert_array_equal(ds.practical_salinity, pracsal)
    def test_calculate_internal_multiple_deployments(self):
        ctd_ds = xr.open_dataset(os.path.join(DATA_DIR, self.ctdpf_fn), decode_times=False)
        ctd_ds = ctd_ds[['obs', 'time', 'deployment', 'temperature', 'pressure',
                         'pressure_temp', 'conductivity', 'ext_volt0']]

        # remap times to make this two separate deployments
        dep1_start = self.ctd_events.deps[1].ntp_start
        dep2_stop = self.ctd_events.deps[2].ntp_start + 864000
        ctd_ds.time.values = np.linspace(dep1_start+1, dep2_stop-1, num=ctd_ds.time.shape[0])

        ctd_stream_dataset = StreamDataset(self.ctdpf_sk, {}, [], 'UNIT')
        ctd_stream_dataset.events = self.ctd_events
        ctd_stream_dataset._insert_dataset(ctd_ds)
        ctd_stream_dataset.calculate_all()

        for deployment in ctd_stream_dataset.datasets:
            ds = ctd_stream_dataset.datasets[deployment]
            tempwat = ctd_sbe16plus_tempwat(ds.temperature,
                                            ctd_stream_dataset.events.get_cal('CC_a0', deployment)[0][2],
                                            ctd_stream_dataset.events.get_cal('CC_a1', deployment)[0][2],
                                            ctd_stream_dataset.events.get_cal('CC_a2', deployment)[0][2],
                                            ctd_stream_dataset.events.get_cal('CC_a3', deployment)[0][2])
            np.testing.assert_array_equal(ds.seawater_temperature, tempwat)

            pracsal = ctd_pracsal(ds.seawater_conductivity,
                                  ds.seawater_temperature,
                                  ds.seawater_pressure)
            np.testing.assert_array_equal(ds.practical_salinity, pracsal)
Exemple #4
0
    def test_calculate_internal_multiple_deployments(self):
        tr = TimeRange(3.65342400e+09, 3.65351040e+09)
        coefficients = {k: [{'start': tr.start-1, 'stop': tr.stop+1, 'value': v, 'deployment': 1},
                            {'start': tr.start-1, 'stop': tr.stop+1, 'value': v, 'deployment': 2}]
                        for k, v in self.ctd_nutnr_cals.iteritems()}

        coefficients = CalibrationCoefficientStore(coefficients, 'UNIT')

        ctd_ds = xr.open_dataset(os.path.join(DATA_DIR, self.ctdpf_fn), decode_times=False)
        ctd_ds = ctd_ds[['obs', 'time', 'deployment', 'temperature', 'pressure',
                         'pressure_temp', 'conductivity', 'ext_volt0']]

        ctd_ds.deployment.values[:100000] = 1
        ctd_ds.deployment.values[100000:] = 2

        ctd_stream_dataset = StreamDataset(self.ctdpf_sk, coefficients, {}, [], 'UNIT')
        ctd_stream_dataset._insert_dataset(ctd_ds)
        ctd_stream_dataset.calculate_internal()

        for ds in ctd_stream_dataset.datasets.itervalues():
            tempwat = ctd_sbe16plus_tempwat(ds.temperature,
                                            self.ctd_nutnr_cals['CC_a0'], self.ctd_nutnr_cals['CC_a1'],
                                            self.ctd_nutnr_cals['CC_a2'], self.ctd_nutnr_cals['CC_a3'])
            np.testing.assert_array_equal(ds.seawater_temperature, tempwat)

            pracsal = ctd_pracsal(ds.seawater_conductivity,
                                  ds.seawater_temperature,
                                  ds.seawater_pressure)
            np.testing.assert_array_equal(ds.practical_salinity, pracsal)
Exemple #5
0
    def test_calculate(self):
        nutnr_sk = StreamKey('CE04OSPS', 'SF01B', '4A-NUTNRA102', 'streamed',
                             'nutnr_a_sample')
        ctdpf_sk = StreamKey('CE04OSPS', 'SF01B', '2A-CTDPFA107', 'streamed',
                             'ctdpf_sbe43_sample')
        nutnr_fn = 'nutnr_a_sample.nc'
        ctdpf_fn = 'ctdpf_sbe43_sample.nc'

        cals = json.load(open(os.path.join(DATA_DIR, 'cals.json')))

        tr = TimeRange(3.65342400e+09, 3.65351040e+09)
        coefficients = {
            k: [{
                'start': tr.start - 1,
                'stop': tr.stop + 1,
                'value': cals[k],
                'deployment': 1
            }]
            for k in cals
        }
        sr = StreamRequest(nutnr_sk, [2443],
                           coefficients,
                           tr, {},
                           request_id='UNIT')
        nutnr_ds = xr.open_dataset(os.path.join(DATA_DIR, nutnr_fn),
                                   decode_times=False)
        ctdpf_ds = xr.open_dataset(os.path.join(DATA_DIR, ctdpf_fn),
                                   decode_times=False)

        nutnr_ds = nutnr_ds[self.base_params +
                            [p.name for p in sr.stream_parameters[nutnr_sk]]]
        ctdpf_ds = ctdpf_ds[self.base_params +
                            [p.name for p in sr.stream_parameters[ctdpf_sk]]]

        sr.datasets[ctdpf_sk] = StreamDataset(ctdpf_sk, sr.coefficients,
                                              sr.uflags, [nutnr_sk],
                                              sr.request_id)
        sr.datasets[nutnr_sk] = StreamDataset(nutnr_sk, sr.coefficients,
                                              sr.uflags, [ctdpf_sk],
                                              sr.request_id)
        sr.datasets[ctdpf_sk]._insert_dataset(ctdpf_ds)
        sr.datasets[nutnr_sk]._insert_dataset(nutnr_ds)

        sr.calculate_derived_products()

        ds = sr.datasets[ctdpf_sk]
        tempwat = ctd_sbe16plus_tempwat(ds.datasets[0].temperature,
                                        cals['CC_a0'], cals['CC_a1'],
                                        cals['CC_a2'], cals['CC_a3'])
        np.testing.assert_array_equal(ds.datasets[0].seawater_temperature,
                                      tempwat)

        pracsal = ctd_pracsal(ds.datasets[0].seawater_conductivity,
                              ds.datasets[0].seawater_temperature,
                              ds.datasets[0].seawater_pressure)
        np.testing.assert_array_equal(ds.datasets[0].practical_salinity,
                                      pracsal)

        response = json.loads(JsonResponse(sr).json())
        self.assertEqual(len(response), len(nutnr_ds.time.values))
    def test_ctd_sbe16plus_tempwat(self):
        """
        Test ctd_sbe16plus_tempwat function.

        Values based on those described in DPS as available on Alfresco:

        OOI (2012). Data Product Specification for Water Temperature. Document
            Control Number 1341-00010. https://alfresco.oceanobservatories.org/
            (See: Company Home >> OOI >> Controlled >> 1000 System Level >>
            1341-00010_Data_Product_SPEC_TEMPWAT_OOI.pdf)

        Implemented by Christopher Wingard, April 2013
        """
        # test inputs
        t0 = 248471
        a0 = 1.281651e-3
        a1 = 2.706002e-4
        a2 = -1.027561e-6
        a3 = 1.749446e-7
        tout = ctdfunc.ctd_sbe16plus_tempwat(t0, a0, a1, a2, a3)
        np.testing.assert_allclose(tout, 22.544681, rtol=1e-6, atol=0)
Exemple #7
0
    def test_ctd_sbe16plus_tempwat(self):
        """
        Test ctd_sbe16plus_tempwat function.

        Values based on those described in DPS as available on Alfresco:

        OOI (2012). Data Product Specification for Water Temperature. Document
            Control Number 1341-00010. https://alfresco.oceanobservatories.org/
            (See: Company Home >> OOI >> Controlled >> 1000 System Level >>
            1341-00010_Data_Product_SPEC_TEMPWAT_OOI.pdf)

        Implemented by Christopher Wingard, April 2013
        """
        # test inputs
        t0 = 248471
        a0 = 1.281651e-3
        a1 = 2.706002e-4
        a2 = -1.027561e-6
        a3 = 1.749446e-7
        tout = ctdfunc.ctd_sbe16plus_tempwat(t0, a0, a1, a2, a3)
        np.testing.assert_allclose(tout, 22.544681, rtol=1e-6, atol=0)
    def test_calculate_internal_single_deployment(self):
        ctd_ds = xr.open_dataset(os.path.join(DATA_DIR, self.ctdpf_fn), decode_times=False)
        ctd_ds = ctd_ds[['obs', 'time', 'deployment', 'temperature', 'pressure',
                         'pressure_temp', 'conductivity', 'ext_volt0']]

        ctd_stream_dataset = StreamDataset(self.ctdpf_sk, {}, [], 'UNIT')
        ctd_stream_dataset.events = self.ctd_events
        ctd_stream_dataset._insert_dataset(ctd_ds)
        ctd_stream_dataset.calculate_all()

        for deployment in ctd_stream_dataset.datasets:
            ds = ctd_stream_dataset.datasets[deployment]
            tempwat = ctd_sbe16plus_tempwat(ds.temperature,
                                            ctd_stream_dataset.events.get_cal('CC_a0', deployment)[0][2],
                                            ctd_stream_dataset.events.get_cal('CC_a1', deployment)[0][2],
                                            ctd_stream_dataset.events.get_cal('CC_a2', deployment)[0][2],
                                            ctd_stream_dataset.events.get_cal('CC_a3', deployment)[0][2])
            np.testing.assert_array_equal(ds.seawater_temperature, tempwat)

            pracsal = ctd_pracsal(ds.seawater_conductivity,
                                  ds.seawater_temperature,
                                  ds.seawater_pressure)
            np.testing.assert_array_equal(ds.practical_salinity, pracsal)
    def test_calculate(self):
        nutnr_sk = StreamKey('CE04OSPS', 'SF01B', '4A-NUTNRA102', 'streamed', 'nutnr_a_sample')
        ctdpf_sk = StreamKey('CE04OSPS', 'SF01B', '2A-CTDPFA107', 'streamed', 'ctdpf_sbe43_sample')
        nutnr_fn = 'nutnr_a_sample.nc'
        ctdpf_fn = 'ctdpf_sbe43_sample.nc'

        cals = json.load(open(os.path.join(DATA_DIR, 'cals.json')))

        tr = TimeRange(3.65342400e+09, 3.65351040e+09)
        coefficients = {k: [{'start': tr.start-1, 'stop': tr.stop+1, 'value': cals[k], 'deployment': 1}] for k in cals}
        sr = StreamRequest(nutnr_sk, [2443], coefficients, tr, {}, request_id='UNIT')
        nutnr_ds = xr.open_dataset(os.path.join(DATA_DIR, nutnr_fn), decode_times=False)
        ctdpf_ds = xr.open_dataset(os.path.join(DATA_DIR, ctdpf_fn), decode_times=False)

        nutnr_ds = nutnr_ds[self.base_params + [p.name for p in sr.stream_parameters[nutnr_sk]]]
        ctdpf_ds = ctdpf_ds[self.base_params + [p.name for p in sr.stream_parameters[ctdpf_sk]]]

        sr.datasets[ctdpf_sk] = StreamDataset(ctdpf_sk, sr.coefficients, sr.uflags, [nutnr_sk], sr.request_id)
        sr.datasets[nutnr_sk] = StreamDataset(nutnr_sk, sr.coefficients, sr.uflags, [ctdpf_sk], sr.request_id)
        sr.datasets[ctdpf_sk]._insert_dataset(ctdpf_ds)
        sr.datasets[nutnr_sk]._insert_dataset(nutnr_ds)

        sr.calculate_derived_products()

        ds = sr.datasets[ctdpf_sk]
        tempwat = ctd_sbe16plus_tempwat(ds.datasets[0].temperature,
                                        cals['CC_a0'], cals['CC_a1'],
                                        cals['CC_a2'], cals['CC_a3'])
        np.testing.assert_array_equal(ds.datasets[0].seawater_temperature, tempwat)

        pracsal = ctd_pracsal(ds.datasets[0].seawater_conductivity,
                              ds.datasets[0].seawater_temperature,
                              ds.datasets[0].seawater_pressure)
        np.testing.assert_array_equal(ds.datasets[0].practical_salinity, pracsal)

        response = json.loads(JsonResponse(sr).json())
        self.assertEqual(len(response), len(nutnr_ds.time.values))