An error occurred while loading the file. Please try again.
-
Thibault Hallouin authored
So that the files for the tests look like typical files `evalhyd` would expect, rather than its transposed version.
e4b61c01
#include <istream>
#include <fstream>
#include <vector>
#include <gtest/gtest.h>
#include <xtensor/xtensor.hpp>
#include <xtensor/xview.hpp>
#include <xtensor/xmanipulation.hpp>
#include <xtensor/xcsv.hpp>
#include "evalhyd/determinist.hpp"
TEST(DeterministTests, TestNSE) {
// read in data
std::ifstream ifs;
ifs.open("./data/q_obs.csv");
xt::xtensor<double, 2> observed_2d =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()
);
ifs.close();
xt::xtensor<double, 1> predicted_1d = xt::row(predicted_2d, 0);
// compute scores (both with 2D and 1D tensors)
std::vector<xt::xtensor<double, 2>> metrics_2d =
evalhyd::evald<xt::xtensor<double, 2>>(
observed_2d, predicted_2d, {"NSE"}
);
std::vector<xt::xtensor<double, 1>> metrics_1d =
evalhyd::evald<xt::xtensor<double, 1>>(
observed_1d, predicted_1d, {"NSE"}
);
// check results (both with 2D and 1D tensors)
xt::xtensor<double, 2> nse_2d =
{{0.71891219}, {0.7190249} , {0.71835777}, {0.71810361}, {0.71776748}};
EXPECT_TRUE(xt::allclose(metrics_2d[0], nse_2d));
xt::xtensor<double, 1> nse_1d = {0.71891219};
EXPECT_TRUE(xt::allclose(metrics_1d[0], nse_1d));
}