From e377768607f11d48106bd1381f1312379c342d7e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 8 Nov 2023 16:24:41 +0100 Subject: Crystal: Remove reference to image structure (part 1) --- src/partialator.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src') diff --git a/src/partialator.c b/src/partialator.c index 9b1803b0..76fce8c8 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -1614,7 +1614,6 @@ int main(int argc, char *argv[]) return 1; } - crystal_set_image(cr, image_for_crystal); *image_for_crystal = *image; image_for_crystal->n_crystals = 1; image_for_crystal->crystals = malloc(sizeof(Crystal *)); @@ -1835,10 +1834,6 @@ int main(int argc, char *argv[]) /* Clean up */ gsl_rng_free(rng); - for ( icryst=0; icryst Date: Wed, 8 Nov 2023 17:08:51 +0100 Subject: Crystal: Remove reference to image structure (part 2) --- src/partialator.c | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/partialator.c b/src/partialator.c index 76fce8c8..de59efde 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -259,7 +259,7 @@ static char *insert_into_filename(const char *fn, const char *add) /* Write custom split results (including a two-way split) */ static void write_custom_split(struct custom_split *csplit, int dsn, - Crystal **crystals, int n_crystals, + Crystal **crystals, struct image **images, int n_crystals, PartialityModel pmodel, int min_measurements, double push_res, SymOpList *sym, int nthreads, const char *outfile) @@ -277,8 +277,8 @@ static void write_custom_split(struct custom_split *csplit, int dsn, char *id; int dsn_crystal; - fn = crystal_get_image(crystals[i])->filename; - evs = crystal_get_image(crystals[i])->ev; + fn = images[i]->filename; + evs = images[i]->ev; if ( evs == NULL ) evs = "//"; id = malloc(strlen(evs)+strlen(fn)+2); @@ -362,7 +362,7 @@ static void show_help(const char *s) } -static signed int find_first_crystal(Crystal **crystals, int n_crystals, +static signed int find_first_crystal(Crystal **crystals, struct image **images, int n_crystals, struct custom_split *csplit, int dsn) { int i; @@ -373,8 +373,8 @@ static signed int find_first_crystal(Crystal **crystals, int n_crystals, char *id; int dsn_crystal; - fn = crystal_get_image(crystals[i])->filename; - evs = crystal_get_image(crystals[i])->ev; + fn = images[i]->filename; + evs = images[i]->ev; if ( evs == NULL ) evs = "//"; id = malloc(strlen(evs)+strlen(fn)+2); @@ -394,7 +394,7 @@ static signed int find_first_crystal(Crystal **crystals, int n_crystals, } -static void check_csplit(Crystal **crystals, int n_crystals, +static void check_csplit(Crystal **crystals, struct image **images, int n_crystals, struct custom_split *csplit) { int i; @@ -412,8 +412,8 @@ static void check_csplit(Crystal **crystals, int n_crystals, char *id; int dsn_crystal; - fn = crystal_get_image(crystals[i])->filename; - evs = crystal_get_image(crystals[i])->ev; + fn = images[i]->filename; + evs = images[i]->ev; if ( evs == NULL ) evs = "//"; id = malloc(strlen(evs)+strlen(fn)+2); @@ -437,7 +437,7 @@ static void check_csplit(Crystal **crystals, int n_crystals, for ( i=0; in_datasets; i++ ) { /* Try to find a crystal with dsn = i */ - if ( find_first_crystal(crystals, n_crystals, csplit, i) != -1 ) + if ( find_first_crystal(crystals, images, n_crystals, csplit, i) != -1 ) { n_cry++; } else { @@ -621,11 +621,10 @@ static void skip_to_end(FILE *fh) } -static int set_initial_params(Crystal *cr, FILE *fh, double force_bandwidth, - double force_radius, double force_lambda) +static int set_initial_params(Crystal *cr, struct image *image, FILE *fh, + double force_bandwidth, double force_radius, + double force_lambda) { - struct image *image = crystal_get_image(cr); - if ( fh != NULL ) { int err; @@ -1085,6 +1084,7 @@ int main(int argc, char *argv[]) int no_Bscale = 0; int no_pr = 0; Crystal **crystals; + struct image **images; char *pmodel_str = NULL; PartialityModel pmodel = PMODEL_XSPHERE; int min_measurements = 2; @@ -1526,6 +1526,7 @@ int main(int argc, char *argv[]) n_crystals = 0; n_crystals_seen = 0; crystals = NULL; + images = NULL; if ( sparams_fn != NULL ) { char line[1024]; sparams_fh = fopen(sparams_fn, "r"); @@ -1575,6 +1576,7 @@ int main(int argc, char *argv[]) Crystal *cr; Crystal **crystals_new; + struct image **images_new; RefList *cr_refl; RefList *cr_refl_raw; struct image *image_for_crystal; @@ -1606,6 +1608,14 @@ int main(int argc, char *argv[]) crystals[n_crystals] = crystal_copy_deep(image->crystals[i]); cr = crystals[n_crystals]; + images_new = realloc(images, + (n_crystals+1)*sizeof(struct image *)); + if ( images_new == NULL ) { + ERROR("Failed to allocate memory for image list\n"); + return 1; + } + images = images_new; + /* Create a completely new, separate image * structure for this crystal. */ image_for_crystal = image_new(); @@ -1615,6 +1625,7 @@ int main(int argc, char *argv[]) } *image_for_crystal = *image; + images[n_crystals] = image_for_crystal; image_for_crystal->n_crystals = 1; image_for_crystal->crystals = malloc(sizeof(Crystal *)); image_for_crystal->crystals[0] = cr; @@ -1641,7 +1652,8 @@ int main(int argc, char *argv[]) crystal_set_user_flag(cr, PRFLAG_OK); reflist_free(cr_refl); - if ( set_initial_params(cr, sparams_fh, force_bandwidth, + if ( set_initial_params(cr, image_for_crystal, + sparams_fh, force_bandwidth, force_radius, force_lambda) ) { ERROR("Failed to set initial parameters\n"); @@ -1681,16 +1693,16 @@ int main(int argc, char *argv[]) for ( icryst=0; icrystn_datasets; j++ ) { write_custom_split(csplit, j, crystals, - n_crystals, pmodel, + images, n_crystals, pmodel, min_measurements, push_res, sym, nthreads, tmp); @@ -1826,7 +1838,7 @@ int main(int argc, char *argv[]) if ( csplit != NULL ) { int i; for ( i=0; in_datasets; i++ ) { - write_custom_split(csplit, i, crystals, n_crystals, + write_custom_split(csplit, i, crystals, images, n_crystals, pmodel, min_measurements, push_res, sym, nthreads, outfile); } -- cgit v1.2.3 From e42773c17459e5bad58632b2792a3f18abb70178 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 9 Nov 2023 09:56:00 +0100 Subject: Crystal: Remove reference to image structure (part 3) --- src/partialator.c | 19 +++++++---- src/post-refinement.c | 88 +++++++++++++++++++++++++-------------------------- src/post-refinement.h | 11 ++++--- 3 files changed, 62 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/src/partialator.c b/src/partialator.c index de59efde..6d362a01 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -896,6 +896,7 @@ struct log_qargs int iter; int next; Crystal **crystals; + struct image **images; int n_crystals; RefList *full; int scaleflags; @@ -908,6 +909,7 @@ struct log_qargs struct log_args { Crystal *cr; + struct image *image; RefList *full; int scaleflags; PartialityModel pmodel; @@ -928,6 +930,7 @@ static void *get_log_task(void *vp) if ( task == NULL ) return NULL; task->cr = qargs->crystals[qargs->next]; + task->image = qargs->images[qargs->next]; task->full = qargs->full; task->iter = qargs->iter; task->cnum = qargs->next; @@ -943,11 +946,11 @@ static void *get_log_task(void *vp) static void write_logs(void *vp, int cookie) { struct log_args *args = vp; - write_specgraph(args->cr, args->full, args->iter, args->cnum, + write_specgraph(args->cr, args->image, args->full, args->iter, args->cnum, args->log_folder); - write_gridscan(args->cr, args->full, args->iter, args->cnum, + write_gridscan(args->cr, args->image, args->full, args->iter, args->cnum, args->scaleflags, args->pmodel, args->log_folder); - write_test_logs(args->cr, args->full, args->iter, args->cnum, + write_test_logs(args->cr, args->image, args->full, args->iter, args->cnum, args->log_folder); } @@ -962,7 +965,8 @@ static void done_log(void *vqargs, void *vp) } -static void write_logs_parallel(Crystal **crystals, int n_crystals, +static void write_logs_parallel(Crystal **crystals, struct image **images, + int n_crystals, RefList *full, int iter, int n_threads, int scaleflags, PartialityModel pmodel, const char *log_folder) @@ -973,6 +977,7 @@ static void write_logs_parallel(Crystal **crystals, int n_crystals, qargs.next = 0; qargs.full = full; qargs.crystals = crystals; + qargs.images = images; qargs.n_done = 0; qargs.n_crystals = n_crystals; qargs.scaleflags = scaleflags; @@ -1727,7 +1732,7 @@ int main(int argc, char *argv[]) if ( do_write_logs ) { write_pgraph(full, crystals, n_crystals, 0, "", log_folder); - write_logs_parallel(crystals, n_crystals, full, 0, nthreads, + write_logs_parallel(crystals, images, n_crystals, full, 0, nthreads, scaleflags, pmodel, log_folder); } @@ -1737,7 +1742,7 @@ int main(int argc, char *argv[]) STATUS("Scaling and refinement cycle %i of %i\n", itn+1, n_iter); if ( !no_pr ) { - refine_all(crystals, n_crystals, full, nthreads, pmodel, + refine_all(crystals, images, n_crystals, full, nthreads, pmodel, itn+1, no_logs, sym, amb, scaleflags, log_folder); } @@ -1816,7 +1821,7 @@ int main(int argc, char *argv[]) show_all_residuals(crystals, n_crystals, full, no_free); if ( do_write_logs ) { write_pgraph(full, crystals, n_crystals, -1, "", log_folder); - write_logs_parallel(crystals, n_crystals, full, -1, nthreads, + write_logs_parallel(crystals, images, n_crystals, full, -1, nthreads, scaleflags, pmodel, log_folder); } diff --git a/src/post-refinement.c b/src/post-refinement.c index 70b14a0f..79557e18 100644 --- a/src/post-refinement.c +++ b/src/post-refinement.c @@ -56,13 +56,14 @@ struct rf_alteration struct rf_priv { - Crystal *cr; /**< Original crystal (before any refinement) */ + Crystal *cr; /**< Original crystal (before any refinement) */ + struct image *image; /**< Original image (before any refinement) */ const RefList *full; int serial; int scaleflags; PartialityModel pmodel; - Crystal *cr_tgt; /**< Crystal to use for testing modifications */ + Crystal *cr_tgt; /**< Crystal to use for testing modifications */ struct image image_tgt; /**< Image structure to go with cr_tgt */ }; @@ -151,32 +152,30 @@ static void rotate_cell_xy(UnitCell *source, UnitCell *tgt, static void apply_parameters(Crystal *cr_orig, Crystal *cr_tgt, + struct image *im_orig, struct image *im_tgt, struct rf_alteration alter) { - double R, lambda; + double R; struct gaussian g; - struct image *image; - image = crystal_get_image(cr_tgt); R = crystal_get_profile_radius(cr_orig); - lambda = crystal_get_image_const(cr_orig)->lambda; rotate_cell_xy(crystal_get_cell(cr_orig), crystal_get_cell(cr_tgt), alter.rot_x, alter.rot_y); crystal_set_profile_radius(cr_tgt, R+alter.delta_R); - image->lambda = lambda+alter.delta_wave; + im_tgt->lambda = im_orig->lambda+alter.delta_wave; - g.kcen = 1.0/image->lambda; - g.sigma = image->bw/image->lambda; + g.kcen = 1.0/im_tgt->lambda; + g.sigma = im_tgt->bw/im_tgt->lambda; g.area = 1; - spectrum_set_gaussians(image->spectrum, &g, 1); + spectrum_set_gaussians(im_tgt->spectrum, &g, 1); } static double calc_residual(struct rf_priv *pv, struct rf_alteration alter, int free) { - apply_parameters(pv->cr, pv->cr_tgt, alter); + apply_parameters(pv->cr, pv->cr_tgt, pv->image, &pv->image_tgt, alter); if ( fabs(crystal_get_profile_radius(pv->cr_tgt)) > 5e9 ) { STATUS("radius > 5e9\n"); @@ -189,13 +188,13 @@ static double calc_residual(struct rf_priv *pv, struct rf_alteration alter, return NAN; } - if ( crystal_get_image(pv->cr_tgt)->lambda <= 0.0 ) { + if ( pv->image_tgt.lambda <= 0.0 ) { STATUS("lambda < 0\n"); return NAN; } - update_predictions(pv->cr_tgt); - calculate_partialities(pv->cr_tgt, pv->pmodel); + update_predictions(pv->cr_tgt, &pv->image_tgt); + calculate_partialities(pv->cr_tgt, &pv->image_tgt, pv->pmodel); return residual(pv->cr_tgt, pv->full, free, NULL, NULL); @@ -264,7 +263,7 @@ static void reindex_cell(UnitCell *cell, SymOpList *amb, int idx) } -static void try_reindex(Crystal *crin, const RefList *full, +static void try_reindex(Crystal *crin, struct image *image, const RefList *full, SymOpList *sym, SymOpList *amb, int scaleflags, PartialityModel pmodel) { @@ -296,8 +295,8 @@ static void try_reindex(Crystal *crin, const RefList *full, amb, sym, idx); crystal_set_reflections(cr, list); - update_predictions(cr); - calculate_partialities(cr, pmodel); + update_predictions(cr, image); + calculate_partialities(cr, image, pmodel); if ( scale_one_crystal(cr, full, scaleflags) ) return; residual_flipped = residual(cr, full, 0, NULL, NULL); @@ -316,12 +315,11 @@ static void try_reindex(Crystal *crin, const RefList *full, } -void write_test_logs(Crystal *crystal, const RefList *full, +void write_test_logs(Crystal *crystal, struct image *image, const RefList *full, signed int cycle, int serial, const char *log_folder) { FILE *fh; - struct image *image = crystal_get_image(crystal); char tmp[256]; char ins[16]; @@ -367,7 +365,7 @@ void write_test_logs(Crystal *crystal, const RefList *full, } -void write_specgraph(Crystal *crystal, const RefList *full, +void write_specgraph(Crystal *crystal, struct image *image, const RefList *full, signed int cycle, int serial, const char *log_folder) { @@ -378,7 +376,6 @@ void write_specgraph(Crystal *crystal, const RefList *full, double G = crystal_get_osf(crystal); double B = crystal_get_Bfac(crystal); UnitCell *cell; - struct image *image = crystal_get_image(crystal); char ins[16]; snprintf(tmp, 256, "%s/specgraph-crystal%i.dat", log_folder, serial); @@ -443,7 +440,7 @@ void write_specgraph(Crystal *crystal, const RefList *full, } -static void write_angle_grid(Crystal *cr, const RefList *full, +static void write_angle_grid(Crystal *cr, struct image *image, const RefList *full, signed int cycle, int serial, int scaleflags, PartialityModel pmodel, const char *log_folder) @@ -462,10 +459,9 @@ static void write_angle_grid(Crystal *cr, const RefList *full, priv.scaleflags = scaleflags; priv.pmodel = pmodel; priv.cr_tgt = crystal_copy(cr); - priv.image_tgt = *crystal_get_image(cr); + priv.image_tgt = *image; spectrum = spectrum_new(); priv.image_tgt.spectrum = spectrum; - crystal_set_image(priv.cr_tgt, &priv.image_tgt); list = copy_reflist(crystal_get_reflections(cr)); crystal_set_reflections(priv.cr_tgt, list); cell = cell_new_from_cell(crystal_get_cell(cr)); @@ -510,7 +506,7 @@ static void write_angle_grid(Crystal *cr, const RefList *full, } -static void write_radius_grid(Crystal *cr, const RefList *full, +static void write_radius_grid(Crystal *cr, struct image *image, const RefList *full, signed int cycle, int serial, int scaleflags, PartialityModel pmodel, const char *log_folder) @@ -529,10 +525,9 @@ static void write_radius_grid(Crystal *cr, const RefList *full, priv.scaleflags = scaleflags; priv.pmodel = pmodel; priv.cr_tgt = crystal_copy(cr); - priv.image_tgt = *crystal_get_image(cr); + priv.image_tgt = *image; spectrum = spectrum_new(); priv.image_tgt.spectrum = spectrum; - crystal_set_image(priv.cr_tgt, &priv.image_tgt); list = copy_reflist(crystal_get_reflections(cr)); crystal_set_reflections(priv.cr_tgt, list); cell = cell_new_from_cell(crystal_get_cell(cr)); @@ -577,13 +572,13 @@ static void write_radius_grid(Crystal *cr, const RefList *full, } -void write_gridscan(Crystal *cr, const RefList *full, +void write_gridscan(Crystal *cr, struct image *image, const RefList *full, signed int cycle, int serial, int scaleflags, PartialityModel pmodel, const char *log_folder) { - write_angle_grid(cr, full, cycle, serial, scaleflags, pmodel, log_folder); - write_radius_grid(cr, full, cycle, serial, scaleflags, pmodel, log_folder); + write_angle_grid(cr, image, full, cycle, serial, scaleflags, pmodel, log_folder); + write_radius_grid(cr, image, full, cycle, serial, scaleflags, pmodel, log_folder); } @@ -631,7 +626,7 @@ static int refine_loop(struct rf_alteration *cur, struct rf_alteration *dirns, *total_iter, lowest_fom, freefom, cur->rot_x, cur->rot_y, crystal_get_profile_radius(priv->cr)+cur->delta_R, - crystal_get_image_const(priv->cr)->lambda+cur->delta_wave); + priv->image->lambda+cur->delta_wave); } } while ( (best != 0) && (n_iter < 10) ); @@ -649,7 +644,7 @@ static void zero_alter(struct rf_alteration *alter) } -static void do_pr_refine(Crystal *cr, const RefList *full, +static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full, PartialityModel pmodel, int serial, int cycle, int write_logs, SymOpList *sym, SymOpList *amb, int scaleflags, @@ -664,7 +659,7 @@ static void do_pr_refine(Crystal *cr, const RefList *full, UnitCell *cell; Spectrum *spectrum; - try_reindex(cr, full, sym, amb, scaleflags, pmodel); + try_reindex(cr, image, full, sym, amb, scaleflags, pmodel); zero_alter(&alter); @@ -674,10 +669,9 @@ static void do_pr_refine(Crystal *cr, const RefList *full, priv.scaleflags = scaleflags; priv.pmodel = pmodel; priv.cr_tgt = crystal_copy(cr); - priv.image_tgt = *crystal_get_image(cr); + priv.image_tgt = *image; spectrum = spectrum_new(); priv.image_tgt.spectrum = spectrum; - crystal_set_image(priv.cr_tgt, &priv.image_tgt); list = copy_reflist(crystal_get_reflections(cr)); crystal_set_reflections(priv.cr_tgt, list); cell = cell_new_from_cell(crystal_get_cell(cr)); @@ -700,7 +694,7 @@ static void do_pr_refine(Crystal *cr, const RefList *full, n_iter, fom, freefom, alter.rot_x, alter.rot_y, crystal_get_profile_radius(cr)+alter.delta_R, - crystal_get_image(cr)->lambda+alter.delta_wave); + image->lambda+alter.delta_wave); } } @@ -724,15 +718,15 @@ static void do_pr_refine(Crystal *cr, const RefList *full, refine_loop(&alter, dirns, 2, &priv, &n_iter, fh); /* Apply the final shifts */ - apply_parameters(cr, cr, alter); - update_predictions(cr); - calculate_partialities(cr, pmodel); + apply_parameters(cr, cr, image, image, alter); + update_predictions(cr, image); + calculate_partialities(cr, image, pmodel); if ( write_logs ) { - write_gridscan(cr, full, cycle, serial, scaleflags, + write_gridscan(cr, image, full, cycle, serial, scaleflags, pmodel, log_folder); - write_specgraph(cr, full, cycle, serial, log_folder); - write_test_logs(cr, full, cycle, serial, log_folder); + write_specgraph(cr, image, full, cycle, serial, log_folder); + write_test_logs(cr, image, full, cycle, serial, log_folder); } if ( crystal_get_profile_radius(cr) > 5e9 ) { @@ -753,6 +747,7 @@ struct refine_args { RefList *full; Crystal *crystal; + struct image *image; PartialityModel pmodel; int serial; int cycle; @@ -769,6 +764,7 @@ struct pr_queue_args int n_started; int n_done; Crystal **crystals; + struct image **images; int n_crystals; struct refine_args task_defaults; }; @@ -777,12 +773,11 @@ struct pr_queue_args static void refine_image(void *task, int id) { struct refine_args *pargs = task; - Crystal *cr = pargs->crystal; int write_logs = 0; write_logs = !pargs->no_logs && (pargs->serial % 20 == 0); - do_pr_refine(cr, pargs->full, pargs->pmodel, + do_pr_refine(pargs->crystal, pargs->image, pargs->full, pargs->pmodel, pargs->serial, pargs->cycle, write_logs, pargs->sym, pargs->amb, pargs->scaleflags, pargs->log_folder); @@ -798,6 +793,7 @@ static void *get_image(void *vqargs) memcpy(task, &qargs->task_defaults, sizeof(struct refine_args)); task->crystal = qargs->crystals[qargs->n_started]; + task->image = qargs->images[qargs->n_started]; task->serial = qargs->n_started; qargs->n_started++; @@ -817,7 +813,7 @@ static void done_image(void *vqargs, void *task) } -void refine_all(Crystal **crystals, int n_crystals, +void refine_all(Crystal **crystals, struct image **images, int n_crystals, RefList *full, int nthreads, PartialityModel pmodel, int cycle, int no_logs, SymOpList *sym, SymOpList *amb, int scaleflags, @@ -828,6 +824,7 @@ void refine_all(Crystal **crystals, int n_crystals, task_defaults.full = full; task_defaults.crystal = NULL; + task_defaults.image = NULL; task_defaults.pmodel = pmodel; task_defaults.cycle = cycle; task_defaults.no_logs = no_logs; @@ -842,6 +839,7 @@ void refine_all(Crystal **crystals, int n_crystals, qargs.n_done = 0; qargs.n_crystals = n_crystals; qargs.crystals = crystals; + qargs.images = images; /* Don't have threads which are doing nothing */ if ( n_crystals < nthreads ) nthreads = n_crystals; diff --git a/src/post-refinement.h b/src/post-refinement.h index 546050a4..7eb1fd0b 100644 --- a/src/post-refinement.h +++ b/src/post-refinement.h @@ -58,18 +58,20 @@ enum prflag extern const char *str_prflag(enum prflag flag); -extern void refine_all(Crystal **crystals, int n_crystals, +extern void refine_all(Crystal **crystals, struct image **images, int n_crystals, RefList *full, int nthreads, PartialityModel pmodel, int cycle, int no_logs, SymOpList *sym, SymOpList *amb, int scaleflags, const char *log_folder); -extern void write_gridscan(Crystal *cr, const RefList *full, +extern void write_gridscan(Crystal *cr, struct image *image, + const RefList *full, int cycle, int serial, int scaleflags, PartialityModel model, const char *log_folder); -extern void write_specgraph(Crystal *crystal, const RefList *full, +extern void write_specgraph(Crystal *crystal, struct image *image, + const RefList *full, signed int cycle, int serial, const char *log_folder); @@ -77,7 +79,8 @@ extern void write_specgraph(Crystal *crystal, const RefList *full, extern double gradient(Crystal *cr, int k, Reflection *refl, PartialityModel pmodel); -extern void write_test_logs(Crystal *crystal, const RefList *full, +extern void write_test_logs(Crystal *crystal, struct image *image, + const RefList *full, signed int cycle, int serial, const char *log_folder); -- cgit v1.2.3 From 9ad42732052c3e2ff41c00bed8b5cec013c8941e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 14 Nov 2023 11:51:40 +0100 Subject: Add missing image initialisers --- src/post-refinement.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/post-refinement.c b/src/post-refinement.c index 79557e18..1bad55ea 100644 --- a/src/post-refinement.c +++ b/src/post-refinement.c @@ -459,6 +459,7 @@ static void write_angle_grid(Crystal *cr, struct image *image, const RefList *fu priv.scaleflags = scaleflags; priv.pmodel = pmodel; priv.cr_tgt = crystal_copy(cr); + priv.image = image; priv.image_tgt = *image; spectrum = spectrum_new(); priv.image_tgt.spectrum = spectrum; @@ -525,6 +526,7 @@ static void write_radius_grid(Crystal *cr, struct image *image, const RefList *f priv.scaleflags = scaleflags; priv.pmodel = pmodel; priv.cr_tgt = crystal_copy(cr); + priv.image = image; priv.image_tgt = *image; spectrum = spectrum_new(); priv.image_tgt.spectrum = spectrum; @@ -669,6 +671,7 @@ static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full, priv.scaleflags = scaleflags; priv.pmodel = pmodel; priv.cr_tgt = crystal_copy(cr); + priv.image = image; priv.image_tgt = *image; spectrum = spectrum_new(); priv.image_tgt.spectrum = spectrum; -- cgit v1.2.3 From 8b51b44b1575a5e4c8d1c41924cebed93ff8d8cc Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Jan 2024 10:16:59 +0100 Subject: Crystals shouldn't own RefLists (part 3) This fixes integration.c, peaks.c and process_hkl.c. --- src/process_hkl.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/process_hkl.c b/src/process_hkl.c index be1c95d4..31e4b1fc 100644 --- a/src/process_hkl.c +++ b/src/process_hkl.c @@ -271,7 +271,7 @@ static void apply_kpred(double k, RefList *list) static int merge_crystal(RefList *model, struct image *image, Crystal *cr, - RefList *reference, const SymOpList *sym, + RefList *new_refl, RefList *reference, const SymOpList *sym, double **hist_vals, signed int hist_h, signed int hist_k, signed int hist_l, int *hist_n, struct polarisation p, double min_snr, double max_adu, @@ -280,11 +280,8 @@ static int merge_crystal(RefList *model, struct image *image, Crystal *cr, { Reflection *refl; RefListIterator *iter; - RefList *new_refl; double scale; - new_refl = crystal_get_reflections(cr); - /* First, correct for polarisation */ apply_kpred(1.0/image->lambda, new_refl); polarisation_correction(new_refl, crystal_get_cell(cr), p); @@ -309,7 +306,7 @@ static int merge_crystal(RefList *model, struct image *image, Crystal *cr, scale = 1.0; } - for ( refl = first_refl(crystal_get_reflections(cr), &iter); + for ( refl = first_refl(new_refl, &iter); refl != NULL; refl = next_refl(refl, iter) ) { @@ -431,7 +428,8 @@ static int merge_stream(Stream *st, for ( i=0; in_crystals; i++ ) { - Crystal *cr = image->crystals[i]; + Crystal *cr = image->crystals[i].cr; + RefList *refls = image->crystals[i].refls; n_crystals_seen++; if ( (n_crystals_seen > start_after) @@ -440,8 +438,8 @@ static int merge_stream(Stream *st, { int r; n_crystals++; - r = merge_crystal(model, image, cr, reference, - sym, hist_vals, + r = merge_crystal(model, image, cr, refls, + reference, sym, hist_vals, hist_h, hist_k, hist_l, hist_i, p, min_snr, max_adu, push_res, -- cgit v1.2.3 From 335067449b3858a55442ffb355af56f55410d154 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Jan 2024 15:16:52 +0100 Subject: Crystals shouldn't own RefLists (part 5) This fixes the entire partialator/scaling/rejection part. --- src/merge.c | 34 ++++++++------ src/merge.h | 8 ++-- src/partialator.c | 125 ++++++++++++++++++++++++-------------------------- src/post-refinement.c | 98 +++++++++++++++++++-------------------- src/post-refinement.h | 7 +-- src/rejection.c | 43 +++++++++-------- src/rejection.h | 6 +-- src/scaling.c | 25 +++++----- src/scaling.h | 7 +-- 9 files changed, 178 insertions(+), 175 deletions(-) (limited to 'src') diff --git a/src/merge.c b/src/merge.c index 0a5c5f14..4a2dae66 100644 --- a/src/merge.c +++ b/src/merge.c @@ -55,7 +55,7 @@ struct merge_queue_args { RefList *full; pthread_rwlock_t full_lock; - Crystal **crystals; + struct crystal_refls *crystals; int n_started; double push_res; int use_weak; @@ -68,6 +68,7 @@ struct merge_worker_args { struct merge_queue_args *qargs; Crystal *crystal; + RefList *refls; int crystal_number; int n_reflections; }; @@ -81,7 +82,9 @@ static void *create_merge_job(void *vqargs) wargs = malloc(sizeof(struct merge_worker_args)); wargs->qargs = qargs; wargs->crystal_number = qargs->n_started; - wargs->crystal = qargs->crystals[qargs->n_started++]; + wargs->crystal = qargs->crystals[qargs->n_started].cr; + wargs->refls = qargs->crystals[qargs->n_started].refls; + qargs->n_started++; return wargs; } @@ -180,7 +183,7 @@ static void run_merge_job(void *vwargs, int cookie) G = crystal_get_osf(cr); B = crystal_get_Bfac(cr); - for ( refl = first_refl(crystal_get_reflections(cr), &iter); + for ( refl = first_refl(wargs->refls, &iter); refl != NULL; refl = next_refl(refl, iter) ) { @@ -262,8 +265,8 @@ static void finalise_merge_job(void *vqargs, void *vwargs) } -RefList *merge_intensities(Crystal **crystals, int n, int n_threads, - int min_meas, +RefList *merge_intensities(struct crystal_refls *crystals, int n, + int n_threads, int min_meas, double push_res, int use_weak, int ln_merge) { RefList *full; @@ -364,7 +367,7 @@ double correct_reflection(double val, Reflection *refl, double osf, double Bfac, } -double residual(Crystal *cr, const RefList *full, int free, +double residual(RefList *list, Crystal *cr, const RefList *full, int free, int *pn_used, const char *filename) { Reflection *refl; @@ -376,7 +379,7 @@ double residual(Crystal *cr, const RefList *full, int free, double B = crystal_get_Bfac(cr); UnitCell *cell = crystal_get_cell(cr); - for ( refl = first_refl(crystal_get_reflections(cr), &iter); + for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { @@ -420,7 +423,8 @@ double residual(Crystal *cr, const RefList *full, int free, } -double log_residual(Crystal *cr, const RefList *full, int free, +double log_residual(RefList *list, Crystal *cr, + const RefList *full, int free, int *pn_used, const char *filename) { double dev = 0.0; @@ -439,7 +443,7 @@ double log_residual(Crystal *cr, const RefList *full, int free, } } - for ( refl = first_refl(crystal_get_reflections(cr), &iter); + for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { @@ -487,7 +491,7 @@ double log_residual(Crystal *cr, const RefList *full, int free, /* Has to match run_merge_job to be useful */ -void write_unmerged(const char *fn, Crystal **crystals, int n_crystals) +void write_unmerged(const char *fn, struct crystal_refls *crystals, int n_crystals) { FILE *fh; int i; @@ -506,17 +510,17 @@ void write_unmerged(const char *fn, Crystal **crystals, int n_crystals) UnitCell *cell; fprintf(fh, "Crystal %i\n", i); - if ( crystal_get_user_flag(crystals[i]) ) { + if ( crystal_get_user_flag(crystals[i].cr) ) { fprintf(fh, "Flagged: yes\n"); } else { fprintf(fh, "Flagged: no\n"); } - G = crystal_get_osf(crystals[i]); - B = crystal_get_Bfac(crystals[i]); - cell = crystal_get_cell(crystals[i]); + G = crystal_get_osf(crystals[i].cr); + B = crystal_get_Bfac(crystals[i].cr); + cell = crystal_get_cell(crystals[i].cr); - for ( refl = first_refl(crystal_get_reflections(crystals[i]), &iter); + for ( refl = first_refl(crystals[i].refls, &iter); refl != NULL; refl = next_refl(refl, iter) ) { diff --git a/src/merge.h b/src/merge.h index 5f7e0e64..e304db78 100644 --- a/src/merge.h +++ b/src/merge.h @@ -43,7 +43,7 @@ #define MIN_PART_MERGE (0.3) -extern RefList *merge_intensities(Crystal **crystals, int n, int n_threads, +extern RefList *merge_intensities(struct crystal_refls *crystals, int n, int n_threads, int min_meas, double push_res, int use_weak, int ln_merge); @@ -53,12 +53,12 @@ extern double correct_reflection_nopart(double val, Reflection *refl, extern double correct_reflection(double val, Reflection *refl, double osf, double Bfac, double res); -extern double residual(Crystal *cr, const RefList *full, int free, +extern double residual(RefList *list, Crystal *cr, const RefList *full, int free, int *pn_used, const char *filename); -extern double log_residual(Crystal *cr, const RefList *full, int free, +extern double log_residual(RefList *list, Crystal *cr, const RefList *full, int free, int *pn_used, const char *filename); -extern void write_unmerged(const char *fn, Crystal **crystals, int n_crystals); +extern void write_unmerged(const char *fn, struct crystal_refls *crystals, int n_crystals); #endif /* MERGE */ diff --git a/src/partialator.c b/src/partialator.c index 6d362a01..659a12c5 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -169,14 +169,14 @@ static void add_to_csplit(struct custom_split *csplit, const char *id, /* Write two-way split results (i.e. for CC1/2 etc) for this list of crystals */ -static void write_split(Crystal **crystals, int n_crystals, const char *outfile, - int nthreads, PartialityModel pmodel, +static void write_split(struct crystal_refls *crystals, int n_crystals, + const char *outfile, int nthreads, PartialityModel pmodel, int min_measurements, SymOpList *sym, double push_res) { char tmp[1024]; RefList *split; - Crystal **crystals1; - Crystal **crystals2; + struct crystal_refls *crystals1; + struct crystal_refls *crystals2; int n_crystals1 = 0; int n_crystals2 = 0; int i; @@ -186,13 +186,12 @@ static void write_split(Crystal **crystals, int n_crystals, const char *outfile, return; } - crystals1 = malloc(n_crystals * sizeof(Crystal *)); + crystals1 = malloc(n_crystals * sizeof(struct crystal_refls)); if ( crystals1 == NULL ) return; - crystals2 = malloc(n_crystals * sizeof(Crystal *)); + crystals2 = malloc(n_crystals * sizeof(struct crystal_refls)); if ( crystals2 == NULL ) return; - for ( i=0; in_datasets; i++ ) { /* Try to find a crystal with dsn = i */ - if ( find_first_crystal(crystals, images, n_crystals, csplit, i) != -1 ) + if ( find_first_crystal(images, n_crystals, csplit, i) != -1 ) { n_cry++; } else { @@ -735,7 +735,7 @@ static void write_to_pgraph(FILE *fh, RefList *list, RefList *full, Crystal *cr, } -static void write_pgraph(RefList *full, Crystal **crystals, int n_crystals, +static void write_pgraph(RefList *full, struct crystal_refls *crystals, int n_crystals, signed int iter, const char *suff, const char *log_folder) { @@ -761,16 +761,16 @@ static void write_pgraph(RefList *full, Crystal **crystals, int n_crystals, } for ( i=0; icr = qargs->crystals[qargs->next]; + task->cr = qargs->crystals[qargs->next].cr; + task->refls = qargs->crystals[qargs->next].refls; task->image = qargs->images[qargs->next]; task->full = qargs->full; task->iter = qargs->iter; @@ -946,12 +948,13 @@ static void *get_log_task(void *vp) static void write_logs(void *vp, int cookie) { struct log_args *args = vp; - write_specgraph(args->cr, args->image, args->full, args->iter, args->cnum, - args->log_folder); - write_gridscan(args->cr, args->image, args->full, args->iter, args->cnum, - args->scaleflags, args->pmodel, args->log_folder); - write_test_logs(args->cr, args->image, args->full, args->iter, args->cnum, - args->log_folder); + write_specgraph(args->refls, args->cr, args->image, args->full, + args->iter, args->cnum, args->log_folder); + write_gridscan(args->refls, args->cr, args->image, args->full, + args->iter, args->cnum, args->scaleflags, args->pmodel, + args->log_folder); + write_test_logs(args->cr, args->image, args->full, args->iter, + args->cnum, args->log_folder); } @@ -965,7 +968,7 @@ static void done_log(void *vqargs, void *vp) } -static void write_logs_parallel(Crystal **crystals, struct image **images, +static void write_logs_parallel(struct crystal_refls *crystals, struct image **images, int n_crystals, RefList *full, int iter, int n_threads, int scaleflags, PartialityModel pmodel, @@ -1088,7 +1091,7 @@ int main(int argc, char *argv[]) int no_scale = 0; int no_Bscale = 0; int no_pr = 0; - Crystal **crystals; + struct crystal_refls *crystals; struct image **images; char *pmodel_str = NULL; PartialityModel pmodel = PMODEL_XSPHERE; @@ -1566,7 +1569,6 @@ int main(int argc, char *argv[]) do { struct image *image; - RefList *as; int i; image = stream_read_chunk(st, STREAM_REFLECTIONS); @@ -1580,41 +1582,39 @@ int main(int argc, char *argv[]) for ( i=0; in_crystals; i++ ) { Crystal *cr; - Crystal **crystals_new; + struct crystal_refls *crystals_new; struct image **images_new; RefList *cr_refl; - RefList *cr_refl_raw; struct image *image_for_crystal; double lowest_r; n_crystals_seen++; if ( n_crystals_seen <= start_after ) continue; - if ( crystal_get_resolution_limit(image->crystals[i]) < min_res ) continue; + if ( crystal_get_resolution_limit(image->crystals[i].cr) < min_res ) continue; - lowest_r = lowest_reflection(crystal_get_cell(image->crystals[i])); - if ( crystal_get_profile_radius(image->crystals[i]) > 0.5*lowest_r ) { + lowest_r = lowest_reflection(crystal_get_cell(image->crystals[i].cr)); + if ( crystal_get_profile_radius(image->crystals[i].cr) > 0.5*lowest_r ) { ERROR("Rejecting %s %s crystal %i because " "profile radius is obviously too big (%e %e).\n", image->filename, image->ev, i, - crystal_get_profile_radius(image->crystals[i]), + crystal_get_profile_radius(image->crystals[i].cr), lowest_r); continue; } crystals_new = realloc(crystals, - (n_crystals+1)*sizeof(Crystal *)); + (n_crystals+1)*sizeof(struct crystal_refls)); if ( crystals_new == NULL ) { ERROR("Failed to allocate memory for crystal " "list.\n"); return 1; } crystals = crystals_new; - crystals[n_crystals] = crystal_copy_deep(image->crystals[i]); - cr = crystals[n_crystals]; + cr = crystal_copy_deep(image->crystals[i].cr); + crystals[n_crystals].cr = cr; - images_new = realloc(images, - (n_crystals+1)*sizeof(struct image *)); + images_new = realloc(images, (n_crystals+1)*sizeof(struct image *)); if ( images_new == NULL ) { ERROR("Failed to allocate memory for image list\n"); return 1; @@ -1631,9 +1631,8 @@ int main(int argc, char *argv[]) *image_for_crystal = *image; images[n_crystals] = image_for_crystal; - image_for_crystal->n_crystals = 1; - image_for_crystal->crystals = malloc(sizeof(Crystal *)); - image_for_crystal->crystals[0] = cr; + image_for_crystal->n_crystals = 0; + image_for_crystal->crystals = NULL; image_for_crystal->filename = strdup(image->filename); image_for_crystal->ev = safe_strdup(image->ev); image_for_crystal->detgeom = NULL; @@ -1644,19 +1643,16 @@ int main(int argc, char *argv[]) image_for_crystal->bad = NULL; image_for_crystal->sat = NULL; - /* This is the raw list of reflections */ - cr_refl_raw = crystal_get_reflections(cr); - - cr_refl = apply_max_adu(cr_refl_raw, max_adu); - reflist_free(cr_refl_raw); - + cr_refl = apply_max_adu(image->crystals[i].refls, max_adu); if ( !no_free ) select_free_reflections(cr_refl, rng); - - as = asymmetric_indices(cr_refl, sym); - crystal_set_reflections(cr, as); - crystal_set_user_flag(cr, PRFLAG_OK); + image_add_crystal_refls(image_for_crystal, cr, + asymmetric_indices(cr_refl, sym)); reflist_free(cr_refl); + crystals[n_crystals].cr = image_for_crystal->crystals[0].cr; + crystals[n_crystals].refls = image_for_crystal->crystals[0].refls; + + crystal_set_user_flag(cr, PRFLAG_OK); if ( set_initial_params(cr, image_for_crystal, sparams_fh, force_bandwidth, force_radius, force_lambda) ) @@ -1697,14 +1693,13 @@ int main(int argc, char *argv[]) STATUS("Initial partiality calculation...\n"); for ( icryst=0; icrystcr_tgt, &pv->image_tgt); - calculate_partialities(pv->cr_tgt, &pv->image_tgt, pv->pmodel); + update_predictions(pv->refls, pv->cr_tgt, &pv->image_tgt); + calculate_partialities(pv->refls, pv->cr_tgt, &pv->image_tgt, pv->pmodel); - return residual(pv->cr_tgt, pv->full, free, NULL, NULL); + return residual(pv->refls, pv->cr_tgt, pv->full, free, NULL, NULL); } @@ -263,9 +264,9 @@ static void reindex_cell(UnitCell *cell, SymOpList *amb, int idx) } -static void try_reindex(Crystal *crin, struct image *image, const RefList *full, - SymOpList *sym, SymOpList *amb, int scaleflags, - PartialityModel pmodel) +static void try_reindex(RefList **prefls, Crystal *crin, struct image *image, + const RefList *full, SymOpList *sym, SymOpList *amb, + int scaleflags, PartialityModel pmodel) { Crystal *cr; double residual_original; @@ -273,8 +274,8 @@ static void try_reindex(Crystal *crin, struct image *image, const RefList *full, if ( sym == NULL || amb == NULL ) return; - if ( scale_one_crystal(crin, full, scaleflags) ) return; - residual_original = residual(crin, full, 0, NULL, NULL); + if ( scale_one_crystal(*prefls, crin, full, scaleflags) ) return; + residual_original = residual(*prefls, crin, full, 0, NULL, NULL); cr = crystal_copy(crin); @@ -291,23 +292,20 @@ static void try_reindex(Crystal *crin, struct image *image, const RefList *full, reindex_cell(cell, amb, idx); crystal_set_cell(cr, cell); - list = reindex_reflections(crystal_get_reflections(crin), - amb, sym, idx); - crystal_set_reflections(cr, list); - - update_predictions(cr, image); - calculate_partialities(cr, image, pmodel); - - if ( scale_one_crystal(cr, full, scaleflags) ) return; - residual_flipped = residual(cr, full, 0, NULL, NULL); + list = reindex_reflections(*prefls, amb, sym, idx); + update_predictions(list, cr, image); + calculate_partialities(list, cr, image, pmodel); + if ( scale_one_crystal(list, cr, full, scaleflags) ) return; + residual_flipped = residual(list, cr, full, 0, NULL, NULL); if ( residual_flipped < residual_original ) { crystal_set_cell(crin, cell); - crystal_set_reflections(crin, list); + reflist_free(*prefls); + *prefls = list; residual_original = residual_flipped; } else { cell_free(crystal_get_cell(cr)); - reflist_free(crystal_get_reflections(cr)); + reflist_free(list); } } @@ -365,7 +363,7 @@ void write_test_logs(Crystal *crystal, struct image *image, const RefList *full, } -void write_specgraph(Crystal *crystal, struct image *image, const RefList *full, +void write_specgraph(RefList *list, Crystal *crystal, struct image *image, const RefList *full, signed int cycle, int serial, const char *log_folder) { @@ -405,7 +403,7 @@ void write_specgraph(Crystal *crystal, struct image *image, const RefList *full, ins[1] = '\0'; } - for ( refl = first_refl(crystal_get_reflections(crystal), &iter); + for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { @@ -440,7 +438,8 @@ void write_specgraph(Crystal *crystal, struct image *image, const RefList *full, } -static void write_angle_grid(Crystal *cr, struct image *image, const RefList *full, +static void write_angle_grid(RefList *list_in, Crystal *cr, struct image *image, + const RefList *full, signed int cycle, int serial, int scaleflags, PartialityModel pmodel, const char *log_folder) @@ -449,7 +448,6 @@ static void write_angle_grid(Crystal *cr, struct image *image, const RefList *fu char fn[64]; char ins[16]; struct rf_priv priv; - RefList *list; UnitCell *cell; Spectrum *spectrum; @@ -463,8 +461,7 @@ static void write_angle_grid(Crystal *cr, struct image *image, const RefList *fu priv.image_tgt = *image; spectrum = spectrum_new(); priv.image_tgt.spectrum = spectrum; - list = copy_reflist(crystal_get_reflections(cr)); - crystal_set_reflections(priv.cr_tgt, list); + priv.refls = copy_reflist(list_in); cell = cell_new_from_cell(crystal_get_cell(cr)); crystal_set_cell(priv.cr_tgt, cell); @@ -501,13 +498,14 @@ static void write_angle_grid(Crystal *cr, struct image *image, const RefList *fu fclose(fh); } - reflist_free(crystal_get_reflections(priv.cr_tgt)); + reflist_free(priv.refls); crystal_free(priv.cr_tgt); spectrum_free(spectrum); } -static void write_radius_grid(Crystal *cr, struct image *image, const RefList *full, +static void write_radius_grid(RefList *list_in, Crystal *cr, struct image *image, + const RefList *full, signed int cycle, int serial, int scaleflags, PartialityModel pmodel, const char *log_folder) @@ -516,7 +514,6 @@ static void write_radius_grid(Crystal *cr, struct image *image, const RefList *f char fn[64]; char ins[16]; struct rf_priv priv; - RefList *list; UnitCell *cell; Spectrum *spectrum; @@ -530,8 +527,7 @@ static void write_radius_grid(Crystal *cr, struct image *image, const RefList *f priv.image_tgt = *image; spectrum = spectrum_new(); priv.image_tgt.spectrum = spectrum; - list = copy_reflist(crystal_get_reflections(cr)); - crystal_set_reflections(priv.cr_tgt, list); + priv.refls = copy_reflist(list_in); cell = cell_new_from_cell(crystal_get_cell(cr)); crystal_set_cell(priv.cr_tgt, cell); @@ -568,19 +564,20 @@ static void write_radius_grid(Crystal *cr, struct image *image, const RefList *f fclose(fh); } - reflist_free(crystal_get_reflections(priv.cr_tgt)); + reflist_free(priv.refls); crystal_free(priv.cr_tgt); spectrum_free(spectrum); } -void write_gridscan(Crystal *cr, struct image *image, const RefList *full, +void write_gridscan(RefList *list, + Crystal *cr, struct image *image, const RefList *full, signed int cycle, int serial, int scaleflags, PartialityModel pmodel, const char *log_folder) { - write_angle_grid(cr, image, full, cycle, serial, scaleflags, pmodel, log_folder); - write_radius_grid(cr, image, full, cycle, serial, scaleflags, pmodel, log_folder); + write_angle_grid(list, cr, image, full, cycle, serial, scaleflags, pmodel, log_folder); + write_radius_grid(list, cr, image, full, cycle, serial, scaleflags, pmodel, log_folder); } @@ -646,7 +643,8 @@ static void zero_alter(struct rf_alteration *alter) } -static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full, +static void do_pr_refine(RefList **plist_in, Crystal *cr, struct image *image, + const RefList *full, PartialityModel pmodel, int serial, int cycle, int write_logs, SymOpList *sym, SymOpList *amb, int scaleflags, @@ -656,12 +654,11 @@ static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full, struct rf_alteration alter; int n_iter = 0; double fom, freefom; - RefList *list; FILE *fh = NULL; UnitCell *cell; Spectrum *spectrum; - try_reindex(cr, image, full, sym, amb, scaleflags, pmodel); + try_reindex(plist_in, cr, image, full, sym, amb, scaleflags, pmodel); zero_alter(&alter); @@ -675,8 +672,7 @@ static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full, priv.image_tgt = *image; spectrum = spectrum_new(); priv.image_tgt.spectrum = spectrum; - list = copy_reflist(crystal_get_reflections(cr)); - crystal_set_reflections(priv.cr_tgt, list); + priv.refls = copy_reflist(*plist_in); cell = cell_new_from_cell(crystal_get_cell(cr)); crystal_set_cell(priv.cr_tgt, cell); @@ -722,13 +718,13 @@ static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full, /* Apply the final shifts */ apply_parameters(cr, cr, image, image, alter); - update_predictions(cr, image); - calculate_partialities(cr, image, pmodel); + update_predictions(*plist_in, cr, image); + calculate_partialities(*plist_in, cr, image, pmodel); if ( write_logs ) { - write_gridscan(cr, image, full, cycle, serial, scaleflags, + write_gridscan(*plist_in, cr, image, full, cycle, serial, scaleflags, pmodel, log_folder); - write_specgraph(cr, image, full, cycle, serial, log_folder); + write_specgraph(*plist_in, cr, image, full, cycle, serial, log_folder); write_test_logs(cr, image, full, cycle, serial, log_folder); } @@ -740,7 +736,7 @@ static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full, fclose(fh); } - reflist_free(crystal_get_reflections(priv.cr_tgt)); + reflist_free(priv.refls); crystal_free(priv.cr_tgt); spectrum_free(spectrum); } @@ -750,6 +746,7 @@ struct refine_args { RefList *full; Crystal *crystal; + RefList **prefls; struct image *image; PartialityModel pmodel; int serial; @@ -766,7 +763,7 @@ struct pr_queue_args { int n_started; int n_done; - Crystal **crystals; + struct crystal_refls *crystals; struct image **images; int n_crystals; struct refine_args task_defaults; @@ -780,7 +777,8 @@ static void refine_image(void *task, int id) write_logs = !pargs->no_logs && (pargs->serial % 20 == 0); - do_pr_refine(pargs->crystal, pargs->image, pargs->full, pargs->pmodel, + do_pr_refine(pargs->prefls, pargs->crystal, pargs->image, + pargs->full, pargs->pmodel, pargs->serial, pargs->cycle, write_logs, pargs->sym, pargs->amb, pargs->scaleflags, pargs->log_folder); @@ -795,7 +793,8 @@ static void *get_image(void *vqargs) task = malloc(sizeof(struct refine_args)); memcpy(task, &qargs->task_defaults, sizeof(struct refine_args)); - task->crystal = qargs->crystals[qargs->n_started]; + task->crystal = qargs->crystals[qargs->n_started].cr; + task->prefls = &qargs->crystals[qargs->n_started].refls; task->image = qargs->images[qargs->n_started]; task->serial = qargs->n_started; @@ -816,7 +815,7 @@ static void done_image(void *vqargs, void *task) } -void refine_all(Crystal **crystals, struct image **images, int n_crystals, +void refine_all(struct crystal_refls *crystals, struct image **images, int n_crystals, RefList *full, int nthreads, PartialityModel pmodel, int cycle, int no_logs, SymOpList *sym, SymOpList *amb, int scaleflags, @@ -827,6 +826,7 @@ void refine_all(Crystal **crystals, struct image **images, int n_crystals, task_defaults.full = full; task_defaults.crystal = NULL; + task_defaults.prefls = NULL; task_defaults.image = NULL; task_defaults.pmodel = pmodel; task_defaults.cycle = cycle; diff --git a/src/post-refinement.h b/src/post-refinement.h index 7eb1fd0b..91c0f4f8 100644 --- a/src/post-refinement.h +++ b/src/post-refinement.h @@ -58,19 +58,20 @@ enum prflag extern const char *str_prflag(enum prflag flag); -extern void refine_all(Crystal **crystals, struct image **images, int n_crystals, +extern void refine_all(struct crystal_refls *crystals, struct image **images, + int n_crystals, RefList *full, int nthreads, PartialityModel pmodel, int cycle, int no_logs, SymOpList *sym, SymOpList *amb, int scaleflags, const char *log_folder); -extern void write_gridscan(Crystal *cr, struct image *image, +extern void write_gridscan(RefList *list, Crystal *cr, struct image *image, const RefList *full, int cycle, int serial, int scaleflags, PartialityModel model, const char *log_folder); -extern void write_specgraph(Crystal *crystal, struct image *image, +extern void write_specgraph(RefList *list, Crystal *crystal, struct image *image, const RefList *full, signed int cycle, int serial, const char *log_folder); diff --git a/src/rejection.c b/src/rejection.c index 4e3ff6ba..d3aa9b1f 100644 --- a/src/rejection.c +++ b/src/rejection.c @@ -63,7 +63,7 @@ static double mean_intensity(RefList *list) /* Reject really obvious outliers */ -void early_rejection(Crystal **crystals, int n) +void early_rejection(struct crystal_refls *crystals, int n) { int i; double m = 0.0; @@ -73,18 +73,16 @@ void early_rejection(Crystal **crystals, int n) for ( i=0; ifull = qargs->full; - wargs->crystal = qargs->crystals[qargs->n_started]; + wargs->crystal = qargs->crystals[qargs->n_started].cr; + wargs->refls = qargs->crystals[qargs->n_started].refls; wargs->crystal_number = qargs->n_started; wargs->non = 0; wargs->nan = 0; @@ -320,9 +320,8 @@ static void run_deltacchalf_job(void *vwargs, int cookie) double cchalf, cchalfi; struct deltacchalf_worker_args *wargs = vwargs; int nref = 0; - RefList *template = crystal_get_reflections(wargs->crystal); - cchalf = calculate_cchalf(template, wargs->full, NULL, &nref); - cchalfi = calculate_cchalf(template, wargs->full, wargs->crystal, &nref); + cchalf = calculate_cchalf(wargs->refls, wargs->full, NULL, &nref); + cchalfi = calculate_cchalf(wargs->refls, wargs->full, wargs->crystal, &nref); //STATUS("Frame %i:", i); //STATUS(" With = %f ", cchalf*100.0); //STATUS("Without = %f", cchalfi*100.0); @@ -355,8 +354,8 @@ static void finalise_deltacchalf_job(void *vqargs, void *vwargs) } -static void check_deltacchalf(Crystal **crystals, int n, RefList *full, - int n_threads) +static void check_deltacchalf(struct crystal_refls *crystals, int n, + RefList *full, int n_threads) { double cchalf; int i; @@ -409,7 +408,7 @@ static void check_deltacchalf(Crystal **crystals, int n, RefList *full, if ( isnan(vals[i]) || isinf(vals[i]) || ((vals[i]<0.0) && (vals[i] < mean-2.0*sd)) ) { - crystal_set_user_flag(crystals[i], PRFLAG_DELTACCHALF); + crystal_set_user_flag(crystals[i].cr, PRFLAG_DELTACCHALF); } } @@ -417,7 +416,7 @@ static void check_deltacchalf(Crystal **crystals, int n, RefList *full, } -static void show_duds(Crystal **crystals, int n_crystals) +static void show_duds(struct crystal_refls *crystals, int n_crystals) { int j; int bads[32]; @@ -427,7 +426,7 @@ static void show_duds(Crystal **crystals, int n_crystals) for ( j=0; j max_B ) { - crystal_set_user_flag(crystals[i], PRFLAG_BIGB); + if ( fabs(crystal_get_Bfac(crystals[i].cr)) > max_B ) { + crystal_set_user_flag(crystals[i].cr, PRFLAG_BIGB); } - if ( crystal_get_user_flag(crystals[i]) == 0 ) n_acc++; + if ( crystal_get_user_flag(crystals[i].cr) == 0 ) n_acc++; } show_duds(crystals, n); diff --git a/src/rejection.h b/src/rejection.h index 7dc2c92b..152c004e 100644 --- a/src/rejection.h +++ b/src/rejection.h @@ -35,10 +35,10 @@ #endif -#include "crystal.h" +#include "image.h" -extern void early_rejection(Crystal **crystals, int n); -extern void check_rejection(Crystal **crystals, int n, RefList *full, +extern void early_rejection(struct crystal_refls *crystals, int n); +extern void check_rejection(struct crystal_refls *crystals, int n, RefList *full, double max_B, int no_deltacchalf, int n_threads); #endif /* REJECTION_H */ diff --git a/src/scaling.c b/src/scaling.c index f007b757..52954f9a 100644 --- a/src/scaling.c +++ b/src/scaling.c @@ -53,6 +53,7 @@ struct scale_args { RefList *full; Crystal *crystal; + RefList *refls; int flags; }; @@ -61,7 +62,7 @@ struct scale_queue_args { int n_started; int n_done; - Crystal **crystals; + struct crystal_refls *crystals; int n_crystals; struct scale_args task_defaults; }; @@ -70,7 +71,7 @@ struct scale_queue_args static void scale_crystal(void *task, int id) { struct scale_args *pargs = task; - scale_one_crystal(pargs->crystal, pargs->full, pargs->flags); + scale_one_crystal(pargs->refls, pargs->crystal, pargs->full, pargs->flags); } @@ -82,7 +83,8 @@ static void *get_crystal(void *vqargs) task = malloc(sizeof(struct scale_args)); memcpy(task, &qargs->task_defaults, sizeof(struct scale_args)); - task->crystal = qargs->crystals[qargs->n_started]; + task->crystal = qargs->crystals[qargs->n_started].cr; + task->refls = qargs->crystals[qargs->n_started].refls; qargs->n_started++; @@ -99,8 +101,8 @@ static void done_crystal(void *vqargs, void *task) } -static double total_log_r(Crystal **crystals, int n_crystals, RefList *full, - int *ninc) +static double total_log_r(struct crystal_refls *crystals, int n_crystals, + RefList *full, int *ninc) { int i; double total = 0.0; @@ -108,8 +110,9 @@ static double total_log_r(Crystal **crystals, int n_crystals, RefList *full, for ( i=0; i Date: Thu, 18 Jan 2024 15:24:09 +0100 Subject: Crystals shouldn't own RefLists (part 6) This fixes the remaining programs. --- src/ambigator.c | 4 ++-- src/cell_explorer.c | 4 +--- src/crystfelimageview.c | 3 +-- src/gui_index.c | 10 +++++----- src/process_image.c | 14 +++++++------- src/whirligig.c | 11 +++++------ 6 files changed, 21 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/ambigator.c b/src/ambigator.c index 3777cf0a..91e621ac 100644 --- a/src/ambigator.c +++ b/src/ambigator.c @@ -1287,7 +1287,8 @@ int main(int argc, char *argv[]) RefList *list; UnitCell *cell; - cr = image->crystals[i]; + cr = image->crystals[i].cr; + list = image->crystals[i].refls; cell = crystal_get_cell(cr); if ( n_crystals == max_crystals ) { @@ -1308,7 +1309,6 @@ int main(int argc, char *argv[]) } - list = crystal_get_reflections(cr); crystals[n_crystals] = asymm_and_merge(list, s_sym, cell, rmin, rmax, diff --git a/src/cell_explorer.c b/src/cell_explorer.c index 99cb284f..a92de347 100644 --- a/src/cell_explorer.c +++ b/src/cell_explorer.c @@ -2002,9 +2002,7 @@ static int add_stream(CellWindow *w, const char *stream_filename, for ( i=0; in_crystals; i++ ) { - Crystal *cr; - - cr = image->crystals[i]; + Crystal *cr = image->crystals[i].cr; if ( w->n_cells == max_cells ) { diff --git a/src/crystfelimageview.c b/src/crystfelimageview.c index 03350204..1659ae4f 100644 --- a/src/crystfelimageview.c +++ b/src/crystfelimageview.c @@ -707,9 +707,8 @@ static gint draw_sig(GtkWidget *window, cairo_t *cr, CrystFELImageView *iv) if ( iv->show_refls ) { int i; for ( i=0; iimage->n_crystals; i++ ) { - Crystal *cry = iv->image->crystals[i]; draw_refls(cr, iv, - crystal_get_reflections(cry), + iv->image->crystals[i].refls, iv->label_refls, crystal_cols[i % n_crystal_cols]); } diff --git a/src/gui_index.c b/src/gui_index.c index 2cc8e8db..218331eb 100644 --- a/src/gui_index.c +++ b/src/gui_index.c @@ -636,19 +636,19 @@ static void run_indexing_once(struct crystfelproject *proj) index_pattern(proj->cur_image, ipriv); for ( i=0; icur_image->n_crystals; i++ ) { - crystal_set_mosaicity(proj->cur_image->crystals[i], 0.0); + crystal_set_mosaicity(proj->cur_image->crystals[i].cr, 0.0); if ( proj->indexing_params.use_fix_profile_radius ) { /* Manual radius */ - crystal_set_profile_radius(proj->cur_image->crystals[i], + crystal_set_profile_radius(proj->cur_image->crystals[i].cr, proj->indexing_params.fix_profile_radius); } else { /* Auto radius determination */ - crystal_set_profile_radius(proj->cur_image->crystals[i], + crystal_set_profile_radius(proj->cur_image->crystals[i].cr, 0.02e9); - if ( refine_radius(proj->cur_image->crystals[i], + if ( refine_radius(proj->cur_image->crystals[i].cr, proj->cur_image) ) { ERROR("WARNING: Radius determination failed\n"); @@ -682,7 +682,7 @@ static void run_indexing_once(struct crystfelproject *proj) STATUS("Number of crystals: %i\n", proj->cur_image->n_crystals); for ( i=0; icur_image->n_crystals; i++ ) { - cell_print(crystal_get_cell(proj->cur_image->crystals[i])); + cell_print(crystal_get_cell(proj->cur_image->crystals[i].cr)); } } diff --git a/src/process_image.c b/src/process_image.c index 2f856594..782c97b9 100644 --- a/src/process_image.c +++ b/src/process_image.c @@ -434,20 +434,20 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, set_last_task(last_task, "prediction params"); if ( iargs->fix_profile_r >= 0.0 ) { for ( i=0; in_crystals; i++ ) { - crystal_set_profile_radius(image->crystals[i], + crystal_set_profile_radius(image->crystals[i].cr, iargs->fix_profile_r); - crystal_set_mosaicity(image->crystals[i], 0.0); + crystal_set_mosaicity(image->crystals[i].cr, 0.0); } } else { for ( i=0; in_crystals; i++ ) { - crystal_set_profile_radius(image->crystals[i], 0.02e9); - crystal_set_mosaicity(image->crystals[i], 0.0); + crystal_set_profile_radius(image->crystals[i].cr, 0.02e9); + crystal_set_mosaicity(image->crystals[i].cr, 0.0); } } if ( iargs->fix_profile_r < 0.0 ) { for ( i=0; in_crystals; i++ ) { - if ( refine_radius(image->crystals[i], image) ) { + if ( refine_radius(image->crystals[i].cr, image) ) { ERROR("WARNING: Radius determination failed\n"); } } @@ -479,7 +479,7 @@ streamwrite: int n = 0; for ( i=0; in_crystals; i++ ) { - n += crystal_get_num_implausible_reflections(image->crystals[i]); + n += crystal_get_num_implausible_reflections(image->crystals[i].cr); } if ( n > 0 ) { STATUS("WARNING: %i implausibly negative reflection%s in %s " @@ -495,7 +495,7 @@ out: pthread_mutex_lock(&sb_shared->totals_lock); any_crystals = 0; for ( i=0; in_crystals; i++ ) { - if ( crystal_get_user_flag(image->crystals[i]) == 0 ) { + if ( crystal_get_user_flag(image->crystals[i].cr) == 0 ) { sb_shared->n_crystals++; any_crystals = 1; } diff --git a/src/whirligig.c b/src/whirligig.c index 20fcfa40..aa2cf090 100644 --- a/src/whirligig.c +++ b/src/whirligig.c @@ -175,12 +175,11 @@ static void process_series(struct image *images, signed int *ser, fprintf(fh, "%i frames in series\n\n", len); fprintf(fh, " # Serial Filename EventID Crystal\n"); for ( i=0; in_crystals; i++ ) { for ( j=0; jn_crystals; j++ ) { - if ( compare_permuted_cell_parameters_and_orientation(crystal_get_cell(i1->crystals[i]), - crystal_get_cell(i2->crystals[j]), + if ( compare_permuted_cell_parameters_and_orientation(crystal_get_cell(i1->crystals[i].cr), + crystal_get_cell(i2->crystals[j].cr), tols, &m) ) { if ( !crystal_used(win, n1, i) @@ -377,12 +376,12 @@ static int try_join(struct window *win, int sn) /* Get the appropriately transformed cell from the last crystal in this * series */ - cr = win->img[sp].crystals[win->ser[sn][sp]]; + cr = win->img[sp].crystals[win->ser[sn][sp]].cr; ref = cell_transform_intmat(crystal_get_cell(cr), win->mat[sn][sp]); for ( j=0; jimg[win->join_ptr].n_crystals; j++ ) { Crystal *cr2; - cr2 = win->img[win->join_ptr].crystals[j]; + cr2 = win->img[win->join_ptr].crystals[j].cr; if ( compare_permuted_cell_parameters_and_orientation(ref, crystal_get_cell(cr2), tols, &win->mat[sn][win->join_ptr]) ) -- cgit v1.2.3 From fd363c300c1767681ac6b03f05132d9e6d8a6884 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 19 Jan 2024 12:59:47 +0100 Subject: Fix incorrect uses of cell_free This also gets rid of crystal_copy_deep. From now on, all crystal_copy calls also copy the UnitCell. --- src/partialator.c | 2 +- src/post-refinement.c | 39 +++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/partialator.c b/src/partialator.c index 659a12c5..7d3f19f6 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -1611,7 +1611,7 @@ int main(int argc, char *argv[]) return 1; } crystals = crystals_new; - cr = crystal_copy_deep(image->crystals[i].cr); + cr = crystal_copy(image->crystals[i].cr); crystals[n_crystals].cr = cr; images_new = realloc(images, (n_crystals+1)*sizeof(struct image *)); diff --git a/src/post-refinement.c b/src/post-refinement.c index c67c0348..8a846b0f 100644 --- a/src/post-refinement.c +++ b/src/post-refinement.c @@ -268,7 +268,6 @@ static void try_reindex(RefList **prefls, Crystal *crin, struct image *image, const RefList *full, SymOpList *sym, SymOpList *amb, int scaleflags, PartialityModel pmodel) { - Crystal *cr; double residual_original; int idx, n; @@ -277,39 +276,39 @@ static void try_reindex(RefList **prefls, Crystal *crin, struct image *image, if ( scale_one_crystal(*prefls, crin, full, scaleflags) ) return; residual_original = residual(*prefls, crin, full, 0, NULL, NULL); - cr = crystal_copy(crin); - n = num_equivs(amb, NULL); for ( idx=0; idx Date: Sat, 20 Jan 2024 10:36:02 +0100 Subject: Remove an unused variable --- src/post-refinement.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/post-refinement.c b/src/post-refinement.c index 8a846b0f..4a02ed08 100644 --- a/src/post-refinement.c +++ b/src/post-refinement.c @@ -281,7 +281,6 @@ static void try_reindex(RefList **prefls, Crystal *crin, struct image *image, for ( idx=0; idx Date: Thu, 25 Jan 2024 15:12:22 +0100 Subject: Peak search algorithms should not mutate image structure This changes all the peak search procedures into pure functions that return a new ImageFeatureList. This takes the management of image->features out of the hands of the peak search routines, and into the calling code's responsibility. In turn, this allows a load of stuff to become const. --- src/gui_peaksearch.c | 72 +++++++++++++++++++++------------------- src/process_image.c | 93 ++++++++++++++++++++++++++++------------------------ 2 files changed, 89 insertions(+), 76 deletions(-) (limited to 'src') diff --git a/src/gui_peaksearch.c b/src/gui_peaksearch.c index 976e08ec..314fd5d4 100644 --- a/src/gui_peaksearch.c +++ b/src/gui_peaksearch.c @@ -41,6 +41,7 @@ #include #include +#include #include "crystfelimageview.h" #include "gui_project.h" @@ -60,52 +61,55 @@ void update_peaks(struct crystfelproject *proj) switch ( proj->peak_search_params.method ) { + ImageFeatureList *peaks; + case PEAK_ZAEF: - search_peaks(proj->cur_image, - proj->peak_search_params.threshold, - proj->peak_search_params.min_sq_gradient, - proj->peak_search_params.min_snr, - proj->peak_search_params.pk_inn, - proj->peak_search_params.pk_mid, - proj->peak_search_params.pk_out, - 1); + proj->cur_image->features = search_peaks(proj->cur_image, + proj->peak_search_params.threshold, + proj->peak_search_params.min_sq_gradient, + proj->peak_search_params.min_snr, + proj->peak_search_params.pk_inn, + proj->peak_search_params.pk_mid, + proj->peak_search_params.pk_out, + 1); break; case PEAK_PEAKFINDER8: - search_peaks_peakfinder8(proj->cur_image, 2048, - proj->peak_search_params.threshold, - proj->peak_search_params.min_snr, - proj->peak_search_params.min_pix_count, - proj->peak_search_params.max_pix_count, - proj->peak_search_params.local_bg_radius, - proj->peak_search_params.min_res, - proj->peak_search_params.max_res, - 1, 0, NULL); + proj->cur_image->features = peakfinder8(proj->cur_image, 2048, + proj->peak_search_params.threshold, + proj->peak_search_params.min_snr, + proj->peak_search_params.min_pix_count, + proj->peak_search_params.max_pix_count, + proj->peak_search_params.local_bg_radius, + proj->peak_search_params.min_res, + proj->peak_search_params.max_res, + 1, 0, NULL); break; case PEAK_PEAKFINDER9: - search_peaks_peakfinder9(proj->cur_image, - proj->peak_search_params.min_snr_biggest_pix, - proj->peak_search_params.min_snr_peak_pix, - proj->peak_search_params.min_snr, - proj->peak_search_params.min_sig, - proj->peak_search_params.min_peak_over_neighbour, - proj->peak_search_params.local_bg_radius); + proj->cur_image->features = search_peaks_peakfinder9(proj->cur_image, + proj->peak_search_params.min_snr_biggest_pix, + proj->peak_search_params.min_snr_peak_pix, + proj->peak_search_params.min_snr, + proj->peak_search_params.min_sig, + proj->peak_search_params.min_peak_over_neighbour, + proj->peak_search_params.local_bg_radius); break; case PEAK_HDF5: case PEAK_CXI: - proj->cur_image->features = image_read_peaks(proj->dtempl, - proj->cur_image->filename, - proj->cur_image->ev, - proj->peak_search_params.half_pixel_shift); + peaks = image_read_peaks(proj->dtempl, + proj->cur_image->filename, + proj->cur_image->ev, + proj->peak_search_params.half_pixel_shift); if ( proj->peak_search_params.revalidate ) { - validate_peaks(proj->cur_image, - proj->peak_search_params.min_snr, - proj->peak_search_params.pk_inn, - proj->peak_search_params.pk_mid, - proj->peak_search_params.pk_out, - 1, 0); + proj->cur_image->features = validate_peaks(proj->cur_image, peaks, + proj->peak_search_params.min_snr, + proj->peak_search_params.pk_inn, + proj->peak_search_params.pk_mid, + proj->peak_search_params.pk_out, + 1, 0); + image_feature_list_free(peaks); } break; diff --git a/src/process_image.c b/src/process_image.c index 782c97b9..c26842c3 100644 --- a/src/process_image.c +++ b/src/process_image.c @@ -57,6 +57,8 @@ #include "im-sandbox.h" #include "im-zmq.h" #include "im-asapo.h" +#include "peaks.h" +#include "peakfinder8.h" static float **backup_image_data(float **dp, struct detgeom *det) { @@ -292,35 +294,42 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, profile_start("peak-search"); switch ( iargs->peak_search.method ) { + ImageFeatureList *peaks; + case PEAK_HDF5: case PEAK_CXI: set_last_task(last_task, "peaksearch:hdf5orcxi"); - image->features = image_read_peaks(iargs->dtempl, - pargs->filename, - pargs->event, - iargs->peak_search.half_pixel_shift); - if ( image->features == NULL ) { - ERROR("Failed to get peaks from HDF5 file.\n"); - } + peaks = image_read_peaks(iargs->dtempl, + pargs->filename, + pargs->event, + iargs->peak_search.half_pixel_shift); if ( iargs->peak_search.revalidate ) { - validate_peaks(image, iargs->peak_search.min_snr, - iargs->peak_search.pk_inn, iargs->peak_search.pk_mid, - iargs->peak_search.pk_out, iargs->peak_search.use_saturated, - iargs->peak_search.check_hdf5_snr); + ImageFeatureList *npeaks = validate_peaks(image, peaks, + iargs->peak_search.min_snr, + iargs->peak_search.pk_inn, + iargs->peak_search.pk_mid, + iargs->peak_search.pk_out, + iargs->peak_search.use_saturated, + iargs->peak_search.check_hdf5_snr); + image_feature_list_free(peaks); + image->features = npeaks; } break; case PEAK_ZAEF: set_last_task(last_task, "peaksearch:zaef"); - search_peaks(image, iargs->peak_search.threshold, - iargs->peak_search.min_sq_gradient, iargs->peak_search.min_snr, - iargs->peak_search.pk_inn, iargs->peak_search.pk_mid, iargs->peak_search.pk_out, - iargs->peak_search.use_saturated); + image->features = search_peaks(image, iargs->peak_search.threshold, + iargs->peak_search.min_sq_gradient, + iargs->peak_search.min_snr, + iargs->peak_search.pk_inn, + iargs->peak_search.pk_mid, + iargs->peak_search.pk_out, + iargs->peak_search.use_saturated); break; case PEAK_PEAKFINDER8: set_last_task(last_task, "peaksearch:pf8"); - if ( search_peaks_peakfinder8(image, 2048, + image->features = peakfinder8(image, 2048, iargs->peak_search.threshold, iargs->peak_search.min_snr, iargs->peak_search.min_pix_count, @@ -329,40 +338,36 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, iargs->peak_search.min_res, iargs->peak_search.max_res, iargs->peak_search.use_saturated, - iargs->peak_search.peakfinder8_fast, - iargs->pf_private) ) { - ERROR("Failed to find peaks in image %s" - "(event %s).\n", - image->filename, image->ev); - } + iargs->peak_search.peakfinder8_fast, + iargs->pf_private); break; case PEAK_PEAKFINDER9: set_last_task(last_task, "peaksearch:pf9"); - if ( search_peaks_peakfinder9(image, - iargs->peak_search.min_snr_biggest_pix, - iargs->peak_search.min_snr_peak_pix, - iargs->peak_search.min_snr, - iargs->peak_search.min_sig, - iargs->peak_search.min_peak_over_neighbour, - iargs->peak_search.local_bg_radius) ) - { - ERROR("Failed to find peaks in image %s" - "(event %s).\n", - image->filename, image->ev); - } + image->features = search_peaks_peakfinder9(image, + iargs->peak_search.min_snr_biggest_pix, + iargs->peak_search.min_snr_peak_pix, + iargs->peak_search.min_snr, + iargs->peak_search.min_sig, + iargs->peak_search.min_peak_over_neighbour, + iargs->peak_search.local_bg_radius); break; case PEAK_MSGPACK: - image->features = image_msgpack_read_peaks(iargs->dtempl, - pargs->zmq_data, - pargs->zmq_data_size, - iargs->peak_search.half_pixel_shift); + peaks = image_msgpack_read_peaks(iargs->dtempl, + pargs->zmq_data, + pargs->zmq_data_size, + iargs->peak_search.half_pixel_shift); if ( iargs->peak_search.revalidate ) { - validate_peaks(image, iargs->peak_search.min_snr, - iargs->peak_search.pk_inn, iargs->peak_search.pk_mid, - iargs->peak_search.pk_out, iargs->peak_search.use_saturated, - iargs->peak_search.check_hdf5_snr); + ImageFeatureList *npeaks = validate_peaks(image, peaks, + iargs->peak_search.min_snr, + iargs->peak_search.pk_inn, + iargs->peak_search.pk_mid, + iargs->peak_search.pk_out, + iargs->peak_search.use_saturated, + iargs->peak_search.check_hdf5_snr); + image_feature_list_free(peaks); + image->features = npeaks; } break; @@ -371,6 +376,10 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, break; } + if ( image->features == NULL ) { + ERROR("Peaksearch failed for image %s" "(event %s).\n", + image->filename, image->ev); + } profile_end("peak-search"); image->peak_resolution = estimate_peak_resolution(image->features, -- cgit v1.2.3