Skip to content
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
1 change: 1 addition & 0 deletions config/params_template.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export stage_min_meters=0
export stage_interval_meters=0.3048
export stage_max_meters=25
export slope_min=0.001
export slope_scale=1000000000
export min_catchment_area=0.25
export min_stream_length=0.5

Expand Down
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
All notable changes to this project will be documented in this file.
We follow the [Semantic Versioning 2.0.0](http://semver.org/) format.

## v4.8.x.3x - 2025-09-11 - [PR#1654](https://github.com/NOAA-OWP/inundation-mapping/pull/1654)

Adjusted the script to source columns from `src_base` instead of `src_full` .


### Changes
`dev-fix-update-hydrotable`: as described.
## v4.8.14.2 - 2025-10-17 - [PR#1677](https://github.com/NOAA-OWP/inundation-mapping/pull/1677)

During a merge of the recent PR for mprunner fixes, one critical line was dropped. The line takes the return value from the child multi-proc function and adds it to a list collection of return results.
Expand Down
19 changes: 16 additions & 3 deletions src/add_crosswalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import json
import sys
import os

import geopandas as gpd
import numpy as np
Expand All @@ -18,6 +19,7 @@
# Define acceptable slope range
SLOPE_MIN = 9.999e-7
SLOPE_MAX = 0.5
SLOPE_SCALE = float(os.getenv("slope_scale"))


def add_crosswalk(
Expand Down Expand Up @@ -284,11 +286,18 @@ def add_crosswalk(
# hfab_mask = (input_src_base['SLOPE_HFAB'] >= SLOPE_MIN) & (input_src_base['SLOPE_HFAB'] <= SLOPE_MAX)

# Apply masks to filter out invalid slope values
sword_slope = input_src_base['SLOPE_IRIS_SWORD'].where(sword_mask)
sword_slope = input_src_base['SLOPE_IRIS_SWORD'].where(sword_mask).astype(float)
# hfab_slope = input_src_base['SLOPE_HFAB'].where(hfab_mask)

# Assign SLOPE values with priority: IRIS_SWORD then RISE_RUN
input_src_base['SLOPE'] = sword_slope.combine_first(input_src_base['SLOPE_RISE_RUN'])
input_src_base['SLOPE'] = (
sword_slope.combine_first(input_src_base['SLOPE_RISE_RUN']).astype(float)
)

#now to preserve slope precisions, we will record slope values as an integer by multiplying by a scale
#later in the code, when we need to use slope values, we will need to divide the values by the same scale
input_src_base['SLOPE'] = ((SLOPE_SCALE * input_src_base['SLOPE']).round()).astype('int64')


input_src_base = input_src_base.rename(columns=lambda x: x.strip(" "))
input_src_base = input_src_base.apply(pd.to_numeric, **{'errors': 'coerce'})
Expand All @@ -302,7 +311,7 @@ def add_crosswalk(
input_src_base['Discharge (m3s-1)'] = (
input_src_base['WetArea (m2)']
* pow(input_src_base['HydraulicRadius (m)'], 2.0 / 3)
* pow(input_src_base['SLOPE'], 0.5)
* pow(input_src_base['SLOPE']/SLOPE_SCALE, 0.5)
/ input_src_base['ManningN']
)

Expand Down Expand Up @@ -367,6 +376,10 @@ def add_crosswalk(

output_src = output_src.merge(crosswalk[['HydroID', 'feature_id']], on='HydroID')

#also add default manning and slope for reseting hydrotable and src full later
output_src['default_SLOPE']=output_src['SLOPE']
output_src['default_ManningN']=output_src['ManningN']

del crosswalk

output_crosswalk = output_src[['HydroID', 'feature_id']]
Expand Down
2 changes: 1 addition & 1 deletion src/bathy_rc_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def bathy_rc_lookup(
modified_src_base['Discharge (m3s-1)'] = (
modified_src_base['WetArea (m2)_bathy_adj']
* pow(modified_src_base['HydraulicRadius (m)_bathy_adj'], 2.0 / 3)
* pow(modified_src_base['SLOPE'], 0.5)
* pow(modified_src_base['SLOPE'], 0.5) #note that slope here is from src base, which is raw data (unscaled data)
/ modified_src_base['ManningN']
)
## mask discharge values for stage = 0 rows in SRC (replace with 0) --> do we need SRC to start at 0??
Expand Down
9 changes: 5 additions & 4 deletions src/bathymetric_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import geopandas as gpd
import pandas as pd

SLOPE_SCALE = float(os.getenv("slope_scale"))


# -------------------------------------------------------
# Function to use RFC Bathymetry where available over eHydro Data
Expand Down Expand Up @@ -135,7 +137,7 @@ def correct_rating_for_ehydro_bathymetry(fim_dir, huc, bathy_file_ehydro, verbos
src_df['Discharge (m3s-1)'] = (
src_df['WetArea (m2)']
* src_df['HydraulicRadius (m)'] ** (2.0 / 3)
* src_df['SLOPE'] ** 0.5
* (src_df['SLOPE']/SLOPE_SCALE) ** 0.5
/ src_df['ManningN']
)
# Force zero stage to have zero discharge
Expand Down Expand Up @@ -281,7 +283,7 @@ def correct_rating_for_ai_bathymetry(fim_dir, huc, strm_order, bathy_file_aibase
src_df['Discharge (m3s-1)'] = (
src_df['WetArea (m2)']
* src_df['HydraulicRadius (m)'] ** (2.0 / 3)
* src_df['SLOPE'] ** 0.5
* (src_df['SLOPE']/SLOPE_SCALE) ** 0.5
/ src_df['ManningN']
)
# Force zero stage to have zero discharge
Expand All @@ -302,7 +304,6 @@ def correct_rating_for_ai_bathymetry(fim_dir, huc, strm_order, bathy_file_aibase
src_df2 = src_df.copy()
discharge_bathymetry = src_df2['Discharge (m3s-1)']
src_df['Discharge (m3s-1)_bathymetryAdjusted'] = discharge_bathymetry

src_df.to_csv(src, index=False)

else:
Expand Down Expand Up @@ -362,7 +363,7 @@ def correct_rating_for_ai_bathymetry(fim_dir, huc, strm_order, bathy_file_aibase
discharge_cms = (
src_df['WetArea (m2)']
* src_df['HydraulicRadius (m)'] ** (2.0 / 3)
* src_df['SLOPE'] ** 0.5
* (src_df['SLOPE']/SLOPE_SCALE) ** 0.5
/ src_df['ManningN']
)
src_df.loc[src_df["Bathymetry_source"] == "AI_Based", "Discharge (m3s-1)"] = discharge_cms
Expand Down
25 changes: 24 additions & 1 deletion src/longitudinal_flow_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import scipy
from scipy.ndimage import generic_filter

SLOPE_SCALE = float(os.getenv("slope_scale"))


# -------------------------------------------------------
def extract_longitudinal_variables(src_df, hydroid, stage):
Expand Down Expand Up @@ -147,6 +149,27 @@ def filter_longitudinal_discharge_jitters(fim_dir, huc):
log_text = f'Filtering Longitudinal Flow Fluctuation for HUC8: {huc}\n'
fim_huc_dir = join(fim_dir, huc)

# if int(branch) == 0:
src_full_0 = join(fim_huc_dir, 'branches', str(0), 'src_full_crosswalked_0.csv')
ht_0_path = join(fim_huc_dir, 'branches', str(0), 'hydroTable_0.csv')

if os.path.isfile(src_full_0) and os.path.isfile(ht_0_path):
src_0_df = pd.read_csv(src_full_0, low_memory=False)
ht_0_df = pd.read_csv(ht_0_path, low_memory=False)

src_0_df.loc[src_0_df['Bathymetry_source'] == str(0), 'Bathymetry_source'] = 'No Bathymetry Applied'
src_0_df.loc[src_0_df['Bathymetry_source'] == 0, 'Bathymetry_source'] = 'No Bathymetry Applied'
src_0_df['Bathymetry_source'] = src_0_df['Bathymetry_source'].fillna('No Bathymetry Applied')
ht_0_df['Bathymetry_source'] = src_0_df['Bathymetry_source']

# Save updated branch 0 ht and src tables
src_0_df = src_0_df.drop_duplicates(subset=['HydroID', 'Stage'], keep='first').reset_index(drop=True)
src_0_df.to_csv(src_full_0, index=False)
ht_0_df = ht_0_df.drop_duplicates(subset=['HydroID', 'stage'], keep='first').reset_index(drop=True)
ht_0_df.to_csv(ht_0_path, index=False)
else:
print("Files do not exist: src_full_crosswalked_0.csv and hydroTable_0.csv")

# Get src_full, hydrotable and catchment from each branch
src_all_branches_path = []
cathment_gpkg_path = []
Expand Down Expand Up @@ -309,7 +332,7 @@ def filter_longitudinal_discharge_jitters(fim_dir, huc):
src_df['Discharge (m3s-1)'] = (
src_df['WetArea (m2)']
* pow(src_df['HydraulicRadius (m)'], 2.0 / 3)
* pow(src_df['SLOPE'], 0.5)
* pow(src_df['SLOPE']/SLOPE_SCALE, 0.5)
/ src_df['ManningN']
)
# Refining Discharge for lake hydroIDs with the original Q
Expand Down
6 changes: 4 additions & 2 deletions src/nonmonotonic_src_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import numpy as np
import pandas as pd

SLOPE_SCALE = float(os.getenv("slope_scale"))


# -------------------------------------------------------
# Analysing each HydroID SRC for nonmonotonic SRC
Expand Down Expand Up @@ -67,7 +69,7 @@ def analyze_nonmonotonic_src(srcs_df, strm_order): # , thalweg_hydroids
srcs_df.loc[row_slice, 'Discharge (m3s-1)'] = (
wet_area
* (srcs_df.loc[row_slice, 'HydraulicRadius (m)'] ** (2.0 / 3))
* (srcs_df.loc[row_slice, 'SLOPE'] ** 0.5)
* ((srcs_df.loc[row_slice, 'SLOPE']/SLOPE_SCALE) ** 0.5)
/ srcs_df.loc[row_slice, 'channel_n']
)
# srcs_df['Discharge (m3s-1)_subdiv'] = np.where(
Expand Down Expand Up @@ -200,7 +202,6 @@ def correct_nonmonotonic_src(fim_dir, huc, strm_order): # , bankfull_flows_file
src_df['subdiv_applied'] = src_df.groupby('HydroID')['subdiv_applied'].ffill()
src_df['channel_n'] = src_df.groupby('HydroID')['channel_n'].ffill()
src_df['overbank_n'] = src_df.groupby('HydroID')['overbank_n'].ffill()

src_df22 = src_df.copy()
discharge_nonmono = src_df22['Discharge (m3s-1)']
src_df22['Discharge (m3s-1)_nonmonotonicAdjusted'] = discharge_nonmono
Expand All @@ -214,6 +215,7 @@ def correct_nonmonotonic_src(fim_dir, huc, strm_order): # , bankfull_flows_file
src_df = src_df5.copy()
src_df.to_csv(src, index=False)


# Adjusting hydro tables for nonmonotonic SRC
# Reporting in the log file
log_text += f'Adjusting Nonmonotonic hydroTable for HUC {huc} Branch {branch}'
Expand Down
5 changes: 3 additions & 2 deletions src/subdiv_chan_obank_src.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

sns.set_theme(style="whitegrid")
warnings.simplefilter(action='ignore', category=FutureWarning)
SLOPE_SCALE = float(os.getenv("slope_scale"))

"""
Compute channel geomety and Manning's equation using subdivision method (separate in-channel vs. overbank)
Expand Down Expand Up @@ -267,7 +268,7 @@ def subdiv_mannings_eq(df_src):
df_src['Discharge_chan (m3s-1)'] = (
df_src['WetArea_chan (m2)']
* pow(df_src['HydraulicRadius_chan (m)'], 2.0 / 3)
* pow(df_src['SLOPE'], 0.5)
* pow(df_src['SLOPE']/SLOPE_SCALE, 0.5)
/ df_src['channel_n']
)
df_src['Velocity_chan (m/s)'] = df_src['Discharge_chan (m3s-1)'] / df_src['WetArea_chan (m2)']
Expand All @@ -291,7 +292,7 @@ def subdiv_mannings_eq(df_src):
df_src['Discharge_obank (m3s-1)'] = (
df_src['WetArea_obank (m2)']
* pow(df_src['HydraulicRadius_obank (m)'], 2.0 / 3)
* pow(df_src['SLOPE'], 0.5)
* pow(df_src['SLOPE']/SLOPE_SCALE, 0.5)
/ df_src['overbank_n']
)
df_src['Velocity_obank (m/s)'] = df_src['Discharge_obank (m3s-1)'] / df_src['WetArea_obank (m2)']
Expand Down
Loading
Loading