Commit a7256eae authored by Thibault Hallouin's avatar Thibault Hallouin
Browse files

make threshold parameter optional

since it is not needed by metrics such as QS or CRPS
Showing with 31 additions and 2 deletions
+31 -2
...@@ -36,15 +36,18 @@ namespace evalhyd ...@@ -36,15 +36,18 @@ namespace evalhyd
const std::vector<std::string>& metrics, const std::vector<std::string>& metrics,
const xt::xtensor<double, 2>& q_obs, const xt::xtensor<double, 2>& q_obs,
const xt::xtensor<double, 2>& q_frc, 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 // check that the metrics to be computed are valid
utils::check_metrics( eh::utils::check_metrics(
metrics, metrics,
{"BS", "BSS", "BS_CRD", "BS_LBD", "QS", "CRPS"} {"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 // instantiate probabilist evaluator
eh::probabilist::Evaluator evaluator(q_obs, q_frc, q_thr); eh::probabilist::Evaluator evaluator(q_obs, q_frc, q_thr);
......
...@@ -92,6 +92,32 @@ namespace evalhyd ...@@ -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
);
}
}
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment