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
621ca544
Commit
621ca544
authored
3 years ago
by
Bock, Andy
Browse files
Options
Downloads
Patches
Plain Diff
Added travel time split
parent
96db245d
No related branches found
No related tags found
1 merge request
!124
Reservoir Mods, POI mods
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
workspace/R/NHD_navigate.R
+80
-0
80 additions, 0 deletions
workspace/R/NHD_navigate.R
with
80 additions
and
0 deletions
workspace/R/NHD_navigate.R
+
80
−
0
View file @
621ca544
...
@@ -695,3 +695,83 @@ split_elev <- function(in_POI_ID, split_DF, elev_diff, max_DA){
...
@@ -695,3 +695,83 @@ split_elev <- function(in_POI_ID, split_DF, elev_diff, max_DA){
return
(
split_elev_DF
)
return
(
split_elev_DF
)
}
}
#' Splits a network based on estimated travel time and drainage area
#' @param in_POI_ID (integer) POI_ID of aggregated flowline that needs to be
#' split based on travel time
#' @param split_DF (sf data.frame) flowlines attributed with POI_ID
#' @param tt_diff (numeric) max travel time change threshold within a segment
#' @param max_DA (numeric) minimum drainage area for resulting split
#'
#' @return (sf data.frame) flowlines with new POI_IDs identified (elev_POI_ID)
split_tt
<-
function
(
in_POI_ID
,
split_DF
,
tt_diff
,
max_DA
){
# subset to a given POI_ID
split_tt_DF
<-
filter
(
split_DF
,
POI_ID
==
in_POI_ID
)
%>%
mutate
(
inc_seg_area
=
c
(
TotDASqKM
[
1
],
(
TotDASqKM
-
lag
(
TotDASqKM
))[
-1
]))
first_iter
<-
unique
(
split_tt_DF
$
iter
)
# Iterate through segs that need splitting
for
(
i
in
c
(
first_iter
:
max
(
split_DF
$
iter
,
na.rm
=
T
))){
#print(i)
# first split
tt_pois_init_iter
<-
split_tt_DF
%>%
# filter by iteration, comes into play when multiple splits
# are required per single POI_ID
filter
(
iter
==
i
)
%>%
# Recalculate inc elev, length, and area based on the last split
mutate
(
csum_length
=
cumsum
(
LENGTHKM
),
cumsum_tt
=
cumsum
(
FL_tt_hrs
),
sum_area
=
cumsum
(
inc_seg_area
))
%>%
# Determine if split actually necessary on this iteration
filter
(
sum
(
FL_tt_hrs
)
>
tt_diff
,
TotDASqKM
>
max_DA
)
%>%
# This is an important step, identify which row to split on based on incremental
# elevaton value. Some flowlines exceed the elevation difference threshold
# The 'split_index' values determiens which row to create a new POI on
mutate
(
split_index
=
ifelse
(
nrow
(
filter
(
.
,
cumsum_tt
>
(
tt_diff
)))
==
nrow
(
.
),
1
,
nrow
(
filter
(
.
,
cumsum_tt
<
(
tt_diff
)))))
%>%
# Take out if at last iteration to avoid duplicating existng POIs
filter
(
!
COMID
==
POI_ID
)
if
(
nrow
()
==
0
){
#print("done")
# Done iterating on possible splits
return
(
split_tt_DF
)}
tt_pois_init_iter
# Get the flowline POI
tt_pois_init_pre
<-
tt_pois_init_iter
%>%
filter
(
row_number
()
==
split_index
)
%>%
mutate
(
new_POI_ID
=
COMID
)
%>%
select
(
COMID
,
POI_ID
,
new_POI_ID
,
Hydroseq_cut
=
Hydroseq
)
# Remaining rows downstream after split
tt_pois_init_post
<-
tt_pois_init_iter
%>%
left_join
(
select
(
tt_pois_init_pre
,
-
COMID
),
by
=
"POI_ID"
)
%>%
filter
(
Hydroseq
<
Hydroseq_cut
)
%>%
ungroup
()
# Test for if we need to split again
if
(
nrow
(
tt_pois_init_post
)
>
0
){
#print("yope")
# Re-cacl the iter based on results above
split_tt_DF
<-
split_tt_DF
%>%
left_join
(
select
(
tt_pois_init_pre
,
-
COMID
),
by
=
"POI_ID"
)
%>%
mutate
(
tt_POI_ID
=
ifelse
((
is.na
(
elev_POI_ID
)
&
Hydroseq
>=
Hydroseq_cut
),
new_POI_ID
,
tt_POI_ID
),
iter
=
ifelse
((
!
is.na
(
new_POI_ID
)
&
Hydroseq
<
Hydroseq_cut
),
iter
+
1
,
orig_iter
))
%>%
select
(
-
c
(
new_POI_ID
,
Hydroseq_cut
))
%>%
ungroup
()
}
else
{
split_tt_DF
<-
split_tt_DF
%>%
left_join
(
select
(
tt_pois_init_pre
,
-
COMID
),
by
=
"POI_ID"
)
%>%
mutate
(
tt_POI_ID
=
ifelse
((
is.na
(
tt_POI_ID
)
&
Hydroseq
>=
Hydroseq_cut
),
new_POI_ID
,
tt_POI_ID
),
iter
=
ifelse
((
!
is.na
(
new_POI_ID
)
&
Hydroseq
<
Hydroseq_cut
),
0
,
orig_iter
))
%>%
select
(
-
c
(
new_POI_ID
,
Hydroseq_cut
))
%>%
ungroup
()
}
}
return
(
split_tt_DF
)
}
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