Files
aare/src/FastPedestal.test.cpp
T
Erik Fröjdh 8551281eb7
Build on RHEL9 / build (push) Successful in 2m52s
Build on RHEL8 / build (push) Successful in 3m33s
Run tests using data on local RHEL8 / build (push) Successful in 4m31s
Build on local RHEL8 / build (push) Successful in 3m4s
Cleaned up Pedestal (#370)
- renamed pedestal.hpp to bind_Pedestal.hpp for python bindings
- variance is now always calculated in double and made private
- cost correctness in a few places
- removed push_fast and explicit updates of mean from Pedestal. If
performance is needed use FastPedestal
- Pedestal no longer caches std
2026-09-14 16:27:53 +02:00

61 lines
2.0 KiB
C++

// SPDX-License-Identifier: MPL-2.0
#include "aare/FastPedestal.hpp"
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
using namespace aare;
TEMPLATE_TEST_CASE("fast pedestal keeps variance in double precision",
"[fast-pedestal]", double, float, int16_t) {
FastPedestal<TestType> pedestal(1, 1, 2);
NDArray<uint16_t, 2> frame({1, 1}, 0);
pedestal.add_init_frame(frame.view());
frame[0] = 1000;
pedestal.add_init_frame(frame.view());
const auto &ready = pedestal;
REQUIRE(ready.std(0, 0) == static_cast<TestType>(500));
REQUIRE(ready.std_unchecked(0) == ready.std(0, 0));
REQUIRE(ready.std()[0] == ready.std(0, 0));
pedestal.push_ema(frame.view());
REQUIRE(ready.std(0, 0) == static_cast<TestType>(std::sqrt(187500.0)));
REQUIRE(ready.std_unchecked(0) == ready.std(0, 0));
REQUIRE(ready.std()[0] == ready.std(0, 0));
}
TEST_CASE("fast pedestal validates standard deviation access",
"[fast-pedestal]") {
FastPedestal<double> pedestal(1, 1, 1);
REQUIRE_THROWS(pedestal.std());
REQUIRE_THROWS(pedestal.std(0, 0));
NDArray<uint16_t, 2> frame({1, 1}, 42);
pedestal.add_init_frame(frame.view());
REQUIRE(pedestal.std(0, 0) == 0.0);
REQUIRE_THROWS(pedestal.std(1, 0));
REQUIRE_THROWS(pedestal.std(0, 1));
}
TEMPLATE_TEST_CASE("fast pedestal std stays finite after settling",
"[fast-pedestal]", double, float, int16_t) {
FastPedestal<TestType> pedestal(1, 1, 10);
NDArray<uint16_t, 2> frame({1, 1}, 16382);
pedestal.add_init_frame(frame.view());
frame[0] = 16383;
for (int i = 0; i < 9; ++i) {
pedestal.add_init_frame(frame.view());
}
for (int i = 0; i < 300; ++i) {
pedestal.push_ema(frame.view());
}
const auto noise = pedestal.std(0, 0);
REQUIRE(std::isfinite(noise));
REQUIRE(noise >= 0);
REQUIRE(static_cast<double>(noise) < 1e-3);
REQUIRE(pedestal.std_unchecked(0) == noise);
REQUIRE(pedestal.std()[0] == noise);
}