Skip to content

Commit

Permalink
One version that works with all the known crosswalk formats (#40)
Browse files Browse the repository at this point in the history
Ensure compatibility with all known x-walk formats
  • Loading branch information
mattw-nws authored Dec 1, 2022
1 parent 41f5703 commit a2e2955
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions python/ngen_cal/src/ngen/cal/ngen.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def __init__(self, **kwargs):
for id, values in data.items():
gage = values.get('Gage_no')
if gage:
self._x_walk[id] = gage[0]
if not isinstance(gage, str):
gage = gage[0]
if gage != "":
self._x_walk[id] = gage

#Read the calibration specific info
with open(self.realization) as fp:
Expand Down Expand Up @@ -316,13 +319,20 @@ def __init__(self, **kwargs):
nexus_data = self._nexus_hydro_fabric.loc[fabric['toid']]
except KeyError:
raise(RuntimeError("No suitable nexus found for catchment {}".format(id)))
nwis = None
try:
nwis = self._x_walk.loc[id.replace('cat', 'wb')]
except KeyError:
try:
nwis = self._x_walk.loc[id]
except KeyError:
nwis = None
if nwis is not None:
#establish the hydro location for the observation nexus associated with this catchment
location = NWISLocation(nwis, nexus_data.name, nexus_data.geometry)
nexus = Nexus(nexus_data.name, location, (), id)
eval_nexus.append( nexus ) # FIXME why did I make this a tuple???
except KeyError:
else:
#in this case, we don't care if all nexus are observable, just need one downstream
#FIXME use the graph to work backwards from an observable nexus to all upstream catchments
#and create independent "sets"
Expand Down Expand Up @@ -354,16 +364,20 @@ def __init__(self, **kwargs):

for id, toid in self._catchment_hydro_fabric['toid'].iteritems():
#look for an observable nexus
nexus_data = self._nexus_hydro_fabric.loc[toid]
nwis = None
try:
nexus_data = self._nexus_hydro_fabric.loc[toid]
nwis = self._x_walk.loc[id.replace('cat', 'wb')]
#establish the hydro location for the observation nexus associated with this catchment
location = NWISLocation(nwis, nexus_data.name, nexus_data.geometry)
nexus = Nexus(nexus_data.name, location, (), id)
eval_nexus.append( nexus )
except KeyError:
#not an observable nexus, try the next one
continue
try:
nwis = self._x_walk.loc[id]
except KeyError:
#not an observable nexus, try the next one
continue
#establish the hydro location for the observation nexus associated with this catchment
location = NWISLocation(nwis, nexus_data.name, nexus_data.geometry)
nexus = Nexus(nexus_data.name, location, (), id)
eval_nexus.append( nexus )
if len(eval_nexus) != 1:
raise RuntimeError( "Currently only a single nexus in the hydrfabric can be gaged")
# FIXME hard coded routing file name...
Expand Down

0 comments on commit a2e2955

Please sign in to comment.