mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-02-20 04:18:40 +01:00
implemented matterhorn transformer for 4 bit dynamic range
This commit is contained in:
@@ -24,6 +24,14 @@ class Moench05Transform:
|
||||
return np.take(data.view(np.uint16), self.pixel_map)
|
||||
|
||||
|
||||
class Moench03Transform:
|
||||
def __init__(self):
|
||||
self.pixel_map = _aare.GenerateMoench03PixelMap()
|
||||
|
||||
def __call__(self, data):
|
||||
return np.take(data.view(np.uint16), self.pixel_map)
|
||||
|
||||
|
||||
class Moench05Transform1g:
|
||||
#Could be moved to C++ without changing the interface
|
||||
def __init__(self):
|
||||
@@ -41,6 +49,14 @@ class Moench05TransformOld:
|
||||
def __call__(self, data):
|
||||
return np.take(data.view(np.uint16), self.pixel_map)
|
||||
|
||||
class Moench04AnalogTransform:
|
||||
#Could be moved to C++ without changing the interface
|
||||
def __init__(self):
|
||||
self.pixel_map = _aare.GenerateMoench04AnalogPixelMap()
|
||||
|
||||
def __call__(self, data):
|
||||
return np.take(data.view(np.uint16), self.pixel_map)
|
||||
|
||||
class Matterhorn02TransceiverTransform:
|
||||
#Could be moved to C++ without changing the interface
|
||||
def __init__(self):
|
||||
@@ -49,10 +65,9 @@ class Matterhorn02TransceiverTransform:
|
||||
def __call__(self, data):
|
||||
return np.take(data.view(np.uint16), self.pixel_map)
|
||||
|
||||
# TODO: give a reasonable name
|
||||
class Matterhorn02Transform:
|
||||
class Matterhorn10Transform:
|
||||
def __init__(self, dynamic_range : int, num_counters : int):
|
||||
self.pixel_map = _aare.GenerateMatterhorn2PixelMap(dynamic_range, num_counters)
|
||||
self.pixel_map = _aare.GenerateMatterhorn10PixelMap(dynamic_range, num_counters)
|
||||
self.dynamic_range = dynamic_range
|
||||
self.num_counters = num_counters
|
||||
|
||||
@@ -61,9 +76,8 @@ class Matterhorn02Transform:
|
||||
return np.take(data.view(np.uint16), self.pixel_map)
|
||||
elif self.dynamic_range == 8:
|
||||
return np.take(data.view(np.uint8), self.pixel_map)
|
||||
else:
|
||||
return 0
|
||||
#return np.take(data.view()) # TODO need to expand to 8 bits
|
||||
else: #dynamic range 4
|
||||
return np.take(_aare.expand4to8bit(data.view(np.uint8)), self.pixel_map)
|
||||
|
||||
class Mythen302Transform:
|
||||
"""
|
||||
@@ -107,7 +121,7 @@ class Mythen302Transform:
|
||||
moench05 = Moench05Transform()
|
||||
moench05_1g = Moench05Transform1g()
|
||||
moench05_old = Moench05TransformOld()
|
||||
matterhorn02 = Matterhorn02Transform()
|
||||
matterhorn02 = Matterhorn02TransceiverTransform()
|
||||
adc_sar_04_64to16 = AdcSar04Transform64to16()
|
||||
adc_sar_05_64to16 = AdcSar05Transform64to16()
|
||||
adc_sar_05_06_07_08_64to16 = AdcSar05060708Transform64to16()
|
||||
@@ -50,7 +50,7 @@ void define_ctb_raw_file_io_bindings(py::module &m) {
|
||||
|
||||
return output;
|
||||
});
|
||||
|
||||
|
||||
m.def("adc_sar_05_decode64to16", [](py::array_t<uint8_t> input) {
|
||||
if (input.ndim() != 2) {
|
||||
throw std::runtime_error(
|
||||
@@ -121,67 +121,81 @@ void define_ctb_raw_file_io_bindings(py::module &m) {
|
||||
});
|
||||
|
||||
m.def("expand24to32bit",
|
||||
[](py::array_t<uint8_t, py::array::c_style | py::array::forcecast>
|
||||
&input, uint32_t offset){
|
||||
[](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();
|
||||
|
||||
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);
|
||||
|
||||
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()});
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
aare::expand24to32bit(input_view, output_view, bitoff);
|
||||
return output;
|
||||
m.def("expand4to8bit",
|
||||
[](py::array_t<uint8_t, py::array::c_style | py::array::forcecast>
|
||||
&input) {
|
||||
py::buffer_info buf = input.request();
|
||||
|
||||
});
|
||||
py::array_t<uint8_t> output(buf.size * 2);
|
||||
|
||||
NDView<uint8_t, 1> input_view(input.mutable_data(),
|
||||
{input.size()});
|
||||
NDView<uint8_t, 1> output_view(output.mutable_data(),
|
||||
{output.size()});
|
||||
|
||||
aare::expand4to8bit(input_view, output_view);
|
||||
return output;
|
||||
});
|
||||
|
||||
m.def("decode_my302",
|
||||
[](py::array_t<uint8_t, py::array::c_style | py::array::forcecast>
|
||||
&input, uint32_t offset){
|
||||
[](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;
|
||||
|
||||
// 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;
|
||||
|
||||
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 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()));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
aare::expand24to32bit(input_view, output_view, bitoff);
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
});
|
||||
return output;
|
||||
});
|
||||
|
||||
py::class_<CtbRawFile>(m, "CtbRawFile")
|
||||
.def(py::init<const std::filesystem::path &>())
|
||||
|
||||
Reference in New Issue
Block a user