An error occurred while loading the file. Please try again.
-
Guillaume Perréal authoredd5ae1ca3
#ifndef EVALHYD_DETERMINIST_HPP
#define EVALHYD_DETERMINIST_HPP
#include <unordered_map>
#include <vector>
#include <xtensor/xexpression.hpp>
#include "utils.hpp"
#include "determinist/evaluator.hpp"
namespace eh = evalhyd;
namespace evalhyd
{
namespace determinist {
/// Function allowing the evaluation of streamflow simulations using a
/// range of relevant metrics.
///
/// \param [in] metrics:
/// Vector of strings for the metric(s) to be computed.
/// \param [in] q_obs:
/// 2D array of streamflow observations.
/// shape: (1+, time)
/// \param [in] q_sim:
/// 2D array of streamflow simulations.
/// shape: (1+, time)
/// \return
/// Vector of 1D array of metrics for each time series.
template <class A>
std::vector<A> evaluate(
const std::vector<std::string>& metrics,
const xt::xexpression<A>& q_obs,
const xt::xexpression<A>& q_sim
)
{
const A& obs = q_obs.derived_cast();
const A& sim = q_sim.derived_cast();
// check that the metrics to be computed are valid
utils::check_metrics(
metrics,
{"NSE"}
);
// instantiate determinist evaluator
eh::determinist::Evaluator<A> evaluator(obs, sim);
// declare maps for memoisation purposes
std::unordered_map<std::string, std::vector<std::string>> elt;
std::unordered_map<std::string, std::vector<std::string>> dep;
// register potentially recurring computation elt across metrics
// TODO
// register nested metrics (i.e. metric dependent on another metric)
// TODO
// determine required elt/dep to be pre-computed
std::vector<std::string> req_elt;
std::vector<std::string> req_dep;
eh::utils::find_requirements(metrics, elt, dep, req_elt, req_dep);
// pre-compute required elt
for ( const auto& element : req_elt )
{
// TODO
}
// pre-compute required dep
7172737475767778798081828384858687888990919293949596
for ( const auto& dependency : req_dep )
{
// TODO
}
// retrieve or compute requested metrics
std::vector<A> r;
for ( const auto& metric : metrics )
{
if ( metric == "NSE" )
{
if (std::find(req_dep.begin(), req_dep.end(), metric)
== req_dep.end())
evaluator.calc_NSE();
r.emplace_back(evaluator.NSE);
}
}
return r;
}
}
}
#endif //EVALHYD_DETERMINIST_HPP