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

add tests with 1D tensors for all deterministic metrics

Showing with 31 additions and 35 deletions
+31 -35
......@@ -8,7 +8,8 @@
#include "evalhyd/evald.hpp"
TEST(DeterministTests, TestMetrics) {
TEST(DeterministTests, TestMetrics2D)
{
// read in data
std::ifstream ifs;
ifs.open("./data/q_obs.csv");
......@@ -21,7 +22,7 @@ TEST(DeterministTests, TestMetrics) {
);
ifs.close();
// compute scores (both with 2D and 1D tensors)
// compute scores (with 2D tensors)
std::vector<xt::xarray<double>> metrics =
evalhyd::evald<xt::xtensor<double, 2>>(
observed, predicted, {"RMSE", "NSE", "KGE", "KGEPRIME"}
......@@ -61,48 +62,42 @@ TEST(DeterministTests, TestMetrics) {
EXPECT_TRUE(xt::allclose(metrics[3], kgeprime));
}
TEST(DeterministTests, TestNSE_1d2d) {
TEST(DeterministTests, TestMetrics1D)
{
// read in data
std::ifstream ifs;
ifs.open("./data/q_obs.csv");
xt::xtensor<double, 2> observed_2d =xt::load_csv<int>(ifs);
xt::xtensor<double, 1> observed = xt::squeeze(xt::load_csv<int>(ifs));
ifs.close();
xt::xtensor<double, 1> observed_1d = xt::squeeze(observed_2d);
ifs.open("./data/q_prd.csv");
xt::xtensor<double, 2> predicted_2d = xt::view(
xt::load_csv<double>(ifs), xt::range(0, 5), xt::all()
xt::xtensor<double, 1> predicted = xt::row(
xt::view(xt::load_csv<double>(ifs), xt::range(0, 5), xt::all()), 0
);
ifs.close();
xt::xtensor<double, 1> predicted_1d = xt::row(predicted_2d, 0);
// compute scores (both with 2D and 1D tensors)
std::vector<xt::xarray<double>> metrics_2d =
evalhyd::evald<xt::xtensor<double, 2>>(
observed_2d, predicted_2d, {"NSE"}
);
std::vector<xt::xarray<double>> metrics_1d =
// compute scores (with 1D tensors)
std::vector<xt::xarray<double>> metrics =
evalhyd::evald<xt::xtensor<double, 1>>(
observed_1d, predicted_1d, {"NSE"}
observed, predicted, {"RMSE", "NSE", "KGE", "KGEPRIME"}
);
// check results (both with 2D and 1D tensors)
xt::xtensor<double, 2> nse =
{{0.71891219},
{0.7190249},
{0.71835777},
{0.71810361},
{0.71776748}};
EXPECT_TRUE(xt::allclose(metrics_2d[0], nse));
xt::xtensor<double, 1> nse_1d = {0.71891219};
EXPECT_TRUE(xt::allclose(metrics_1d[0], nse[0]));
// check results on all metrics
xt::xtensor<double, 1> rmse = {777.034272};
EXPECT_TRUE(xt::allclose(metrics[0], rmse));
xt::xtensor<double, 1> nse = {0.718912};
EXPECT_TRUE(xt::allclose(metrics[1], nse));
xt::xtensor<double, 1> kge = {0.748088};
EXPECT_TRUE(xt::allclose(metrics[2], kge));
xt::xtensor<double, 1> kgeprime = {0.813141};
EXPECT_TRUE(xt::allclose(metrics[3], kgeprime));
}
TEST(DeterministTests, TestNSE_transform) {
TEST(DeterministTests, TestTransform)
{
// read in data
std::ifstream ifs;
ifs.open("./data/q_obs.csv");
......
......@@ -9,7 +9,8 @@
using namespace xt::placeholders; // required for `_` to work
TEST(ProbabilistTests, TestBrier) {
TEST(ProbabilistTests, TestBrier)
{
// read in data
std::ifstream ifs;
ifs.open("./data/q_obs.csv");
......@@ -59,7 +60,8 @@ TEST(ProbabilistTests, TestBrier) {
EXPECT_TRUE(xt::allclose(metrics[3], bs_lbd));
}
TEST(ProbabilistTests, TestQuantiles) {
TEST(ProbabilistTests, TestQuantiles)
{
// read in data
std::ifstream ifs;
ifs.open("./data/q_obs.csv");
......@@ -103,10 +105,10 @@ TEST(ProbabilistTests, TestQuantiles) {
xt::xtensor<double, 3> crps =
{{{ 257.412129}}};
EXPECT_TRUE(xt::allclose(metrics[1], crps));
}
TEST(ProbabilistTests, TestMasks) {
TEST(ProbabilistTests, TestMasks)
{
// read in data
std::ifstream ifs;
ifs.open("./data/q_obs.csv");
......@@ -155,5 +157,4 @@ TEST(ProbabilistTests, TestMasks) {
{
EXPECT_TRUE(xt::allclose(metrics_masked[0], metrics_subset[0]));
}
}
\ No newline at end of file
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