Skip to content

Commit

Permalink
Make methods smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed Nov 22, 2024
1 parent f0497a0 commit de5e129
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
9 changes: 6 additions & 3 deletions satpy/readers/seviri_l1b_hrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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."""
Expand Down
22 changes: 14 additions & 8 deletions satpy/readers/seviri_l1b_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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":
Expand Down
15 changes: 10 additions & 5 deletions satpy/readers/seviri_l1b_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit de5e129

Please sign in to comment.