Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack to accommodate Alaska glacially dammed lakes (GDLs) #553

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/troute-network/troute/nhd_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,12 @@ def get_channel_restart_from_wrf_hydro(
inplace=True,
)
qdf2[channel_ID_column] = xdf

# handle GDL sythetic waterbody segmetns
gdl_idx = qdf2[qdf2['link'] < 10].index
if not gdl_idx.empty:
qdf2.loc[gdl_idx,"link"] = (qdf2.loc[gdl_idx,"link"] + 9999).astype("int64")

qdf2 = qdf2.reset_index().set_index([channel_ID_column])

q_initial_states = qdf2
Expand Down
6 changes: 6 additions & 0 deletions src/troute-network/troute/nhd_network_utilities_v02.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def build_connections(supernetwork_parameters):
# rename dataframe columns to keys in the cols dict variable
param_df = param_df.rename(columns=nhd_network.reverse_dict(cols))


# handle GDL sythetic waterbody segmetns
gdl_idx = param_df[param_df['key'] < 10].index
if not gdl_idx.empty:
param_df.loc[gdl_idx,"key"] = (param_df.loc[gdl_idx,"key"] + 9999).astype("int64")

# handle synthetic waterbody segments
synthetic_wb_segments = supernetwork_parameters.get("synthetic_wb_segments", None)
synthetic_wb_id_offset = supernetwork_parameters.get("synthetic_wb_id_offset", 9.99e11)
Expand Down
14 changes: 12 additions & 2 deletions src/troute-nwm/src/nwm_routing/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

LOG = logging.getLogger('')

def _reindex_lake_to_link_id(target_df, crosswalk):
def _reindex_lake_to_link_id(target_df, crosswalk, gdl=False):
'''
Utility function for replacing lake ID index values
with link ID values in a dataframe. This is used to
Expand Down Expand Up @@ -40,6 +40,10 @@ def _reindex_lake_to_link_id(target_df, crosswalk):
# replace lake ids with link IDs in the target_df index array
linkids = np.fromiter(crosswalk.values(), dtype = int)
idxs[lake_index_intersect[1]] = linkids[lake_index_intersect[2]]

# accout for re-numbered GDL indices
if gdl:
idxs = np.where(idxs < 10010, idxs-9999, idxs)

# (re) set the target_df index
target_df.set_index(idxs, inplace = True)
Expand Down Expand Up @@ -133,7 +137,13 @@ def nwm_output_generator(

# replace waterbody lake_ids with outlet link ids
if link_lake_crosswalk:
flowveldepth = _reindex_lake_to_link_id(flowveldepth, link_lake_crosswalk)

if min(link_lake_crosswalk.keys()) < 10:
gdl_flag = True
else:
gdl_flag = False

flowveldepth = _reindex_lake_to_link_id(flowveldepth, link_lake_crosswalk, gdl_flag)

# todo: create a unit test by saving FVD array to disk and then checking that
# it matches FVD array from parent branch or other configurations.
Expand Down