library(woody) library(tidyverse) library(DiagrammeR)
grViz(" digraph boxes_and_circles { graph [overlap = true, fontsize = 10] node [shape = box, style= filled] wpath [fillcolor = burlywood1] qpath [fillcolor = cadetblue1] W [fillcolor = burlywood1] Q [fillcolor = cadetblue1] Wc [fillcolor = darkkhaki] Qc [fillcolor = cadetblue1] Q [fillcolor = cadetblue1] Wwt [fillcolor = darkkhaki] Wwt_test [fillcolor = darkkhaki] myrf [fillcolor = gold] Wp [fillcolor = darkolivegreen2] node [shape = ellipse,fixedsize = false,color = grey, style= filled, fillcolor=grey90] 'import_Wdata()' 'import_Qdata()' 'complete_Qdata()' 'complete_Wdata_with_Qdata()' 'Wdata_as_waiting_times()' 'run_rf()' 'predict_rf()' # several 'edge' statements wpath -> 'import_Wdata()' [arrowhead = none] 'import_Wdata()'-> W qpath -> 'import_Qdata()' [arrowhead = none] 'import_Qdata()'-> Q Q -> 'complete_Qdata()' [arrowhead=none] 'complete_Qdata()' -> Qc W -> 'complete_Wdata_with_Qdata()' [arrowhead=none] Qc-> 'complete_Wdata_with_Qdata()' [arrowhead=none] 'complete_Wdata_with_Qdata()' -> Wc Wc -> 'Wdata_as_waiting_times()' [arrowhead=none] 'Wdata_as_waiting_times()' -> Wwt Wwt -> 'run_rf()' [arrowhead = none] 'run_rf()' -> myrf myrf -> 'predict_rf()' [arrowhead = none] 'Wwt_test' -> 'predict_rf()' [arrowhead = none] 'predict_rf()' -> 'Wp' } ")
W
data about wood occurrencesgrViz(" digraph boxes_and_circles { graph [overlap = true, fontsize = 10] node [shape = box, style= filled] wpath [fillcolor = burlywood] W [fillcolor = burlywood] node [shape = ellipse,fixedsize = false,color = grey, style= filled, fillcolor=grey90] 'import_Wdata()' # several 'edge' statements wpath -> 'import_Wdata()' [arrowhead = none] 'import_Wdata()'-> W } ")
wpath="../data-raw/mem_data/woody_data_train/" mystation="V2942010" fs::dir_tree(wpath)
library(woody)
Import all wood log files inside a file (1 directory per event)
W=import_Wdata(wpath,site="training")
Q
data about dischargegrViz(" digraph boxes_and_circles { graph [overlap = true, fontsize = 10] graph [overlap = true, fontsize = 10] node [shape = box, style= filled] qpath [fillcolor = cadetblue1] Q [fillcolor = cadetblue1] node [shape = ellipse,fixedsize = false,color = grey, style= filled, fillcolor=grey90] 'import_Qdata()' qpath -> 'import_Qdata()' [arrowhead = none] 'import_Qdata()'-> Q } ")
Import Q
:
qpath="../data-raw/Qdata/Qdatc_Ain.csv" Q=import_Qdata(path=qpath, site="Ain")
The first lines of Q
look like this
knitr::kable(head(Q))
Q
into Qc
grViz(" digraph boxes_and_circles { graph [overlap = true, fontsize = 10] node [shape = box, style= filled] Qc [fillcolor = cadetblue1] Q [fillcolor = cadetblue1] node [shape = ellipse,fixedsize = false,color = grey, style= filled, fillcolor=grey90] 'complete_Qdata()' # several 'edge' statements Q -> 'complete_Qdata()' [arrowhead=none] 'complete_Qdata()' -> Qc } ")
Now complete Q
with variables T_Q and S
result_file="../data-raw/results/Q.RDS" if(!file.exists(result_file)){ Qc=complete_Qdata(qtvar=Q,site="Ain") saveRDS(Qc,result_file) } Qc=readRDS(result_file)
The first lines of Qc
look like this:
knitr::kable(head(Qc))
W
with Q
and get Wc
grViz(" digraph boxes_and_circles { graph [overlap = true, fontsize = 10] node [shape = box, style= filled] W [fillcolor = burlywood] Wc [fillcolor = darkkhaki] Qc [fillcolor = cadetblue1] node [shape = ellipse,fixedsize = false,color = grey, style= filled, fillcolor=grey90] 'complete_Wdata_with_Qdata()' # several 'edge' statements W -> 'complete_Wdata_with_Qdata()' [arrowhead=none] Qc-> 'complete_Wdata_with_Qdata()' [arrowhead=none] 'complete_Wdata_with_Qdata()' -> Wc } ")
Complete W
with discharge data (interpolating Q
)
Wc=complete_Wdata_with_Qdata(Wdata=W, Qdata=Qc)
The first lines of Wc
look like this:
knitr::kable(head(Wc))
Wc
into Wwt
grViz(" digraph boxes_and_circles { graph [overlap = true, fontsize = 10] node [shape = box, style= filled] Wc [fillcolor = darkkhaki] Wwt [fillcolor = darkkhaki] node [shape = ellipse,fixedsize = false,color = grey, style= filled, fillcolor=grey90] 'Wdata_as_waiting_times()' # several 'edge' statements Wc -> 'Wdata_as_waiting_times()' [arrowhead=none] 'Wdata_as_waiting_times()' -> Wwt } ")
Then calculate Wwt
, where 1 row= 1 waiting time between two wood occurrences.
Wwt=Wdata_as_waiting_times(Wc)
The first lines of Wwt
look like this:
knitr::kable(head(Wwt))
grViz(" digraph boxes_and_circles { graph [overlap = true, fontsize = 10] node [shape = box, style= filled] Wwt [fillcolor = darkkhaki] myrf [fillcolor = gold] node [shape = ellipse,fixedsize = false,color = grey, style= filled, fillcolor=grey90] 'run_rf()' # several 'edge' statements Wwt -> 'run_rf()' [arrowhead = none] 'run_rf()' -> myrf } ")
myrf <- run_rf(Wwt) myrf
grViz(" digraph boxes_and_circles { graph [overlap = true, fontsize = 10] node [shape = box, style= filled] Wwt_test [fillcolor = darkkhaki] myrf [fillcolor = gold] Wp [fillcolor = darkolivegreen2] node [shape = ellipse,fixedsize = false,color = grey, style= filled, fillcolor=grey90] 'predict_rf()' # several 'edge' statements Wwt_test -> 'predict_rf()' [arrowhead = none] myrf -> 'predict_rf()' [arrowhead = none] 'predict_rf()' -> 'Wp' } ")
Predict on training data itself
Wp=predict_rf(obj_rf=myrf, newdata=Wwt)
R2:
calc_rf_R2(Wp)
wpathpred="../data-raw/mem_data/woody_data_predict/" Wwt_test=import_Wdata(wpathpred) %>% complete_Wdata_with_Qdata(Qc) %>% Wdata_as_waiting_times() Wp_test=predict_rf(Wwt_test,myrf) calc_rf_R2(Wp_test)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.