File size: 1,900 Bytes
dbf7a0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""One-shot fetch of NYC Hurricane Ida 2021 high-water marks from USGS STN.

Output: data/ida_2021_hwms_ny.geojson — point GeoJSON with elev_ft + site
metadata. Used by the Riprap agent's `step_ida_hwm` action as the
empirical post-event flood signal (the same role Prithvi-EO plays for
SAR-derived extents in the parent project).
"""
from __future__ import annotations

import json
import sys
from pathlib import Path

import httpx

OUT = Path(__file__).resolve().parent.parent / "data" / "ida_2021_hwms_ny.geojson"
URL = "https://stn.wim.usgs.gov/STNServices/HWMs/FilteredHWMs.json"


def main() -> int:
    print("fetching USGS STN Ida 2021 NY HWMs...", file=sys.stderr)
    r = httpx.get(URL, params={"Event": 312, "States": "NY"}, timeout=60)
    r.raise_for_status()
    data = r.json()

    features = []
    for d in data:
        lat = d.get("latitude"); lon = d.get("longitude")
        if lat is None or lon is None:
            continue
        features.append({
            "type": "Feature",
            "geometry": {"type": "Point", "coordinates": [lon, lat]},
            "properties": {
                "hwm_id": d.get("hwm_id"),
                "site_no": d.get("site_no"),
                "elev_ft": d.get("elev_ft"),
                "height_above_gnd": d.get("height_above_gnd"),
                "hwm_type": d.get("hwmTypeName"),
                "hwm_quality": d.get("hwmQualityName"),
                "county": d.get("countyName"),
                "site_description": d.get("siteDescription"),
                "waterbody": d.get("waterbody"),
            },
        })
    OUT.parent.mkdir(exist_ok=True, parents=True)
    OUT.write_text(json.dumps({"type": "FeatureCollection", "features": features}))
    print(f"wrote {len(features)} HWMs -> {OUT} ({OUT.stat().st_size // 1024} KB)",
          file=sys.stderr)
    return 0


if __name__ == "__main__":
    sys.exit(main())