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

[1pt] PR: Tool to evaluate crosswalk accuracy #1061

Merged
merged 23 commits into from
Jan 12, 2024
Merged
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 Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ARG depDir=/dependencies
ENV inputsDir=$dataDir/inputs
ENV outputsDir=/outputs
ENV srcDir=$projectDir/src
ENV toolsDir=$projectDir/tools
ENV workDir=/fim_temp
ENV taudemDir=$depDir/taudem/bin
ENV taudemDir2=$depDir/taudem_accelerated_flowDirections/taudem/build/bin
Expand Down
22 changes: 22 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
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.4.8.4 - 2024-01-12 - [PR#1061](https://github.com/NOAA-OWP/inundation-mapping/pull/1061)

Adds a post-processing tool to compare crosswalked (conflated) `feature_id`s between NWM stream network to DEM-derived reaches. The tool is run if the `-x` flag is added to `fim_pipeline.sh`. Results are computed for branch 0 and saved in a summary file in the HUC output folder.

### Additions

- `tools/evaluate_crosswalk.py`: evaluates crosswalk accuracy using two methods:
- intersections: the number of intersections between streamlines
- network (or tree): compares the feature_ids of the immediate upstream segments

### Changes

- `Dockerfile`: added `toolsDir` environment variable
- `fim_pipeline.sh`: added `-x` flag to run crosswalk evaluation tool
- `fim_post_processing.sh`: changed hardcoded `/foss_fim/tools` to `toolsDir` environment variable
- `fim_pre_processing.sh`: added `evaluateCrosswalk` environment variable
- `src/`
- `add_crosswalk.py`: fix bug
- `delineate_hydros_and_produce_HAND.sh`: added a call to `verify_crosswalk.py` if evaluateCrosswalk is True.

<br/><br/>

## v4.4.8.3 - 2024-01-05 - [PR#1059](https://github.com/NOAA-OWP/inundation-mapping/pull/1059)

Fixes erroneous branch inundation in levee-protected areas.
Expand Down
1 change: 1 addition & 0 deletions fim_pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ usage()
will be skipped.
-isaws : If this param is included, AWS objects will be used where possible
- Note: This feature is not yet implemented.
-x : If this param is included, the crosswalk will be evaluated.


Running 'fim_pipeline.sh' is a quicker process than running all three scripts independently; however,
Expand Down
2 changes: 1 addition & 1 deletion fim_post_processing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ echo
echo -e $startDiv"Combining crosswalk tables"
# aggregate outputs
Tstart
python3 /foss_fim/tools/combine_crosswalk_tables.py \
python3 $toolsDir/combine_crosswalk_tables.py \
-d $outputDestDir \
-o $outputDestDir/crosswalk_table.csv
Tcount
Expand Down
5 changes: 5 additions & 0 deletions fim_pre_processing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ in
-isaws)
isAWS=1
;;
-x)
evaluateCrosswalk=1
;;
*) ;;
esac
shift
Expand Down Expand Up @@ -129,6 +132,7 @@ if [ "$jobBranchLimit" = "" ]; then jobBranchLimit=1; fi
if [ -z "$overwrite" ]; then overwrite=0; fi
if [ -z "$skipcal" ]; then skipcal=0; fi
if [ -z "$isAWS" ]; then isAWS=0; fi
if [ -z "$evaluateCrosswalk" ]; then evaluateCrosswalk=0; fi

# validate and set defaults for the deny lists
if [ "$deny_unit_list" = "" ]
Expand Down Expand Up @@ -234,6 +238,7 @@ echo "export deny_branch_zero_list=$deny_branch_zero_list" >> $args_file
echo "export has_deny_branch_zero_override=$has_deny_branch_zero_override" >> $args_file
echo "export isAWS=$isAWS" >> $args_file
echo "export skipcal=$skipcal" >> $args_file
echo "export evaluateCrosswalk=$evaluateCrosswalk" >> $args_file

echo "--- Pre-processing is complete"

Expand Down
6 changes: 5 additions & 1 deletion src/add_crosswalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ def add_crosswalk(
else:
update_id = output_flows.loc[output_flows.HydroID == short_id]['HydroID'].item()

str_order = output_flows.loc[output_flows.HydroID == short_id]['order_'].item()
output_order = output_flows.loc[output_flows.HydroID == short_id]['order_']
if len(output_order) == 1:
str_order = output_order.item()
else:
str_order = output_order.max()
sml_segs = pd.concat(
[
sml_segs,
Expand Down
17 changes: 16 additions & 1 deletion src/delineate_hydros_and_produce_HAND.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ T_total_start

## MASK LEVEE-PROTECTED AREAS FROM DEM ##
if [ "$mask_leveed_area_toggle" = "True" ] && [ -f $tempHucDataDir/LeveeProtectedAreas_subset.gpkg ]; then
echo -e $startDiv"Mask levee-protected areas from DEM (*Overwrite dem_meters.tif output) $hucNumber $branch_zero_id"
echo -e $startDiv"Mask levee-protected areas from DEM (*Overwrite dem_meters.tif output) $hucNumber $current_branch_id"
date -u
Tstart
python3 $srcDir/mask_dem.py \
Expand Down Expand Up @@ -303,3 +303,18 @@ python3 $srcDir/add_crosswalk.py \
-e $min_catchment_area \
-g $min_stream_length
Tcount

## EVALUATE CROSSWALK ##
if [ "$current_branch_id" = "$branch_zero_id" ] && [ "$evaluateCrosswalk" = "1" ] ; then
echo -e $startDiv"Evaluate crosswalk $hucNumber $current_branch_id"
date -u
Tstart
python3 $toolsDir/evaluate_crosswalk.py \
-a $tempCurrentBranchDataDir/demDerived_reaches_split_filtered_addedAttributes_crosswalked_$current_branch_id.gpkg \
-b $b_arg \
-c $tempHucDataDir/crosswalk_evaluation_$current_branch_id.csv \
-d $tempHucDataDir/nwm_headwater_points_subset.gpkg \
-u $hucNumber \
-z $current_branch_id
Tcount
fi
Loading