aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-03-08 15:18:27 +0100
committerThomas White <taw@physics.org>2022-03-08 17:41:52 +0100
commitdad7c029fdfc1d0a475a86a01ecb02d2adc16dc2 (patch)
tree2e79bb418309fd9c6cd75484678fa01b374f1658 /libcrystfel
parent0b758e3ae3c3fd66c75a42740a80afbabba5c82f (diff)
Fix slabbiness assumptions
This adds a new routine, data_template_slabby_file_to_panel_coords, to be used (only!) in places where external forces require assumptions of slabbiness: pixel maps and MsgPack/HDF5 peak lists (including CXI-style). This also fixes the prototype of data_template_file_to_panel_coords to make the panel number strictly an input parameter. This was an oversight in the implementation of DataTemplate, and caused problems when reading non-slabby streams. Fixes: https://gitlab.desy.de/thomas.white/crystfel/-/issues/66
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/datatemplate.c60
-rw-r--r--libcrystfel/src/datatemplate.h6
-rw-r--r--libcrystfel/src/image-hdf5.c10
-rw-r--r--libcrystfel/src/image-msgpack.c5
-rw-r--r--libcrystfel/src/stream.c17
5 files changed, 62 insertions, 36 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index 26ff77c1..1ffa2777 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -1531,39 +1531,55 @@ void data_template_free(DataTemplate *dt)
}
-static int data_template_find_panel(const DataTemplate *dt,
- int fs, int ss, int *ppn)
+int data_template_file_to_panel_coords(const DataTemplate *dt,
+ float *pfs, float *pss,
+ int pn)
+{
+ *pfs = *pfs - dt->panels[pn].orig_min_fs;
+ *pss = *pss - dt->panels[pn].orig_min_ss;
+ return 0;
+}
+
+
+/**
+ * Convert image-data-space fs/ss coordinates to panel-relative fs/ss
+ * coordinates and panel number, assuming that the data is all in one slab.
+ *
+ * WARNING: This is probably not the routine you are looking for!
+ * If you use this routine, your code will only work with 'slabby' data, and
+ * will break for (amongst others) EuXFEL data. Use
+ * data_template_file_to_panel_coords instead, and provide the panel number.
+ *
+ * \returns 0 on success, 1 on failure
+ *
+ */
+int data_template_slabby_file_to_panel_coords(const DataTemplate *dt,
+ float *pfs, float *pss, int *ppn)
{
int p;
+ int found = 0;
for ( p=0; p<dt->n_panels; p++ ) {
- if ( (fs >= dt->panels[p].orig_min_fs)
- && (fs < dt->panels[p].orig_max_fs+1)
- && (ss >= dt->panels[p].orig_min_ss)
- && (ss < dt->panels[p].orig_max_ss+1) ) {
+ if ( (*pfs >= dt->panels[p].orig_min_fs)
+ && (*pfs < dt->panels[p].orig_max_fs+1)
+ && (*pss >= dt->panels[p].orig_min_ss)
+ && (*pss < dt->panels[p].orig_max_ss+1) )
+ {
+ if ( found ) {
+ ERROR("Panel is ambiguous for fs,ss %f,%f\n");
+ return 1;
+ }
*ppn = p;
- return 0;
+ found = 1;
}
}
- return 1;
-}
-
-
-int data_template_file_to_panel_coords(const DataTemplate *dt,
- float *pfs, float *pss,
- int *ppn)
-{
- int pn;
-
- if ( data_template_find_panel(dt, *pfs, *pss, &pn) ) {
+ if ( !found ) {
+ ERROR("Couldn't find panel for fs,ss %f,%f\n", *pfs, *pss);
return 1;
}
- *ppn = pn;
- *pfs = *pfs - dt->panels[pn].orig_min_fs;
- *pss = *pss - dt->panels[pn].orig_min_ss;
- return 0;
+ return data_template_file_to_panel_coords(dt, pfs, pss, *ppn);
}
diff --git a/libcrystfel/src/datatemplate.h b/libcrystfel/src/datatemplate.h
index 3d457f80..28cabcf5 100644
--- a/libcrystfel/src/datatemplate.h
+++ b/libcrystfel/src/datatemplate.h
@@ -76,7 +76,11 @@ extern int data_template_panel_name_to_number(const DataTemplate *dt,
extern int data_template_file_to_panel_coords(const DataTemplate *dt,
float *pfs, float *pss,
- int *pn);
+ int pn);
+
+extern int data_template_slabby_file_to_panel_coords(const DataTemplate *dt,
+ float *pfs, float *pss,
+ int *ppn);
extern int data_template_panel_to_file_coords(const DataTemplate *dt,
int pn,
diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c
index ce357f36..702c1392 100644
--- a/libcrystfel/src/image-hdf5.c
+++ b/libcrystfel/src/image-hdf5.c
@@ -1354,9 +1354,8 @@ ImageFeatureList *image_hdf5_read_peaks_cxi(const DataTemplate *dtempl,
ss = buf_y[pk] + peak_offset;
val = buf_i[pk];
- if ( data_template_file_to_panel_coords(dtempl,
- &fs, &ss,
- &pn) )
+ if ( data_template_slabby_file_to_panel_coords(dtempl,
+ &fs, &ss, &pn) )
{
ERROR("Failed to convert %i,%i to "
"panel-relative coordinates\n", fs, ss);
@@ -1477,9 +1476,8 @@ ImageFeatureList *image_hdf5_read_peaks_hdf5(const DataTemplate *dtempl,
ss = buf[tw*i+1] + peak_offset;
val = buf[tw*i+2];
- if ( data_template_file_to_panel_coords(dtempl,
- &fs, &ss,
- &pn) )
+ if ( data_template_slabby_file_to_panel_coords(dtempl,
+ &fs, &ss, &pn) )
{
ERROR("Failed to convert %i,%i to "
"panel-relative coordinates\n", fs, ss);
diff --git a/libcrystfel/src/image-msgpack.c b/libcrystfel/src/image-msgpack.c
index a92fb49d..11876b7c 100644
--- a/libcrystfel/src/image-msgpack.c
+++ b/libcrystfel/src/image-msgpack.c
@@ -216,8 +216,9 @@ ImageFeatureList *image_msgpack_read_peaks(const DataTemplate *dtempl,
val = peak_i->via.array.ptr[pk].via.f64;
/* Convert coordinates to panel-relative */
- if ( data_template_file_to_panel_coords(dtempl, &fs, &ss, &pn) ) {
- ERROR("Peak not in panel!\n");
+ if ( data_template_slabby_file_to_panel_coords(dtempl, &fs, &ss, &pn) ) {
+ ERROR("Failed to convert %i,%i to "
+ "panel-relative coordinates\n", fs, ss);
} else {
image_add_feature(features, fs, ss, pn,
NULL, val, NULL);
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index 4836d24b..1cfb4249 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -154,7 +154,7 @@ static ImageFeatureList *read_peaks(Stream *st,
} else {
data_template_file_to_panel_coords(st->dtempl_read,
- &x, &y, &pn);
+ &x, &y, pn);
image_add_feature(features, x, y,
pn, image, intensity,
@@ -269,11 +269,18 @@ static RefList *read_stream_reflections_2_3(Stream *st)
set_intensity(refl, intensity);
if ( st->dtempl_read != NULL ) {
int pn;
- if ( data_template_file_to_panel_coords(st->dtempl_read, &fs, &ss, &pn) ) {
- ERROR("Failed to convert\n");
+
+ if ( data_template_panel_name_to_number(st->dtempl_read,
+ pname, &pn) )
+ {
+ ERROR("No such panel '%s'\n", pname);
} else {
- set_detector_pos(refl, fs, ss);
- set_panel_number(refl, pn);
+ if ( data_template_file_to_panel_coords(st->dtempl_read, &fs, &ss, pn) ) {
+ ERROR("Failed to convert\n");
+ } else {
+ set_detector_pos(refl, fs, ss);
+ set_panel_number(refl, pn);
+ }
}
}
set_esd_intensity(refl, sigma);