-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_model_data.R
More file actions
30 lines (22 loc) · 996 Bytes
/
add_model_data.R
File metadata and controls
30 lines (22 loc) · 996 Bytes
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
add_model_data <- function(timeseries_data, land_type_code, model_col, scenario="subsheds", site=omsite) {
# Timeseries data must have year, month, and day columns
source("https://raw.githubusercontent.com/HARPgroup/baseflow_storage/refs/heads/main/make_model_daily.R")
# Get model data from given land code and land type
model_data <- read.csv(paste0(site,"/p6/out/land/", scenario, "/pwater/", land_type_code,"_pwater.csv"))
# Make model data daily using func make_model_daily
model_data <- make_model_daily(model_data, "index")
# select date and column from model data
m_col <- sqldf(sprintf(
"select year, month, day, %s from model_data"
, model_col))
#combine m_col and original data
final_df <- sqldf(sprintf(
"select a.*, b.%s from
timeseries_data as a
left outer join m_col as b
on( a.Year = b.year and
a.Month = b.month and
a.Day = b.day)"
, model_col))
return(final_df)
}