Skip to content

Commit 9f5eddb

Browse files
Merge pull request #20 from NewGraphEnvironment/10-fix-review-feedback
Fix review feedback: CRS guard, logging, upgrade loop
2 parents 6cb37a4 + 18fa010 commit 9f5eddb

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

scripts/item_create.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,13 @@ def load_validation_cache(urls_to_check: list[str]) -> dict:
149149
existing_urls = set()
150150
logger.info("No existing validation cache found, will validate all URLs")
151151

152-
# Detect old-format rows missing spatial metadata
153-
has_spatial = set()
152+
# Detect old-format rows missing spatial metadata (all spatial columns null).
153+
# Rows that were extracted but have epsg=None (no CRS) are NOT re-upgraded —
154+
# they'll have height/width/transform populated from the extraction.
154155
needs_upgrade = set()
155-
if "epsg" in df_existing.columns:
156+
if "transform" in df_existing.columns:
156157
for _, row in df_existing.iterrows():
157-
if pd.notna(row.get("epsg")):
158-
has_spatial.add(row["url"])
159-
elif row.get("is_geotiff"):
158+
if row.get("is_geotiff") and pd.isna(row.get("transform")):
160159
needs_upgrade.add(row["url"])
161160
else:
162161
needs_upgrade = {row["url"] for _, row in df_existing.iterrows() if row["is_geotiff"]}

scripts/stac_utils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import json
12+
import logging
1213
import re
1314
from datetime import datetime, timezone
1415

@@ -19,6 +20,8 @@
1920
from rio_cogeo.cogeo import cog_validate
2021
from shapely.geometry import box, mapping
2122

23+
logger = logging.getLogger(__name__)
24+
2225

2326
# =============================================================================
2427
# Path Configuration
@@ -93,11 +96,12 @@ def datetime_parse_item(s: str | None) -> datetime | None:
9396
# =============================================================================
9497

9598
def geotiff_extract_metadata(url: str) -> dict:
96-
"""Extract spatial metadata and validate GeoTIFF/COG status in one remote read.
99+
"""Extract spatial metadata and validate GeoTIFF/COG status.
97100
98-
Opens the remote GeoTIFF via /vsicurl/, extracts CRS, bounds, shape, and
99-
transform, then validates COG status. All metadata needed for STAC item
100-
creation is returned so subsequent builds can skip the remote read.
101+
Opens the remote GeoTIFF via /vsicurl/ to extract CRS, bounds, shape, and
102+
transform, then validates COG status (second remote read via cog_validate).
103+
All metadata needed for STAC item creation is cached so subsequent builds
104+
skip remote reads entirely.
101105
102106
Returns dict with url, is_geotiff, is_cog, epsg, height, width, transform, bounds.
103107
"""
@@ -106,7 +110,7 @@ def geotiff_extract_metadata(url: str) -> dict:
106110

107111
try:
108112
with rasterio.open(vsicurl_path) as src:
109-
epsg = src.crs.to_epsg()
113+
epsg = src.crs.to_epsg() if src.crs else None
110114
height = src.height
111115
width = src.width
112116
transform = list(src.transform)[:6]
@@ -124,7 +128,8 @@ def geotiff_extract_metadata(url: str) -> dict:
124128
"transform": json.dumps(transform),
125129
"bounds": json.dumps(bounds),
126130
}
127-
except Exception:
131+
except Exception as e:
132+
logger.warning("Failed to read %s: %s", url, e)
128133
return {
129134
"url": url,
130135
"is_geotiff": False,

0 commit comments

Comments
 (0)