Skip to content

Commit

Permalink
fix so duplicate_ids tranformations don't happen for NHD Network runs
Browse files Browse the repository at this point in the history
  • Loading branch information
shorvath-noaa committed May 2, 2024
1 parent 0ae2089 commit 692d28a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/troute-nwm/src/nwm_routing/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def main_v04(argv):
hybrid_parameters,
preprocessing_parameters,
output_parameters,
verbose=True, showtiming=showtiming)
verbose=True, showtiming=showtiming)
duplicate_ids_df = network._duplicate_ids_df

elif supernetwork_parameters["network_type"] == 'NHDNetwork':
network = NHDNetwork(supernetwork_parameters,
Expand All @@ -99,6 +100,7 @@ def main_v04(argv):
verbose=True,
showtiming=showtiming,
)
duplicate_ids_df = pd.DataFrame()

if showtiming:
network_end_time = time.time()
Expand Down Expand Up @@ -259,7 +261,7 @@ def main_v04(argv):
cpu_pool,
network.waterbody_dataframe,
network.waterbody_types_dataframe,
network._duplicate_ids_df,
duplicate_ids_df,
data_assimilation_parameters,
data_assimilation.lastobs_df,
network.link_gage_df,
Expand Down
15 changes: 10 additions & 5 deletions src/troute-nwm/src/nwm_routing/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ def nwm_output_generator(
wbdy = wbdy.loc[wbdy_id_list]

# Replace synthetic waterbody IDs (made from duplicate IDs) with
# original waterbody IDs:
flow_df = flow_df.rename(index=dict(duplicate_ids_df[['synthetic_ids','lake_id']].values))
wbdy = wbdy.rename(index=dict(duplicate_ids_df[['synthetic_ids','lake_id']].values))
# original waterbody IDs (if duplicates exist):
if not duplicate_ids_df.empty:
flow_df = flow_df.rename(index=dict(duplicate_ids_df[['synthetic_ids','lake_id']].values))
wbdy = wbdy.rename(index=dict(duplicate_ids_df[['synthetic_ids','lake_id']].values))

timestep, variable = zip(*flow_df.columns.tolist())
timestep_index = np.where(((np.array(list(set(list(timestep)))) + 1) * dt) % (dt * qts_subdivisions) == 0)
Expand Down Expand Up @@ -227,8 +228,12 @@ def nwm_output_generator(
if wbdyo and not waterbodies_df.empty:

time_index, tmp_variable = map(list,zip(*i_df.columns.tolist()))
output_waterbodies_df = waterbodies_df.rename(index=dict(duplicate_ids_df[['synthetic_ids','lake_id']].values))
output_waterbody_types_df = waterbody_types_df.rename(index=dict(duplicate_ids_df[['synthetic_ids','lake_id']].values))
if not duplicate_ids_df.empty:
output_waterbodies_df = waterbodies_df.rename(index=dict(duplicate_ids_df[['synthetic_ids','lake_id']].values))
output_waterbody_types_df = waterbody_types_df.rename(index=dict(duplicate_ids_df[['synthetic_ids','lake_id']].values))
else:
output_waterbodies_df = waterbodies_df
output_waterbody_types_df = waterbody_types_df
LOG.info("- writing t-route flow results to LAKEOUT files")
start = time.time()
for i in range(i_df.shape[1]):
Expand Down

0 comments on commit 692d28a

Please sign in to comment.