Skip to content

Commit

Permalink
maint: support latest pystac==1.12.1
Browse files Browse the repository at this point in the history
- pystac changed item_assets handling, used to be an extension
  but it is part of core spec now
- fix for calling to stackstac in bench code, current stackstac==0.5.1 can't handle
  newer version of proj extension, keep stac items from migrating to latest software version
  • Loading branch information
Kirill888 committed Feb 7, 2025
1 parent e903790 commit 37cc926
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
8 changes: 7 additions & 1 deletion odc/stac/bench/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,13 @@ def load_from_json(geojson, params: BenchLoadParams, **kw):
:param params: data loading configuration
:param kw: passed on to underlying data load function
"""
all_items = [pystac.item.Item.from_dict(f) for f in geojson["features"]]
# Don't migrate items when loading with stackstac. Migration to stac 1.1
# removes `proj:epsg` from the item properties that stackstac (==0.5.1 at
# the time of writing) uses to determine the CRS
migrate = kw.get("migrate", params.method == "odc-stac")
all_items = [
pystac.item.Item.from_dict(f, migrate=migrate) for f in geojson["features"]
]

opts = params.compute_args()
opts.update(**kw)
Expand Down
12 changes: 12 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ docs =
ipython
ipykernel

test =
pytest
pytest-cov
pytest-timeout
pystac_client
distributed
geopandas

test-all =
%(test)s
datacube
stackstac

[options.packages.find]
include =
Expand Down
10 changes: 5 additions & 5 deletions tests/test-env-py310.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ dependencies:
- pandas
- toolz
- odc-geo >=0.4.7
- pystac ==1.9.0
- dask ==2023.12.0
- xarray ==2023.12.0
- rasterio ==1.3.9
- pystac >=1.12.1
- dask
- xarray
- rasterio

# For mypy
- types-python-dateutil
Expand All @@ -36,7 +36,7 @@ dependencies:
- mock
- deepdiff
- pystac-client >=0.2.0
- geopandas <1
- geopandas
- stackstac
- zarr

Expand Down
16 changes: 12 additions & 4 deletions tests/test_eo3converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
_ = pytest.importorskip("datacube")

import uuid
from typing import Any

import pystac
import pystac.asset
Expand Down Expand Up @@ -55,7 +56,13 @@ def test_infer_product_collection(

# Check unhappy path
collection = sentinel_stac_collection.clone()
collection.stac_extensions.remove(ItemAssetsExtension.get_schema_uri())
item_assets = getattr(collection, "item_assets", None)
if item_assets is not None:
# newer pystac
item_assets.clear()
else:
collection.stac_extensions.remove(ItemAssetsExtension.get_schema_uri())

with pytest.raises(ValueError):
infer_dc_product(collection)

Expand Down Expand Up @@ -161,6 +168,7 @@ def test_item_to_ds_no_proj(sentinel_stac_ms: pystac.item.Item):

product = infer_dc_product(item, STAC_CFG)

assert item.geometry is not None
geom = Geometry(item.geometry, "EPSG:4326")
ds = _item_to_ds(item, product, STAC_CFG)
assert ds.crs == "EPSG:4326"
Expand Down Expand Up @@ -196,7 +204,7 @@ def test_item_uuid():
assert id1 != id2


def test_issue_n6(usgs_landsat_stac_v1):
def test_issue_n6(usgs_landsat_stac_v1: pystac.Item):
expected_bands = {
"blue",
"coastal",
Expand All @@ -213,12 +221,12 @@ def test_issue_n6(usgs_landsat_stac_v1):
assert set(p.measurements) == expected_bands


def test_partial_proj(partial_proj_stac):
def test_partial_proj(partial_proj_stac: pystac.Item):
(ds,) = list(stac2ds([partial_proj_stac]))
assert ds.metadata_doc["grids"]["default"]["shape"] == (1, 1)


def test_noassets_case(no_bands_stac):
def test_noassets_case(no_bands_stac: Any):
(ds,) = stac2ds([no_bands_stac])
assert len(ds.measurements) == 0

Expand Down

0 comments on commit 37cc926

Please sign in to comment.