Spaces:
Running on Zero
Running on Zero
| """ | |
| Run this against your real downloaded BD TOPO data to: | |
| 1. Actually answer the karst/bétoire question with real data. | |
| 2. Cross-validate the new catchment polygons against Hub'Eau's surface_bv | |
| numbers (from catchment_area.csv, built earlier via download_catchment_area.py). | |
| """ | |
| import sys | |
| sys.path.insert(0, ".") | |
| from pathlib import Path | |
| from src.data.loaders.bdtopo_hydro import BDTopoHydroLoader | |
| loader = BDTopoHydroLoader(data_path=Path("datasets/bdtopo_hydro")) | |
| # --- 1. The karst question, for real this time --- | |
| print("=" * 70) | |
| print("KARST CHECK near amont/aval bétoire stations") | |
| print("=" * 70) | |
| BETOIRE_STATIONS = { | |
| "H605641101": ("Ajou [amont bétoire]", 48.98492, 0.78902), | |
| "H605641201": ("Grosley-sur-Risle [aval bétoire]", 49.04707, 0.79984), | |
| } | |
| surfaces = loader.load_surfaces() | |
| any_found = False | |
| for code, (name, lat, lon) in BETOIRE_STATIONS.items(): | |
| results = loader.check_karst_near_point(lat, lon, search_radius_km=3.0, surfaces_geojson=surfaces) | |
| print(f"\n{code} ({name}):") | |
| if results: | |
| any_found = True | |
| for r in results: | |
| print(f" -> {r['nature']!r} at {r['distance_km']:.2f} km") | |
| else: | |
| print(" -> no karst-classified feature within 3 km") | |
| print() | |
| if any_found: | |
| print("VERDICT: CONFIRMED by real BD TOPO data -- the bétoire naming is backed " | |
| "by an actual mapped karst feature.") | |
| else: | |
| print("VERDICT: No karst feature found within 3km. Try a wider search radius, " | |
| "or this may just be historical/informal naming not reflected in the " | |
| "current BD TOPO classification.") | |
| # --- 2. Cross-validate catchment polygons against Hub'Eau surface_bv --- | |
| print() | |
| print("=" * 70) | |
| print("CATCHMENT POLYGON CROSS-CHECK vs Hub'Eau surface_bv") | |
| print("=" * 70) | |
| try: | |
| import geopandas as gpd | |
| import pandas as pd | |
| catchments = loader.load_catchments() | |
| print(f"Loaded {len(catchments)} catchment polygon(s)") | |
| print(f"Columns: {list(catchments.columns)}") | |
| hubeau_path = Path("datasets/catchment_area.csv") | |
| if hubeau_path.exists(): | |
| hubeau = pd.read_csv(hubeau_path).dropna(subset=["catchment_area_km2"]) | |
| print(f"\nLoaded {len(hubeau)} Hub'Eau reference values from {hubeau_path}") | |
| # Compute polygon areas in km^2 (reproject to a metric CRS for accurate area) | |
| catchments_metric = catchments.to_crs(epsg=2154) # Lambert-93, standard for France | |
| catchments["area_km2_computed"] = catchments_metric.geometry.area / 1e6 | |
| print(catchments[["area_km2_computed"]].describe()) | |
| print("\n(Match these against datasets/catchment_area.csv's real Hub'Eau values " | |
| "by whichever ID field the polygons carry -- check catchments.columns " | |
| "above for a station/site code to join on.)") | |
| else: | |
| print(f"\n{hubeau_path} not found -- skipping cross-check. " | |
| f"(Run download_catchment_area.py first if you want this comparison.)") | |
| except ImportError: | |
| print("geopandas not installed -- skipping catchment polygon check.") |