The {martelosim} package is a tool making possible to simulate the evolution of a marteloscope over several decades, a first thinning corresponding to the marking made on the field and later thinning reproducing a strategy deduced from the field marking.
The package uses the model Samsara2 (Lafond et al. (2017), Courbaud et al. (2016), Courbaud et al. (2015)), which is a module of the software CAPSIS. It proposes a specific interface for marteloscopes that facilitates the preparation of all the files describing the marteloscope initial conditions, the loading of field marking information during a marking exercise, the simulation processing, and the production of a standardized output report.
The package is designed to be run by the marteloscope instructor on a computer. During a marteloscope exercise, each marking group enters his marking data on a tablet (we propose an Excel file by default. The EFI I+Trainer can be used also for this step). The marteloscope instructor collects all the marking files and runs the simulations for all the groups on his computer. The package produces a personalized simulation report for each group.
Here are the steps you have to follow:
Specific data describing the initial conditions of your marteloscope
are required to run simulations. You can look at
Data_Marteloscope_Prelenfrey.xlsx (link
to download) for an example and save it with a name corresponding to
your marteloscope (ex
Data_Marteloscope_MyMarteloscope_en.xlsx). The page
Notice describes the variables to fill and indicates which
data is mandatory or optional. Please follow exactly the required data
formats otherwise the martelosim package will not be able to read the
data correctly. The file contains many pages but several of them are
metadata not field data (ex: regeneration size class definitions, price
per species, quality and size) and a lot is optional. If you don’t fill
optional data, Samsara2 will use default values or simulate virtual
objects (ex virtual saplings)
If you have installed your marteloscope following the EFI Integrate+ protocol, you will have some data transformation to make and some additional data to inform but it should not be a big deal. For Samsara2, you have to give only one quality to the whole tree. Samsara2 requires a Z coordinate for every tree in order to calculate light interception correctly. If you have not measured it on the field, you can let this variable empty. An approximate Z will be calculated using the marteloscope average slope and exposure.
If you need to calculate tree X, Y and Z coordinates from field
measures of distances, azimuth and vertical angles between reference
poles and trees, you can use the additional
martelo-main.zip R code by Jean-Matthieu Monnet to convert
field measures into X,Y, Z coordinates.
Java is usually already installed in most computers. However, for Capsis, you need a version 1.8.xxx of Java. To check the version of Java on your computer,
java –versionIf you don’t have a Java 1.8.xxx on your computer, download a “Java SE Runtime Environnement 8” on your machine, https://java.com/en/download/manual.jsp (for Windows choose an offline version) https://www.oracle.com/java/technologies/javase-jre8-downloads.html (subscription is mandatory on this site)
Run the Capsis installer provided to you by LESSEM.
You can download it at this link : download capsis
capsis-Samsara2_4.2.7-22711_setup.jar/My documents/Capsis).Be careful : the Capis version must be compatible with the R package
version you install. The last stable version of
{martelosim} require version 4.2.7-22711 for
Capsis.
To check the version of Capsis on your computer you can go with an explorer into your folder Capsis and open the text file “revision”. Alternatively, when Samsara is running, a message is displayed on the terminal indicating the version.
If you do large simulations, there can be a problem of insufficient RAM (Random Access Memory) allocated to Capsis. If it is the case, you can increase it (within the limit of your machine).
The RAM allocated to Capsis depends on your machine. It is indicated in Megabytes in the text file “memory” in your Capsis folder. Alternatively it is also written in the MS-DOS terminal when you launch Capsis directly :
You can increase it (within the limit of your machine) typing in the terminal the command “setmem” with the nb of Megabytes you want (too large a number can slow calculations):
Link to install R : https://cran.r-project.org/bin/windows/base/
Link to install RStudio : https://posit.co/download/rstudio-desktop/
Open R studio or close any project and paste one of the following commands in the console:
If you are a marteloscope instructor
You should install the last stabilized version of the package, copying and pasting the command line:
install.packages('martelosim', repos = c('https://inrae.r-universe.dev', 'https://cloud.r-project.org'))
If you are a researcher
You can install the current development version with the command line:
if (!require("remotes", quietly = TRUE)) {install.packages("remotes")}
remotes::install_url('https://forge.inrae.fr/lessem/rpackages/martelosim/-/archive/dev/martelosim-dev.zip')
Restart R either in closing and reopening RStudio or by copying and
pasting the command .rs.restartR()
You have to prepare in advance a marteloscope exercise by following the 3 steps in sequence:
On your windows explorer create a directory where you will store all
your marteloscope exercises, and a subdirectory for each marteloscope.
Ex: martelosim_Workshops/Prelenfrey
File/New project (in the upper left menu bar)
New directory
martelosim workshop
Creation menu
Directory name : we suggest that you create a directory
named with the marteloscope and the date of your exercise: ex
Prelenfrey_2024.11.19. You can create right away a
succession of directories to organize your marteloscopes and future
workshops. (ex :
martelosim_Workshops/Prelenfrey/Prelenfrey_2024.11.19)Subdirectory of : indicate the folder in which you want
to store the directory of your exercise : ex
martelosim_Workshops/PrelenfreyMarteloscope site name : Repeat the Marteloscope name :
ex PrelenfreyWorkshop Date : Repeat the workshop date : ex
2024.11.19Capsis path : Click on Browse and develop
the pathway up to your Capsis folder and select the file capsis.shMarteloscope inventory path : Click Browse
and select the Data_Marteloscope_MyMarteloscope.xlsx file
that you have prepared with your field data.
martelosim project
Prelenfrey_2024.11.19) In this folder, you find
Prelenfrey_2024.11.19.Rproj)Prelenfrey_2024.11.19.Rproj).This script prepares the files describing your marteloscope initial conditions. You have to run it before each exercise.
If R studio has not opened script_01_start.R, go in the RStudio
bottom right window. Select the tab Files, open the
directory scripts and double click on the file
scripts/01_start.R
To run a RStudio script, click on each line of code and type
Ctrl Enter , it will run the code section by section.
martelosim::martelosim_options() displays the
indications for your workshop. You can check that they are correct.martelosim::new_inventory() copies the Excel file of
field data, provided by INRAE and in a format suitable for Samsara2, in
the subdirectory “data” of your exercise and checks its name :
Prelenfrey will copy the example file
of Prelenfrey stored in the package. This is what we suggest to do to
test the package the first time. In our example, this file will be
named:
martelosims_Workshops/Prelenfrey/Prelenfrey_2024.11.19/data/Data_Marteloscope_Prelenfrey.xlsxnew provide an empty Excel file of
field data if you have not already completed it.getOption("mart_lang") : the language
(English or French) will correspond to what you have indicated
previously in the create marteloscope box.open = TRUE, then the Excel file is open
and you can check the Prelenfrey data file. You have to close the Excel
file before continuing running the R code.martelosim::build_samsa2_files()
data. These
files will be used by the simulator Samsara2 to make simulations.markings, the default marking
file markings/Prelenfrey_2024.11.19_Marking_X.xlsx which
can be used on the field to enter marking data for the marking group
X.martelosim::prepare_samsara() omplements field data if
your marteloscope is not rectangular or if you have not measured the
regeneration on the field.
create_periphery = TRUE means that virtual
trees will be created in a rectangular plot around the marteloscope to
manage border conditions for light calculationscreate_virtual_saplings = TRUE means that
virtual saplings in balance with the adult tree stand and ground light
conditions are created.martelosim::martelo_maps() creates a pdf file with maps
to help you locate interesting trees on the field. These maps are stored
in the folder reports. (ex:
reports/Prelenfrey_Maps.pdf).navigateToFile(« script 02_test.R ») opens the script
used for the next step.This script runs marteloscope marking exercise with a random marking in order to test the whole process.
martelosim::random_marking() creates a virtual marking
file in the subdirectory markings where trees have been
selected randomly. It makes a marking file similar to a field marking
file. In our example:
markings/Prelenfrey_2024.11.19_Marking_Random.xlsxMarkingGroups <- c("Random") means you are working
with marking made by the virtual marking group called
Randomwrite_samsara_cmd() creates the file data
Prelenfrey_CommandFile.txt in the data folder.
This command file plans all the simulation steps for Samsara2. The
option :
marking_groups = MarkingGroups means that the
simulation will be made for the groups named in the MarkingGroup
vectorthinning_time = 10 means that a thinning will be
applied every 10 years. The first one will be the field marking, the
newt ones will be made using the Multicriteria_Thinner of Samsara2
mimicking the same kind of marking strategy than the field marking.evolution_time = 20 means that the simulation will
cover 20 years.silviculture = "auto" means that the parameters of the
Muticriteria_Thinner will be automatically deduced from the field
marking.run_samsara() runs the simulations for the the random
marking and stores result files in the folder data/Output.
It takes approximately 1 minutes for a 20 year evolution
simulation.marking_groups = MarkingGroups means that the report
will be made for the groups named in the MarkingGroup vector.dendrometry = TRUE, etc… means that the report will
include pages for all these topics.The scripts 03_workshop.R is for a real marking
exercise, not needed if you just want to test the package on a virtual
marteloscope with a random marking.
Objectives: - Check that the data in your marteloscope is correctly formatted - Check that the process is running correctly on your marteloscope - Test the production and storage of a field marking data file on tablets - Test the transfer of data between tablets and computer - Test the whole process of simulation based on a field marking
A new R project must be created before each exercise. Follow the same
instructions as in part 3.1.1. changing Prelenfrey and
2024.11.19 by your own marteloscope name and exercise
date.
01_start.R - Before each exerciseBefore the exercise, run 01_start.R to prepares the
files describing your marteloscope initial conditions. Follow the same
instructions as in part 3.1.2. Note that :
martelosim::new_inventory() copies the Excel file of
field data in the subdirectory data of your exercise and
checks its name :
new will copy the data file template
in the folder “data” with the name of your marteloscope and date of your
exercise. If the option open = TRUE, then the Excel file is
opened directly. You can fill it with your own data. You have to close
the Excel file before continuing running the R code.copy, opens a popup window to copy a
data file you have already prepared and stored anywhere on your
computer. If the popup window does not open directly it may appear on
the bottom bar of your screen. Be careful that the format of the file is
correct.02_test.R to test a random markingTo run a simulation with a random marking, follow the instructions in Run the script 01_start.R
Case 1: You intend to use the simple Excel file provided with the package
Internal storage/Documents/Marteloscopes/MyMarteloscope/)Marteloscopes directory.script_01.R. For example:
YourMarteloscopeName_YYYY.MM.DD_Marking_X.xlsx. Change the
name of the file with the correct tablet name or marking group name (ex:
YourMarteloscopeName_ YYYY.MM.DD _Marking_A.xlsx for group
A)Case 2: You intend to use the I+Trainer software
Internal storage/iplus/ which has been created
automatically when installing the I+Trainer on your tablet.Internal storage/iplus/directory.Case 1: You use the default Excel marking file provided with the package
Action column has been filled with the keyword
Wait which mean that you don’t do anything on this tree. If
you click on the box, you can choose among the actions: “Cut”,
Wait, Promote or Retain. You can
select a reason for your choice in the column Reason.markings folder for simulation. Check that the name
of the file is correct. it should follow the rule:
YourMarteloscopeName_ YYYY.MM.DD _Marking_YourGroup.xlsx.Case 2: You use the field the I+Trainer software
Save results on the device -> Save final results
on the SD card, create PDF and restart the application. A csv result
file is automatically saved in the directory
Internal storage/iplus/ with a long name given by Iplus (ex
Benoit_Prelenfrey_France_2024-10-02_1557.csv). You will
have to change this name by a Samsara2 compatible name
(YourMarteloscopeName_YYYY.MM.DD_Marking_YourGroup.csv)
either now or later on your computer.markings folder for simulation. Check that the name
of the file is correct. it should follow the rule:
YourMarteloscopeName_ YYYY.MM.DD _Marking_YourGroup.csvThis script runs marteloscope marking exercise in order to test the whole process.
find_marking() reads the making file template. You
can check that it identifies all of your marking files. If the option
open = TRUE, the Excel sheet is opened to be checked. You
have to close the Excel sheet before going on.
Choose the names of the marking groups for which you want to run
the simulation by completing the
MarkingGroups <- c("Random","X") (ex:
MarkingGroups <- c("A","B","C") if your groups are named
A, B and C).
write_samsara_cmd() (as in Run the
script 01_start.R) creates the file data
YourMarteloscopeName_Martelo_CommandFile.txt. This command
file plans all the simulation steps for Samsara2. The option :
marking_groups = MarkingGroupsmeans that the simulation
will be made for the groups named in the MarkingGroup vectorthinning_time = 10 means that a thinning will be
applied every 10 years. The first one will be the field marking, the
newt ones will be made using the Multicriteria_Thinner of Samsara2
mimicking the same kind of marking strategy than the field marking.evolution_time = 20 means that the simulation will
cover 20 years.silviculture = "auto" means that the parameters of the
Muticriteria_Thinner will be automatically deduced from the field
marking.run_samsara() runs the simulations for the marking
groups you have chosen in the creation of the CommandFile and stores
result files in the folder data.
martelo_report() writes a PDF report for the marking
group and stores it in the “reports” folder.
marking_groups = MarkingGroups, means that reports will
be made for all the groups in MarkingGroups.dendrometry = TRUE, etc… makes you able to select
topics you want to have in the reports (1 page / topic).Now that simulations are running on your computer, look in more detail at simulation reports to check that their predictions are realistic. Do you think the order of magnitude of production is correct? Do you think the regeneration flux is correct? Do you think the natural mortality is correct? Do you think the tree microhabitat evolution is correct?
A model is a strong simplification of reality. Predictions depend on the equations chosen to represent the different processes, on the parameter values in these equations and on the description of the initial state. Processes have been calibrated on large datasets averaging many different conditions and it is inevitable that the specific conditions of your marteloscope are represented quite poorly. If there are big inconsistencies, please let us know.
When analyzing the results of a simulation, you should not concentrate too much on quantitative predictions. It is more interesting to try and understand how the different variables evolve in relation to each other. Are some variables moving in similar directions ? Are other variables moving in opposite directions ? Is a change in one variable the consequence of an earlier change in another ?
A few days before the field workshop, you have to prepare a new project on your computer and your tablets and test everything. The D day you have to be able to do all the manipulations quickly and smoothly.
On your computer:
martelosim_Workshops/MyMarteloscope/MyMarteloscope_YYYY.MM.DD)script 01_start.R to prepare the initial state
files required for the simulations.script 02_test.R to check that everything is
working with a random markingOn your tablets: Transfer from your computer to the tablets the empty
marking file YourMarteloscopeName_YYYY.MM.DD_Marking_X.xlsx
and change the names replacing X by the name of each tablet
Alternatively, prepare your tablets with the I+Trainer software.
At the beginning try not to have too many groups in the field: the more groups there are, the more manipulations there are to do.
Save results on the device -> Save final results on the
SD card, create PDF and restart the application03_workshop.R to make the simulations
and produce the pdf reports.Be careful that file names are correct and that you have written all the group names in the vector MarkingGroups.
The transfer of files between tablets and computer is a bit of a pain but is doable. If you are well prepared, the whole process should take about 30 minutes.
You can use your marteloscope data to make simulations with Samsara2 for other purposes than field marking workshops. Marteloscope simulation has been standardized to be efficient and fast, but the drawback is that the simulation scenario is not very flexible. In other contexts, you can imagine more complex simulation scenarios using Samsara2 in two ways: