From 0f3ef6f7225955b96e1cdb2240ad76832614eca9 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Mon, 19 Oct 2020 12:38:19 +0200 Subject: [PATCH 1/4] Test to read also angles --- satpy/tests/reader_tests/test_mersi2_l1b.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/satpy/tests/reader_tests/test_mersi2_l1b.py b/satpy/tests/reader_tests/test_mersi2_l1b.py index 53e63a0841..314a53cd57 100644 --- a/satpy/tests/reader_tests/test_mersi2_l1b.py +++ b/satpy/tests/reader_tests/test_mersi2_l1b.py @@ -196,9 +196,19 @@ def _get_geo_data(self, num_scans, rows_per_scan, num_cols, prefix='Geolocation/ 'valid_range': [-180, 180], }, dims=('_rows', '_cols')), + prefix + 'SensorZenith': + xr.DataArray( + da.ones((num_scans * rows_per_scan, num_cols), chunks=1024), + attrs={ + 'Slope': [.01] * 1, 'Intercept': [0.] * 1, + 'units': 'degree', + 'valid_range': [0, 28000], + }, + dims=('_rows', '_cols')), } return geo + def get_test_content(self, filename, filename_info, filetype_info): """Mimic reader input file content.""" rows_per_scan = self.filetype_info.get('rows_per_scan', 10) @@ -338,8 +348,9 @@ def test_fy3d_counts_calib(self): ds_ids = [] for band_name in ['1', '2', '3', '4', '5', '20', '24', '25']: ds_ids.append(make_dataid(name=band_name, calibration='counts')) + ds_ids.append(make_dataid(name='satellite_zenith_angle')) res = reader.load(ds_ids) - self.assertEqual(8, len(res)) + self.assertEqual(9, len(res)) self.assertEqual((2 * 40, 2048 * 2), res['1'].shape) self.assertEqual('counts', res['1'].attrs['calibration']) self.assertEqual(res['1'].dtype, np.uint16) From a22ba45bbb473edc8599fad59a4f0167264fd3b2 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Mon, 19 Oct 2020 12:51:42 +0200 Subject: [PATCH 2/4] Angle dataset do not have kwd 'calibration' --- satpy/readers/mersi2_l1b.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/satpy/readers/mersi2_l1b.py b/satpy/readers/mersi2_l1b.py index ebb377bf14..d65c388cf8 100644 --- a/satpy/readers/mersi2_l1b.py +++ b/satpy/readers/mersi2_l1b.py @@ -92,7 +92,7 @@ def get_dataset(self, dataset_id, ds_info): fill_value = attrs.pop('FillValue', np.nan) # covered by valid_range valid_range = attrs.pop('valid_range', None) - if dataset_id['calibration'] == 'counts': + if 'calibration' in dataset_id and dataset_id['calibration'] == 'counts': # preserve integer type of counts if possible attrs['_FillValue'] = fill_value new_fill = fill_value @@ -110,20 +110,20 @@ def get_dataset(self, dataset_id, ds_info): slope = attrs.pop('Slope', None) intercept = attrs.pop('Intercept', None) - if slope is not None and dataset_id['calibration'] != 'counts': + if slope is not None and ('calibration' not in dataset_id or dataset_id['calibration'] != 'counts'): if band_index is not None: slope = slope[band_index] intercept = intercept[band_index] data = data * slope + intercept - if dataset_id['calibration'] == "reflectance": + if 'calibration' in dataset_id and dataset_id['calibration'] == "reflectance": # some bands have 0 counts for the first N columns and # seem to be invalid data points data = data.where(data != 0) coeffs = self._get_coefficients(ds_info['calibration_key'], ds_info['calibration_index']) data = coeffs[0] + coeffs[1] * data + coeffs[2] * data**2 - elif dataset_id['calibration'] == "brightness_temperature": + elif 'calibration' in dataset_id and dataset_id['calibration'] == "brightness_temperature": cal_index = ds_info['calibration_index'] # Apparently we don't use these calibration factors for Rad -> BT # coeffs = self._get_coefficients(ds_info['calibration_key'], cal_index) From e343da47cebf2887d413e40ec2cd080c29f8779f Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Mon, 19 Oct 2020 12:59:45 +0200 Subject: [PATCH 3/4] flake8 --- satpy/tests/reader_tests/test_mersi2_l1b.py | 1 - 1 file changed, 1 deletion(-) diff --git a/satpy/tests/reader_tests/test_mersi2_l1b.py b/satpy/tests/reader_tests/test_mersi2_l1b.py index 314a53cd57..15d14a8599 100644 --- a/satpy/tests/reader_tests/test_mersi2_l1b.py +++ b/satpy/tests/reader_tests/test_mersi2_l1b.py @@ -208,7 +208,6 @@ def _get_geo_data(self, num_scans, rows_per_scan, num_cols, prefix='Geolocation/ } return geo - def get_test_content(self, filename, filename_info, filetype_info): """Mimic reader input file content.""" rows_per_scan = self.filetype_info.get('rows_per_scan', 10) From d3a473ccae039aab3bb97332143b0e0a9ab30254 Mon Sep 17 00:00:00 2001 From: "Nina.Hakansson" Date: Mon, 19 Oct 2020 13:54:57 +0200 Subject: [PATCH 4/4] Fixing style suggested by Martin. --- satpy/readers/mersi2_l1b.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/satpy/readers/mersi2_l1b.py b/satpy/readers/mersi2_l1b.py index d65c388cf8..77bd1ad190 100644 --- a/satpy/readers/mersi2_l1b.py +++ b/satpy/readers/mersi2_l1b.py @@ -92,7 +92,7 @@ def get_dataset(self, dataset_id, ds_info): fill_value = attrs.pop('FillValue', np.nan) # covered by valid_range valid_range = attrs.pop('valid_range', None) - if 'calibration' in dataset_id and dataset_id['calibration'] == 'counts': + if dataset_id.get('calibration') == 'counts': # preserve integer type of counts if possible attrs['_FillValue'] = fill_value new_fill = fill_value @@ -110,20 +110,20 @@ def get_dataset(self, dataset_id, ds_info): slope = attrs.pop('Slope', None) intercept = attrs.pop('Intercept', None) - if slope is not None and ('calibration' not in dataset_id or dataset_id['calibration'] != 'counts'): + if slope is not None and dataset_id.get('calibration') != 'counts': if band_index is not None: slope = slope[band_index] intercept = intercept[band_index] data = data * slope + intercept - if 'calibration' in dataset_id and dataset_id['calibration'] == "reflectance": + if dataset_id.get('calibration') == "reflectance": # some bands have 0 counts for the first N columns and # seem to be invalid data points data = data.where(data != 0) coeffs = self._get_coefficients(ds_info['calibration_key'], ds_info['calibration_index']) data = coeffs[0] + coeffs[1] * data + coeffs[2] * data**2 - elif 'calibration' in dataset_id and dataset_id['calibration'] == "brightness_temperature": + elif dataset_id.get('calibration') == "brightness_temperature": cal_index = ds_info['calibration_index'] # Apparently we don't use these calibration factors for Rad -> BT # coeffs = self._get_coefficients(ds_info['calibration_key'], cal_index)