Further enhacements

This commit is contained in:
2024-04-29 14:13:35 +02:00
parent 870d0c4e43
commit 64dbd2291e
65 changed files with 808 additions and 850 deletions
+15 -11
View File
@@ -61,15 +61,14 @@ void MXAnalyzer::ReadFromCPU(const int16_t *image, const SpotFindingSettings &se
ReadFromFPGA(&output, settings, module_number);
}
bool MXAnalyzer::Process(DataMessage &message, const SpotFindingSettings& settings) {
void MXAnalyzer::Process(DataMessage &message, const SpotFindingSettings& settings) {
message.indexing_result = 0;
if (!find_spots)
return false;
bool indexed = false;
return;
std::vector<DiffractionSpot> spots_out;
FilterSpotsByCount(experiment, spots, spots_out);
spots.clear();
for (const auto &spot: spots_out)
message.spots.push_back(spot);
@@ -82,21 +81,25 @@ bool MXAnalyzer::Process(DataMessage &message, const SpotFindingSettings& settin
auto indexer_result = indexer.Run(recip, settings.indexing_tolerance);
float x_drift = 0.0f, y_drift = 0.0f;
if (!indexer_result.empty()) {
message.indexing_result = 1;
CalculateBeamCenterAndDistance(spots_out,
indexer_result[0],
message);
// identify indexed spots
for (int i = 0; i < recip.size(); i++) {
auto predicted_pos = RecipToDector(experiment, indexer_result[0].predicted_spots[i]);
float x_diff = predicted_pos.first - spots_out[i].RawCoord().x;
float y_diff = predicted_pos.second - spots_out[i].RawCoord().y;
message.spots[i].indexed = (x_diff * x_diff + y_diff * y_diff
< spot_distance_threshold_pxl * spot_distance_threshold_pxl);
}
indexer_result[0].l.Save(message.indexing_lattice);
message.indexing_unit_cell = indexer_result[0].l.GetUnitCell();
}
}
spots.clear();
return indexed;
}
void MXAnalyzer::CalculateBeamCenterAndDistance(const std::vector<DiffractionSpot> &spots,
@@ -125,7 +128,8 @@ void MXAnalyzer::CalculateBeamCenterAndDistance(const std::vector<DiffractionSpo
auto reg_x = regression(spot_x_Sd1_over_Sd3, spot_x_position);
auto reg_y = regression(spot_y_Sd2_over_Sd3, spot_y_position);
message.corr_beam_x_pxl = experiment.GetBeamX_pxl() - reg_x.intercept / experiment.GetPixelSize_mm();
message.corr_beam_y_pxl = experiment.GetBeamY_pxl() - reg_y.intercept / experiment.GetPixelSize_mm();
// Subtract 0.5 pixel, to account for differences in definition of pixel coordinate (center or top-left corner)
message.corr_beam_x_pxl = experiment.GetBeamX_pxl() - reg_x.intercept / experiment.GetPixelSize_mm() - 0.5;
message.corr_beam_y_pxl = experiment.GetBeamY_pxl() - reg_y.intercept / experiment.GetPixelSize_mm() - 0.5;
message.corr_det_dist_mm = experiment.GetDetectorDistance_mm() - (reg_x.slope + reg_y.slope) / 2.0;
}