From 0da136dd6faec832cd25e964c13f6081e0899a17 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 17 Nov 2015 13:38:59 +0100 Subject: Make gradient background fitting optional --- libcrystfel/src/integration.c | 59 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 12 deletions(-) (limited to 'libcrystfel/src/integration.c') diff --git a/libcrystfel/src/integration.c b/libcrystfel/src/integration.c index 1b7001a6..afa4edca 100644 --- a/libcrystfel/src/integration.c +++ b/libcrystfel/src/integration.c @@ -331,7 +331,7 @@ static void show_peak_box(struct intcontext *ic, struct peak_box *bx, } -static void fit_bg(struct intcontext *ic, struct peak_box *bx) +static void fit_gradient_bg(struct intcontext *ic, struct peak_box *bx) { int p, q; gsl_vector *v; @@ -369,6 +369,33 @@ static void fit_bg(struct intcontext *ic, struct peak_box *bx) } +static void fit_bg(struct intcontext *ic, struct peak_box *bx) +{ + int p, q; + double tbg = 0.0; + int n = 0; + + if ( ic->meth & INTEGRATION_GRADIENTBG ) { + fit_gradient_bg(ic, bx); + return; + } + + /* else do a flat background */ + for ( p=0; pw; p++ ) { + for ( q=0; qw; q++ ) { + if ( bx->bm[p + ic->w*q] == BM_BG ) { + tbg += boxi(ic, bx, p, q); + n++; + } + } + } + + bx->a = 0.0; + bx->b = 0.0; + bx->c = tbg / n; +} + + static void zero_profiles(struct intcontext *ic) { int i; @@ -1113,7 +1140,9 @@ static double peak_height(struct intcontext *ic, struct peak_box *bx) static int bg_ok(struct intcontext *ic, struct peak_box *bx) { - double max_grad = (peak_height(ic, bx) - bg_under_peak(ic, bx)) / 10.0; + double max_grad; + + max_grad = fabs((peak_height(ic, bx) - bg_under_peak(ic, bx))) / 10.0; if ( (fabs(bx->a) > max_grad) || (fabs(bx->b) > max_grad) ) { return 0; @@ -1717,32 +1746,38 @@ IntegrationMethod integration_method(const char *str, int *err) for ( i=0; i