aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2015-11-17 13:38:59 +0100
committerThomas White <taw@physics.org>2015-11-17 13:41:05 +0100
commit0da136dd6faec832cd25e964c13f6081e0899a17 (patch)
tree21007288e44f3ae93c02c97b9d9f744d4a0ea85c /libcrystfel
parent4af4c99976d9658cc38fe97755bae9b909c5a7e8 (diff)
Make gradient background fitting optional
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/integration.c59
-rw-r--r--libcrystfel/src/integration.h2
2 files changed, 49 insertions, 12 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;