Skip to content

Commit

Permalink
fix datacube extension
Browse files Browse the repository at this point in the history
  • Loading branch information
dchandan committed Oct 26, 2023
1 parent 65bd5bb commit f540dbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion STACpopulator/implementations/CMIP6_UofT/add_CMIP6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")

Expand Down
8 changes: 5 additions & 3 deletions STACpopulator/implementations/CMIP6_UofT/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`."""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit f540dbe

Please sign in to comment.