From b73f3b723fa665ad489b532be3fb2dbe0547fa31 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Sep 2026 12:34:28 +0200 Subject: [PATCH] added test for apply_remap --- include/aare/StrixelPixelRemapAlgorithm.hpp | 3 --- python/src/StrixelRemap/bind_StrixelRemap.hpp | 20 ++++++++++----- python/tests/test_StrixelPixelRemapAPI.py | 25 ++++++++++++++++--- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/include/aare/StrixelPixelRemapAlgorithm.hpp b/include/aare/StrixelPixelRemapAlgorithm.hpp index eb4384bb..87ef7365 100644 --- a/include/aare/StrixelPixelRemapAlgorithm.hpp +++ b/include/aare/StrixelPixelRemapAlgorithm.hpp @@ -132,9 +132,6 @@ void ApplyRemap(NDView input, NDView order_map, // Correctly mapped pixel output(row, col) = input[flat_index]; - // Long version - // T const &value = input[flat_index]; - // output(row, col) = value; } } } diff --git a/python/src/StrixelRemap/bind_StrixelRemap.hpp b/python/src/StrixelRemap/bind_StrixelRemap.hpp index 4f12bce0..7aeecf81 100644 --- a/python/src/StrixelRemap/bind_StrixelRemap.hpp +++ b/python/src/StrixelRemap/bind_StrixelRemap.hpp @@ -177,7 +177,7 @@ void define_RemapAlgorithm(py::module &m) { // cant use np.take or have to mask -1 indices m.def( - "ApplyRemap", + "apply_remap", [](py::array input, py::array_t order_map, @@ -191,8 +191,11 @@ void define_RemapAlgorithm(py::module &m) { throw std::runtime_error("Input and output arrays must be 2D"); } - auto i_dtype = input.dtype(); - auto o_dtype = output.dtype(); + if (!input.dtype().is(py::dtype::of())) { + throw std::runtime_error("Apply remap only supports input " + "arrays of type uint16_t"); // jungfrau + // frames + } if (!input.dtype().is(output.dtype())) { throw std::runtime_error( @@ -202,13 +205,18 @@ void define_RemapAlgorithm(py::module &m) { auto input_array = py::array_t::ensure(input); + + if (!input_array) { + throw std::runtime_error("conversion failed"); + } + auto output_array = py::array_t::ensure(output); - aare::remap::algo::ApplyRemap( - make_view_2d(input_array), // TODO expecting uint16_t for now - make_view_2d(order_map), make_view_2d(output_array)); + aare::remap::algo::ApplyRemap(make_view_2d(input_array), + make_view_2d(order_map), + make_view_2d(output_array)); }, py::arg("input").noconvert(), py::arg("order_map").noconvert(), py::arg("output").noconvert(), diff --git a/python/tests/test_StrixelPixelRemapAPI.py b/python/tests/test_StrixelPixelRemapAPI.py index 488daaba..62741451 100644 --- a/python/tests/test_StrixelPixelRemapAPI.py +++ b/python/tests/test_StrixelPixelRemapAPI.py @@ -71,18 +71,37 @@ def test_predefinedRemap(): user_roi = strixelremap.InclusiveROI(strixelremap.Chip1.placement_on_module.xmin + 5, strixelremap.Chip1.placement_on_module.xmin + 9, strixelremap.Chip1.placement_on_module.ymin + 5, strixelremap.Chip1.placement_on_module.ymin + 7) strixelpixelmap = strixelremap.jungfrau_tew_singlechip_25um_strixel_map(user_roi = user_roi, placement = strixelremap.Chip1) - - print(strixelpixelmap.map) assert strixelpixelmap.map.shape == (9, 2) assert np.array_equal(strixelpixelmap.map, np.array([[-1, 2], [0, 3], [1, 4], [-1, 7], [5,8], [6,9], [-1,12], [10,13], [11,14]])) + input_data = np.array([[1,2,3,4,5],[1,2,3,4,5], [1,2,3,4,5]]).astype(np.uint16) + + order_map = strixelpixelmap.map + + output = np.empty(order_map.shape, dtype=input_data.dtype) + + strixelremap.apply_remap(input_data, order_map, output) + assert np.array_equal(output, np.array([[0, 3], [1,4], [2,5], [0, 3], [1,4], [2,5], [0, 3], [1,4], [2,5]])) +def test_apply_remap(): + """ Apply remap throws upon invalid input data type """ + strixelpixelmap = strixelremap.jungfrau_ilgad_singlechip_25um_strixel_map(user_roi = strixelremap.Chip1.placement_on_module, placement = strixelremap.Chip1) -# test apply remap + order_map = strixelpixelmap.map + + user_roi_height = strixelremap.Chip1.placement_on_module.height + user_roi_width = strixelremap.Chip1.placement_on_module.width + + data = np.random.rand(user_roi_height, user_roi_width).astype(np.float64) + + output = np.empty(order_map.shape, dtype=data.dtype) + + with pytest.raises(RuntimeError): + strixelremap.apply_remap(data, order_map, output) # Documenation, Example \ No newline at end of file