From 372eef76605a7dc39fa6af0df3a24c0dddfc0eee Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Thu, 3 Jun 2021 17:32:49 +0200 Subject: [PATCH 1/3] Change wavelenght format to match pps-level1c PPS (2021) need the wavelenght attribute to be a list with min, center, max value for the wavelength. --- level1c4pps/seviri2pps_lib.py | 1 + level1c4pps/tests/test_seviri2pps.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/level1c4pps/seviri2pps_lib.py b/level1c4pps/seviri2pps_lib.py index 7672dfa..f7b04c1 100644 --- a/level1c4pps/seviri2pps_lib.py +++ b/level1c4pps/seviri2pps_lib.py @@ -260,6 +260,7 @@ def set_attrs(scene): idtag = PPS_TAGNAMES[band] scene[band].attrs['id_tag'] = idtag scene[band].attrs['description'] = 'SEVIRI ' + str(band) + scene[band].attrs['wavelength'] = scene[band].attrs['wavelength'][0:3] if 'sun_earth_distance_correction_factor' not in scene[band].attrs: scene[band].attrs['sun_earth_distance_correction_applied'] = False scene[band].attrs['sun_earth_distance_correction_factor'] = 1.0 diff --git a/level1c4pps/tests/test_seviri2pps.py b/level1c4pps/tests/test_seviri2pps.py index 6a75c3b..c640b0b 100644 --- a/level1c4pps/tests/test_seviri2pps.py +++ b/level1c4pps/tests/test_seviri2pps.py @@ -45,14 +45,16 @@ def get_fake_scene(): dims=('y', 'x'), attrs={'calibration': 'reflectance', 'sun_earth_distance_correction_applied': True, - 'start_time': start_time} + 'start_time': start_time, + 'wavelength': [0.56, 0.635, 0.71, 'um']} ) scene['IR_108'] = xr.DataArray( [[5, 6], [7, 8]], dims=('y', 'x'), attrs={'calibration': 'brightness_temperature', - 'start_time': start_time} + 'start_time': start_time, + 'wavelength': [9.8, 10.8, 11.8, 'um']} ) scene.attrs['sensor'] = {'seviri'} return scene @@ -196,8 +198,9 @@ def get_observer_look_patched(lon, lat, alt, *args): def test_set_attrs(self): """Test setting scene attributes.""" seviri2pps.BANDNAMES = ['VIS006', 'IR_108'] - vis006 = mock.MagicMock(attrs={}) + vis006 = mock.MagicMock(attrs={'wavelength': [0.56, 0.635, 0.71, 'um']}) ir108 = mock.MagicMock(attrs={'platform_name': 'myplatform', + 'wavelength': [9.8, 10.8, 11.8, 'um'], 'orbital_parameters': {'orb_a': 1, 'orb_b': 2}, 'georef_offset_corrected': True}) @@ -245,11 +248,13 @@ def test_update_coords(self, get_mean_acq_time): dims=('x',), coords={'acq_time': ('x', [0, 0, 0])}, attrs={'area': 'myarea', + 'wavelength': [0.56, 0.635, 0.71, 'um'], 'start_time': dt.datetime(2009, 7, 1, 0)}) ir_108 = xr.DataArray(data=[4, 5, 6], dims=('x',), coords={'acq_time': ('x', [0, 0, 0])}, - attrs={'start_time': dt.datetime(2009, 7, 1, 1)}) + attrs={'start_time': dt.datetime(2009, 7, 1, 1), + 'wavelength': [9.8, 10.8, 11.8, 'um']}) scene_dict = {'VIS006': vis006.copy(), 'IR_108': ir_108.copy()} scene = mock.MagicMock(attrs={}) scene.__getitem__.side_effect = scene_dict.__getitem__ From b7d0bb45b8aae2bd6763bac060425c4780150f99 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Fri, 18 Jun 2021 10:51:53 +0200 Subject: [PATCH 2/3] Use satpy WavelengthRange function --- level1c4pps/seviri2pps_lib.py | 4 +++- level1c4pps/tests/test_seviri2pps.py | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/level1c4pps/seviri2pps_lib.py b/level1c4pps/seviri2pps_lib.py index f7b04c1..6a94f17 100644 --- a/level1c4pps/seviri2pps_lib.py +++ b/level1c4pps/seviri2pps_lib.py @@ -260,7 +260,9 @@ def set_attrs(scene): idtag = PPS_TAGNAMES[band] scene[band].attrs['id_tag'] = idtag scene[band].attrs['description'] = 'SEVIRI ' + str(band) - scene[band].attrs['wavelength'] = scene[band].attrs['wavelength'][0:3] + scene[band].attrs['wavelength'] = [scene[band].attrs['wavelength'].min, + scene[band].attrs['wavelength'].central, + scene[band].attrs['wavelength'].max] if 'sun_earth_distance_correction_factor' not in scene[band].attrs: scene[band].attrs['sun_earth_distance_correction_applied'] = False scene[band].attrs['sun_earth_distance_correction_factor'] = 1.0 diff --git a/level1c4pps/tests/test_seviri2pps.py b/level1c4pps/tests/test_seviri2pps.py index c640b0b..8dd629e 100644 --- a/level1c4pps/tests/test_seviri2pps.py +++ b/level1c4pps/tests/test_seviri2pps.py @@ -34,7 +34,7 @@ import level1c4pps.seviri2pps_lib as seviri2pps import level1c4pps.calibration_coefs as calib - +from satpy.dataset.dataid import WavelengthRange def get_fake_scene(): scene = Scene() @@ -46,7 +46,7 @@ def get_fake_scene(): attrs={'calibration': 'reflectance', 'sun_earth_distance_correction_applied': True, 'start_time': start_time, - 'wavelength': [0.56, 0.635, 0.71, 'um']} + 'wavelength': WavelengthRange(0.56, 0.635, 0.71)} ) scene['IR_108'] = xr.DataArray( [[5, 6], @@ -54,7 +54,7 @@ def get_fake_scene(): dims=('y', 'x'), attrs={'calibration': 'brightness_temperature', 'start_time': start_time, - 'wavelength': [9.8, 10.8, 11.8, 'um']} + 'wavelength': WavelengthRange(9.8, 10.8, 11.8)} ) scene.attrs['sensor'] = {'seviri'} return scene @@ -198,9 +198,9 @@ def get_observer_look_patched(lon, lat, alt, *args): def test_set_attrs(self): """Test setting scene attributes.""" seviri2pps.BANDNAMES = ['VIS006', 'IR_108'] - vis006 = mock.MagicMock(attrs={'wavelength': [0.56, 0.635, 0.71, 'um']}) + vis006 = mock.MagicMock(attrs={ 'wavelength': WavelengthRange(0.56, 0.635, 0.71)}) ir108 = mock.MagicMock(attrs={'platform_name': 'myplatform', - 'wavelength': [9.8, 10.8, 11.8, 'um'], + 'wavelength': WavelengthRange(9.8, 10.8, 11.8), 'orbital_parameters': {'orb_a': 1, 'orb_b': 2}, 'georef_offset_corrected': True}) @@ -248,13 +248,13 @@ def test_update_coords(self, get_mean_acq_time): dims=('x',), coords={'acq_time': ('x', [0, 0, 0])}, attrs={'area': 'myarea', - 'wavelength': [0.56, 0.635, 0.71, 'um'], + 'wavelength': WavelengthRange(0.56, 0.635, 0.71), 'start_time': dt.datetime(2009, 7, 1, 0)}) ir_108 = xr.DataArray(data=[4, 5, 6], dims=('x',), coords={'acq_time': ('x', [0, 0, 0])}, attrs={'start_time': dt.datetime(2009, 7, 1, 1), - 'wavelength': [9.8, 10.8, 11.8, 'um']}) + 'wavelength': WavelengthRange(9.8, 10.8, 11.8)}) scene_dict = {'VIS006': vis006.copy(), 'IR_108': ir_108.copy()} scene = mock.MagicMock(attrs={}) scene.__getitem__.side_effect = scene_dict.__getitem__ From 3728fa5376fd649ccdbd7dbc8a178392be4a1b96 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Fri, 18 Jun 2021 10:56:37 +0200 Subject: [PATCH 3/3] flake8 --- level1c4pps/tests/test_seviri2pps.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/level1c4pps/tests/test_seviri2pps.py b/level1c4pps/tests/test_seviri2pps.py index 8dd629e..0acfee8 100644 --- a/level1c4pps/tests/test_seviri2pps.py +++ b/level1c4pps/tests/test_seviri2pps.py @@ -36,6 +36,7 @@ import level1c4pps.calibration_coefs as calib from satpy.dataset.dataid import WavelengthRange + def get_fake_scene(): scene = Scene() start_time = dt.datetime(2020, 1, 1, 12) @@ -198,7 +199,7 @@ def get_observer_look_patched(lon, lat, alt, *args): def test_set_attrs(self): """Test setting scene attributes.""" seviri2pps.BANDNAMES = ['VIS006', 'IR_108'] - vis006 = mock.MagicMock(attrs={ 'wavelength': WavelengthRange(0.56, 0.635, 0.71)}) + vis006 = mock.MagicMock(attrs={'wavelength': WavelengthRange(0.56, 0.635, 0.71)}) ir108 = mock.MagicMock(attrs={'platform_name': 'myplatform', 'wavelength': WavelengthRange(9.8, 10.8, 11.8), 'orbital_parameters': {'orb_a': 1, @@ -248,7 +249,7 @@ def test_update_coords(self, get_mean_acq_time): dims=('x',), coords={'acq_time': ('x', [0, 0, 0])}, attrs={'area': 'myarea', - 'wavelength': WavelengthRange(0.56, 0.635, 0.71), + 'wavelength': WavelengthRange(0.56, 0.635, 0.71), 'start_time': dt.datetime(2009, 7, 1, 0)}) ir_108 = xr.DataArray(data=[4, 5, 6], dims=('x',), @@ -488,6 +489,7 @@ def test_set_nominal_scan_time(self): self.assertEqual(arr.attrs['start_time'], start_time) self.assertEqual(arr.attrs['end_time'], end_time) + class TestCalibration(unittest.TestCase): """Test SEVIRI calibration."""