22 β Cornerstone optimization
Goal: drop the 33s DEP join and 5β10s Sandy join on the HF Space CPU to <1s without changing Stone semantics.
Layer triage: live vs bakeable
The Cornerstone is a Hazard Reader β it reads what the ground already remembers. Every Cornerstone source is by definition historical or modeled, so the per-query cost of recomputing a spatial join is unwarranted. Live recency belongs to the Touchstone (FloodNet) and Lodestone (forecasts), not here.
| Source | Nature | Updates | Verdict |
|---|---|---|---|
dep_stormwater |
Modeled scenarios (2050/2080 SLR + design storm) | NYC DEP republishes every few years | bake to GeoTIFF |
sandy_inundation |
Empirical 2012 extent | Will not change | bake to GeoTIFF |
ida_hwm |
USGS HWMs (point set, ~few hundred) | Will not change | already O(n) haversine β leave alone |
prithvi_water |
Pre-baked Ida polygons | Will not change | already baked |
microtopo (DEM/HAND/TWI) |
LiDAR-derived rasters | Re-baked on terrain changes | already raster β already fast |
Live (kept live for demo recency):
- Geocoding (Geosearch + Nominatim fallback)
- FloodNet sensor pull (Touchstone)
- TTM battery surge / pluvial forecast (Lodestone)
- NYCHA / DOE / MTA registers (semi-static, prebuilt at boot β already fast)
So this experiment only touches the two slow Cornerstone specialists.
Approaches benchmarked
- baseline β current
gpd.sjoin(full layer) - strtree β pre-warm
gdf.sindex, query with single-pointintersects - bbox-prefilter β clip layer to bbox(point, 100ft) then sjoin
- raster β bake polygons β uint8 GeoTIFF in EPSG:2263;
rasterio.sample()per point
For DEP, the raster encodes max Flooding_Category per pixel
(0=outside, 1/2/3 = depth class). Sandy is a 1-bit raster.
Files
bench.pyβ runs all four paths on canonical addressesbake_rasters.pyβ one-time bake of DEP + Sandy to GeoTIFFRESULTS.mdβ written afterbench.pycompletes
Canonical addresses
Per CLAUDE.md / probe set:
- 80 Pioneer Street, Brooklyn β (40.6790, -74.0050)
- 2508 Beach Channel Drive, Queens β (40.5867, -73.8062)
- Coney Island I Houses, Brooklyn β (40.5772, -73.9870)
- Carleton Manor, Queens β (40.6033, -73.7626)