From 81996417496446ffd4294132afec37728534c557 Mon Sep 17 00:00:00 2001 From: davidh-ssec Date: Wed, 2 Dec 2015 11:36:56 -0600 Subject: [PATCH] handle optional dependencies for composites (not tested) --- mpop/composites/__init__.py | 7 +------ mpop/scene.py | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/mpop/composites/__init__.py b/mpop/composites/__init__.py index d743e450..e44fa908 100644 --- a/mpop/composites/__init__.py +++ b/mpop/composites/__init__.py @@ -42,12 +42,7 @@ def __init__(self, name, prerequisites=[], optional_prerequisites=[], metadata_r kwargs["metadata_requirements"] = metadata_requirements super(CompositeBase, self).__init__(**kwargs) - @property - def prerequisites(self): - # Semi-backward compatible - return self.info["prerequisites"] - - def __call__(self, projectables, nonprojectables=None, **info): + def __call__(self, datasets, optional_datasets=None, **info): raise NotImplementedError() diff --git a/mpop/scene.py b/mpop/scene.py index f2ee836d..7c18722a 100644 --- a/mpop/scene.py +++ b/mpop/scene.py @@ -308,9 +308,10 @@ def read(self, dataset_keys, calibration=None, resolution=None, polarization=Non needed_bands = set(dataset_ids) while composites_needed: for band in composites_needed.copy(): - new_bands = set(reader_instance.get_dataset_key(prereq) - for prereq in self.compositors[band].prerequisites) - needed_bands |= new_bands + needed_bands |= set(reader_instance.get_dataset_key(prereq) + for prereq in self.compositors[band].info["prerequisites"]) + needed_bands |= set(reader_instance.get_dataset_key(prereq) + for prereq in self.compositors[band].info["optional_prerequisites"]) composites_needed.remove(band) # A composite might use a product from another reader, so only pass along the ones we know about @@ -352,13 +353,19 @@ def compute(self, *requirements): requirement_name = requirement.name else: requirement_name = requirement - # Compute any composites that this one depends on - self.compute(*self.compositors[requirement_name].prerequisites) - # TODO: Get non-projectable dependencies like moon illumination fraction - prereq_projectables = [self[prereq] for prereq in self.compositors[requirement_name].prerequisites] + compositor = self.compositors[requirement_name] + # Compute any composites that this one depends on + self.compute(*compositor.info["prerequisites"]) + # Compute any composites that this composite might optionally depend on + if compositor.info["optional_prerequisites"]: + self.compute(*compositor.info["optional_prerequisites"]) + + prereq_datasets = [self[prereq] for prereq in compositor.info["prerequisites"]] + optional_datasets = [self[prereq] for prereq in compositor.info["optional_prerequisites"] + if prereq in self] try: - comp_projectable = self.compositors[requirement_name](prereq_projectables, **self.info) + comp_projectable = compositor(prereq_datasets, optional_datasets=optional_datasets, **self.info) # validate the composite projectable assert("name" in comp_projectable.info) @@ -382,9 +389,9 @@ def compute(self, *requirements): self.wishlist.remove(requirement_name) self.wishlist.add(band_id) except IncompatibleAreas: - for ds_id, projectable in self.datasets.iteritems(): + for ds_id, projectable in self.datasets.items(): # FIXME: Can compositors use wavelengths or only names? - if ds_id.name in self.compositors[requirement_name].prerequisites: + if ds_id.name in compositor.info["prerequisites"]: projectable.info["keep"] = True def unload(self):