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 Xarray sub-package #1013

Merged
merged 19 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
python -m pip install -e src/titiler/extensions["test,cogeo,stac"]
python -m pytest src/titiler/extensions --cov=titiler.extensions --cov-report=xml --cov-append --cov-report=term-missing

- name: Test titiler.xarray
run: |
python -m pip install -e src/titiler/xarray["test,all"]
python -m pytest src/titiler/xarray --cov=titiler.xarray --cov-report=xml --cov-append --cov-report=term-missing

- name: Test titiler.mosaic
run: |
python -m pip install -e src/titiler/mosaic["test"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy_mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install src/titiler/core src/titiler/extensions["cogeo,stac"] src/titiler/mosaic src/titiler/application
python -m pip install src/titiler/core src/titiler/extensions["cogeo,stac"] src/titiler/xarray src/titiler/mosaic src/titiler/application
python -m pip install -r requirements/requirements-docs.txt


Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Starting with version `0.3.0`, the `TiTiler` python module has been split into a
| Package | Version | Description
| ------- | ------- |-------------
[**titiler.core**](https://github.com/developmentseed/titiler/tree/main/src/titiler/core) | [![titiler.core](https://img.shields.io/pypi/v/titiler.core?color=%2334D058&label=pypi)](https://pypi.org/project/titiler.core) | The `Core` package contains libraries to help create a dynamic tiler for COG and STAC
[**titiler.xarray**](https://github.com/developmentseed/titiler/tree/main/src/titiler/xarray) | [![titiler.xarray](https://img.shields.io/pypi/v/titiler.xarray?color=%2334D058&label=pypi)](https://pypi.org/project/titiler.xarray) | The `xarray` package contains libraries to help create a dynamic tiler for Zarr/NetCDF datasets
[**titiler.extensions**](https://github.com/developmentseed/titiler/tree/main/src/titiler/extensions) | [![titiler.extensions](https://img.shields.io/pypi/v/titiler.extensions?color=%2334D058&label=pypi)](https://pypi.org/project/titiler.extensions) | TiTiler's extensions package. Contains extensions for Tiler Factories.
[**titiler.mosaic**](https://github.com/developmentseed/titiler/tree/main/src/titiler/mosaic) | [![titiler.mosaic](https://img.shields.io/pypi/v/titiler.mosaic?color=%2334D058&label=pypi)](https://pypi.org/project/titiler.mosaic) | The `mosaic` package contains libraries to help create a dynamic tiler for MosaicJSON (adds `cogeo-mosaic` requirement)
[**titiler.application**](https://github.com/developmentseed/titiler/tree/main/src/titiler/application) | [![titiler.application](https://img.shields.io/pypi/v/titiler.application?color=%2334D058&label=pypi)](https://pypi.org/project/titiler.application) | TiTiler's `demo` package. Contains a FastAPI application with full support of COG, STAC and MosaicJSON
Expand All @@ -71,6 +72,7 @@ python -m pip install -U pip
python -m pip install titiler.{package}
# e.g.,
# python -m pip install titiler.core
# python -m pip install titiler.xarray
# python -m pip install titiler.extensions
# python -m pip install titiler.mosaic
# python -m pip install titiler.application (also installs core, extensions and mosaic)
Expand All @@ -89,7 +91,7 @@ git clone https://github.com/developmentseed/titiler.git
cd titiler

python -m pip install -U pip
python -m pip install -e src/titiler/core -e src/titiler/extensions -e src/titiler/mosaic -e src/titiler/application
python -m pip install -e src/titiler/core -e src/titiler/xarray -e src/titiler/extensions -e src/titiler/mosaic -e src/titiler/application
python -m pip install uvicorn

uvicorn titiler.application.main:app --reload
Expand Down Expand Up @@ -125,6 +127,7 @@ Some options can be set via environment variables, see: https://github.com/tiang
src/titiler/ - titiler modules.
├── application/ - Titiler's `Application` package
├── extensions/ - Titiler's `Extensions` package
├── xarray/ - Titiler's `Xarray` package
├── core/ - Titiler's `Core` package
└── mosaic/ - Titiler's `Mosaic` package
```
Expand Down
1 change: 1 addition & 0 deletions scripts/publish
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

SUBPACKAGE_DIRS=(
"core"
"xarray"
"mosaic"
"application"
"extensions"
Expand Down
2 changes: 1 addition & 1 deletion src/titiler/core/titiler/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ def bbox_image(
):
"""Create image from a bbox."""
with rasterio.Env(**env):
with self.reader(src_path, **reader_params) as src_dst:
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
image = src_dst.part(
[minx, miny, maxx, maxy],
dst_crs=dst_crs,
Expand Down
46 changes: 46 additions & 0 deletions src/titiler/xarray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## titiler.xarray

Adds support for Xarray Dataset (NetCDF/Zarr) in Titiler.

## Installation

```bash
$ python -m pip install -U pip

# From Pypi
$ python -m pip install titiler.xarray

# Or from sources
$ git clone https://github.com/developmentseed/titiler.git
$ cd titiler && python -m pip install -e src/titiler/core -e src/titiler/xarray
```

## How To

```python
from fastapi import FastAPI
from titiler.xarray.factory import TilerFactory

# Create a FastAPI application
app = FastAPI(
description="A lightweight Cloud Optimized GeoTIFF tile server",
)

# Create a set of MosaicJSON endpoints
endpoint = TilerFactory()

# Register the Mosaic endpoints to the application
app.include_router(endpoint.router)
```

## Package structure

```
titiler/
└── xarray/
├── tests/ - Tests suite
└── titiler/xarray/ - `xarray` namespace package
├── dependencies.py - titiler-xarray dependencies
├── io.py - titiler-xarray Readers
└── factory.py - endpoints factory
```
69 changes: 69 additions & 0 deletions src/titiler/xarray/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[project]
name = "titiler.xarray"
description = "Xarray plugin for TiTiler."
readme = "README.md"
requires-python = ">=3.8"
authors = [
{name = "Vincent Sarago", email = "[email protected]"},
{name = "Aimee Barciauskas", email = "[email protected]"},
]
license = {text = "MIT"}
keywords = [
"TiTiler",
"Xarray",
"Zarr",
"NetCDF",
"HDF",
]
classifiers = [
"Intended Audience :: Information Technology",
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: GIS",
]
dynamic = ["version"]
dependencies = [
"titiler.core==0.19.0.dev",
"xarray",
"rioxarray",
]

[project.optional-dependencies]
all = [
"zarr",
"h5netcdf",
"fsspec",
"s3fs",
"aiohttp",
]
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
test = [
"pytest",
"pytest-cov",
"pytest-asyncio",
"httpx",
]

[project.urls]
Homepage = "https://developmentseed.org/titiler/"
Documentation = "https://developmentseed.org/titiler/"
Issues = "https://github.com/developmentseed/titiler/issues"
Source = "https://github.com/developmentseed/titiler"
Changelog = "https://developmentseed.org/titiler/release-notes/"

[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"

[tool.pdm.version]
source = "file"
path = "titiler/xarray/__init__.py"

[tool.pdm.build]
includes = ["titiler/xarray"]
excludes = ["tests/", "**/.mypy_cache", "**/.DS_Store"]
1 change: 1 addition & 0 deletions src/titiler/xarray/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""titiler.xarray test configuration."""
Binary file added src/titiler/xarray/tests/fixtures/dataset_2d.nc
Binary file not shown.
Binary file added src/titiler/xarray/tests/fixtures/dataset_3d.nc
Binary file not shown.
1 change: 1 addition & 0 deletions src/titiler/xarray/tests/fixtures/dataset_3d.zarr/.zattrs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions src/titiler/xarray/tests/fixtures/dataset_3d.zarr/.zgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
119 changes: 119 additions & 0 deletions src/titiler/xarray/tests/fixtures/dataset_3d.zarr/.zmetadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"metadata": {
".zattrs": {},
".zgroup": {
"zarr_format": 2
},
"dataset/.zarray": {
"chunks": [
1,
250,
500
],
"compressor": {
"blocksize": 0,
"clevel": 5,
"cname": "lz4",
"id": "blosc",
"shuffle": 1
},
"dtype": "<f8",
"fill_value": "NaN",
"filters": null,
"order": "C",
"shape": [
2,
1000,
2000
],
"zarr_format": 2
},
"dataset/.zattrs": {
"_ARRAY_DIMENSIONS": [
"time",
"y",
"x"
],
"valid_max": 1000.0,
"valid_min": 0.0
},
"time/.zarray": {
"chunks": [
2
],
"compressor": {
"blocksize": 0,
"clevel": 5,
"cname": "lz4",
"id": "blosc",
"shuffle": 1
},
"dtype": "<i8",
"fill_value": null,
"filters": null,
"order": "C",
"shape": [
2
],
"zarr_format": 2
},
"time/.zattrs": {
"_ARRAY_DIMENSIONS": [
"time"
],
"calendar": "proleptic_gregorian",
"units": "days since 2022-01-01 00:00:00"
},
"x/.zarray": {
"chunks": [
2000
],
"compressor": {
"blocksize": 0,
"clevel": 5,
"cname": "lz4",
"id": "blosc",
"shuffle": 1
},
"dtype": "<f8",
"fill_value": "NaN",
"filters": null,
"order": "C",
"shape": [
2000
],
"zarr_format": 2
},
"x/.zattrs": {
"_ARRAY_DIMENSIONS": [
"x"
]
},
"y/.zarray": {
"chunks": [
1000
],
"compressor": {
"blocksize": 0,
"clevel": 5,
"cname": "lz4",
"id": "blosc",
"shuffle": 1
},
"dtype": "<f8",
"fill_value": "NaN",
"filters": null,
"order": "C",
"shape": [
1000
],
"zarr_format": 2
},
"y/.zattrs": {
"_ARRAY_DIMENSIONS": [
"y"
]
}
},
"zarr_consolidated_format": 1
}
24 changes: 24 additions & 0 deletions src/titiler/xarray/tests/fixtures/dataset_3d.zarr/dataset/.zarray
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"chunks": [
1,
250,
500
],
"compressor": {
"blocksize": 0,
"clevel": 5,
"cname": "lz4",
"id": "blosc",
"shuffle": 1
},
"dtype": "<f8",
"fill_value": "NaN",
"filters": null,
"order": "C",
"shape": [
2,
1000,
2000
],
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_ARRAY_DIMENSIONS": [
"time",
"y",
"x"
],
"valid_max": 1000.0,
"valid_min": 0.0
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions src/titiler/xarray/tests/fixtures/dataset_3d.zarr/time/.zarray
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"chunks": [
2
],
"compressor": {
"blocksize": 0,
"clevel": 5,
"cname": "lz4",
"id": "blosc",
"shuffle": 1
},
"dtype": "<i8",
"fill_value": null,
"filters": null,
"order": "C",
"shape": [
2
],
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"_ARRAY_DIMENSIONS": [
"time"
],
"calendar": "proleptic_gregorian",
"units": "days since 2022-01-01 00:00:00"
}
Binary file not shown.
Loading
Loading