mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-10-17 15:35:10 +02:00
Fixed failing tests due to updated bindings (#420)
- New python bindings return a (1,n_bytes) array instead of a 1d array - Flatten on python side before transform
This commit is contained in:
@@ -135,7 +135,7 @@ class Matterhorn10Transform:
|
||||
elif self.dynamic_range == 8:
|
||||
return np.take(data.view(np.uint8), self.pixel_map).reshape(self.num_counters, Matterhorn10.nRows, Matterhorn10.nCols)
|
||||
else: #dynamic range 4
|
||||
return np.take(_aare.expand4to8bit(data.view(np.uint8)), self.pixel_map).reshape(self.num_counters, Matterhorn10.nRows, Matterhorn10.nCols)
|
||||
return np.take(_aare.expand4to8bit(data.view(np.uint8).reshape(-1)), self.pixel_map).reshape(self.num_counters, Matterhorn10.nRows, Matterhorn10.nCols)
|
||||
|
||||
class Mythen302Transform:
|
||||
"""
|
||||
@@ -169,7 +169,7 @@ class Mythen302Transform:
|
||||
image : np.ndarray
|
||||
uint32 array of size 64, 3
|
||||
"""
|
||||
res = _aare.decode_my302(data, self.offset)
|
||||
res = _aare.decode_my302(data.reshape(-1), self.offset)
|
||||
res = res.reshape(
|
||||
Mythen302Transform._n_channels, Mythen302Transform._n_counters
|
||||
)
|
||||
|
||||
@@ -56,3 +56,34 @@ def test_matterhorn10_16bit_4counters(test_data_path):
|
||||
expected_data = np.tile(np.arange(255, -1, -1,dtype=np.uint16), (4, 256, 1)) # TODO: endianess issue ?
|
||||
|
||||
assert np.all(frames == expected_data)
|
||||
|
||||
|
||||
def test_matterhorn10_4bit_accepts_2d_frame():
|
||||
"""CtbRawFile.read_frame returns a (1, n_bytes) array; the 4 bit path must accept it"""
|
||||
n_bytes = (transform.Matterhorn10.nRows * transform.Matterhorn10.nCols * 4) // 8
|
||||
data = (np.arange(n_bytes) % 256).astype(np.uint8).reshape(1, n_bytes)
|
||||
t = transform.Matterhorn10Transform(dynamic_range=4, num_counters=1)
|
||||
|
||||
frames = t(data)
|
||||
|
||||
assert frames.shape == (1, 256, 256)
|
||||
assert frames.dtype == np.uint8
|
||||
|
||||
flat = data.reshape(-1)
|
||||
nibbles = np.stack([flat & 0x0F, flat >> 4], axis=-1).reshape(-1)
|
||||
expected = np.take(nibbles, t.pixel_map).reshape(1, 256, 256)
|
||||
assert np.array_equal(frames, expected)
|
||||
|
||||
|
||||
def test_mythen302_accepts_2d_frame():
|
||||
"""CtbRawFile.read_frame returns a (1, n_bytes) array; Mythen302Transform must accept it"""
|
||||
n_bytes = 64 * 3 * 3 + 2 # two extra bytes for the 4 bit offset
|
||||
rng = np.random.default_rng(0)
|
||||
data = rng.integers(0, 256, size=(1, n_bytes), dtype=np.uint8)
|
||||
t = transform.Mythen302Transform(offset=4)
|
||||
|
||||
res = t(data)
|
||||
|
||||
assert res.shape == (64, 3)
|
||||
assert res.dtype == np.uint32
|
||||
assert np.array_equal(res, t(data.reshape(-1)))
|
||||
|
||||
Reference in New Issue
Block a user