mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-06 12:50:40 +02:00
changed template arguments added tests
This commit is contained in:
parent
20d1d02fda
commit
a13affa4d3
@ -23,10 +23,8 @@ template <typename Type, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
|
|||||||
void define_cluster(py::module &m, const std::string &typestr) {
|
void define_cluster(py::module &m, const std::string &typestr) {
|
||||||
auto class_name = fmt::format("Cluster{}", typestr);
|
auto class_name = fmt::format("Cluster{}", typestr);
|
||||||
|
|
||||||
using ClusterType =
|
|
||||||
Cluster<Type, ClusterSizeX, ClusterSizeY, CoordType, void>;
|
|
||||||
py::class_<Cluster<Type, ClusterSizeX, ClusterSizeY, CoordType, void>>(
|
py::class_<Cluster<Type, ClusterSizeX, ClusterSizeY, CoordType, void>>(
|
||||||
m, class_name.c_str())
|
m, class_name.c_str(), py::buffer_protocol())
|
||||||
|
|
||||||
.def(py::init([](uint8_t x, uint8_t y, py::array_t<Type> data) {
|
.def(py::init([](uint8_t x, uint8_t y, py::array_t<Type> data) {
|
||||||
py::buffer_info buf_info = data.request();
|
py::buffer_info buf_info = data.request();
|
||||||
@ -37,83 +35,57 @@ void define_cluster(py::module &m, const std::string &typestr) {
|
|||||||
std::copy(ptr, ptr + ClusterSizeX * ClusterSizeY,
|
std::copy(ptr, ptr + ClusterSizeX * ClusterSizeY,
|
||||||
cluster.data); // Copy array contents
|
cluster.data); // Copy array contents
|
||||||
return cluster;
|
return cluster;
|
||||||
}))
|
}));
|
||||||
|
|
||||||
//.def(py::init<>())
|
/*
|
||||||
.def_readwrite("x", &ClusterType::x)
|
.def_property(
|
||||||
.def_readwrite("y", &ClusterType::y)
|
"data",
|
||||||
.def_property(
|
[](ClusterType &c) -> py::array {
|
||||||
"data",
|
return py::array(py::buffer_info(
|
||||||
[](ClusterType &c) -> py::array {
|
c.data, sizeof(Type),
|
||||||
return py::array(py::buffer_info(
|
py::format_descriptor<Type>::format(), // Type
|
||||||
c.data, sizeof(Type),
|
// format
|
||||||
py::format_descriptor<Type>::format(), // Type
|
1, // Number of dimensions
|
||||||
// format
|
{static_cast<ssize_t>(ClusterSizeX *
|
||||||
1, // Number of dimensions
|
ClusterSizeY)}, // Shape (flattened)
|
||||||
{static_cast<ssize_t>(ClusterSizeX *
|
{sizeof(Type)} // Stride (step size between elements)
|
||||||
ClusterSizeY)}, // Shape (flattened)
|
));
|
||||||
{sizeof(Type)} // Stride (step size between elements)
|
},
|
||||||
));
|
[](ClusterType &c, py::array_t<Type> arr) {
|
||||||
},
|
py::buffer_info buf_info = arr.request();
|
||||||
[](ClusterType &c, py::array_t<Type> arr) {
|
Type *ptr = static_cast<Type *>(buf_info.ptr);
|
||||||
py::buffer_info buf_info = arr.request();
|
std::copy(ptr, ptr + ClusterSizeX * ClusterSizeY,
|
||||||
Type *ptr = static_cast<Type *>(buf_info.ptr);
|
c.data); // TODO dont iterate over centers!!!
|
||||||
std::copy(ptr, ptr + ClusterSizeX * ClusterSizeY,
|
|
||||||
c.data); // TODO dont iterate over centers!!!
|
});
|
||||||
});
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
|
template <typename Type, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
|
||||||
typename CoordType = uint16_t>
|
typename CoordType = uint16_t>
|
||||||
void define_cluster_vector(py::module &m, const std::string &typestr) {
|
void define_cluster_vector(py::module &m, const std::string &typestr) {
|
||||||
using ClusterType =
|
using ClusterType =
|
||||||
Cluster<Type, ClusterSizeX, ClusterSizeY, uint16_t, void>;
|
Cluster<Type, ClusterSizeX, ClusterSizeY, CoordType, void>;
|
||||||
auto class_name = fmt::format("ClusterVector_{}", typestr);
|
auto class_name = fmt::format("ClusterVector_{}", typestr);
|
||||||
|
|
||||||
py::class_<ClusterVector<ClusterType>>(m, class_name.c_str(),
|
py::class_<ClusterVector<
|
||||||
py::buffer_protocol())
|
Cluster<Type, ClusterSizeX, ClusterSizeY, CoordType, void>, void>>(
|
||||||
|
m, class_name.c_str(),
|
||||||
|
py::buffer_protocol())
|
||||||
|
|
||||||
.def(py::init()) // TODO change!!!
|
.def(py::init()) // TODO change!!!
|
||||||
/*
|
|
||||||
.def("push_back",
|
|
||||||
[](ClusterVector<ClusterType> &self, ClusterType &cl) {
|
|
||||||
// auto view = make_view_2d(data);
|
|
||||||
self.push_back(cl);
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
.def(
|
|
||||||
"push_back",
|
|
||||||
[](ClusterVector<ClusterType> &self, py::object obj) {
|
|
||||||
ClusterType &cl = py::cast<ClusterType &>(obj);
|
|
||||||
self.push_back(cl);
|
|
||||||
},
|
|
||||||
py::arg("cluster"))
|
|
||||||
*/
|
|
||||||
|
|
||||||
.def("push_back",
|
.def("push_back",
|
||||||
[](ClusterVector<ClusterType> &self, const ClusterType &cluster) {
|
[](ClusterVector<ClusterType> &self, const ClusterType &cluster) {
|
||||||
self.push_back(cluster);
|
self.push_back(cluster);
|
||||||
})
|
})
|
||||||
|
|
||||||
//.def("push_back", &ClusterVector<ClusterType>::push_back) //TODO
|
|
||||||
// implement push_back
|
// implement push_back
|
||||||
.def_property_readonly("size", &ClusterVector<ClusterType>::size)
|
.def_property_readonly("size", &ClusterVector<ClusterType>::size)
|
||||||
.def("item_size", &ClusterVector<ClusterType>::item_size)
|
.def("item_size", &ClusterVector<ClusterType>::item_size)
|
||||||
.def_property_readonly("fmt",
|
.def_property_readonly("fmt",
|
||||||
[typestr]() { return fmt_format<ClusterType>; })
|
[typestr]() { return fmt_format<ClusterType>; })
|
||||||
/*
|
|
||||||
.def("sum",
|
|
||||||
[](ClusterVector<ClusterType> &self) {
|
|
||||||
auto *vec = new std::vector<T>(self.sum());
|
|
||||||
return return_vector(vec);
|
|
||||||
})
|
|
||||||
.def("sum_2x2",
|
|
||||||
[](ClusterVector<ClusterType> &self) {
|
|
||||||
auto *vec = new std::vector<T>(self.sum_2x2());
|
|
||||||
return return_vector(vec);
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
.def_property_readonly("cluster_size_x",
|
.def_property_readonly("cluster_size_x",
|
||||||
&ClusterVector<ClusterType>::cluster_size_x)
|
&ClusterVector<ClusterType>::cluster_size_x)
|
||||||
.def_property_readonly("cluster_size_y",
|
.def_property_readonly("cluster_size_y",
|
||||||
@ -135,11 +107,14 @@ void define_cluster_vector(py::module &m, const std::string &typestr) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ClusterType>
|
template <typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
|
||||||
|
typename CoordType = uint16_t>
|
||||||
void define_cluster_finder_mt_bindings(py::module &m,
|
void define_cluster_finder_mt_bindings(py::module &m,
|
||||||
const std::string &typestr) {
|
const std::string &typestr) {
|
||||||
auto class_name = fmt::format("ClusterFinderMT_{}", typestr);
|
auto class_name = fmt::format("ClusterFinderMT_{}", typestr);
|
||||||
|
|
||||||
|
using ClusterType = Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>;
|
||||||
|
|
||||||
py::class_<ClusterFinderMT<ClusterType, uint16_t, pd_type>>(
|
py::class_<ClusterFinderMT<ClusterType, uint16_t, pd_type>>(
|
||||||
m, class_name.c_str())
|
m, class_name.c_str())
|
||||||
.def(py::init<Shape<2>, pd_type, size_t, size_t>(),
|
.def(py::init<Shape<2>, pd_type, size_t, size_t>(),
|
||||||
@ -185,11 +160,14 @@ void define_cluster_finder_mt_bindings(py::module &m,
|
|||||||
py::arg("thread_index") = 0);
|
py::arg("thread_index") = 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ClusterType>
|
template <typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
|
||||||
|
typename CoordType = uint16_t>
|
||||||
void define_cluster_collector_bindings(py::module &m,
|
void define_cluster_collector_bindings(py::module &m,
|
||||||
const std::string &typestr) {
|
const std::string &typestr) {
|
||||||
auto class_name = fmt::format("ClusterCollector_{}", typestr);
|
auto class_name = fmt::format("ClusterCollector_{}", typestr);
|
||||||
|
|
||||||
|
using ClusterType = Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>;
|
||||||
|
|
||||||
py::class_<ClusterCollector<ClusterType>>(m, class_name.c_str())
|
py::class_<ClusterCollector<ClusterType>>(m, class_name.c_str())
|
||||||
.def(py::init<ClusterFinderMT<ClusterType, uint16_t, double> *>())
|
.def(py::init<ClusterFinderMT<ClusterType, uint16_t, double> *>())
|
||||||
.def("stop", &ClusterCollector<ClusterType>::stop)
|
.def("stop", &ClusterCollector<ClusterType>::stop)
|
||||||
@ -198,26 +176,32 @@ void define_cluster_collector_bindings(py::module &m,
|
|||||||
[](ClusterCollector<ClusterType> &self) {
|
[](ClusterCollector<ClusterType> &self) {
|
||||||
auto v = new std::vector<ClusterVector<ClusterType>>(
|
auto v = new std::vector<ClusterVector<ClusterType>>(
|
||||||
self.steal_clusters());
|
self.steal_clusters());
|
||||||
return v;
|
return v; // TODO change!!!
|
||||||
},
|
},
|
||||||
py::return_value_policy::take_ownership);
|
py::return_value_policy::take_ownership);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ClusterType>
|
template <typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
|
||||||
|
typename CoordType = uint16_t>
|
||||||
void define_cluster_file_sink_bindings(py::module &m,
|
void define_cluster_file_sink_bindings(py::module &m,
|
||||||
const std::string &typestr) {
|
const std::string &typestr) {
|
||||||
auto class_name = fmt::format("ClusterFileSink_{}", typestr);
|
auto class_name = fmt::format("ClusterFileSink_{}", typestr);
|
||||||
|
|
||||||
|
using ClusterType = Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>;
|
||||||
|
|
||||||
py::class_<ClusterFileSink<ClusterType>>(m, class_name.c_str())
|
py::class_<ClusterFileSink<ClusterType>>(m, class_name.c_str())
|
||||||
.def(py::init<ClusterFinderMT<ClusterType, uint16_t, double> *,
|
.def(py::init<ClusterFinderMT<ClusterType, uint16_t, double> *,
|
||||||
const std::filesystem::path &>())
|
const std::filesystem::path &>())
|
||||||
.def("stop", &ClusterFileSink<ClusterType>::stop);
|
.def("stop", &ClusterFileSink<ClusterType>::stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ClusterType>
|
template <typename T, uint8_t ClusterSizeX, uint8_t ClusterSizeY,
|
||||||
|
typename CoordType = uint16_t>
|
||||||
void define_cluster_finder_bindings(py::module &m, const std::string &typestr) {
|
void define_cluster_finder_bindings(py::module &m, const std::string &typestr) {
|
||||||
auto class_name = fmt::format("ClusterFinder_{}", typestr);
|
auto class_name = fmt::format("ClusterFinder_{}", typestr);
|
||||||
|
|
||||||
|
using ClusterType = Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>;
|
||||||
|
|
||||||
py::class_<ClusterFinder<ClusterType, uint16_t, pd_type>>(
|
py::class_<ClusterFinder<ClusterType, uint16_t, pd_type>>(
|
||||||
m, class_name.c_str())
|
m, class_name.c_str())
|
||||||
.def(py::init<Shape<2>, pd_type, size_t>(), py::arg("image_size"),
|
.def(py::init<Shape<2>, pd_type, size_t>(), py::arg("image_size"),
|
||||||
@ -248,9 +232,9 @@ void define_cluster_finder_bindings(py::module &m, const std::string &typestr) {
|
|||||||
"steal_clusters",
|
"steal_clusters",
|
||||||
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self,
|
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self,
|
||||||
bool realloc_same_capacity) {
|
bool realloc_same_capacity) {
|
||||||
auto v = new ClusterVector<ClusterType>(
|
ClusterVector<ClusterType> clusters =
|
||||||
self.steal_clusters(realloc_same_capacity));
|
self.steal_clusters(realloc_same_capacity);
|
||||||
return v;
|
return clusters;
|
||||||
},
|
},
|
||||||
py::arg("realloc_same_capacity") = false)
|
py::arg("realloc_same_capacity") = false)
|
||||||
.def(
|
.def(
|
||||||
|
@ -80,7 +80,12 @@ void define_cluster_file_io_bindings(py::module &m,
|
|||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Type, uint8_t CoordSizeX, uint8_t CoordSizeY,
|
||||||
|
typename CoordType = uint16_t>
|
||||||
|
void register_calculate_eta(py::module &m) {
|
||||||
|
using ClusterType = Cluster<Type, CoordSizeX, CoordSizeY, CoordType>;
|
||||||
m.def("calculate_eta2",
|
m.def("calculate_eta2",
|
||||||
[](const aare::ClusterVector<ClusterType> &clusters) {
|
[](const aare::ClusterVector<ClusterType> &clusters) {
|
||||||
auto eta2 = new NDArray<double, 2>(calculate_eta2(clusters));
|
auto eta2 = new NDArray<double, 2>(calculate_eta2(clusters));
|
||||||
|
@ -9,12 +9,13 @@
|
|||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
|
|
||||||
template <typename ClusterType>
|
template <typename Type, uint8_t CoordSizeX, uint8_t CoordSizeY,
|
||||||
void register_interpolate(py::class_<aare::Interpolator> &interpolator,
|
typename CoordType = uint16_t>
|
||||||
const std::string &typestr) {
|
void register_interpolate(py::class_<aare::Interpolator> &interpolator) {
|
||||||
auto name = fmt::format("interpolate_{}", typestr);
|
|
||||||
|
|
||||||
interpolator.def(name.c_str(),
|
using ClusterType = Cluster<Type, CoordSizeX, CoordSizeY, CoordType>;
|
||||||
|
|
||||||
|
interpolator.def("interpolate",
|
||||||
[](aare::Interpolator &self,
|
[](aare::Interpolator &self,
|
||||||
const ClusterVector<ClusterType> &clusters) {
|
const ClusterVector<ClusterType> &clusters) {
|
||||||
auto photons = self.interpolate<ClusterType>(clusters);
|
auto photons = self.interpolate<ClusterType>(clusters);
|
||||||
@ -50,12 +51,12 @@ void define_interpolation_bindings(py::module &m) {
|
|||||||
return return_image_data(ptr);
|
return return_image_data(ptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
register_interpolate<Cluster<int, 3, 3>>(interpolator, "Cluster3x3i");
|
register_interpolate<int, 3, 3, uint16_t>(interpolator);
|
||||||
register_interpolate<Cluster<float, 3, 3>>(interpolator, "Cluster3x3f");
|
register_interpolate<float, 3, 3, uint16_t>(interpolator);
|
||||||
register_interpolate<Cluster<double, 3, 3>>(interpolator, "Cluster3x3d");
|
register_interpolate<double, 3, 3, uint16_t>(interpolator);
|
||||||
register_interpolate<Cluster<int, 2, 2>>(interpolator, "Cluster2x2i");
|
register_interpolate<int, 2, 2, uint16_t>(interpolator);
|
||||||
register_interpolate<Cluster<float, 2, 2>>(interpolator, "Cluster2x2f");
|
register_interpolate<float, 2, 2, uint16_t>(interpolator);
|
||||||
register_interpolate<Cluster<double, 2, 2>>(interpolator, "Cluster2x2d");
|
register_interpolate<double, 2, 2, uint16_t>(interpolator);
|
||||||
|
|
||||||
// TODO! Evaluate without converting to double
|
// TODO! Evaluate without converting to double
|
||||||
m.def(
|
m.def(
|
||||||
|
@ -43,33 +43,33 @@ PYBIND11_MODULE(_aare, m) {
|
|||||||
define_cluster_vector<double, 2, 2, uint16_t>(m, "Cluster2x2d");
|
define_cluster_vector<double, 2, 2, uint16_t>(m, "Cluster2x2d");
|
||||||
define_cluster_vector<float, 2, 2, uint16_t>(m, "Cluster2x2f");
|
define_cluster_vector<float, 2, 2, uint16_t>(m, "Cluster2x2f");
|
||||||
|
|
||||||
define_cluster_finder_bindings<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
define_cluster_finder_bindings<int, 3, 3, uint16_t>(m, "Cluster3x3i");
|
||||||
define_cluster_finder_bindings<Cluster<double, 3, 3>>(m, "Cluster3x3d");
|
define_cluster_finder_bindings<double, 3, 3, uint16_t>(m, "Cluster3x3d");
|
||||||
define_cluster_finder_bindings<Cluster<float, 3, 3>>(m, "Cluster3x3f");
|
define_cluster_finder_bindings<float, 3, 3, uint16_t>(m, "Cluster3x3f");
|
||||||
define_cluster_finder_bindings<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
define_cluster_finder_bindings<int, 2, 2, uint16_t>(m, "Cluster2x2i");
|
||||||
define_cluster_finder_bindings<Cluster<double, 2, 2>>(m, "Cluster2x2d");
|
define_cluster_finder_bindings<double, 2, 2, uint16_t>(m, "Cluster2x2d");
|
||||||
define_cluster_finder_bindings<Cluster<float, 2, 2>>(m, "Cluster2x2f");
|
define_cluster_finder_bindings<float, 2, 2, uint16_t>(m, "Cluster2x2f");
|
||||||
|
|
||||||
define_cluster_finder_mt_bindings<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
define_cluster_finder_mt_bindings<int, 3, 3, uint16_t>(m, "Cluster3x3i");
|
||||||
define_cluster_finder_mt_bindings<Cluster<double, 3, 3>>(m, "Cluster3x3d");
|
define_cluster_finder_mt_bindings<double, 3, 3, uint16_t>(m, "Cluster3x3d");
|
||||||
define_cluster_finder_mt_bindings<Cluster<float, 3, 3>>(m, "Cluster3x3f");
|
define_cluster_finder_mt_bindings<float, 3, 3, uint16_t>(m, "Cluster3x3f");
|
||||||
define_cluster_finder_mt_bindings<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
define_cluster_finder_mt_bindings<int, 2, 2, uint16_t>(m, "Cluster2x2i");
|
||||||
define_cluster_finder_mt_bindings<Cluster<double, 2, 2>>(m, "Cluster2x2d");
|
define_cluster_finder_mt_bindings<double, 2, 2, uint16_t>(m, "Cluster2x2d");
|
||||||
define_cluster_finder_mt_bindings<Cluster<float, 2, 2>>(m, "Cluster2x2f");
|
define_cluster_finder_mt_bindings<float, 2, 2, uint16_t>(m, "Cluster2x2f");
|
||||||
|
|
||||||
define_cluster_file_sink_bindings<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
define_cluster_file_sink_bindings<int, 3, 3, uint16_t>(m, "Cluster3x3i");
|
||||||
define_cluster_file_sink_bindings<Cluster<double, 3, 3>>(m, "Cluster3x3d");
|
define_cluster_file_sink_bindings<double, 3, 3, uint16_t>(m, "Cluster3x3d");
|
||||||
define_cluster_file_sink_bindings<Cluster<float, 3, 3>>(m, "Cluster3x3f");
|
define_cluster_file_sink_bindings<float, 3, 3, uint16_t>(m, "Cluster3x3f");
|
||||||
define_cluster_file_sink_bindings<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
define_cluster_file_sink_bindings<int, 2, 2, uint16_t>(m, "Cluster2x2i");
|
||||||
define_cluster_file_sink_bindings<Cluster<double, 2, 2>>(m, "Cluster2x2d");
|
define_cluster_file_sink_bindings<double, 2, 2, uint16_t>(m, "Cluster2x2d");
|
||||||
define_cluster_file_sink_bindings<Cluster<float, 2, 2>>(m, "Cluster2x2f");
|
define_cluster_file_sink_bindings<float, 2, 2, uint16_t>(m, "Cluster2x2f");
|
||||||
|
|
||||||
define_cluster_collector_bindings<Cluster<int, 3, 3>>(m, "Cluster3x3i");
|
define_cluster_collector_bindings<int, 3, 3, uint16_t>(m, "Cluster3x3i");
|
||||||
define_cluster_collector_bindings<Cluster<double, 3, 3>>(m, "Cluster3x3f");
|
define_cluster_collector_bindings<double, 3, 3, uint16_t>(m, "Cluster3x3f");
|
||||||
define_cluster_collector_bindings<Cluster<float, 3, 3>>(m, "Cluster3x3d");
|
define_cluster_collector_bindings<float, 3, 3, uint16_t>(m, "Cluster3x3d");
|
||||||
define_cluster_collector_bindings<Cluster<int, 2, 2>>(m, "Cluster2x2i");
|
define_cluster_collector_bindings<int, 2, 2, uint16_t>(m, "Cluster2x2i");
|
||||||
define_cluster_collector_bindings<Cluster<double, 2, 2>>(m, "Cluster2x2f");
|
define_cluster_collector_bindings<double, 2, 2, uint16_t>(m, "Cluster2x2f");
|
||||||
define_cluster_collector_bindings<Cluster<float, 2, 2>>(m, "Cluster2x2d");
|
define_cluster_collector_bindings<float, 2, 2, uint16_t>(m, "Cluster2x2d");
|
||||||
|
|
||||||
define_cluster<int, 3, 3, uint16_t>(m, "3x3i");
|
define_cluster<int, 3, 3, uint16_t>(m, "3x3i");
|
||||||
define_cluster<float, 3, 3, uint16_t>(m, "3x3f");
|
define_cluster<float, 3, 3, uint16_t>(m, "3x3f");
|
||||||
@ -77,4 +77,11 @@ PYBIND11_MODULE(_aare, m) {
|
|||||||
define_cluster<int, 2, 2, uint16_t>(m, "2x2i");
|
define_cluster<int, 2, 2, uint16_t>(m, "2x2i");
|
||||||
define_cluster<float, 2, 2, uint16_t>(m, "2x2f");
|
define_cluster<float, 2, 2, uint16_t>(m, "2x2f");
|
||||||
define_cluster<double, 2, 2, uint16_t>(m, "2x2d");
|
define_cluster<double, 2, 2, uint16_t>(m, "2x2d");
|
||||||
|
|
||||||
|
register_calculate_eta<int, 3, 3, uint16_t>(m);
|
||||||
|
register_calculate_eta<float, 3, 3, uint16_t>(m);
|
||||||
|
register_calculate_eta<double, 3, 3, uint16_t>(m);
|
||||||
|
register_calculate_eta<int, 2, 2, uint16_t>(m);
|
||||||
|
register_calculate_eta<float, 2, 2, uint16_t>(m);
|
||||||
|
register_calculate_eta<double, 2, 2, uint16_t>(m);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from _aare import ClusterVector_Cluster3x3i, Interpolator, Cluster3x3i, ClusterFinder_Cluster3x3i
|
import aare._aare as aare #import ClusterVector_Cluster3x3i, ClusterVector_Cluster2x2i, Interpolator, Cluster3x3i, ClusterFinder_Cluster3x3i, Cluster2x2i, ClusterFile_Cluster3x3i, Cluster3x3f, calculate_eta2
|
||||||
|
|
||||||
def test_ClusterVector():
|
def test_ClusterVector():
|
||||||
"""Test ClusterVector"""
|
"""Test ClusterVector"""
|
||||||
|
|
||||||
clustervector = ClusterVector_Cluster3x3i()
|
clustervector = aare.ClusterVector_Cluster3x3i()
|
||||||
assert clustervector.cluster_size_x == 3
|
assert clustervector.cluster_size_x == 3
|
||||||
assert clustervector.cluster_size_y == 3
|
assert clustervector.cluster_size_y == 3
|
||||||
assert clustervector.item_size() == 4+9*4
|
assert clustervector.item_size() == 4+9*4
|
||||||
@ -14,14 +14,16 @@ def test_ClusterVector():
|
|||||||
assert clustervector.capacity == 1024
|
assert clustervector.capacity == 1024
|
||||||
assert clustervector.size == 0
|
assert clustervector.size == 0
|
||||||
|
|
||||||
cluster = Cluster3x3i(0,0,np.ones(9, dtype=np.int32))
|
cluster = aare.Cluster3x3i(0,0,np.ones(9, dtype=np.int32))
|
||||||
|
|
||||||
clustervector.push_back(cluster)
|
clustervector.push_back(cluster)
|
||||||
assert clustervector.size == 1
|
assert clustervector.size == 1
|
||||||
|
|
||||||
#push_back - check size
|
with pytest.raises(TypeError): # Or use the appropriate exception type
|
||||||
|
clustervector.push_back(aare.Cluster2x2i(0,0,np.ones(4, dtype=np.int32)))
|
||||||
|
|
||||||
|
with pytest.raises(TypeError):
|
||||||
|
clustervector.push_back(aare.Cluster3x3f(0,0,np.ones(9, dtype=np.float32)))
|
||||||
|
|
||||||
def test_Interpolator():
|
def test_Interpolator():
|
||||||
"""Test Interpolator"""
|
"""Test Interpolator"""
|
||||||
@ -31,31 +33,87 @@ def test_Interpolator():
|
|||||||
ybins = np.linspace(0, 5, 30, dtype=np.float64)
|
ybins = np.linspace(0, 5, 30, dtype=np.float64)
|
||||||
|
|
||||||
etacube = np.zeros(shape=[30, 30, 20], dtype=np.float64)
|
etacube = np.zeros(shape=[30, 30, 20], dtype=np.float64)
|
||||||
interpolator = Interpolator(etacube, xbins, ybins, ebins)
|
interpolator = aare.Interpolator(etacube, xbins, ybins, ebins)
|
||||||
|
|
||||||
assert interpolator.get_ietax().shape == (30,30,20)
|
assert interpolator.get_ietax().shape == (30,30,20)
|
||||||
assert interpolator.get_ietay().shape == (30,30,20)
|
assert interpolator.get_ietay().shape == (30,30,20)
|
||||||
clustervector = ClusterVector_Cluster3x3i()
|
clustervector = aare.ClusterVector_Cluster3x3i()
|
||||||
|
|
||||||
cluster = Cluster3x3i(0,0, np.ones(9, dtype=np.int32))
|
cluster = aare.Cluster3x3i(0,0, np.ones(9, dtype=np.int32))
|
||||||
#clustervector.push_back(cluster)
|
clustervector.push_back(cluster)
|
||||||
#num_clusters = 1;
|
|
||||||
|
|
||||||
#assert interpolator.interpolate_Cluster3x3i(clustervector).shape == (num_clusters, 3)
|
interpolated_photons = interpolator.interpolate(clustervector)
|
||||||
|
|
||||||
|
assert interpolated_photons.size == 1
|
||||||
|
|
||||||
|
assert interpolated_photons[0]["x"] == -1
|
||||||
|
assert interpolated_photons[0]["y"] == -1
|
||||||
|
assert interpolated_photons[0]["energy"] == 4 #eta_sum = 4, dx, dy = -1,-1 m_ietax = 0, m_ietay = 0
|
||||||
|
|
||||||
|
clustervector = aare.ClusterVector_Cluster2x2i()
|
||||||
|
|
||||||
|
cluster = aare.Cluster2x2i(0,0, np.ones(4, dtype=np.int32))
|
||||||
|
clustervector.push_back(cluster)
|
||||||
|
|
||||||
|
interpolated_photons = interpolator.interpolate(clustervector)
|
||||||
|
|
||||||
|
assert interpolated_photons.size == 1
|
||||||
|
|
||||||
|
assert interpolated_photons[0]["x"] == 0
|
||||||
|
assert interpolated_photons[0]["y"] == 0
|
||||||
|
assert interpolated_photons[0]["energy"] == 4
|
||||||
|
|
||||||
|
@pytest.mark.files
|
||||||
|
def test_cluster_file():
|
||||||
|
"""Test ClusterFile"""
|
||||||
|
cluster_file = aare.ClusterFile_Cluster3x3i(test_data_path() / "clust/single_frame_97_clustrers.clust")
|
||||||
|
clustervector = cluster_file.read_clusters() #conversion does not work
|
||||||
|
|
||||||
|
cluster_file.close()
|
||||||
|
|
||||||
|
###reading with wrong file
|
||||||
|
cluster_file = ClusterFile_Cluster2x2i(test_data_path() / "clust/single_frame_97_clustrers.clust") #TODO check behavior!
|
||||||
|
|
||||||
|
def test_calculate_eta():
|
||||||
|
"""Calculate Eta"""
|
||||||
|
clusters = aare.ClusterVector_Cluster3x3i()
|
||||||
|
clusters.push_back(aare.Cluster3x3i(0,0, np.ones(9, dtype=np.int32)))
|
||||||
|
clusters.push_back(aare.Cluster3x3i(0,0, np.array([1,1,1,2,2,2,3,3,3])))
|
||||||
|
|
||||||
|
eta2 = aare.calculate_eta2(clusters)
|
||||||
|
|
||||||
|
assert eta2.shape == (2,2)
|
||||||
|
assert eta2[0,0] == 0.5
|
||||||
|
assert eta2[0,1] == 0.5
|
||||||
|
assert eta2[1,0] == 0.5
|
||||||
|
assert eta2[1,1] == 0.6 #1/5
|
||||||
|
|
||||||
|
def test_cluster_finder():
|
||||||
|
"""Test ClusterFinder"""
|
||||||
|
|
||||||
|
clusterfinder = aare.ClusterFinder_Cluster3x3i([100,100])
|
||||||
|
|
||||||
|
#frame = np.random.rand(100,100)
|
||||||
|
frame = np.zeros(shape=[100,100])
|
||||||
|
|
||||||
|
clusterfinder.find_clusters(frame)
|
||||||
|
|
||||||
|
clusters = clusterfinder.steal_clusters(False) #conversion does not work
|
||||||
|
|
||||||
|
assert clusters.size == 0
|
||||||
|
|
||||||
|
|
||||||
#def test_cluster_file():
|
def test_cluster_collector():
|
||||||
|
"""Test ClusterCollector"""
|
||||||
|
|
||||||
#def test_cluster_finder():
|
clusterfinder = aare.ClusterFinderMT_Cluster3x3i([100,100]) #TODO: no idea what the data is in InputQueue not zero
|
||||||
#"""Test ClusterFinder"""
|
|
||||||
|
|
||||||
#clusterfinder = ClusterFinder_Cluster3x3i([100,100])
|
clustercollector = aare.ClusterCollector_Cluster3x3i(clusterfinder)
|
||||||
|
|
||||||
#clusterfinder.find_clusters()
|
cluster_vectors = clustercollector.steal_clusters()
|
||||||
|
|
||||||
#clusters = clusterfinder.steal_clusters()
|
assert len(cluster_vectors) == 1 #single thread execution
|
||||||
|
assert cluster_vectors[0].size == 0 #
|
||||||
#print("cluster size: ", clusters.size())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user