Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in datacube extension. #33

Merged
merged 7 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased](https://github.com/crim-ca/stac-populator) (latest)

<!-- insert list items of new changes here -->
* Fix datacube extension creation to match schema.

## [0.2.0](https://github.com/crim-ca/stac-populator/tree/0.2.0) (2023-11-10)

Expand Down
34 changes: 22 additions & 12 deletions STACpopulator/implementations/CMIP6_UofT/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class DataCubeHelper:
"""Return STAC Item from CF JSON metadata, as provided by `xncml.Dataset.to_cf_dict`."""

axis = {"X": "x", "Y": "y", "Z": "z", "T": "t", "longitude": "x", "latitude": "y", "vertical": "z", "time": "t"}
axis = {"X": "x", "Y": "y", "Z": "z", "T": None, "longitude": "x", "latitude": "y", "vertical": "z", "time": "t"}

def __init__(self, attrs: dict):
"""
Expand Down Expand Up @@ -145,6 +145,7 @@ def __init__(self, attrs: dict):
def dimensions(self) -> dict:
"""Return Dimension objects required for Datacube extension."""


dims = {}
for name, length in self.attrs["dimensions"].items():
v = self.attrs["variables"].get(name)
Expand All @@ -163,17 +164,20 @@ def dimensions(self) -> dict:
extent = bbox[0], bbox[2]
elif key == "Y":
extent = bbox[1], bbox[3]
elif key in ["T", "time"]:
extent = self.temporal_extent()
else:
extent = None

dims[name] = Dimension(
properties=dict(
axis=axis,
type=type_,
extent=extent,
description=v.get("description", v.get("long_name", criteria["standard_name"])),
)
extent = ["", ""]

properties = dict(
type=type_.value,
extent=extent,
description=v.get("description", v.get("long_name", criteria["standard_name"][0])) or "",
)
if type_ == DimensionType.SPATIAL:
properties["axis"] = axis

dims[name] = Dimension(properties=properties)

return dims

Expand All @@ -192,8 +196,8 @@ def variables(self) -> dict:
properties=dict(
dimensions=meta["shape"],
type=VariableType.AUXILIARY.value if self.is_coordinate(attrs) else VariableType.DATA.value,
description=attrs.get("description", attrs.get("long_name")),
unit=attrs.get("units", None),
description=attrs.get("description", attrs.get("long_name", "")),
unit=attrs.get("units", ""),
)
)
return variables
Expand All @@ -207,3 +211,9 @@ def is_coordinate(self, attrs: dict) -> bool:
if attrs.get(criterion, None) in expected:
return True
return False

def temporal_extent(self):
cfmeta = self.attrs["groups"]["CFMetadata"]["attributes"]
start_datetime = cfmeta["time_coverage_start"]
end_datetime = cfmeta["time_coverage_end"]
return [start_datetime, end_datetime]
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ dev = [
"pytest-cov",
"coverage",
"bump-my-version",
"jsonschema",
huard marked this conversation as resolved.
Show resolved Hide resolved
]

[tool.pytest.ini_options]
Expand Down
Loading
Loading