mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-05-02 19:20:04 +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> eta2({static_cast<int64_t>(clusters.size()), 2});
|
||||
|
||||
for (const ClusterType &cluster : clusters) {
|
||||
auto e = calculate_eta2(cluster);
|
||||
for (size_t i = 0; i < clusters.size(); i++) {
|
||||
auto e = calculate_eta2(clusters[i]);
|
||||
eta2(i, 0) = e.x;
|
||||
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<NDArray<int32_t, 2>>
|
||||
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
|
||||
be applied if set*/
|
||||
std::optional<InvertedGainMap> m_gain_map; /*Gain map to apply to the
|
||||
clusters, will be applied if set*/
|
||||
|
||||
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
|
||||
* to the clusters that pass ROI and noise_map selection. The gain map is expected to be in ADU/energy.
|
||||
* @brief Set the gain map to use when reading clusters. If set the gain map
|
||||
* 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) {
|
||||
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
|
||||
|
@ -76,8 +76,9 @@ class ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
|
||||
std::vector<T> sum() {
|
||||
std::vector<T> sums(m_data.size());
|
||||
|
||||
std::transform(m_data.begin(), m_data.end(), sums.begin(),
|
||||
[](const T &cluster) { return cluster.sum(); });
|
||||
std::transform(
|
||||
m_data.begin(), m_data.end(), sums.begin(),
|
||||
[](const ClusterType &cluster) { return cluster.sum(); });
|
||||
|
||||
return sums;
|
||||
}
|
||||
@ -90,9 +91,10 @@ class ClusterVector<Cluster<T, ClusterSizeX, ClusterSizeY, CoordType>> {
|
||||
std::vector<T> sum_2x2() {
|
||||
std::vector<T> sums_2x2(m_data.size());
|
||||
|
||||
std::transform(
|
||||
m_data.begin(), m_data.end(), sums_2x2.begin(),
|
||||
[](const T &cluster) { return cluster.max_sum_2x2().first; });
|
||||
std::transform(m_data.begin(), m_data.end(), sums_2x2.begin(),
|
||||
[](const ClusterType &cluster) {
|
||||
return cluster.max_sum_2x2().first;
|
||||
});
|
||||
|
||||
return sums_2x2;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
/************************************************
|
||||
* @file ApplyGainMap.hpp
|
||||
* @short function to apply gain map of image size to a vector of clusters
|
||||
* @file GainMap.hpp
|
||||
* @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
|
||||
@ -12,18 +13,17 @@
|
||||
|
||||
namespace aare {
|
||||
|
||||
class GainMap {
|
||||
class InvertedGainMap {
|
||||
|
||||
public:
|
||||
explicit GainMap(const NDArray<double, 2> &gain_map)
|
||||
explicit InvertedGainMap(const NDArray<double, 2> &gain_map)
|
||||
: m_gain_map(gain_map) {
|
||||
for (auto &item : m_gain_map) {
|
||||
for (auto &item : m_gain_map) {
|
||||
item = 1.0 / item;
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
explicit GainMap(const NDView<double, 2> gain_map) {
|
||||
explicit InvertedGainMap(const NDView<double, 2> gain_map) {
|
||||
m_gain_map = NDArray<double, 2>(gain_map);
|
||||
for (auto &item : m_gain_map) {
|
||||
item = 1.0 / item;
|
||||
@ -41,14 +41,18 @@ class GainMap {
|
||||
|
||||
int64_t index_cluster_center_x = ClusterSizeX / 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 &&
|
||||
cl.y < m_gain_map.shape(0) - 1) {
|
||||
for (size_t j = 0; j < ClusterSizeX * ClusterSizeY; j++) {
|
||||
size_t x = cl.x + j % ClusterSizeX - index_cluster_center_x;
|
||||
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 {
|
||||
// clear edge clusters
|
||||
|
@ -59,9 +59,6 @@ void define_cluster_file_io_bindings(py::module &m,
|
||||
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("write_frame", &ClusterFile<ClusterType>::write_frame)
|
||||
.def("__enter__", [](ClusterFile<ClusterType> &self) { return &self; })
|
||||
|
Loading…
x
Reference in New Issue
Block a user