Open rburghol opened 1 year ago
@megpritch @juliabruneau Super exciting outcome on this script. I did a couple tweaks in #723, but nothing big.
Better new: Tried this same script on another file that had multiple LRsegs in it, config/catalog/geo/vahydro/land_water_area.csv
, and it friggin worked out of the box! The only hitch was that land_water_area.csv
has funny column headers with parentheses "(" and the 3-asterisks at the end.
Those get stripped and replaced with ".", so the header goes from:
riverseg,landseg,area(acres)***
to
riverseg,landseg,area.acres....
Did you all figure out a clean way to restore the files header line that would work without knowing what the header line was supposed to be?
If we can figure out the header glitch, this script should work for any land/river data set that needs to be proportioned, so a lot of work gets done for us...
Testing water balance:
./run/resegment/sub_divide_watershed JL1_6562_6560 JL1_6560_6440 cbp-6.1 subsheds 9.52
subsheds
./run/resegment/sub_divide_watershed JL1_6562_6560 JL1_6560_6440 cbp-6.1 subsheds 50
p6ss
hspf
and hsp2
basin=JL1_6560_6440
segs=`cbp get_riversegs $basin`
scenario="p6ss"
model="hspf_cbp6"
for i in $segs; do
deps=`cbp mm_river_deps $scenario $i`
echo "Segment $i Found deps= $deps"
job_name=`cbp mm_job_name $scenario $i`
echo "sbatch --job-name=$job_name $deps /opt/model/meta_model/run_model $model $scenario $i auto river"
sbatch --job-name=$job_name $deps /opt/model/meta_model/run_model $model $scenario $i auto river
done
# use R to query and sum land use
library("data.table")
library("sqldf")
lu <- read.csv("/opt/model/p6/vadeq/input/scenario/river/land_use/land_use_2013VAHYDRO2018615.csv")
# compare to:
# lu <- read.csv("/opt/model/p6/vadeq/input/scenario/river/land_use/land_use_2013BASE20180615.csv")
lwa <- read.csv("/opt/model/p6/vadeq/config/catalog/geo/vahydro/land_water_area.csv")
# isolate watersheds
lu_mr <- sqldf("select * from lu where riverseg = 'JL1_6560_6440'")
lu_bc <- sqldf("select * from lu where riverseg = 'JL1_6562_6560'")
lwa_mr <- sqldf("select * from lwa where riverseg = 'JL1_6560_6440'")
lwa_bc <- sqldf("select * from lwa where riverseg = 'JL1_6562_6560'")
# verify LU just the acre columns:
sum(lu_mr[1,3:length(lu_mr[1,])])
sum(lu_bc[1,3:length(lu_bc[1,])])
# verify lwa
sum(lwa_mr[1,3:length(lwa_mr[1,])])
sum(lwa_bc[1,3:length(lwa_bc[1,])])
Check the WDMs for eos
and stream
cbp wdmexp subsheds river/eos JL1_6560_6440.wdm 11 1984 2020
cbp wdmexp subsheds river/stream JL1_6560_6440.wdm 11 1984 2020
cbp wdmexp p6ss river/eos JL1_6560_6440.wdm 11 1984 2020
cbp wdmexp p6ss river/stream JL1_6560_6440.wdm 11 1984 2020
p6ss
appears to check out! p6ss
: cbp wdmexp p6ss river/stream JL1_6560_6440.wdm 111 1984 2020
subsheds
:cbp wdmexp subsheds river/stream JL1_6560_6440.wdm 111 1984 2020
hsp2_cbp6
, since this was not enabled in hspf_cbp6
?Hourly files:
_hydr
file summary. So hydr is faithful representation of 111.
library("data.table")
data.table 1.14.2 using 8 threads (see ?getDTthreads). Latest news: r-datatable.com
> ss_h <- read.csv("/media/model/p6/out/river/subsheds/hydr/JL1_6560_6440_hydr.csv")
> ss_s read.csv("/media/model/p6/out/river/p6ss/hydr/JL1_6560_6440_hydr.csv")
Error: unexpected symbol in "ss_s read.csv"
> ss_s <- read.csv("/media/model/p6/out/river/p6ss/hydr/JL1_6560_6440_hydr.csv")
> avg(ss_s$OVOL3)
Error in avg(ss_s$OVOL3) : could not find function "avg"
> mean(ss_s$OVOL3)
[1] 12.29902
> mean(ss_h$OVOL3)
[1] 8.857211
cbp wdmexp p6ss river/stream JL1_6562_6560.wdm 111 1984 202
hourly average = 4.2521007611897845
cbp wdmexp p6ss river/stream JL1_6560_6440.wdm 10 1984 2020
hourly average = 4.2521007611897845
cbp wdmexp p6ss river/eos JL1_6560_6440.wdm 11 1984 2020
hourly average = 3.8349030073749422
cbp wdmexp p6ss river/stream JL1_6560_6440.wdm 11 1984 202
hourly average = 8.0870037696102397
3.83 + 4.25 = 8.08
4.25 (10) + 8.08(11)
and results in
cbp wdmexp p6ss river/stream JL1_6560_6440.wdm 111 1984 2020
hourly average = 12.300728864283556
Will need a function that takes 1 to n source land/river seg entries in a CSV and subtracts the area ratio proportion from the receiving watershed, and creates new lines for each land/riverseg combo using the new riverseg, and each land seg flowing into the receiving watershed.
Code 1: Small alteration based on code in pull request: https://github.com/HARPgroup/HARParchive/pull/719 . This preserves the land segment names, so there can be no confusion on that front.
Code 2: Update recieving segment LU.