aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2016-04-07 17:36:57 +0200
committerThomas White <taw@physics.org>2016-07-01 10:17:38 +0200
commit6309221fcc3c573cdb20a7c953b8964fb85f78c5 (patch)
tree73955116d69a4b05490ce33dcee4ab90d765bdfc /libcrystfel
parent984ba3a87edddbe223f4597d322d21971c704c1e (diff)
No more slab-relative coordinates in libcrystfel
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/detector.c231
-rw-r--r--libcrystfel/src/detector.h30
-rw-r--r--libcrystfel/src/filters.c20
-rw-r--r--libcrystfel/src/geometry.c11
-rw-r--r--libcrystfel/src/hdf5-file.c577
-rw-r--r--libcrystfel/src/image.c32
-rw-r--r--libcrystfel/src/image.h16
-rw-r--r--libcrystfel/src/index.c6
-rw-r--r--libcrystfel/src/integration.c33
-rw-r--r--libcrystfel/src/mosflm.c20
-rw-r--r--libcrystfel/src/peaks.c94
-rw-r--r--libcrystfel/src/predict-refine.c16
-rw-r--r--libcrystfel/src/stream.c74
-rw-r--r--libcrystfel/src/xds.c20
14 files changed, 312 insertions, 868 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index 610da657..91fedaf2 100644
--- a/libcrystfel/src/detector.c
+++ b/libcrystfel/src/detector.c
@@ -3,12 +3,12 @@
*
* Detector properties
*
- * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
* Copyright © 2012 Richard Kirian
*
* Authors:
- * 2009-2015 Thomas White <taw@physics.org>
+ * 2009-2016 Thomas White <taw@physics.org>
* 2014 Valerio Mariani
* 2014 Kenneth Beyerlein <kenneth.beyerlein@desy.de>
* 2011 Andrew Aquila
@@ -298,39 +298,19 @@ struct rvec get_q_for_panel(struct panel *p, double fs, double ss,
}
-struct rvec get_q(struct image *image, double fs, double ss,
- double *ttp, double k)
-{
- struct panel *p;
- const unsigned int fsi = fs;
- const unsigned int ssi = ss; /* Explicit rounding */
-
- /* Determine which panel to use */
- p = find_panel(image->det, fsi, ssi);
- assert(p != NULL);
-
- return get_q_for_panel(p, fs-(double)p->min_fs, ss-(double)p->min_ss,
- ttp, k);
-}
-
-
-int in_bad_region(struct detector *det, double fs, double ss)
+int in_bad_region(struct detector *det, struct panel *p, double fs, double ss)
{
double rx, ry;
- struct panel *p;
double xs, ys;
int i;
- /* Determine which panel to use */
- p = find_panel(det, fs, ss);
-
/* No panel found -> definitely bad! */
if ( p == NULL ) return 1;
/* Convert xs and ys, which are in fast scan/slow scan coordinates,
* to x and y */
- xs = (fs-(double)p->min_fs)*p->fsx + (ss-(double)p->min_ss)*p->ssx;
- ys = (fs-(double)p->min_fs)*p->fsy + (ss-(double)p->min_ss)*p->ssy;
+ xs = fs*p->fsx + ss*p->ssx;
+ ys = fs*p->fsy + ss*p->ssy;
rx = xs + p->cnx;
ry = ys + p->cny;
@@ -348,8 +328,8 @@ int in_bad_region(struct detector *det, double fs, double ss)
/* fs/ss bad regions are specified according to the
* original coordinates */
- nfs = (fs-p->min_fs) + p->orig_min_fs;
- nss = (ss-p->min_ss) + p->orig_min_ss;
+ nfs = fs + p->orig_min_fs;
+ nss = ss + p->orig_min_ss;
if ( nfs < b->min_fs ) continue;
if ( nfs > b->max_fs ) continue;
@@ -372,34 +352,6 @@ int in_bad_region(struct detector *det, double fs, double ss)
}
-double get_tt(struct image *image, double fs, double ss, int *err)
-{
- double r, rx, ry;
- struct panel *p;
- double xs, ys;
-
- *err = 0;
-
- p = find_panel(image->det, fs, ss);
- if ( p == NULL ) {
- *err = 1;
- return 0.0;
- }
-
- /* Convert xs and ys, which are in fast scan/slow scan coordinates,
- * to x and y */
- xs = (fs-p->min_fs)*p->fsx + (ss-p->min_ss)*p->ssx;
- ys = (fs-p->min_fs)*p->fsy + (ss-p->min_ss)*p->ssy;
-
- rx = (xs + p->cnx) / p->res;
- ry = (ys + p->cny) / p->res;
-
- r = sqrt(pow(rx, 2.0) + pow(ry, 2.0));
-
- return atan2(r, p->clen);
-}
-
-
int detector_has_clen_references(struct detector *det)
{
int i;
@@ -538,32 +490,6 @@ void record_image(struct image *image, int do_poisson, double background,
}
-signed int find_panel_number(struct detector *det, double fs, double ss)
-{
- int p;
-
- /* Fractional pixel coordinates are allowed to be a little further along
- * than "== max_{f,s}s" for an integer. */
-
- for ( p=0; p<det->n_panels; p++ ) {
- if ( (fs >= det->panels[p].min_fs)
- && (fs < det->panels[p].max_fs+1)
- && (ss >= det->panels[p].min_ss)
- && (ss < det->panels[p].max_ss+1) ) return p;
- }
-
- return -1;
-}
-
-
-struct panel *find_panel(struct detector *det, double fs, double ss)
-{
- signed int pn = find_panel_number(det, fs, ss);
- if ( pn == -1 ) return NULL;
- return &det->panels[pn];
-}
-
-
signed int find_orig_panel_number(struct detector *det, double fs, double ss)
{
int p;
@@ -589,6 +515,18 @@ struct panel *find_orig_panel(struct detector *det, double fs, double ss)
}
+int panel_number(struct detector *det, struct panel *p)
+{
+ int pn;
+
+ for ( pn=0; pn<det->n_panels; pn++ ) {
+ if ( &det->panels[pn] == p ) return pn;
+ }
+
+ return det->n_panels;
+}
+
+
void fill_in_values(struct detector *det, struct hdfile *f, struct event* ev)
{
int i;
@@ -940,13 +878,13 @@ static int parse_field_for_panel(struct panel *panel, const char *key,
int reject = 0;
if ( strcmp(key, "min_fs") == 0 ) {
- panel->min_fs = atof(val);
+ panel->orig_min_fs = atof(val);
} else if ( strcmp(key, "max_fs") == 0 ) {
- panel->max_fs = atof(val);
+ panel->orig_max_fs = atof(val);
} else if ( strcmp(key, "min_ss") == 0 ) {
- panel->min_ss = atof(val);
+ panel->orig_min_ss = atof(val);
} else if ( strcmp(key, "max_ss") == 0 ) {
- panel->max_ss = atof(val);
+ panel->orig_max_ss = atof(val);
} else if ( strcmp(key, "corner_x") == 0 ) {
panel->cnx = atof(val);
} else if ( strcmp(key, "corner_y") == 0 ) {
@@ -1212,16 +1150,13 @@ static void find_min_max_d(struct detector *det)
for ( i=0; i<det->n_panels; i++ ) {
struct panel *p;
- double w, h;
p = &det->panels[i];
- w = p->max_fs - p->min_fs + 1;
- h = p->max_ss - p->min_ss + 1;
- check_point(p, 0, 0, &min_d, &max_d, det);
- check_point(p, w, 0, &min_d, &max_d, det);
- check_point(p, 0, h, &min_d, &max_d, det);
- check_point(p, w, h, &min_d, &max_d, det);
+ check_point(p, 0, 0, &min_d, &max_d, det);
+ check_point(p, p->w, 0, &min_d, &max_d, det);
+ check_point(p, 0, p->h, &min_d, &max_d, det);
+ check_point(p, p->w, p->h, &min_d, &max_d, det);
}
}
@@ -1239,8 +1174,6 @@ struct detector *get_detector_geometry(const char *filename,
int reject = 0;
int path_dim;
int dim_dim;
- int curr_ss;
- int x, y, max_fs, max_ss;
int dim_reject = 0;
int dim_dim_reject = 0;
struct rg_definition **rg_defl = NULL;
@@ -1277,10 +1210,6 @@ struct detector *get_detector_geometry(const char *filename,
det->rigid_group_collections = NULL;
/* The default defaults... */
- det->defaults.min_fs = -1;
- det->defaults.min_ss = -1;
- det->defaults.max_fs = -1;
- det->defaults.max_ss = -1;
det->defaults.orig_min_fs = -1;
det->defaults.orig_min_ss = -1;
det->defaults.orig_max_fs = -1;
@@ -1394,9 +1323,6 @@ struct detector *get_detector_geometry(const char *filename,
return NULL;
}
- max_fs = 0;
- max_ss = 0;
-
path_dim = -1;
dim_reject = 0;
@@ -1524,32 +1450,24 @@ struct detector *get_detector_geometry(const char *filename,
det->dim_dim = dim_dim;
- curr_ss = 0;
-
for ( i=0; i<det->n_panels; i++ ) {
- if ( det->panels[i].max_fs-det->panels[i].min_fs+1 !=
- det->panels[0].max_fs-det->panels[0].min_fs+1 ) {
- ERROR("All panels should have the same fs extent\n");
- reject = 1;
- }
-
- if ( det->panels[i ].min_fs < 0 ) {
+ if ( det->panels[i].orig_min_fs < 0 ) {
ERROR("Please specify the minimum FS coordinate for"
" panel %s\n", det->panels[i].name);
reject = 1;
}
- if ( det->panels[i].max_fs < 0 ) {
+ if ( det->panels[i].orig_max_fs < 0 ) {
ERROR("Please specify the maximum FS coordinate for"
" panel %s\n", det->panels[i].name);
reject = 1;
}
- if ( det->panels[i].min_ss < 0 ) {
+ if ( det->panels[i].orig_min_ss < 0 ) {
ERROR("Please specify the minimum SS coordinate for"
" panel %s\n", det->panels[i].name);
reject = 1;
}
- if ( det->panels[i].max_ss < 0 ) {
+ if ( det->panels[i].orig_max_ss < 0 ) {
ERROR("Please specify the maximum SS coordinate for"
" panel %s\n", det->panels[i].name);
reject = 1;
@@ -1587,28 +1505,10 @@ struct detector *get_detector_geometry(const char *filename,
/* It's not a problem if "no_index" is still zero */
/* The default transformation matrix is at least valid */
- det->panels[i].orig_max_fs = det->panels[i].max_fs;
- det->panels[i].orig_min_fs = det->panels[i].min_fs;
- det->panels[i].orig_max_ss = det->panels[i].max_ss;
- det->panels[i].orig_min_ss = det->panels[i].min_ss;
-
- det->panels[i].w =
- det->panels[i].max_fs-det->panels[i].min_fs+1;
- det->panels[i].h =
- det->panels[i].max_ss-det->panels[i].min_ss+1;
-
- det->panels[i].min_fs = 0;
- det->panels[i].max_fs = det->panels[i].w-1;
- det->panels[i].min_ss = curr_ss;
- det->panels[i].max_ss = curr_ss+det->panels[i].h-1;
- curr_ss += det->panels[i].h;
-
- if ( det->panels[i].max_fs > max_fs ) {
- max_fs = det->panels[i].max_fs;
- }
- if ( det->panels[i].max_ss > max_ss ) {
- max_ss = det->panels[i].max_ss;
- }
+ det->panels[i].w = det->panels[i].orig_max_fs
+ - det->panels[i].orig_min_fs+1;
+ det->panels[i].h = det->panels[i].orig_max_ss
+ - det->panels[i].orig_min_ss+1;
}
@@ -1620,20 +1520,6 @@ struct detector *get_detector_geometry(const char *filename,
}
}
- for ( x=0; x<=max_fs; x++ ) {
- for ( y=0; y<=max_ss; y++ ) {
- if ( find_panel(det, x, y) == NULL ) {
- ERROR("Detector geometry invalid: contains gaps.\n");
- reject = 1;
- goto out;
- }
- }
- }
-
-out:
- det->max_fs = max_fs;
- det->max_ss = max_ss;
-
free(det->defaults.clen_from);
free(det->defaults.data);
free(det->defaults.mask);
@@ -1744,8 +1630,8 @@ out:
p->xss = -p->fsy / d;
p->yss = p->fsx / d;
- p->w = p->max_fs - p->min_fs + 1;
- p->h = p->max_ss - p->min_ss + 1;
+ p->w = p->orig_max_fs - p->orig_min_fs + 1;
+ p->h = p->orig_max_ss - p->orig_min_ss + 1;
}
@@ -1884,7 +1770,7 @@ struct detector *copy_geom(const struct detector *in)
}
-struct detector *simple_geometry(const struct image *image)
+struct detector *simple_geometry(const struct image *image, int w, int h)
{
struct detector *geom;
@@ -1893,16 +1779,12 @@ struct detector *simple_geometry(const struct image *image)
geom->n_panels = 1;
geom->panels = calloc(1, sizeof(struct panel));
- geom->panels[0].min_fs = 0;
- geom->panels[0].max_fs = image->width-1;
- geom->panels[0].min_ss = 0;
- geom->panels[0].max_ss = image->height-1;
geom->panels[0].orig_min_fs = 0;
- geom->panels[0].orig_max_fs = image->width-1;
+ geom->panels[0].orig_max_fs = w-1;
geom->panels[0].orig_min_ss = 0;
- geom->panels[0].orig_max_ss = image->height-1;
- geom->panels[0].cnx = -image->width / 2.0;
- geom->panels[0].cny = -image->height / 2.0;
+ geom->panels[0].orig_max_ss = h-1;
+ geom->panels[0].cnx = -w / 2.0;
+ geom->panels[0].cny = -h / 2.0;
geom->panels[0].max_adu = INFINITY;
geom->panels[0].orig_min_fs = -1;
geom->panels[0].orig_max_fs = -1;
@@ -1919,8 +1801,8 @@ struct detector *simple_geometry(const struct image *image)
geom->panels[0].yfs = 0;
geom->panels[0].yss = 1;
- geom->panels[0].w = image->width;
- geom->panels[0].h = image->height;
+ geom->panels[0].w = w;
+ geom->panels[0].h = h;
geom->panels[0].mask = NULL;
geom->panels[0].data = NULL;
@@ -1931,8 +1813,8 @@ struct detector *simple_geometry(const struct image *image)
}
-int reverse_2d_mapping(double x, double y, double *pfs, double *pss,
- struct detector *det)
+int reverse_2d_mapping(double x, double y, struct detector *det,
+ struct panel **pp, double *pfs, double *pss)
{
int i;
@@ -1952,11 +1834,12 @@ int reverse_2d_mapping(double x, double y, double *pfs, double *pss,
/* In range? */
if ( fs < 0 ) continue;
if ( ss < 0 ) continue;
- if ( fs > p->max_fs-p->min_fs ) continue;
- if ( ss > p->max_ss-p->min_ss ) continue;
+ if ( fs > p->w ) continue;
+ if ( ss > p->h ) continue;
- *pfs = fs + p->min_fs;
- *pss = ss + p->min_ss;
+ *pfs = fs;
+ *pss = ss;
+ *pp = p;
return 0;
}
@@ -2095,20 +1978,16 @@ void get_pixel_extents(struct detector *det,
for ( i=0; i<det->n_panels; i++ ) {
check_extents(det->panels[i], min_x, min_y, max_x, max_y,
- 0.0,
- 0.0);
+ 0.0, 0.0);
check_extents(det->panels[i], min_x, min_y, max_x, max_y,
- 0.0,
- det->panels[i].max_ss-det->panels[i].min_ss+1);
+ 0.0, det->panels[i].h+1);
check_extents(det->panels[i], min_x, min_y, max_x, max_y,
- det->panels[i].max_fs-det->panels[i].min_fs+1,
- 0.0);
+ det->panels[i].w+1, 0.0);
check_extents(det->panels[i], min_x, min_y, max_x, max_y,
- det->panels[i].max_fs-det->panels[i].min_fs+1,
- det->panels[i].max_ss-det->panels[i].min_ss+1);
+ det->panels[i].w+1, det->panels[i].h+1);
}
diff --git a/libcrystfel/src/detector.h b/libcrystfel/src/detector.h
index a52d56b7..dad3afe4 100644
--- a/libcrystfel/src/detector.h
+++ b/libcrystfel/src/detector.h
@@ -3,12 +3,12 @@
*
* Detector properties
*
- * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
* Copyright © 2012 Richard Kirian
*
* Authors:
- * 2009-2015 Thomas White <taw@physics.org>
+ * 2009-2016 Thomas White <taw@physics.org>
* 2011-2012 Richard Kirian <rkirian@asu.edu>
* 2014 Valerio Mariani
* 2011 Andrew Aquila
@@ -84,12 +84,6 @@ struct panel
{
char name[1024]; /* Name for this panel */
- /* Position of panel in the data block in memory (see below) */
- int min_fs; /* Smallest FS value considered to be in the panel */
- int max_fs; /* Largest FS value considered to be in this panel */
- int min_ss; /* ... and so on */
- int max_ss;
-
double cnx; /* Location of corner (min_fs,min_ss) in pixels */
double cny;
double coffset;
@@ -158,9 +152,6 @@ struct detector
struct panel *panels;
int n_panels;
- int max_fs;
- int max_ss; /* Size of overall array needed, minus 1 */
-
struct badregion *bad;
int n_bad;
@@ -192,32 +183,31 @@ struct detector
};
-extern struct rvec get_q(struct image *image, double fs, double ss,
- double *ttp, double k);
-
extern struct rvec get_q_for_panel(struct panel *p, double fs, double ss,
double *ttp, double k);
extern double get_tt(struct image *image, double xs, double ys, int *err);
-extern int in_bad_region(struct detector *det, double fs, double ss);
+extern int in_bad_region(struct detector *det, struct panel *p,
+ double fs, double ss);
extern void record_image(struct image *image, int do_poisson, double background,
gsl_rng *rng, double beam_radius, double nphotons);
-extern struct panel *find_panel(struct detector *det, double fs, double ss);
-extern signed int find_panel_number(struct detector *det, double fs, double ss);
extern struct panel *find_orig_panel(struct detector *det,
double fs, double ss);
+
extern signed int find_orig_panel_number(struct detector *det,
double fs, double ss);
+extern int panel_number(struct detector *det, struct panel *p);
+
extern struct detector *get_detector_geometry(const char *filename,
struct beam_params *beam);
extern void free_detector_geometry(struct detector *det);
-extern struct detector *simple_geometry(const struct image *image);
+extern struct detector *simple_geometry(const struct image *image, int w, int h);
extern void get_pixel_extents(struct detector *det,
double *min_x, double *min_y,
@@ -235,8 +225,8 @@ extern int rigid_group_is_in_collection(struct rg_collection *c,
extern struct detector *copy_geom(const struct detector *in);
-extern int reverse_2d_mapping(double x, double y, double *pfs, double *pss,
- struct detector *det);
+extern int reverse_2d_mapping(double x, double y, struct detector *det,
+ struct panel **pp, double *pfs, double *pss);
extern double largest_q(struct image *image);
diff --git a/libcrystfel/src/filters.c b/libcrystfel/src/filters.c
index c804099e..cbaf6001 100644
--- a/libcrystfel/src/filters.c
+++ b/libcrystfel/src/filters.c
@@ -3,11 +3,11 @@
*
* Image filtering
*
- * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2010-2015 Thomas White <taw@physics.org>
+ * 2010-2016 Thomas White <taw@physics.org>
* 2013 Anton Barty <anton.barty@desy.de>
*
* This file is part of CrystFEL.
@@ -132,7 +132,6 @@ void filter_median(struct image *image, int size)
int counter;
int nn;
float *buffer;
- float *localBg;
int pn;
if ( size <= 0 ) return;
@@ -142,9 +141,8 @@ void filter_median(struct image *image, int size)
/* "localBg" is way too big, but guaranteed big enough */
buffer = calloc(nn, sizeof(float));
- localBg = calloc(image->width*image->height, sizeof(float));
- if ( (buffer == NULL) || (localBg == NULL) ) {
- ERROR("Failed to allocate LB buffers.\n");
+ if ( buffer == NULL ) {
+ ERROR("Failed to allocate LB buffer.\n");
return;
}
@@ -155,9 +153,16 @@ void filter_median(struct image *image, int size)
int fs, ss;
int i;
struct panel *p;
+ float *localBg;
p = &image->det->panels[pn];
+ localBg = calloc(p->w*p->h, sizeof(float));
+ if ( localBg == NULL ) {
+ ERROR("Failed to allocate LB buffer.\n");
+ return;
+ }
+
for ( fs=0; fs<p->w; fs++ ) {
for ( ss=0; ss<p->h; ss++ ) {
@@ -193,8 +198,9 @@ void filter_median(struct image *image, int size)
for ( i=0; i<p->w*p->h; i++ ) {
image->dp[pn][i] -= localBg[i];
}
+
+ free(localBg);
}
- free(localBg);
free(buffer);
}
diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c
index 4c24f0bf..0f643ebe 100644
--- a/libcrystfel/src/geometry.c
+++ b/libcrystfel/src/geometry.c
@@ -69,16 +69,13 @@ static int locate_peak_on_panel(double x, double y, double z, double k,
fs = p->xfs*plx + p->yfs*ply;
ss = p->xss*plx + p->yss*ply;
- fs += p->min_fs;
- ss += p->min_ss;
-
*pfs = fs; *pss = ss;
/* Now, is this on this panel? */
- if ( fs < p->min_fs ) return 0;
- if ( fs > p->max_fs ) return 0;
- if ( ss < p->min_ss ) return 0;
- if ( ss > p->max_ss ) return 0;
+ if ( fs < 0 ) return 0;
+ if ( fs > p->w ) return 0;
+ if ( ss < 0 ) return 0;
+ if ( ss > p->h ) return 0;
return 1;
}
diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c
index 16fa0e75..95da2353 100644
--- a/libcrystfel/src/hdf5-file.c
+++ b/libcrystfel/src/hdf5-file.c
@@ -88,9 +88,6 @@ struct hdfile {
const char *path; /* Current data path */
- size_t nfs; /* Image width */
- size_t nss; /* Image height */
-
hid_t fh; /* HDF file handle */
hid_t dh; /* Dataset handle */
@@ -127,67 +124,12 @@ struct hdfile *hdfile_open(const char *filename)
int hdfile_set_image(struct hdfile *f, const char *path,
struct panel *p)
{
- hsize_t *size;
- hsize_t *max_size;
- hid_t sh;
- int sh_dim;
- int di;
-
f->dh = H5Dopen2(f->fh, path, H5P_DEFAULT);
if ( f->dh < 0 ) {
ERROR("Couldn't open dataset\n");
return -1;
}
f->data_open = 1;
- sh = H5Dget_space(f->dh);
- sh_dim = H5Sget_simple_extent_ndims(sh);
-
- if ( p == NULL ) {
-
- if ( sh_dim != 2 ) {
- ERROR("Dataset is not two-dimensional\n");
- return -1;
- }
-
- } else {
-
- if ( sh_dim != p->dim_structure->num_dims ) {
- ERROR("Dataset dimensionality does not match "
- "geometry file\n");
- return -1;
- }
-
- }
-
- size = malloc(sh_dim*sizeof(hsize_t));
- max_size = malloc(sh_dim*sizeof(hsize_t));
-
- H5Sget_simple_extent_dims(sh, size, max_size);
- H5Sclose(sh);
-
- if ( p == NULL ) {
-
- f->nss = size[0];
- f->nfs = size[1];
-
- } else {
-
- for ( di=0; di<p->dim_structure->num_dims; di++ ) {
-
- if ( p->dim_structure->dims[di] == HYSL_SS ) {
- f->nss = size[di];
- }
- if ( p->dim_structure->dims[di] == HYSL_FS ) {
- f->nfs = size[di];
- }
-
- }
-
- }
-
- free(size);
- free(max_size);
-
return 0;
}
@@ -441,13 +383,11 @@ int get_peaks_cxi(struct image *image, struct hdfile *f, const char *p,
if ( p == NULL ) continue;
if ( p->no_index ) continue;
- /* Convert coordinates to match rearranged
- * panels in memory */
- fs = fs - p->orig_min_fs + p->min_fs;
- ss = ss - p->orig_min_ss + p->min_ss;
+ /* Convert coordinates to panel-relative */
+ fs = fs - p->orig_min_fs;
+ ss = ss - p->orig_min_ss;
- image_add_feature(image->features, fs, ss, image,
- val, NULL);
+ image_add_feature(image->features, fs, ss, p, image, val, NULL);
}
@@ -541,11 +481,11 @@ int get_peaks(struct image *image, struct hdfile *f, const char *p)
if ( p == NULL ) continue;
if ( p->no_index ) continue;
- /* Convert coordinates to match rearranged panels in memory */
- fs = fs - p->orig_min_fs + p->min_fs;
- ss = ss - p->orig_min_ss + p->min_ss;
+ /* Convert coordinates to panel-relative */
+ fs = fs - p->orig_min_fs;
+ ss = ss - p->orig_min_ss;
- image_add_feature(image->features, fs, ss, image, val,
+ image_add_feature(image->features, fs, ss, p, image, val,
NULL);
}
@@ -791,9 +731,6 @@ static void write_location(hid_t fh, struct detector *det, float *data,
for ( pi=0; pi<loc->n_panels; pi++ ) {
hsize_t f_offset[2], f_count[2];
- hsize_t m_offset[2], m_count[2];
- hsize_t dimsm[2];
- hid_t memspace;
struct panel p;
int r;
@@ -818,18 +755,7 @@ static void write_location(hid_t fh, struct detector *det, float *data,
return;
}
- m_offset[0] = p.min_ss;
- m_offset[1] = p.min_fs;
- m_count[0] = p.max_ss - p.min_ss +1;
- m_count[1] = p.max_fs - p.min_fs +1;
-
- dimsm[0] = det->max_ss + 1;
- dimsm[1] = det->max_fs + 1;
- memspace = H5Screate_simple(2, dimsm, NULL);
-
- r = H5Sselect_hyperslab(memspace, H5S_SELECT_SET,
- m_offset, NULL, m_count, NULL);
- r = H5Dwrite(dh, H5T_NATIVE_FLOAT, memspace,
+ r = H5Dwrite(dh, H5T_NATIVE_FLOAT, H5S_ALL,
dh_dataspace, H5P_DEFAULT, data);
if ( r < 0 ) {
ERROR("Couldn't write data\n");
@@ -837,13 +763,11 @@ static void write_location(hid_t fh, struct detector *det, float *data,
H5Dclose(dh);
H5Sclose(dh_dataspace);
H5Sclose(sh);
- H5Sclose(memspace);
H5Fclose(fh);
return;
}
H5Sclose(dh_dataspace);
- H5Sclose(memspace);
}
H5Pclose(ph);
H5Sclose(sh);
@@ -961,34 +885,6 @@ static void write_spectrum(hid_t fh, struct sample *spectrum, int spectrum_size,
}
-static float *make_array_from_dp(const struct image *image)
-{
- int i;
- float *data;
-
- data = malloc(image->width * image->height * sizeof(float));
- if ( data == NULL ) {
- ERROR("Failed to allocate data\n");
- return NULL;
- }
-
- for ( i=0; i<image->det->n_panels; i++ ) {
-
- int fs, ss;
- struct panel *p = &image->det->panels[i];
-
- for ( ss=0; ss<p->h; ss++ ) {
- for ( fs=0; fs<p->w; fs++ ) {
- int idx = p->min_fs+fs + image->width*(p->min_ss+ss);
- data[idx] = image->dp[i][fs + p->w*ss];
- }
- }
- }
-
- return data;
-}
-
-
int hdf5_write_image(const char *filename, const struct image *image,
char *element)
{
@@ -998,16 +894,12 @@ int hdf5_write_image(const char *filename, const struct image *image,
struct hdf5_write_location *locations;
int num_locations;
const char *ph_en_loc;
- float *data;
if ( image->det == NULL ) {
ERROR("Geometry not available\n");
return 1;
}
- data = make_array_from_dp(image);
- if ( data == NULL ) return 1;
-
fh = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if ( fh < 0 ) {
ERROR("Couldn't create file: %s\n", filename);
@@ -1024,7 +916,7 @@ int hdf5_write_image(const char *filename, const struct image *image,
&num_locations);
for ( li=0; li<num_locations; li++ ) {
- write_location(fh, image->det, data, &locations[li]);
+ write_location(fh, image->det, image->dp[li], &locations[li]);
}
if ( image->beam == NULL
@@ -1047,7 +939,6 @@ int hdf5_write_image(const char *filename, const struct image *image,
for ( li=0; li<num_locations; li ++ ) {
free(locations[li].panel_idxs);
}
- free(data);
free(locations);
return 0;
}
@@ -1139,84 +1030,44 @@ static void debodge_saturation(struct hdfile *f, struct image *image)
}
-static int unpack_panels(struct image *image, struct detector *det,
- float *data, uint16_t *flags, float *sat)
+static int *make_badmask(int *flags, struct panel *p, struct detector *det)
{
- int pi;
+ int *badmap;
+ int fs, ss;
- image->dp = malloc(det->n_panels * sizeof(float *));
- image->bad = malloc(det->n_panels * sizeof(int *));
- image->sat = malloc(det->n_panels * sizeof(float *));
- if ( (image->dp == NULL) || (image->bad == NULL)
- || (image->sat == NULL) )
- {
- ERROR("Failed to allocate panels.\n");
- return 1;
+ badmap = malloc(p->w*p->h*sizeof(int));
+ if ( badmap == NULL ) {
+ ERROR("Failed to allocate bad mask for panel %s\n",
+ p->name);
+ return NULL;
}
- for ( pi=0; pi<det->n_panels; pi++ ) {
-
- struct panel *p;
- int fs, ss;
-
- p = &det->panels[pi];
- image->dp[pi] = malloc(p->w*p->h*sizeof(float));
- image->bad[pi] = calloc(p->w*p->h, sizeof(int));
- image->sat[pi] = malloc(p->w*p->h*sizeof(float));
- if ( (image->dp[pi] == NULL) || (image->bad[pi] == NULL)
- || (image->sat[pi] == NULL) )
- {
- ERROR("Failed to allocate panel\n");
- return 1;
- }
-
- for ( ss=0; ss<p->h; ss++ ) {
- for ( fs=0; fs<p->w; fs++ ) {
-
- int idx;
- int cfs, css;
- int bad = 0;
-
- cfs = fs+p->min_fs;
- css = ss+p->min_ss;
- idx = cfs + css*image->width;
-
- image->dp[pi][fs+p->w*ss] = data[idx];
+ for ( ss=0; ss<p->h; ss++ ) {
+ for ( fs=0; fs<p->w; fs++ ) {
- if ( sat != NULL ) {
- image->sat[pi][fs+p->w*ss] = sat[idx];
- } else {
- image->sat[pi][fs+p->w*ss] = INFINITY;
- }
+ int bad = 0;
+ int f;
- if ( p->no_index ) bad = 1;
-
- if ( in_bad_region(det, cfs, css) ) {
- bad = 1;
- }
+ if ( p->no_index ) bad = 1;
- if ( flags != NULL ) {
-
- int f;
-
- f = flags[idx];
+ if ( in_bad_region(det, p, fs, ss) ) {
+ bad = 1;
+ }
- /* Bad if it's missing any of the "good" bits */
- if ( (f & image->det->mask_good)
- != image->det->mask_good ) bad = 1;
+ f = flags[fs+p->w*ss];
- /* Bad if it has any of the "bad" bits. */
- if ( f & image->det->mask_bad ) bad = 1;
+ /* Bad if it's missing any of the "good" bits */
+ if ( (f & det->mask_good) != det->mask_good ) bad = 1;
- }
- image->bad[pi][fs+p->w*ss] = bad;
+ /* Bad if it has any of the "bad" bits. */
+ if ( f & det->mask_bad ) bad = 1;
- }
- }
+ badmap[fs+p->w*ss] = bad;
}
+ }
- return 0;
+ return badmap;
}
@@ -1448,6 +1299,11 @@ int hdf5_read(struct hdfile *f, struct image *image, const char *element,
herr_t r;
float *buf;
int fail;
+ hsize_t *size;
+ hsize_t *max_size;
+ hid_t sh;
+ int sh_dim;
+ int w, h;
if ( element == NULL ) {
fail = hdfile_set_first_image(f, "/");
@@ -1460,13 +1316,26 @@ int hdf5_read(struct hdfile *f, struct image *image, const char *element,
return 1;
}
- image->width = f->nfs;
- image->height = f->nss;
+ sh = H5Dget_space(f->dh);
+ sh_dim = H5Sget_simple_extent_ndims(sh);
+
+ if ( sh_dim != 2 ) {
+ ERROR("Dataset is not two-dimensional\n");
+ return -1;
+ }
- buf = malloc(sizeof(float)*f->nfs*f->nss);
+ size = malloc(sh_dim*sizeof(hsize_t));
+ max_size = malloc(sh_dim*sizeof(hsize_t));
+ H5Sget_simple_extent_dims(sh, size, max_size);
+ H5Sclose(sh);
+ w = size[1];
+ h = size[0];
+ free(size);
+ free(max_size);
+ buf = malloc(sizeof(float)*w*h);
r = H5Dread(f->dh, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
- H5P_DEFAULT, buf);
+ H5P_DEFAULT, buf);
if ( r < 0 ) {
ERROR("Couldn't read data\n");
free(buf);
@@ -1476,9 +1345,8 @@ int hdf5_read(struct hdfile *f, struct image *image, const char *element,
if ( image->det != NULL ) {
ERROR("WARNING: hdf5_read() called with geometry structure.\n");
}
- image->det = simple_geometry(image);
+ image->det = simple_geometry(image, w, h);
- unpack_panels(image, image->det, buf, NULL, NULL);
if ( satcorr ) debodge_saturation(f, image);
if ( image->beam != NULL ) {
@@ -1501,210 +1369,10 @@ int hdf5_read(struct hdfile *f, struct image *image, const char *element,
}
-static hsize_t *first_two_dims(hsize_t *in, struct dim_structure *ds)
-{
- int i, j;
- hsize_t *out = malloc(2*sizeof(hsize_t));
-
- if ( out == NULL ) return NULL;
-
- j = 0;
- for ( i=0; i<ds->num_dims; i++ ) {
- if ( (ds->dims[i] == HYSL_FS) || (ds->dims[i] == HYSL_SS) ) {
- out[j++] = in[i];
- }
- }
- return out;
-}
-
-
-static int load_mask(struct hdfile *f, struct event *ev, char *mask,
- const char *mask_file,
- const char *pname, struct image *image,
- size_t p_w, size_t sum_p_h, uint16_t *flags,
- hsize_t *in_f_offset, hsize_t *in_f_count,
- hsize_t *m_offset, hsize_t *m_count,
- struct dim_structure *dim_struct)
-{
- hid_t mask_dataspace, mask_dh;
- int exists;
- int check, r;
- hid_t memspace;
- hsize_t dimsm[2];
- hid_t fh;
- hsize_t *f_offset, *f_count;
-
- if ( mask_file != NULL ) {
-
- fh = H5Fopen(mask_file, H5F_ACC_RDONLY, H5P_DEFAULT);
- if ( fh < 0 ) {
- ERROR("Couldn't open mask file '%s'\n", mask_file);
- return 1;
- }
-
- /* If we have an external map file, we assume it to be a simple
- * 2D job */
- f_offset = first_two_dims(in_f_offset, dim_struct);
- f_count = first_two_dims(in_f_count, dim_struct);
-
- } else {
- fh = f->fh;
- f_offset = in_f_offset;
- f_count = in_f_count;
- }
-
- if ( ev != NULL ) {
- mask = retrieve_full_path(ev, mask);
- }
-
- exists = check_path_existence(fh, mask);
- if ( !exists ) {
- ERROR("Cannot find flags for panel %s\n", pname);
- goto err;
- }
-
- mask_dh = H5Dopen2(fh, mask, H5P_DEFAULT);
- if ( mask_dh <= 0 ) {
- ERROR("Couldn't open flags for panel %s\n", pname);
- goto err;
- }
-
- mask_dataspace = H5Dget_space(mask_dh);
- check = H5Sselect_hyperslab(mask_dataspace, H5S_SELECT_SET,
- f_offset, NULL, f_count, NULL);
- if ( check < 0 ) {
- ERROR("Error selecting mask dataspace for panel %s\n", pname);
- goto err;
- }
-
- dimsm[0] = sum_p_h;
- dimsm[1] = p_w;
- memspace = H5Screate_simple(2, dimsm, NULL);
- check = H5Sselect_hyperslab(memspace, H5S_SELECT_SET,
- m_offset, NULL, m_count, NULL);
- if ( check < 0 ) {
- ERROR("Error selecting memory dataspace for panel %s\n", pname);
- goto err;
- }
-
- r = H5Dread(mask_dh, H5T_NATIVE_UINT16, memspace,
- mask_dataspace, H5P_DEFAULT, flags);
- if ( r < 0 ) {
- ERROR("Couldn't read flags for panel %s\n", pname);
- goto err;
- }
-
- H5Sclose(mask_dataspace);
- H5Dclose(mask_dh);
- if ( ev != NULL ) free(mask);
-
- return 0;
-
-err:
- if ( mask_file != NULL ) H5Fclose(fh);
- if ( ev != NULL ) free(mask);
- return 1;
-}
-
-
-static int load_satmap(struct hdfile *f, struct event *ev, char *satmap,
- const char *satmap_file,
- const char *pname, struct image *image,
- size_t p_w, size_t sum_p_h, float *smap,
- hsize_t *in_f_offset, hsize_t *in_f_count,
- hsize_t *m_offset, hsize_t *m_count,
- struct dim_structure *dim_struct)
-{
- hid_t satmap_dataspace, satmap_dh;
- int exists;
- int check, r;
- hid_t memspace;
- hsize_t dimsm[2];
- hid_t fh;
- hsize_t *f_offset, *f_count;
-
- if ( satmap_file != NULL ) {
-
- fh = H5Fopen(satmap_file, H5F_ACC_RDONLY, H5P_DEFAULT);
- if ( fh < 0 ) {
- ERROR("Couldn't open satmap file '%s'\n", satmap_file);
- return 1;
- }
-
- /* If we have an external map file, we assume it to be a simple
- * 2D job */
- f_offset = first_two_dims(in_f_offset, dim_struct);
- f_count = first_two_dims(in_f_count, dim_struct);
-
- } else {
- fh = f->fh;
- f_offset = in_f_offset;
- f_count = in_f_count;
- }
-
- if ( ev != NULL ) {
- satmap = retrieve_full_path(ev, satmap);
- }
-
- exists = check_path_existence(fh, satmap);
- if ( !exists ) {
- ERROR("Cannot find satmap for panel %s\n", pname);
- goto err;
- }
-
- satmap_dh = H5Dopen2(fh, satmap, H5P_DEFAULT);
- if ( satmap_dh <= 0 ) {
- ERROR("Couldn't open satmap for panel %s\n", pname);
- goto err;
- }
-
- satmap_dataspace = H5Dget_space(satmap_dh);
- check = H5Sselect_hyperslab(satmap_dataspace, H5S_SELECT_SET,
- f_offset, NULL, f_count, NULL);
- if ( check < 0 ) {
- ERROR("Error selecting satmap dataspace for panel %s\n", pname);
- goto err;
- }
-
- dimsm[0] = sum_p_h;
- dimsm[1] = p_w;
- memspace = H5Screate_simple(2, dimsm, NULL);
- check = H5Sselect_hyperslab(memspace, H5S_SELECT_SET,
- m_offset, NULL, m_count, NULL);
- if ( check < 0 ) {
- ERROR("Error selecting memory dataspace for panel %s\n", pname);
- goto err;
- }
-
- r = H5Dread(satmap_dh, H5T_NATIVE_FLOAT, memspace,
- satmap_dataspace, H5P_DEFAULT, smap);
- if ( r < 0 ) {
- ERROR("Couldn't read satmap for panel %s\n", pname);
- goto err;
- }
-
- H5Sclose(satmap_dataspace);
- H5Dclose(satmap_dh);
- if ( ev != NULL ) free(satmap);
-
- return 0;
-
-err:
- if ( satmap_file != NULL ) H5Fclose(fh);
- if ( ev != NULL ) free(satmap);
- return 1;
-}
-
-
int hdf5_read2(struct hdfile *f, struct image *image, struct event *ev,
int satcorr)
{
herr_t r;
- float *buf;
- uint16_t *flags;
- float *smap;
- int sum_p_h;
- int p_w;
int pi;
int i;
@@ -1713,51 +1381,21 @@ int hdf5_read2(struct hdfile *f, struct image *image, struct event *ev,
return 1;
}
- p_w = image->det->panels[0].w;
- sum_p_h = 0;
-
- for ( pi=0; pi<image->det->n_panels; pi++ ) {
-
- if ( image->det->panels[pi].w != p_w ) {
- ERROR("Panels must have the same width.");
- return 1;
- }
-
- sum_p_h += image->det->panels[pi].h;
-
- }
-
- buf = malloc(sizeof(float)*p_w*sum_p_h);
- if ( buf == NULL ) {
- ERROR("Failed to allocate memory for image\n");
- return 1;
- }
- image->width = p_w;
- image->height = sum_p_h;
-
- flags = calloc(p_w*sum_p_h,sizeof(uint16_t));
- if ( flags == NULL ) {
- ERROR("Failed to allocate memory for flags\n");
- return 1;
- }
-
- smap = calloc(p_w*sum_p_h,sizeof(float));
- if ( smap == NULL ) {
- ERROR("Failed to allocate memory for satmap\n");
+ image->dp = malloc(image->det->n_panels*sizeof(float *));
+ image->bad = malloc(image->det->n_panels*sizeof(int *));
+ image->sat = malloc(image->det->n_panels*sizeof(float *));
+ if ( (image->dp==NULL) || (image->bad==NULL) || (image->sat==NULL) ) {
+ ERROR("Failed to allocate data arrays.\n");
return 1;
}
- for ( i=0; i<p_w*sum_p_h; i++ ) smap[i] = INFINITY;
for ( pi=0; pi<image->det->n_panels; pi++ ) {
- int data_width, data_height;
hsize_t *f_offset, *f_count;
int hsi;
struct dim_structure *hsd;
- hsize_t m_offset[2], m_count[2];
- hsize_t dimsm[2];
herr_t check;
- hid_t dataspace, memspace;
+ hid_t dataspace;
int fail;
struct panel *p;
@@ -1807,25 +1445,14 @@ int hdf5_read2(struct hdfile *f, struct image *image, struct event *ev,
return 1;
}
- data_width = f->nfs;
- data_height = f->nss;
-
- if ( (data_width < p->w )
- || (data_height < p->h) )
- {
- ERROR("Data size doesn't match panel geometry size"
- " - rejecting image.\n");
- ERROR("Panel name: %s. Data size: %i,%i. "
- "Geometry size: %i,%i\n",
- p->name, data_width, data_height, p->w, p->h);
- return 1;
- }
-
+ /* Determine where to read the data from in the file */
hsd = image->det->panels[pi].dim_structure;
-
f_offset = malloc(hsd->num_dims*sizeof(hsize_t));
f_count = malloc(hsd->num_dims*sizeof(hsize_t));
-
+ if ( (f_offset == NULL) || (f_count == NULL ) ) {
+ ERROR("Failed to allocate offset or count.\n");
+ return 1;
+ }
for ( hsi=0; hsi<hsd->num_dims; hsi++ ) {
if ( hsd->dims[hsi] == HYSL_FS ) {
@@ -1844,76 +1471,74 @@ int hdf5_read2(struct hdfile *f, struct image *image, struct event *ev,
}
+ /* Set up dataspace for file */
dataspace = H5Dget_space(f->dh);
check = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET,
f_offset, NULL, f_count, NULL);
if ( check < 0 ) {
ERROR("Error selecting file dataspace for panel %s\n",
p->name);
- free(buf);
return 1;
}
- m_offset[0] = p->min_ss;
- m_offset[1] = p->min_fs;
- m_count[0] = p->max_ss - p->min_ss +1;
- m_count[1] = p->max_fs - p->min_fs +1;
- dimsm[0] = sum_p_h;
- dimsm[1] = p_w;
- memspace = H5Screate_simple(2, dimsm, NULL);
- check = H5Sselect_hyperslab(memspace, H5S_SELECT_SET,
- m_offset, NULL, m_count, NULL);
- if ( check < 0 ) {
- ERROR("Error selecting memory dataspace for panel %s\n",
- p->name);
- free(buf);
+ image->dp[pi] = malloc(p->w*p->h*sizeof(float));
+ image->sat[pi] = malloc(p->w*p->h*sizeof(float));
+ if ( (image->dp[pi] == NULL) || (image->sat[pi] == NULL) ) {
+ ERROR("Failed to allocate panel %s\n", p->name);
free(f_offset);
free(f_count);
return 1;
}
+ for ( i=0; i<p->w*p->h; i++ ) image->sat[pi][i] = INFINITY;
- r = H5Dread(f->dh, H5T_NATIVE_FLOAT, memspace, dataspace,
- H5P_DEFAULT, buf);
+ r = H5Dread(f->dh, H5T_NATIVE_FLOAT, H5S_ALL, dataspace,
+ H5P_DEFAULT, image->dp[pi]);
if ( r < 0 ) {
ERROR("Couldn't read data for panel %s\n",
p->name);
- free(buf);
free(f_offset);
free(f_count);
return 1;
}
- H5Dclose(f->dh);
- f->data_open = 0;
- H5Sclose(dataspace);
- H5Sclose(memspace);
if ( p->mask != NULL ) {
- if ( load_mask(f, ev, p->mask, p->mask_file, p->name,
- image, p_w, sum_p_h, flags,
- f_offset, f_count, m_offset, m_count,
- hsd) ) {
- ERROR("Error loading bad pixel mask!\n");
+ int *flags = malloc(p->w*p->h*sizeof(int));
+ r = H5Dread(f->dh, H5T_NATIVE_FLOAT, H5S_ALL, dataspace,
+ H5P_DEFAULT, flags);
+ if ( r < 0 ) {
+ ERROR("Couldn't read flags for panel %s\n",
+ p->name);
+ free(f_offset);
+ free(f_count);
+ return 1;
}
+ image->bad[pi] = make_badmask(flags, p, image->det);
+ } else {
+ image->bad[pi] = calloc(p->w*p->h, sizeof(int));
}
if ( p->satmap != NULL ) {
- if ( load_satmap(f, ev, p->satmap, p->satmap_file,
- p->name, image, p_w, sum_p_h, smap,
- f_offset, f_count, m_offset, m_count,
- hsd) )
- {
- ERROR("Error loading saturation map!\n");
+ r = H5Dread(f->dh, H5T_NATIVE_FLOAT, H5S_ALL, dataspace,
+ H5P_DEFAULT, image->sat[pi]);
+ if ( r < 0 ) {
+ ERROR("Couldn't read satmap for panel %s\n",
+ p->name);
+ free(f_offset);
+ free(f_count);
+ return 1;
}
}
+ H5Sclose(dataspace);
free(f_offset);
free(f_count);
}
+ H5Dclose(f->dh);
+ f->data_open = 0;
fill_in_values(image->det, f, ev);
- unpack_panels(image, image->det, buf, flags, smap);
if ( satcorr ) debodge_saturation(f, image);
if ( image->beam != NULL ) {
@@ -1932,10 +1557,6 @@ int hdf5_read2(struct hdfile *f, struct image *image, struct event *ev,
fill_in_adu(image);
- free(buf);
- free(flags);
- free(smap);
-
return 0;
}
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index 82ad8f7e..7bb4cede 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -3,12 +3,12 @@
*
* Handle images and image features
*
- * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
* 2014 Kenneth Beyerlein <kenneth.beyerlein@desy.de>
- * 2011-2014 Thomas White <taw@physics.org>
+ * 2011-2016 Thomas White <taw@physics.org>
*
* This file is part of CrystFEL.
*
@@ -59,6 +59,7 @@ struct _imagefeaturelist
void image_add_feature(ImageFeatureList *flist, double fs, double ss,
+ struct panel *p,
struct image *parent, double intensity, const char *name)
{
if ( flist->features ) {
@@ -72,6 +73,7 @@ void image_add_feature(ImageFeatureList *flist, double fs, double ss,
flist->features[flist->n_features].fs = fs;
flist->features[flist->n_features].ss = ss;
+ flist->features[flist->n_features].p = p;
flist->features[flist->n_features].intensity = intensity;
flist->features[flist->n_features].parent = parent;
flist->features[flist->n_features].name = name;
@@ -145,27 +147,17 @@ void image_feature_list_free(ImageFeatureList *flist)
struct imagefeature *image_feature_closest(ImageFeatureList *flist,
double fs, double ss,
- double *d, int *idx,
- struct detector *det)
+ struct panel *p, double *d, int *idx)
{
int i;
double dmin = +HUGE_VAL;
int closest = 0;
- struct panel *p1;
-
- p1 = find_panel(det, fs, ss);
for ( i=0; i<flist->n_features; i++ ) {
double ds;
- struct panel *p2;
- p2 = find_panel(det, flist->features[i].fs,
- flist->features[i].ss);
-
- if ( p1 != p2 ) {
- continue;
- }
+ if ( p != flist->features[i].p ) continue;
ds = distance(flist->features[i].fs, flist->features[i].ss,
fs, ss);
@@ -189,19 +181,16 @@ struct imagefeature *image_feature_closest(ImageFeatureList *flist,
Reflection *image_reflection_closest(RefList *rlist,
- double fs, double ss,
+ double fs, double ss, struct panel *p,
struct detector *det,
double *d)
{
double dmin = HUGE_VAL;
Reflection *closest = NULL;
- struct panel *p1;
Reflection *refl;
RefListIterator *iter;
- p1 = find_panel(det, fs, ss);
-
for ( refl = first_refl(rlist, &iter);
refl != NULL;
refl = next_refl(refl, iter) )
@@ -211,12 +200,9 @@ Reflection *image_reflection_closest(RefList *rlist,
double rfs, rss;
get_detector_pos(refl, &rfs, &rss);
+ p2 = get_panel(refl);
- p2 = find_panel(det, rfs, rss);
-
- if ( p1 != p2 ) {
- continue;
- }
+ if ( p != p2 ) continue;
ds = distance(rfs, rss, fs, ss);
diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h
index ddbfc9dc..89c01785 100644
--- a/libcrystfel/src/image.h
+++ b/libcrystfel/src/image.h
@@ -3,11 +3,11 @@
*
* Handle images and image features
*
- * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2009-2013 Thomas White <taw@physics.org>
+ * 2009-2016 Thomas White <taw@physics.org>
* 2014 Valerio Mariani
*
*
@@ -73,7 +73,7 @@ struct imagefeature {
struct image *parent;
double fs;
double ss;
- char *pn;
+ struct panel *p;
double intensity;
/* Reciprocal space coordinates (m^-1 of course) of this feature */
@@ -188,9 +188,6 @@ struct image {
double div; /* Divergence in radians */
double bw; /* Bandwidth as a fraction */
- int width;
- int height;
-
/* Detected peaks */
long long int num_peaks;
long long int num_saturated_peaks;
@@ -208,6 +205,7 @@ extern ImageFeatureList *image_feature_list_new(void);
extern void image_feature_list_free(ImageFeatureList *flist);
extern void image_add_feature(ImageFeatureList *flist, double x, double y,
+ struct panel *p,
struct image *parent, double intensity,
const char *name);
@@ -215,10 +213,12 @@ extern void image_remove_feature(ImageFeatureList *flist, int idx);
extern struct imagefeature *image_feature_closest(ImageFeatureList *flist,
double fs, double ss,
- double *d, int *idx,
- struct detector *det);
+ struct panel *p,
+ double *d, int *idx);
+
extern Reflection *image_reflection_closest(RefList *rlist,
double fs, double ss,
+ struct panel *p,
struct detector *det,
double *d);
diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c
index 6b530b61..c8c86414 100644
--- a/libcrystfel/src/index.c
+++ b/libcrystfel/src/index.c
@@ -224,7 +224,8 @@ void map_all_peaks(struct image *image)
f = image_get_feature(image->features, i);
if ( f == NULL ) continue;
- r = get_q(image, f->fs, f->ss, NULL, 1.0/image->lambda);
+ r = get_q_for_panel(f->p, f->fs, f->ss,
+ NULL, 1.0/image->lambda);
f->rx = r.u; f->ry = r.v; f->rz = r.w;
}
@@ -352,7 +353,8 @@ static int delete_explained_peaks(struct image *image, Crystal *cr)
nspots++;
/* Reciprocal space position of found peak */
- q = get_q(image, f->fs, f->ss, NULL, 1.0/image->lambda);
+ q = get_q_for_panel(f->p, f->fs, f->ss,
+ NULL, 1.0/image->lambda);
/* Decimal and fractional Miller indices of nearest
* reciprocal lattice point */
diff --git a/libcrystfel/src/integration.c b/libcrystfel/src/integration.c
index 7380f836..d50f8d6b 100644
--- a/libcrystfel/src/integration.c
+++ b/libcrystfel/src/integration.c
@@ -3,11 +3,11 @@
*
* Integration of intensities
*
- * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2010-2014 Thomas White <taw@physics.org>
+ * 2010-2016 Thomas White <taw@physics.org>
*
* This file is part of CrystFEL.
*
@@ -271,8 +271,8 @@ static void show_peak_box(struct intcontext *ic, struct peak_box *bx,
get_indices(bx->refl, &h, &k, &l);
get_detector_pos(bx->refl, &fs, &ss);
/* Convert coordinates to match arrangement of panels in HDF5 file */
- fs = fs - bx->p->min_fs + bx->p->orig_min_fs;
- ss = ss - bx->p->min_ss + bx->p->orig_min_ss;
+ fs = fs + bx->p->orig_min_fs;
+ ss = ss + bx->p->orig_min_ss;
printw("Indices %i %i %i\nPanel %s\nPosition fs = %.1f, ss = %.1f\n\n",
h, k, l, bx->p->name, fs, ss);
@@ -1280,6 +1280,12 @@ static void setup_profile_boxes(struct intcontext *ic, RefList *list)
set_redundancy(refl, 0);
get_detector_pos(refl, &pfs, &pss);
+ p = get_panel(refl);
+ pn = panel_number(ic->image->det, p);
+ if ( pn == ic->image->det->n_panels ) {
+ ERROR("Couldn't find panel %p\n", p);
+ continue;
+ }
/* Explicit truncation of digits after the decimal point.
* This is actually the correct thing to do here, not
@@ -1289,12 +1295,11 @@ static void setup_profile_boxes(struct intcontext *ic, RefList *list)
* belongs to pixel index 2. */
fid_fs = pfs;
fid_ss = pss;
- pn = find_panel_number(ic->image->det, fid_fs, fid_ss);
- p = &ic->image->det->panels[pn];
- cfs = (fid_fs-p->min_fs) - ic->halfw;
- css = (fid_ss-p->min_ss) - ic->halfw;
+ cfs = fid_fs - ic->halfw;
+ css = fid_ss - ic->halfw;
+ /* Add the box */
bx = add_box(ic);
bx->refl = refl;
bx->cfs = cfs;
@@ -1414,6 +1419,12 @@ static void integrate_rings_once(Reflection *refl, struct image *image,
set_redundancy(refl, 0);
get_detector_pos(refl, &pfs, &pss);
+ p = get_panel(refl);
+ pn = panel_number(image->det, p);
+ if ( pn == image->det->n_panels ) {
+ ERROR("Couldn't find panel %p\n", p);
+ return;
+ }
/* Explicit truncation of digits after the decimal point.
* This is actually the correct thing to do here, not
@@ -1423,11 +1434,9 @@ static void integrate_rings_once(Reflection *refl, struct image *image,
* belongs to pixel index 2. */
fid_fs = pfs;
fid_ss = pss;
- pn = find_panel_number(image->det, fid_fs, fid_ss);
- p = &image->det->panels[pn];
- cfs = (fid_fs-p->min_fs) - ic->halfw;
- css = (fid_ss-p->min_ss) - ic->halfw;
+ cfs = fid_fs - ic->halfw;
+ css = fid_ss - ic->halfw;
bx = add_box(ic);
bx->refl = refl;
diff --git a/libcrystfel/src/mosflm.c b/libcrystfel/src/mosflm.c
index 8a546630..f1a1e8ae 100644
--- a/libcrystfel/src/mosflm.c
+++ b/libcrystfel/src/mosflm.c
@@ -3,13 +3,13 @@
*
* Invoke the DPS auto-indexing algorithm through MOSFLM
*
- * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
* Copyright © 2012 Richard Kirian
*
* Authors:
* 2010 Richard Kirian <rkirian@asu.edu>
- * 2010-2014 Thomas White <taw@physics.org>
+ * 2010-2016 Thomas White <taw@physics.org>
* 2014 Takanori Nakane <nakane.t@gmail.com>
*
* This file is part of CrystFEL.
@@ -373,22 +373,18 @@ static void write_spt(struct image *image, const char *filename)
for ( i=0; i<n; i++ ) {
struct imagefeature *f;
- struct panel *p;
double xs, ys, rx, ry, x, y;
f = image_get_feature(image->features, i);
if ( f == NULL ) continue;
- p = find_panel(image->det, f->fs, f->ss);
- if ( p == NULL ) continue;
+ xs = f->fs*f->p->fsx + f->ss*f->p->ssx;
+ ys = f->fs*f->p->fsy + f->ss*f->p->ssy;
+ rx = (xs + f->p->cnx) / f->p->res;
+ ry = (ys + f->p->cny) / f->p->res;
- xs = (f->fs-p->min_fs)*p->fsx + (f->ss-p->min_ss)*p->ssx;
- ys = (f->fs-p->min_fs)*p->fsy + (f->ss-p->min_ss)*p->ssy;
- rx = (xs + p->cnx) / p->res;
- ry = (ys + p->cny) / p->res;
-
- x = -rx*fclen/p->clen;
- y = ry*fclen/p->clen; /* Peak positions in m */
+ x = -rx*fclen/f->p->clen;
+ y = ry*fclen/f->p->clen; /* Peak positions in m */
fprintf(fh, "%10.2f %10.2f %10.2f %10.2f %10.2f %10.2f\n",
x*1e3, y*1e3, 0.0, 0.0, 1000.0, 10.0);
diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c
index 1b865bc8..7fc30ef7 100644
--- a/libcrystfel/src/peaks.c
+++ b/libcrystfel/src/peaks.c
@@ -3,12 +3,12 @@
*
* Peak search and other image analysis
*
- * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
* Copyright © 2012 Richard Kirian
*
* Authors:
- * 2010-2014 Thomas White <taw@physics.org>
+ * 2010-2016 Thomas White <taw@physics.org>
* 2012 Kenneth Beyerlein <kenneth.beyerlein@desy.de>
* 2011 Andrew Martin <andrew.martin@desy.de>
* 2011 Richard Kirian
@@ -69,10 +69,7 @@ static int cull_peaks_in_panel(struct image *image, struct panel *p)
f = image_get_feature(image->features, i);
if ( f == NULL ) continue;
- if ( f->fs < p->min_fs ) continue;
- if ( f->fs > p->max_fs ) continue;
- if ( f->ss < p->min_ss ) continue;
- if ( f->ss > p->max_ss ) continue;
+ if ( f->p != p ) continue;
/* How many peaks are in the same column? */
ncol = 0;
@@ -145,8 +142,7 @@ static int cull_peaks(struct image *image)
static void add_crystal_to_mask(struct image *image, struct panel *p,
- double ir_inn, int w, int h,
- int *mask, Crystal *cr)
+ double ir_inn, int *mask, Crystal *cr)
{
Reflection *refl;
RefListIterator *iter;
@@ -156,19 +152,13 @@ static void add_crystal_to_mask(struct image *image, struct panel *p,
refl != NULL;
refl = next_refl(refl, iter) )
{
- struct panel *p2;
double pk2_fs, pk2_ss;
signed int dfs, dss;
- double pk2_cfs, pk2_css;
get_detector_pos(refl, &pk2_fs, &pk2_ss);
/* Determine if reflection is in the same panel */
- p2 = find_panel(image->det, pk2_fs, pk2_ss);
- if ( p2 != p ) continue;
-
- pk2_cfs = pk2_fs - p->min_fs;
- pk2_css = pk2_ss - p->min_ss;
+ if ( get_panel(refl) != p ) continue;
for ( dfs=-ir_inn; dfs<=ir_inn; dfs++ ) {
for ( dss=-ir_inn; dss<=ir_inn; dss++ ) {
@@ -178,16 +168,16 @@ static void add_crystal_to_mask(struct image *image, struct panel *p,
/* In peak region for this peak? */
if ( dfs*dfs + dss*dss > ir_inn*ir_inn ) continue;
- fs = pk2_cfs + dfs;
- ss = pk2_css + dss;
+ fs = pk2_fs + dfs;
+ ss = pk2_ss + dss;
/* On panel? */
- if ( fs >= w ) continue;
- if ( ss >= h ) continue;
+ if ( fs >= p->w ) continue;
+ if ( ss >= p->h ) continue;
if ( fs < 0 ) continue;
if ( ss < 0 ) continue;
- mask[fs + ss*w]++;
+ mask[fs + ss*p->w]++;
}
}
@@ -200,19 +190,16 @@ static void add_crystal_to_mask(struct image *image, struct panel *p,
int *make_BgMask(struct image *image, struct panel *p, double ir_inn)
{
int *mask;
- int w, h;
int i;
- w = p->max_fs - p->min_fs + 1;
- h = p->max_ss - p->min_ss + 1;
- mask = calloc(w*h, sizeof(int));
+ mask = calloc(p->w*p->h, sizeof(int));
if ( mask == NULL ) return NULL;
if ( image->crystals == NULL ) return mask;
for ( i=0; i<image->n_crystals; i++ ) {
add_crystal_to_mask(image, p, ir_inn,
- w, h, mask, image->crystals[i]);
+ mask, image->crystals[i]);
}
return mask;
@@ -221,7 +208,8 @@ int *make_BgMask(struct image *image, struct panel *p, double ir_inn)
/* Returns non-zero if peak has been vetoed.
* i.e. don't use result if return value is not zero. */
-static int integrate_peak(struct image *image, int cfs, int css,
+static int integrate_peak(struct image *image,
+ int p_cfs, int p_css, struct panel *p,
double *pfs, double *pss,
double *intensity, double *sigma,
double ir_inn, double ir_mid, double ir_out,
@@ -234,30 +222,26 @@ static int integrate_peak(struct image *image, int cfs, int css,
double fsct, ssct;
double bg_tot = 0.0;
int bg_counts = 0;
- struct panel *p;
double bg_mean, bg_var;
double bg_tot_sq = 0.0;
double var;
double aduph;
- int p_cfs, p_css;
- signed int pn;
-
- pn = find_panel_number(image->det, cfs, css);
- if ( pn == -1 ) return 2;
- p = &image->det->panels[pn];
+ int pn;
if ( saturated != NULL ) *saturated = 0;
- /* Determine regions where there is expected to be a peak */
- p_cfs = cfs - p->min_fs;
- p_css = css - p->min_ss; /* Panel-relative coordinates */
-
aduph = p->adu_per_photon;
lim_sq = pow(ir_inn, 2.0);
mid_lim_sq = pow(ir_mid, 2.0);
out_lim_sq = pow(ir_out, 2.0);
+ pn = panel_number(image->det, p);
+ if ( pn == image->det->n_panels ) {
+ ERROR("Couldn't find panel %p\n", p);
+ return 20;
+ }
+
/* Estimate the background */
for ( dss=-ir_out; dss<=+ir_out; dss++ ) {
for ( dfs=-ir_out; dfs<=+ir_out; dfs++ ) {
@@ -328,8 +312,8 @@ static int integrate_peak(struct image *image, int cfs, int css,
pk_counts++;
pk_total += val;
- fsct += val*(cfs+dfs);
- ssct += val*(css+dss);
+ fsct += val*(p_cfs+dfs);
+ ssct += val*(p_css+dss);
}
}
@@ -462,7 +446,7 @@ static void search_peaks_in_panel(struct image *image, float threshold,
assert(mask_ss >= 0);
/* Centroid peak and get better coordinates. */
- r = integrate_peak(image, mask_fs+p->min_fs, mask_ss+p->min_ss,
+ r = integrate_peak(image, mask_fs, mask_ss, p,
&f_fs, &f_ss, &intensity, &sigma,
ir_inn, ir_mid, ir_out, &saturated);
@@ -473,8 +457,8 @@ static void search_peaks_in_panel(struct image *image, float threshold,
}
/* It is possible for the centroid to fall outside the image */
- if ( (f_fs < p->min_fs) || (f_fs > p->max_fs)
- || (f_ss < p->min_ss) || (f_ss > p->max_ss) ) {
+ if ( (f_fs < 0) || (f_fs > p->w)
+ || (f_ss < 0) || (f_ss > p->h) ) {
nrej_fra++;
continue;
}
@@ -485,8 +469,7 @@ static void search_peaks_in_panel(struct image *image, float threshold,
}
/* Check for a nearby feature */
- image_feature_closest(image->features, f_fs, f_ss, &d, &idx,
- image->det);
+ image_feature_closest(image->features, f_fs, f_ss, p, &d, &idx);
if ( d < 2.0*ir_inn ) {
nrej_pro++;
continue;
@@ -501,7 +484,7 @@ static void search_peaks_in_panel(struct image *image, float threshold,
}
/* Add using "better" coordinates */
- image_add_feature(image->features, f_fs, f_ss,
+ image_add_feature(image->features, f_fs, f_ss, p,
image, intensity, NULL);
nacc++;
@@ -578,7 +561,8 @@ int peak_sanity_check(struct image *image, Crystal **crystals, int n_cryst)
n_feat++;
/* Reciprocal space position of found peak */
- q = get_q(image, f->fs, f->ss, NULL, 1.0/image->lambda);
+ q = get_q_for_panel(f->p, f->fs, f->ss,
+ NULL, 1.0/image->lambda);
for ( j=0; j<n_cryst; j++ ) {
@@ -642,7 +626,6 @@ void validate_peaks(struct image *image, double min_snr,
int idx;
double f_fs, f_ss;
double intensity, sigma;
- struct panel *p;
int saturated;
f = image_get_feature(image->features, i);
@@ -651,13 +634,7 @@ void validate_peaks(struct image *image, double min_snr,
continue;
}
- p = find_panel(image->det, f->fs, f->ss);
- if ( p == NULL ) {
- n_wtf++;
- continue;
- }
-
- r = integrate_peak(image, f->fs, f->ss,
+ r = integrate_peak(image, f->fs, f->ss, f->p,
&f_fs, &f_ss, &intensity, &sigma,
ir_inn, ir_mid, ir_out, &saturated);
if ( r ) {
@@ -673,8 +650,8 @@ void validate_peaks(struct image *image, double min_snr,
}
/* It is possible for the centroid to fall outside the image */
- if ( (f_fs < p->min_fs) || (f_fs > p->max_fs)
- || (f_ss < p->min_ss) || (f_ss > p->max_ss) )
+ if ( (f_fs < 0) || (f_fs > f->p->w)
+ || (f_ss < 0) || (f_ss > f->p->h) )
{
n_dft++;
continue;
@@ -686,14 +663,15 @@ void validate_peaks(struct image *image, double min_snr,
}
/* Check for a nearby feature */
- image_feature_closest(flist, f_fs, f_ss, &d, &idx, image->det);
+ image_feature_closest(flist, f_fs, f_ss, f->p, &d, &idx);
if ( d < 2.0*ir_inn ) {
n_prx++;
continue;
}
/* Add using "better" coordinates */
- image_add_feature(flist, f_fs, f_ss, image, intensity, NULL);
+ image_add_feature(flist, f_fs, f_ss, f->p, image, intensity,
+ NULL);
}
diff --git a/libcrystfel/src/predict-refine.c b/libcrystfel/src/predict-refine.c
index 70345803..743b4d04 100644
--- a/libcrystfel/src/predict-refine.c
+++ b/libcrystfel/src/predict-refine.c
@@ -3,11 +3,11 @@
*
* Prediction refinement
*
- * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2010-2015 Thomas White <taw@physics.org>
+ * 2010-2016 Thomas White <taw@physics.org>
*
* This file is part of CrystFEL.
*
@@ -140,10 +140,10 @@ static void UNUSED write_pairs(const char *filename, struct reflpeak *rps,
fs = rps[i].peak->fs;
ss = rps[i].peak->ss;
+ p = rps[i].panel;
- p = find_panel(det, fs, ss);
- write_fs = fs - p->min_fs + p->orig_min_fs;
- write_ss = ss - p->min_ss + p->orig_min_ss;
+ write_fs = fs + p->orig_min_fs;
+ write_ss = ss + p->orig_min_ss;
fprintf(fh, "%7.2f %7.2f dev r,x,y: %9f %9f %9f %9f\n",
write_fs, write_ss,
@@ -229,7 +229,6 @@ static int pair_peaks(struct image *image, Crystal *cr,
struct imagefeature *f;
double h, k, l, hd, kd, ld;
Reflection *refl;
- struct panel *p;
/* Assume all image "features" are genuine peaks */
f = image_get_feature(image->features, i);
@@ -258,12 +257,11 @@ static int pair_peaks(struct image *image, Crystal *cr,
* in how far away it is from the peak location.
* The predicted position and excitation errors will be
* filled in by update_partialities(). */
- p = find_panel(image->det, f->fs, f->ss);
- set_panel(refl, p);
+ set_panel(refl, f->p);
rps[n].refl = refl;
rps[n].peak = f;
- rps[n].panel = p;
+ rps[n].panel = f->p;
n++;
}
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index dffce8f6..0d67bf8c 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -3,12 +3,12 @@
*
* Stream tools
*
- * Copyright © 2013-2015 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2013-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
* Copyright © 2012 Richard Kirian
*
* Authors:
- * 2010-2015 Thomas White <taw@physics.org>
+ * 2010-2016 Thomas White <taw@physics.org>
* 2014 Valerio Mariani
* 2011 Richard Kirian
* 2011 Andrew Aquila
@@ -106,16 +106,16 @@ static int read_peaks(FILE *fh, struct image *image)
return 1;
}
- add_x = x-p->orig_min_fs+p->min_fs;
- add_y = y-p->orig_min_ss+p->min_ss;
+ add_x = x-p->orig_min_fs;
+ add_y = y-p->orig_min_ss;
image_add_feature(image->features, add_x, add_y,
- image, intensity, NULL);
+ p, image, intensity, NULL);
} else {
image_add_feature(image->features, x, y,
- image, intensity, NULL);
+ p, image, intensity, NULL);
}
}
@@ -165,10 +165,10 @@ static int read_peaks_2_3(FILE *fh, struct image *image)
return 1;
}
- add_x = x-p->orig_min_fs+p->min_fs;
- add_y = y-p->orig_min_ss+p->min_ss;
+ add_x = x-p->orig_min_fs;
+ add_y = y-p->orig_min_ss;
- image_add_feature(image->features, add_x, add_y,
+ image_add_feature(image->features, add_x, add_y, p,
image, intensity, NULL);
}
@@ -196,7 +196,8 @@ static int write_peaks(struct image *image, FILE *ofh)
f = image_get_feature(image->features, i);
if ( f == NULL ) continue;
- r = get_q(image, f->fs, f->ss, NULL, 1.0/image->lambda);
+ r = get_q_for_panel(f->p, f->fs, f->ss,
+ NULL, 1.0/image->lambda);
q = modulus(r.u, r.v, r.w);
if ( image->det != NULL ) {
@@ -212,8 +213,8 @@ static int write_peaks(struct image *image, FILE *ofh)
/* Convert coordinates to match arrangement of panels in
* HDF5 file */
- write_fs = f->fs - p->min_fs + p->orig_min_fs;
- write_ss = f->ss - p->min_ss + p->orig_min_ss;
+ write_fs = f->fs + p->orig_min_fs;
+ write_ss = f->ss + p->orig_min_ss;
fprintf(ofh, "%7.2f %7.2f %10.2f %10.2f\n",
write_fs, write_ss, q/1.0e9, f->intensity);
@@ -244,28 +245,22 @@ static int write_peaks_2_3(struct image *image, FILE *ofh)
struct imagefeature *f;
struct rvec r;
double q;
- struct panel *p;
double write_fs, write_ss;
f = image_get_feature(image->features, i);
if ( f == NULL ) continue;
- r = get_q(image, f->fs, f->ss, NULL, 1.0/image->lambda);
+ r = get_q_for_panel(f->p, f->fs, f->ss,
+ NULL, 1.0/image->lambda);
q = modulus(r.u, r.v, r.w);
- p = find_panel(image->det, f->fs, f->ss);
- if ( p == NULL ) {
- ERROR("Panel not found\n");
- return 1;
- }
-
/* Convert coordinates to match arrangement of panels in HDF5
* file */
- write_fs = f->fs - p->min_fs + p->orig_min_fs;
- write_ss = f->ss - p->min_ss + p->orig_min_ss;
+ write_fs = f->fs + f->p->orig_min_fs;
+ write_ss = f->ss + f->p->orig_min_ss;
fprintf(ofh, "%7.2f %7.2f %10.2f %10.2f %s\n",
- write_fs, write_ss, q/1.0e9, f->intensity, p->name);
+ write_fs, write_ss, q/1.0e9, f->intensity, f->p->name);
}
@@ -328,8 +323,8 @@ static RefList *read_stream_reflections_2_3(FILE *fh, struct detector *det)
if ( p == NULL ) {
ERROR("Couldn't find panel '%s'\n", pn);
} else {
- write_fs = fs - p->orig_min_fs + p->min_fs;
- write_ss = ss - p->orig_min_ss + p->min_ss;
+ write_fs = fs - p->orig_min_fs;
+ write_ss = ss - p->orig_min_ss;
set_detector_pos(refl, write_fs, write_ss);
set_panel(refl, p);
}
@@ -406,8 +401,8 @@ static RefList *read_stream_reflections_2_1(FILE *fh, struct detector *det)
ERROR("No panel at %.2f,%.2f\n",
fs, ss);
} else {
- write_fs = fs - p->orig_min_fs + p->min_fs;
- write_ss = ss - p->orig_min_ss + p->min_ss;
+ write_fs = fs - p->orig_min_fs;
+ write_ss = ss - p->orig_min_ss;
set_detector_pos(refl, write_fs, write_ss);
}
@@ -480,8 +475,8 @@ static RefList *read_stream_reflections_2_2(FILE *fh, struct detector *det)
ERROR("No panel at %.2f,%.2f\n",
fs, ss);
} else {
- write_fs = fs - p->orig_min_fs + p->min_fs;
- write_ss = ss - p->orig_min_ss + p->min_ss;
+ write_fs = fs - p->orig_min_fs;
+ write_ss = ss - p->orig_min_ss;
set_detector_pos(refl, write_fs, write_ss);
}
@@ -555,8 +550,8 @@ static int write_stream_reflections_2_1(FILE *fh, RefList *list,
/* Convert coordinates to match arrangement of panels
* in HDF5 file */
- write_fs = fs - p->min_fs + p->orig_min_fs;
- write_ss = ss - p->min_ss + p->orig_min_ss;
+ write_fs = fs + p->orig_min_fs;
+ write_ss = ss + p->orig_min_ss;
fprintf(fh, "%3i %3i %3i %10.2f %s %10.2f %7i "
"%6.1f %6.1f\n",
@@ -617,8 +612,8 @@ static int write_stream_reflections_2_2(FILE *fh, RefList *list,
/* Convert coordinates to match arrangement of panels in HDF5
* file */
- write_fs = fs - p->min_fs + p->orig_min_fs;
- write_ss = ss - p->min_ss + p->orig_min_ss;
+ write_fs = fs + p->orig_min_fs;
+ write_ss = ss + p->orig_min_ss;
fprintf(fh, "%4i %4i %4i %10.2f %10.2f %10.2f %10.2f"
" %6.1f %6.1f\n",
@@ -654,10 +649,11 @@ static int write_stream_reflections_2_3(FILE *fh, RefList *list,
double intensity, esd_i, pk, bg;
double fs, ss;
double write_fs, write_ss;
- struct panel *p = NULL;
+ struct panel *p;
get_indices(refl, &h, &k, &l);
get_detector_pos(refl, &fs, &ss);
+ p = get_panel(refl);
intensity = get_intensity(refl);
esd_i = get_esd_intensity(refl);
pk = get_peak(refl);
@@ -666,14 +662,8 @@ static int write_stream_reflections_2_3(FILE *fh, RefList *list,
/* Reflections with redundancy = 0 are not written */
if ( get_redundancy(refl) == 0 ) continue;
- p = find_panel(image->det,fs,ss);
- if ( p == NULL ) {
- ERROR("Panel not found\n");
- return 1;
- }
-
- write_fs = fs-p->min_fs+p->orig_min_fs;
- write_ss = ss-p->min_ss+p->orig_min_ss;
+ write_fs = fs+p->orig_min_fs;
+ write_ss = ss+p->orig_min_ss;
fprintf(fh,
"%4i %4i %4i %10.2f %10.2f %10.2f %10.2f "
diff --git a/libcrystfel/src/xds.c b/libcrystfel/src/xds.c
index bda60d89..7add6904 100644
--- a/libcrystfel/src/xds.c
+++ b/libcrystfel/src/xds.c
@@ -3,12 +3,12 @@
*
* Invoke xds for crystal autoindexing
*
- * Copyright © 2013-2015 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2013-2016 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
* Copyright © 2013 Cornelius Gati
*
* Authors:
- * 2010-2015 Thomas White <taw@physics.org>
+ * 2010-2016 Thomas White <taw@physics.org>
* 2013 Cornelius Gati <cornelius.gati@cfel.de>
*
* This file is part of CrystFEL.
@@ -321,27 +321,19 @@ static void write_spot(struct image *image)
{
struct imagefeature *f;
- struct panel *p;
double xs, ys, rx, ry, x, y;
f = image_get_feature(image->features, i);
if ( f == NULL ) continue;
- p = find_panel(image->det, f->fs, f->ss);
- if ( p == NULL ) continue;
-
- xs = (f->fs-p->min_fs)*p->fsx + (f->ss-p->min_ss)*p->ssx;
- ys = (f->fs-p->min_fs)*p->fsy + (f->ss-p->min_ss)*p->ssy;
- rx = ((xs + p->cnx) / p->res);
- ry = ((ys + p->cny) / p->res);
-
- //printf("xs=%f ys=%f ----> rx=%f ry=%f\n", xs, ys, rx, ry);
+ xs = f->fs*f->p->fsx + f->ss*f->p->ssx;
+ ys = f->fs*f->p->fsy + f->ss*f->p->ssy;
+ rx = (xs + f->p->cnx) / f->p->res;
+ ry = (ys + f->p->cny) / f->p->res;
x = rx;
y = ry; /* Peak positions in m */
- //printf("x=%f y=%f\n", x, y);
-
x = (rx / 70e-6) + 1500;
y = (ry / 70e-6) + 1500;