Issue with splitting basins of 198 stations
I found 198 USGS stations that NLDI successfully processes with the splitCatchment
flag set to true while the master version of nldi-flowtools
cannot. NLDI uses an older version of nldi-tools
so there seems to be some changes in the master version that causes this issue. I uploaded the stations in a gist under my Github account.
Here's the code for reproducing the issue:
import async_retriever as ar
import pygeoutils as geoutils
import pandas as pd
import geopandas as gpd
from pynhd import NLDI
from nldi_flowtools.nldi_flowtools import splitcatchment
url = "https://gist.githubusercontent.com/cheginit/af4e127014d95c35a5a4a7c0731f9f59/raw/stations.json"
stations = pd.DataFrame(ar.retrieve_json([url])[0])
d = 0.00045
cf = 1.3
basins = {}
for i, x, y in stations[["dec_long_va", "dec_lat_va"]].itertuples(name=None):
basin = geoutils.json2geodf(splitcatchment(x, y, False))
basin = basin[basin.catchmentID.isna()]
basins[i] = basin.buffer(-d).buffer(d * cf).simplify(d).geometry.iloc[0]
basins = gpd.GeoSeries(basins)
nldi = NLDI()
basins_nldi = nldi.get_basins(stations.index.to_list(), split_catchment=True, simplified=False)
All geometries in basins
are empty while basins_nldi
returns the correct basins.
Conversely, I found a station that NLDI processes incorrectly while the master version of nldi-tools
does correctly.
from pygeohydro import NWIS
nwis = NWIS()
station = nwis.get_info({"site": "03368000"})
x, y = station.geometry.x.iloc[0], station.geometry.y.iloc[0]
basin = geoutils.json2geodf(splitcatchment(x, y, False))
basin = basin[basin.catchmentID.isna()].buffer(-d).buffer(d * cf).simplify(d)
basin_nldi = nldi.get_basins("03368000", split_catchment=True, simplified=False)
ax = basin.plot(figsize=(6, 6), color="b", lw=2, alpha=0.5)
basin_nldi.plot(ax=ax, color="k")
station.plot(ax=ax, color="r")
ax.set_axis_off()