Skip to content

Commit

Permalink
Merge pull request #2235 from djhoese/bugfix-load-modifiers-kwarg
Browse files Browse the repository at this point in the history
Fix Scene.load modifiers keyword argument having no effect
  • Loading branch information
djhoese committed Oct 13, 2022
2 parents 5cc09e0 + 0534dda commit e7d24a3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion satpy/dataset/dataid.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class DataQuery:
"""The data query object.
A DataQuery can be used in Satpy to query for a Dataset. This way
a fully qualified DataID can be found even if some of the DataID
a fully qualified DataID can be found even if some DataID
elements are unknown. In this case a `*` signifies something that is
unknown or not applicable to the requested Dataset.
"""
Expand Down
45 changes: 24 additions & 21 deletions satpy/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ def unload(self, keepables=None):
del self._datasets[ds_id]

def load(self, wishlist, calibration='*', resolution='*',
polarization='*', level='*', generate=True, unload=True,
polarization='*', level='*', modifiers='*', generate=True, unload=True,
**kwargs):
"""Read and generate requested datasets.
Expand All @@ -1305,35 +1305,37 @@ def load(self, wishlist, calibration='*', resolution='*',
or they can not provide certain parameters and the "best" parameter
will be chosen. For example, if a dataset is available in multiple
resolutions and no resolution is specified in the wishlist's DataQuery
then the highest (smallest number) resolution will be chosen.
then the highest (the smallest number) resolution will be chosen.
Loaded `DataArray` objects are created and stored in the Scene object.
Args:
wishlist (iterable): List of names (str), wavelengths (float),
DataQuery objects or DataID of the requested
datasets to load. See `available_dataset_ids()`
for what datasets are available.
calibration (list, str): Calibration levels to limit available
datasets. This is a shortcut to
having to list each DataQuery/DataID in
`wishlist`.
DataQuery objects or DataID of the requested datasets to load.
See `available_dataset_ids()` for what datasets are available.
calibration (list | str): Calibration levels to limit available
datasets. This is a shortcut to having to list each
DataQuery/DataID in `wishlist`.
resolution (list | float): Resolution to limit available datasets.
This is a shortcut similar to
calibration.
This is a shortcut similar to calibration.
polarization (list | str): Polarization ('V', 'H') to limit
available datasets. This is a shortcut
similar to calibration.
available datasets. This is a shortcut similar to calibration.
modifiers (tuple | str): Modifiers that should be applied to the
loaded datasets. This is a shortcut similar to calibration,
but only represents a single set of modifiers as a tuple.
For example, specifying
``modifiers=('sunz_corrected', 'rayleigh_corrected')`` will
attempt to apply both of these modifiers to all loaded
datasets in the specified order ('sunz_corrected' first).
level (list | str): Pressure level to limit available datasets.
Pressure should be in hPa or mb. If an
altitude is used it should be specified in
inverse meters (1/m). The units of this
parameter ultimately depend on the reader.
Pressure should be in hPa or mb. If an altitude is used it
should be specified in inverse meters (1/m). The units of this
parameter ultimately depend on the reader.
generate (bool): Generate composites from the loaded datasets
(default: True)
unload (bool): Unload datasets that were required to generate
the requested datasets (composite dependencies)
but are no longer needed.
(default: True)
unload (bool): Unload datasets that were required to generate the
requested datasets (composite dependencies) but are no longer
needed.
"""
if isinstance(wishlist, str):
Expand All @@ -1343,6 +1345,7 @@ def load(self, wishlist, calibration='*', resolution='*',
query = DataQuery(calibration=calibration,
polarization=polarization,
resolution=resolution,
modifiers=modifiers,
level=level)
self._update_dependency_tree(needed_datasets, query)

Expand Down
8 changes: 8 additions & 0 deletions satpy/tests/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,14 @@ def test_load_modified(self):
assert len(loaded_ids) == 1
assert loaded_ids[0]['modifiers'] == ('mod1', 'mod2')

def test_load_modified_with_load_kwarg(self):
"""Test loading a modified dataset using the ``Scene.load`` keyword argument."""
scene = Scene(filenames=['fake1_1.txt'], reader='fake1')
scene.load(['ds1'], modifiers=('mod1', 'mod2'))
loaded_ids = list(scene._datasets.keys())
assert len(loaded_ids) == 1
assert loaded_ids[0]['modifiers'] == ('mod1', 'mod2')

def test_load_multiple_modified(self):
"""Test loading multiple modified datasets."""
scene = Scene(filenames=['fake1_1.txt'], reader='fake1')
Expand Down

0 comments on commit e7d24a3

Please sign in to comment.