diff --git a/satpy/readers/seviri_l1b_hrit.py b/satpy/readers/seviri_l1b_hrit.py index 15c382a54a..f08650f331 100644 --- a/satpy/readers/seviri_l1b_hrit.py +++ b/satpy/readers/seviri_l1b_hrit.py @@ -728,6 +728,11 @@ def pad_hrv_data(self, res): def calibrate(self, data, calibration): """Calibrate the data.""" + calib = self._get_calibration_handler() + res = calib.calibrate(data, calibration) + return res + + def _get_calibration_handler(self): calib_params = CalibParams( mode=self.calib_mode.upper(), internal_coefs=self._get_calib_coefs(), @@ -736,9 +741,7 @@ def calibrate(self, data, calibration): ) scan_params = ScanParams(self.platform_id, self.channel_name, self.observation_start_time) - calib = SEVIRICalibrationHandler(calib_params, scan_params) - res = calib.calibrate(data, calibration) - return res + return SEVIRICalibrationHandler(calib_params, scan_params) def _mask_bad_quality(self, data): """Mask scanlines with bad quality.""" diff --git a/satpy/readers/seviri_l1b_native.py b/satpy/readers/seviri_l1b_native.py index 8ef97b3a78..18c6d9f711 100644 --- a/satpy/readers/seviri_l1b_native.py +++ b/satpy/readers/seviri_l1b_native.py @@ -623,22 +623,22 @@ def _get_hrv_channel(self): def calibrate(self, data, dataset_id): """Calibrate the data.""" tic = dt.datetime.now() + calib = self._get_calibration_handler(dataset_id) + res = calib.calibrate(data, dataset_id["calibration"]) + logger.debug("Calibration time " + str(dt.datetime.now() - tic)) + return res + + def _get_calibration_handler(self, dataset_id): channel_name = dataset_id["name"] - band_idx = self._get_band_index(channel_name) - radiance_types = self.header["15_DATA_HEADER"]["ImageDescription"][ - "Level15ImageProduction"]["PlannedChanProcessing"] calib_params = CalibParams( mode=self.calib_mode.upper(), internal_coefs=self._get_calib_coefs(channel_name), external_coefs=self.ext_calib_coefs, - radiance_type=radiance_types[band_idx] + radiance_type=self._get_radiance_type(channel_name) ) scan_params = ScanParams(self.platform_id, channel_name, self.observation_start_time) - calib = SEVIRICalibrationHandler(calib_params, scan_params) - res = calib.calibrate(data, dataset_id["calibration"]) - logger.debug("Calibration time " + str(dt.datetime.now() - tic)) - return res + return SEVIRICalibrationHandler(calib_params, scan_params) def _get_calib_coefs(self, channel_name): """Get coefficients for calibration from counts to radiance.""" @@ -668,6 +668,12 @@ def _get_band_index(self, channel_name): # hence, this channel index needs to refer to full channel list return list(CHANNEL_NAMES.values()).index(channel_name) + def _get_radiance_type(self, channel_name): + band_idx = self._get_band_index(channel_name) + radiance_types = self.header["15_DATA_HEADER"]["ImageDescription"][ + "Level15ImageProduction"]["PlannedChanProcessing"] + return radiance_types[band_idx] + def _add_scanline_acq_time(self, dataset, dataset_id): """Add scanline acquisition time to the given dataset.""" if dataset_id["name"] == "HRV": diff --git a/satpy/readers/seviri_l1b_nc.py b/satpy/readers/seviri_l1b_nc.py index b75b2cc09d..726caf83a1 100644 --- a/satpy/readers/seviri_l1b_nc.py +++ b/satpy/readers/seviri_l1b_nc.py @@ -189,21 +189,26 @@ def calibrate(self, dataset, dataset_id): if dataset_id["calibration"] == "counts": dataset.attrs["_FillValue"] = 0 - band_idx = list(CHANNEL_NAMES.values()).index(channel) - radiance_type = self.nc["planned_chan_processing"].values[band_idx] + calib = self._get_calibration_handler(dataset, channel) + return calib.calibrate(dataset, calibration) + + def _get_calibration_handler(self, dataset, channel): calib_params = CalibParams( mode="NOMINAL", internal_coefs=self._get_calib_coefs(dataset, channel), external_coefs=self.ext_calib_coefs, - radiance_type=radiance_type + radiance_type=self._get_radiance_type(channel) ) scan_params = ScanParams( int(self.platform_id), channel, self.observation_start_time ) - calib = SEVIRICalibrationHandler(calib_params, scan_params) - return calib.calibrate(dataset, calibration) + return SEVIRICalibrationHandler(calib_params, scan_params) + + def _get_radiance_type(self, channel): + band_idx = list(CHANNEL_NAMES.values()).index(channel) + return self.nc["planned_chan_processing"].values[band_idx] def _get_calib_coefs(self, dataset, channel): """Get coefficients for calibration from counts to radiance.