Skip to content

Commit

Permalink
Fix Scene save_datasets to only save datasets from the wishlist
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Jun 28, 2018
1 parent 9767550 commit 8f31507
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 7 additions & 1 deletion satpy/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,13 @@ def save_datasets(self, writer="geotiff", datasets=None, compute=True,
if datasets is not None:
datasets = [self[ds] for ds in datasets]
else:
datasets = self.datasets.values()
datasets = [self.datasets.get(ds) for ds in self.wishlist]
datasets = [ds for ds in datasets if ds is not None]
if not datasets:
raise RuntimeError("None of the requested datasets have been "
"generated or could not be loaded. Requested "
"composite inputs may need to have matching "
"dimensions (eg. through resampling).")
writer, save_kwargs = load_writer(writer,
ppp_config_dir=self.ppp_config_dir,
**kwargs)
Expand Down
15 changes: 14 additions & 1 deletion satpy/tests/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ def test_save_datasets_default(self):
os.path.join(self.base_dir, 'test_20180101_000000.tif')))

def test_save_datasets_bad_writer(self):
"""Save a dataset using 'save_datasets'."""
"""Save a dataset using 'save_datasets' and a bad writer."""
from satpy.scene import Scene
import xarray as xr
import dask.array as da
Expand All @@ -1639,6 +1639,19 @@ def test_save_datasets_bad_writer(self):
writer='_bad_writer_',
base_dir=self.base_dir)

def test_save_datasets_missing_wishlist(self):
"""Calling 'save_datasets' with no valid datasets."""
from satpy.scene import Scene, DatasetID
scn = Scene()
scn.wishlist.add(DatasetID(name='true_color'))
self.assertRaises(RuntimeError,
scn.save_datasets,
writer='geotiff',
base_dir=self.base_dir)
self.assertRaises(KeyError,
scn.save_datasets,
datasets=['no_exist'])

def test_save_dataset_default(self):
"""Save a dataset using 'save_dataset'."""
from satpy.scene import Scene
Expand Down

0 comments on commit 8f31507

Please sign in to comment.