mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-24 04:17:58 +02:00
added flatfield creation test
This commit is contained in:
64
acquire_flatfield_data.py
Normal file
64
acquire_flatfield_data.py
Normal file
@ -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?
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -61,15 +61,17 @@ class FlatField {
|
|||||||
std::string filename =
|
std::string filename =
|
||||||
file_in_path.path().filename().string();
|
file_in_path.path().filename().string();
|
||||||
if (filename.find("master") != std::string::npos) {
|
if (filename.find("master") != std::string::npos) {
|
||||||
File f(filename);
|
File f(file_in_path);
|
||||||
auto frames = f.read_n(f.total_frames());
|
auto frames = f.read_n(f.total_frames());
|
||||||
for (const auto &frame : frames) {
|
for (const auto &frame : frames) {
|
||||||
if (frame.rows() * frame.cols() !=
|
if (frame.rows() * frame.cols() !=
|
||||||
mythen_detector->num_strips()) {
|
mythen_detector->num_strips() *
|
||||||
|
mythen_detector->num_counters()) {
|
||||||
throw std::runtime_error(fmt::format(
|
throw std::runtime_error(fmt::format(
|
||||||
"sizes mismatch. Expect a size of "
|
"sizes mismatch. Expect a size of "
|
||||||
"{} - frame has a size of {}",
|
"{} - frame has a size of {}",
|
||||||
mythen_detector->num_strips(),
|
mythen_detector->num_strips() *
|
||||||
|
mythen_detector->num_counters(),
|
||||||
frame.rows() * frame.cols()));
|
frame.rows() * frame.cols()));
|
||||||
}
|
}
|
||||||
for (ssize_t row = 0; row < frame.rows(); ++row)
|
for (ssize_t row = 0; row < frame.rows(); ++row)
|
||||||
|
@ -30,9 +30,10 @@ class MythenDetectorSpecifications {
|
|||||||
|
|
||||||
MythenDetectorSpecifications(const size_t max_modules,
|
MythenDetectorSpecifications(const size_t max_modules,
|
||||||
const double exposure_time,
|
const double exposure_time,
|
||||||
const double bloffset)
|
const double num_counters = 1,
|
||||||
: max_modules_(max_modules), exposure_time_(exposure_time),
|
double bloffset = 1.532)
|
||||||
bloffset_(bloffset) {
|
: max_modules_(max_modules), num_counters_(num_counters),
|
||||||
|
exposure_time_(exposure_time), bloffset_(bloffset) {
|
||||||
num_strips_ = max_modules_ * strips_per_module_;
|
num_strips_ = max_modules_ * strips_per_module_;
|
||||||
|
|
||||||
num_connected_modules_ = max_modules_;
|
num_connected_modules_ = max_modules_;
|
||||||
@ -44,6 +45,7 @@ class MythenDetectorSpecifications {
|
|||||||
std::array<ssize_t, 1>{static_cast<ssize_t>(max_modules_)}, true);
|
std::array<ssize_t, 1>{static_cast<ssize_t>(max_modules_)}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO templated on filereader
|
||||||
void read_bad_channels_from_file(const std::string &filename) {
|
void read_bad_channels_from_file(const std::string &filename) {
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
@ -73,6 +75,7 @@ class MythenDetectorSpecifications {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO template on filereader
|
||||||
void read_unconnected_modules_from_file(const std::string &filename) {
|
void read_unconnected_modules_from_file(const std::string &filename) {
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
@ -112,6 +115,8 @@ class MythenDetectorSpecifications {
|
|||||||
|
|
||||||
size_t max_modules() const { return max_modules_; }
|
size_t max_modules() const { return max_modules_; }
|
||||||
|
|
||||||
|
size_t num_counters() const { return num_counters_; }
|
||||||
|
|
||||||
double exposure_time() const { return exposure_time_; }
|
double exposure_time() const { return exposure_time_; }
|
||||||
|
|
||||||
double bloffset() const { return bloffset_; }
|
double bloffset() const { return bloffset_; }
|
||||||
@ -135,6 +140,8 @@ class MythenDetectorSpecifications {
|
|||||||
|
|
||||||
size_t max_modules_ = 48;
|
size_t max_modules_ = 48;
|
||||||
|
|
||||||
|
size_t num_counters_ = 1;
|
||||||
|
|
||||||
double exposure_time_ = 5.0; // TODO: could read from acquired file but
|
double exposure_time_ = 5.0; // TODO: could read from acquired file but
|
||||||
// maybe should be configurable
|
// maybe should be configurable
|
||||||
double bloffset_ = 1.532; // what is this? detector offset relative to what?
|
double bloffset_ = 1.532; // what is this? detector offset relative to what?
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
using namespace aare;
|
using namespace aare;
|
||||||
|
|
||||||
TEST_CASE("read initial angle calibration file",
|
TEST_CASE("read initial angle calibration file",
|
||||||
"[.anglecalibration] [.files]") {
|
"[anglecalibration] [.files]") {
|
||||||
|
|
||||||
std::shared_ptr<MythenDetectorSpecifications> mythen_detector_ptr =
|
std::shared_ptr<MythenDetectorSpecifications> mythen_detector_ptr =
|
||||||
std::make_shared<MythenDetectorSpecifications>();
|
std::make_shared<MythenDetectorSpecifications>();
|
||||||
@ -53,7 +53,7 @@ TEST_CASE("read initial angle calibration file",
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("read bad channels",
|
TEST_CASE("read bad channels",
|
||||||
"[.anglecalibration][.mythenspecifications][.files]") {
|
"[anglecalibration][mythenspecifications][.files]") {
|
||||||
|
|
||||||
MythenDetectorSpecifications mythen_detector;
|
MythenDetectorSpecifications mythen_detector;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ TEST_CASE("read bad channels",
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("read unconnected modules",
|
TEST_CASE("read unconnected modules",
|
||||||
"[.anglecalibration][.mythenspecifications][.files]") {
|
"[anglecalibration][mythenspecifications][.files]") {
|
||||||
|
|
||||||
MythenDetectorSpecifications mythen_detector;
|
MythenDetectorSpecifications mythen_detector;
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ TEST_CASE("read unconnected modules",
|
|||||||
[](const bool element) { return element; }));
|
[](const bool element) { return element; }));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("read flatfield", "[.anglecalibration][.flatfield][.files]") {
|
TEST_CASE("read flatfield", "[anglecalibration][flatfield][.files]") {
|
||||||
|
|
||||||
std::shared_ptr<MythenDetectorSpecifications> mythen_detector_ptr =
|
std::shared_ptr<MythenDetectorSpecifications> mythen_detector_ptr =
|
||||||
std::make_shared<MythenDetectorSpecifications>();
|
std::make_shared<MythenDetectorSpecifications>();
|
||||||
@ -116,7 +116,35 @@ TEST_CASE("read flatfield", "[.anglecalibration][.flatfield][.files]") {
|
|||||||
CHECK(flatfield_data[21] == 4234186);
|
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<MythenDetectorSpecifications> mythen_detector_ptr =
|
||||||
|
std::make_shared<MythenDetectorSpecifications>(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";
|
auto fpath = test_data_path() / "AngleCalibration_Test_Data";
|
||||||
|
|
||||||
@ -196,7 +224,7 @@ TEST_CASE("compare result with python code", "[.anglecalibration] [.files]") {
|
|||||||
1e-8)); //
|
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<MythenDetectorSpecifications> mythen_detector_ptr =
|
std::shared_ptr<MythenDetectorSpecifications> mythen_detector_ptr =
|
||||||
std::make_shared<MythenDetectorSpecifications>();
|
std::make_shared<MythenDetectorSpecifications>();
|
||||||
|
Reference in New Issue
Block a user