Skip to content

Commit c1aff3c

Browse files
committed
fix: ensure --crs-groups flag set for S2 conversions
The --crs-groups flag triggers prepare_dataset_with_crs_info() in data-model, which writes CRS metadata via ds.rio.write_crs() and creates the spatial_ref coordinate variable required by TiTiler validation. Restores working configuration from commit 21ea009.
1 parent 2132d65 commit c1aff3c

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

scripts/augment_stac_item.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ def add_visualization(item: Item, raster_base: str, collection_id: str) -> None:
6666
_add_tile_links(item, base_url, query, "Sentinel-1 GRD VH")
6767

6868
elif coll_lower.startswith(("sentinel-2", "sentinel2")):
69-
# S2: Point to overview level 0 for quicklook TCI
70-
# Use /r10m/0/tci path to access the overview array with spatial_ref
71-
var_path = "/quality/l2a_quicklook/r10m/0/tci"
69+
# S2: Use colon separator for TiTiler variable path
70+
var_path = "/quality/l2a_quicklook/r10m:tci"
7271
query = (
7372
f"variables={urllib.parse.quote(var_path, safe='')}&bidx=1&bidx=2&bidx=3&assets=TCI_10m"
7473
)

scripts/create_geozarr_item.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import argparse
77
import logging
8-
import re
98
from typing import Any
109
from urllib.parse import urlparse
1110

@@ -31,30 +30,6 @@ def s3_to_https(s3_url: str, endpoint: str) -> str:
3130
return f"https://{bucket}.{host}/{path}"
3231

3332

34-
def normalize_r60m_href(href: str) -> str:
35-
"""Add /0/ subdirectory to r10m/r20m/r60m paths to match GeoZarr output structure.
36-
37-
GeoZarr conversion creates /0/ subdirectories (overview level 0) for all
38-
resolution bands. This normalizes asset hrefs accordingly.
39-
40-
Example: .../r10m/tci → .../r10m/0/tci
41-
.../r60m/b09 → .../r60m/0/b09
42-
"""
43-
# Check for any resolution level pattern
44-
for res in ["r10m", "r20m", "r60m"]:
45-
if f"/{res}/" not in href:
46-
continue
47-
48-
# If already has /0/ or other digit subdirectory, don't modify
49-
if re.search(rf"/{res}/\d+/", href):
50-
continue
51-
52-
# Insert /0/ after /{res}/
53-
href = re.sub(rf"/({res})/", r"/\1/0/", href)
54-
55-
return href
56-
57-
5833
def find_source_zarr_base(source_item: dict) -> str | None:
5934
"""Find the base Zarr URL from source item assets."""
6035
for asset in source_item.get("assets", {}).values():
@@ -112,9 +87,6 @@ def create_geozarr_item(
11287
subpath = old_href[len(source_zarr_base) :]
11388
new_href = output_zarr_base + subpath
11489

115-
# Normalize r60m paths to include /0/ subdirectory (GeoZarr structure)
116-
new_href = normalize_r60m_href(new_href)
117-
11890
# Convert to https if needed
11991
if new_href.startswith("s3://"):
12092
new_href = s3_to_https(new_href, s3_endpoint)

scripts/get_zarr_url.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
"""Extract Zarr URL from STAC item - standalone script for workflow templates."""
3+
4+
import sys
5+
6+
import httpx
7+
8+
9+
def get_zarr_url(stac_item_url: str) -> str:
10+
"""Get Zarr asset URL from STAC item."""
11+
r = httpx.get(stac_item_url, timeout=30.0, follow_redirects=True)
12+
r.raise_for_status()
13+
assets = r.json().get("assets", {})
14+
15+
# Priority: product, zarr, then any .zarr asset
16+
for key in ["product", "zarr"]:
17+
if key in assets and (href := assets[key].get("href")):
18+
return str(href)
19+
20+
# Fallback: any asset with .zarr in href
21+
for asset in assets.values():
22+
if ".zarr" in asset.get("href", ""):
23+
return str(asset["href"])
24+
25+
raise RuntimeError("No Zarr asset found in STAC item")
26+
27+
28+
if __name__ == "__main__":
29+
if len(sys.argv) != 2:
30+
print("Usage: get_zarr_url.py <stac_item_url>", file=sys.stderr)
31+
sys.exit(1)
32+
33+
try:
34+
zarr_url = get_zarr_url(sys.argv[1])
35+
print(zarr_url)
36+
except Exception as e:
37+
print(f"Error: {e}", file=sys.stderr)
38+
sys.exit(1)

0 commit comments

Comments
 (0)