Commit 116fcf67 authored by Thibault Hallouin's avatar Thibault Hallouin
Browse files

add unittest on masking functionality

No related merge requests found
Pipeline #37092 passed with stages
in 8 seconds
Showing with 48 additions and 0 deletions
+48 -0
......@@ -7,6 +7,8 @@
#include "evalhyd/evalp.hpp"
using namespace xt::placeholders; // required for `_` to work
TEST(ProbabilistTests, TestBrier) {
// read in data
std::ifstream ifs;
......@@ -58,3 +60,49 @@ TEST(ProbabilistTests, TestBrier) {
{0.017191279, 0.1048221, 0.1743227}}}}};
EXPECT_TRUE(xt::allclose(metrics[3], bs_lbd));
}
TEST(ProbabilistTests, TestMasks) {
// read in data
std::ifstream ifs;
ifs.open("./data/q_obs.csv");
xt::xtensor<double, 1> observed = xt::squeeze(xt::load_csv<int>(ifs));
ifs.close();
ifs.open("./data/q_prd.csv");
xt::xtensor<double, 2> predicted = xt::load_csv<double>(ifs);
ifs.close();
// generate temporal subset by dropping 20 first time steps
xt::xtensor<double, 2> masks =
xt::ones<bool>({std::size_t {1}, std::size_t {observed.size()}});
xt::view(masks, 0, xt::range(0, 20)) = 0;
// compute scores using masks to subset whole record
xt::xtensor<double, 1> thresholds = {690, 534, 445};
std::vector<std::string> metrics = {"BS", "BSS", "BS_CRD", "BS_LBD"};
std::vector<xt::xarray<double>> metrics_masked =
evalhyd::evalp(
xt::view(observed, xt::newaxis(), xt::all()),
xt::view(predicted, xt::newaxis(), xt::newaxis(), xt::all(), xt::all()),
metrics,
thresholds,
masks
);
// compute scores on pre-computed subset of whole record
std::vector<xt::xarray<double>> metrics_subset =
evalhyd::evalp(
xt::view(observed, xt::newaxis(), xt::range(20, _)),
xt::view(predicted, xt::newaxis(), xt::newaxis(), xt::all(), xt::range(20, _)),
metrics,
thresholds
);
// check results are identical
for (int m = 0; m < metrics.size(); m++)
{
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