From 07d511bb4f93aed23b9031d0b464b17bdf8f2060 Mon Sep 17 00:00:00 2001 From: Dong Ha Kim Date: Fri, 8 Dec 2023 20:22:00 +0000 Subject: [PATCH] temporary fix to qlats to run both NHD with syn/natural x-sec and HYfeature only with syn x-sec for now --- src/troute-routing/troute/routing/compute.py | 13 +++++++++---- .../troute/routing/diffusive_utils_v02.py | 13 +++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/troute-routing/troute/routing/compute.py b/src/troute-routing/troute/routing/compute.py index 45a2ab372..a4f9fe8c8 100644 --- a/src/troute-routing/troute/routing/compute.py +++ b/src/troute-routing/troute/routing/compute.py @@ -1485,9 +1485,9 @@ def compute_diffusive_routing( # diffusive streamflow DA activation switch #if da_parameter_dict['diffusive_streamflow_nudging']==True: if 'diffusive_streamflow_nudging' in da_parameter_dict: - diff_usgs_df = usgs_df + diffusive_usgs_df = usgs_df else: - diff_usgs_df = pd.DataFrame() + diffusive_usgs_df = pd.DataFrame() # tw in refactored hydrofabric if refactored_diffusive_domain: @@ -1504,6 +1504,11 @@ def compute_diffusive_routing( else: coastal_boundary_depth_bytw_df = pd.DataFrame() + # temporary: column names of qlats from HYfeature are currently timestamps. To be consistent with qlats from NHD + # the column names need to be changed to intergers from zero incrementing by 1 + diffusive_qlats = qlats.copy() + diffusive_qlats.columns = range(diffusive_qlats.shape[1]) + # build diffusive inputs diffusive_inputs = diff_utils.diffusive_input_data_v02( tw, @@ -1514,7 +1519,7 @@ def compute_diffusive_routing( diffusive_network_data[tw]['tributary_segments'], None, # place holder for diffusive parameters diffusive_network_data[tw]['param_df'], - qlats, + diffusive_qlats, q0, junction_inflows, qts_subdivisions, @@ -1523,7 +1528,7 @@ def compute_diffusive_routing( dt, waterbodies_df, topobathy_bytw, - diff_usgs_df, + diffusive_usgs_df, refactored_diffusive_domain_bytw, refactored_reaches_byrftw, coastal_boundary_depth_bytw_df, diff --git a/src/troute-routing/troute/routing/diffusive_utils_v02.py b/src/troute-routing/troute/routing/diffusive_utils_v02.py index 8065a77f6..4e540a503 100644 --- a/src/troute-routing/troute/routing/diffusive_utils_v02.py +++ b/src/troute-routing/troute/routing/diffusive_utils_v02.py @@ -253,7 +253,6 @@ def fp_qlat_map( ----- data in qlat_g are normalized by segment length with units of m2/sec = m3/sec/m """ - frj = -1 for x in range(mx_jorder, -1, -1): for head_segment, reach in ordered_reaches[x]: @@ -534,10 +533,13 @@ def fp_da_map( usgs_df_complete = usgs_df.replace(np.nan, -4444.0) - for i in range(len(timestamps)): - if timestamps[i] not in usgs_df.columns: - usgs_df_complete.insert(i, timestamps[i], -4444.0*np.ones(len(usgs_df)), allow_duplicates=False) - + missing_timestamps = [ts for ts in timestamps if ts not in usgs_df.columns] + missing_data = pd.DataFrame(-4444.0*np.ones((len(usgs_df), len(missing_timestamps))), + columns=missing_timestamps, + index=usgs_df.index) + usgs_df_complete = pd.concat([usgs_df_complete, missing_data], axis=1) + usgs_df_complete = usgs_df_complete[timestamps] + frj = -1 for x in range(mx_jorder, -1, -1): for head_segment, reach in ordered_reaches[x]: @@ -683,7 +685,6 @@ def diffusive_input_data_v02( ------- diff_ins -- (dict) formatted inputs for diffusive wave model """ - # lateral inflow timestep (sec). Currently, lateral flow in CHAROUT files at one hour time step dt_ql_g = 3600.0 # upstream boundary condition timestep = MC simulation time step (sec)