mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-12-26 15:01:25 +01:00
Separated cluster size for finding and saving. You now specfic the cluster size you want when search through a frame, but you can also now specify a cluster size to save afterwards. For example, you search for 3x3s but save 9x9s
This commit is contained in:
@@ -21,9 +21,11 @@ class ClusterFinder {
|
|||||||
const PEDESTAL_TYPE c3;
|
const PEDESTAL_TYPE c3;
|
||||||
ChunkedPedestal<PEDESTAL_TYPE> m_pedestal;
|
ChunkedPedestal<PEDESTAL_TYPE> m_pedestal;
|
||||||
ClusterVector<ClusterType> m_clusters;
|
ClusterVector<ClusterType> m_clusters;
|
||||||
|
const uint32_t ClusterSizeX;
|
||||||
|
const uint32_t ClusterSizeY;
|
||||||
|
|
||||||
static const uint8_t ClusterSizeX = ClusterType::cluster_size_x;
|
static const uint8_t SavedClusterSizeX = ClusterType::cluster_size_x;
|
||||||
static const uint8_t ClusterSizeY = ClusterType::cluster_size_y;
|
static const uint8_t SavedClusterSizeY = ClusterType::cluster_size_y;
|
||||||
using CT = typename ClusterType::value_type;
|
using CT = typename ClusterType::value_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -37,10 +39,12 @@ class ClusterFinder {
|
|||||||
*/
|
*/
|
||||||
ClusterFinder(Shape<2> image_size, PEDESTAL_TYPE nSigma = 5.0,
|
ClusterFinder(Shape<2> image_size, PEDESTAL_TYPE nSigma = 5.0,
|
||||||
size_t capacity = 1000000,
|
size_t capacity = 1000000,
|
||||||
uint32_t chunk_size = 50000, uint32_t n_chunks = 10)
|
uint32_t chunk_size = 50000, uint32_t n_chunks = 10,
|
||||||
|
uint32_t cluster_size_x = 3, uint32_t cluster_size_y = 3)
|
||||||
: m_image_size(image_size), m_nSigma(nSigma),
|
: m_image_size(image_size), m_nSigma(nSigma),
|
||||||
c2(sqrt((ClusterSizeY + 1) / 2 * (ClusterSizeX + 1) / 2)),
|
c2(sqrt((cluster_size_y + 1) / 2 * (cluster_size_x + 1) / 2)),
|
||||||
c3(sqrt(ClusterSizeX * ClusterSizeY)),
|
c3(sqrt(cluster_size_x * cluster_size_y)),
|
||||||
|
ClusterSizeX(cluster_size_x), ClusterSizeY(cluster_size_y),
|
||||||
m_pedestal(image_size[0], image_size[1], chunk_size, n_chunks), m_clusters(capacity) {
|
m_pedestal(image_size[0], image_size[1], chunk_size, n_chunks), m_clusters(capacity) {
|
||||||
LOG(logDEBUG) << "ClusterFinder: "
|
LOG(logDEBUG) << "ClusterFinder: "
|
||||||
<< "image_size: " << image_size[0] << "x" << image_size[1]
|
<< "image_size: " << image_size[0] << "x" << image_size[1]
|
||||||
@@ -63,7 +67,7 @@ class ClusterFinder {
|
|||||||
NDArray<PEDESTAL_TYPE, 2> noise() { return m_pedestal.std(); }
|
NDArray<PEDESTAL_TYPE, 2> noise() { return m_pedestal.std(); }
|
||||||
void clear_pedestal() { m_pedestal.clear(); }
|
void clear_pedestal() { m_pedestal.clear(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Move the clusters from the ClusterVector in the ClusterFinder to a
|
* @brief Move the clusters from the ClusterVector in the ClusterFinder to a
|
||||||
* new ClusterVector and return it.
|
* new ClusterVector and return it.
|
||||||
* @param realloc_same_capacity if true the new ClusterVector will have the
|
* @param realloc_same_capacity if true the new ClusterVector will have the
|
||||||
@@ -80,11 +84,13 @@ class ClusterFinder {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
void find_clusters(NDView<FRAME_TYPE, 2> frame, uint64_t frame_number = 0) {
|
void find_clusters(NDView<FRAME_TYPE, 2> frame, uint64_t frame_number = 0) {
|
||||||
// // TODO! deal with even size clusters
|
|
||||||
// // currently 3,3 -> +/- 1
|
// // currently 3,3 -> +/- 1
|
||||||
// // 4,4 -> +/- 2
|
// // 4,4 -> +/- 2
|
||||||
int dy = ClusterSizeY / 2;
|
int dy = ClusterSizeY / 2;
|
||||||
int dx = ClusterSizeX / 2;
|
int dx = ClusterSizeX / 2;
|
||||||
|
int dy2 = SavedClusterSizeY / 2;
|
||||||
|
int dx2 = SavedClusterSizeX / 2;
|
||||||
|
|
||||||
int has_center_pixel_x =
|
int has_center_pixel_x =
|
||||||
ClusterSizeX %
|
ClusterSizeX %
|
||||||
2; // for even sized clusters there is no proper cluster center and
|
2; // for even sized clusters there is no proper cluster center and
|
||||||
@@ -179,16 +185,19 @@ class ClusterFinder {
|
|||||||
// It's worth redoing the look since most of the time we
|
// It's worth redoing the look since most of the time we
|
||||||
// don't have a photon
|
// don't have a photon
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (int ir = -dy; ir < dy + has_center_pixel_y; ir++) {
|
for (int ir = -dy2; ir < dy2 + has_center_pixel_y; ir++) {
|
||||||
size_t inner_row_offset = row_offset + (ir * frame.shape(1));
|
size_t inner_row_offset = row_offset + (ir * frame.shape(1));
|
||||||
for (int ic = -dx; ic < dx + has_center_pixel_y; ic++) {
|
for (int ic = -dx2; ic < dx2 + has_center_pixel_y; ic++) {
|
||||||
if (ix + ic >= 0 && ix + ic < frame.shape(1) &&
|
if (ix + ic >= 0 && ix + ic < frame.shape(1) &&
|
||||||
iy + ir >= 0 && iy + ir < frame.shape(0)) {
|
iy + ir >= 0 && iy + ir < frame.shape(0)) {
|
||||||
// if (m_pedestal.std(iy + ir, ix + ic) == 0) continue;
|
// if (m_pedestal.std(iy + ir, ix + ic) == 0) continue;
|
||||||
if (std_ptr[inner_row_offset + ix + ic] == 0) continue;
|
// if (std_ptr[inner_row_offset + ix + ic] == 0) continue;
|
||||||
|
|
||||||
// CT tmp = static_cast<CT>(frame(iy + ir, ix + ic)) - static_cast<CT>(m_pedestal.mean(iy + ir, ix + ic));
|
// CT tmp = static_cast<CT>(frame(iy + ir, ix + ic)) - static_cast<CT>(m_pedestal.mean(iy + ir, ix + ic));
|
||||||
CT tmp = static_cast<CT>(frame(iy + ir, ix + ic)) - static_cast<CT>(mean_ptr[inner_row_offset + ix + ic]);
|
|
||||||
|
CT tmp = 0;
|
||||||
|
if (std_ptr[inner_row_offset + ix + ic] != 0)
|
||||||
|
tmp = static_cast<CT>(frame(iy + ir, ix + ic)) - static_cast<CT>(mean_ptr[inner_row_offset + ix + ic]);
|
||||||
|
|
||||||
cluster.data[i] = tmp; // Watch for out of bounds access
|
cluster.data[i] = tmp; // Watch for out of bounds access
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
@@ -129,7 +129,8 @@ class ClusterFinderMT {
|
|||||||
*/
|
*/
|
||||||
ClusterFinderMT(Shape<2> image_size, PEDESTAL_TYPE nSigma = 5.0,
|
ClusterFinderMT(Shape<2> image_size, PEDESTAL_TYPE nSigma = 5.0,
|
||||||
size_t capacity = 2000, size_t n_threads = 3,
|
size_t capacity = 2000, size_t n_threads = 3,
|
||||||
uint32_t chunk_size = 50000, uint32_t n_chunks = 10)
|
uint32_t chunk_size = 50000, uint32_t n_chunks = 10,
|
||||||
|
uint32_t cluster_size_x = 3, uint32_t cluster_size_y = 3)
|
||||||
: m_n_threads(n_threads) {
|
: m_n_threads(n_threads) {
|
||||||
|
|
||||||
LOG(logDEBUG1) << "ClusterFinderMT: "
|
LOG(logDEBUG1) << "ClusterFinderMT: "
|
||||||
@@ -142,7 +143,7 @@ class ClusterFinderMT {
|
|||||||
m_cluster_finders.push_back(
|
m_cluster_finders.push_back(
|
||||||
std::make_unique<
|
std::make_unique<
|
||||||
ClusterFinder<ClusterType, FRAME_TYPE, PEDESTAL_TYPE>>(
|
ClusterFinder<ClusterType, FRAME_TYPE, PEDESTAL_TYPE>>(
|
||||||
image_size, nSigma, capacity, chunk_size, n_chunks));
|
image_size, nSigma, capacity, chunk_size, n_chunks, cluster_size_x, cluster_size_y));
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < n_threads; i++) {
|
for (size_t i = 0; i < n_threads; i++) {
|
||||||
m_input_queues.emplace_back(std::make_unique<InputQueue>(200));
|
m_input_queues.emplace_back(std::make_unique<InputQueue>(200));
|
||||||
|
|||||||
@@ -26,24 +26,24 @@ def _get_class(name, cluster_size, dtype):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ClusterFinder(image_size, cluster_size, n_sigma=5, dtype = np.int32, capacity = 1024, chunk_size=50000, n_chunks = 10):
|
def ClusterFinder(image_size, saved_cluster_size, checked_cluster_size, n_sigma=5, dtype = np.int32, capacity = 1024, chunk_size=50000, n_chunks = 10):
|
||||||
"""
|
"""
|
||||||
Factory function to create a ClusterFinder object. Provides a cleaner syntax for
|
Factory function to create a ClusterFinder object. Provides a cleaner syntax for
|
||||||
the templated ClusterFinder in C++.
|
the templated ClusterFinder in C++.
|
||||||
"""
|
"""
|
||||||
cls = _get_class("ClusterFinder", cluster_size, dtype)
|
cls = _get_class("ClusterFinder", saved_cluster_size, dtype)
|
||||||
return cls(image_size, n_sigma=n_sigma, capacity=capacity, chunk_size=chunk_size, n_chunks=n_chunks)
|
return cls(image_size, n_sigma=n_sigma, capacity=capacity, chunk_size=chunk_size, n_chunks=n_chunks, cluster_size_x=checked_cluster_size[0], cluster_size_y=checked_cluster_size[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ClusterFinderMT(image_size, cluster_size = (3,3), dtype=np.int32, n_sigma=5, capacity = 1024, n_threads = 3, chunk_size=50000, n_chunks = 10):
|
def ClusterFinderMT(image_size, saved_cluster_size = (3,3), checked_cluster_size = (3,3), dtype=np.int32, n_sigma=5, capacity = 1024, n_threads = 3, chunk_size=50000, n_chunks = 10):
|
||||||
"""
|
"""
|
||||||
Factory function to create a ClusterFinderMT object. Provides a cleaner syntax for
|
Factory function to create a ClusterFinderMT object. Provides a cleaner syntax for
|
||||||
the templated ClusterFinderMT in C++.
|
the templated ClusterFinderMT in C++.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cls = _get_class("ClusterFinderMT", cluster_size, dtype)
|
cls = _get_class("ClusterFinderMT", saved_cluster_size, dtype)
|
||||||
return cls(image_size, n_sigma=n_sigma, capacity=capacity, n_threads=n_threads, chunk_size=chunk_size, n_chunks=n_chunks)
|
return cls(image_size, n_sigma=n_sigma, capacity=capacity, n_threads=n_threads, chunk_size=chunk_size, n_chunks=n_chunks, cluster_size_x=checked_cluster_size[0], cluster_size_y=checked_cluster_size[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,9 +30,10 @@ void define_ClusterFinder(py::module &m, const std::string &typestr) {
|
|||||||
|
|
||||||
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, uint32_t, uint32_t>(), py::arg("image_size"),
|
.def(py::init<Shape<2>, pd_type, size_t, uint32_t, uint32_t, uint32_t, uint32_t>(),
|
||||||
py::arg("n_sigma") = 5.0, py::arg("capacity") = 1'000'000,
|
py::arg("image_size"), py::arg("n_sigma") = 5.0, py::arg("capacity") = 1'000'000,
|
||||||
py::arg("chunk_size") = 50'000, py::arg("n_chunks") = 10)
|
py::arg("chunk_size") = 50'000, py::arg("n_chunks") = 10,
|
||||||
|
py::arg("cluster_size_x") = 3, py::arg("cluster_size_y") = 3)
|
||||||
.def("push_pedestal_frame",
|
.def("push_pedestal_frame",
|
||||||
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self,
|
[](ClusterFinder<ClusterType, uint16_t, pd_type> &self,
|
||||||
py::array_t<uint16_t> frame) {
|
py::array_t<uint16_t> frame) {
|
||||||
|
|||||||
@@ -30,10 +30,11 @@ void define_ClusterFinderMT(py::module &m, const std::string &typestr) {
|
|||||||
|
|
||||||
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, uint32_t, uint32_t>(),
|
.def(py::init<Shape<2>, pd_type, size_t, size_t, uint32_t, uint32_t, uint32_t, uint32_t>(),
|
||||||
py::arg("image_size"), py::arg("n_sigma") = 5.0,
|
py::arg("image_size"), py::arg("n_sigma") = 5.0,
|
||||||
py::arg("capacity") = 2048, py::arg("n_threads") = 3,
|
py::arg("capacity") = 2048, py::arg("n_threads") = 3,
|
||||||
py::arg("chunk_size") = 50'000, py::arg("n_chunks") = 10)
|
py::arg("chunk_size") = 50'000, py::arg("n_chunks") = 10,
|
||||||
|
py::arg("cluster_size_x") = 3, py::arg("cluster_size_y") = 3)
|
||||||
.def("push_pedestal_frame",
|
.def("push_pedestal_frame",
|
||||||
[](ClusterFinderMT<ClusterType, uint16_t, pd_type> &self,
|
[](ClusterFinderMT<ClusterType, uint16_t, pd_type> &self,
|
||||||
py::array_t<uint16_t> frame) {
|
py::array_t<uint16_t> frame) {
|
||||||
|
|||||||
Reference in New Issue
Block a user