cluster finder (#72)

implement fixed size cluster finder algorithm 
clusterFile functions are commented and put on hold.

---------

Co-authored-by: Bechir <bechir.brahem420@gmail.com>
Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>
This commit is contained in:
Bechir Braham
2024-06-17 10:57:23 +02:00
committed by GitHub
parent 1dd361a343
commit 5b7ab5a810
33 changed files with 845 additions and 111 deletions

View File

@ -2,7 +2,7 @@
set(EXAMPLE_LIST "json_example;logger_example;numpy_read_example;multiport_example;raw_example;zmq_restream_example")
set(EXAMPLE_LIST "${EXAMPLE_LIST};mythen_example;numpy_write_example;zmq_receiver_example;zmq_sender_example;")
set(EXAMPLE_LIST "${EXAMPLE_LIST};cluster_example;zmq_multi_receiver;zmq_task_ventilator;zmq_worker;zmq_sink")
set(EXAMPLE_LIST "${EXAMPLE_LIST};testing_pedestal;")
set(EXAMPLE_LIST "${EXAMPLE_LIST};testing_pedestal;cluster_finder_example;")
foreach(example ${EXAMPLE_LIST})
add_executable(${example} ${example}.cpp)

View File

@ -7,48 +7,33 @@
using namespace aare;
int main() {
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv("AARE_ROOT_DIR"));
std::filesystem::path const fpath(PROJECT_ROOT_DIR / "data" / "clusters" / "single_frame_97_clustrers.clust");
std::filesystem::path const fpath("/mnt/sls_det_storage/moench_data/testNewFW20230714/cu_half_speed_master_4.json");
// reading a file
aare::ClusterFile cf(fpath, "r");
std::cout << "file opened " << '\n';
std::cout << "n_clusters " << cf.count() << '\n';
std::cout << "frame_number " << cf.frame() << '\n';
std::cout << "file size: " << cf.count() << '\n';
cf.seek(0); // seek to the beginning of the file (this is the default behavior of the constructor)
NDArray<double, 2> frame({10, 10});
frame = 0;
auto cluster = cf.read(97);
std::cout << "read 10 clusters" << '\n';
int offset = 0;
int data_offset = 0;
for (auto c : cluster) {
assert(c.y == offset + 200);
for (int i = 0; i < 9; i++) {
assert(c.data[i] == data_offset + i);
for (int i = 5; i < 8; i++) {
for (int j = 5; j < 8; j++) {
frame(i, j) = (i + j) % 10;
}
offset++;
data_offset += 9;
}
// writing a file
std::filesystem::path const fpath_out("/tmp/cluster_example_file.clust");
aare::ClusterFile cf_out(fpath_out, "w", ClusterFileConfig(1, 44));
std::cout << "file opened for writing" << '\n';
std::vector<Cluster> clusters;
for (int i = 0; i < 1084; i++) {
Cluster c;
c.x = i;
c.y = i + 200;
for (int j = 0; j < 9; j++) {
c.data[j] = j;
for (int i = 0; i < frame.shape(0); i++) {
for (int j = 0; j < frame.shape(1); j++) {
std::cout << frame(i, j) << " ";
}
clusters.push_back(c);
std::cout << std::endl;
}
cf_out.write(clusters);
std::cout << "wrote 10 clusters" << '\n';
cf_out.update_header();
return 0;
ClusterFinder clusterFinder(3, 3, 1, 1); // 3x3 cluster, 1 nSigma, 1 threshold
Pedestal p(10, 10);
auto clusters = clusterFinder.find_clusters(frame.span(), p);
aare::logger::info("nclusters:", clusters.size());
for (auto &cluster : clusters) {
aare::logger::info("cluster center:", cluster.to_string<double>());
}
}

View File

@ -0,0 +1,63 @@
#include "aare.hpp"
#include "aare/examples/defs.hpp"
#include <cassert>
#include <iostream>
using namespace aare;
int main() {
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv("AARE_ROOT_DIR"));
std::filesystem::path const fpath_frame("/home/l_bechir/tmp/testNewFW20230714/cu_half_speed_master_4.json");
std::filesystem::path const fpath_cluster("/home/l_bechir/tmp/testNewFW20230714/clust/cu_half_speed_d0_f0_4.clust");
auto file = RawFile(fpath_frame, "r");
logger::info("RAW file");
logger::info("file rows:", file.rows(), "cols:", file.cols());
logger::info(file.total_frames());
Frame frame(0, 0, 0);
for (auto i = 0; i < 10000; i++) {
if (file.frame_number(i) == 23389) {
logger::info("frame_number:", file.frame_number(i));
frame = file.read();
}
}
logger::info("frame", frame.rows(), frame.cols(), frame.bitdepth());
ClusterFileV2 cf(fpath_cluster, "r");
auto anna_clusters = cf.read();
logger::info("Cluster file");
logger::info("nclusters:", anna_clusters.size());
logger::info("frame_number", anna_clusters[0].frame_number);
ClusterFinder clusterFinder(3, 3, 5, 0);
Pedestal p(file.rows(), file.cols());
file.seek(0);
logger::info("Starting Pedestal calculation");
for (auto i = 0; i < 1000; i++) {
p.push(file.read().view<uint16_t>());
}
logger::info("Pedestal calculation done");
logger::info("Pedestal mean:", p.mean(0, 0), "std:", p.standard_deviation(0, 0));
logger::info("Pedestal mean:", p.mean(200, 200), "std:", p.standard_deviation(200, 200));
FileConfig cfg;
cfg.dtype = DType(typeid(double));
cfg.rows = p.rows();
cfg.cols = p.cols();
NumpyFile np_pedestal("/home/l_bechir/tmp/testNewFW20230714/pedestal.npy", "w", cfg);
cfg.dtype = DType(typeid(uint16_t));
NumpyFile np_frame("/home/l_bechir/tmp/testNewFW20230714/frame.npy", "w", cfg);
np_pedestal.write(p.mean());
np_frame.write(frame.view<uint16_t>());
auto clusters = clusterFinder.find_clusters(frame.view<uint16_t>(), p);
logger::info("nclusters:", clusters.size());
// aare::logger::info("nclusters:", clusters.size());
// for (auto &cluster : clusters) {
// aare::logger::info("cluster center:", cluster.to_string<double>());
// }
}