def test_radiance_calibration(self, xr_): """Test radiance calibration steps.""" from satpy.readers.slstr_l1b import CHANCALIB_FACTORS xr_.open_dataset.return_value = self.fake_dataset ds_id = make_dataid(name='foo', calibration='radiance', stripe='a', view='nadir') filename_info = {'mission_id': 'S3A', 'dataset_name': 'foo', 'start_time': 0, 'end_time': 0, 'stripe': 'a', 'view': 'n'} test = NCSLSTR1B('somedir/S1_radiance_co.nc', filename_info, 'c') # Check warning is raised if we don't have calibration with warnings.catch_warnings(record=True) as w: test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'foo'})) assert issubclass(w[-1].category, UserWarning) # Check user calibration is used correctly test = NCSLSTR1B('somedir/S1_radiance_co.nc', filename_info, 'c', user_calibration={'foo_nadir': 0.4}) data = test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'foo'})) np.testing.assert_allclose(data.values, self.base_data * 0.4) # Check internal calibration is used correctly ds_id = make_dataid(name='S5', calibration='radiance', stripe='a', view='nadir') filename_info['dataset_name'] = 'S5' test = NCSLSTR1B('somedir/S1_radiance_an.nc', filename_info, 'c') data = test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'S5'})) np.testing.assert_allclose(data.values, self.base_data * CHANCALIB_FACTORS['S5_nadir'])
def test_instantiate(self, xr_): """Test initialization of file handlers.""" xr_.open_dataset.return_value = self.fake_dataset good_start = datetime.strptime(self.start_time, '%Y-%m-%dT%H:%M:%S.%fZ') good_end = datetime.strptime(self.end_time, '%Y-%m-%dT%H:%M:%S.%fZ') ds_id = make_dataid(name='foo', calibration='radiance', stripe='a', view='nadir') filename_info = {'mission_id': 'S3A', 'dataset_name': 'foo', 'start_time': 0, 'end_time': 0, 'stripe': 'a', 'view': 'n'} test = NCSLSTR1B('somedir/S1_radiance_an.nc', filename_info, 'c') assert test.view == 'nadir' assert test.stripe == 'a' test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'foo'})) self.assertEqual(test.start_time, good_start) self.assertEqual(test.end_time, good_end) xr_.open_dataset.assert_called() xr_.open_dataset.reset_mock() filename_info = {'mission_id': 'S3A', 'dataset_name': 'foo', 'start_time': 0, 'end_time': 0, 'stripe': 'c', 'view': 'o'} test = NCSLSTR1B('somedir/S1_radiance_co.nc', filename_info, 'c') assert test.view == 'oblique' assert test.stripe == 'c' test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'foo'})) self.assertEqual(test.start_time, good_start) self.assertEqual(test.end_time, good_end) xr_.open_dataset.assert_called() xr_.open_dataset.reset_mock() filename_info = {'mission_id': 'S3A', 'dataset_name': 'foo', 'start_time': 0, 'end_time': 0, 'stripe': 'a', 'view': 'n'} test = NCSLSTRGeo('somedir/S1_radiance_an.nc', filename_info, 'c') test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'foo'})) self.assertEqual(test.start_time, good_start) self.assertEqual(test.end_time, good_end) xr_.open_dataset.assert_called() xr_.open_dataset.reset_mock() test = NCSLSTRAngles('somedir/S1_radiance_an.nc', filename_info, 'c') # TODO: Make this test work # test.get_dataset(ds_id, filename_info) self.assertEqual(test.start_time, good_start) self.assertEqual(test.end_time, good_end) xr_.open_dataset.assert_called() xr_.open_dataset.reset_mock() test = NCSLSTRFlag('somedir/S1_radiance_an.nc', filename_info, 'c') assert test.view == 'nadir' assert test.stripe == 'a' self.assertEqual(test.start_time, good_start) self.assertEqual(test.end_time, good_end) xr_.open_dataset.assert_called() xr_.open_dataset.reset_mock()
def test_instantiate(self, mocked_dataset): """Test initialization of file handlers.""" from satpy.readers.slstr_l1b import NCSLSTR1B, NCSLSTRGeo, NCSLSTRAngles, NCSLSTRFlag from satpy import DatasetID ds_id = DatasetID(name='foo') filename_info = { 'mission_id': 'S3A', 'dataset_name': 'foo', 'start_time': 0, 'end_time': 0 } test = NCSLSTR1B('somedir/S1_radiance_an.nc', filename_info, 'c') assert (test.view == 'n') assert (test.stripe == 'a') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCSLSTR1B('somedir/S1_radiance_co.nc', filename_info, 'c') assert (test.view == 'o') assert (test.stripe == 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCSLSTRGeo('somedir/S1_radiance_an.nc', filename_info, 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCSLSTRAngles('somedir/S1_radiance_an.nc', filename_info, 'c') # TODO: Make this test work # test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCSLSTRFlag('somedir/S1_radiance_an.nc', filename_info, 'c') assert (test.view == 'n') assert (test.stripe == 'a') mocked_dataset.assert_called() mocked_dataset.reset_mock()
def test_cal_rad(self): """Test the radiance to reflectance converter.""" rad = np.array([10., 20., 30., 40., 50., 60., 70.]) didx = np.array([1, 2., 1., 3., 2., 2., 0.]) solflux = np.array([100., 200., 300., 400.]) good_rad = np.array([1. / 20., 1. / 15., 3. / 20., 1. / 10., 1. / 6., 2. / 10., 7. / 10.]) out_rad = NCSLSTR1B._cal_rad(rad, didx, solflux) np.testing.assert_allclose(out_rad, good_rad)
def test_instantiate(self, mocked_dataset): """Test initialization of file handlers.""" from satpy.readers.slstr_l1b import NCSLSTR1B, NCSLSTRGeo, NCSLSTRAngles, NCSLSTRFlag ds_id = make_dataid(name='foo', calibration='radiance', stripe='a', view='nadir') filename_info = {'mission_id': 'S3A', 'dataset_name': 'foo', 'start_time': 0, 'end_time': 0, 'stripe': 'a', 'view': 'n'} test = NCSLSTR1B('somedir/S1_radiance_an.nc', filename_info, 'c') assert(test.view == 'nadir') assert(test.stripe == 'a') test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'foo'})) mocked_dataset.assert_called() mocked_dataset.reset_mock() filename_info = {'mission_id': 'S3A', 'dataset_name': 'foo', 'start_time': 0, 'end_time': 0, 'stripe': 'c', 'view': 'o'} test = NCSLSTR1B('somedir/S1_radiance_co.nc', filename_info, 'c') assert(test.view == 'oblique') assert(test.stripe == 'c') test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'foo'})) mocked_dataset.assert_called() mocked_dataset.reset_mock() filename_info = {'mission_id': 'S3A', 'dataset_name': 'foo', 'start_time': 0, 'end_time': 0, 'stripe': 'a', 'view': 'n'} test = NCSLSTRGeo('somedir/S1_radiance_an.nc', filename_info, 'c') test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'foo'})) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCSLSTRAngles('somedir/S1_radiance_an.nc', filename_info, 'c') # TODO: Make this test work # test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCSLSTRFlag('somedir/S1_radiance_an.nc', filename_info, 'c') assert(test.view == 'nadir') assert(test.stripe == 'a') mocked_dataset.assert_called() mocked_dataset.reset_mock()
def test_reflectance_calibration(self, da_, xr_): """Test reflectance calibration.""" xr_.open_dataset.return_value = self.fake_dataset da_.map_blocks.return_value = self.rad / 100. filename_info = {'mission_id': 'S3A', 'dataset_name': 'S5', 'start_time': 0, 'end_time': 0, 'stripe': 'a', 'view': 'n'} ds_id = make_dataid(name='S5', calibration='reflectance', stripe='a', view='nadir') test = NCSLSTR1B('somedir/S1_radiance_an.nc', filename_info, 'c') data = test.get_dataset(ds_id, dict(filename_info, **{'file_key': 'S5'})) self.assertEqual(data.units, '%') np.testing.assert_allclose(data.values, self.rad * np.pi)