Detector Geometry customization
This commit is contained in:
@@ -31,29 +31,10 @@ DiffractionExperiment::operator JFJochProtoBuf::JungfraujochSettings() const {
|
||||
return settings;
|
||||
}
|
||||
|
||||
DiffractionExperiment::DiffractionExperiment() : DiffractionExperiment(2, {4,4}, 0, 0, true)
|
||||
DiffractionExperiment::DiffractionExperiment() : DiffractionExperiment(DetectorGeometry(8, 2))
|
||||
{}
|
||||
|
||||
DiffractionExperiment::DiffractionExperiment(int64_t horizontal_stacking, const std::vector<int64_t> &vec, int64_t gap_x,
|
||||
int64_t gap_y, bool mirror_y_in_conversion) {
|
||||
check_min("Gap X",gap_x, 0);
|
||||
check_min("Gap Y",gap_y, 0);
|
||||
check_min("Horizontal module stacking",horizontal_stacking, 1);
|
||||
|
||||
if (gap_x % 2 == 1)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Gap X has to be even number");
|
||||
|
||||
if (gap_y % 2 == 1)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Gap Y has to be even number");
|
||||
|
||||
if (vec.empty())
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "At least one data stream with one module needs to be defined");
|
||||
|
||||
for (const auto& val: vec) {
|
||||
if (val == 0)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Cannot define data stream with zero modules");
|
||||
}
|
||||
|
||||
DiffractionExperiment::DiffractionExperiment(const DetectorGeometry& geom) {
|
||||
dataset.set_photon_energy_kev(WVL_1A_IN_KEV);
|
||||
dataset.set_detector_distance_mm(100);
|
||||
dataset.mutable_scattering_vector()->set_x(0);
|
||||
@@ -70,7 +51,8 @@ DiffractionExperiment::DiffractionExperiment(int64_t horizontal_stacking, const
|
||||
|
||||
dataset.set_compression(JFJochProtoBuf::BSHUF_LZ4);
|
||||
|
||||
*internal.mutable_data_stream_modules() = {vec.begin(), vec.end()};
|
||||
internal.set_ndatastreams(1);
|
||||
internal.set_nmodules(geom.GetModulesNum());
|
||||
|
||||
internal.set_frame_time_us(MIN_FRAME_TIME_HALF_SPEED_IN_US);
|
||||
internal.set_count_time_us(MIN_FRAME_TIME_HALF_SPEED_IN_US - READOUT_TIME_IN_US);
|
||||
@@ -96,42 +78,11 @@ DiffractionExperiment::DiffractionExperiment(int64_t horizontal_stacking, const
|
||||
internal.set_storage_cells(1);
|
||||
internal.set_storage_cell_start(15);
|
||||
|
||||
CalculateGeometry(horizontal_stacking, vec, gap_x, gap_y, mirror_y_in_conversion);
|
||||
*internal.mutable_conv_geometry() = geom;
|
||||
|
||||
Mode(DetectorMode::Conversion);
|
||||
}
|
||||
|
||||
void DiffractionExperiment::CalculateGeometry(int64_t horizontal_stacking, const std::vector<int64_t> &v, int64_t gap_x,
|
||||
int64_t gap_y, bool mirror_y_in_conversion) {
|
||||
auto nmodules = GetModulesNum();
|
||||
|
||||
const auto cgeom = internal.mutable_conv_geometry();
|
||||
|
||||
cgeom->set_width_pxl(horizontal_stacking * CONVERTED_MODULE_COLS + (horizontal_stacking - 1) * gap_x);
|
||||
int64_t conv_lines = nmodules / horizontal_stacking + (nmodules % horizontal_stacking > 0 ? 1 : 0);
|
||||
cgeom->set_height_pxl(conv_lines * CONVERTED_MODULE_LINES + (conv_lines - 1) * gap_y);
|
||||
cgeom->set_mirror_modules_in_y(mirror_y_in_conversion);
|
||||
|
||||
for (int module = 0; module < nmodules; module++) {
|
||||
int64_t module_x = module % horizontal_stacking;
|
||||
int64_t module_y = module / horizontal_stacking;
|
||||
|
||||
int64_t pixel_x = module_x * (CONVERTED_MODULE_COLS + gap_x);
|
||||
int64_t pixel_y = module_y * (CONVERTED_MODULE_LINES + gap_y);
|
||||
|
||||
if (mirror_y_in_conversion)
|
||||
pixel_y = cgeom->height_pxl() - pixel_y - 1;
|
||||
|
||||
cgeom->add_pixel0_of_module(pixel_y * cgeom->width_pxl() + pixel_x);
|
||||
}
|
||||
|
||||
const auto rgeom = internal.mutable_raw_geometry();
|
||||
rgeom->set_width_pxl(RAW_MODULE_COLS);
|
||||
rgeom->set_height_pxl(nmodules * RAW_MODULE_LINES);
|
||||
rgeom->set_mirror_modules_in_y(false);
|
||||
for (int module = 0; module < nmodules; module++)
|
||||
rgeom->add_pixel0_of_module( module * RAW_MODULE_SIZE);
|
||||
}
|
||||
|
||||
// setter functions
|
||||
|
||||
DiffractionExperiment &DiffractionExperiment::Mode(DetectorMode input) {
|
||||
@@ -152,11 +103,13 @@ DiffractionExperiment &DiffractionExperiment::Mode(DetectorMode input) {
|
||||
internal.set_mode(JFJochProtoBuf::PEDESTAL_G2);
|
||||
break;
|
||||
}
|
||||
if (input == DetectorMode::Conversion)
|
||||
*internal.mutable_geometry() = internal.conv_geometry();
|
||||
else
|
||||
*internal.mutable_geometry() = internal.raw_geometry();
|
||||
return *this;
|
||||
}
|
||||
|
||||
DiffractionExperiment &DiffractionExperiment::DataStreams(int64_t input) {
|
||||
check_max("Number of data streams", input, 7);
|
||||
check_min("Number of data streams", input, 1);
|
||||
internal.set_ndatastreams(input);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -660,20 +613,20 @@ bool DiffractionExperiment::IsPixelSigned() const {
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetDataStreamsNum() const {
|
||||
return internal.data_stream_modules_size();
|
||||
return std::min(internal.ndatastreams(), internal.nmodules());
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetModulesNum(uint16_t data_stream) const {
|
||||
if (data_stream == TASK_NO_DATA_STREAM)
|
||||
return std::accumulate(internal.data_stream_modules().begin(), internal.data_stream_modules().end(), 0);
|
||||
return internal.nmodules();
|
||||
|
||||
if (data_stream >= GetDataStreamsNum())
|
||||
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Non exisiting data stream");
|
||||
return internal.data_stream_modules(data_stream);
|
||||
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Non existing data stream");
|
||||
|
||||
return (internal.nmodules() + (GetDataStreamsNum() - 1) - data_stream) / GetDataStreamsNum();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetFirstModuleOfDataStream(uint16_t data_stream) const {
|
||||
if (data_stream == TASK_NO_DATA_STREAM)
|
||||
return 0;
|
||||
if (data_stream >= GetDataStreamsNum())
|
||||
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Non exisiting data stream");
|
||||
|
||||
@@ -690,35 +643,46 @@ int64_t DiffractionExperiment::GetPixelsNum() const {
|
||||
return GetXPixelsNum() * GetYPixelsNum();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetPixelsNumFullImage() const {
|
||||
return GetXPixelsNumFullImage() * GetYPixelsNumFullImage();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetXPixelsNumFullImage() const {
|
||||
if (GetDetectorMode() != DetectorMode::Conversion)
|
||||
return RAW_MODULE_COLS;
|
||||
else
|
||||
return internal.conv_geometry().width_pxl();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetXPixelsNum() const {
|
||||
if (GetBinning2x2())
|
||||
return internal.geometry().width_pxl() / 2;
|
||||
return GetXPixelsNumFullImage() / 2;
|
||||
else
|
||||
return internal.geometry().width_pxl();
|
||||
return GetXPixelsNumFullImage();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetYPixelsNum() const {
|
||||
if (GetBinning2x2())
|
||||
return internal.geometry().height_pxl() / 2;
|
||||
return GetYPixelsNumFullImage() / 2;
|
||||
else
|
||||
return internal.geometry().height_pxl();
|
||||
return GetYPixelsNumFullImage();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetYPixelsNumFullImage() const {
|
||||
if (GetDetectorMode() != DetectorMode::Conversion)
|
||||
return RAW_MODULE_LINES * GetModulesNum();
|
||||
else
|
||||
return internal.conv_geometry().height_pxl();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetPixel0OfModule(uint16_t module_number) const {
|
||||
if (module_number >= internal.geometry().pixel0_of_module_size())
|
||||
if (module_number >= GetModulesNum())
|
||||
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Module number out of bounds");
|
||||
|
||||
if (GetBinning2x2()) {
|
||||
auto tmp = internal.geometry().pixel0_of_module(module_number);
|
||||
auto col = tmp % internal.geometry().width_pxl();
|
||||
auto line = tmp / internal.geometry().width_pxl();
|
||||
return line / 2 * (internal.geometry().width_pxl() / 2) + col / 2;
|
||||
} else
|
||||
return internal.geometry().pixel0_of_module(module_number);
|
||||
}
|
||||
|
||||
bool DiffractionExperiment::IsUpsideDown() const {
|
||||
return internal.geometry().mirror_modules_in_y();
|
||||
if (GetDetectorMode() != DetectorMode::Conversion)
|
||||
return RAW_MODULE_SIZE * module_number;
|
||||
else
|
||||
return internal.conv_geometry().module_geometry(module_number).pixel0();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetOverflow() const {
|
||||
@@ -1242,3 +1206,17 @@ std::string DiffractionExperiment::GetInstrumentName() const {
|
||||
std::string DiffractionExperiment::GetInstrumentNameShort() const {
|
||||
return internal.instrument_name_short();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetModuleFastDirectionStep(uint16_t module_number) const {
|
||||
if (module_number >= GetModulesNum())
|
||||
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Module number out of bounds");
|
||||
|
||||
return internal.conv_geometry().module_geometry(module_number).fast_direction_step();
|
||||
}
|
||||
|
||||
int64_t DiffractionExperiment::GetModuleSlowDirectionStep(uint16_t module_number) const {
|
||||
if (module_number >= GetModulesNum())
|
||||
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Module number out of bounds");
|
||||
|
||||
return internal.conv_geometry().module_geometry(module_number).slow_direction_step();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user