aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-03-10 16:48:28 +0100
committerThomas White <taw@physics.org>2021-03-11 15:59:11 +0100
commitd6db66c2d57be8071465cfcac70baea4499c99df (patch)
tree96df69be8af0e959b6ed38c0bbb2a4377030bb79 /libcrystfel/src
parente79af3cbb5f02528e403488e2a3bc7902fb3f382 (diff)
detgeom_transform_coords: Take an additional detector shift
This allows the refined detector position to be used in a lot of places.
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/crystal.c2
-rw-r--r--libcrystfel/src/detgeom.c13
-rw-r--r--libcrystfel/src/detgeom.h1
-rw-r--r--libcrystfel/src/image.c2
-rw-r--r--libcrystfel/src/index.c6
-rw-r--r--libcrystfel/src/indexers/asdf.c2
-rw-r--r--libcrystfel/src/indexers/dirax.c2
-rw-r--r--libcrystfel/src/indexers/felix.c2
-rw-r--r--libcrystfel/src/indexers/mosflm.c2
-rw-r--r--libcrystfel/src/indexers/pinkindexer.c3
-rw-r--r--libcrystfel/src/indexers/taketwo.c2
-rw-r--r--libcrystfel/src/indexers/xds.c2
-rw-r--r--libcrystfel/src/indexers/xgandalf.c2
-rw-r--r--libcrystfel/src/integration.c13
-rw-r--r--libcrystfel/src/peaks.c17
-rw-r--r--libcrystfel/src/predict-refine.c7
-rw-r--r--libcrystfel/src/stream.c2
17 files changed, 52 insertions, 28 deletions
diff --git a/libcrystfel/src/crystal.c b/libcrystfel/src/crystal.c
index ebd1e6a5..c9f59bb7 100644
--- a/libcrystfel/src/crystal.c
+++ b/libcrystfel/src/crystal.c
@@ -67,7 +67,7 @@ struct _crystal
/* Text notes, which go in the stream */
char *notes;
- /* Detector shift */
+ /* Detector shift in metres */
double det_shift_x;
double det_shift_y;
};
diff --git a/libcrystfel/src/detgeom.c b/libcrystfel/src/detgeom.c
index 0ddbcbf4..5612a225 100644
--- a/libcrystfel/src/detgeom.c
+++ b/libcrystfel/src/detgeom.c
@@ -45,14 +45,15 @@
void detgeom_transform_coords(struct detgeom_panel *p,
double fs, double ss,
double wavelength,
+ double dx, double dy,
double *r)
{
double xs, ys, zs;
double fac;
/* Calculate 3D position of given position, in pixels */
- xs = p->cnx + fs*p->fsx + ss*p->ssx;
- ys = p->cny + fs*p->fsy + ss*p->ssy;
+ xs = p->cnx + fs*p->fsx + ss*p->ssx + dx*p->pixel_pitch;
+ ys = p->cny + fs*p->fsy + ss*p->ssy + dy*p->pixel_pitch;
zs = p->cnz + fs*p->fsz + ss*p->ssz;
fac = wavelength * sqrt(xs*xs + ys*ys + zs*zs);
@@ -82,16 +83,16 @@ static double panel_max_res(struct detgeom_panel *p,
double r[3];
double max_res = 0.0;
- detgeom_transform_coords(p, 0, 0, wavelength, r);
+ detgeom_transform_coords(p, 0, 0, wavelength, 0.0, 0.0, r);
max_res = biggest(max_res, modulus(r[0], r[1], r[2]));
- detgeom_transform_coords(p, 0, p->h, wavelength, r);
+ detgeom_transform_coords(p, 0, p->h, wavelength, 0.0, 0.0, r);
max_res = biggest(max_res, modulus(r[0], r[1], r[2]));
- detgeom_transform_coords(p, p->w, 0, wavelength, r);
+ detgeom_transform_coords(p, p->w, 0, wavelength, 0.0, 0.0, r);
max_res = biggest(max_res, modulus(r[0], r[1], r[2]));
- detgeom_transform_coords(p, p->w, p->h, wavelength, r);
+ detgeom_transform_coords(p, p->w, p->h, wavelength, 0.0, 0.0, r);
max_res = biggest(max_res, modulus(r[0], r[1], r[2]));
return max_res;
diff --git a/libcrystfel/src/detgeom.h b/libcrystfel/src/detgeom.h
index 255c6cfb..5e3815ac 100644
--- a/libcrystfel/src/detgeom.h
+++ b/libcrystfel/src/detgeom.h
@@ -95,6 +95,7 @@ struct detgeom
extern void detgeom_transform_coords(struct detgeom_panel *p,
double fs, double ss,
double wavelength,
+ double dx, double dy,
double *r);
extern void detgeom_free(struct detgeom *detgeom);
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index 7e4a7549..f6971b1e 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -1175,7 +1175,7 @@ void mark_resolution_range_as_bad(struct image *image,
double r;
detgeom_transform_coords(p, fs, ss,
image->lambda,
- q);
+ 0.0, 0.0, q);
r = modulus(q[0], q[1], q[2]);
if ( (r >= min) && (r <= max) ) {
image->bad[i][fs+p->w*ss] = 1;
diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c
index 62df3cd6..e0959657 100644
--- a/libcrystfel/src/index.c
+++ b/libcrystfel/src/index.c
@@ -831,6 +831,7 @@ static int delete_explained_peaks(struct image *image, Crystal *cr)
double ax, ay, az;
double bx, by, bz;
double cx, cy, cz;
+ double dx, dy;
const double min_dist = 0.25;
int i, nspots = 0, nindexed = 0;
@@ -841,6 +842,8 @@ static int delete_explained_peaks(struct image *image, Crystal *cr)
cell_get_cartesian(crystal_get_cell(cr), &ax, &ay, &az,
&bx, &by, &bz, &cx, &cy, &cz);
+ crystal_get_det_shift(cr, &dx, &dy);
+
/* Loop over peaks, checking proximity to nearest reflection */
for ( i=0; i<image_feature_count(image->features); i++ ) {
@@ -855,7 +858,8 @@ static int delete_explained_peaks(struct image *image, Crystal *cr)
/* Reciprocal space position of found peak */
detgeom_transform_coords(&image->detgeom->panels[f->pn],
- f->fs, f->ss, image->lambda, q);
+ f->fs, f->ss, image->lambda, dx, dy,
+ q);
/* Decimal and fractional Miller indices of nearest
* reciprocal lattice point */
diff --git a/libcrystfel/src/indexers/asdf.c b/libcrystfel/src/indexers/asdf.c
index af8acd78..0c57f9f0 100644
--- a/libcrystfel/src/indexers/asdf.c
+++ b/libcrystfel/src/indexers/asdf.c
@@ -1123,7 +1123,7 @@ int run_asdf(struct image *image, void *ipriv)
detgeom_transform_coords(&image->detgeom->panels[f->pn],
f->fs, f->ss, image->lambda,
- r);
+ 0.0, 0.0, r);
reflections[N_reflections] = gsl_vector_alloc(3);
gsl_vector_set(reflections[N_reflections], 0, r[0]/1e10);
diff --git a/libcrystfel/src/indexers/dirax.c b/libcrystfel/src/indexers/dirax.c
index d19cc8b0..4b59f6cb 100644
--- a/libcrystfel/src/indexers/dirax.c
+++ b/libcrystfel/src/indexers/dirax.c
@@ -497,7 +497,7 @@ static void write_drx(struct image *image)
detgeom_transform_coords(&image->detgeom->panels[f->pn],
f->fs, f->ss, image->lambda,
- r);
+ 0.0, 0.0, r);
fprintf(fh, "%10f %10f %10f %8f\n",
r[0]/1e10, r[1]/1e10, r[2]/1e10, 1.0);
diff --git a/libcrystfel/src/indexers/felix.c b/libcrystfel/src/indexers/felix.c
index de49ac0b..89de5f70 100644
--- a/libcrystfel/src/indexers/felix.c
+++ b/libcrystfel/src/indexers/felix.c
@@ -371,7 +371,7 @@ static void write_gve(struct image *image, struct felix_private *gp)
detgeom_transform_coords(&image->detgeom->panels[f->pn],
f->fs, f->ss, image->lambda,
- r);
+ 0.0, 0.0, r);
fprintf(fh, "%.6f %.6f %.6f 0 0 %.6f %.6f %.6f 0\n",
r[2]/1e10, r[0]/1e10, r[1]/1e10,
diff --git a/libcrystfel/src/indexers/mosflm.c b/libcrystfel/src/indexers/mosflm.c
index 9f674d9c..b0e0b121 100644
--- a/libcrystfel/src/indexers/mosflm.c
+++ b/libcrystfel/src/indexers/mosflm.c
@@ -364,7 +364,7 @@ static void write_spt(struct image *image, const char *filename)
detgeom_transform_coords(&image->detgeom->panels[f->pn],
f->fs, f->ss, image->lambda,
- r);
+ 0.0, 0.0, r);
ttx = angle_between_2d(0.0, 1.0,
r[0], 1.0/image->lambda + r[2]);
diff --git a/libcrystfel/src/indexers/pinkindexer.c b/libcrystfel/src/indexers/pinkindexer.c
index 03442764..6d98d3c0 100644
--- a/libcrystfel/src/indexers/pinkindexer.c
+++ b/libcrystfel/src/indexers/pinkindexer.c
@@ -112,7 +112,8 @@ int run_pinkIndexer(struct image *image, void *ipriv)
if ( f == NULL ) continue;
detgeom_transform_coords(&image->detgeom->panels[f->pn],
- f->fs, f->ss, image->lambda, r);
+ f->fs, f->ss, image->lambda,
+ 0.0, 0.0, r);
reciprocalPeaks_1_per_A->coordinates_x[reciprocalPeaks_1_per_A->peakCount] = r[2] * 1e-10;
reciprocalPeaks_1_per_A->coordinates_y[reciprocalPeaks_1_per_A->peakCount] = r[0] * 1e-10;
reciprocalPeaks_1_per_A->coordinates_z[reciprocalPeaks_1_per_A->peakCount] = r[1] * 1e-10;
diff --git a/libcrystfel/src/indexers/taketwo.c b/libcrystfel/src/indexers/taketwo.c
index 66c0d1cc..1bccf1e0 100644
--- a/libcrystfel/src/indexers/taketwo.c
+++ b/libcrystfel/src/indexers/taketwo.c
@@ -2164,7 +2164,7 @@ int taketwo_index(struct image *image, void *priv)
detgeom_transform_coords(&image->detgeom->panels[pk->pn],
pk->fs, pk->ss, image->lambda,
- r);
+ 0.0, 0.0, r);
rlps[n_rlps].u = r[0];
rlps[n_rlps].v = r[1];
diff --git a/libcrystfel/src/indexers/xds.c b/libcrystfel/src/indexers/xds.c
index c66f734a..3b2f2b87 100644
--- a/libcrystfel/src/indexers/xds.c
+++ b/libcrystfel/src/indexers/xds.c
@@ -221,7 +221,7 @@ static void write_spot(struct image *image)
detgeom_transform_coords(&image->detgeom->panels[f->pn],
f->fs, f->ss, image->lambda,
- r);
+ 0.0, 0.0, r);
ttx = angle_between_2d(0.0, 1.0,
r[0], 1.0/image->lambda + r[2]);
diff --git a/libcrystfel/src/indexers/xgandalf.c b/libcrystfel/src/indexers/xgandalf.c
index 04cd6a87..6b09f65c 100644
--- a/libcrystfel/src/indexers/xgandalf.c
+++ b/libcrystfel/src/indexers/xgandalf.c
@@ -101,7 +101,7 @@ int run_xgandalf(struct image *image, void *ipriv)
detgeom_transform_coords(&image->detgeom->panels[f->pn],
f->fs, f->ss, image->lambda,
- r);
+ 0.0, 0.0, r);
reciprocalPeaks_1_per_A->coordinates_x[reciprocalPeaks_1_per_A->peakCount] = r[0] * 1e-10;
reciprocalPeaks_1_per_A->coordinates_y[reciprocalPeaks_1_per_A->peakCount] = r[1] * 1e-10;
diff --git a/libcrystfel/src/integration.c b/libcrystfel/src/integration.c
index d88e769c..4c813a11 100644
--- a/libcrystfel/src/integration.c
+++ b/libcrystfel/src/integration.c
@@ -1518,7 +1518,7 @@ int integrate_rings_once(Reflection *refl,
}
-static double estimate_resolution(UnitCell *cell, struct image *image)
+static double estimate_resolution(Crystal *cr, struct image *image)
{
int i;
const double min_dist = 0.25;
@@ -1527,6 +1527,9 @@ static double estimate_resolution(UnitCell *cell, struct image *image)
int n_acc = 0;
int max_acc = 1024;
int n;
+ double dx, dy;
+ UnitCell *cell;
+
acc = malloc(max_acc*sizeof(double));
if ( acc == NULL ) {
@@ -1534,6 +1537,9 @@ static double estimate_resolution(UnitCell *cell, struct image *image)
return INFINITY;
}
+ cell = crystal_get_cell(cr);
+ crystal_get_det_shift(cr, &dx, &dy);
+
for ( i=0; i<image_feature_count(image->features); i++ ) {
struct imagefeature *f;
@@ -1554,7 +1560,7 @@ static double estimate_resolution(UnitCell *cell, struct image *image)
detgeom_transform_coords(&image->detgeom->panels[f->pn],
f->fs, f->ss, image->lambda,
- r);
+ dx, dy, r);
/* Decimal and fractional Miller indices of nearest
* reciprocal lattice point */
@@ -1670,8 +1676,7 @@ void integrate_all_5(struct image *image, IntegrationMethod meth,
saved_R * 5);
}
- res = estimate_resolution(crystal_get_cell(image->crystals[i]),
- image);
+ res = estimate_resolution(image->crystals[i], image);
crystal_set_resolution_limit(image->crystals[i], res);
list = predict_to_res(image->crystals[i], res+push_res);
diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c
index 685e8492..d55ddd03 100644
--- a/libcrystfel/src/peaks.c
+++ b/libcrystfel/src/peaks.c
@@ -600,15 +600,22 @@ int indexing_peak_check(struct image *image, Crystal **crystals, int n_cryst,
if ( f == NULL ) continue;
n_feat++;
- /* Reciprocal space position of found peak */
- detgeom_transform_coords(&image->detgeom->panels[f->pn],
- f->fs, f->ss, image->lambda, q);
-
for ( j=0; j<n_cryst; j++ ) {
double ax, ay, az;
double bx, by, bz;
double cx, cy, cz;
+ double dx, dy;
+
+ crystal_get_det_shift(crystals[j], &dx, &dy);
+
+ /* Reciprocal space position of found peak,
+ * based on a calculation including any updates to the
+ * detector position from the refinement of the
+ * current crystal. */
+ detgeom_transform_coords(&image->detgeom->panels[f->pn],
+ f->fs, f->ss, image->lambda,
+ dx, dy, q);
cell_get_cartesian(crystal_get_cell(crystals[j]),
&ax, &ay, &az,
@@ -748,7 +755,7 @@ double estimate_peak_resolution(ImageFeatureList *peaks, double lambda,
detgeom_transform_coords(&det->panels[f->pn],
f->fs, f->ss,
- lambda, r);
+ lambda, 0.0, 0.0, r);
rns[i] = modulus(r[0], r[1], r[2]);
}
diff --git a/libcrystfel/src/predict-refine.c b/libcrystfel/src/predict-refine.c
index 7166b3d9..2432055f 100644
--- a/libcrystfel/src/predict-refine.c
+++ b/libcrystfel/src/predict-refine.c
@@ -178,12 +178,15 @@ static int pair_peaks(struct image *image, Crystal *cr,
double ax, ay, az;
double bx, by, bz;
double cx, cy, cz;
+ double dx, dy;
RefList *all_reflist;
all_reflist = reflist_new();
cell_get_cartesian(crystal_get_cell(cr),
&ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz);
+ crystal_get_det_shift(cr, &dx, &dy);
+
/* First, create a RefList containing the most likely indices for each
* peak, with no exclusion criteria */
for ( i=0; i<image_feature_count(image->features); i++ ) {
@@ -199,7 +202,7 @@ static int pair_peaks(struct image *image, Crystal *cr,
detgeom_transform_coords(&image->detgeom->panels[f->pn],
f->fs, f->ss, image->lambda,
- r);
+ dx, dy, r);
/* Decimal and fractional Miller indices of nearest reciprocal
* lattice point */
@@ -584,6 +587,8 @@ int refine_prediction(struct image *image, Crystal *cr)
}
crystal_set_reflections(cr, reflist);
+ crystal_get_det_shift(cr, &total_x, &total_y);
+
/* Normalise the intensities to max 1 */
max_I = -INFINITY;
for ( i=0; i<n; i++ ) {
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index 3b4f033b..83756c7a 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -207,7 +207,7 @@ static int write_peaks(const struct image *image,
p = &image->detgeom->panels[f->pn];
detgeom_transform_coords(p, f->fs, f->ss,
- image->lambda, r);
+ image->lambda, 0.0, 0.0, r);
q = modulus(r[0], r[1], r[2]);
write_fs = f->fs;