diff --git a/.gitignore b/.gitignore index 8c03af5..def6eb7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ docs .Rhistory +.RData +.httr-oauth +.DS_Store +.quarto diff --git a/R/miniSTICS.R b/R/miniSTICS.R index c2713d4..9638a04 100644 --- a/R/miniSTICS.R +++ b/R/miniSTICS.R @@ -75,6 +75,7 @@ #' \itemize{ #' \item tcmin: Base temperature (°C) #' \item tcopt: Optimal temperature (°C) +#' \item tcxstop : Temperature at which phenological development stops (°c) #' \item flag_vern: Vernalization sensitivity (logical) #' \item jvc: Vernalization requirement (days) #' \item tfroid: Optimal vernalization temperature (°C) @@ -224,7 +225,7 @@ miniSTICS <- function(soil, weather_station, practices, plant, weather) { weather_station = c("lat", "z"), practices = c("sowing_year", "doy_sowing", "doy_stop_sim", "zrac0", "density"), plant = c( - "tcmin", "tcopt", + "tcmin", "tcopt", "tcxstop", "flag_vern", "jvc", "tfroid", "ampfroid", "flag_photo", "phobase", "phosat", "st2germinate", "st2emerge", "stlevamf", "stamflax", "stlevdrp", "stdrpmat", @@ -315,10 +316,22 @@ miniSTICS <- function(soil, weather_station, practices, plant, weather) { ) } + # to do : # compute photoperiod in the routine based on "lat" + # function has been added, with a check if variable does not exist, as for ETP and Temp_Moy + + if (!"Photoperiod" %in% names(weather_var)) { + + weather_var <- weather_var |> + mutate(Sol_decl = (23.45*pi/180)*sin((360*pi/180/365.25)*(DOY+283)) ) + + weather_var <- weather_var |> + mutate(Photoperiod = (24/pi)*acos(-tan(lat*pi/180)*tan(Sol_decl)) ) + + } + weather_var <- weather_var |> dplyr::select(Date, Rain, Radiation, Temp, Photoperiod, ETP) - # to do : # compute photeperiod in the routine based on "lat ministics <- tibble(doy = c(doy_sowing:doy_stop_sim)) |> mutate(D_Cal = year_2import + doy) |> @@ -333,8 +346,19 @@ miniSTICS <- function(soil, weather_station, practices, plant, weather) { # This allows to use "mutate" fonction to speed up computation process # The routine should be rewritten if we wanted to simulate WStress ! + # ministics <- ministics |> + # mutate(UDEVCULT = ifelse(Temp < tcmin, 0, ifelse(Temp < tcopt, Temp - tcmin, tcopt - tcmin))) |> + # mutate(RFPI = (Photoperiod - phosat) / (phosat - phobase) + 1) |> + # mutate(JVI = max((1 - ((tfroid - Temp) / ampfroid)^2), 0)) + + # function has been added, to account for triangular function of udevcult + # need to check if the order of function is coherent + # 1 - check if smaller than tcmin, then 0 + # 2 - check if greater than tcxstop, then 0 + # 3 - check if smaller or greater than tcopt, then positive slope (tcmin-tcxtop) or negative slope ((tcopt - tcmin)/(tcopt - tcxstop)*(Temp - tcxstop)) + ministics <- ministics |> - mutate(UDEVCULT = ifelse(Temp < tcmin, 0, ifelse(Temp < tcopt, Temp - tcmin, tcopt - tcmin))) |> + mutate(UDEVCULT = ifelse(Temp < tcmin, 0, ifelse ( Temp > tcxstop, 0,ifelse(Temp < tcopt, Temp - tcmin, (tcopt - tcmin)/(tcopt - tcxstop)*(Temp - tcxstop) ))) ) |> mutate(RFPI = (Photoperiod - phosat) / (phosat - phobase) + 1) |> mutate(JVI = max((1 - ((tfroid - Temp) / ampfroid)^2), 0)) diff --git a/R/plant_parameters.R b/R/plant_parameters.R index 27059fd..3fba92b 100644 --- a/R/plant_parameters.R +++ b/R/plant_parameters.R @@ -17,6 +17,7 @@ #' \itemize{ #' \item tcmin: Base temperature (°C) #' \item tcopt: Optimal temperature (°C) +#' \item tcxstop : Temperature at which phenological development stops (°c) #' \item flag_vern: Vernalization sensitivity (logical) #' \item jvc: Vernalization requirement (days) #' \item tfroid: Optimal vernalization temperature (°C) @@ -87,6 +88,7 @@ plant_parameters <- function(...) { params <- list( tcmin = 0, tcopt = 35, + tcxstop = 45, flag_vern = TRUE, jvc = 45, tfroid = 6.5, diff --git a/man/miniSTICS.Rd b/man/miniSTICS.Rd index e4edf75..ef139ce 100644 --- a/man/miniSTICS.Rd +++ b/man/miniSTICS.Rd @@ -62,6 +62,7 @@ Phenology: \itemize{ \item tcmin: Base temperature (°C) \item tcopt: Optimal temperature (°C) +\item tcxstop : Temperature at which phenological development stops (°c) \item flag_vern: Vernalization sensitivity (logical) \item jvc: Vernalization requirement (days) \item tfroid: Optimal vernalization temperature (°C) diff --git a/man/plant_parameters.Rd b/man/plant_parameters.Rd index 639764f..a9a8bfd 100644 --- a/man/plant_parameters.Rd +++ b/man/plant_parameters.Rd @@ -26,6 +26,7 @@ Phenology: \itemize{ \item tcmin: Base temperature (°C) \item tcopt: Optimal temperature (°C) +\item tcxstop : Temperature at which phenological development stops (°c) \item flag_vern: Vernalization sensitivity (logical) \item jvc: Vernalization requirement (days) \item tfroid: Optimal vernalization temperature (°C) diff --git a/tests/testthat/test-parameter-validation.R b/tests/testthat/test-parameter-validation.R index b807b90..74ff687 100644 --- a/tests/testthat/test-parameter-validation.R +++ b/tests/testthat/test-parameter-validation.R @@ -42,6 +42,7 @@ valid_plant <- function() { list( tcmin = 1, tcopt = 1, + tcxstop = 1, flag_vern = FALSE, jvc = 1, tfroid = 1,