mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-02-21 09:38:40 +01:00
clang-format
This commit is contained in:
@@ -39,7 +39,8 @@ void define_raw_file_io_bindings(py::module &m) {
|
||||
// return headers from all subfiles
|
||||
py::array_t<DetectorHeader> header(self.n_modules());
|
||||
|
||||
py::array image = allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
py::array image =
|
||||
allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
self.read_into(
|
||||
reinterpret_cast<std::byte *>(image.mutable_data()),
|
||||
header.mutable_data());
|
||||
@@ -72,7 +73,8 @@ void define_raw_file_io_bindings(py::module &m) {
|
||||
{self.n_modules_in_roi()[0], n_frames});
|
||||
}
|
||||
|
||||
py::array images = allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
py::array images =
|
||||
allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
self.read_into(
|
||||
reinterpret_cast<std::byte *>(images.mutable_data()),
|
||||
n_frames, header.mutable_data());
|
||||
@@ -85,33 +87,32 @@ void define_raw_file_io_bindings(py::module &m) {
|
||||
|
||||
.def(
|
||||
"read_roi",
|
||||
[](RawFile &self,
|
||||
const size_t roi_index) {
|
||||
[](RawFile &self, const size_t roi_index) {
|
||||
if (self.num_rois() == 0) {
|
||||
throw std::runtime_error(LOCATION + "No ROIs defined.");
|
||||
}
|
||||
|
||||
if ( roi_index >= self.num_rois()) {
|
||||
if (roi_index >= self.num_rois()) {
|
||||
throw std::runtime_error(LOCATION +
|
||||
"ROI index out of range.");
|
||||
}
|
||||
|
||||
// return headers from all subfiles
|
||||
py::array_t<DetectorHeader> header(self.n_modules_in_roi()[roi_index]);
|
||||
py::array_t<DetectorHeader> header(
|
||||
self.n_modules_in_roi()[roi_index]);
|
||||
|
||||
|
||||
std::vector<size_t> shape;
|
||||
shape.reserve(2);
|
||||
shape.push_back(self.roi_geometries(roi_index).pixels_y());
|
||||
shape.push_back(self.roi_geometries(roi_index).pixels_x());
|
||||
|
||||
py::array image = allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
|
||||
py::array image =
|
||||
allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
|
||||
self.read_roi_into(
|
||||
reinterpret_cast<std::byte *>(image.mutable_data()),
|
||||
roi_index, self.tell(), header.mutable_data());
|
||||
|
||||
|
||||
self.seek(self.tell() + 1); // advance frame number so the
|
||||
return py::make_tuple(header, image);
|
||||
},
|
||||
@@ -143,8 +144,6 @@ void define_raw_file_io_bindings(py::module &m) {
|
||||
throw std::runtime_error(LOCATION + "No ROIs defined.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t number_of_ROIs = self.num_rois();
|
||||
|
||||
// const uint8_t item_size = self.bytes_per_pixel();
|
||||
@@ -152,25 +151,25 @@ void define_raw_file_io_bindings(py::module &m) {
|
||||
std::vector<py::array> images(number_of_ROIs);
|
||||
|
||||
// return headers from all subfiles
|
||||
std::vector<py::array_t<DetectorHeader>> headers(number_of_ROIs);
|
||||
std::vector<py::array_t<DetectorHeader>> headers(
|
||||
number_of_ROIs);
|
||||
for (size_t r = 0; r < number_of_ROIs; r++) {
|
||||
headers[r] =
|
||||
py::array_t<DetectorHeader>(self.n_modules_in_roi()[r]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (size_t r = 0; r < number_of_ROIs; r++) {
|
||||
std::vector<size_t> shape;
|
||||
shape.reserve(2);
|
||||
shape.push_back(self.roi_geometries(r).pixels_y());
|
||||
shape.push_back(self.roi_geometries(r).pixels_x());
|
||||
|
||||
images[r] = allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
images[r] =
|
||||
allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
|
||||
self.read_roi_into(
|
||||
reinterpret_cast<std::byte *>(images[r].mutable_data()),
|
||||
r, self.tell(),headers[r].mutable_data());
|
||||
r, self.tell(), headers[r].mutable_data());
|
||||
}
|
||||
self.seek(self.tell() + 1); // advance frame number so the
|
||||
return py::make_tuple(headers, images);
|
||||
@@ -217,12 +216,10 @@ void define_raw_file_io_bindings(py::module &m) {
|
||||
|
||||
// return headers from all subfiles
|
||||
auto n_mod = self.n_modules_in_roi()[roi_index];
|
||||
py::array_t<DetectorHeader> header({
|
||||
n_frames, n_mod}
|
||||
);
|
||||
py::array_t<DetectorHeader> header({n_frames, n_mod});
|
||||
|
||||
|
||||
py::array images = allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
py::array images =
|
||||
allocate_image_data(self.bytes_per_pixel(), shape);
|
||||
|
||||
auto image_buffer =
|
||||
reinterpret_cast<std::byte *>(images.mutable_data());
|
||||
|
||||
@@ -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,65 @@ 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("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 &>())
|
||||
|
||||
@@ -64,9 +64,8 @@ void define_file_io_bindings(py::module &m) {
|
||||
.def_property_readonly("cols", &File::cols)
|
||||
.def_property_readonly("bitdepth", &File::bitdepth)
|
||||
.def_property_readonly("bytes_per_pixel", &File::bytes_per_pixel)
|
||||
.def_property_readonly(
|
||||
"detector_type",
|
||||
[](File &self) { return self.detector_type(); })
|
||||
.def_property_readonly("detector_type",
|
||||
[](File &self) { return self.detector_type(); })
|
||||
.def("read_frame",
|
||||
[](File &self) {
|
||||
const uint8_t item_size = self.bytes_per_pixel();
|
||||
@@ -161,7 +160,6 @@ void define_file_io_bindings(py::module &m) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
py::class_<ScanParameters>(m, "ScanParameters")
|
||||
.def(py::init<const std::string &>())
|
||||
.def(py::init<const ScanParameters &>())
|
||||
|
||||
@@ -86,17 +86,17 @@ struct fmt_format_trait<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
|
||||
template <typename ClusterType>
|
||||
auto fmt_format = fmt_format_trait<ClusterType>::value();
|
||||
|
||||
/**
|
||||
* Helper function to allocate image data given item size and shape
|
||||
* used when we want to fill a numpy array and return to python
|
||||
*/
|
||||
/**
|
||||
* Helper function to allocate image data given item size and shape
|
||||
* used when we want to fill a numpy array and return to python
|
||||
*/
|
||||
py::array allocate_image_data(size_t item_size,
|
||||
const std::vector<size_t> &shape) {
|
||||
py::array image_data;
|
||||
if (item_size == 1) {
|
||||
image_data = py::array_t<uint8_t>(shape);
|
||||
} else if (item_size == 2) {
|
||||
image_data = py::array_t<uint16_t>(shape);
|
||||
image_data = py::array_t<uint16_t>(shape);
|
||||
} else if (item_size == 4) {
|
||||
image_data = py::array_t<uint32_t>(shape);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user