Skip to content

Fixup attrs #40

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 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __pycache__
htmlcov
dist
.direnv
.venv
8 changes: 8 additions & 0 deletions tests/test_xstac.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pyproj
import pytest
import pystac
Expand Down Expand Up @@ -164,3 +165,10 @@ def test_disable_infer_temporal_extent(ds, item_template):
# del item_template["properties"]["datetime"]
result = xarray_to_stac(ds, item_template, temporal_dimension=False)
assert "start_datetime" not in result.properties


def test_fixup_numpy_attrs_by_default(ds, item_template):
ds.prcp.attrs["values"] = np.zeros(2)
result = xarray_to_stac(ds, item_template, temporal_dimension=False)
assert result.properties["cube:variables"]["prcp"]["attrs"]["values"] == [0.0, 0.0]
json.dumps(result.to_dict())
2 changes: 2 additions & 0 deletions xstac/_xstac.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ def xarray_to_stac(
**additional_dimensions:
A dictionary with keys ``extent``, ``values``, ``step``.
"""
ds = fix_attrs(ds)

temporal_dimension = maybe_use_cf_standard_axis(
temporal_dimension, "temporal_dimension", ds
)
Expand Down
Loading