From e21cc1f84a8cb2b0627e99383c882e59efda4920 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 11 Mar 2021 17:06:59 +0100 Subject: indexamajig: Use static wavelength from DataTemplate as estimate If the geometry file contains a literal wavelength, then let's use it. That's better than nagging the user for a --wavelength-estimate. --- libcrystfel/src/datatemplate.c | 53 +++++++++++++++++++++++++++++++++++++ libcrystfel/src/datatemplate.h | 2 ++ libcrystfel/src/datatemplate_priv.h | 2 ++ libcrystfel/src/image.c | 28 -------------------- src/indexamajig.c | 11 ++++++++ 5 files changed, 68 insertions(+), 28 deletions(-) diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c index 4326aa33..290b9227 100644 --- a/libcrystfel/src/datatemplate.c +++ b/libcrystfel/src/datatemplate.c @@ -1628,3 +1628,56 @@ int data_template_get_slab_extents(const DataTemplate *dt, *ph = h + 1; return 0; } + + +double convert_to_m(double val, int units) +{ + switch ( units ) { + + case WAVELENGTH_M : + return val; + + case WAVELENGTH_A : + return val * 1e-10; + + case WAVELENGTH_PHOTON_EV : + return ph_eV_to_lambda(val); + + case WAVELENGTH_PHOTON_KEV : + return ph_eV_to_lambda(val*1e3); + + case WAVELENGTH_ELECTRON_V : + return el_V_to_lambda(val); + + case WAVELENGTH_ELECTRON_KV : + return el_V_to_lambda(val*1e3); + + } + + return NAN; +} + + +/** + * Get the wavelength from a DataTemplate, if possible. + * + * WARNING: This is probably not the routine you are looking for! + * See the disclaimer for image_create_for_simulation(), which applies + * equally to this routine. + * + * \returns the wavelength, in metres, or NAN if impossible. + */ +double data_template_get_wavelength_if_possible(const DataTemplate *dt) +{ + float val; + char *rval; + + if ( dt->wavelength_from == NULL ) return NAN; + + val = strtod(dt->wavelength_from, &rval); + if ( (*rval == '\0') && (rval != dt->wavelength_from) ) { + return convert_to_m(val, dt->wavelength_unit); + } else { + return NAN; + } +} diff --git a/libcrystfel/src/datatemplate.h b/libcrystfel/src/datatemplate.h index 22322b57..3d457f80 100644 --- a/libcrystfel/src/datatemplate.h +++ b/libcrystfel/src/datatemplate.h @@ -90,6 +90,8 @@ extern int data_template_get_slab_extents(const DataTemplate *dt, int *pw, int * extern struct rg_collection *data_template_get_rigid_groups(const DataTemplate *dtempl, const char *collection_name); +extern double data_template_get_wavelength_if_possible(const DataTemplate *dt); + #ifdef __cplusplus } #endif diff --git a/libcrystfel/src/datatemplate_priv.h b/libcrystfel/src/datatemplate_priv.h index 62911748..71569273 100644 --- a/libcrystfel/src/datatemplate_priv.h +++ b/libcrystfel/src/datatemplate_priv.h @@ -234,4 +234,6 @@ struct _datatemplate char *shift_y_from; }; +extern double convert_to_m(double val, int units); + #endif /* DATATEMPLATE_PRIV_H */ diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index 767689f8..db47f75d 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -400,34 +400,6 @@ static double im_get_length(struct image *image, const char *from, } -static double convert_to_m(double val, int units) -{ - switch ( units ) { - - case WAVELENGTH_M : - return val; - - case WAVELENGTH_A : - return val * 1e-10; - - case WAVELENGTH_PHOTON_EV : - return ph_eV_to_lambda(val); - - case WAVELENGTH_PHOTON_KEV : - return ph_eV_to_lambda(val*1e3); - - case WAVELENGTH_ELECTRON_V : - return el_V_to_lambda(val); - - case WAVELENGTH_ELECTRON_KV : - return el_V_to_lambda(val*1e3); - - } - - return NAN; -} - - int create_detgeom(struct image *image, const DataTemplate *dtempl) { struct detgeom *detgeom; diff --git a/src/indexamajig.c b/src/indexamajig.c index e4da883a..6980c4b7 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -601,6 +601,7 @@ int main(int argc, char *argv[]) FelixOptions *felix_opts = NULL; XGandalfOptions *xgandalf_opts = NULL; PinkIndexerOptions *pinkindexer_opts = NULL; + double wl_from_dt; /* Defaults for "top level" arguments */ args.filename = NULL; @@ -930,6 +931,16 @@ int main(int argc, char *argv[]) } + wl_from_dt = data_template_get_wavelength_if_possible(args.iargs.dtempl); + if ( !isnan(wl_from_dt) ) { + if ( !isnan(args.iargs.wavelength_estimate) ) { + ERROR("WARNING: Ignoring your value for " + "--wavelength-estimate because the geometry file " + "already contains a static value.\n"); + } + args.iargs.wavelength_estimate = wl_from_dt; + } + /* Prepare the indexing system */ if ( args.indm_str == NULL ) { -- cgit v1.2.3