An error occurred while loading the file. Please try again.
-
Thibault Hallouin authored62e0818b
#include <fstream>
#include <vector>
#include <gtest/gtest.h>
#include <xtensor/xtensor.hpp>
#include <xtensor/xmanipulation.hpp>
#include <xtensor/xcsv.hpp>
#include "evalhyd/evalp.hpp"
using namespace xt::placeholders; // required for `_` to work
TEST(ProbabilistTests, TestBrier)
{
// 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();
// compute scores
xt::xtensor<double, 1> thresholds = {690, 534, 445};
std::vector<xt::xarray<double>> metrics =
evalhyd::evalp(
// shape: (sites [1], time [t])
xt::view(observed, xt::newaxis(), xt::all()),
// shape: (sites [1], lead times [1], members [m], time [t])
xt::view(predicted, xt::newaxis(), xt::newaxis(), xt::all(), xt::all()),
{"BS", "BSS", "BS_CRD", "BS_LBD"},
thresholds
);
// check results
// Brier scores
xt::xtensor<double, 4> bs =
{{{{0.10615136, 0.07395622, 0.08669186}}}};
EXPECT_TRUE(xt::allclose(metrics[0], bs));
// Brier skill scores
xt::xtensor<double, 4> bss =
{{{{0.5705594, 0.6661165, 0.5635126}}}};
EXPECT_TRUE(xt::allclose(metrics[1], bss));
// Brier calibration-refinement decompositions
xt::xtensor<double, 5> bs_crd =
{{{{{0.011411758, 0.1524456, 0.2471852},
{0.005532413, 0.1530793, 0.2215031},
{0.010139431, 0.1220601, 0.1986125}}}}};
EXPECT_TRUE(xt::allclose(metrics[2], bs_crd));
// Brier likelihood-base rate decompositions
xt::xtensor<double, 5> bs_lbd =
{{{{{0.012159881, 0.1506234, 0.2446149},
{0.008031746, 0.1473869, 0.2133114},
{0.017191279, 0.1048221, 0.1743227}}}}};
EXPECT_TRUE(xt::allclose(metrics[3], bs_lbd));
}
TEST(ProbabilistTests, TestQuantiles)
{
// 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();