From ca8af7c85c2af0b4aabe3564e30c362feea6cfaa Mon Sep 17 00:00:00 2001 From: Kevin Kramer Date: Tue, 25 Jun 2024 11:28:12 +0200 Subject: [PATCH] PhenologicalAutocut applies at least 1 cut. --- R/autocut.R | 14 ++++++++++---- R/environment.R | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/R/autocut.R b/R/autocut.R index 4efb083..7f2d0f7 100644 --- a/R/autocut.R +++ b/R/autocut.R @@ -131,10 +131,16 @@ PhenologicalAutocut = R6Class( last_cut_DOY = i0 + lower[[1]] } - # Time between cuts - integer_n_cuts = round(self$n_cuts) - delta = floor((last_cut_DOY - first_cut_DOY) / (integer_n_cuts - 1)) - self$cut_DOYs = (((1:integer_n_cuts) - 1) * delta) + first_cut_DOY + # Calculate time between cuts + # Round n_cuts but apply at least 1 + integer_n_cuts = max(1, round(self$n_cuts)) + if (integer_n_cuts != 1) { + delta = floor((last_cut_DOY - first_cut_DOY) / (integer_n_cuts - 1)) + self$cut_DOYs = (((1:integer_n_cuts) - 1) * delta) + first_cut_DOY + } else { + # If there's just one cut, apply it at end of season + self$cut_DOYs = c(last_cut_DOY) + } }, #' @description Does a cut occur on *DOY*? diff --git a/R/environment.R b/R/environment.R index f2e91bd..66b0f32 100644 --- a/R/environment.R +++ b/R/environment.R @@ -40,7 +40,8 @@ ModvegeEnvironment = R6Class( param_file = NULL, #' @field weather_file Name of supplied weather file. weather_file = NULL, -#' @field management_file Name of supplied management file. +#' @field management_file Name of supplied management file or management +#' intensity for [Autocut] ('high', 'middle', 'low', 'extensive'). management_file = NULL, #' @field parameters A [ModvegeParameters] object. parameters = NULL,