mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-05-03 11:40:02 +02:00
changed name of GainMap to InvertedGainMap
This commit is contained in:
parent
f06e722dce
commit
eb6862ff99
@ -40,8 +40,8 @@ template <typename ClusterType,
|
|||||||
NDArray<double, 2> calculate_eta2(const ClusterVector<ClusterType> &clusters) {
|
NDArray<double, 2> calculate_eta2(const ClusterVector<ClusterType> &clusters) {
|
||||||
NDArray<double, 2> eta2({static_cast<int64_t>(clusters.size()), 2});
|
NDArray<double, 2> eta2({static_cast<int64_t>(clusters.size()), 2});
|
||||||
|
|
||||||
for (const ClusterType &cluster : clusters) {
|
for (size_t i = 0; i < clusters.size(); i++) {
|
||||||
auto e = calculate_eta2(cluster);
|
auto e = calculate_eta2(clusters[i]);
|
||||||
eta2(i, 0) = e.x;
|
eta2(i, 0) = e.x;
|
||||||
eta2(i, 1) = e.y;
|
eta2(i, 1) = e.y;
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ class ClusterFile {
|
|||||||
std::optional<ROI> m_roi; /*Region of interest, will be applied if set*/
|
std::optional<ROI> m_roi; /*Region of interest, will be applied if set*/
|
||||||
std::optional<NDArray<int32_t, 2>>
|
std::optional<NDArray<int32_t, 2>>
|
||||||
m_noise_map; /*Noise map to cut photons, will be applied if set*/
|
m_noise_map; /*Noise map to cut photons, will be applied if set*/
|
||||||
std::optional<GainMap> m_gain_map; /*Gain map to apply to the clusters, will
|
std::optional<InvertedGainMap> m_gain_map; /*Gain map to apply to the
|
||||||
be applied if set*/
|
clusters, will be applied if set*/
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -160,16 +160,21 @@ class ClusterFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the gain map to use when reading clusters. If set the gain map will be applied
|
* @brief Set the gain map to use when reading clusters. If set the gain map
|
||||||
* to the clusters that pass ROI and noise_map selection. The gain map is expected to be in ADU/energy.
|
* will be applied to the clusters that pass ROI and noise_map selection.
|
||||||
|
* The gain map is expected to be in ADU/energy.
|
||||||
*/
|
*/
|
||||||
void set_gain_map(const NDView<double, 2> gain_map) {
|
void set_gain_map(const NDView<double, 2> gain_map) {
|
||||||
m_gain_map = GainMap(gain_map);
|
m_gain_map = InvertedGainMap(gain_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_gain_map(const GainMap &gain_map) { m_gain_map = gain_map; }
|
void set_gain_map(const InvertedGainMap &gain_map) {
|
||||||
|
m_gain_map = gain_map;
|
||||||
|
}
|
||||||
|
|
||||||
void set_gain_map(const GainMap &&gain_map) { m_gain_map = gain_map; }
|
void set_gain_map(const InvertedGainMap &&gain_map) {
|
||||||
|
m_gain_map = gain_map;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Close the file. If not closed the file will be
|
* @brief Close the file. If not closed the file will be
|
||||||
|
@ -76,8 +76,9 @@ class ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
|
|||||||
std::vector<T> sum() {
|
std::vector<T> sum() {
|
||||||
std::vector<T> sums(m_data.size());
|
std::vector<T> sums(m_data.size());
|
||||||
|
|
||||||
std::transform(m_data.begin(), m_data.end(), sums.begin(),
|
std::transform(
|
||||||
[](const T &cluster) { return cluster.sum(); });
|
m_data.begin(), m_data.end(), sums.begin(),
|
||||||
|
[](const ClusterType &cluster) { return cluster.sum(); });
|
||||||
|
|
||||||
return sums;
|
return sums;
|
||||||
}
|
}
|
||||||
@ -90,9 +91,10 @@ class ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
|
|||||||
std::vector<T> sum_2x2() {
|
std::vector<T> sum_2x2() {
|
||||||
std::vector<T> sums_2x2(m_data.size());
|
std::vector<T> 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(),
|
[](const ClusterType &cluster) {
|
||||||
[](const T &cluster) { return cluster.max_sum_2x2().first; });
|
return cluster.max_sum_2x2().first;
|
||||||
|
});
|
||||||
|
|
||||||
return sums_2x2;
|
return sums_2x2;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/************************************************
|
/************************************************
|
||||||
* @file ApplyGainMap.hpp
|
* @file GainMap.hpp
|
||||||
* @short function to apply gain map of image size to a vector of clusters
|
* @short function to apply gain map of image size to a vector of clusters -
|
||||||
|
*note stored gainmap is inverted for efficient aaplication to images
|
||||||
***********************************************/
|
***********************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -12,18 +13,17 @@
|
|||||||
|
|
||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
class GainMap {
|
class InvertedGainMap {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GainMap(const NDArray<double, 2> &gain_map)
|
explicit InvertedGainMap(const NDArray<double, 2> &gain_map)
|
||||||
: m_gain_map(gain_map) {
|
: m_gain_map(gain_map) {
|
||||||
for (auto &item : m_gain_map) {
|
for (auto &item : m_gain_map) {
|
||||||
item = 1.0 / item;
|
item = 1.0 / item;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
};
|
explicit InvertedGainMap(const NDView<double, 2> gain_map) {
|
||||||
|
|
||||||
explicit GainMap(const NDView<double, 2> gain_map) {
|
|
||||||
m_gain_map = NDArray<double, 2>(gain_map);
|
m_gain_map = NDArray<double, 2>(gain_map);
|
||||||
for (auto &item : m_gain_map) {
|
for (auto &item : m_gain_map) {
|
||||||
item = 1.0 / item;
|
item = 1.0 / item;
|
||||||
@ -41,14 +41,18 @@ class GainMap {
|
|||||||
|
|
||||||
int64_t index_cluster_center_x = ClusterSizeX / 2;
|
int64_t index_cluster_center_x = ClusterSizeX / 2;
|
||||||
int64_t index_cluster_center_y = ClusterSizeY / 2;
|
int64_t index_cluster_center_y = ClusterSizeY / 2;
|
||||||
for (T &cl : clustervec) {
|
for (size_t i = 0; i < clustervec.size(); i++) {
|
||||||
|
auto &cl = clustervec[i];
|
||||||
|
|
||||||
if (cl.x > 0 && cl.y > 0 && cl.x < m_gain_map.shape(1) - 1 &&
|
if (cl.x > 0 && cl.y > 0 && cl.x < m_gain_map.shape(1) - 1 &&
|
||||||
cl.y < m_gain_map.shape(0) - 1) {
|
cl.y < m_gain_map.shape(0) - 1) {
|
||||||
for (size_t j = 0; j < ClusterSizeX * ClusterSizeY; j++) {
|
for (size_t j = 0; j < ClusterSizeX * ClusterSizeY; j++) {
|
||||||
size_t x = cl.x + j % ClusterSizeX - index_cluster_center_x;
|
size_t x = cl.x + j % ClusterSizeX - index_cluster_center_x;
|
||||||
size_t y = cl.y + j / ClusterSizeX - index_cluster_center_y;
|
size_t y = cl.y + j / ClusterSizeX - index_cluster_center_y;
|
||||||
cl.data[j] = static_cast<T>(cl.data[j] * m_gain_map(y, x)); //cast after conversion to keep precision
|
cl.data[j] = static_cast<T>(
|
||||||
|
static_cast<double>(cl.data[j]) *
|
||||||
|
m_gain_map(
|
||||||
|
y, x)); // cast after conversion to keep precision
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// clear edge clusters
|
// clear edge clusters
|
||||||
|
@ -59,9 +59,6 @@ void define_cluster_file_io_bindings(py::module &m,
|
|||||||
self.set_gain_map(view);
|
self.set_gain_map(view);
|
||||||
})
|
})
|
||||||
|
|
||||||
// void set_gain_map(const GainMap &gain_map); //TODO do i need a
|
|
||||||
// gainmap constructor?
|
|
||||||
|
|
||||||
.def("close", &ClusterFile<ClusterType>::close)
|
.def("close", &ClusterFile<ClusterType>::close)
|
||||||
.def("write_frame", &ClusterFile<ClusterType>::write_frame)
|
.def("write_frame", &ClusterFile<ClusterType>::write_frame)
|
||||||
.def("__enter__", [](ClusterFile<ClusterType> &self) { return &self; })
|
.def("__enter__", [](ClusterFile<ClusterType> &self) { return &self; })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user