added docs for ClusterFinderMT

This commit is contained in:
froejdh_e
2025-01-10 10:22:04 +01:00
parent cc95561eda
commit caf7b4ecdb
12 changed files with 309 additions and 105 deletions

View File

@ -8,7 +8,7 @@ from ._aare import DetectorType
from ._aare import ClusterFile
from ._aare import hitmap
from ._aare import ClusterFinderMT, ClusterCollector, ClusterFileSink
from ._aare import ClusterFinderMT, ClusterCollector, ClusterFileSink, ClusterVector_i
from .CtbRawFile import CtbRawFile
from .RawFile import RawFile

View File

@ -35,11 +35,34 @@ for i in range(100):
# time.sleep(1)
cf.stop()
time.sleep(1)
print('Second run')
cf.start()
for i in range(100):
img = f.read_frame()
cf.find_clusters(img)
cf.stop()
print('Third run')
cf.start()
for i in range(129):
img = f.read_frame()
cf.find_clusters(img)
cf.stop()
out_file.stop()
print('Done')
cfile = ClusterFile("test.clust")
i = 0
while True:
try:
cv = cfile.read_frame()
i+=1
except RuntimeError:
break
print(f'Read {i} frames')

View File

@ -22,8 +22,7 @@ void define_cluster_vector(py::module &m, const std::string &typestr) {
py::class_<ClusterVector<T>>(m, class_name.c_str(), py::buffer_protocol())
.def(py::init<int, int>())
.def_property_readonly("size", &ClusterVector<T>::size)
.def("element_offset",
py::overload_cast<>(&ClusterVector<T>::element_offset, py::const_))
.def("item_size", &ClusterVector<T>::item_size)
.def_property_readonly("fmt",
[typestr](ClusterVector<T> &self) {
return fmt::format(
@ -41,13 +40,13 @@ void define_cluster_vector(py::module &m, const std::string &typestr) {
.def_buffer([typestr](ClusterVector<T> &self) -> py::buffer_info {
return py::buffer_info(
self.data(), /* Pointer to buffer */
self.element_offset(), /* Size of one scalar */
self.item_size(), /* Size of one scalar */
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.element_offset()} /* Strides (in bytes) for each index */
{self.item_size()} /* Strides (in bytes) for each index */
);
});
}
@ -56,7 +55,7 @@ void define_cluster_finder_mt_bindings(py::module &m) {
py::class_<ClusterFinderMT<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") = 1000,
py::arg("n_sigma") = 5.0, py::arg("capacity") = 2048,
py::arg("n_threads") = 3)
.def("push_pedestal_frame",
[](ClusterFinderMT<uint16_t, pd_type> &self,
@ -75,6 +74,7 @@ void define_cluster_finder_mt_bindings(py::module &m) {
py::arg(), py::arg("frame_number") = 0)
.def("sync", &ClusterFinderMT<uint16_t, pd_type>::sync)
.def("stop", &ClusterFinderMT<uint16_t, pd_type>::stop)
.def("start", &ClusterFinderMT<uint16_t, pd_type>::start)
.def_property_readonly("pedestal",
[](ClusterFinderMT<uint16_t, pd_type> &self) {
auto pd = new NDArray<pd_type, 2>{};
@ -162,7 +162,7 @@ void define_cluster_finder_bindings(py::module &m) {
for (py::ssize_t j = 0; j < r.shape(1); j++)
r(i, j) = 0;
size_t stride = cv.element_offset();
size_t stride = cv.item_size();
auto ptr = cv.data();
for (size_t i = 0; i < cv.size(); i++) {
auto x = *reinterpret_cast<int16_t *>(ptr);

View File

@ -30,12 +30,12 @@ void define_cluster_file_io_bindings(py::module &m) {
[](ClusterFile &self, size_t n_clusters) {
auto v = new ClusterVector<int32_t>(self.read_clusters(n_clusters));
return v;
})
},py::return_value_policy::take_ownership)
.def("read_frame",
[](ClusterFile &self) {
auto v = new ClusterVector<int32_t>(self.read_frame());
return v;
})
},py::return_value_policy::take_ownership)
.def("write_frame", &ClusterFile::write_frame)
.def("read_cluster_with_cut",
[](ClusterFile &self, size_t n_clusters,