Skip to content
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

add kwargs to xarrayReader methods for compatibility #762

Merged
merged 4 commits into from
Nov 5, 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
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 7.2.0 (2024-11-05)

* Ensure compatibility between XarrayReader and other Readers by adding `**kwargs` on class methods (https://github.com/cogeotiff/rio-tiler/pull/762)

* add `STACReader.get_asset_list()` method to enable easier customization of the asset listing/validation (https://github.com/cogeotiff/rio-tiler/pull/762)

# 7.1.0 (2024-10-29)

* Add `preview()` and `statistics()` methods to XarrayReader (https://github.com/cogeotiff/rio-tiler/pull/755)
Expand Down
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ nav:
- rio-tiler + STAC: 'examples/Using-rio-tiler-STACReader.ipynb'
- Non-Earth dataset: 'examples/Using-nonEarth-dataset.ipynb'
- Xarray + rio-tiler: 'examples/Using-rio-tiler-XarrayReader.ipynb'
- STAC + Xarray: 'examples/STAC_datacube_support.ipynb'
- Migration Guides:
- v1.0 -> v2.0: 'migrations/v2_migration.md'
- v2.0 -> v3.0: 'migrations/v3_migration.md'
Expand Down
515 changes: 515 additions & 0 deletions docs/src/examples/STAC_datacube_support.ipynb

Large diffs are not rendered by default.

Binary file added docs/src/examples/data/dataset_2d.nc
Binary file not shown.
111 changes: 111 additions & 0 deletions docs/src/examples/data/stac_netcdf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "my_stac",
"properties": {
"proj:epsg": 4326,
"proj:geometry": {
"type": "Polygon",
"coordinates": [
[
[
-170.085,
79.91999999999659
],
[
169.91499999997504,
79.91999999999659
],
[
169.91499999997504,
-80.08
],
[
-170.085,
-80.08
],
[
-170.085,
79.91999999999659
]
]
]
},
"proj:bbox": [
-170.085,
79.91999999999659,
169.91499999997504,
-80.08
],
"proj:shape": [
1000,
2000
],
"proj:transform": [
0.16999999999998752,
0,
-170.085,
0,
0.1599999999999966,
-80.08,
0,
0,
1
],
"datetime": "2024-11-05T09:03:47.523834Z"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-170.085,
79.91999999999659
],
[
169.91499999997504,
79.91999999999659
],
[
169.91499999997504,
-80.08
],
[
-170.085,
-80.08
],
[
-170.085,
79.91999999999659
]
]
]
},
"links": [],
"assets": {
"netcdf": {
"href": "dataset_2d.nc",
"type": "application/x-netcdf",
"roles": ["data"],
"cube:variables": {
"dataset": {
"dimensions": [
"y",
"x"
],
"type": "data"
}
}
}
},
"bbox": [
-170.085,
-80.08,
169.91499999997504,
79.91999999999659
],
"stac_extensions": [
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"https://stac-extensions.github.io/datacube/v2.2.0/schema.json"
]
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ test = [
# XarrayReader
"xarray",
"rioxarray",
"h5netcdf",
# S3
"boto3",
# Some tests will fail with 5.0
Expand Down
23 changes: 19 additions & 4 deletions rio_tiler/io/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
import json
import os
import warnings
from typing import Any, Dict, Iterator, Optional, Sequence, Set, Tuple, Type, Union
from typing import (
Any,
Dict,
Iterator,
List,
Optional,
Sequence,
Set,
Tuple,
Type,
Union,
)
from urllib.parse import urlparse

import attr
Expand Down Expand Up @@ -273,7 +284,13 @@ def __attrs_post_init__(self):
self.minzoom = self.minzoom if self.minzoom is not None else self._minzoom
self.maxzoom = self.maxzoom if self.maxzoom is not None else self._maxzoom

self.assets = list(
self.assets = self.get_asset_list()
if not self.assets:
raise MissingAssets("No valid asset found. Asset's media types not supported")

def get_asset_list(self) -> List[str]:
"""Get valid asset list"""
return list(
_get_assets(
self.item,
include=self.include_assets,
Expand All @@ -282,8 +299,6 @@ def __attrs_post_init__(self):
exclude_asset_types=self.exclude_asset_types,
)
)
if not self.assets:
raise MissingAssets("No valid asset found. Asset's media types not supported")

def _get_reader(self, asset_info: AssetInfo) -> Tuple[Type[BaseReader], Dict]:
"""Get Asset Reader."""
Expand Down
8 changes: 7 additions & 1 deletion rio_tiler/io/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import warnings
from typing import Dict, List, Optional
from typing import Any, Dict, List, Optional

import attr
import numpy
Expand Down Expand Up @@ -156,6 +156,7 @@ def statistics(
percentiles: Optional[List[int]] = None,
hist_options: Optional[Dict] = None,
nodata: Optional[NoData] = None,
**kwargs: Any,
) -> Dict[str, BandStatistics]:
"""Return statistics from a dataset."""
hist_options = hist_options or {}
Expand Down Expand Up @@ -188,6 +189,7 @@ def tile(
reproject_method: WarpResampling = "nearest",
auto_expand: bool = True,
nodata: Optional[NoData] = None,
**kwargs: Any,
) -> ImageData:
"""Read a Web Map tile from a dataset.

Expand Down Expand Up @@ -264,6 +266,7 @@ def part(
height: Optional[int] = None,
width: Optional[int] = None,
resampling_method: RIOResampling = "nearest",
**kwargs: Any,
) -> ImageData:
"""Read part of a dataset.

Expand Down Expand Up @@ -362,6 +365,7 @@ def preview(
dst_crs: Optional[CRS] = None,
reproject_method: WarpResampling = "nearest",
resampling_method: RIOResampling = "nearest",
**kwargs: Any,
) -> ImageData:
"""Return a preview of a dataset.

Expand Down Expand Up @@ -446,6 +450,7 @@ def point(
lat: float,
coord_crs: CRS = WGS84_CRS,
nodata: Optional[NoData] = None,
**kwargs: Any,
) -> PointData:
"""Read a pixel value from a dataset.

Expand Down Expand Up @@ -499,6 +504,7 @@ def feature(
height: Optional[int] = None,
width: Optional[int] = None,
resampling_method: RIOResampling = "nearest",
**kwargs: Any,
) -> ImageData:
"""Read part of a dataset defined by a geojson feature.

Expand Down
Binary file added tests/fixtures/dataset_2d.nc
Binary file not shown.
Binary file added tests/fixtures/dataset_2d.tif
Binary file not shown.
106 changes: 106 additions & 0 deletions tests/fixtures/stac_netcdf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "my_stac",
"properties": {
"proj:epsg": 4326,
"proj:geometry": {
"type": "Polygon",
"coordinates": [
[
[
-170.085,
79.91999999999659
],
[
169.91499999997504,
79.91999999999659
],
[
169.91499999997504,
-80.08
],
[
-170.085,
-80.08
],
[
-170.085,
79.91999999999659
]
]
]
},
"proj:bbox": [
-170.085,
79.91999999999659,
169.91499999997504,
-80.08
],
"proj:shape": [
1000,
2000
],
"proj:transform": [
0.16999999999998752,
0,
-170.085,
0,
0.1599999999999966,
-80.08,
0,
0,
1
],
"datetime": "2024-11-05T09:03:47.523834Z"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-170.085,
79.91999999999659
],
[
169.91499999997504,
79.91999999999659
],
[
169.91499999997504,
-80.08
],
[
-170.085,
-80.08
],
[
-170.085,
79.91999999999659
]
]
]
},
"links": [],
"assets": {
"geotiff": {
"href": "dataset_2d.tif",
"type": "image/tiff; application=geotiff",
"roles": ["data"]
},
"netcdf": {
"href": "dataset_2d.nc",
"type": "application/x-netcdf",
"roles": ["data"]
}
},
"bbox": [
-170.085,
-80.08,
169.91499999997504,
79.91999999999659
],
"stac_extensions": [
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
]
}
Loading
Loading