Skip to content

Commit d990c23

Browse files
author
Ariana Barzinpour
committed
Merge branch 'develop' into fix_odc_product_cache
2 parents a3b28e9 + b46d41c commit d990c23

17 files changed

+44
-26
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
- uses: conda-incubator/setup-miniconda@v3
6767
if: steps.conda_cache.outputs.cache-hit != 'true'
6868
with:
69-
miniforge-variant: Mambaforge
69+
miniforge-variant: Miniforge3
7070
miniforge-version: latest
7171
use-mamba: true
7272

@@ -108,7 +108,7 @@ jobs:
108108
- uses: conda-incubator/setup-miniconda@v3
109109
if: steps.binder_cache.outputs.cache-hit != 'true'
110110
with:
111-
miniforge-variant: Mambaforge
111+
miniforge-variant: Miniforge3
112112
miniforge-version: latest
113113
use-mamba: true
114114

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v5.0.0
44
hooks:
55
- id: end-of-file-fixer
66
- id: check-added-large-files

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ odc.stac.load
1818
catalog = pystac_client.Client.open(...)
1919
query = catalog.search(...)
2020
xx = odc.stac.load(
21-
query.get_items(),
21+
query.items(),
2222
bands=["red", "green", "blue"],
2323
)
2424
xx.red.plot.imshow(col="time")

docs/conf.py

-2
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ def ensure_notebooks(dst_folder):
135135
"python": ("https://docs.python.org/3", None),
136136
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
137137
"numpy": ("https://docs.scipy.org/doc/numpy/", None),
138-
"np": ("https://docs.scipy.org/doc/numpy/", None),
139138
"xarray": ("https://xarray.pydata.org/en/stable/", None),
140-
"xr": ("https://xarray.pydata.org/en/stable/", None),
141139
"datacube": ("https://datacube-core.readthedocs.io/en/latest/", None),
142140
"odc-geo": ("https://odc-geo.readthedocs.io/en/latest/", None),
143141
"pystac": ("https://pystac.readthedocs.io/en/latest/", None),

docs/intro.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Load STAC :py:class:`pystac.Item`\s into :py:class:`xarray.Dataset`.
1010
catalog = pystac_client.Client.open(...)
1111
query = catalog.search(...)
1212
xx = odc.stac.load(
13-
query.get_items(),
13+
query.items(),
1414
bands=["red", "green", "blue"],
1515
resolution=100,
1616
)

docs/samples/save-cog-from-stac.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
collections=["landsat-8-c2-l2"],
4242
datetime="2021-07-01T08:00:00Z/2021-07-01T09:00:00Z",
4343
bbox=(-180, -50, 180, 50),
44-
).get_all_items()
44+
).item_collection()
4545

4646
# Compute Polygon of the pass in EPSG:3857
4747
ls8_pass = geom.unary_union(

odc/loader/_builder.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
)
4343
from ._utils import SizedIterable, pmap
4444
from .types import (
45+
Band_DType,
4546
DaskRasterReader,
4647
MultiBandRasterSource,
4748
RasterGroupMetadata,
@@ -609,6 +610,7 @@ def chunked_load(
609610
env: Dict[str, Any],
610611
rdr: ReaderDriver,
611612
*,
613+
dtype: Band_DType = None,
612614
chunks: Mapping[str, int | Literal["auto"]] | None = None,
613615
pool: ThreadPoolExecutor | int | None = None,
614616
progress: Optional[Any] = None,
@@ -640,6 +642,7 @@ def chunked_load(
640642
env,
641643
rdr,
642644
chunks=chunks,
645+
dtype=dtype,
643646
)
644647

645648

@@ -653,6 +656,7 @@ def dask_chunked_load(
653656
env: Dict[str, Any],
654657
rdr: ReaderDriver,
655658
*,
659+
dtype: Band_DType = None,
656660
chunks: Mapping[str, int | Literal["auto"]] | None = None,
657661
) -> xr.Dataset:
658662
"""Builds Dask graph for data loading."""
@@ -662,10 +666,7 @@ def dask_chunked_load(
662666
gbox = gbt.base
663667
extra_dims = template.extra_dims_full()
664668
chunk_shape = resolve_chunk_shape(
665-
len(tss),
666-
gbox,
667-
chunks,
668-
extra_dims=extra_dims,
669+
len(tss), gbox, chunks, extra_dims=extra_dims, dtype=dtype
669670
)
670671
chunks_normalized = dict(zip(["time", "y", "x", *extra_dims], chunk_shape))
671672
dask_loader = DaskGraphBuilder(

odc/loader/_reader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
import numpy as np
1414
from dask import delayed
15-
from numpy.typing import DTypeLike
1615
from odc.geo.geobox import GeoBox
1716

1817
from .types import (
18+
Band_DType,
1919
RasterBandMetadata,
2020
RasterLoadParams,
2121
RasterSource,
@@ -115,7 +115,7 @@ def open(
115115
def resolve_load_cfg(
116116
bands: dict[str, RasterBandMetadata],
117117
resampling: str | dict[str, str] | None = None,
118-
dtype: DTypeLike | dict[str, DTypeLike] | None = None,
118+
dtype: Band_DType | None = None,
119119
use_overviews: bool = True,
120120
nodata: float | None = None,
121121
fail_on_error: bool = True,

odc/loader/types.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919

2020
import numpy as np
21+
from numpy.typing import DTypeLike
2122
from odc.geo import Unset
2223
from odc.geo.geobox import GeoBox, GeoBoxBase
2324

@@ -34,6 +35,8 @@
3435

3536
ReaderSubsetSelection = Any
3637

38+
Band_DType = Union[DTypeLike, Mapping[str, DTypeLike]]
39+
3740

3841
@dataclass(eq=True, frozen=True)
3942
class RasterBandMetadata:

odc/stac/_stac_load.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import pystac.item
2727
import xarray as xr
2828
from dask.utils import ndeepmap
29-
from numpy.typing import DTypeLike
3029
from odc.geo import CRS, MaybeCRS, SomeResolution
3130
from odc.geo.geobox import GeoBox, GeoboxAnchor, GeoboxTiles
3231
from odc.geo.types import Unset
@@ -37,7 +36,7 @@
3736
resolve_chunk_shape,
3837
resolve_load_cfg,
3938
)
40-
from odc.loader.types import ReaderDriverSpec
39+
from odc.loader.types import ReaderDriverSpec, Band_DType
4140

4241
from ._mdtools import ConversionConfig, output_geobox, parse_items
4342
from .model import BandQuery, ParsedItem, RasterCollectionMetadata
@@ -90,7 +89,7 @@ def load(
9089
*,
9190
groupby: Optional[Groupby] = "time",
9291
resampling: Optional[Union[str, Dict[str, str]]] = None,
93-
dtype: Union[DTypeLike, Dict[str, DTypeLike], None] = None,
92+
dtype: Band_DType = None,
9493
chunks: Optional[Dict[str, int | Literal["auto"]]] = None,
9594
pool: Union[ThreadPoolExecutor, int, None] = None,
9695
# Geo selection
@@ -105,6 +104,7 @@ def load(
105104
y: Optional[Tuple[float, float]] = None,
106105
like: Optional[Any] = None,
107106
geopolygon: Optional[Any] = None,
107+
intersects: Optional[Any] = None,
108108
# UI
109109
progress: Optional[Any] = None,
110110
fail_on_error: bool = True,
@@ -130,7 +130,7 @@ def load(
130130
catalog = pystac.Client.open(...)
131131
query = catalog.search(...)
132132
xx = odc.stac.load(
133-
query.get_items(),
133+
query.items(),
134134
bands=["red", "green", "blue"],
135135
)
136136
xx.red.plot.imshow(col="time")
@@ -263,6 +263,10 @@ def load(
263263
``EPSG:4326`` projection for dictionary and Shapely inputs. CRS information available
264264
on GeoPandas inputs should be understood correctly.
265265
266+
:param intersects:
267+
Simple alias to `geopolygon` so that the same inputs work for `pystac_client.Client.search`
268+
as they do here.
269+
266270
.. rubric:: STAC Related Options
267271
268272
:param stac_cfg:
@@ -293,7 +297,7 @@ def load(
293297
)
294298
295299
xx = stac.load(
296-
query.get_items(),
300+
query.items(),
297301
bands=["red", "green", "blue"],
298302
resolution=100, # 1/10 of the native 10m resolution
299303
patch_url=pc.sign,
@@ -355,6 +359,9 @@ def load(
355359
items = list(items)
356360
_parsed = list(parse_items(items, cfg=stac_cfg, md_plugin=md_plugin))
357361

362+
if geopolygon is None and intersects is not None:
363+
geopolygon = intersects
364+
358365
gbox = output_geobox(
359366
_parsed,
360367
bands=bands,
@@ -459,6 +466,7 @@ def _with_debug_info(ds: xr.Dataset, **kw) -> xr.Dataset:
459466
chunks=chunks,
460467
pool=pool,
461468
progress=progress,
469+
dtype=dtype,
462470
)
463471
)
464472

odc/stac/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""version information only."""
22

3-
__version__ = "0.3.10"
3+
__version__ = "0.3.11"

odc/stac/bench/_prepare.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def dump_site(site: Dict[str, Any], overwrite: bool = False) -> Dict[str, Any]:
6565
cat = pystac_client.Client.open(api)
6666
search = cat.search(**search)
6767
print(f"Query API end-point: {api}")
68-
all_features = search.get_all_items_as_dict()
68+
all_features = search.item_collection_as_dict()
6969
all_features["properties"] = dict(
7070
api=search.url, search=search._parameters # pylint: disable=protected-access
7171
)

odc/stac/bench/_run.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,9 @@ def compute_args(self, method: str = "") -> Dict[str, Any]:
360360
assets = list(self.bands)
361361

362362
extra.setdefault("dtype", "uint16")
363-
extra.setdefault("fill_value", 0)
363+
extra.setdefault("fill_value", np.uint16(0))
364364
extra.setdefault("xy_coords", "center")
365+
extra.setdefault("rescale", False)
365366

366367
return _trim_dict(
367368
{
@@ -380,7 +381,7 @@ def compute_args(self, method: str = "") -> Dict[str, Any]:
380381
def _default_nodata(dtype):
381382
if dtype.kind == "f":
382383
return float("nan")
383-
return 0
384+
return dtype.type(0)
384385

385386

386387
def load_from_json(geojson, params: BenchLoadParams, **kw):

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ requires = ["setuptools>=51.0.0", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.mypy]
6-
python_version = "3.9"
6+
python_version = "3.10"
77
ignore_missing_imports = true
88
allow_redefinition = true
9+
plugins = "numpy.typing.mypy_plugin"
910

1011
[tool.coverage.run]
1112
omit = [

requirements-dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ planetary-computer
1414
pylint
1515
isort
1616
pytest
17+
pandas-stubs

tests/notebooks/bench-prep-query.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
bbox=bbox,
5656
)
5757
print("Query API end-point")
58-
all_features = search.get_all_items_as_dict()
58+
all_features = search.item_collection_as_dict()
5959

6060
all_features["properties"] = dict(url=search.url, query=search._parameters)
6161
all_features["properties"]

tests/test_bench.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from unittest.mock import MagicMock
88

99
import xarray
10+
import numpy as np
1011
from distributed import Client
1112
from odc.geo.xr import ODCExtension
1213

@@ -107,7 +108,11 @@ def test_load_from_json_stackstac(fake_dask_client, bench_site1, bench_site2):
107108
resampling="nearest",
108109
extra={
109110
"odc-stac": {"groupby": "solar_day", "stac_cfg": CFG},
110-
"stackstac": {"dtype": "uint16", "fill_value": 0},
111+
"stackstac": {
112+
"dtype": "uint16",
113+
"fill_value": np.uint16(0),
114+
"rescale": False,
115+
},
111116
},
112117
)
113118
xx = load_from_json(bench_site1, params)

0 commit comments

Comments
 (0)