Commit 2b0694d5 authored by Thibault Hallouin's avatar Thibault Hallouin
Browse files

add check on metrics validity

Showing with 33 additions and 0 deletions
+33 -0
...@@ -39,6 +39,13 @@ namespace evalhyd ...@@ -39,6 +39,13 @@ namespace evalhyd
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(
metrics,
{"bs", "bss", "bs_crd", "bs_lbd", "qs", "crps"}
);
// instantiate probabilist evaluator
eh::probabilist::Evaluator evaluator(q_obs, q_frc, q_thr); eh::probabilist::Evaluator evaluator(q_obs, q_frc, q_thr);
// declare maps for memoisation purposes // declare maps for memoisation purposes
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include <stdexcept>
#include <xtensor/xtensor.hpp> #include <xtensor/xtensor.hpp>
namespace evalhyd namespace evalhyd
...@@ -66,6 +67,31 @@ namespace evalhyd ...@@ -66,6 +67,31 @@ namespace evalhyd
} }
} }
} }
/// Procedure to check that all elements in the list of metrics are
/// valid metrics.
///
/// \param [in] requested_metrics:
/// Vector of strings for the metric(s) to be computed.
/// \param [in] valid_metrics:
/// Vector of strings for the metric(s) to can be computed.
inline void check_metrics (
const std::vector<std::string>& requested_metrics,
const std::vector<std::string>& valid_metrics
)
{
for (const auto& metric : requested_metrics)
{
if (std::find(valid_metrics.begin(), valid_metrics.end(), metric)
== valid_metrics.end())
{
throw std::runtime_error(
"invalid evaluation metric: " + 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