v1.0.0-rc.36

This commit is contained in:
2025-05-05 19:32:22 +02:00
parent 759243d1bf
commit 040cf08386
333 changed files with 22724 additions and 15251 deletions
+91 -33
View File
@@ -18,7 +18,7 @@ using namespace std::literals::chrono_literals;
#define check_min(param, val, min) if ((val) < (min)) throw JFJochException(JFJochExceptionCategory::InputParameterBelowMin, param)
#define check_finite(param, val) if (!std::isfinite(val)) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, param)
DiffractionExperiment::DiffractionExperiment() : DiffractionExperiment(DetectorGeometry(8, 2)) {}
DiffractionExperiment::DiffractionExperiment() : DiffractionExperiment(DetJF4M()) {}
DiffractionExperiment::DiffractionExperiment(const DetectorSetup& det_setup)
: detector(det_setup) {
@@ -285,24 +285,28 @@ std::chrono::microseconds DiffractionExperiment::GetFrameCountTime() const {
.value_or(detector_settings.GetFrameTime() - detector.GetReadOutTime());
}
bool DiffractionExperiment::GetFrameCountTimeAuto() const {
return detector_settings.GetCountTime().has_value();
}
std::chrono::microseconds DiffractionExperiment::GetImageCountTime() const {
return GetFrameCountTime() * GetSummation();
}
int64_t DiffractionExperiment::GetPedestalG0Frames() const {
if (GetDetectorType() == DetectorType::EIGER)
if (GetDetectorType() != DetectorType::JUNGFRAU)
return 0;
return detector_settings.GetPedestalG0Frames();
}
int64_t DiffractionExperiment::GetPedestalG1Frames() const {
if (GetDetectorType() == DetectorType::EIGER)
if (GetDetectorType() != DetectorType::JUNGFRAU)
return 0;
return detector_settings.GetPedestalG1Frames();
}
int64_t DiffractionExperiment::GetPedestalG2Frames() const {
if (GetDetectorType() == DetectorType::EIGER)
if (GetDetectorType() != DetectorType::JUNGFRAU)
return 0;
return detector_settings.GetPedestalG2Frames();
}
@@ -345,14 +349,17 @@ CompressionAlgorithm DiffractionExperiment::GetCompressionAlgorithm() const {
}
int64_t DiffractionExperiment::GetByteDepthImage() const {
if (detector.GetBitDepthImage())
return detector.GetBitDepthImage().value() / 8;
if (IsCPUSummation())
return 4;
auto bit_depth_image = image_format_settings.GetBitDepthImage();
if (!bit_depth_image.has_value()) {
if (GetByteDepthReadout() == 4)
if (GetBitDepthReadout() == 32)
return 4;
if (GetByteDepthReadout() == 1)
if (GetBitDepthReadout() == 8)
return 1;
return (GetSummation() > 2) ? 4 : 2;
}
@@ -407,8 +414,20 @@ int64_t DiffractionExperiment::GetYPixelsNum() const {
return detector.GetGeometry().GetHeight(IsGeometryTransformed());
}
int64_t DiffractionExperiment::GetPixel0OfModule(uint16_t module_number) const {
return detector.GetGeometry().GetPixel0(module_number, IsGeometryTransformed());
int64_t DiffractionExperiment::GetPixelsNumConv() const {
return GetXPixelsNumConv() * GetYPixelsNumConv();
}
int64_t DiffractionExperiment::GetXPixelsNumConv() const {
return detector.GetGeometry().GetWidth(true);
}
int64_t DiffractionExperiment::GetYPixelsNumConv() const {
return detector.GetGeometry().GetHeight(true);
}
int64_t DiffractionExperiment::GetPixel0OfModuleConv(uint16_t module_number) const {
return detector.GetGeometry().GetPixel0(module_number, true);
}
int64_t DiffractionExperiment::GetOverflow() const {
@@ -424,6 +443,16 @@ int64_t DiffractionExperiment::GetOverflow() const {
}
}
int64_t DiffractionExperiment::GetSaturationLimit() const {
auto sat = detector.GetSaturationLimit();
auto overflow = GetOverflow();
if (!sat)
return overflow;
return std::min(sat.value(), overflow);
}
int64_t DiffractionExperiment::GetUnderflow() const {
if (!IsPixelSigned())
return -1;
@@ -574,7 +603,7 @@ void DiffractionExperiment::FillMessage(StartMessage &message) const {
message.incident_energy = GetIncidentEnergy_keV() * 1e3f;
message.image_size_x = GetXPixelsNum();
message.image_size_y = GetYPixelsNum();
message.saturation_value = GetOverflow() - 1;
message.saturation_value = GetSaturationLimit() - 1;
message.error_value = GetUnderflow();
message.frame_time = GetImageTime().count() * 1e-6f;
message.count_time = GetImageCountTime().count() * 1e-6f;
@@ -584,7 +613,7 @@ void DiffractionExperiment::FillMessage(StartMessage &message) const {
message.sensor_material = detector.GetSensorMaterial();
message.sensor_thickness = detector.GetSensorThickness_um() * 1e-6f;
message.bit_depth_image = GetByteDepthImage() * 8;
message.bit_depth_readout = GetByteDepthReadout() * 8;
message.bit_depth_readout = GetBitDepthReadout();
if (GetDetectorType() == DetectorType::JUNGFRAU) {
message.storage_cell_number = GetStorageCellNumber();
@@ -635,21 +664,22 @@ void DiffractionExperiment::FillMessage(StartMessage &message) const {
message.detector_serial_number = detector.GetSerialNumber();
message.write_master_file = dataset.IsWriteNXmxHDF5Master();
message.overwrite = file_writer.IsOverwriteExistingFiles();
message.hdf5_format_version = file_writer.GetHDF5MasterFormatVersion();
message.file_format = file_writer.GetHDF5MasterFormatVersion();
message.channels = {"default"};
if (GetDetectorType() == DetectorType::JUNGFRAU)
message.jungfrau_conversion_enabled = IsJungfrauConvPhotonCnt();
if (GetDetectorType() == DetectorType::EIGER) {
float threshold = GetEigerThreshold_keV().value_or(GetIncidentEnergy_keV() / 2.0f);
message.threshold_energy["default"] = threshold * 1000.0f; // threshold in CBOR is in eV
switch (GetDetectorType()) {
case DetectorType::JUNGFRAU:
message.jungfrau_conversion_enabled = IsJungfrauConvPhotonCnt();
if (IsJungfrauConvPhotonCnt())
message.jungfrau_conversion_factor = GetPhotonEnergyForConversion_keV() * 1000;
break;
case DetectorType::EIGER:
case DetectorType::DECTRIS:
message.threshold_energy["default"] = GetEigerThreshold_keV() * 1000.0f; // threshold in CBOR is in eV
break;
}
if (IsJungfrauConvPhotonCnt())
message.jungfrau_conversion_factor = GetPhotonEnergyForConversion_keV() * 1000;
message.geometry_transformation_enabled = IsGeometryTransformed();
if (GetSummation() == 1)
@@ -909,6 +939,19 @@ const DetectorSetup &DiffractionExperiment::GetDetectorSetup() const {
return detector;
}
DetectorSetup &DiffractionExperiment::Detector() {
return detector;
}
DiffractionExperiment &DiffractionExperiment::NeuralNetModelPath(const std::string &input) {
neural_net_model_path = input;
return *this;
}
std::string DiffractionExperiment::GetNeuralNetModelPath() const {
return neural_net_model_path;
}
DiffractionExperiment &DiffractionExperiment::PulsedSource(bool input) {
instrument.PulsedSource(input);
return *this;
@@ -987,9 +1030,7 @@ const ROIMap &DiffractionExperiment::ROI() const {
}
std::vector<uint16_t> DiffractionExperiment::ExportROIMap() const {
return roi_mask.GetROIMap(GetDiffractionGeometry(),
detector.GetGeometry().GetWidth(),
detector.GetGeometry().GetHeight());
return roi_mask.GetROIMap(GetDiffractionGeometry(), GetXPixelsNumConv(), GetYPixelsNumConv());
}
DiffractionExperiment &DiffractionExperiment::ImagesPerFile(int64_t input) {
@@ -1060,7 +1101,8 @@ FileWriterSettings DiffractionExperiment::GetFileWriterSettings() const {
}
bool DiffractionExperiment::IsGeometryTransformed() const {
return image_format_settings.IsGeometryTransformed();
// For DECTRIS detectors always operate in transformed geometry
return (GetDetectorType() == DetectorType::DECTRIS) || image_format_settings.IsGeometryTransformed();
}
DiffractionExperiment &DiffractionExperiment::GeometryTransformation(bool input) {
@@ -1088,16 +1130,23 @@ int64_t DiffractionExperiment::GetImageFillValue() const {
}
}
int64_t DiffractionExperiment::GetByteDepthReadout() const {
int64_t DiffractionExperiment::GetBitDepthReadout() const {
if (GetDetectorType() == DetectorType::EIGER) {
if (detector_settings.GetEigerBitDepth().has_value())
return detector_settings.GetEigerBitDepth().value() / 8;
return detector_settings.GetEigerBitDepth().value();
if (GetFrameTime().count() > 1000)
return 4;
return 32;
if (GetFrameTime().count() < 450)
return 1;
return 8;
return 16;
}
return 2;
auto det_value = detector.GetBitDepthReadout();
if (det_value)
return det_value.value();
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"Bit depth readout not configured");
}
bool DiffractionExperiment::IsPedestalRun() const {
@@ -1217,8 +1266,17 @@ uint32_t DiffractionExperiment::GetPedestalMinImageCount() const {
return detector_settings.GetPedestalMinImageCount();
}
std::optional<float> DiffractionExperiment::GetEigerThreshold_keV() const {
return detector_settings.GetEigerThreshold_keV();
float DiffractionExperiment::GetEigerThreshold_keV() const {
float thr = GetIncidentEnergy_keV() / 2.0f;
auto val = detector_settings.GetEigerThreshold_keV();
if (val)
thr = val.value();
if (thr < detector.GetMinThreshold_keV())
thr = detector.GetMinThreshold_keV();
return thr;
}
DetectorTiming DiffractionExperiment::GetDetectorTiming() const {
@@ -1283,12 +1341,12 @@ bool DiffractionExperiment::IsElectronSource() const {
return instrument.IsElectronSource();
}
DiffractionExperiment &DiffractionExperiment::HDF5MasterFormatVersion(FileWriterFileFormat input) {
DiffractionExperiment &DiffractionExperiment::SetFileWriterFormat(FileWriterFormat input) {
file_writer.HDF5MasterFormatVersion(input);
return *this;
}
FileWriterFileFormat DiffractionExperiment::GetHDF5MasterFormatVersion() const {
FileWriterFormat DiffractionExperiment::GetFileWriterFormat() const {
return file_writer.GetHDF5MasterFormatVersion();
}