gowachin / matreex

LESSEM internal package for simulation of forest dynamic depending on climatic variables
https://gowachin.github.io/matreex/
Other
3 stars 0 forks source link

Default init_pop function sometime give BA to close to 1 #3

Closed kunstler closed 2 years ago

kunstler commented 2 years ago

The default init_pop function

init_pop <- function (mesh, SurfEch = 0.03) 
{
  ct <- drop(Buildct(mesh = mesh, SurfEch = SurfEch))
  ini <- exp(runif(1, -0.005, 0.005) * mesh)
  alea <- rbinom(length(mesh), 1, runif(1, 0.6, 0.9)) == 1
  while (all(alea)) {
    alea <- rbinom(length(mesh), 1, runif(1, 0.6, 0.9)) == 
      1
  }
  ini[alea] <- 0
  res <- as.numeric(ini/sum(ct * ini))
  res <- res + 1e-10
  return(res)
}

This can lead to problem when basal area drop below 1 (as in teh current version there is no IPM for BA 0)

Maybe change to

init_pop <- function (mesh, SurfEch = 0.03) 
{
  ct <- drop(Buildct(mesh = mesh, SurfEch = SurfEch))
  ini <- exp(runif(1, -0.005, 0.005) * mesh)
  alea <- rbinom(length(mesh), 1, runif(1, 0.6, 0.9)) == 1
  while (all(alea)) {
    alea <- rbinom(length(mesh), 1, runif(1, 0.6, 0.9)) == 
      1
  }
  ini[alea] <- 0
  res <- as.numeric(ini/sum(ct * ini))
  res <- res + 1e-4
  return(res)
}
gowachin commented 2 years ago

This was incorporated with fae39ef and more functions to initiate a population where added to the package 7c368a1.

We can now modify the def_init with def_initBA(BA = 20) to set an initial basal area of 20. This allow to conserve some random effect to simulation while fixing the basal area.

We can also define a starting distribution (for example the equilibrium) with the function def_init_k(x) by providing a initial vector x that must be the same size as the mesh (and with at least one value > 0).