From 5007a946fab23f0363020918dd5acf48294b9dde Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 28 May 2021 15:05:35 +0200 Subject: Initial re-parameterisation of prediction refinement with fs/ss coordinates The gradients need to be updated. --- libcrystfel/src/geometry.c | 29 ++++++++++++++--------- libcrystfel/src/geometry.h | 10 ++++---- libcrystfel/src/predict-refine.c | 51 +++++++++++----------------------------- libcrystfel/src/predict-refine.h | 9 ++----- 4 files changed, 39 insertions(+), 60 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index 8e8a445d..5289856b 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -1086,9 +1086,11 @@ void polarisation_correction(RefList *list, UnitCell *cell, } -/* Returns dx_h/dP, where P = any parameter */ -double x_gradient(int param, Reflection *refl, UnitCell *cell, - struct detgeom_panel *p) +/* Returns dfs_refl/dP, where P = any parameter * + * fs_refl is the fast scan position of refl in panel 'p', + * in metres (not pixels) */ +double fs_gradient(int param, Reflection *refl, UnitCell *cell, + struct detgeom_panel *p) { signed int h, k, l; double xl, zl, kpred; @@ -1140,16 +1142,20 @@ double x_gradient(int param, Reflection *refl, UnitCell *cell, case GPARAM_CLEN : return -xl / (kpred+zl); + default: + ERROR("Positional gradient requested for parameter %i?\n", param); + abort(); + } - ERROR("Positional gradient requested for parameter %i?\n", param); - abort(); } -/* Returns dy_h/dP, where P = any parameter */ -double y_gradient(int param, Reflection *refl, UnitCell *cell, - struct detgeom_panel *p) +/* Returns dss_refl/dP, where P = any parameter + * ss_refl is the slow scan position of refl in panel 'p', + * in metres (not pixels) */ +double ss_gradient(int param, Reflection *refl, UnitCell *cell, + struct detgeom_panel *p) { signed int h, k, l; double yl, zl, kpred; @@ -1201,8 +1207,9 @@ double y_gradient(int param, Reflection *refl, UnitCell *cell, case GPARAM_CLEN : return -yl / (kpred+zl); - } + default : + ERROR("Positional gradient requested for parameter %i?\n", param); + abort(); - ERROR("Positional gradient requested for parameter %i?\n", param); - abort(); + } } diff --git a/libcrystfel/src/geometry.h b/libcrystfel/src/geometry.h index 21bd4d39..a7057f12 100644 --- a/libcrystfel/src/geometry.h +++ b/libcrystfel/src/geometry.h @@ -8,7 +8,7 @@ * Copyright © 2012 Richard Kirian * * Authors: - * 2010-2020 Thomas White + * 2010-2021 Thomas White * 2012 Richard Kirian * * This file is part of CrystFEL. @@ -120,10 +120,10 @@ extern void polarisation_correction(RefList *list, UnitCell *cell, extern double sphere_fraction(double rlow, double rhigh, double pr); extern double gaussian_fraction(double rlow, double rhigh, double pr); -extern double x_gradient(int param, Reflection *refl, UnitCell *cell, - struct detgeom_panel *p); -extern double y_gradient(int param, Reflection *refl, UnitCell *cell, - struct detgeom_panel *p); +extern double fs_gradient(int param, Reflection *refl, UnitCell *cell, + struct detgeom_panel *p); +extern double ss_gradient(int param, Reflection *refl, UnitCell *cell, + struct detgeom_panel *p); #ifdef __cplusplus } diff --git a/libcrystfel/src/predict-refine.c b/libcrystfel/src/predict-refine.c index 5210846a..1ed3bfed 100644 --- a/libcrystfel/src/predict-refine.c +++ b/libcrystfel/src/predict-refine.c @@ -68,19 +68,6 @@ static const enum gparam rv[] = }; -void twod_mapping(double fs, double ss, double *px, double *py, - struct detgeom_panel *p, double dx, double dy) -{ - double xs, ys; - - xs = fs*p->fsx + ss*p->ssx; /* pixels */ - ys = fs*p->fsy + ss*p->ssy; /* pixels */ - - *px = (xs + p->cnx) * p->pixel_pitch + dx; /* metres */ - *py = (ys + p->cny) * p->pixel_pitch + dy; /* metres */ -} - - static double r_dev(struct reflpeak *rp) { /* Excitation error term */ @@ -88,29 +75,19 @@ static double r_dev(struct reflpeak *rp) } -double x_dev(struct reflpeak *rp, struct detgeom *det, - double dx, double dy) +double fs_dev(struct reflpeak *rp, struct detgeom *det) { - /* Peak position term */ - double xpk, ypk, xh, yh; double fsh, ssh; - twod_mapping(rp->peak->fs, rp->peak->ss, &xpk, &ypk, rp->panel, dx, dy); get_detector_pos(rp->refl, &fsh, &ssh); - twod_mapping(fsh, ssh, &xh, &yh, rp->panel, dx, dy); - return xh-xpk; + return fsh - rp->peak->fs; } -double y_dev(struct reflpeak *rp, struct detgeom *det, - double dx, double dy) +double ss_dev(struct reflpeak *rp, struct detgeom *det) { - /* Peak position term */ - double xpk, ypk, xh, yh; double fsh, ssh; - twod_mapping(rp->peak->fs, rp->peak->ss, &xpk, &ypk, rp->panel, dx, dy); get_detector_pos(rp->refl, &fsh, &ssh); - twod_mapping(fsh, ssh, &xh, &yh, rp->panel, dx, dy); - return yh-ypk; + return ssh - rp->peak->ss; } @@ -397,10 +374,10 @@ static int iterate(struct reflpeak *rps, int n, UnitCell *cell, } - /* Positional x terms */ + /* Positional fs terms */ for ( k=0; kdetgeom, *total_x, *total_y); + v_c = fs_dev(&rps[i], image->detgeom, *total_x, *total_y); v_c *= -gradients[k]; v_curr = gsl_vector_get(v, k); gsl_vector_set(v, k, v_curr + v_c); } - /* Positional y terms */ + /* Positional ss terms */ for ( k=0; kdetgeom, *total_x, *total_y); + v_c = ss_dev(&rps[i], image->detgeom, *total_x, *total_y); v_c *= -gradients[k]; v_curr = gsl_vector_get(v, k); gsl_vector_set(v, k, v_curr + v_c); @@ -535,13 +512,13 @@ static double pred_residual(struct reflpeak *rps, int n, struct detgeom *det, r = 0.0; for ( i=0; i