mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-21 03:07:59 +02:00
Feature/reactivate python bindings (#74)
major changes: - add python bindings for all c++ features except network_io - changes to cross compile on windows,linux and macos - fix bugs with cluster_finder - use Dtype in Frame instead of bitdepth - remove boost::program_options and replace with our implementation - add Transforms class that applies a sequence of functions (c++ or python functions) on a Frame. - remove frame reorder and flip from SubFile.cpp. use Transforms instead - Test clusterFinder and Pedestal results in comparison with slsDetectorCalibration --------- Co-authored-by: Bechir <bechir.brahem420@gmail.com> Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
|
||||
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;cluster_finder_example;")
|
||||
set(EXAMPLE_LIST "json_example;logger_example;numpy_read_example;multiport_example;raw_example;")
|
||||
set(EXAMPLE_LIST "${EXAMPLE_LIST};mythen_example;numpy_write_example;zmq_sender_example;")
|
||||
set(EXAMPLE_LIST "${EXAMPLE_LIST};cluster_example;zmq_multi_receiver;zmq_worker;zmq_sink")
|
||||
set(EXAMPLE_LIST "${EXAMPLE_LIST};zmq_task_ventilator;zmq_restream_example;zmq_receiver_example")
|
||||
set(EXAMPLE_LIST "${EXAMPLE_LIST};testing_pedestal;cluster_finder_example;reorder_moench_example")
|
||||
|
||||
foreach(example ${EXAMPLE_LIST})
|
||||
add_executable(${example} ${example}.cpp)
|
||||
@ -11,7 +12,6 @@ foreach(example ${EXAMPLE_LIST})
|
||||
endforeach()
|
||||
|
||||
|
||||
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
|
||||
|
||||
|
||||
|
||||
|
@ -7,33 +7,26 @@
|
||||
using namespace aare;
|
||||
int main() {
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv("AARE_ROOT_DIR"));
|
||||
std::filesystem::path const fpath("/mnt/sls_det_storage/moench_data/testNewFW20230714/cu_half_speed_master_4.json");
|
||||
|
||||
NDArray<double, 2> frame({10, 10});
|
||||
frame = 0;
|
||||
|
||||
for (int i = 5; i < 8; i++) {
|
||||
for (int j = 5; j < 8; j++) {
|
||||
frame(i, j) = (i + j) % 10;
|
||||
}
|
||||
std::filesystem::path const fpath("/home/l_bechir/tmp/testNewFW20230714/cu_half_speed_master_4.json");
|
||||
auto f = File(fpath, "r");
|
||||
// calculate pedestal
|
||||
Pedestal pedestal(400,400,1000);
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
auto frame = f.read();
|
||||
pedestal.push<uint16_t>(frame);
|
||||
}
|
||||
|
||||
for (int i = 0; i < frame.shape(0); i++) {
|
||||
for (int j = 0; j < frame.shape(1); j++) {
|
||||
std::cout << frame(i, j) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
// find clusters
|
||||
ClusterFinder clusterFinder(3, 3, 5, 0);
|
||||
f.seek(0);
|
||||
std::vector<std::vector<Cluster>> clusters_vector;
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
auto frame = f.iread(i);
|
||||
auto clusters = clusterFinder.find_clusters_without_threshold(frame.view<uint16_t>(), pedestal,false);
|
||||
clusters_vector.emplace_back(clusters);
|
||||
}
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed_seconds = end-start;
|
||||
std::cout << "elapsed time: " << elapsed_seconds.count() << "s\n";
|
||||
|
||||
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>());
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ int main() {
|
||||
logger::info("RAW file");
|
||||
logger::info("file rows:", file.rows(), "cols:", file.cols());
|
||||
logger::info(file.total_frames());
|
||||
Frame frame(0, 0, 0);
|
||||
Frame frame(0, 0, Dtype::NONE);
|
||||
for (auto i = 0; i < 10000; i++) {
|
||||
if (file.frame_number(i) == 23389) {
|
||||
logger::info("frame_number:", file.frame_number(i));
|
||||
@ -41,18 +41,18 @@ int main() {
|
||||
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.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));
|
||||
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);
|
||||
auto clusters = clusterFinder.find_clusters_without_threshold(frame.view<uint16_t>(), p);
|
||||
logger::info("nclusters:", clusters.size());
|
||||
|
||||
// aare::logger::info("nclusters:", clusters.size());
|
||||
|
@ -9,10 +9,10 @@ using aare::Frame;
|
||||
|
||||
int main() {
|
||||
auto path = std::filesystem::path("/tmp/test.npy");
|
||||
auto dtype = aare::DType(typeid(uint32_t));
|
||||
auto dtype = aare::Dtype(typeid(uint32_t));
|
||||
FileConfig const cfg = {dtype, 100, 100};
|
||||
File npy(path, "w", cfg);
|
||||
Frame f(100, 100, dtype.bitdepth());
|
||||
Frame f(100, 100, dtype);
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
f.set<uint32_t>(i / 100, i % 100, i);
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ int main() {
|
||||
config.max_frames_per_file = 100;
|
||||
config.rows = 1024;
|
||||
config.cols = 512;
|
||||
config.dtype = aare::DType::UINT16;
|
||||
config.dtype = aare::Dtype::UINT16;
|
||||
File file2(path2, "w", config);
|
||||
Frame frame(1024, 512, 16);
|
||||
Frame frame(1024, 512, aare::Dtype::UINT16);
|
||||
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
for (int j = 0; j < 512; j++) {
|
||||
|
18
examples/reorder_moench_example.cpp
Normal file
18
examples/reorder_moench_example.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "aare.hpp"
|
||||
#include "aare/examples/defs.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace aare;
|
||||
|
||||
|
||||
int main() {
|
||||
std::filesystem::path const fpath("/mnt/sls_det_storage/moench_data/testNewFW20230714/cu_half_speed_master_4.json");
|
||||
File file(fpath, "r");
|
||||
|
||||
Frame frame = file.iread(0);
|
||||
std::cout << frame.rows() << " " << frame.cols() << " " << frame.bitdepth() << std::endl;
|
||||
Transforms transforms;
|
||||
transforms.add(Transforms::reorder_moench());
|
||||
transforms(frame);
|
||||
}
|
@ -11,7 +11,7 @@ using namespace aare;
|
||||
|
||||
void print_vpair(std::vector<std::pair<int, double>> &v) {
|
||||
std::cout << "[ ";
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
for (unsigned int i = 0; i < v.size(); i++) {
|
||||
std::cout << "(" << v[i].first << "," << v[i].second << "), ";
|
||||
}
|
||||
std::cout << "]" << std::endl;
|
||||
@ -19,7 +19,7 @@ void print_vpair(std::vector<std::pair<int, double>> &v) {
|
||||
int range(int min, int max, int i, int steps) { return min + (max - min) * i / steps; }
|
||||
int main() {
|
||||
const int rows = 1, cols = 1;
|
||||
double MEAN = 5.0, STD = 1.0, VAR = STD * STD, TOLERANCE = 0.1;
|
||||
double MEAN = 5.0, STD = 1.0;
|
||||
|
||||
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
|
||||
std::default_random_engine generator(seed);
|
||||
@ -53,7 +53,7 @@ int main() {
|
||||
long double sum2 = 0;
|
||||
// fill 1000 first values of pedestal
|
||||
for (int x = 0; x < 1000; x++) {
|
||||
Frame frame(rows, cols, 64);
|
||||
Frame frame(rows, cols, Dtype::DOUBLE);
|
||||
double val = distribution(generator);
|
||||
frame.set<double>(0, 0, val);
|
||||
pedestal.push<double>(frame);
|
||||
@ -63,7 +63,7 @@ int main() {
|
||||
}
|
||||
|
||||
for (int x = 0, aa = 0; x < 100000; x++, aa++) {
|
||||
Frame frame(rows, cols, 64);
|
||||
Frame frame(rows, cols, Dtype::DOUBLE);
|
||||
double val = distribution(generator);
|
||||
frame.set<double>(0, 0, val);
|
||||
pedestal.push<double>(frame);
|
||||
|
@ -1,12 +1,10 @@
|
||||
#include "aare.hpp"
|
||||
#include "aare/examples/defs.hpp"
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <cassert>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
using namespace aare;
|
||||
namespace po = boost::program_options;
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
@ -1,39 +1,19 @@
|
||||
#include "aare.hpp"
|
||||
#include "aare/examples/defs.hpp"
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <cassert>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
using namespace aare;
|
||||
namespace po = boost::program_options;
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
aare::logger::set_verbosity(aare::logger::DEBUG);
|
||||
|
||||
po::options_description desc("options");
|
||||
desc.add_options()("help", "produce help message")("port,p", po::value<uint16_t>()->default_value(5555),
|
||||
"port number");
|
||||
po::positional_options_description pd;
|
||||
pd.add("port", 1);
|
||||
po::variables_map vm;
|
||||
try {
|
||||
auto parsed = po::command_line_parser(argc, argv).options(desc).positional(pd).run();
|
||||
po::store(parsed, vm);
|
||||
po::notify(vm);
|
||||
|
||||
} catch (const boost::program_options::error &e) {
|
||||
cout << e.what() << "\n";
|
||||
cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
if (vm.count("help")) {
|
||||
cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto port = vm["port"].as<uint16_t>();
|
||||
ArgParser parser("Zmq receiver example");
|
||||
parser.add_option("port", "p", true, false, "5555", "port number");
|
||||
auto args = parser.parse(argc, argv);
|
||||
int port = std::stoi(args["port"]);
|
||||
|
||||
std::string const endpoint = "tcp://127.0.0.1:" + std::to_string(port);
|
||||
aare::ZmqSocketReceiver socket(endpoint);
|
||||
@ -43,7 +23,7 @@ int main(int argc, char **argv) {
|
||||
aare::logger::info("Received ", v.size(), " frames");
|
||||
aare::logger::info("acquisition:", v[0].header.acqIndex);
|
||||
aare::logger::info("Header size:", v[0].header.to_string().size());
|
||||
aare::logger::info("Frame size:", v[0].frame.size());
|
||||
aare::logger::info("Frame size:", v[0].frame.bytes());
|
||||
aare::logger::info("Header:", v[0].header.to_string());
|
||||
|
||||
// for (ZmqFrame zmq_frame : v) {
|
||||
|
@ -1,56 +1,26 @@
|
||||
#include "aare.hpp"
|
||||
#include "aare/examples/defs.hpp"
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
using namespace aare;
|
||||
using namespace std;
|
||||
namespace po = boost::program_options;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
aare::logger::set_verbosity(aare::logger::DEBUG);
|
||||
|
||||
po::options_description desc("Allowed options");
|
||||
desc.add_options()("help", "produce help message")("file,f", po::value<string>(), "input file")(
|
||||
"port,p", po::value<uint16_t>(), "port number")("fps", po::value<uint16_t>()->default_value(1),
|
||||
"frames per second (default 1)")("loop,l",
|
||||
"loop over the file");
|
||||
po::positional_options_description pd;
|
||||
pd.add("file", -1);
|
||||
ArgParser parser("Zmq restream example");
|
||||
parser.add_option("file", "f", true, true, "", "input file");
|
||||
parser.add_option("port", "p", true, true, "", "port number");
|
||||
parser.add_option("fps", "fp", true, false, "1", "frames per second");
|
||||
parser.add_option("loop", "l", false, false, "", "loop over the file");
|
||||
|
||||
po::variables_map vm;
|
||||
try {
|
||||
auto parsed = po::command_line_parser(argc, argv).options(desc).positional(pd).run();
|
||||
po::store(parsed, vm);
|
||||
po::notify(vm);
|
||||
|
||||
} catch (const boost::program_options::error &e) {
|
||||
cout << e.what() << "\n";
|
||||
cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (vm.count("help")) {
|
||||
cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
if (vm.count("file") != 1) {
|
||||
aare::logger::error("file is required");
|
||||
cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
if (vm.count("port") != 1) {
|
||||
aare::logger::error("port is required");
|
||||
cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string const path = vm["file"].as<string>();
|
||||
uint16_t const port = vm["port"].as<uint16_t>();
|
||||
bool const loop = vm.count("loop") == 1;
|
||||
uint16_t const fps = vm["fps"].as<uint16_t>();
|
||||
auto args = parser.parse(argc, argv);
|
||||
std::string const path = args["file"];
|
||||
uint16_t const port = std::stoi(args["port"]);
|
||||
bool const loop = args["loop"] == "1";
|
||||
uint16_t const fps = std::stoi(args["fps"]);
|
||||
|
||||
aare::logger::debug("ARGS: file:", path, "port:", port, "fps:", fps, "loop:", loop);
|
||||
auto d = round<std::chrono::milliseconds>(std::chrono::duration<double>{1. / fps});
|
||||
@ -78,7 +48,7 @@ int main(int argc, char **argv) {
|
||||
header.shape.row = frame.rows();
|
||||
header.shape.col = frame.cols();
|
||||
header.bitmode = frame.bitdepth();
|
||||
header.size = frame.size();
|
||||
header.size = frame.bytes();
|
||||
|
||||
sender.send({header, frame});
|
||||
std::this_thread::sleep_for(d);
|
||||
|
@ -4,7 +4,11 @@
|
||||
#include <ctime> // std::time
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#include <unistd.h> // sleep
|
||||
|
||||
// sleep
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
using namespace aare;
|
||||
|
||||
int main() {
|
||||
@ -12,7 +16,7 @@ int main() {
|
||||
std::string const endpoint = "tcp://*:5555";
|
||||
aare::ZmqSocketSender socket(endpoint);
|
||||
socket.bind();
|
||||
Frame frame(1024, 1024, sizeof(uint32_t) * 8);
|
||||
Frame frame(1024, 1024, Dtype::UINT32);
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
for (int j = 0; j < 1024; j++) {
|
||||
frame.set(i, j, i + j);
|
||||
@ -26,6 +30,7 @@ int main() {
|
||||
std::vector<ZmqFrame> zmq_frames;
|
||||
// send two exact frames
|
||||
|
||||
std::chrono::milliseconds sleep_time(1); // or whatever
|
||||
int acqid = 0;
|
||||
while (true) {
|
||||
zmq_frames.clear();
|
||||
@ -34,7 +39,7 @@ int main() {
|
||||
|
||||
aare::logger::info("acquisition:", header.acqIndex);
|
||||
aare::logger::info("Header size:", header.to_string().size());
|
||||
aare::logger::info("Frame size:", frame.size());
|
||||
aare::logger::info("Frame size:", frame.bytes());
|
||||
aare::logger::info("Number of frames:", n_frames);
|
||||
|
||||
for (size_t i = 0; i < n_frames; i++) {
|
||||
@ -42,7 +47,7 @@ int main() {
|
||||
}
|
||||
size_t const rc = socket.send(zmq_frames);
|
||||
aare::logger::info("Sent bytes", rc);
|
||||
sleep(1);
|
||||
std::this_thread::sleep_for(sleep_time);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -2,12 +2,10 @@
|
||||
#include "aare/examples/defs.hpp"
|
||||
|
||||
#include "zmq.h"
|
||||
#include <boost/program_options.hpp>
|
||||
#include <cassert>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
using namespace aare;
|
||||
namespace po = boost::program_options;
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
@ -1,39 +1,19 @@
|
||||
#include "aare.hpp"
|
||||
#include "aare/examples/defs.hpp"
|
||||
|
||||
#include "zmq.h"
|
||||
#include <boost/program_options.hpp>
|
||||
#include <cassert>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
using namespace aare;
|
||||
namespace po = boost::program_options;
|
||||
using namespace std;
|
||||
|
||||
string setup(int argc, char **argv) {
|
||||
logger::set_verbosity(logger::DEBUG);
|
||||
po::options_description desc("options");
|
||||
desc.add_options()("help", "produce help message")("port,p", po::value<uint16_t>()->default_value(5555),
|
||||
"port number");
|
||||
po::positional_options_description pd;
|
||||
pd.add("port", 1);
|
||||
po::variables_map vm;
|
||||
try {
|
||||
auto parsed = po::command_line_parser(argc, argv).options(desc).positional(pd).run();
|
||||
po::store(parsed, vm);
|
||||
po::notify(vm);
|
||||
|
||||
} catch (const boost::program_options::error &e) {
|
||||
cout << e.what() << "\n";
|
||||
cout << desc << "\n";
|
||||
exit(1);
|
||||
}
|
||||
if (vm.count("help")) {
|
||||
cout << desc << "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
auto port = vm["port"].as<uint16_t>();
|
||||
ArgParser parser("Zmq task ventilator");
|
||||
parser.add_option("port", "p", true, false, "5555", "port number");
|
||||
auto args = parser.parse(argc, argv);
|
||||
int port = std::stoi(args["port"]);
|
||||
|
||||
return "tcp://127.0.0.1:" + to_string(port);
|
||||
}
|
||||
@ -55,7 +35,7 @@ int process(const std::string &endpoint) {
|
||||
logger::info(zframe.header.to_string());
|
||||
|
||||
// 3. create task
|
||||
Task *task = Task::init(zframe.frame.data(), zframe.frame.size());
|
||||
Task *task = Task::init(zframe.frame.data(), zframe.frame.bytes());
|
||||
task->opcode = (size_t)Task::Operation::PEDESTAL;
|
||||
task->id = zframe.header.frameNumber;
|
||||
|
||||
|
@ -3,12 +3,10 @@
|
||||
#include "aare/examples/defs.hpp"
|
||||
|
||||
#include "zmq.h"
|
||||
#include <boost/program_options.hpp>
|
||||
#include <cassert>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
using namespace aare;
|
||||
namespace po = boost::program_options;
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
Reference in New Issue
Block a user