diff options
-rw-r--r-- | libcrystfel/src/integration.c | 59 | ||||
-rw-r--r-- | libcrystfel/src/integration.h | 2 | ||||
-rw-r--r-- | src/indexamajig.c | 2 |
3 files changed, 50 insertions, 13 deletions
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; p<ic->w; p++ ) { + for ( q=0; q<ic->w; 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<n; i++ ) { - if ( strcmp(methods[i], "rings") == 0) { + if ( strcmp(methods[i], "rings") == 0 ) { meth = INTEGRATION_DEFAULTS_RINGS; - } else if ( strcmp(methods[i], "prof2d") == 0) { + } else if ( strcmp(methods[i], "prof2d") == 0 ) { meth = INTEGRATION_DEFAULTS_PROF2D; - } else if ( strcmp(methods[i], "none") == 0) { + } else if ( strcmp(methods[i], "none") == 0 ) { return INTEGRATION_NONE; - } else if ( strcmp(methods[i], "sat") == 0) { + } else if ( strcmp(methods[i], "sat") == 0 ) { meth |= INTEGRATION_SATURATED; - } else if ( strcmp(methods[i], "nosat") == 0) { + } else if ( strcmp(methods[i], "nosat") == 0 ) { meth &= ~INTEGRATION_SATURATED; - } else if ( strcmp(methods[i], "cen") == 0) { + } else if ( strcmp(methods[i], "cen") == 0 ) { meth |= INTEGRATION_CENTER; - } else if ( strcmp(methods[i], "rescut") == 0) { + } else if ( strcmp(methods[i], "nocen") == 0 ) { + meth &= ~INTEGRATION_CENTER; + + } else if ( strcmp(methods[i], "rescut") == 0 ) { meth |= INTEGRATION_RESCUT; - } else if ( strcmp(methods[i], "norescut") == 0) { + } else if ( strcmp(methods[i], "norescut") == 0 ) { meth &= ~INTEGRATION_RESCUT; - } else if ( strcmp(methods[i], "nocen") == 0) { - meth &= ~INTEGRATION_CENTER; + } else if ( strcmp(methods[i], "grad") == 0 ) { + meth |= INTEGRATION_GRADIENTBG; + + } else if ( strcmp(methods[i], "nograd") == 0 ) { + meth &= ~INTEGRATION_GRADIENTBG; } else { ERROR("Bad integration method: '%s'\n", str); diff --git a/libcrystfel/src/integration.h b/libcrystfel/src/integration.h index a012fc14..2dd6139a 100644 --- a/libcrystfel/src/integration.h +++ b/libcrystfel/src/integration.h @@ -75,6 +75,7 @@ typedef enum { * @INTEGRATION_SATURATED: Integrate saturated reflections * @INTEGRATION_CENTER: Center the peak in the box prior to integration * @INTEGRATION_RESCUT: Stop integrating at the diffraction limit of the crystal + * @INTEGRATION_GRADIENTBG: Fit a gradient to the background * * An enumeration of all the available integration methods. **/ @@ -91,6 +92,7 @@ typedef enum { INTEGRATION_SATURATED = 256, INTEGRATION_CENTER = 512, INTEGRATION_RESCUT = 1024, + INTEGRATION_GRADIENTBG = 2048, } IntegrationMethod; diff --git a/src/indexamajig.c b/src/indexamajig.c index 164fa071..7fe66805 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -235,7 +235,7 @@ int main(int argc, char *argv[]) } iargs.indm = NULL; /* No default */ iargs.ipriv = NULL; /* No default */ - iargs.int_meth = integration_method("rings-nocen", NULL); + iargs.int_meth = integration_method("rings-nocen-nosat-grad", NULL); iargs.push_res = 0.0; iargs.highres = +INFINITY; iargs.fix_profile_r = -1.0; |