Skip to content

Commit

Permalink
feat: allow user to select evaluation feature when more than one obse…
Browse files Browse the repository at this point in the history
…rvable feature exists in the hydrofabric
  • Loading branch information
hellkite500 authored and aaraney committed Jun 27, 2024
1 parent a129e8f commit d40cc71
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions python/ngen_cal/src/ngen/cal/ngen.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class NgenBase(ModelExec):
# but we should probably take a closer look at this in the near future
realization: FilePath
hydrofabric: Optional[FilePath]
eval_feature: Optional[str]
catchments: Optional[FilePath]
nexus: Optional[FilePath]
crosswalk: Optional[FilePath]
Expand Down Expand Up @@ -420,9 +421,17 @@ def __init__(self, **kwargs):
#FIXME pick up params per catchmment somehow???
params = _map_params_to_realization(self.params, catchment)
catchments.append(AdjustableCatchment(self.workdir, id, nexus, params))

if self.eval_feature:
for n in eval_nexus:
wb = self._flowpath_hydro_fabric[ self._flowpath_hydro_fabric['toid'] == n.id ]
key = wb.iloc[0].name
if key == self.eval_feature:
eval_nexus = [n]
break

if len(eval_nexus) != 1:
raise RuntimeError( "Currently only a single nexus in the hydrfabric can be gaged")
raise RuntimeError( "Currently only a single nexus in the hydrfabric can be gaged, set the eval_feature key to pick one.")
self._catchments.append(CalibrationSet(catchments, eval_nexus[0], self.routing_output, start_t, end_t, self.eval_params))

def _strip_global_params(self) -> None:
Expand Down Expand Up @@ -467,8 +476,17 @@ def __init__(self, **kwargs):
location = NWISLocation(nwis, nexus_data.name, nexus_data.geometry)
nexus = Nexus(nexus_data.name, location, (), id)
eval_nexus.append( nexus )

if self.eval_feature:
for n in eval_nexus:
wb = self._flowpath_hydro_fabric[ self._flowpath_hydro_fabric['toid'] == n.id ]
key = wb.iloc[0].name
if key == self.eval_feature:
eval_nexus = [n]
break

if len(eval_nexus) != 1:
raise RuntimeError( "Currently only a single nexus in the hydrfabric can be gaged")
raise RuntimeError( "Currently only a single nexus in the hydrfabric can be gaged, set the eval_feature key to pick one.")
params = _params_as_df(self.params)
self._catchments.append(UniformCalibrationSet(eval_nexus=eval_nexus[0], routing_output=self.routing_output, start_time=start_t, end_time=end_t, eval_params=self.eval_params, params=params))

Expand Down

0 comments on commit d40cc71

Please sign in to comment.