mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-02-19 15:48:43 +01:00
index now returns enum type
This commit is contained in:
@@ -3,16 +3,10 @@
|
|||||||
#include "aare/Cluster.hpp"
|
#include "aare/Cluster.hpp"
|
||||||
#include "aare/ClusterVector.hpp"
|
#include "aare/ClusterVector.hpp"
|
||||||
#include "aare/NDArray.hpp"
|
#include "aare/NDArray.hpp"
|
||||||
|
#include "aare/defs.hpp"
|
||||||
|
|
||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
enum class corner : int {
|
|
||||||
cTopLeft = 0,
|
|
||||||
cTopRight = 1,
|
|
||||||
cBottomLeft = 2,
|
|
||||||
cBottomRight = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class pixel : int {
|
enum class pixel : int {
|
||||||
pBottomLeft = 0,
|
pBottomLeft = 0,
|
||||||
pBottom = 1,
|
pBottom = 1,
|
||||||
@@ -28,7 +22,7 @@ enum class pixel : int {
|
|||||||
template <typename T> struct Eta2 {
|
template <typename T> struct Eta2 {
|
||||||
double x;
|
double x;
|
||||||
double y;
|
double y;
|
||||||
int c{0};
|
corner c{0};
|
||||||
T sum;
|
T sum;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -66,11 +60,11 @@ calculate_eta2(const Cluster<T, ClusterSizeX, ClusterSizeY, CoordType> &cl) {
|
|||||||
(ClusterSizeX / 2) + (ClusterSizeY / 2) * ClusterSizeX;
|
(ClusterSizeX / 2) + (ClusterSizeY / 2) * ClusterSizeX;
|
||||||
|
|
||||||
auto max_sum = cl.max_sum_2x2();
|
auto max_sum = cl.max_sum_2x2();
|
||||||
eta.sum = max_sum.first;
|
eta.sum = max_sum.sum;
|
||||||
int c = max_sum.second;
|
corner c = max_sum.index;
|
||||||
|
|
||||||
// subcluster top right from center
|
// subcluster top right from center
|
||||||
switch (static_cast<corner>(c)) {
|
switch (c) {
|
||||||
case (corner::cTopLeft):
|
case (corner::cTopLeft):
|
||||||
if ((cl.data[cluster_center_index - 1] +
|
if ((cl.data[cluster_center_index - 1] +
|
||||||
cl.data[cluster_center_index]) != 0)
|
cl.data[cluster_center_index]) != 0)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ struct Cluster {
|
|||||||
* @return photon energy of subcluster, 2x2 subcluster index relative to
|
* @return photon energy of subcluster, 2x2 subcluster index relative to
|
||||||
* cluster center
|
* cluster center
|
||||||
*/
|
*/
|
||||||
Sum_index_pair<T, int> max_sum_2x2() const {
|
Sum_index_pair<T, corner> max_sum_2x2() const {
|
||||||
|
|
||||||
if constexpr (cluster_size_x == 3 && cluster_size_y == 3) {
|
if constexpr (cluster_size_x == 3 && cluster_size_y == 3) {
|
||||||
std::array<T, 4> sum_2x2_subclusters;
|
std::array<T, 4> sum_2x2_subclusters;
|
||||||
@@ -57,10 +57,11 @@ struct Cluster {
|
|||||||
int index = std::max_element(sum_2x2_subclusters.begin(),
|
int index = std::max_element(sum_2x2_subclusters.begin(),
|
||||||
sum_2x2_subclusters.end()) -
|
sum_2x2_subclusters.end()) -
|
||||||
sum_2x2_subclusters.begin();
|
sum_2x2_subclusters.begin();
|
||||||
return Sum_index_pair<T, int>{sum_2x2_subclusters[index], index};
|
return Sum_index_pair<T, corner>{sum_2x2_subclusters[index],
|
||||||
|
corner{index}};
|
||||||
} else if constexpr (cluster_size_x == 2 && cluster_size_y == 2) {
|
} else if constexpr (cluster_size_x == 2 && cluster_size_y == 2) {
|
||||||
return Sum_index_pair<T, int>{data[0] + data[1] + data[2] + data[3],
|
return Sum_index_pair<T, corner>{
|
||||||
0};
|
data[0] + data[1] + data[2] + data[3], corner{0}};
|
||||||
} else {
|
} else {
|
||||||
constexpr size_t cluster_center_index =
|
constexpr size_t cluster_center_index =
|
||||||
(ClusterSizeX / 2) + (ClusterSizeY / 2) * ClusterSizeX;
|
(ClusterSizeX / 2) + (ClusterSizeY / 2) * ClusterSizeX;
|
||||||
@@ -99,7 +100,8 @@ struct Cluster {
|
|||||||
int index = std::max_element(sum_2x2_subcluster.begin(),
|
int index = std::max_element(sum_2x2_subcluster.begin(),
|
||||||
sum_2x2_subcluster.end()) -
|
sum_2x2_subcluster.end()) -
|
||||||
sum_2x2_subcluster.begin();
|
sum_2x2_subcluster.begin();
|
||||||
return Sum_index_pair<T, int>{sum_2x2_subcluster[index], index};
|
return Sum_index_pair<T, corner>{sum_2x2_subcluster[index],
|
||||||
|
corner{index}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -127,8 +129,8 @@ reduce_to_2x2(const Cluster<T, ClusterSizeX, ClusterSizeY, CoordType> &c) {
|
|||||||
(ClusterSizeX / 2) + (ClusterSizeY / 2) * ClusterSizeX;
|
(ClusterSizeX / 2) + (ClusterSizeY / 2) * ClusterSizeX;
|
||||||
|
|
||||||
int16_t index_bottom_left_max_2x2_subcluster =
|
int16_t index_bottom_left_max_2x2_subcluster =
|
||||||
(int(index / (ClusterSizeX - 1))) * ClusterSizeX +
|
(int(static_cast<int>(index) / (ClusterSizeX - 1))) * ClusterSizeX +
|
||||||
index % (ClusterSizeX - 1);
|
static_cast<int>(index) % (ClusterSizeX - 1);
|
||||||
|
|
||||||
result.x =
|
result.x =
|
||||||
c.x + (index_bottom_left_max_2x2_subcluster - cluster_center_index) %
|
c.x + (index_bottom_left_max_2x2_subcluster - cluster_center_index) %
|
||||||
@@ -151,22 +153,22 @@ Cluster<T, 2, 2, int16_t> reduce_to_2x2(const Cluster<T, 3, 3, int16_t> &c) {
|
|||||||
|
|
||||||
auto [s, i] = c.max_sum_2x2();
|
auto [s, i] = c.max_sum_2x2();
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case corner::cTopLeft:
|
||||||
result.x = c.x - 1;
|
result.x = c.x - 1;
|
||||||
result.y = c.y + 1;
|
result.y = c.y + 1;
|
||||||
result.data = {c.data[0], c.data[1], c.data[3], c.data[4]};
|
result.data = {c.data[0], c.data[1], c.data[3], c.data[4]};
|
||||||
break;
|
break;
|
||||||
case 1:
|
case corner::cTopRight:
|
||||||
result.x = c.x;
|
result.x = c.x;
|
||||||
result.y = c.y + 1;
|
result.y = c.y + 1;
|
||||||
result.data = {c.data[1], c.data[2], c.data[4], c.data[5]};
|
result.data = {c.data[1], c.data[2], c.data[4], c.data[5]};
|
||||||
break;
|
break;
|
||||||
case 2:
|
case corner::cBottomLeft:
|
||||||
result.x = c.x - 1;
|
result.x = c.x - 1;
|
||||||
result.y = c.y;
|
result.y = c.y;
|
||||||
result.data = {c.data[3], c.data[4], c.data[6], c.data[7]};
|
result.data = {c.data[3], c.data[4], c.data[6], c.data[7]};
|
||||||
break;
|
break;
|
||||||
case 3:
|
case corner::cBottomRight:
|
||||||
result.x = c.x;
|
result.x = c.x;
|
||||||
result.y = c.y;
|
result.y = c.y;
|
||||||
result.data = {c.data[4], c.data[5], c.data[7], c.data[8]};
|
result.data = {c.data[4], c.data[5], c.data[7], c.data[8]};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "aare/ClusterFinderMT.hpp"
|
#include "aare/ClusterFinderMT.hpp"
|
||||||
#include "aare/ClusterVector.hpp"
|
#include "aare/ClusterVector.hpp"
|
||||||
#include "aare/ProducerConsumerQueue.hpp"
|
#include "aare/ProducerConsumerQueue.hpp"
|
||||||
|
#include "aare/defs.hpp"
|
||||||
|
|
||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
|
|||||||
@@ -438,8 +438,8 @@ bool ClusterFile<ClusterType, Enable>::is_selected(ClusterType &cl) {
|
|||||||
|
|
||||||
if (m_noise_map) {
|
if (m_noise_map) {
|
||||||
auto sum_1x1 = cl.data[cluster_center_index]; // central pixel
|
auto sum_1x1 = cl.data[cluster_center_index]; // central pixel
|
||||||
auto sum_2x2 = cl.max_sum_2x2().first; // highest sum of 2x2 subclusters
|
auto sum_2x2 = cl.max_sum_2x2().sum; // highest sum of 2x2 subclusters
|
||||||
auto total_sum = cl.sum(); // sum of all pixels
|
auto total_sum = cl.sum(); // sum of all pixels
|
||||||
|
|
||||||
auto noise =
|
auto noise =
|
||||||
(*m_noise_map)(cl.y, cl.x); // TODO! check if this is correct
|
(*m_noise_map)(cl.y, cl.x); // TODO! check if this is correct
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ class ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
|
|||||||
* each cluster
|
* each cluster
|
||||||
* @return vector of sums index pairs for each cluster
|
* @return vector of sums index pairs for each cluster
|
||||||
*/
|
*/
|
||||||
std::vector<Sum_index_pair<T, int>> sum_2x2() {
|
std::vector<Sum_index_pair<T, corner>> sum_2x2() {
|
||||||
std::vector<Sum_index_pair<T, int>> sums_2x2(m_data.size());
|
std::vector<Sum_index_pair<T, corner>> sums_2x2(m_data.size());
|
||||||
|
|
||||||
std::transform(
|
std::transform(
|
||||||
m_data.begin(), m_data.end(), sums_2x2.begin(),
|
m_data.begin(), m_data.end(), sums_2x2.begin(),
|
||||||
|
|||||||
@@ -337,6 +337,13 @@ template <typename T1, typename T2> struct Sum_index_pair {
|
|||||||
T2 index;
|
T2 index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class corner : int {
|
||||||
|
cTopLeft = 0,
|
||||||
|
cTopRight = 1,
|
||||||
|
cBottomLeft = 2,
|
||||||
|
cBottomRight = 3
|
||||||
|
};
|
||||||
|
|
||||||
enum class TimingMode { Auto, Trigger };
|
enum class TimingMode { Auto, Trigger };
|
||||||
enum class FrameDiscardPolicy { NoDiscard, Discard, DiscardPartial };
|
enum class FrameDiscardPolicy { NoDiscard, Discard, DiscardPartial };
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,9 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#define PYBIND11_DETAILED_ERROR_MESSAGES
|
|
||||||
#define PYBIND11_DISABLE_STL_CONTAINERS
|
|
||||||
#include <pybind11/pybind11.h>
|
#include <pybind11/pybind11.h>
|
||||||
// #include <pybind11/stl.h>
|
#include <pybind11/stl.h>
|
||||||
// #include <pybind11/stl_bind.h>
|
#include <pybind11/stl_bind.h>
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
using pd_type = double;
|
using pd_type = double;
|
||||||
@@ -49,31 +47,10 @@ void define_ClusterVector(py::module &m, const std::string &typestr) {
|
|||||||
})
|
})
|
||||||
.def("sum_2x2",
|
.def("sum_2x2",
|
||||||
[](ClusterVector<ClusterType> &self) {
|
[](ClusterVector<ClusterType> &self) {
|
||||||
// auto *vec =
|
auto *vec = new std::vector<Sum_index_pair<Type, corner>>(
|
||||||
// new std::vector<Sum_index_pair<Type, int>>(self.sum_2x2());
|
self.sum_2x2());
|
||||||
|
|
||||||
/*
|
return return_vector(vec);
|
||||||
py::capsule free_when_done(vec, [](void *f) {
|
|
||||||
std::vector<std::pair<Type, int>> *foo =
|
|
||||||
reinterpret_cast<std::vector<std::pair<Type, int>> *>(
|
|
||||||
f);
|
|
||||||
delete foo;
|
|
||||||
});
|
|
||||||
|
|
||||||
py::buffer result(
|
|
||||||
vec->data(),
|
|
||||||
static_cast<py::ssize_t>(sizeof(std::pair<Type, int>)),
|
|
||||||
fmt::format("T{{{}:sum:i:index}}",
|
|
||||||
py::format_descriptor<Type>::format()),
|
|
||||||
static_cast<py::ssize_t>(1),
|
|
||||||
std::vector<py::ssize_t>{
|
|
||||||
static_cast<py::ssize_t>(vec->size())},
|
|
||||||
std::vector<py::ssize_t>{static_cast<py::ssize_t>(
|
|
||||||
sizeof(std::pair<Type, int>))});
|
|
||||||
//,static_cast<py::object>(free_when_done));
|
|
||||||
*/
|
|
||||||
|
|
||||||
return self.sum_2x2(); // return_vector(vec);
|
|
||||||
})
|
})
|
||||||
.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)
|
||||||
|
|||||||
@@ -130,4 +130,11 @@ PYBIND11_MODULE(_aare, m) {
|
|||||||
m, "Sum_index_pair_i",
|
m, "Sum_index_pair_i",
|
||||||
fmt::format("T{{{}:sum:i:index}}",
|
fmt::format("T{{{}:sum:i:index}}",
|
||||||
py::format_descriptor<double>::format()));
|
py::format_descriptor<double>::format()));
|
||||||
|
|
||||||
|
using Sum_index_pair_d = Sum_index_pair<double, corner>;
|
||||||
|
PYBIND11_NUMPY_DTYPE(Sum_index_pair_d, sum, index);
|
||||||
|
using Sum_index_pair_f = Sum_index_pair<float, corner>;
|
||||||
|
PYBIND11_NUMPY_DTYPE(Sum_index_pair_f, sum, index);
|
||||||
|
using Sum_index_pair_i = Sum_index_pair<int, corner>;
|
||||||
|
PYBIND11_NUMPY_DTYPE(Sum_index_pair_i, sum, index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ def test_max_2x2_sum():
|
|||||||
assert cv.size == 2
|
assert cv.size == 2
|
||||||
max_2x2 = cv.sum_2x2()
|
max_2x2 = cv.sum_2x2()
|
||||||
assert max_2x2.size == 2
|
assert max_2x2.size == 2
|
||||||
print(max_2x2[0])
|
assert max_2x2[0]["sum"] == 8
|
||||||
|
assert max_2x2[0]["index"] == 2
|
||||||
|
|
||||||
|
|
||||||
def test_make_a_hitmap_from_cluster_vector():
|
def test_make_a_hitmap_from_cluster_vector():
|
||||||
|
|||||||
Reference in New Issue
Block a user