mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-11 06:47:14 +02:00
refactored python files
This commit is contained in:
@ -21,9 +21,8 @@ using namespace aare;
|
||||
template <typename ClusterType>
|
||||
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);
|
||||
|
||||
py::class_<ClusterVector<ClusterType>>(m, class_name.c_str(),
|
||||
py::buffer_protocol())
|
||||
.def(py::init<int, int>(), py::arg("cluster_size_x") = 3,
|
||||
@ -41,6 +40,7 @@ void define_cluster_vector(py::module &m, const std::string &typestr) {
|
||||
self.fmt_base(), self.cluster_size_x(),
|
||||
self.cluster_size_y(), typestr);
|
||||
})
|
||||
/*
|
||||
.def("sum",
|
||||
[](ClusterVector<ClusterType> &self) {
|
||||
auto *vec = new std::vector<T>(self.sum());
|
||||
@ -51,6 +51,7 @@ void define_cluster_vector(py::module &m, const std::string &typestr) {
|
||||
auto *vec = new std::vector<T>(self.sum_2x2());
|
||||
return return_vector(vec);
|
||||
})
|
||||
*/
|
||||
.def_property_readonly("cluster_size_x",
|
||||
&ClusterVector<ClusterType>::cluster_size_x)
|
||||
.def_property_readonly("cluster_size_y",
|
||||
@ -75,13 +76,16 @@ void define_cluster_vector(py::module &m, const std::string &typestr) {
|
||||
}
|
||||
|
||||
template <typename ClusterType>
|
||||
void define_cluster_finder_mt_bindings(py::module &m) {
|
||||
void define_cluster_finder_mt_bindings(py::module &m,
|
||||
const std::string &typestr) {
|
||||
|
||||
auto class_name = fmt::format("ClusterFinderMT_{}", typestr);
|
||||
|
||||
py::class_<ClusterFinderMT<ClusterType, uint16_t, pd_type>>(
|
||||
m, "ClusterFinderMT")
|
||||
.def(py::init<Shape<2>, Shape<2>, pd_type, size_t, size_t>(),
|
||||
py::arg("image_size"), py::arg("cluster_size"),
|
||||
py::arg("n_sigma") = 5.0, py::arg("capacity") = 2048,
|
||||
py::arg("n_threads") = 3)
|
||||
m, class_name.c_str())
|
||||
.def(py::init<Shape<2>, pd_type, size_t, size_t>(),
|
||||
py::arg("image_size"), py::arg("n_sigma") = 5.0,
|
||||
py::arg("capacity") = 2048, py::arg("n_threads") = 3)
|
||||
.def("push_pedestal_frame",
|
||||
[](ClusterFinderMT<ClusterType, uint16_t, pd_type> &self,
|
||||
py::array_t<uint16_t> frame) {
|
||||
@ -123,8 +127,12 @@ void define_cluster_finder_mt_bindings(py::module &m) {
|
||||
}
|
||||
|
||||
template <typename ClusterType>
|
||||
void define_cluster_collector_bindings(py::module &m) {
|
||||
py::class_<ClusterCollector<ClusterType>>(m, "ClusterCollector")
|
||||
void define_cluster_collector_bindings(py::module &m,
|
||||
const std::string &typestr) {
|
||||
|
||||
auto class_name = fmt::format("ClusterCollector_{}", typestr);
|
||||
|
||||
py::class_<ClusterCollector<ClusterType>>(m, class_name.c_str())
|
||||
.def(py::init<ClusterFinderMT<ClusterType, uint16_t, double> *>())
|
||||
.def("stop", &ClusterCollector<ClusterType>::stop)
|
||||
.def(
|
||||
@ -138,19 +146,25 @@ void define_cluster_collector_bindings(py::module &m) {
|
||||
}
|
||||
|
||||
template <typename ClusterType>
|
||||
void define_cluster_file_sink_bindings(py::module &m) {
|
||||
py::class_<ClusterFileSink<ClusterType>>(m, "ClusterFileSink")
|
||||
void define_cluster_file_sink_bindings(py::module &m,
|
||||
const std::string &typestr) {
|
||||
|
||||
auto class_name = fmt::format("ClusterFileSink_{}", typestr);
|
||||
|
||||
py::class_<ClusterFileSink<ClusterType>>(m, class_name.c_str())
|
||||
.def(py::init<ClusterFinderMT<ClusterType, uint16_t, double> *,
|
||||
const std::filesystem::path &>())
|
||||
.def("stop", &ClusterFileSink<ClusterType>::stop);
|
||||
}
|
||||
|
||||
template <typename ClusterType>
|
||||
void define_cluster_finder_bindings(py::module &m) {
|
||||
py::class_<ClusterFinder<ClusterType, uint16_t, pd_type>>(m,
|
||||
"ClusterFinder")
|
||||
.def(py::init<Shape<2>, Shape<2>, pd_type, size_t>(),
|
||||
py::arg("image_size"), py::arg("cluster_size"),
|
||||
void define_cluster_finder_bindings(py::module &m, const std::string &typestr) {
|
||||
|
||||
auto class_name = fmt::format("ClusterFinder_{}", typestr);
|
||||
|
||||
py::class_<ClusterFinder<ClusterType, uint16_t, pd_type>>(
|
||||
m, class_name.c_str())
|
||||
.def(py::init<Shape<2>, pd_type, size_t>(), py::arg("image_size"),
|
||||
py::arg("n_sigma") = 5.0, py::arg("capacity") = 1'000'000)
|
||||
.def("push_pedestal_frame",
|
||||
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self,
|
||||
@ -213,9 +227,6 @@ void define_cluster_finder_bindings(py::module &m) {
|
||||
}
|
||||
return hitmap;
|
||||
});
|
||||
define_cluster_vector<int>(m, "i");
|
||||
define_cluster_vector<double>(m, "d");
|
||||
define_cluster_vector<float>(m, "f");
|
||||
|
||||
py::class_<DynamicCluster>(m, "DynamicCluster", py::buffer_protocol())
|
||||
.def(py::init<int, int, Dtype>())
|
||||
@ -233,4 +244,4 @@ void define_cluster_finder_bindings(py::module &m) {
|
||||
return "<DynamicCluster: x: " + std::to_string(a.x) +
|
||||
", y: " + std::to_string(a.y) + ">";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "aare/CalculateEta.hpp"
|
||||
#include "aare/ClusterFile.hpp"
|
||||
#include "aare/defs.hpp"
|
||||
|
||||
@ -19,10 +20,14 @@ namespace py = pybind11;
|
||||
using namespace ::aare;
|
||||
|
||||
template <typename ClusterType>
|
||||
void define_cluster_file_io_bindings(py::module &m) {
|
||||
PYBIND11_NUMPY_DTYPE(Cluster3x3, x, y, data);
|
||||
void define_cluster_file_io_bindings(py::module &m,
|
||||
const std::string &typestr) {
|
||||
// PYBIND11_NUMPY_DTYPE(Cluster<int, 3, 3>, x, y,
|
||||
// data); // is this used - maybe use as cluster type
|
||||
|
||||
py::class_<ClusterFile<ClusterType>>(m, "ClusterFile")
|
||||
auto class_name = fmt::format("ClusterFile_{}", typestr);
|
||||
|
||||
py::class_<ClusterFile<ClusterType>>(m, class_name.c_str())
|
||||
.def(py::init<const std::filesystem::path &, size_t,
|
||||
const std::string &>(),
|
||||
py::arg(), py::arg("chunk_size") = 1000, py::arg("mode") = "r")
|
||||
@ -84,12 +89,11 @@ void define_cluster_file_io_bindings(py::module &m) {
|
||||
return v;
|
||||
});
|
||||
|
||||
/*
|
||||
m.def("calculate_eta2", []( aare::ClusterVector<ClusterType> &clusters) {
|
||||
auto eta2 = new NDArray<double, 2>(calculate_eta2(clusters));
|
||||
return return_image_data(eta2);
|
||||
});
|
||||
*/ //add in different file
|
||||
m.def("calculate_eta2",
|
||||
[](const aare::ClusterVector<ClusterType> &clusters) {
|
||||
auto eta2 = new NDArray<double, 2>(calculate_eta2(clusters));
|
||||
return return_image_data(eta2);
|
||||
});
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
@ -9,39 +9,53 @@
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
template <typename ClusterType>
|
||||
void register_interpolate(py::class_<aare::Interpolator> &interpolator) {
|
||||
std::string name =
|
||||
fmt::format("interpolate_{}", typeid(ClusterType).name());
|
||||
|
||||
interpolator.def(name.c_str(),
|
||||
[](aare::Interpolator &self,
|
||||
const ClusterVector<ClusterType> &clusters) {
|
||||
auto photons = self.interpolate<ClusterType>(clusters);
|
||||
auto *ptr = new std::vector<Photon>{photons};
|
||||
return return_vector(ptr);
|
||||
});
|
||||
}
|
||||
|
||||
void define_interpolation_bindings(py::module &m) {
|
||||
|
||||
PYBIND11_NUMPY_DTYPE(aare::Photon, x, y, energy);
|
||||
|
||||
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, py::array_t<double> ybins,
|
||||
py::array_t<double> ebins) {
|
||||
auto 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,
|
||||
py::array_t<double> ybins,
|
||||
py::array_t<double> ebins) {
|
||||
return Interpolator(make_view_3d(etacube), make_view_1d(xbins),
|
||||
make_view_1d(ybins), make_view_1d(ebins));
|
||||
}))
|
||||
.def("get_ietax",
|
||||
[](Interpolator &self) {
|
||||
auto *ptr = new NDArray<double, 3>{};
|
||||
*ptr = self.get_ietax();
|
||||
return return_image_data(ptr);
|
||||
})
|
||||
.def("get_ietay",
|
||||
[](Interpolator &self) {
|
||||
auto *ptr = new NDArray<double, 3>{};
|
||||
*ptr = self.get_ietay();
|
||||
return return_image_data(ptr);
|
||||
})
|
||||
.def("get_ietax",
|
||||
[](Interpolator &self) {
|
||||
auto *ptr = new NDArray<double, 3>{};
|
||||
*ptr = self.get_ietax();
|
||||
return return_image_data(ptr);
|
||||
})
|
||||
.def("get_ietay", [](Interpolator &self) {
|
||||
auto *ptr = new NDArray<double, 3>{};
|
||||
*ptr = self.get_ietay();
|
||||
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);
|
||||
});
|
||||
register_interpolate<Cluster<int, 3, 3>>(interpolator);
|
||||
register_interpolate<Cluster<float, 3, 3>>(interpolator);
|
||||
register_interpolate<Cluster<double, 3, 3>>(interpolator);
|
||||
register_interpolate<Cluster<int, 2, 2>>(interpolator);
|
||||
register_interpolate<Cluster<float, 2, 2>>(interpolator);
|
||||
register_interpolate<Cluster<double, 2, 2>>(interpolator);
|
||||
|
||||
// TODO! Evaluate without converting to double
|
||||
m.def(
|
||||
|
@ -26,11 +26,48 @@ PYBIND11_MODULE(_aare, m) {
|
||||
define_pixel_map_bindings(m);
|
||||
define_pedestal_bindings<double>(m, "Pedestal_d");
|
||||
define_pedestal_bindings<float>(m, "Pedestal_f");
|
||||
define_cluster_finder_bindings(m);
|
||||
define_cluster_finder_mt_bindings(m);
|
||||
define_cluster_file_io_bindings(m);
|
||||
define_cluster_collector_bindings(m);
|
||||
define_cluster_file_sink_bindings(m);
|
||||
define_fit_bindings(m);
|
||||
define_interpolation_bindings(m);
|
||||
}
|
||||
|
||||
define_cluster_file_io_bindings<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
||||
define_cluster_file_io_bindings<Cluster<double, 3, 3>>(m, "Cluster3x3d");
|
||||
define_cluster_file_io_bindings<Cluster<float, 3, 3>>(m, "Cluster3x3f");
|
||||
define_cluster_file_io_bindings<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
||||
define_cluster_file_io_bindings<Cluster<float, 2, 2>>(m, "Cluster2x2f");
|
||||
define_cluster_file_io_bindings<Cluster<double, 2, 2>>(m, "Cluster2x2d");
|
||||
|
||||
define_cluster_vector<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
||||
define_cluster_vector<Cluster<double, 3, 3>>(m, "Cluster3x3d");
|
||||
define_cluster_vector<Cluster<float, 3, 3>>(m, "Cluster3x3f");
|
||||
define_cluster_vector<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
||||
define_cluster_vector<Cluster<double, 2, 2>>(m, "Cluster2x2d");
|
||||
define_cluster_vector<Cluster<float, 2, 2>>(m, "Cluster2x2f");
|
||||
|
||||
define_cluster_finder_bindings<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
||||
define_cluster_finder_bindings<Cluster<double, 3, 3>>(m, "Cluster3x3d");
|
||||
define_cluster_finder_bindings<Cluster<float, 3, 3>>(m, "Cluster3x3f");
|
||||
define_cluster_finder_bindings<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
||||
define_cluster_finder_bindings<Cluster<double, 2, 2>>(m, "Cluster2x2d");
|
||||
define_cluster_finder_bindings<Cluster<float, 2, 2>>(m, "Cluster2x2f");
|
||||
|
||||
define_cluster_finder_mt_bindings<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
||||
define_cluster_finder_mt_bindings<Cluster<double, 3, 3>>(m, "Cluster3x3d");
|
||||
define_cluster_finder_mt_bindings<Cluster<float, 3, 3>>(m, "Cluster3x3f");
|
||||
define_cluster_finder_mt_bindings<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
||||
define_cluster_finder_mt_bindings<Cluster<double, 2, 2>>(m, "Cluster2x2d");
|
||||
define_cluster_finder_mt_bindings<Cluster<float, 2, 2>>(m, "Cluster2x2f");
|
||||
|
||||
define_cluster_file_sink_bindings<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
||||
define_cluster_file_sink_bindings<Cluster<double, 3, 3>>(m, "Cluster3x3d");
|
||||
define_cluster_file_sink_bindings<Cluster<float, 3, 3>>(m, "Cluster3x3f");
|
||||
define_cluster_file_sink_bindings<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
||||
define_cluster_file_sink_bindings<Cluster<double, 2, 2>>(m, "Cluster2x2d");
|
||||
define_cluster_file_sink_bindings<Cluster<float, 2, 2>>(m, "Cluster2x2f");
|
||||
|
||||
define_cluster_collector_bindings<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
||||
define_cluster_collector_bindings<Cluster<double, 3, 3>>(m, "Cluster3x3f");
|
||||
define_cluster_collector_bindings<Cluster<float, 3, 3>>(m, "Cluster3x3d");
|
||||
define_cluster_collector_bindings<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
||||
define_cluster_collector_bindings<Cluster<double, 2, 2>>(m, "Cluster2x2f");
|
||||
define_cluster_collector_bindings<Cluster<float, 2, 2>>(m, "Cluster2x2d");
|
||||
}
|
||||
|
Reference in New Issue
Block a user