Skip to content

Commit

Permalink
Merge pull request #800 from wroberts4/master
Browse files Browse the repository at this point in the history
Fix 'virr_l1b' reader when slope attribute is 0
  • Loading branch information
djhoese committed Jun 6, 2019
2 parents 2418be0 + ccdb401 commit 20e2063
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions satpy/readers/virr_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,29 @@ def get_dataset(self, dataset_id, ds_info):
data = data.where((data >= self[file_key + '/attr/valid_range'][0]) &
(data <= self[file_key + '/attr/valid_range'][1]))
if 'E' in dataset_id.name:
slope = self[self.l1b_prefix + 'Emissive_Radiance_Scales'].data[:, band_index][:, np.newaxis]
slope = self._correct_slope(self[self.l1b_prefix + 'Emissive_Radiance_Scales'].
data[:, band_index][:, np.newaxis])
intercept = self[self.l1b_prefix + 'Emissive_Radiance_Offsets'].data[:, band_index][:, np.newaxis]
# Converts cm^-1 (wavenumbers) and (mW/m^2)/(str/cm^-1) (radiance data)
# to SI units m^-1, mW*m^-3*str^-1.
wave_number = self['/attr/' + self.wave_number][band_index] * 100
bt_data = rad2temp(wave_number,
(data.data * slope + intercept) * 1e-5)
bt_data = rad2temp(wave_number, (data.data * slope + intercept) * 1e-5)
if isinstance(bt_data, np.ndarray):
# old versions of pyspectral produce numpy arrays
data.data = da.from_array(bt_data, chunks=data.data.chunks)
else:
# new versions of pyspectral can do dask arrays
data.data = bt_data
elif 'R' in dataset_id.name:
slope = self['/attr/RefSB_Cal_Coefficients'][0::2]
slope = self._correct_slope(self['/attr/RefSB_Cal_Coefficients'][0::2])
intercept = self['/attr/RefSB_Cal_Coefficients'][1::2]
data = data * slope[band_index] + intercept[band_index]
else:
slope = self._correct_slope(self[file_key + '/attr/Slope'])
intercept = self[file_key + '/attr/Intercept']
data = data.where((data >= self[file_key + '/attr/valid_range'][0]) &
(data <= self[file_key + '/attr/valid_range'][1]))
data = self[file_key + '/attr/Intercept'] + self[file_key + '/attr/Slope'] * data
data = data * slope + intercept
new_dims = {old: new for old, new in zip(data.dims, ('y', 'x'))}
data = data.rename(new_dims)
data.attrs.update({'platform_name': self['/attr/Satellite Name'],
Expand All @@ -111,6 +113,10 @@ def get_dataset(self, dataset_id, ds_info):
data.attrs.update({'units': '1'})
return data

def _correct_slope(self, slope):
# 0 slope is invalid. Note: slope can be a scalar or array.
return da.where(slope == 0, 1, slope)

@property
def start_time(self):
start_time = self['/attr/Observing Beginning Date'] + 'T' + self['/attr/Observing Beginning Time'] + 'Z'
Expand Down
6 changes: 4 additions & 2 deletions satpy/tests/reader_tests/test_virr_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ def _fy3_helper(self, platform_name, reader, Emissive_units):
'E1': 496.542155, 'E2': 297.444511, 'E3': 288.956557, 'solar_zenith_angle': .1,
'satellite_zenith_angle': .1, 'solar_azimuth_angle': .1, 'satellite_azimuth_angle': .1,
'longitude': 10}
datasets = reader.load([band for band, val in band_values.items()])
datasets = reader.load([band for band in band_values])
for dataset in datasets:
# Object returned by get_dataset.
ds = datasets[dataset.name]
attributes = ds.attrs
self.assertTrue(isinstance(ds.data, da.Array))
self.assertEqual('VIRR', attributes['sensor'])
self.assertEqual(platform_name, attributes['platform_name'])
self.assertEqual(datetime.datetime(2018, 12, 25, 21, 41, 47, 90000), attributes['start_time'])
Expand Down Expand Up @@ -166,7 +168,7 @@ def test_fy3b_file(self):
self.assertTrue(FY3B_reader.file_handlers)
self._fy3_helper('FY3B', FY3B_reader, 'milliWstts/m^2/cm^(-1)/steradian')

def test_FY3C_file(self):
def test_fy3c_file(self):
from satpy.readers import load_reader
FY3C_reader = load_reader(self.reader_configs)
FY3C_files = FY3C_reader.select_files_from_pathnames(['tf2018359143912.FY3C-L_VIRRX_GEOXX.HDF',
Expand Down

0 comments on commit 20e2063

Please sign in to comment.