Merge 'origin/main' into feature/cuda_clusterfinder

This commit is contained in:
kferjaoui
2026-07-21 15:21:49 +02:00
64 changed files with 4365 additions and 542 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+31
View File
@@ -0,0 +1,31 @@
import pytest
from aare import Interpolator, ClusterVector, Etai, Cluster
import numpy as np
def test_interpolation_api():
eta_distribution = np.zeros((10, 10, 1)) # dummy eta distribution
etax_bins = np.linspace(0, 1.0, 11)
etay_bins = np.linspace(0, 1.0, 11)
e_bins = np.array([0., 10.]) # dummy energy bins
interpolator = Interpolator(eta_distribution, etax_bins, etay_bins, e_bins)
cluster_vector = ClusterVector()
cluster_vector.push_back(Cluster(10, 5, np.ones(shape=9, dtype=np.int32)))
cluster_vector.push_back(Cluster(20, 10, np.ones(shape=9, dtype=np.int32)))
eta1 = Etai()
eta1.x = 0.1
eta1.y = 0.1
eta1.sum = 5
eta2 = Etai()
eta2.x = 0.1
eta2.y = 0.9
eta2.sum = 6
etas = np.array([eta1, eta2]) # dummy etas for the clusters
photons = interpolator.interpolate(cluster_vector, etas)
assert photons.size == cluster_vector.size # should return one photon per cluster
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+40
View File
@@ -0,0 +1,40 @@
import numpy as np
import pytest
from aare import Pedestal_d, Pedestal_f
@pytest.mark.parametrize(
("pedestal_type", "expected_dtype"),
[(Pedestal_d, np.float64), (Pedestal_f, np.float32)],
)
def test_numpy_array_minus_pedestal(pedestal_type, expected_dtype):
pedestal = pedestal_type(2, 3)
pedestal.push(np.array([[2, 4, 6], [8, 10, 12]], dtype=np.uint16))
array = np.array([[12, 14, 16], [18, 20, 22]], dtype=np.uint16)
result = array - pedestal
np.testing.assert_array_equal(
result, np.array([[10, 10, 10], [10, 10, 10]], dtype=expected_dtype)
)
assert result.dtype == expected_dtype
def test_numpy_array_minus_pedestal_rejects_incompatible_shape():
pedestal = Pedestal_d(2, 3)
array = np.zeros((2, 2), dtype=np.float64)
with pytest.raises(ValueError):
array - pedestal
def test_pedestal_exposes_mean_as_read_only_buffer():
pedestal = Pedestal_d(2, 3)
pedestal.push(np.array([[2, 4, 6], [8, 10, 12]], dtype=np.uint16))
mean = np.asarray(pedestal)
np.testing.assert_array_equal(mean, pedestal.view())
assert np.shares_memory(mean, pedestal.view())
assert not mean.flags.writeable
+8 -9
View File
@@ -8,10 +8,10 @@ def test_matterhorn10_16bit(test_data_path):
with CtbRawFile(test_data_path / "raw/Matterhorn10/16bit_master_0.json", transform = transform.Matterhorn10Transform(dynamic_range=16, num_counters=1)) as f:
headers, frames = f.read_frame()
assert frames.shape == (256, 256)
assert frames.shape == (1, 256, 256)
assert frames.dtype == np.uint16
expected_data = np.tile(np.arange(255, -1, -1,dtype=np.uint16), (256, 1)) # TODO: endianess issue ?
expected_data = np.tile(np.arange(255, -1, -1,dtype=np.uint16), (1, 256, 1)) # TODO: endianess issue ?
assert np.all(frames == expected_data)
@@ -22,24 +22,23 @@ def test_matterhorn10_8bit(test_data_path):
with CtbRawFile(test_data_path / "raw/Matterhorn10/8bit_master_1.json", transform = transform.Matterhorn10Transform(dynamic_range=8, num_counters=1)) as f:
headers, frames = f.read_frame()
assert frames.shape == (256, 256)
assert frames.shape == (1, 256, 256)
assert frames.dtype == np.uint8
expected_data = np.tile(np.arange(255, -1, -1,dtype=np.uint8), (256, 1)) # TODO: endianess issue ?
expected_data = np.tile(np.arange(255, -1, -1,dtype=np.uint8), (1, 256, 1)) # TODO: endianess issue ?
assert np.all(frames == expected_data)
@pytest.mark.withdata
def test_matterhorn10_4bit(test_data_path):
""" Matterhorn10Transform 1 counter 4 bit dynamic range """
with CtbRawFile(test_data_path / "raw/Matterhorn10/newnewrun_4bit_1counter_master_0.json", transform = transform.Matterhorn10Transform(dynamic_range=4, num_counters=1)) as f:
headers, frames = f.read_frame()
assert frames.shape == (256, 256)
assert frames.shape == (1, 256, 256)
assert frames.dtype == np.uint8
expected_data = np.tile(np.tile(np.arange(15, -1, -1, dtype=np.uint8), 16), (256, 1)) # TODO: endianess issue ?
expected_data = np.tile(np.tile(np.arange(15, -1, -1, dtype=np.uint8), 16), (1, 256, 1)) # TODO: endianess issue ?
assert np.all(frames == expected_data)
@@ -50,9 +49,9 @@ def test_matterhorn10_16bit_4counters(test_data_path):
with CtbRawFile(test_data_path / "raw/Matterhorn10/4counter_16bit_master_4.json", transform = transform.Matterhorn10Transform(dynamic_range=16, num_counters=4)) as f:
headers, frames = f.read_frame()
assert frames.shape == (4*256, 256)
assert frames.shape == (4, 256, 256)
assert frames.dtype == np.uint16
expected_data = np.tile(np.arange(255, -1, -1,dtype=np.uint16), (4*256, 1)) # TODO: endianess issue ?
expected_data = np.tile(np.arange(255, -1, -1,dtype=np.uint16), (4, 256, 1)) # TODO: endianess issue ?
assert np.all(frames == expected_data)