From 1c7b9b7121e6b31a9a59405e81a408f53d7baa45 Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 20 Jun 2025 08:44:06 +0200 Subject: [PATCH] added flatfield creation test --- acquire_flatfield_data.py | 64 +++++++++++++++++++ include/aare/FlatField.hpp | 8 ++- include/aare/MythenDetectorSpecifications.hpp | 13 +++- src/AngleCalibration.test.cpp | 40 ++++++++++-- 4 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 acquire_flatfield_data.py diff --git a/acquire_flatfield_data.py b/acquire_flatfield_data.py new file mode 100644 index 0000000..63af684 --- /dev/null +++ b/acquire_flatfield_data.py @@ -0,0 +1,64 @@ +from slsdet import Mythen3,timingMode,detectorSettings,runStatus,dacIndex,scanParameters +#from patterntools.zmqreceiver import ZmqReceiver +#from detConf_module import * +import numpy as np +from slsdet.lookup import view, find +from epics import caput, caget +import time + + +d = Mythen3() +#d.detsize = [10, 1] + +d.hostname = 'localhost:2000+localhost:2002' + +d.rx_hostname = 'localhost' + +#d.rx_tcpport = 2012 + +d.udp_dstport = 5006 + +d.udp_dstip = 'auto' + +d.udp_srcip = 'auto' + +#rx=makeReceiver(d) + +nmod=len(d.hostname) +print("num modules: ", nmod) + +d.frames = 3 +d.exptime = 5 + +d.fwrite=1 +#d.counters = [0, 1] +print(d.counters) + +d.fpath = "~/Documents/tmp/Flatfieldacquisition" +d.fwrite = 1 + +#where do i set the strips? +#d.detsize = 2 do I have to set this + +d.startReceiver() +d.startDetector() +for angle in [87,2]: + d.fname = 'run_'+str(angle) + caput('BL11I-MO-DIFF-01:DELTA.VAL',angle,wait=False) + print("moving detector to ",angle) + d.acquire() + time.sleep(d.exptime) + while d.status != runStatus.IDLE: + time.sleep(0.01) + + nf=np.min(d.rx_framescaught) + ang=caget('BL11I-MO-DIFF-01:DELTA.RBV') + print("angle is: ", ang) + print("caught frames: ", nf) + +d.stopReceiver() + +#dd, hh = rx[imod].receive_one_frame() what is this - does this exist in cpp? + + + diff --git a/include/aare/FlatField.hpp b/include/aare/FlatField.hpp index 989f43b..367cf7c 100644 --- a/include/aare/FlatField.hpp +++ b/include/aare/FlatField.hpp @@ -61,15 +61,17 @@ class FlatField { std::string filename = file_in_path.path().filename().string(); if (filename.find("master") != std::string::npos) { - File f(filename); + File f(file_in_path); auto frames = f.read_n(f.total_frames()); for (const auto &frame : frames) { if (frame.rows() * frame.cols() != - mythen_detector->num_strips()) { + mythen_detector->num_strips() * + mythen_detector->num_counters()) { throw std::runtime_error(fmt::format( "sizes mismatch. Expect a size of " "{} - frame has a size of {}", - mythen_detector->num_strips(), + mythen_detector->num_strips() * + mythen_detector->num_counters(), frame.rows() * frame.cols())); } for (ssize_t row = 0; row < frame.rows(); ++row) diff --git a/include/aare/MythenDetectorSpecifications.hpp b/include/aare/MythenDetectorSpecifications.hpp index f93be95..0466833 100644 --- a/include/aare/MythenDetectorSpecifications.hpp +++ b/include/aare/MythenDetectorSpecifications.hpp @@ -30,9 +30,10 @@ class MythenDetectorSpecifications { MythenDetectorSpecifications(const size_t max_modules, const double exposure_time, - const double bloffset) - : max_modules_(max_modules), exposure_time_(exposure_time), - bloffset_(bloffset) { + const double num_counters = 1, + double bloffset = 1.532) + : max_modules_(max_modules), num_counters_(num_counters), + exposure_time_(exposure_time), bloffset_(bloffset) { num_strips_ = max_modules_ * strips_per_module_; num_connected_modules_ = max_modules_; @@ -44,6 +45,7 @@ class MythenDetectorSpecifications { std::array{static_cast(max_modules_)}, true); } + // TODO templated on filereader void read_bad_channels_from_file(const std::string &filename) { std::string line; @@ -73,6 +75,7 @@ class MythenDetectorSpecifications { } } + // TODO template on filereader void read_unconnected_modules_from_file(const std::string &filename) { std::string line; @@ -112,6 +115,8 @@ class MythenDetectorSpecifications { size_t max_modules() const { return max_modules_; } + size_t num_counters() const { return num_counters_; } + double exposure_time() const { return exposure_time_; } double bloffset() const { return bloffset_; } @@ -135,6 +140,8 @@ class MythenDetectorSpecifications { size_t max_modules_ = 48; + size_t num_counters_ = 1; + double exposure_time_ = 5.0; // TODO: could read from acquired file but // maybe should be configurable double bloffset_ = 1.532; // what is this? detector offset relative to what? diff --git a/src/AngleCalibration.test.cpp b/src/AngleCalibration.test.cpp index 5194881..dc455e3 100644 --- a/src/AngleCalibration.test.cpp +++ b/src/AngleCalibration.test.cpp @@ -21,7 +21,7 @@ using namespace aare; TEST_CASE("read initial angle calibration file", - "[.anglecalibration] [.files]") { + "[anglecalibration] [.files]") { std::shared_ptr mythen_detector_ptr = std::make_shared(); @@ -53,7 +53,7 @@ TEST_CASE("read initial angle calibration file", } TEST_CASE("read bad channels", - "[.anglecalibration][.mythenspecifications][.files]") { + "[anglecalibration][mythenspecifications][.files]") { MythenDetectorSpecifications mythen_detector; @@ -74,7 +74,7 @@ TEST_CASE("read bad channels", } TEST_CASE("read unconnected modules", - "[.anglecalibration][.mythenspecifications][.files]") { + "[anglecalibration][mythenspecifications][.files]") { MythenDetectorSpecifications mythen_detector; @@ -93,7 +93,7 @@ TEST_CASE("read unconnected modules", [](const bool element) { return element; })); } -TEST_CASE("read flatfield", "[.anglecalibration][.flatfield][.files]") { +TEST_CASE("read flatfield", "[anglecalibration][flatfield][.files]") { std::shared_ptr mythen_detector_ptr = std::make_shared(); @@ -116,7 +116,35 @@ TEST_CASE("read flatfield", "[.anglecalibration][.flatfield][.files]") { CHECK(flatfield_data[21] == 4234186); } -TEST_CASE("compare result with python code", "[.anglecalibration] [.files]") { +TEST_CASE("create flatfield", "[anglecalibration], [flatfield], [.files]") { + + ssize_t n_modules = 2; + double exposure_time = 5.0; + size_t n_counters = 1; + std::shared_ptr mythen_detector_ptr = + std::make_shared(n_modules, exposure_time, + n_counters); + + FlatField flatfield(mythen_detector_ptr); + + auto data_path = test_data_path() / "AngleCalibration_Test_Data" / + "Flatfieldacquisition"; + + REQUIRE(std::filesystem::exists(data_path)); + + CHECK_NOTHROW(flatfield.create_flatfield_from_rawfilesystem(data_path)); + + auto flatfield_data = flatfield.get_flatfield(); + + CHECK(flatfield_data.size() == n_modules * 1280); + + CHECK(flatfield_data[0] == 0); + CHECK(flatfield_data[21] == + 2 * 3 * + 21); // virtual data 2 angles, 3 frames - 21 as increasing numbers +} + +TEST_CASE("compare result with python code", "[anglecalibration] [.files]") { auto fpath = test_data_path() / "AngleCalibration_Test_Data"; @@ -196,7 +224,7 @@ TEST_CASE("compare result with python code", "[.anglecalibration] [.files]") { 1e-8)); // } -TEST_CASE("check conversion from DG to EE parameters", "[.anglecalibration]") { +TEST_CASE("check conversion from DG to EE parameters", "[anglecalibration]") { std::shared_ptr mythen_detector_ptr = std::make_shared();