diff options
author | Thomas White <taw@physics.org> | 2021-03-11 17:06:59 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-03-11 17:06:59 +0100 |
commit | e21cc1f84a8cb2b0627e99383c882e59efda4920 (patch) | |
tree | 7d8c56a259b8b4b9e030f22e26871e3cbe1942b5 /libcrystfel | |
parent | 0722b797e25ba3bf95d5eec56198460be0eb6aa8 (diff) |
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.
Diffstat (limited to 'libcrystfel')
-rw-r--r-- | libcrystfel/src/datatemplate.c | 53 | ||||
-rw-r--r-- | libcrystfel/src/datatemplate.h | 2 | ||||
-rw-r--r-- | libcrystfel/src/datatemplate_priv.h | 2 | ||||
-rw-r--r-- | libcrystfel/src/image.c | 28 |
4 files changed, 57 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; |