Skip to content

Commit

Permalink
Fixup attrs (#40)
Browse files Browse the repository at this point in the history
* Fixup attrs
  • Loading branch information
ghidalgo3 authored Aug 23, 2024
1 parent f078c9b commit c9e666f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
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

0 comments on commit c9e666f

Please sign in to comment.