SamsaraLightLoader is a module of the Capsis platform that allows to test the SamsaraLight library. From inventory data (spatialized trees) and weather data, this module allows to estimate the amount of light that is intercepted by the trees or that is transmitted to different points in the understory.
RCapsis is an R package allowing to use Capsis and Java objects directly from R. https://sourceforge.net/projects/rcapsis.capsisbridge.p/
The objective of this document is to illustrate the use of these two tools. The approach proposed here allows to estimate the light intercepted by the trees of different plots.
library(RCapsis)
## Loading required package: J4R
## Welcome to J4R!
## Please, make sure that Java (version 8 or later) is installed on your computer.
## For more information, visit https://sourceforge.net/p/repiceasource/wiki/J4R/ .
library(tidyverse)
## -- Attaching packages ------------------------------------------------------------------------------------------------------ tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.0.3 v dplyr 1.0.2
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 4.0.5
## -- Conflicts --------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
path="c:/Eclipse_Workspace/capsis4/"
setCapsisPath(path = path)
connectToCapsis()
## Starting local Java server...
## [1] TRUE
A script has been implmented in SamsaraLightLoader. This script is initialized providing the adresses of four directories containing the inventory files, weather files or directories where output will be written.
tree_dir <- createJavaObject("java.io.File", "c:/Data_G_current/J4R/20210630_lilo/tree")
meteo_dir <- createJavaObject("java.io.File", "c:/Data_G_current/J4R/20210630_lilo/meteo")
output_dir <- createJavaObject("java.io.File", "c:/Data_G_current/J4R/20210630_lilo/output")
export_dir <- createJavaObject("java.io.File", "c:/Data_G_current/J4R/20210630_lilo/export")
export <- createJavaObject("samsaralightloader.myscripts.LiloExportTreeLight", tree_dir, meteo_dir, output_dir, export_dir)
The next step run the computation for each combination of inventory and weather file.
export$doAnalysis() #takes time : it runs the simulation.
The results can be store in a csv file or imported as R objects.
export$writeResults() #write a csv file
results<-export$getResults()
n_items <- results$size()
indexes <- as.integer(0:(n_items-1))
items<-results$get(indexes)
capsis.output<-tibble(site=items$site[indexes],
meteo=items$meteo[indexes],
id = items$id[indexes],
species = items$species[indexes],
dbh = items$dbh[indexes],
e = items$e[indexes],
epot = items$epot[indexes]
)
head(capsis.output)
## # A tibble: 6 x 7
## site meteo id species dbh e epot
## <chr> <chr> <int> <chr> <dbl> <dbl> <dbl>
## 1 inventory1 meteo 98 pseudotsuga 63.0 214049. 521837.
## 2 inventory1 meteo 45 pseudotsuga 66.5 158742. 497859.
## 3 inventory1 meteo 140 pseudotsuga 41.7 45256. 149044.
## 4 inventory1 meteo 47 pseudotsuga 50.9 40937. 328474.
## 5 inventory1 meteo 87 pseudotsuga 59.8 141559. 339908.
## 6 inventory1 meteo 56 pseudotsuga 60.5 162038. 593316.
ggplot(data=capsis.output, aes(x=dbh,y=e))+facet_wrap(~site)+geom_point()+stat_smooth()+ylab("Intercept light (MJ)")+xlab("dbh (cm)")
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
shutdownClient()
## Closing connections and removing sockets...
## Done.