Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
swatdoctr
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph Schürz
swatdoctr
Commits
29e997fe
Commit
29e997fe
authored
2 years ago
by
Christoph Schürz
Browse files
Options
Downloads
Patches
Plain Diff
Add luse tables to read out after sim, update read_tbl
parent
3da14197
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/run_swat_verify.R
+19
-8
19 additions, 8 deletions
R/run_swat_verify.R
with
19 additions
and
8 deletions
R/run_swat_verify.R
+
19
−
8
View file @
29e997fe
...
...
@@ -66,14 +66,20 @@ run_swat_verification <- function(project_path, outputs = c('wb', 'mgt', 'plt'),
model_output
<-
list
()
if
(
'plt'
%in%
outputs
)
{
model_output
$
hru_pw_day
<-
read_tbl
(
'hru_pw_day'
,
run_path
)
model_output
$
hru_pw_day
<-
read_tbl
(
'hru_pw_day
.txt
'
,
run_path
,
3
)
}
if
(
'wb'
%in%
outputs
)
{
model_output
$
basin_wb_day
<-
read_tbl
(
'basin_wb_day'
,
run_path
)
model_output
$
basin_pw_day
<-
read_tbl
(
'basin_pw_day'
,
run_path
)
model_output
$
basin_wb_day
<-
read_tbl
(
'basin_wb_day
.txt
'
,
run_path
,
3
)
model_output
$
basin_pw_day
<-
read_tbl
(
'basin_pw_day
.txt
'
,
run_path
,
3
)
}
if
(
'mgt'
%in%
outputs
)
{
model_output
$
mgt_out
<-
read_mgt
(
run_path
)
hru_data
<-
read_tbl
(
'hru-data.hru'
,
run_path
,
2
)
landuse_lum
<-
read_tbl
(
'landuse.lum'
,
run_path
,
2
)
model_output
$
lum_mgt
<-
left_join
(
hru_data
,
landuse_lum
,
by
=
c
(
"lu_mgt"
=
'name'
))
%>%
select
(
id
,
topo
,
hydro
,
soil
,
lu_mgt
,
mgt
)
}
}
...
...
@@ -153,6 +159,7 @@ find_swat_exe <- function(project_path, os) {
#'
#' @param out_file Name of the output file that should be read.
#' @param run_path Path to the folder where simulations are performed
#' @param n_skip Integer number, how many lines to skip when reading table
#'
#' @importFrom data.table fread
#' @importFrom purrr set_names
...
...
@@ -162,8 +169,8 @@ find_swat_exe <- function(project_path, os) {
#'
#' @keywords internal
#'
read_tbl
<-
function
(
out_
file
,
run_path
)
{
file_path
<-
paste0
(
run_path
,
'/'
,
out_file
,
'.txt'
)
read_tbl
<-
function
(
file
,
run_path
,
n_skip
)
{
file_path
<-
paste0
(
run_path
,
'/'
,
file
)
col_names
<-
read_lines
(
file
=
file_path
,
skip
=
1
,
n_max
=
1
)
%>%
str_trim
(
.
)
%>%
...
...
@@ -179,7 +186,7 @@ read_tbl <- function(out_file, run_path) {
}
}
fread
(
file_path
,
skip
=
3
)
%>%
fread
(
file_path
,
skip
=
n_skip
,
header
=
FALSE
)
%>%
set_names
(
.
,
col_names
)
%>%
tibble
(
.
)
}
...
...
@@ -188,7 +195,7 @@ read_tbl <- function(out_file, run_path) {
#'
#' @param run_path Path to the folder where simulations are performed
#'
#' @importFrom purrr map set_names
#' @importFrom purrr map
map_df
set_names
#' @importFrom stringr str_trim str_split
#' @importFrom tibble as_tibble
#' @importFrom vroom vroom_lines
...
...
@@ -198,7 +205,7 @@ read_tbl <- function(out_file, run_path) {
read_mgt
<-
function
(
run_path
)
{
file_path
<-
paste0
(
run_path
,
'/mgt_out.txt'
)
vroom_lines
(
file_path
,
skip
=
3
)
%>%
mgt
<-
vroom_lines
(
file_path
,
skip
=
3
)
%>%
str_trim
(
.
)
%>%
str_split
(
.
,
'\t[:space:]+|[:space:]+'
)
%>%
map
(
.
,
~
.x
[
1
:
21
])
%>%
...
...
@@ -210,6 +217,10 @@ read_mgt <- function(run_path) {
'phubase'
,
'phuplant'
,
'soil_water'
,
'plant_bioms'
,
'surf_rsd'
,
'soil_no3'
,
'soil_solp'
,
'op_var'
,
paste0
(
'var'
,
1
:
7
)))
mgt
[,
c
(
1
:
4
,
7
:
21
)]
<-
map_df
(
mgt
[,
c
(
1
:
4
,
7
:
21
)],
as.numeric
)
return
(
mgt
)
}
...
...
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