Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mersi 2 angles reading #1407

Merged
merged 4 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions satpy/readers/mersi2_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 dataset_id.get('calibration') == 'counts':
# preserve integer type of counts if possible
attrs['_FillValue'] = fill_value
new_fill = fill_value
Expand All @@ -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 dataset_id.get('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 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 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)
Expand Down
12 changes: 11 additions & 1 deletion satpy/tests/reader_tests/test_mersi2_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ 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

Expand Down Expand Up @@ -338,8 +347,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)
Expand Down