diff --git a/image_analysis/IndexAndRefine.cpp b/image_analysis/IndexAndRefine.cpp index 6311c596..8605b232 100644 --- a/image_analysis/IndexAndRefine.cpp +++ b/image_analysis/IndexAndRefine.cpp @@ -258,7 +258,7 @@ std::optional IndexAndRefine::ScaleRotationData(const ScaleMer ScaleMergeOptions options = opts; // If the experiment provides a wedge, propagate it - if (experiment.GetGoniometer().has_value()) { + if (experiment.GetGoniometer().has_value() && rotation_indexer) { options.wedge_deg = experiment.GetGoniometer()->GetWedge_deg(); options.mosaicity_init_deg_vec = mosaicity; } diff --git a/image_analysis/scale_merge/ScaleAndMerge.cpp b/image_analysis/scale_merge/ScaleAndMerge.cpp index 74f8c667..e8bf2f5e 100644 --- a/image_analysis/scale_merge/ScaleAndMerge.cpp +++ b/image_analysis/scale_merge/ScaleAndMerge.cpp @@ -192,7 +192,8 @@ ScaleMergeResult ScaleAndMergeReflectionsCeres(const std::vector 0.0; + const bool rotation_crystallography = opt.wedge_deg.has_value(); + ceres::Problem problem; struct ObsRef { @@ -298,7 +299,7 @@ ScaleMergeResult ScaleAndMergeReflectionsCeres(const std::vector( - new IntensityResidual(*o.r, o.sigma, opt.wedge_deg, refine_partiality)); + new IntensityResidual(*o.r, o.sigma, opt.wedge_deg.value_or(0.0), rotation_crystallography)); problem.AddResidualBlock(cost, nullptr, &g[o.img_id], @@ -315,25 +316,26 @@ ScaleMergeResult ScaleAndMergeReflectionsCeres(const std::vector( + new SmoothnessRegularizationResidual(0.05)); - if (opt.smoothen_g) { - for (int i = 0; i < g.size() - 2; ++i) { - if (image_slot_used[i] && image_slot_used[i + 1] && image_slot_used[i + 2]) { - auto *cost = new ceres::AutoDiffCostFunction( - new SmoothnessRegularizationResidual(0.05)); - - problem.AddResidualBlock(cost, nullptr, &g[i], &g[i + 1], &g[i + 2]); + problem.AddResidualBlock(cost, nullptr, &g[i], &g[i + 1], &g[i + 2]); + } } } - } - if (opt.smoothen_mos && opt.refine_mosaicity) { - for (int i = 0; i < mosaicity.size() - 2; ++i) { - if (image_slot_used[i] && image_slot_used[i + 1] && image_slot_used[i + 2]) { - auto *cost = new ceres::AutoDiffCostFunction( - new SmoothnessRegularizationResidual(0.05)); + if (opt.smoothen_mos && opt.refine_mosaicity) { + for (int i = 0; i < mosaicity.size() - 2; ++i) { + if (image_slot_used[i] && image_slot_used[i + 1] && image_slot_used[i + 2]) { + auto *cost = new ceres::AutoDiffCostFunction( + new SmoothnessRegularizationResidual(0.05)); - problem.AddResidualBlock(cost, nullptr, &mosaicity[i], &mosaicity[i + 1], &mosaicity[i + 2]); + problem.AddResidualBlock(cost, nullptr, &mosaicity[i], &mosaicity[i + 1], &mosaicity[i + 2]); + } } } } @@ -430,7 +432,7 @@ ScaleMergeResult ScaleAndMergeReflectionsCeres(const std::vector 0.0) { + if (rotation_crystallography && mosaicity[o.img_id] > 0.0) { const double c1 = r.zeta / std::sqrt(2.0); const double arg_plus = (r.delta_phi_deg + half_wedge) * c1 / mosaicity[o.img_id]; const double arg_minus = (r.delta_phi_deg - half_wedge) * c1 / mosaicity[o.img_id]; diff --git a/image_analysis/scale_merge/ScaleAndMerge.h b/image_analysis/scale_merge/ScaleAndMerge.h index 2699f898..764ce01c 100644 --- a/image_analysis/scale_merge/ScaleAndMerge.h +++ b/image_analysis/scale_merge/ScaleAndMerge.h @@ -28,7 +28,7 @@ struct ScaleMergeOptions { // --- Kabsch(XDS)-style partiality model --- // Rotation range (wedge) used in partiality calculation. // Set to 0 to disable partiality correction. - double wedge_deg = 1.0; + std::optional wedge_deg; // --- Mosaicity (user input in degrees; internally converted to radians) --- bool refine_mosaicity = true;