mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-04-20 05:40:03 +02:00
started to do python refactoring
Some checks failed
Build the package using cmake then documentation / build (ubuntu-latest, 3.12) (push) Failing after 44s
Some checks failed
Build the package using cmake then documentation / build (ubuntu-latest, 3.12) (push) Failing after 44s
This commit is contained in:
parent
d7ef9bb1d8
commit
a24bbd9cf9
@ -16,149 +16,176 @@
|
|||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
using pd_type = double;
|
using pd_type = double;
|
||||||
|
|
||||||
template <typename T>
|
using namespace aare;
|
||||||
|
|
||||||
|
template <typename ClusterType>
|
||||||
void define_cluster_vector(py::module &m, const std::string &typestr) {
|
void define_cluster_vector(py::module &m, const std::string &typestr) {
|
||||||
|
|
||||||
|
using T = typename extract_template_arguments<ClusterType>::value_type;
|
||||||
|
|
||||||
auto class_name = fmt::format("ClusterVector_{}", typestr);
|
auto class_name = fmt::format("ClusterVector_{}", typestr);
|
||||||
py::class_<ClusterVector<T>>(m, class_name.c_str(), py::buffer_protocol())
|
py::class_<ClusterVector<ClusterType>>(m, class_name.c_str(),
|
||||||
.def(py::init<int, int>(),
|
py::buffer_protocol())
|
||||||
py::arg("cluster_size_x") = 3, py::arg("cluster_size_y") = 3)
|
.def(py::init<int, int>(), py::arg("cluster_size_x") = 3,
|
||||||
|
py::arg("cluster_size_y") = 3) // TODO change!!!
|
||||||
.def("push_back",
|
.def("push_back",
|
||||||
[](ClusterVector<T> &self, int x, int y, py::array_t<T> data) {
|
[](ClusterVector<ClusterType> &self, ClusterType &cl) {
|
||||||
// auto view = make_view_2d(data);
|
// auto view = make_view_2d(data);
|
||||||
self.push_back(x, y, reinterpret_cast<const std::byte*>(data.data()));
|
self.push_back(cl);
|
||||||
})
|
})
|
||||||
.def_property_readonly("size", &ClusterVector<T>::size)
|
.def_property_readonly("size", &ClusterVector<ClusterType>::size)
|
||||||
.def("item_size", &ClusterVector<T>::item_size)
|
.def("item_size", &ClusterVector<ClusterType>::item_size)
|
||||||
.def_property_readonly("fmt",
|
.def_property_readonly("fmt",
|
||||||
[typestr](ClusterVector<T> &self) {
|
[typestr](ClusterVector<ClusterType> &self) {
|
||||||
return fmt::format(
|
return fmt::format(
|
||||||
self.fmt_base(), self.cluster_size_x(),
|
self.fmt_base(), self.cluster_size_x(),
|
||||||
self.cluster_size_y(), typestr);
|
self.cluster_size_y(), typestr);
|
||||||
})
|
})
|
||||||
.def("sum",
|
.def("sum",
|
||||||
[](ClusterVector<T> &self) {
|
[](ClusterVector<ClusterType> &self) {
|
||||||
auto *vec = new std::vector<T>(self.sum());
|
auto *vec = new std::vector<T>(self.sum());
|
||||||
return return_vector(vec);
|
return return_vector(vec);
|
||||||
})
|
})
|
||||||
.def("sum_2x2", [](ClusterVector<T> &self) {
|
.def("sum_2x2",
|
||||||
auto *vec = new std::vector<T>(self.sum_2x2());
|
[](ClusterVector<ClusterType> &self) {
|
||||||
return return_vector(vec);
|
auto *vec = new std::vector<T>(self.sum_2x2());
|
||||||
})
|
return return_vector(vec);
|
||||||
.def_property_readonly("cluster_size_x", &ClusterVector<T>::cluster_size_x)
|
})
|
||||||
.def_property_readonly("cluster_size_y", &ClusterVector<T>::cluster_size_y)
|
.def_property_readonly("cluster_size_x",
|
||||||
.def_property_readonly("capacity", &ClusterVector<T>::capacity)
|
&ClusterVector<ClusterType>::cluster_size_x)
|
||||||
.def_property("frame_number", &ClusterVector<T>::frame_number,
|
.def_property_readonly("cluster_size_y",
|
||||||
&ClusterVector<T>::set_frame_number)
|
&ClusterVector<ClusterType>::cluster_size_y)
|
||||||
.def_buffer([typestr](ClusterVector<T> &self) -> py::buffer_info {
|
.def_property_readonly("capacity",
|
||||||
return py::buffer_info(
|
&ClusterVector<ClusterType>::capacity)
|
||||||
self.data(), /* Pointer to buffer */
|
.def_property("frame_number", &ClusterVector<ClusterType>::frame_number,
|
||||||
self.item_size(), /* Size of one scalar */
|
&ClusterVector<ClusterType>::set_frame_number)
|
||||||
fmt::format(self.fmt_base(), self.cluster_size_x(),
|
.def_buffer(
|
||||||
self.cluster_size_y(),
|
[typestr](ClusterVector<ClusterType> &self) -> py::buffer_info {
|
||||||
typestr), /* Format descriptor */
|
return py::buffer_info(
|
||||||
1, /* Number of dimensions */
|
self.data(), /* Pointer to buffer */
|
||||||
{self.size()}, /* Buffer dimensions */
|
self.item_size(), /* Size of one scalar */
|
||||||
{self.item_size()} /* Strides (in bytes) for each index */
|
fmt::format(self.fmt_base(), self.cluster_size_x(),
|
||||||
);
|
self.cluster_size_y(),
|
||||||
});
|
typestr), /* Format descriptor */
|
||||||
|
1, /* Number of dimensions */
|
||||||
|
{self.size()}, /* Buffer dimensions */
|
||||||
|
{self.item_size()} /* Strides (in bytes) for each index */
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ClusterType>
|
||||||
void define_cluster_finder_mt_bindings(py::module &m) {
|
void define_cluster_finder_mt_bindings(py::module &m) {
|
||||||
py::class_<ClusterFinderMT<uint16_t, pd_type>>(m, "ClusterFinderMT")
|
py::class_<ClusterFinderMT<ClusterType, uint16_t, pd_type>>(
|
||||||
|
m, "ClusterFinderMT")
|
||||||
.def(py::init<Shape<2>, Shape<2>, pd_type, size_t, size_t>(),
|
.def(py::init<Shape<2>, Shape<2>, pd_type, size_t, size_t>(),
|
||||||
py::arg("image_size"), py::arg("cluster_size"),
|
py::arg("image_size"), py::arg("cluster_size"),
|
||||||
py::arg("n_sigma") = 5.0, py::arg("capacity") = 2048,
|
py::arg("n_sigma") = 5.0, py::arg("capacity") = 2048,
|
||||||
py::arg("n_threads") = 3)
|
py::arg("n_threads") = 3)
|
||||||
.def("push_pedestal_frame",
|
.def("push_pedestal_frame",
|
||||||
[](ClusterFinderMT<uint16_t, pd_type> &self,
|
[](ClusterFinderMT<ClusterType, uint16_t, pd_type> &self,
|
||||||
py::array_t<uint16_t> frame) {
|
py::array_t<uint16_t> frame) {
|
||||||
auto view = make_view_2d(frame);
|
auto view = make_view_2d(frame);
|
||||||
self.push_pedestal_frame(view);
|
self.push_pedestal_frame(view);
|
||||||
})
|
})
|
||||||
.def(
|
.def(
|
||||||
"find_clusters",
|
"find_clusters",
|
||||||
[](ClusterFinderMT<uint16_t, pd_type> &self,
|
[](ClusterFinderMT<ClusterType, uint16_t, pd_type> &self,
|
||||||
py::array_t<uint16_t> frame, uint64_t frame_number) {
|
py::array_t<uint16_t> frame, uint64_t frame_number) {
|
||||||
auto view = make_view_2d(frame);
|
auto view = make_view_2d(frame);
|
||||||
self.find_clusters(view, frame_number);
|
self.find_clusters(view, frame_number);
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
py::arg(), py::arg("frame_number") = 0)
|
py::arg(), py::arg("frame_number") = 0)
|
||||||
.def("clear_pedestal", &ClusterFinderMT<uint16_t, pd_type>::clear_pedestal)
|
.def("clear_pedestal",
|
||||||
.def("sync", &ClusterFinderMT<uint16_t, pd_type>::sync)
|
&ClusterFinderMT<ClusterType, uint16_t, pd_type>::clear_pedestal)
|
||||||
.def("stop", &ClusterFinderMT<uint16_t, pd_type>::stop)
|
.def("sync", &ClusterFinderMT<ClusterType, uint16_t, pd_type>::sync)
|
||||||
.def("start", &ClusterFinderMT<uint16_t, pd_type>::start)
|
.def("stop", &ClusterFinderMT<ClusterType, uint16_t, pd_type>::stop)
|
||||||
.def("pedestal",
|
.def("start", &ClusterFinderMT<ClusterType, uint16_t, pd_type>::start)
|
||||||
[](ClusterFinderMT<uint16_t, pd_type> &self, size_t thread_index) {
|
.def(
|
||||||
auto pd = new NDArray<pd_type, 2>{};
|
"pedestal",
|
||||||
*pd = self.pedestal(thread_index);
|
[](ClusterFinderMT<ClusterType, uint16_t, pd_type> &self,
|
||||||
return return_image_data(pd);
|
size_t thread_index) {
|
||||||
},py::arg("thread_index") = 0)
|
auto pd = new NDArray<pd_type, 2>{};
|
||||||
.def("noise",
|
*pd = self.pedestal(thread_index);
|
||||||
[](ClusterFinderMT<uint16_t, pd_type> &self, size_t thread_index) {
|
return return_image_data(pd);
|
||||||
auto arr = new NDArray<pd_type, 2>{};
|
},
|
||||||
*arr = self.noise(thread_index);
|
py::arg("thread_index") = 0)
|
||||||
return return_image_data(arr);
|
.def(
|
||||||
},py::arg("thread_index") = 0);
|
"noise",
|
||||||
|
[](ClusterFinderMT<ClusterType, uint16_t, pd_type> &self,
|
||||||
|
size_t thread_index) {
|
||||||
|
auto arr = new NDArray<pd_type, 2>{};
|
||||||
|
*arr = self.noise(thread_index);
|
||||||
|
return return_image_data(arr);
|
||||||
|
},
|
||||||
|
py::arg("thread_index") = 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ClusterType>
|
||||||
void define_cluster_collector_bindings(py::module &m) {
|
void define_cluster_collector_bindings(py::module &m) {
|
||||||
py::class_<ClusterCollector>(m, "ClusterCollector")
|
py::class_<ClusterCollector<ClusterType>>(m, "ClusterCollector")
|
||||||
.def(py::init<ClusterFinderMT<uint16_t, double, int32_t> *>())
|
.def(py::init<ClusterFinderMT<ClusterType, uint16_t, double> *>())
|
||||||
.def("stop", &ClusterCollector::stop)
|
.def("stop", &ClusterCollector<ClusterType>::stop)
|
||||||
.def(
|
.def(
|
||||||
"steal_clusters",
|
"steal_clusters",
|
||||||
[](ClusterCollector &self) {
|
[](ClusterCollector<ClusterType> &self) {
|
||||||
auto v =
|
auto v = new std::vector<ClusterVector<ClusterType>>(
|
||||||
new std::vector<ClusterVector<int>>(self.steal_clusters());
|
self.steal_clusters());
|
||||||
return v;
|
return v;
|
||||||
},
|
},
|
||||||
py::return_value_policy::take_ownership);
|
py::return_value_policy::take_ownership);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ClusterType>
|
||||||
void define_cluster_file_sink_bindings(py::module &m) {
|
void define_cluster_file_sink_bindings(py::module &m) {
|
||||||
py::class_<ClusterFileSink>(m, "ClusterFileSink")
|
py::class_<ClusterFileSink<ClusterType>>(m, "ClusterFileSink")
|
||||||
.def(py::init<ClusterFinderMT<uint16_t, double, int32_t> *,
|
.def(py::init<ClusterFinderMT<ClusterType, uint16_t, double> *,
|
||||||
const std::filesystem::path &>())
|
const std::filesystem::path &>())
|
||||||
.def("stop", &ClusterFileSink::stop);
|
.def("stop", &ClusterFileSink<ClusterType>::stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ClusterType>
|
||||||
void define_cluster_finder_bindings(py::module &m) {
|
void define_cluster_finder_bindings(py::module &m) {
|
||||||
py::class_<ClusterFinder<uint16_t, pd_type>>(m, "ClusterFinder")
|
py::class_<ClusterFinder<ClusterType, uint16_t, pd_type>>(m,
|
||||||
|
"ClusterFinder")
|
||||||
.def(py::init<Shape<2>, Shape<2>, pd_type, size_t>(),
|
.def(py::init<Shape<2>, Shape<2>, pd_type, size_t>(),
|
||||||
py::arg("image_size"), py::arg("cluster_size"),
|
py::arg("image_size"), py::arg("cluster_size"),
|
||||||
py::arg("n_sigma") = 5.0, py::arg("capacity") = 1'000'000)
|
py::arg("n_sigma") = 5.0, py::arg("capacity") = 1'000'000)
|
||||||
.def("push_pedestal_frame",
|
.def("push_pedestal_frame",
|
||||||
[](ClusterFinder<uint16_t, pd_type> &self,
|
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self,
|
||||||
py::array_t<uint16_t> frame) {
|
py::array_t<uint16_t> frame) {
|
||||||
auto view = make_view_2d(frame);
|
auto view = make_view_2d(frame);
|
||||||
self.push_pedestal_frame(view);
|
self.push_pedestal_frame(view);
|
||||||
})
|
})
|
||||||
.def("clear_pedestal", &ClusterFinder<uint16_t, pd_type>::clear_pedestal)
|
.def("clear_pedestal",
|
||||||
.def_property_readonly("pedestal",
|
&ClusterFinder<ClusterType, uint16_t, pd_type>::clear_pedestal)
|
||||||
[](ClusterFinder<uint16_t, pd_type> &self) {
|
.def_property_readonly(
|
||||||
auto pd = new NDArray<pd_type, 2>{};
|
"pedestal",
|
||||||
*pd = self.pedestal();
|
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self) {
|
||||||
return return_image_data(pd);
|
auto pd = new NDArray<pd_type, 2>{};
|
||||||
})
|
*pd = self.pedestal();
|
||||||
.def_property_readonly("noise",
|
return return_image_data(pd);
|
||||||
[](ClusterFinder<uint16_t, pd_type> &self) {
|
})
|
||||||
auto arr = new NDArray<pd_type, 2>{};
|
.def_property_readonly(
|
||||||
*arr = self.noise();
|
"noise",
|
||||||
return return_image_data(arr);
|
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self) {
|
||||||
})
|
auto arr = new NDArray<pd_type, 2>{};
|
||||||
|
*arr = self.noise();
|
||||||
|
return return_image_data(arr);
|
||||||
|
})
|
||||||
.def(
|
.def(
|
||||||
"steal_clusters",
|
"steal_clusters",
|
||||||
[](ClusterFinder<uint16_t, pd_type> &self,
|
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self,
|
||||||
bool realloc_same_capacity) {
|
bool realloc_same_capacity) {
|
||||||
auto v = new ClusterVector<int>(
|
auto v = new ClusterVector<ClusterType>(
|
||||||
self.steal_clusters(realloc_same_capacity));
|
self.steal_clusters(realloc_same_capacity));
|
||||||
return v;
|
return v;
|
||||||
},
|
},
|
||||||
py::arg("realloc_same_capacity") = false)
|
py::arg("realloc_same_capacity") = false)
|
||||||
.def(
|
.def(
|
||||||
"find_clusters",
|
"find_clusters",
|
||||||
[](ClusterFinder<uint16_t, pd_type> &self,
|
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self,
|
||||||
py::array_t<uint16_t> frame, uint64_t frame_number) {
|
py::array_t<uint16_t> frame, uint64_t frame_number) {
|
||||||
auto view = make_view_2d(frame);
|
auto view = make_view_2d(frame);
|
||||||
self.find_clusters(view, frame_number);
|
self.find_clusters(view, frame_number);
|
||||||
@ -167,7 +194,7 @@ void define_cluster_finder_bindings(py::module &m) {
|
|||||||
py::arg(), py::arg("frame_number") = 0);
|
py::arg(), py::arg("frame_number") = 0);
|
||||||
|
|
||||||
m.def("hitmap",
|
m.def("hitmap",
|
||||||
[](std::array<size_t, 2> image_size, ClusterVector<int32_t> &cv) {
|
[](std::array<size_t, 2> image_size, ClusterVector<ClusterType> &cv) {
|
||||||
py::array_t<int32_t> hitmap(image_size);
|
py::array_t<int32_t> hitmap(image_size);
|
||||||
auto r = hitmap.mutable_unchecked<2>();
|
auto r = hitmap.mutable_unchecked<2>();
|
||||||
|
|
||||||
|
@ -10,69 +10,86 @@
|
|||||||
#include <pybind11/stl/filesystem.h>
|
#include <pybind11/stl/filesystem.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//Disable warnings for unused parameters, as we ignore some
|
// Disable warnings for unused parameters, as we ignore some
|
||||||
//in the __exit__ method
|
// in the __exit__ method
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||||
|
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
using namespace ::aare;
|
using namespace ::aare;
|
||||||
|
|
||||||
|
template <typename ClusterType>
|
||||||
void define_cluster_file_io_bindings(py::module &m) {
|
void define_cluster_file_io_bindings(py::module &m) {
|
||||||
PYBIND11_NUMPY_DTYPE(Cluster3x3, x, y, data);
|
PYBIND11_NUMPY_DTYPE(Cluster3x3, x, y, data);
|
||||||
|
|
||||||
py::class_<ClusterFile>(m, "ClusterFile")
|
py::class_<ClusterFile<ClusterType>>(m, "ClusterFile")
|
||||||
.def(py::init<const std::filesystem::path &, size_t,
|
.def(py::init<const std::filesystem::path &, size_t,
|
||||||
const std::string &>(),
|
const std::string &>(),
|
||||||
py::arg(), py::arg("chunk_size") = 1000, py::arg("mode") = "r")
|
py::arg(), py::arg("chunk_size") = 1000, py::arg("mode") = "r")
|
||||||
.def("read_clusters",
|
.def(
|
||||||
[](ClusterFile &self, size_t n_clusters) {
|
"read_clusters",
|
||||||
auto v = new ClusterVector<int32_t>(self.read_clusters(n_clusters));
|
[](ClusterFile<ClusterType> &self, size_t n_clusters) {
|
||||||
|
auto v = new ClusterVector<ClusterType>(
|
||||||
|
self.read_clusters(n_clusters));
|
||||||
return v;
|
return v;
|
||||||
},py::return_value_policy::take_ownership)
|
},
|
||||||
.def("read_clusters",
|
py::return_value_policy::take_ownership)
|
||||||
[](ClusterFile &self, size_t n_clusters, ROI roi) {
|
.def(
|
||||||
auto v = new ClusterVector<int32_t>(self.read_clusters(n_clusters, roi));
|
"read_clusters",
|
||||||
return v;
|
[](ClusterFile<ClusterType> &self, size_t n_clusters, ROI roi) {
|
||||||
},py::return_value_policy::take_ownership)
|
auto v = new ClusterVector<ClusterType>(
|
||||||
|
self.read_clusters(n_clusters, roi));
|
||||||
|
return v;
|
||||||
|
},
|
||||||
|
py::return_value_policy::take_ownership)
|
||||||
.def("read_frame",
|
.def("read_frame",
|
||||||
[](ClusterFile &self) {
|
[](ClusterFile<ClusterType> &self) {
|
||||||
auto v = new ClusterVector<int32_t>(self.read_frame());
|
auto v = new ClusterVector<ClusterType>(self.read_frame());
|
||||||
return v;
|
return v;
|
||||||
})
|
})
|
||||||
.def("set_roi", &ClusterFile::set_roi)
|
.def("set_roi", &ClusterFile<ClusterType>::set_roi)
|
||||||
.def("set_noise_map", [](ClusterFile &self, py::array_t<int32_t> noise_map) {
|
.def(
|
||||||
auto view = make_view_2d(noise_map);
|
"set_noise_map",
|
||||||
self.set_noise_map(view);
|
[](ClusterFile<ClusterType> &self, py::array_t<int32_t> noise_map) {
|
||||||
})
|
auto view = make_view_2d(noise_map);
|
||||||
.def("set_gain_map", [](ClusterFile &self, py::array_t<double> gain_map) {
|
self.set_noise_map(view);
|
||||||
auto view = make_view_2d(gain_map);
|
})
|
||||||
self.set_gain_map(view);
|
|
||||||
})
|
.def("set_gain_map",
|
||||||
.def("close", &ClusterFile::close)
|
[](ClusterFile<ClusterType> &self, py::array_t<double> gain_map) {
|
||||||
.def("write_frame", &ClusterFile::write_frame)
|
auto view = make_view_2d(gain_map);
|
||||||
.def("__enter__", [](ClusterFile &self) { return &self; })
|
self.set_gain_map(view);
|
||||||
|
})
|
||||||
|
|
||||||
|
// void set_gain_map(const GainMap &gain_map); //TODO do i need a
|
||||||
|
// gainmap constructor?
|
||||||
|
|
||||||
|
.def("close", &ClusterFile<ClusterType>::close)
|
||||||
|
.def("write_frame", &ClusterFile<ClusterType>::write_frame)
|
||||||
|
.def("__enter__", [](ClusterFile<ClusterType> &self) { return &self; })
|
||||||
.def("__exit__",
|
.def("__exit__",
|
||||||
[](ClusterFile &self,
|
[](ClusterFile<ClusterType> &self,
|
||||||
const std::optional<pybind11::type> &exc_type,
|
const std::optional<pybind11::type> &exc_type,
|
||||||
const std::optional<pybind11::object> &exc_value,
|
const std::optional<pybind11::object> &exc_value,
|
||||||
const std::optional<pybind11::object> &traceback) {
|
const std::optional<pybind11::object> &traceback) {
|
||||||
self.close();
|
self.close();
|
||||||
})
|
})
|
||||||
.def("__iter__", [](ClusterFile &self) { return &self; })
|
.def("__iter__", [](ClusterFile<ClusterType> &self) { return &self; })
|
||||||
.def("__next__", [](ClusterFile &self) {
|
.def("__next__", [](ClusterFile<ClusterType> &self) {
|
||||||
auto v = new ClusterVector<int32_t>(self.read_clusters(self.chunk_size()));
|
auto v = new ClusterVector<ClusterType>(
|
||||||
|
self.read_clusters(self.chunk_size()));
|
||||||
if (v->size() == 0) {
|
if (v->size() == 0) {
|
||||||
throw py::stop_iteration();
|
throw py::stop_iteration();
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
});
|
});
|
||||||
|
|
||||||
m.def("calculate_eta2", []( aare::ClusterVector<int32_t> &clusters) {
|
/*
|
||||||
auto eta2 = new NDArray<double, 2>(calculate_eta2(clusters));
|
m.def("calculate_eta2", []( aare::ClusterVector<ClusterType> &clusters) {
|
||||||
return return_image_data(eta2);
|
auto eta2 = new NDArray<double, 2>(calculate_eta2(clusters));
|
||||||
});
|
return return_image_data(eta2);
|
||||||
|
});
|
||||||
|
*/ //add in different file
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
@ -8,31 +8,40 @@
|
|||||||
#include <pybind11/stl.h>
|
#include <pybind11/stl.h>
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
|
|
||||||
void define_interpolation_bindings(py::module &m) {
|
void define_interpolation_bindings(py::module &m) {
|
||||||
|
|
||||||
PYBIND11_NUMPY_DTYPE(aare::Photon, x,y,energy);
|
PYBIND11_NUMPY_DTYPE(aare::Photon, x, y, energy);
|
||||||
|
|
||||||
py::class_<aare::Interpolator>(m, "Interpolator")
|
py::class_<aare::Interpolator>(m, "Interpolator")
|
||||||
.def(py::init([](py::array_t<double, py::array::c_style | py::array::forcecast> etacube, py::array_t<double> xbins,
|
.def(py::init(
|
||||||
py::array_t<double> ybins, py::array_t<double> ebins) {
|
[](py::array_t<double, py::array::c_style | py::array::forcecast>
|
||||||
return Interpolator(make_view_3d(etacube), make_view_1d(xbins),
|
etacube,
|
||||||
make_view_1d(ybins), make_view_1d(ebins));
|
py::array_t<double> xbins, py::array_t<double> ybins,
|
||||||
}))
|
py::array_t<double> ebins) {
|
||||||
.def("get_ietax", [](Interpolator& self){
|
return Interpolator(make_view_3d(etacube), make_view_1d(xbins),
|
||||||
auto*ptr = new NDArray<double,3>{};
|
make_view_1d(ybins), make_view_1d(ebins));
|
||||||
*ptr = self.get_ietax();
|
}))
|
||||||
return return_image_data(ptr);
|
.def("get_ietax",
|
||||||
})
|
[](Interpolator &self) {
|
||||||
.def("get_ietay", [](Interpolator& self){
|
auto *ptr = new NDArray<double, 3>{};
|
||||||
auto*ptr = new NDArray<double,3>{};
|
*ptr = self.get_ietax();
|
||||||
*ptr = self.get_ietay();
|
return return_image_data(ptr);
|
||||||
return return_image_data(ptr);
|
})
|
||||||
})
|
.def("get_ietay",
|
||||||
.def("interpolate", [](Interpolator& self, const ClusterVector<int32_t>& clusters){
|
[](Interpolator &self) {
|
||||||
auto photons = self.interpolate(clusters);
|
auto *ptr = new NDArray<double, 3>{};
|
||||||
auto* ptr = new std::vector<Photon>{photons};
|
*ptr = self.get_ietay();
|
||||||
return return_vector(ptr);
|
return return_image_data(ptr);
|
||||||
});
|
})
|
||||||
|
|
||||||
|
// TODO take care of clustertype template
|
||||||
|
.def("interpolate",
|
||||||
|
[](Interpolator &self, const ClusterVector<auto> &clusters) {
|
||||||
|
auto photons = self.interpolate<ClusterType>(clusters);
|
||||||
|
auto *ptr = new std::vector<Photon>{photons};
|
||||||
|
return return_vector(ptr);
|
||||||
|
});
|
||||||
|
|
||||||
// TODO! Evaluate without converting to double
|
// TODO! Evaluate without converting to double
|
||||||
m.def(
|
m.def(
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
//Files with bindings to the different classes
|
// Files with bindings to the different classes
|
||||||
#include "file.hpp"
|
|
||||||
#include "raw_file.hpp"
|
|
||||||
#include "ctb_raw_file.hpp"
|
|
||||||
#include "raw_master_file.hpp"
|
|
||||||
#include "var_cluster.hpp"
|
|
||||||
#include "pixel_map.hpp"
|
|
||||||
#include "pedestal.hpp"
|
|
||||||
#include "cluster.hpp"
|
#include "cluster.hpp"
|
||||||
#include "cluster_file.hpp"
|
#include "cluster_file.hpp"
|
||||||
|
#include "ctb_raw_file.hpp"
|
||||||
|
#include "file.hpp"
|
||||||
#include "fit.hpp"
|
#include "fit.hpp"
|
||||||
#include "interpolation.hpp"
|
#include "interpolation.hpp"
|
||||||
|
#include "pedestal.hpp"
|
||||||
|
#include "pixel_map.hpp"
|
||||||
|
#include "raw_file.hpp"
|
||||||
|
#include "raw_master_file.hpp"
|
||||||
|
#include "var_cluster.hpp"
|
||||||
|
|
||||||
//Pybind stuff
|
// Pybind stuff
|
||||||
#include <pybind11/pybind11.h>
|
#include <pybind11/pybind11.h>
|
||||||
#include <pybind11/stl.h>
|
#include <pybind11/stl.h>
|
||||||
|
|
||||||
@ -33,5 +33,4 @@ PYBIND11_MODULE(_aare, m) {
|
|||||||
define_cluster_file_sink_bindings(m);
|
define_cluster_file_sink_bindings(m);
|
||||||
define_fit_bindings(m);
|
define_fit_bindings(m);
|
||||||
define_interpolation_bindings(m);
|
define_interpolation_bindings(m);
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user