diff --git a/include/evalhyd/probabilist.hpp b/include/evalhyd/probabilist.hpp index 140d1a2a89ddeeb739dc559d5d920d42701c1371..fe59365a21ceedf4ebe74d9ed1c56e93eaf36cba 100644 --- a/include/evalhyd/probabilist.hpp +++ b/include/evalhyd/probabilist.hpp @@ -36,15 +36,18 @@ namespace evalhyd const std::vector<std::string>& metrics, const xt::xtensor<double, 2>& q_obs, const xt::xtensor<double, 2>& q_frc, - const xt::xtensor<double, 1>& q_thr + const xt::xtensor<double, 1>& q_thr = {} ) { // check that the metrics to be computed are valid - utils::check_metrics( + eh::utils::check_metrics( metrics, {"BS", "BSS", "BS_CRD", "BS_LBD", "QS", "CRPS"} ); + // check that optional parameters are given as arguments + eh::utils::check_optionals(metrics, q_thr); + // instantiate probabilist evaluator eh::probabilist::Evaluator evaluator(q_obs, q_frc, q_thr); diff --git a/include/evalhyd/utils.hpp b/include/evalhyd/utils.hpp index 4caa7e5bbaf54cfdd9f44c94075cfa6a094520fe..d96b35115ccc0c027ac6f4e79685824c934078ab 100644 --- a/include/evalhyd/utils.hpp +++ b/include/evalhyd/utils.hpp @@ -92,6 +92,32 @@ namespace evalhyd } } + /// Procedure to check that optional parameters are provided + /// as arguments when required metrics need them. + /// + /// \param [in] metrics: + /// Vector of strings for the metric(s) to be computed. + /// \param [in] thresholds: + /// Array of thresholds for metrics based on exceedance events. + inline void check_optionals ( + const std::vector<std::string>& metrics, + const xt::xtensor<double, 1>& thresholds + ) + { + std::vector<std::string>threshold_metrics = + {"BS, BS_CRD", "BS_LBD", "BSS"}; + + for (const auto& metric : metrics) + { + if (std::find(threshold_metrics.begin(), threshold_metrics.end(), + metric) != threshold_metrics.end()) + if (thresholds.size() < 1) + throw std::runtime_error( + "missing parameter 'thresholds' required to " + "compute " + metric + ); + } + } } }