Skip to content

Add dimension names from coords for CRS lookup #42

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

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion tests/test_xstac.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import xarray as xr

from xstac import xarray_to_stac, fix_attrs
from xstac._xstac import _bbox_to_geometry, maybe_infer_reference_system
from xstac._xstac import _bbox_to_geometry, maybe_infer_reference_system, maybe_use_cf_standard_axis


# def test_no_time_dimension(ds, collection_template):
Expand Down Expand Up @@ -51,6 +51,22 @@ def test_xarray_to_stac(
assert dimensions == collection_expected_dims
assert result.extra_fields["cube:variables"] == collection_expected_vars

@pytest.mark.parametrize("dimension_key", ["x_dimension", "y_dimension", "temporal_dimension", "longitude", "latitude"])
def test_maybe_use_cf_standard_axis(ds, dimension_key):
match dimension_key:
case "x_dimension":
expected = "x"
case "y_dimension":
expected = "y"
case "temporal_dimension":
expected = "time"
case "longitude":
expected = "lon"
case "latitude":
expected = "lat"
case _:
expected = dimension_key
assert maybe_use_cf_standard_axis(None, dimension_key, ds) == expected

def test_validation_with_none(ds_without_spatial_dims):
# https://github.com/TomAugspurger/xstac/issues/9
Expand Down
2 changes: 1 addition & 1 deletion xstac/_xstac.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

SCHEMA_URI = "https://stac-extensions.github.io/datacube/v2.0.0/schema.json"

CF_STANDARD_AXES = dict(temporal_dimension="T", x_dimension="X", y_dimension="Y")
CF_STANDARD_AXES = dict(temporal_dimension="T", x_dimension="X", y_dimension="Y", latitude="latitude", longitude="longitude")


def maybe_use_cf_standard_axis(kw, kw_name, ds):
Expand Down