From b1ae07a6ca931096514671f0ea226557a570e37a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 12 Jul 2021 14:02:04 +0200 Subject: GUI: Add --wavelength-estimate and --camera-length-estimate Only when using PinkIndexer. Closes: https://gitlab.desy.de/thomas.white/crystfel/-/issues/25 --- src/gui_backend_local.c | 8 +++-- src/gui_backend_slurm.c | 8 +++-- src/gui_index.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++--- src/gui_index.h | 4 ++- src/gui_project.h | 4 ++- 5 files changed, 109 insertions(+), 10 deletions(-) diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c index 97bb9d7a..d78fc037 100644 --- a/src/gui_backend_local.c +++ b/src/gui_backend_local.c @@ -505,7 +505,9 @@ static void *run_merging(const char *job_title, static void *run_indexing(const char *job_title, const char *job_notes, struct crystfelproject *proj, - void *opts_priv) + void *opts_priv, + double wavelength_estimate, + double clen_estimate) { struct local_indexing_opts *opts = opts_priv; struct local_job *job; @@ -539,7 +541,9 @@ static void *run_indexing(const char *job_title, "crystfel.stream", NULL, 1, &proj->peak_search_params, - &proj->indexing_params) ) + &proj->indexing_params, + wavelength_estimate, + clen_estimate) ) { char *args[3]; args[0] = "sh"; diff --git a/src/gui_backend_slurm.c b/src/gui_backend_slurm.c index 97c89be4..e0f74b10 100644 --- a/src/gui_backend_slurm.c +++ b/src/gui_backend_slurm.c @@ -581,7 +581,9 @@ static void write_partial_file_list(GFile *workdir, static void *run_indexing(const char *job_title, const char *job_notes, struct crystfelproject *proj, - void *opts_priv) + void *opts_priv, + double wavelength_estimate, + double clen_estimate) { struct slurm_indexing_opts *opts = opts_priv; struct slurm_job *job; @@ -645,7 +647,9 @@ static void *run_indexing(const char *job_title, "crystfel-${SLURM_ARRAY_TASK_ID}.stream", serial_offs, 0, &proj->peak_search_params, - &proj->indexing_params) ) + &proj->indexing_params, + wavelength_estimate, + clen_estimate) ) { job = start_slurm_job(GUI_JOB_INDEXING, sc_filename, diff --git a/src/gui_index.c b/src/gui_index.c index b36ebff2..8c3e7dc0 100644 --- a/src/gui_index.c +++ b/src/gui_index.c @@ -135,16 +135,55 @@ static void get_indexing_opts(struct crystfelproject *proj, } +static int get_first_frame_parameters(struct crystfelproject *proj, + double *wavelength_estimate, + double *clen_estimate) +{ + struct image *image; + + if ( proj->n_frames < 1 ) { + ERROR("No frames!\n"); + return 1; + } + + + image = image_read(proj->dtempl, + proj->filenames[0], + proj->events[0], + 0, 0); + + if ( image == NULL ) { + ERROR("Failed to load first frame\n"); + return 1; + } + + *wavelength_estimate = image->lambda; + *clen_estimate = detgeom_mean_camera_length(image->detgeom); + + image_free(image); + + return 0; +} + + static int run_indexing_all(struct crystfelproject *proj, int backend_idx, const char *job_title, const char *job_notes) { struct crystfel_backend *be; void *job_priv; + double wavelength_estimate; + double clen_estimate; + + /* Get parameters from first frame */ + if ( get_first_frame_parameters(proj, &wavelength_estimate, + &clen_estimate) ) return 1; be = &proj->backends[backend_idx]; job_priv = be->run_indexing(job_title, job_notes, proj, - be->indexing_opts_priv); + be->indexing_opts_priv, + wavelength_estimate, + clen_estimate); if ( job_priv != NULL ) { char name[256]; @@ -679,6 +718,16 @@ static void add_arg_float(char **args, int pos, const char *label, } +static void add_arg_float_exp(char **args, int pos, const char *label, + float val) +{ + char *str = malloc(64); + if ( str == NULL ) return; + snprintf(str, 63, "--%s=%e", label, val); + args[pos] = str; +} + + static void add_arg_int(char **args, int pos, const char *label, int val) { @@ -703,13 +752,40 @@ static void add_arg_string(char **args, int pos, const char *label, } +static int is_method(IndexingMethod m, IndexingMethod b) +{ + return (m & INDEXING_METHOD_MASK) == b; +} + + +static int pinkindexer_used(const char *methods) +{ + IndexingMethod *m; + int n, i; + int r = 0; + + m = parse_indexing_methods(methods, &n); + for ( i=0; iindexing_methods != NULL ) { add_arg(args, n_args++, "--indexing"); add_arg(args, n_args++, indexing_params->indexing_methods); + + if ( pinkindexer_used(indexing_params->indexing_methods) ) { + add_arg_float_exp(args, n_args++, "wavelength-estimate", + wavelength_estimate); + add_arg_float(args, n_args++, "camera-length-estimate", + clen_estimate); + } } if ( indexing_params->cell_file != NULL ) { add_arg(args, n_args++, "-p"); @@ -883,7 +966,9 @@ int write_indexamajig_script(const char *script_filename, const char *serial_start, int redirect_output, struct peak_params *peak_search_params, - struct index_params *indexing_params) + struct index_params *indexing_params, + double wavelength_estimate, + double clen_estimate) { FILE *fh; int i; @@ -895,7 +980,9 @@ int write_indexamajig_script(const char *script_filename, stream_filename, serial_start, peak_search_params, - indexing_params); + indexing_params, + wavelength_estimate, + clen_estimate); if ( cmdline == NULL ) return 1; fh = fopen(script_filename, "w"); diff --git a/src/gui_index.h b/src/gui_index.h index 49392d5e..991ba08e 100644 --- a/src/gui_index.h +++ b/src/gui_index.h @@ -51,6 +51,8 @@ extern int write_indexamajig_script(const char *script_filename, const char *serial_start, int redirect_output, struct peak_params *peak_search_params, - struct index_params *indexing_params); + struct index_params *indexing_params, + double wavelength_estimate, + double clen_estimate); #endif diff --git a/src/gui_project.h b/src/gui_project.h index 183c9e75..556bc0f2 100644 --- a/src/gui_project.h +++ b/src/gui_project.h @@ -175,7 +175,9 @@ struct crystfel_backend { void *(*run_indexing)(const char *job_title, const char *job_notes, struct crystfelproject *proj, - void *opts_priv); + void *opts_priv, + double wavelength_estimate, + double clen_estimate); /* Called to ask the backend to write its indexing options */ void (*write_indexing_opts)(void *opts_priv, FILE *fh); -- cgit v1.2.3