Skip to content

Commit

Permalink
fix: handle hf's with 'flowpath-attributes'
Browse files Browse the repository at this point in the history
  • Loading branch information
aaraney committed Jul 30, 2024
1 parent 94d03dd commit 00650e2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion python/ngen_cal/src/ngen/cal/ngen.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,19 @@ def _read_hydrofabric(self):
self._flowpath_hydro_fabric = gpd.read_file(self.hydrofabric, layer='flowpaths')
self._flowpath_hydro_fabric.set_index('id', inplace=True)

attributes = gpd.read_file(self.hydrofabric, layer="flowpath_attributes")
# DataLayerError if using pyogrio engine; ValueError if using fiona engine.
try:
# cannot assume pyogrio is installed
from pyogrio.errors import DataLayerError
except ImportError:
DataLayerError = ValueError
# some hydrofabric versions use 'flowpath_attributes' others use 'flowpath-attributes'
# try first then second on failure
try:
attributes = gpd.read_file(self.hydrofabric, layer="flowpath_attributes")
except (DataLayerError, ValueError):
attributes = gpd.read_file(self.hydrofabric, layer="flowpath-attributes")
attributes.set_index("id", inplace=True)

self._x_walk = pd.Series( attributes[ ~ attributes['rl_gages'].isna() ]['rl_gages'] )

Expand Down

0 comments on commit 00650e2

Please sign in to comment.