From c6448075aef8607ac370bb69782b5b18f82ef120 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 12 Jan 2024 13:59:41 +0100 Subject: indexamajig: Implement --max-mille-level --- libcrystfel/src/crystfel-mille.c | 26 ++++++++++++++++++++++++-- libcrystfel/src/crystfel-mille.h | 2 +- libcrystfel/src/index.c | 14 +++++++------- libcrystfel/src/index.h | 3 ++- libcrystfel/src/predict-refine.c | 6 ++++-- libcrystfel/src/predict-refine.h | 3 ++- src/indexamajig.c | 4 ++++ src/process_image.c | 2 +- 8 files changed, 45 insertions(+), 15 deletions(-) diff --git a/libcrystfel/src/crystfel-mille.c b/libcrystfel/src/crystfel-mille.c index 0fca6f30..8eacaa60 100644 --- a/libcrystfel/src/crystfel-mille.c +++ b/libcrystfel/src/crystfel-mille.c @@ -145,11 +145,28 @@ static void mille_add_measurement(Mille *m, } +/* group must not be NULL + * count_depth() = 0 means this is the top group */ +static int count_depth(const struct detgeom_panel_group *group) +{ + int depth = 0; + assert(group != NULL); + do { + depth++; + group = group->parent; + } while ( group != NULL ); + return depth-1; +} + + void write_mille(Mille *mille, int n, UnitCell *cell, struct reflpeak *rps, struct image *image, - gsl_matrix **Minvs) + int max_level, gsl_matrix **Minvs) { int i; + int depth; + + assert(max_level >= 0); /* No groups -> no refinement */ if ( image->detgeom->top_group == NULL ) { @@ -212,8 +229,13 @@ void write_mille(Mille *mille, int n, UnitCell *cell, /* Global gradients for each hierarchy level, starting at the * individual panel and working up to the top level */ j = 0; - levels = 0; group = image->detgeom->panels[rps[i].peak->pn].group; + depth = count_depth(group); + while ( depth > max_level ) { + depth--; + group = group->parent; + } + levels = 0; while ( group != NULL ) { double cx, cy, cz; diff --git a/libcrystfel/src/crystfel-mille.h b/libcrystfel/src/crystfel-mille.h index a4b83815..d6602ef0 100644 --- a/libcrystfel/src/crystfel-mille.h +++ b/libcrystfel/src/crystfel-mille.h @@ -51,7 +51,7 @@ extern enum gparam mille_unlabel(int n); extern void write_mille(Mille *mille, int n, UnitCell *cell, struct reflpeak *rps, struct image *image, - gsl_matrix **Minvs); + int max_level, gsl_matrix **Minvs); extern void crystfel_mille_delete_last_record(Mille *m); diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c index f519c3b9..d93664b1 100644 --- a/libcrystfel/src/index.c +++ b/libcrystfel/src/index.c @@ -592,7 +592,7 @@ static float real_time() /* Return non-zero for "success" */ static int try_indexer(struct image *image, IndexingMethod indm, IndexingPrivate *ipriv, void *mpriv, char *last_task, - Mille *mille) + Mille *mille, int max_mille_level) { int i, r; int n_bad = 0; @@ -720,7 +720,7 @@ static int try_indexer(struct image *image, IndexingMethod indm, { int r; profile_start("refine"); - r = refine_prediction(image, cr, mille); + r = refine_prediction(image, cr, mille, max_mille_level); profile_end("refine"); if ( r ) { crystal_set_user_flag(cr, 1); @@ -921,25 +921,25 @@ static int finished_retry(IndexingMethod indm, IndexingFlags flags, void index_pattern(struct image *image, IndexingPrivate *ipriv) { - index_pattern_4(image, ipriv, NULL, NULL, NULL); + index_pattern_4(image, ipriv, NULL, NULL, NULL, 0); } void index_pattern_2(struct image *image, IndexingPrivate *ipriv, int *ping) { - index_pattern_4(image, ipriv, ping, NULL, NULL); + index_pattern_4(image, ipriv, ping, NULL, NULL, 0); } void index_pattern_3(struct image *image, IndexingPrivate *ipriv, int *ping, char *last_task) { - index_pattern_4(image, ipriv, ping, last_task, NULL); + index_pattern_4(image, ipriv, ping, last_task, NULL, 0); } void index_pattern_4(struct image *image, IndexingPrivate *ipriv, int *ping, - char *last_task, Mille *mille) + char *last_task, Mille *mille, int max_mille_level) { int n = 0; ImageFeatureList *orig; @@ -994,7 +994,7 @@ void index_pattern_4(struct image *image, IndexingPrivate *ipriv, int *ping, r = try_indexer(image, ipriv->methods[n], ipriv, ipriv->engine_private[n], - last_task, mille); + last_task, mille, max_mille_level); success += r; ntry++; done = finished_retry(ipriv->methods[n], ipriv->flags, diff --git a/libcrystfel/src/index.h b/libcrystfel/src/index.h index fa371276..10d07f08 100644 --- a/libcrystfel/src/index.h +++ b/libcrystfel/src/index.h @@ -253,7 +253,8 @@ extern void index_pattern_3(struct image *image, IndexingPrivate *ipriv, int *ping, char *last_task); extern void index_pattern_4(struct image *image, IndexingPrivate *ipriv, - int *ping, char *last_task, Mille *mille); + int *ping, char *last_task, Mille *mille, + int max_mille_level); extern void cleanup_indexing(IndexingPrivate *ipriv); diff --git a/libcrystfel/src/predict-refine.c b/libcrystfel/src/predict-refine.c index 32d0f77b..d5a3b403 100644 --- a/libcrystfel/src/predict-refine.c +++ b/libcrystfel/src/predict-refine.c @@ -796,7 +796,8 @@ static void free_rps_noreflist(struct reflpeak *rps, int n) } -int refine_prediction(struct image *image, Crystal *cr, Mille *mille) +int refine_prediction(struct image *image, Crystal *cr, + Mille *mille, int max_mille_level) { int n; int i; @@ -879,7 +880,8 @@ int refine_prediction(struct image *image, Crystal *cr, Mille *mille) if ( mille != NULL ) { profile_start("mille-calc"); - write_mille(mille, n, crystal_get_cell(cr), rps, image, Minvs); + write_mille(mille, n, crystal_get_cell(cr), rps, image, + max_mille_level, Minvs); profile_end("mille-calc"); } diff --git a/libcrystfel/src/predict-refine.h b/libcrystfel/src/predict-refine.h index 604799c0..080e5923 100644 --- a/libcrystfel/src/predict-refine.h +++ b/libcrystfel/src/predict-refine.h @@ -67,7 +67,8 @@ struct reflpeak { * Prediction refinement: refinement of indexing solutions before integration. */ -extern int refine_prediction(struct image *image, Crystal *cr, Mille *mille); +extern int refine_prediction(struct image *image, Crystal *cr, + Mille *mille, int max_mille_level); extern int refine_radius(Crystal *cr, struct image *image); diff --git a/src/indexamajig.c b/src/indexamajig.c index fd95a01c..ce8b2cbf 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -754,6 +754,10 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) ERROR("Invalid value for --max-mille-level\n"); return EINVAL; } + if ( args->iargs.max_mille_level < 0 ) { + ERROR("Invalid value for --max-mille-level\n"); + return EINVAL; + } break; /* ---------- Integration ---------- */ diff --git a/src/process_image.c b/src/process_image.c index 57a994ac..2f856594 100644 --- a/src/process_image.c +++ b/src/process_image.c @@ -420,7 +420,7 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, set_last_task(last_task, "indexing"); profile_start("index"); index_pattern_4(image, iargs->ipriv, &sb_shared->pings[cookie], - last_task, mille); + last_task, mille, iargs->max_mille_level); profile_end("index"); r = chdir(rn); -- cgit v1.2.3