From 5df680c4c5157d8409224262dcf1fa31a1ba5f5a Mon Sep 17 00:00:00 2001 From: Thibault Hallouin <thibault.hallouin@inrae.fr> Date: Tue, 5 Sep 2023 12:19:05 +0200 Subject: [PATCH] add support for minute and hourly time step for bootstrapping fixes https://gitlab.irstea.fr/HYCAR-Hydro/evalhyd/evalhyd-cpp/-/issues/9 --- include/evalhyd/detail/uncertainty.hpp | 37 ++++++++++++++++++++++++-- include/evalhyd/evald.hpp | 4 ++- include/evalhyd/evalp.hpp | 4 ++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/include/evalhyd/detail/uncertainty.hpp b/include/evalhyd/detail/uncertainty.hpp index af55fc2..3ea64e7 100644 --- a/include/evalhyd/detail/uncertainty.hpp +++ b/include/evalhyd/detail/uncertainty.hpp @@ -105,8 +105,41 @@ namespace evalhyd (x_timepoints >= start) && (x_timepoints < end); // check that year is complete (without a rigorous leap year check) - int n_days = xt::sum(wdw)(); - if ((n_days != 365) && (n_days != 366)) + bool complete_yr = true; + if (std::chrono::minutes(ti).count() == 1) + { + // minute timestep + int n_minutes = xt::sum(wdw)(); + if ((n_minutes != 60 * 24 * 365) && (n_minutes != 60 * 24 * 366)) + { + complete_yr = false; + } + } + else if (std::chrono::minutes(ti).count() == 60) + { + // hourly timestep + int n_hours = xt::sum(wdw)(); + if ((n_hours != 24 * 365) && (n_hours != 24 * 366)) + { + complete_yr = false; + } + } + else if (std::chrono::minutes(ti).count() == 60 * 24) + { + // daily timestep + int n_days = xt::sum(wdw)(); + if ((n_days != 365) && (n_days != 366)) + { + complete_yr = false; + } + } + else + { + throw std::runtime_error( + "time step must be minute, hourly, or daily" + ); + } + if (!complete_yr) { throw std::runtime_error( "year starting in " + std::to_string(y - 400) diff --git a/include/evalhyd/evald.hpp b/include/evalhyd/evald.hpp index 9ddeead..580b4f0 100644 --- a/include/evalhyd/evald.hpp +++ b/include/evalhyd/evald.hpp @@ -132,7 +132,9 @@ namespace evalhyd /// The date and time must be specified in a string following the /// ISO 8601-1:2019 standard, i.e. "YYYY-MM-DD hh:mm:ss" (e.g. the /// 21st of May 2007 at 4 in the afternoon is "2007-05-21 16:00:00"). - /// If provided, it is only used if *bootstrap* is also provided. + /// The time series must feature complete years. Only minute, hourly, + /// and daily time steps are supported. If provided, it is only used + /// if *bootstrap* is also provided. /// /// seed: ``int``, optional /// A value for the seed used by random generators. This parameter diff --git a/include/evalhyd/evalp.hpp b/include/evalhyd/evalp.hpp index c044120..3b5f831 100644 --- a/include/evalhyd/evalp.hpp +++ b/include/evalhyd/evalp.hpp @@ -123,7 +123,9 @@ namespace evalhyd /// The date and time must be specified in a string following the /// ISO 8601-1:2019 standard, i.e. "YYYY-MM-DD hh:mm:ss" (e.g. the /// 21st of May 2007 at 4 in the afternoon is "2007-05-21 16:00:00"). - /// If provided, it is only used if *bootstrap* is also provided. + /// The time series must feature complete years. Only minute, hourly, + /// and daily time steps are supported. If provided, it is only used + /// if *bootstrap* is also provided. /// /// seed: ``int``, optional /// A value for the seed used by random generators. This parameter -- GitLab