Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ cdk.out/
node_modules
cdk.context.json
*.nc
.DS_Store
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Example of application built with `titiler.xarray` [package](https://development
# It's recommended to install dependencies in a virtual environment
uv sync --dev
export TEST_ENVIRONMENT=true # set this when running locally to mock redis
#optional: Disable caching
#export TITILER_MULTIDIM_ENABLE_CACHE=false
uv run uvicorn titiler.multidim.main:app --reload
```

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies = [
"requests",
"rioxarray",
"s3fs",
"xarray",
"zarr>=2,<3",
"xarray>2025.07.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pickling problem is solved if we bump this up to 2025.10.1!

"zarr>3.1.0",
]

[project.optional-dependencies]
Expand All @@ -56,6 +56,7 @@ lambda = [

[dependency-groups]
dev = [
"dask>=2025.9.1",
"fakeredis>=2.23.5",
"httpx",
"ipykernel>=6.30.1",
Expand Down
2 changes: 2 additions & 0 deletions src/titiler/multidim/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def __attrs_post_init__(self):
group=self.group,
decode_times=self.decode_times,
)
print(f"DEBUG: Dataset id {id(self.ds)} opened from {self.src_path}")
print(f"DEBUG: {api_settings.enable_cache=}")

if not ds and api_settings.enable_cache:
# Serialize the dataset to bytes using pickle
Expand Down
30 changes: 26 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
"""titiler.multidim tests configuration."""
"""Auto-parametrized fixture that runs both cache configurations."""

import sys
import pytest
from fastapi.testclient import TestClient


@pytest.fixture
def app(monkeypatch):
"""App fixture."""
# This fixture will automatically parametrize ALL tests that use it
@pytest.fixture(
params=[
pytest.param({"cache": True}, id="with_cache"),
pytest.param({"cache": False}, id="without_cache"),
]
)
def app(request, monkeypatch):
"""Auto-parametrized app fixture that runs tests with both cache configurations."""
config = request.param
enable_cache = config.get("cache", False)

# Set environment variables using monkeypatch (auto-cleanup)
monkeypatch.setenv("TITILER_MULTIDIM_DEBUG", "TRUE")
monkeypatch.setenv("TEST_ENVIRONMENT", "1")
monkeypatch.setenv(
"TITILER_MULTIDIM_ENABLE_CACHE", "TRUE" if enable_cache else "FALSE"
)

# Clear module cache to ensure fresh import
modules_to_clear = [
key for key in sys.modules.keys() if key.startswith("titiler.multidim")
]
for module in modules_to_clear:
del sys.modules[module]

# Import and return the app
from titiler.multidim.main import app

with TestClient(app) as client:
Expand Down
32 changes: 23 additions & 9 deletions tests/fixtures/generate_test_zarr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Create zarr fixture."""
"""Create zarr fixtures for v2 and v3."""

import numpy as np
import xarray as xr
Expand All @@ -8,31 +8,32 @@
time_dim = 10
lat_dim = 36
lon_dim = 72
chunk_size = (10, 10, 10)
chunk_size = {"time": 10, "lat": 10, "lon": 10}

# Create coordinates
time = np.arange(time_dim)
lat = np.linspace(-90 + res / 2, 90 - res / 2, lat_dim)
lon = np.linspace(-180 + res / 2, 180 - res / 2, lon_dim)
lat = np.linspace(-90.0 + res / 2, 90.0 - res / 2, lat_dim)
lon = np.linspace(-180.0 + res / 2, 180.0 - res / 2, lon_dim)

dtype = np.float64
# Initialize variables with random data
CDD0 = xr.DataArray(
np.random.rand(time_dim, lat_dim, lon_dim).astype(np.uint8),
np.random.rand(time_dim, lat_dim, lon_dim).astype(dtype),
dims=("time", "lat", "lon"),
name="CDD0",
)
DISPH = xr.DataArray(
np.random.rand(time_dim, lat_dim, lon_dim).astype(np.uint8),
np.random.rand(time_dim, lat_dim, lon_dim).astype(dtype),
dims=("time", "lat", "lon"),
name="DISPH",
)
FROST_DAYS = xr.DataArray(
np.random.rand(time_dim, lat_dim, lon_dim).astype(np.uint8),
np.random.rand(time_dim, lat_dim, lon_dim).astype(dtype),
dims=("time", "lat", "lon"),
name="FROST_DAYS",
)
GWETPROF = xr.DataArray(
np.random.rand(time_dim, lat_dim, lon_dim).astype(np.uint8),
np.random.rand(time_dim, lat_dim, lon_dim).astype(dtype),
dims=("time", "lat", "lon"),
name="GWETPROF",
)
Expand All @@ -49,4 +50,17 @@
)

# Save dataset to a local Zarr store
ds.to_zarr("tests/fixtures/test_zarr_store.zarr", mode="w")
ds.to_zarr(
"tests/fixtures/zarr_store_v3.zarr",
mode="w",
zarr_format=3,
consolidated=False,
)

# Save dataset to a local Zarr store
ds.to_zarr(
"tests/fixtures/zarr_store_v2.zarr",
mode="w",
zarr_format=2,
consolidated=True,
)
72 changes: 0 additions & 72 deletions tests/fixtures/responses/test_zarr_store_zarr_histogram.json

This file was deleted.

14 changes: 0 additions & 14 deletions tests/fixtures/responses/test_zarr_store_zarr_info.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"scheme": "xyz",
"tiles": [
"http://testserver/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?url=tests%2Ffixtures%2Ftest_zarr_store.zarr&variable=CDD0&decode_times=false&sel=time%3D0"
"http://testserver/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?url=tests%2Ffixtures%2Fzarr_store_v2.zarr&variable=CDD0&decode_times=false&sel=time%3D0"
],
"minzoom": 0,
"maxzoom": 0,
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/responses/zarr_store_v3_zarr_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bounds": [-180, -90.0, 180.0, 90.0],
"band_metadata": [],
"band_descriptions": [],
"dtype": "float64",
"nodata_type": "None",
"height": 36,
"count": 1,
"width": 72,
"attrs": {},
"name": "CDD0"
}
12 changes: 12 additions & 0 deletions tests/fixtures/responses/zarr_store_v3_zarr_tilejson.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tilejson": "2.2.0",
"version": "1.0.0",
"scheme": "xyz",
"tiles": [
"http://testserver/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?url=tests%2Ffixtures%2Fzarr_store_v3.zarr&variable=CDD0&decode_times=false&sel=time%3D0"
],
"minzoom": 0,
"maxzoom": 0,
"bounds": [-180.0, -90.0, 180.0, 90.0],
"center": [0.0, 0.0, 0]
}
3 changes: 0 additions & 3 deletions tests/fixtures/test_zarr_store.zarr/.zgroup

This file was deleted.

Loading
Loading