From f540dbe1ef7f4e17ad736e743bfb77c184616fd3 Mon Sep 17 00:00:00 2001 From: Deepak Chandan Date: Thu, 26 Oct 2023 13:53:22 -0400 Subject: [PATCH] fix datacube extension --- STACpopulator/implementations/CMIP6_UofT/add_CMIP6.py | 3 ++- STACpopulator/implementations/CMIP6_UofT/extensions.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/STACpopulator/implementations/CMIP6_UofT/add_CMIP6.py b/STACpopulator/implementations/CMIP6_UofT/add_CMIP6.py index fc39baf..32f8577 100644 --- a/STACpopulator/implementations/CMIP6_UofT/add_CMIP6.py +++ b/STACpopulator/implementations/CMIP6_UofT/add_CMIP6.py @@ -7,6 +7,7 @@ import pyessv from colorlog import ColoredFormatter from pydantic import AnyHttpUrl, ConfigDict, Field, FieldValidationInfo, field_validator +from pystac.extensions.datacube import DatacubeExtension from STACpopulator import STACpopulatorBase from STACpopulator.implementations.CMIP6_UofT.extensions import DataCubeHelper @@ -150,7 +151,7 @@ def create_stac_item(self, item_name: str, item_data: MutableMapping[str, Any]) try: dchelper = DataCubeHelper(item_data) dc_ext = DatacubeExtension.ext(item, add_if_missing=True) - dc_ext.apply(dimensions=dchelper.dimensions(), variables=dchelper.variables()) + dc_ext.apply(dimensions=dchelper.dimensions, variables=dchelper.variables) except: LOGGER.warning(f"Failed to add Datacube extension to item {item_name}") diff --git a/STACpopulator/implementations/CMIP6_UofT/extensions.py b/STACpopulator/implementations/CMIP6_UofT/extensions.py index 9f77b0f..31450a6 100644 --- a/STACpopulator/implementations/CMIP6_UofT/extensions.py +++ b/STACpopulator/implementations/CMIP6_UofT/extensions.py @@ -2,6 +2,8 @@ from pystac.extensions.datacube import Dimension, DimensionType, Variable, VariableType +from STACpopulator.stac_utils import ncattrs_to_bbox + class DataCubeHelper: """Return STAC Item from CF JSON metadata, as provided by `xncml.Dataset.to_cf_dict`.""" @@ -147,7 +149,7 @@ def dimensions(self) -> dict: for name, length in self.attrs["dimensions"].items(): v = self.attrs["variables"].get(name) if v: - bbox = self.obj.ncattrs_to_bbox() + bbox = ncattrs_to_bbox(self.attrs) for key, criteria in self.coordinate_criteria.items(): for criterion, expected in criteria.items(): if v["attributes"].get(criterion, None) in expected: @@ -196,8 +198,8 @@ def variables(self) -> dict: ) return variables - @property - @functools.cache + # @property + # @functools.cache def is_coordinate(self, attrs: dict) -> bool: """Return whether variable is a coordinate.""" for key, criteria in self.coordinate_criteria.items():