Skip to content

Commit

Permalink
Add option to specify a global calibration mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed Jun 13, 2024
1 parent 30aff09 commit e82e2b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion satpy/readers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ def __init__(self, coefs, modes=None, default="nominal", fallback=None):
coefs (dict): One set of calibration coefficients for each
calibration mode. The actual coefficients can be of any type
(reader-specific).
modes (dict): Desired calibration modes
modes (str or dict): Desired calibration modes. Use a dictionary
`{mode: channels}` to specify multiple modes. Use a string to
specify one mode for all channels.
default (str): Default coefficients to be used if no mode has been
specified. Default: "nominal".
fallback (str): Fallback coefficients if the desired coefficients
Expand All @@ -549,6 +551,18 @@ def __init__(self, coefs, modes=None, default="nominal", fallback=None):
raise KeyError("Need at least default coefficients")
if self.fallback and self.fallback not in self.coefs:
raise KeyError("No fallback coefficients")
self.modes = self._make_modes(modes)

def _make_modes(self, modes):
if modes is None:
return {}
elif self._same_mode_for_all_channels(modes):
all_channels = self.coefs[self.default].keys()
return {modes: all_channels}
return modes

def _same_mode_for_all_channels(self, modes):
return isinstance(modes, str)

def get_coefs(self, channel):
"""Get calibration coefficients for the given channel.
Expand Down
4 changes: 4 additions & 0 deletions satpy/tests/reader_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ def fixture_coefs(self):
None,
{"ch1": "nominal_ch1", "ch2": "nominal_ch2"}
),
(
"nominal",
{"ch1": "nominal_ch1", "ch2": "nominal_ch2"}
),
(
{"nominal": ["ch1", "ch2"]},
{"ch1": "nominal_ch1", "ch2": "nominal_ch2"}
Expand Down

0 comments on commit e82e2b9

Please sign in to comment.