-
Notifications
You must be signed in to change notification settings - Fork 26
/
fim_post_processing.sh
executable file
·229 lines (200 loc) · 7.2 KB
/
fim_post_processing.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash -e
:
usage()
{
echo "
Post processing for creating FIM hydrofabric.
Usage : fim_post_processing.sh [REQ: -n <run name> ] [OPT: -h -j <job limit>]
REQUIRED:
-n/--runName : A name to tag the output directories and log files.
OPTIONS:
-h/--help : help file
-j/--jobLimit : max number of concurrent jobs to run. Default 1 job at time. 1 outputs
stdout and stderr to terminal and logs. With >1 outputs progress and logs the rest.
Note: Not the same variable name as fim_pipeline or fim_pre_processing
and can be the multiplication of jobHucLimit and jobBranchLimit
"
exit
}
while [ "$1" != "" ]; do
case $1
in
-n|--runName)
shift
runName=$1
;;
-j|--jobLimit)
shift
jobLimit=$1
;;
-h|--help)
shift
usage
;;
*) ;;
esac
shift
done
# print usage if arguments empty
if [ "$runName" = "" ]
then
echo "ERROR: Missing -n run time name argument"
usage
exit 22
fi
outputDestDir=$outputsDir/$runName
## Check for output destination directory ##
if [ ! -d "$outputDestDir" ]; then
echo "Depends on output from units and branches. "
echo "Please provide an output folder name that has hucs/branches run."
exit 1
fi
#########################################################################################
# #
# PLEASE DO NOT USE the job limits coming in from the runtime_args.env #
# Most of the time, post processing will not be run on the same servers #
# that is running fim_process_unit_wb.sh and the processing power #
# used to run fim_post_processing.sh will be different (hence.. different job limit) #
# #
#########################################################################################
if [ "$jobLimit" = "" ]; then jobLimit=1; fi
# Clean out the other post processing files before starting
rm -rdf $outputDestDir/logs/src_optimization
rm -f $outputDestDir/logs/log_bankfull_indentify.log
rm -f $outputDestDir/logs/subdiv_src_.log
# load up enviromental information
args_file=$outputDestDir/runtime_args.env
fim_inputs=$outputDestDir/fim_inputs.csv
source $args_file
source $outputDestDir/params.env
source $srcDir/bash_functions.env
source $srcDir/bash_variables.env
echo
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "---- Start of fim_post_processing"
echo "---- Started: `date -u`"
T_total_start
post_proc_start_time=`date +%s`
## AGGREGATE BRANCH LISTS INTO ONE ##
echo -e $startDiv"Start branch aggregation"
python3 $srcDir/aggregate_branch_lists.py -d $outputDestDir -f "branch_ids.csv" -o $fim_inputs
## GET NON ZERO EXIT CODES FOR BRANCHES ##
echo -e $startDiv"Start non-zero exit code checking"
find $outputDestDir/logs/branch -name "*_branch_*.log" -type f | \
xargs grep -E "Exit status: ([1-9][0-9]{0,2})" > \
"$outputDestDir/branch_errors/non_zero_exit_codes.log" &
## RUN AGGREGATE BRANCH ELEV TABLES ##
echo "Processing usgs & ras2fim elev table aggregation"
python3 $srcDir/aggregate_by_huc.py -fim $outputDestDir -i $fim_inputs -elev -ras -j $jobLimit
## RUN BATHYMETRY ADJUSTMENT ROUTINE ##
if [ "$bathymetry_adjust" = "True" ]; then
echo -e $startDiv"Performing Bathymetry Adjustment routine"
# Run bathymetry adjustment routine
Tstart
python3 $srcDir/bathymetric_adjustment.py \
-fim_dir $outputDestDir \
-bathy $bathymetry_file \
-buffer $wbd_buffer \
-wbd $inputsDir/wbd/WBD_National_EPSG_5070_WBDHU8_clip_dem_domain.gpkg \
-j $jobLimit
Tcount
fi
## RUN SYNTHETIC RATING CURVE BANKFULL ESTIMATION ROUTINE ##
if [ "$src_bankfull_toggle" = "True" ]; then
echo -e $startDiv"Estimating bankfull stage in SRCs"
# Run SRC bankfull estimation routine routine
Tstart
python3 $srcDir/identify_src_bankfull.py \
-fim_dir $outputDestDir \
-flows $bankfull_flows_file \
-j $jobLimit
Tcount
fi
## RUN SYNTHETIC RATING SUBDIVISION ROUTINE ##
if [ "$src_subdiv_toggle" = "True" ] && [ "$src_bankfull_toggle" = "True" ]; then
echo -e $startDiv"Performing SRC channel/overbank subdivision routine"
# Run SRC Subdivision & Variable Roughness routine
Tstart
python3 $srcDir/subdiv_chan_obank_src.py \
-fim_dir $outputDestDir \
-mann $vmann_input_file \
-j $jobLimit
Tcount
fi
## RUN SYNTHETIC RATING CURVE CALIBRATION W/ USGS GAGE RATING CURVES ##
if [ "$src_adjust_usgs" = "True" ] && [ "$src_subdiv_toggle" = "True" ] && [ "$skipcal" = "0" ]; then
Tstart
echo
echo -e $startDiv"Performing SRC adjustments using USGS rating curve database"
# Run SRC Optimization routine using USGS rating curve data (WSE and flow @ NWM recur flow values)
python3 $srcDir/src_adjust_usgs_rating_trace.py \
-run_dir $outputDestDir \
-usgs_rc $usgs_rating_curve_csv \
-nwm_recur $nwm_recur_file \
-j $jobLimit
Tcount
date -u
fi
## RUN SYNTHETIC RATING CURVE CALIBRATION W/ RAS2FIM CROSS SECTION RATING CURVES ##
if [ "$src_adjust_ras2fim" = "True" ] && [ "$src_subdiv_toggle" = "True" ] && [ "$skipcal" = "0" ]; then
Tstart
echo
echo -e $startDiv"Performing SRC adjustments using ras2fim rating curve database"
# Run SRC Optimization routine using ras2fim rating curve data (WSE and flow @ NWM recur flow values)
python3 $srcDir/src_adjust_ras2fim_rating.py \
-run_dir $outputDestDir \
-ras_rc $ras_rating_curve_csv \
-nwm_recur $nwm_recur_file \
-j $jobLimit
Tcount
date -u
fi
## RUN SYNTHETIC RATING CURVE CALIBRATION W/ BENCHMARK POINTS (.parquet files) ##
if [ "$src_adjust_spatial" = "True" ] && [ "$src_subdiv_toggle" = "True" ] && [ "$skipcal" = "0" ]; then
Tstart
echo
echo -e $startDiv"Performing SRC adjustments using benchmark point .parquet files"
python3 $srcDir/src_adjust_spatial_obs.py -fim_dir $outputDestDir -j $jobLimit
Tcount
date -u
fi
## AGGREGATE BRANCH TABLES ##
echo
echo -e $startDiv"Aggregating branch hydrotables"
Tstart
python3 $srcDir/aggregate_by_huc.py \
-fim $outputDestDir \
-i $fim_inputs \
-htable \
-bridge \
-j $jobLimit
Tcount
date -u
## PERFORM MANUAL CALIBRATION
if [ "$manual_calb_toggle" = "True" ] && [ -f $man_calb_file ]; then
echo
echo -e $startDiv"Performing manual calibration"
Tstart
python3 $srcDir/src_manual_calibration.py \
-fim_dir $outputDestDir \
-calb_file $man_calb_file
Tcount
date -u
fi
echo
echo -e $startDiv"Combining crosswalk tables"
# aggregate outputs
Tstart
python3 $toolsDir/combine_crosswalk_tables.py \
-d $outputDestDir \
-o $outputDestDir/crosswalk_table.csv
Tcount
date -u
find $outputDestDir -type d -exec chmod -R 777 {} +
find $outputDestDir -type f -exec chmod -R 777 {} +
echo
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "---- End of fim_post_processing"
echo "---- Ended: `date -u`"
Calc_Duration $post_proc_start_time
echo