mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-02-19 04:58:40 +01:00
Dev/decode my302 (#254)
This PR adds support for decoding digital data from the my320 test chip. - Added BitOffset (strong type) - Expand 24 to 32 bit - Python bindings for decoding my302 - Improved docs
This commit is contained in:
@@ -49,6 +49,43 @@ class Matterhorn02Transform:
|
||||
else:
|
||||
return np.take(data.view(np.uint16), self.pixel_map[0:counters])
|
||||
|
||||
class Mythen302Transform:
|
||||
"""
|
||||
Transform Mythen 302 test chip data from a buffer of bytes (uint8_t)
|
||||
to a uint32 numpy array of [64,3] representing channels and counters.
|
||||
Assumes data taken with rx_dbitlist 17 6, rx_dbitreorder 1 and Digital
|
||||
Samples = 2310 [(64x3x24)/2 + some extra]
|
||||
|
||||
.. note::
|
||||
|
||||
The offset is in number of bits 0-7
|
||||
|
||||
"""
|
||||
_n_channels = 64
|
||||
_n_counters = 3
|
||||
|
||||
def __init__(self, offset=4):
|
||||
self.offset = offset
|
||||
|
||||
def __call__(self, data : np.ndarray):
|
||||
"""
|
||||
Transform buffer of data to a [64,3] np.ndarray of uint32.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
data : np.ndarray
|
||||
Expected dtype: uint8
|
||||
|
||||
Returns
|
||||
----------
|
||||
image : np.ndarray
|
||||
uint32 array of size 64, 3
|
||||
"""
|
||||
res = _aare.decode_my302(data, self.offset)
|
||||
res = res.reshape(
|
||||
Mythen302Transform._n_channels, Mythen302Transform._n_counters
|
||||
)
|
||||
return res
|
||||
|
||||
#on import generate the pixel maps to avoid doing it every time
|
||||
moench05 = Moench05Transform()
|
||||
|
||||
@@ -96,6 +96,69 @@ void define_ctb_raw_file_io_bindings(py::module &m) {
|
||||
return output;
|
||||
});
|
||||
|
||||
m.def("expand24to32bit",
|
||||
[](py::array_t<uint8_t, py::array::c_style | py::array::forcecast>
|
||||
&input, uint32_t offset){
|
||||
|
||||
aare::BitOffset bitoff(offset);
|
||||
py::buffer_info buf = input.request();
|
||||
|
||||
constexpr uint32_t bytes_per_channel = 3; //24 bit
|
||||
py::array_t<uint32_t> output(buf.size/bytes_per_channel);
|
||||
|
||||
NDView<uint8_t, 1> input_view(input.mutable_data(),
|
||||
{input.size()});
|
||||
NDView<uint32_t, 1> output_view(output.mutable_data(),
|
||||
{output.size()});
|
||||
|
||||
aare::expand24to32bit(input_view, output_view, bitoff);
|
||||
return output;
|
||||
|
||||
});
|
||||
|
||||
m.def("decode_my302",
|
||||
[](py::array_t<uint8_t, py::array::c_style | py::array::forcecast>
|
||||
&input, uint32_t offset){
|
||||
|
||||
// Physical layout of the chip
|
||||
constexpr size_t channels = 64;
|
||||
constexpr size_t counters = 3;
|
||||
constexpr size_t bytes_per_channel = 3; //24 bit
|
||||
constexpr int n_outputs = 2;
|
||||
|
||||
ssize_t expected_size = channels*counters*bytes_per_channel;
|
||||
|
||||
//If whe have an offset we need one extra byte per output
|
||||
aare::BitOffset bitoff(offset);
|
||||
if(bitoff.value())
|
||||
expected_size += n_outputs;
|
||||
|
||||
if (input.size() != expected_size) {
|
||||
throw std::runtime_error(
|
||||
fmt::format("{} Expected an input size of {} bytes. Called "
|
||||
"with input size of {}",
|
||||
LOCATION, expected_size, input.size()));
|
||||
}
|
||||
|
||||
py::buffer_info buf = input.request();
|
||||
py::array_t<uint32_t> output(channels * counters);
|
||||
|
||||
for (int i = 0; i!=n_outputs; ++i){
|
||||
auto step = input.size()/n_outputs;
|
||||
auto out_step = output.size()/n_outputs;
|
||||
NDView<uint8_t, 1> input_view(input.mutable_data()+step*i,
|
||||
{input.size()/n_outputs});
|
||||
NDView<uint32_t, 1> output_view(output.mutable_data()+out_step*i,
|
||||
{output.size()/n_outputs});
|
||||
|
||||
aare::expand24to32bit(input_view, output_view, bitoff);
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
});
|
||||
|
||||
py::class_<CtbRawFile>(m, "CtbRawFile")
|
||||
.def(py::init<const std::filesystem::path &>())
|
||||
.def("read_frame",
|
||||
|
||||
Reference in New Issue
Block a user