Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pygeoapi split_catchment does not return same geometry as get_basin #88

Open
3 tasks done
colby-thrash opened this issue Jan 31, 2025 · 1 comment
Open
3 tasks done
Labels
bug Something isn't working

Comments

@colby-thrash
Copy link

colby-thrash commented Jan 31, 2025

What happened?

I utilized your tutorial to split a small watershed at the location of the gage. The geometry results of split_catchment do not match those of the NLDI get_basin. I pulled the NHD flowlines for high and medium resolution. It looks like the difference in geometry is associated with the difference in flowline resolution. Is it safe to assume that split_catchment does not use high resolution flowlines/DEM data for delineation?

What did you expect to happen?

I expected to be able to split the basin at the gage to get upstream watershed geometry that matches the NLDI get_basin geometry.

I was able to use split_catchment successfully on two other small watersheds with no discrepancies. It's possible I found an edge case with this specific gage? I wouldn't expect the difference to matter much on larger watersheds but it could potentially on small watersheds.

Minimal Complete Verifiable Example

from pygeohydro import NWIS
from pynhd import NLDI
import geopandas as gpd
import shapely.geometry as sgeom
import pynhd
import matplotlib.pyplot as plt

station_id = 'USGS-06896500'
site = NWIS().get_info({'site': station_id.split('-')[-1]})
basin = NLDI().get_basins(station_id, split_catchment=False, simplified=False)

gdf = gpd.GeoDataFrame(
    {
        "upstream": [
            False,
        ]
    },
    geometry = [sgeom.Point((site.geometry.iloc[0].coords[0]))], 
    crs=site.crs,
)
split = pynhd.pygeoapi(gdf, 'split_catchment') 

nhd_hr = pynhd.NHDPlusHR("flowline")
nhd_mr = pynhd.NHD('flowline_mr')
flw_mr = nhd_mr.bygeom(basin.geometry.iloc[0], basin.crs)
flw_hr = nhd_hr.bygeom(basin.geometry.iloc[0], basin.crs)


ax = split.plot(figsize=(8, 8), facecolor="lightgrey", edgecolor="black", alpha=0.8) #, label='pygeoapi split_catchment')
site.plot(ax=ax, color='r')
basin.boundary.plot(ax=ax, color='r', label='get_basin similified=False')
plt.title(f'{station_id} get_basin vs split_catchment comparison')
flw_hr.plot(ax=ax, color='C0', label='flowline hr')
flw_mr.plot(ax=ax, color='C2', label='flowline mr')
plt.legend(loc='upper left')

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

Anything else we need to know?

No response

Environment

SYS INFO

commit: None
python: 3.12.8 | packaged by conda-forge | (main, Dec 5 2024, 14:06:27) [MSC v.1942 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 186 Stepping 2, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: ('English_United States', '1252')

PACKAGE VERSION

async-retriever 0.19.1
pygeoogc 0.19.0
pygeoutils 0.19.0
py3dep 0.19.0
pynhd 0.19.0
pygridmet N/A
pydaymet N/A
hydrosignatures 0.19.0
pynldas2 N/A
pygeohydro 0.19.0
aiohttp 3.11.11
aiohttp-client-cache 0.12.4
aiosqlite 0.20.0
cytoolz 1.0.1
ujson 5.10.0
defusedxml 0.7.1
joblib 1.4.2
multidict 6.1.0
owslib 0.32.1
pyproj 3.7.0
requests 2.32.3
requests-cache 1.2.1
shapely 2.0.6
url-normalize 1.4.3
urllib3 2.3.0
yarl 1.18.3
geopandas 1.0.1
netcdf4 1.7.2
numpy 2.2.2
rasterio 1.4.3
rioxarray 0.18.2
scipy 1.15.1
xarray 2025.1.1
click 8.1.8
networkx 3.4.2
pyarrow 19.0.0
folium 0.19.4
h5netcdf 1.4.1
matplotlib 3.10.0
pandas 2.2.2
numba N/A
py7zr N/A
pyogrio 0.10.0

@colby-thrash colby-thrash added the bug Something isn't working label Jan 31, 2025
@cheginit
Copy link
Collaborator

cheginit commented Feb 4, 2025

Is it safe to assume that split_catchment does not use high resolution flowlines/DEM data for delineation?

Right, the backbone network of NLDI is currently NHD MR. They are working on adding support for HR too. Currently, there aren't many web services that use the HR version since the network itself is still a work in progress and missing some important elements such as catchments.

Also, the source code for the split catchment functionality that PyGeoAPI uses is available here. You can install and work with it locally!

EDIT: I will look into the discrepancy that you mentioned and let you know if I find anything interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants