diff --git a/include/aare/decode.hpp b/include/aare/decode.hpp index 3cec22d..96a5645 100644 --- a/include/aare/decode.hpp +++ b/include/aare/decode.hpp @@ -7,8 +7,11 @@ namespace aare { +uint16_t adc_sar_05_06_07_08decode64to16(uint64_t input); uint16_t adc_sar_05_decode64to16(uint64_t input); uint16_t adc_sar_04_decode64to16(uint64_t input); +void adc_sar_05_06_07_08decode64to16(NDView input, + NDView output); void adc_sar_05_decode64to16(NDView input, NDView output); void adc_sar_04_decode64to16(NDView input, diff --git a/python/aare/transform.py b/python/aare/transform.py index fddfc1e..d1492e4 100644 --- a/python/aare/transform.py +++ b/python/aare/transform.py @@ -10,6 +10,10 @@ class AdcSar04Transform64to16: class AdcSar05Transform64to16: def __call__(self, data): return _aare.adc_sar_05_decode64to16(data) + +class AdcSar05060708Transform64to16: + def __call__(self, data): + return _aare.adc_sar_05_06_07_08decode64to16(data) class Moench05Transform: #Could be moved to C++ without changing the interface @@ -93,4 +97,5 @@ moench05_1g = Moench05Transform1g() moench05_old = Moench05TransformOld() matterhorn02 = Matterhorn02Transform() adc_sar_04_64to16 = AdcSar04Transform64to16() -adc_sar_05_64to16 = AdcSar05Transform64to16() \ No newline at end of file +adc_sar_05_64to16 = AdcSar05Transform64to16() +adc_sar_05_06_07_08_64to16 = AdcSar05060708Transform64to16() \ No newline at end of file diff --git a/python/src/ctb_raw_file.hpp b/python/src/ctb_raw_file.hpp index a6702bd..d9691d4 100644 --- a/python/src/ctb_raw_file.hpp +++ b/python/src/ctb_raw_file.hpp @@ -27,6 +27,30 @@ using namespace ::aare; void define_ctb_raw_file_io_bindings(py::module &m) { + m.def("adc_sar_05_06_07_08decode64to16", [](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) / + static_cast(bits_per_byte)}; + 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_05_06_07_08decode64to16(input_view, output_view); + + return output; + }); + m.def("adc_sar_05_decode64to16", [](py::array_t input) { if (input.ndim() != 2) { throw std::runtime_error( diff --git a/src/decode.cpp b/src/decode.cpp index 2de470f..34b9033 100644 --- a/src/decode.cpp +++ b/src/decode.cpp @@ -4,6 +4,39 @@ #include namespace aare { +uint16_t adc_sar_05_06_07_08decode64to16(uint64_t input) { + + // we want bits 29,17,28,18,31,21,27,20,24,23,25,22 and then pad to 16 + uint16_t output = 0; + output |= ((input >> 22) & 1) << 11; + output |= ((input >> 25) & 1) << 10; + output |= ((input >> 23) & 1) << 9; + output |= ((input >> 24) & 1) << 8; + output |= ((input >> 20) & 1) << 7; + output |= ((input >> 27) & 1) << 6; + output |= ((input >> 21) & 1) << 5; + output |= ((input >> 31) & 1) << 4; + output |= ((input >> 18) & 1) << 3; + output |= ((input >> 28) & 1) << 2; + output |= ((input >> 17) & 1) << 1; + output |= ((input >> 29) & 1) << 0; + return output; +} + +void adc_sar_05_06_07_08decode64to16(NDView input, + NDView output) { + if (input.shape() != output.shape()) { + throw std::invalid_argument(LOCATION + + " input and output shapes must match"); + } + + for (ssize_t i = 0; i < input.shape(0); i++) { + for (ssize_t j = 0; j < input.shape(1); j++) { + output(i, j) = adc_sar_05_06_07_08decode64to16(input(i, j)); + } + } +} + uint16_t adc_sar_05_decode64to16(uint64_t input) { // we want bits 29,19,28,18,31,21,27,20,24,23,25,22 and then pad to 16