From c0c5e07ad8c1f090c5435f0cadc81f408360ce4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Wed, 12 Feb 2025 16:17:32 +0100 Subject: [PATCH] added decoding of adc_sar_04 (#127) --- include/aare/decode.hpp | 3 ++- python/aare/transform.py | 5 +++++ python/src/ctb_raw_file.hpp | 23 +++++++++++++++++++---- src/decode.cpp | 29 +++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/include/aare/decode.hpp b/include/aare/decode.hpp index 7ff0963..1c3c479 100644 --- a/include/aare/decode.hpp +++ b/include/aare/decode.hpp @@ -6,7 +6,8 @@ namespace aare { uint16_t adc_sar_05_decode64to16(uint64_t input); - +uint16_t adc_sar_04_decode64to16(uint64_t input); void adc_sar_05_decode64to16(NDView input, NDView output); +void adc_sar_04_decode64to16(NDView input, NDView output); } // namespace aare \ No newline at end of file diff --git a/python/aare/transform.py b/python/aare/transform.py index bbb3b5d..2f66942 100644 --- a/python/aare/transform.py +++ b/python/aare/transform.py @@ -2,6 +2,10 @@ import numpy as np from . import _aare +class AdcSar04Transform64to16: + def __call__(self, data): + return _aare.adc_sar_04_decode64to16(data) + class AdcSar05Transform64to16: def __call__(self, data): return _aare.adc_sar_05_decode64to16(data) @@ -50,4 +54,5 @@ moench05 = Moench05Transform() moench05_1g = Moench05Transform1g() moench05_old = Moench05TransformOld() matterhorn02 = Matterhorn02Transform() +adc_sar_04_64to16 = AdcSar04Transform64to16() adc_sar_05_64to16 = AdcSar05Transform64to16() \ No newline at end of file diff --git a/python/src/ctb_raw_file.hpp b/python/src/ctb_raw_file.hpp index 5aeb387..9ce656d 100644 --- a/python/src/ctb_raw_file.hpp +++ b/python/src/ctb_raw_file.hpp @@ -37,15 +37,30 @@ m.def("adc_sar_05_decode64to16", [](py::array_t input) { //Create a view of the input and output arrays NDView input_view(reinterpret_cast(input.mutable_data()), {output.shape(0), output.shape(1)}); - NDView output_view(output.mutable_data(), {output.shape(0), output.shape(1)}); adc_sar_05_decode64to16(input_view, output_view); - // for (size_t i=0; i!=input_view.size(); ++i) { - // output_view(i) = decode_adc(input_view(i)); - // } + + return output; +}); +m.def("adc_sar_04_decode64to16", [](py::array_t input) { + + + if(input.ndim() != 2){ + throw std::runtime_error("Only 2D arrays are supported at this moment"); + } + + //Create a 2D output array with the same shape as the input + std::vector shape{input.shape(0), input.shape(1)/8}; + py::array_t output(shape); + + //Create a view of the input and output arrays + NDView input_view(reinterpret_cast(input.mutable_data()), {output.shape(0), output.shape(1)}); + NDView output_view(output.mutable_data(), {output.shape(0), output.shape(1)}); + + adc_sar_04_decode64to16(input_view, output_view); return output; }); diff --git a/src/decode.cpp b/src/decode.cpp index 8af8319..17c033d 100644 --- a/src/decode.cpp +++ b/src/decode.cpp @@ -29,4 +29,33 @@ void adc_sar_05_decode64to16(NDView input, NDView outpu } } +uint16_t adc_sar_04_decode64to16(uint64_t input){ + + // bit_map = array([15,17,19,21,23,4,6,8,10,12,14,16] LSB->MSB + uint16_t output = 0; + output |= ((input >> 16) & 1) << 11; + output |= ((input >> 14) & 1) << 10; + output |= ((input >> 12) & 1) << 9; + output |= ((input >> 10) & 1) << 8; + output |= ((input >> 8) & 1) << 7; + output |= ((input >> 6) & 1) << 6; + output |= ((input >> 4) & 1) << 5; + output |= ((input >> 23) & 1) << 4; + output |= ((input >> 21) & 1) << 3; + output |= ((input >> 19) & 1) << 2; + output |= ((input >> 17) & 1) << 1; + output |= ((input >> 15) & 1) << 0; + return output; +} + +void adc_sar_04_decode64to16(NDView input, NDView output){ + for(int64_t i = 0; i < input.shape(0); i++){ + for(int64_t j = 0; j < input.shape(1); j++){ + output(i,j) = adc_sar_04_decode64to16(input(i,j)); + } + } +} + + + } // namespace aare