Skip to content

Commit

Permalink
Get the GSD from output resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgleith committed Nov 5, 2020
1 parent 02a353e commit 7eb9dbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions datacube_alchemist/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def _munge_dataset_to_eo3(ds: Dataset) -> DatasetDoc:
product = ProductDoc(name=ds.type.name)
# Wrap properties to avoid typos and the like
properties = StacPropertyView(ds.metadata_doc.get("properties", {}))
if properties.get('eo:gsd'):
del properties['eo:gsd']
return DatasetDoc(
id=ds.id,
product=product,
Expand Down
20 changes: 13 additions & 7 deletions datacube_alchemist/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ def transform_name(self) -> str:
return self.config.specification.transform

@property
def _transform(self) -> Type[Transformation]:
def transform(self) -> Type[Transformation]:

module_name, class_name = self.transform_name.rsplit(".", maxsplit=1)
module = importlib.import_module(name=module_name)
imported_class = getattr(module, class_name)
assert issubclass(imported_class, Transformation)
return imported_class

def _native_resolution(self, task: AlchemistTask) -> float:
geobox = native_geobox(
task.dataset, basis=list(task.dataset.measurements.keys())[0]
)
return geobox.affine[0]

def _transform_with_args(self, task: AlchemistTask) -> Transformation:
transform_args = None
if task.settings.specification.transform_args:
Expand All @@ -84,9 +90,9 @@ def _transform_with_args(self, task: AlchemistTask) -> Transformation:
task.dataset.type.name
)
if transform_args is not None:
return self._transform(**transform_args)
return self.transform(**transform_args)
else:
return self._transform()
return self.transform()

def _find_dataset(self, uuid: str) -> Dataset:
# Find a dataset for a given UUID from within the available
Expand Down Expand Up @@ -270,10 +276,7 @@ def execute_task(

# Load and process data in a decimated array
if dryrun:
geobox = native_geobox(
task.dataset, basis=list(task.dataset.measurements.keys())[0]
)
res_by_ten = geobox.affine[0] * 10
res_by_ten = self._native_resolution(task) * 10
data = self.dc.load(
product=task.dataset.type.name,
id=task.dataset.id,
Expand Down Expand Up @@ -347,6 +350,9 @@ def execute_task(
for k, v in task.settings.output.properties.items():
dataset_assembler.properties[k] = v

# Update the GSD
dataset_assembler.properties['eo:gsd'] = self._native_resolution(task)

dataset_assembler.processed = datetime.utcnow()

dataset_assembler.note_software_version(
Expand Down

0 comments on commit 7eb9dbb

Please sign in to comment.