Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
reference-hydrofabric
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Water Mission Area
nhgf
reference-hydrofabric
Commits
4cc570bd
Commit
4cc570bd
authored
3 months ago
by
Blodgett, David L.
Browse files
Options
Downloads
Patches
Plain Diff
add rpu output to prepare_vpu_base_layers for
#153
parent
d6e55009
No related branches found
No related tags found
1 merge request
!183
Refactor - progress
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
workspace/R/2_prep.R
+49
-2
49 additions, 2 deletions
workspace/R/2_prep.R
workspace/_targets.R
+1
-1
1 addition, 1 deletion
workspace/_targets.R
with
50 additions
and
3 deletions
workspace/R/2_prep.R
+
49
−
2
View file @
4cc570bd
...
...
@@ -394,8 +394,9 @@ finalize_gages <- function(SWIM, NHDPlusV2_gages, gfv11_gages, gages_ii_ref,
#' @param nav_gpkg character path to geopackage where vpu base layers will be written
#' @param vpu vpu that will be written into output list
#' @param full_cat_table table of all catchments for each vpu
#' @param rpu_vpu data.frame ontaining all rpu-vpu pairs
#' @return a list with the vpu and three tables for flowlines, waterbodies, and catchments
prepare_vpu_base_layers
<-
function
(
ref_gpkg
,
nav_gpkg
,
vpu
,
full_cat_table
)
{
prepare_vpu_base_layers
<-
function
(
ref_gpkg
,
nav_gpkg
,
vpu
,
full_cat_table
,
rpu_vpu
)
{
fline
<-
read_sf
(
ref_gpkg
,
"flowlines"
)
catchment
<-
read_sf
(
ref_gpkg
,
"catchments"
)
...
...
@@ -439,5 +440,51 @@ prepare_vpu_base_layers <- function(ref_gpkg, nav_gpkg, vpu, full_cat_table) {
write_sf
(
cat_network
,
nav_gpkg
,
nhd_network
)
write_sf
(
waterbodies
,
nav_gpkg
,
nhd_waterbody
)
return
(
list
(
vpu
=
vpu
,
flowline
=
nhd
,
catchment
=
cat_network
,
waterbodies
=
waterbodies
))
rpus
<-
rpu_vpu
[
rpu_vpu
$
vpuid
==
vpu
,]
$
rpuid
cats_rpu
<-
full_cat_table
%>%
filter
(
RPUID
%in%
rpus
)
cats
<-
catchment
%>%
rename
(
FEATUREID
=
featureid
,
AREASQKM
=
areasqkm
)
%>%
mutate
(
VPUID
=
vpu
)
%>%
left_join
(
select
(
cats_rpu
,
FEATUREID
,
RPUID
),
by
=
c
(
"FEATUREID"
))
%>%
filter
(
FEATUREID
%in%
unique
(
c
(
nhd
$
COMID
,
full_cat_table
$
FEATUREID
[
full_cat_table
$
RPUID
%in%
rpus
])))
%>%
mutate
(
hy_cats
=
ifelse
(
FEATUREID
%in%
nhd
$
COMID
,
1
,
0
),
full_cats
=
ifelse
(
FEATUREID
%in%
cats_rpu
$
FEATUREID
,
1
,
0
))
%>%
filter
(
full_cats
==
1
|
hy_cats
==
1
)
%>%
st_sf
()
write_sf
(
cats
,
nav_gpkg
,
nhd_catchment
)
rpu_list
<-
setNames
(
rep
(
list
(
list
()),
length
(
rpus
)),
rpus
)
for
(
rpu_code
in
rpus
)
{
out_refac_gpkg
<-
file.path
(
"cache"
,
paste0
(
rpu_code
,
"_refactor.gpkg"
))
nhd_sub
<-
subset_rpu
(
nhd
,
rpu_code
,
run_make_standalone
=
TRUE
)
%>%
st_sf
()
write_sf
(
nhd_sub
,
out_refac_gpkg
,
nhd_flowline
)
cats_rpu
<-
full_cat_table
%>%
filter
(
RPUID
==
rpu_code
)
catchments
<-
cats
%>%
mutate
(
hy_cats
=
ifelse
(
FEATUREID
%in%
nhd_sub
$
COMID
,
1
,
0
),
full_cats
=
ifelse
(
FEATUREID
%in%
cats_rpu
$
FEATUREID
,
1
,
0
))
%>%
filter
(
full_cats
==
1
|
hy_cats
==
1
)
%>%
st_sf
()
write_sf
(
catchments
,
out_refac_gpkg
,
nhd_catchment
)
rpu_list
[[
rpu_code
]]
<-
list
(
flowline
=
nhd
,
catchment
=
catchments
)
}
return
(
list
(
vpu
=
vpu
,
flowline
=
nhd
,
catchment
=
cats
,
catchment_network
=
cat_network
,
waterbodies
=
waterbodies
,
rpus
=
rpu_list
))
}
This diff is collapsed.
Click to expand it.
workspace/_targets.R
+
1
−
1
View file @
4cc570bd
...
...
@@ -80,6 +80,6 @@ list(
pattern
=
map
(
vpu_codes
)),
# ~1GB of memory
tar_target
(
vpu_base
,
prepare_vpu_base_layers
(
ref_gpkg
,
nav_gpkg
,
vpu_codes
,
full_cat_table
),
tar_target
(
vpu_base
,
prepare_vpu_base_layers
(
ref_gpkg
,
nav_gpkg
,
vpu_codes
,
full_cat_table
,
rpu_vpu
),
pattern
=
map
(
ref_gpkg
,
nav_gpkg
,
vpu_codes
),
deployment
=
"worker"
)
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment