Skip to content

feat(topo): add standalone basin topo.nc generation pipeline#31

Open
jmichellehu wants to merge 13 commits into
mainfrom
basin-setup-workflow
Open

feat(topo): add standalone basin topo.nc generation pipeline#31
jmichellehu wants to merge 13 commits into
mainfrom
basin-setup-workflow

Conversation

@jmichellehu
Copy link
Copy Markdown
Contributor

@jmichellehu jmichellehu commented May 27, 2026

Add four python scripts to automate construction of topo.nc for SMRF/iSnobal with input basin name, HUC ID, or polygon. No dependency on USDA-ARS basin_setup repository. Includes associated conda env and README.md.

[scripts/topo] contains:

  • generate_topo.py: full pipeline manager (fetch_basin → fetch_dem → build_topo_nc)
  • fetch_basin.py: queries USGS WBD for HUC watershed boundaries
  • fetch_dem.py: streams or downloads USGS 3DEP 1/3 arc-second DEM tiles
  • build_topo_nc.py: combines DEM, basin mask, and vegetation into topo.nc

[conda/basin_setup.yaml] update to match the new pipeline. Remove legacy version pins and unused packages (colorama, coloredlogs, inicheck, spatialnc); add requests; relax python and numpy constraints.

Add four python scripts to construct topo.nc for SMRF/iSnobal using an input basin name,
HUC ID, or input polygon file. No dependency on USDA-ARS basin_setup repository. Contains:

- generate_topo.py: full pipeline manager (fetch_basin → fetch_dem → build_topo_nc)
- fetch_basin.py: queries USGS WBD for HUC watershed boundaries
- fetch_dem.py: streams or downloads USGS 3DEP 1/3 arc-second DEM tiles
- build_topo_nc.py: combines DEM, basin mask, and vegetation into topo.nc

[conda/basin_setup.yaml] update to match the new pipeline. Remove
legacy version pins and unused packages (colorama, coloredlogs, inicheck,
spatialnc); add requests; relax python and numpy constraints.
@jmichellehu jmichellehu requested review from Copilot and jomey May 27, 2026 01:03
@jmichellehu jmichellehu requested a review from a team May 27, 2026 01:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a self-contained Python pipeline under scripts/topo/ for generating a topo.nc file (DEM, basin mask, vegetation layers) suitable for SMRF/iSnobal, replacing the dependency on the external USDA-ARS basin_setup repository. State flows between scripts via a basin.env key=value file in the output directory, and the existing basin_setup conda environment is restructured to support the new dependencies.

Changes:

  • Four new scripts: generate_topo.py orchestrator plus fetch_basin.py (USGS WBD HUC fetch), fetch_dem.py (3DEP DEM tiles via vsicurl or download), and build_topo_nc.py (CF-compliant NetCDF assembly with LANDFIRE or user-supplied vegetation).
  • New scripts/topo/README.md documenting requirements, vegetation options, quick start, step-by-step usage, and the basin.env handoff contract.
  • conda/basin_setup.yaml rewritten: legacy pins/packages removed (colorama, coloredlogs, inicheck, spatialnc, strict python=3.11, numpy<1.25, gdal<3.9), requests and dask added, constraints relaxed.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
scripts/topo/README.md Documents new topo pipeline, vegetation options, CLI examples, and basin.env contract
scripts/topo/generate_topo.py Orchestrator chaining basin → DEM → topo.nc with conda-env guard and shared CLI
scripts/topo/fetch_basin.py Queries USGS WBD by HUC ID/name/polygon and writes UTM GeoPackage + basin.env
scripts/topo/fetch_dem.py Queries USGS TNM for 3DEP tiles, streams or downloads them, mosaics via GDAL VRT/Warp
scripts/topo/build_topo_nc.py Clips DEM/vegetation, rasterizes mask, writes CF-style NetCDF with projection var
conda/basin_setup.yaml Replaces legacy env with relaxed deps for the new pure-Python pipeline

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/topo/README.md Outdated
Comment thread scripts/topo/generate_topo.py Outdated
Comment thread scripts/topo/fetch_basin.py Outdated
Comment thread scripts/topo/build_topo_nc.py Outdated
Comment thread scripts/topo/build_topo_nc.py
Comment thread conda/basin_setup.yaml
Comment thread scripts/topo/fetch_basin.py Outdated
Comment thread scripts/topo/generate_topo.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Comment thread scripts/topo/generate_topo.py Outdated
Comment thread scripts/topo/fetch_basin.py Outdated
Comment thread scripts/topo/fetch_dem.py
Comment thread scripts/topo/fetch_dem.py
Comment thread scripts/topo/fetch_basin.py Outdated
Default uses vsicurl, keeping the flag creates more confusion
Apply Copilot suggestion to guard against issues with malformed tile titles.
Co-authored by Claude Sonnet 4.6
SMRF's load_topo.py expects the UTM zone to be stored in projection info.
Add handling for hemispheres to extract 2 digit zone.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread scripts/topo/fetch_basin.py Outdated
Comment thread scripts/topo/generate_topo.py Outdated
Comment thread scripts/topo/build_topo_nc.py Outdated
- Fix -e EPSG override so crs in polygon and basin.env agree
- Validate EPSG is a UTM zone across all scripts
- Enforce crs checks for input POLY
- Mask EVT NoData pixels to deal with extent padding, fill with open (tau=1,k=0)
- Change gdf.crs.srs to f'EPSG:{gdf.crs.to_epsg()}' in _padded_extents
- Add check for zero-sized tiles in fetch_dem
- Fix minor typos in README.md and add Claude acknowledgement
@jomey jomey added the Topo Anything related to setting up the topo file or related metadata label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Topo Anything related to setting up the topo file or related metadata

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants