FATE simulationR/PRE_FATE.params_PFGsoil.R
    PRE_FATE.params_PFGsoil.RdThis script is designed to create parameter files containing
soil contribution and tolerance for each PFG (one file for each of them)
used in the soil module of FATE.
PRE_FATE.params_PFGsoil(
  name.simulation,
  mat.PFG.soil,
  mat.PFG.tol = NULL,
  opt.folder.name = NULL
)a string corresponding to the main directory
or simulation name of the FATE simulation
a data.frame with 3 to 7 columns : 
PFG,
type, (or active_germ_low,
  active_germ_medium, active_germ_high) (or
  strategy_ag)
soil_contrib, soil_tol_min, soil_tol_max
  (or strategy_contrib)
(see Details)
(optional) 
a data.frame with 2 to 4 columns : 
PFG,
lifeStage, resources, tolerance
  (or strategy_tol)
(see Details)
(optional) 
 a string corresponding
to the name of the folder that will be created into the
name.simulation/DATA/PFGS/SOIL/ directory to store the results
A .txt file per PFG into the
name.simulation/DATA/PFGS/SOIL/ directory with the following
parameters :
name of the PFG
germination rates depending on soil conditions
  
(integer between 0 and 100%)
contribution to the soil value of the pixel
lower value of soil supported by the PFG, 
  defining the limit between Low and Medium soil resources
  for this PFG
upper value of soil supported by the PFG, 
  defining the limit between Medium and High soil resources
  for this PFG
soil tolerance table (in a single row). 
  This is a vector of 9 numbers corresponding to the ability of the PFG to
  survive or not :
at different life stages (Germinant (Ge), Immature
    (Im), Mature (Ma))
under different soil conditions (Low (L), Medium
    (M) or High (H)).
These parameters should be given in this order : GeL, GeM, GeH, ImL,
  ImM, ImH, MaL, MaM, MaH
  
(integer between 0 and 100%).
  
A SOIL_COMPLETE_TABLE.csv file summarizing information for all
groups into the name.simulation/DATA/PFGS/ directory.
If the opt.folder.name has been used, the files will be into the
folder name.simulation/DATA/PFGS/SOIL/opt.folder.name/.
The soil module allows the user to add the effect of
soil interaction within a primary vegetation succession. 
Several parameters, given within mat.PFG.soil or mat.PFG.tol,
are required for each PFG in order to set up the soil interaction :
the concerned plant functional group 
or life-form, based on Raunkier. 
 It should be either
  H (herbaceous), C (chamaephyte) or P (phanerophyte)
  for now
an integer between 0 and
  100 corresponding to the proportion of seeds that will germinate for
  Low soil condition
an integer between 0 and
  100 corresponding to the proportion of seeds that will germinate for
  Medium soil condition
an integer between 0 and
  100 corresponding to the proportion of seeds that will germinate for
  High soil condition
a string to choose the germination
  strategy : poor_lover, indifferent, rich_lover
  
a value corresponding to the PFG preference for soil
  fertility 
 (e.g. nitrogen value from Ellenberg or Flora Indicativa)
the minimum soil value tolerated by the PFG (on the
  same scale than soil_contrib)
the maximum soil value tolerated by the PFG (on the
  same scale than soil_contrib)
a string to choose the
  contribution strategy : oligotrophic, mesotrophic,
  eutrophic 
the concerned life stage (Germinant,
  Immature, Mature)
the concerned soil condition (Low,
  Medium, High)
an integer between 0 and 100
  corresponding to the proportion of surviving individuals
a string to choose the tolerance
  strategy : poor_lover, ubiquist, rich_lover
  
These values will allow to calculate or define a set of characteristics for each PFG :
proportion of seeds that will germinate for each soil
  condition (Low, Medium, High) 
  Three methods to define these proportions are available :
from predefined scenarios (using strategy_ag) : | _L_ _M_ _H_ | _______________ | 80% 90% 50% | poor_lover | 90% 90% 90% | indifferent | 50% 90% 80% | rich_lover 
from predefined rules (using type) :
for H (herbaceous) : 80%, 100%, 50%
for C (chamaephyte) or P (phanerophyte) :
      90%, 100%, 90%
from user data : 
with the values contained within the active_germ_low,
    active_germ_medium and active_germ_high columns, if
    provided 
Two methods to define these values are available :
from predefined scenarios (using
    strategy_contrib) : 
the values give the soil_tol_min, soil_contrib
        and soil_tol_max
with L: low soil, M: medium soil, H:
        high soil 
| ___ L ___ | ___ M ___ | ___ H ___ | _____________________________________ __________ 1 ___ 1.5 ___ 2 __________ oligotrophic __________ 1.5 _ 2.5 _ 4.5 __________ mesotrophic __________ 3 ____ 4 ____ 5 __________ eutrophic 
from user data : 
with the values contained within the soil_contrib,
      soil_tol_min and soil_tol_max columns, if provided 
defined for each life stage (Germinant,
  Immature, Mature) 
 and each soil condition (Low,
  Medium, High) 
  Three methods to define these tolerances are available :
from predefined scenarios (using
    strategy_tol) : 
the values give the percentage of surviving individuals to the concerned conditions
with g: Germinant, i: Immature, m: Mature
with L: low soil, M: medium soil, H:
        high soil 
| _____ g ____ | _____ i ____ | _____ m ____ | | _L__ _M_ _H_ | _L__ _M_ _H_ | _L__ _M_ _H_ | ______________________________________________ | 30% 100% 10% | 60% 100% 40% | 90% 100% 70% | poor_lover | 90% 100% 80% | 90% 100% 80% | 90% 100% 80% | ubiquist | 10% 100% 30% | 40% 100% 60% | 70% 100% 90% | rich_lover 
from predefined rules (corresponding to the
    poor_lover strategy) :
germinants are severely impacted by wrong soil conditions
immatures are half impacted by wrong soil conditions
matures are little impacted by wrong soil conditions
for all life stages, not enough is better than too much
the values give the percentage of surviving individuals to the concerned conditions
with g: Germinant, i: Immature, m: Mature
with L: low soil, M: medium soil, H:
        high soil 
| _____ g ____ | _____ i ____ | _____ m ____ | | _L__ _M_ _H_ | _L__ _M_ _H_ | _L__ _M_ _H_ | ______________________________________________ | 30% 100% 10% | 60% 100% 40% | 90% 100% 70% | 
from user data : 
with the values contained within the lifeStage,
      resources and tolerance columns, if provided
                                                    
## Create a skeleton folder with the default name ('FATE_simulation')
PRE_FATE.skeletonDirectory()
## Create PFG soil parameter files (with strategies) -----------------------------------------
tab.soil = data.frame(PFG = paste0('PFG', 1:6)
                      , strategy_ag = c('rich_lover', 'indifferent' , 'indifferent'
                                        , 'rich_lover', 'indifferent', 'poor_lover')
                      , strategy_contrib = c('eutrophic', 'mesotrophic', 'mesotrophic'
                                             , 'mesotrophic', 'mesotrophic', 'oligotrophic'))
tab.tol = data.frame(PFG = paste0('PFG', 1:6)
                     , strategy_tol = c('rich_lover', 'ubiquist', 'poor_lover'
                                        , 'ubiquist', 'poor_lover', 'poor_lover'))
PRE_FATE.params_PFGsoil(name.simulation = 'FATE_simulation'
                        , mat.PFG.soil = tab.soil
                        , mat.PFG.tol = tab.tol)
                                                        
## Create PFG soil parameter files (with all values) -----------------------------------------
tab.soil = data.frame(PFG = paste0('PFG', 1:6)
                      , active_germ_low = c(50, 80, 80, 60, 80, 80)
                      , active_germ_medium = rep(90, 6)
                      , active_germ_high = c(90, 80, 80, 90, 80, 40)
                      , strategy_contrib = c('eutrophic', 'mesotrophic', 'mesotrophic'
                                             , 'mesotrophic', 'mesotrophic', 'oligotrophic'))
tab.tol = expand.grid(resources = c('Low', 'Medium', 'High')
                      , lifeStage = c('Germinant', 'Immature', 'Mature')
                      , PFG = paste0('PFG', 1:6))
tab.tol$tolerance = c(80, 80, 40, 80, 50, 40, 90, 40, 40
                      , rep(90, 9)
                      , rep(90, 9)
                      , 80, 80, 60, 80, 60, 60, 90, 50, 50
                      , 80, 80, 80, 50, 60, 90, 30, 40, 90
                      , 80, 80, 80, 50, 50, 90, 50, 50, 90)
PRE_FATE.params_PFGsoil(name.simulation = 'FATE_simulation'
                        , mat.PFG.soil = tab.soil
                        , mat.PFG.tol = tab.tol)
                                                        
                                                        
## -------------------------------------------------------------------------------------------
## Load example data
Champsaur_params = .loadData('Champsaur_params', 'RData')
## Create a skeleton folder
PRE_FATE.skeletonDirectory(name.simulation = 'FATE_Champsaur')
## PFG traits for light
tab.soil = Champsaur_params$tab.SOIL
str(tab.soil)
## Create PFG soil parameter files -----------------------------------------------------------
PRE_FATE.params_PFGsoil(name.simulation = 'FATE_Champsaur'
                           , mat.PFG.soil = tab.soil)