aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2015-02-16 10:56:45 +0100
committerThomas White <taw@physics.org>2015-02-16 15:15:31 +0100
commit3fcc518b7efc9fb4e2e6fe95c0bdbf2d1bab035b (patch)
treeb0ef3148bdb516684c3b2a6bc6cee15539965370 /libcrystfel/src
parent463c7cc933e9928fa825507f1a122a5a8dc013f4 (diff)
indexamajig: --peaks=cxi instead of --peaks=hdf5 --cxi-hdf5-peaks
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/hdf5-file.c255
-rw-r--r--libcrystfel/src/hdf5-file.h10
-rw-r--r--libcrystfel/src/peaks.h4
3 files changed, 136 insertions, 133 deletions
diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c
index daaacd9f..25e700ab 100644
--- a/libcrystfel/src/hdf5-file.c
+++ b/libcrystfel/src/hdf5-file.c
@@ -378,169 +378,170 @@ static float *read_hdf5_data(struct hdfile *f, char *path, int line)
}
-int get_peaks(struct image *image, struct hdfile *f, const char *p,
- int cxi_format, struct filename_plus_event *fpe)
+/* Get peaks from HDF5, in "CXI format" (as in "CXIDB") */
+int get_peaks_cxi(struct image *image, struct hdfile *f, const char *p,
+ struct filename_plus_event *fpe)
{
- if ( cxi_format ) {
-
- char path_n[1024];
- char path_x[1024];
- char path_y[1024];
- char path_i[1024];
- int r;
- int pk;
-
- int line = 0;
- int num_peaks;
+ char path_n[1024];
+ char path_x[1024];
+ char path_y[1024];
+ char path_i[1024];
+ int r;
+ int pk;
- float *buf_x;
- float *buf_y;
- float *buf_i;
+ int line = 0;
+ int num_peaks;
- if ( (fpe != NULL) && (fpe->ev != NULL)
- && (fpe->ev->dim_entries != NULL) )
- {
- line = fpe->ev->dim_entries[0];
- } else {
- ERROR("CXI format peak list format selected,"
- "but file has no event structure");
- return 1;
- }
+ float *buf_x;
+ float *buf_y;
+ float *buf_i;
- snprintf(path_n, 1024, "%s/nPeaks", p);
- snprintf(path_x, 1024, "%s/peakXPosRaw", p);
- snprintf(path_y, 1024, "%s/peakYPosRaw", p);
- snprintf(path_i, 1024, "%s/peakTotalIntensity", p);
+ if ( (fpe != NULL) && (fpe->ev != NULL)
+ && (fpe->ev->dim_entries != NULL) )
+ {
+ line = fpe->ev->dim_entries[0];
+ } else {
+ ERROR("CXI format peak list format selected,"
+ "but file has no event structure");
+ return 1;
+ }
- r = read_peak_count(f, path_n, line, &num_peaks);
- if ( r != 0 ) return 1;
+ snprintf(path_n, 1024, "%s/nPeaks", p);
+ snprintf(path_x, 1024, "%s/peakXPosRaw", p);
+ snprintf(path_y, 1024, "%s/peakYPosRaw", p);
+ snprintf(path_i, 1024, "%s/peakTotalIntensity", p);
- buf_x = read_hdf5_data(f, path_x, line);
- if ( r != 0 ) return 1;
+ r = read_peak_count(f, path_n, line, &num_peaks);
+ if ( r != 0 ) return 1;
- buf_y = read_hdf5_data(f, path_y, line);
- if ( r != 0 ) return 1;
+ buf_x = read_hdf5_data(f, path_x, line);
+ if ( r != 0 ) return 1;
- buf_i = read_hdf5_data(f, path_i, line);
- if ( r != 0 ) return 1;
+ buf_y = read_hdf5_data(f, path_y, line);
+ if ( r != 0 ) return 1;
- if ( image->features != NULL ) {
- image_feature_list_free(image->features);
- }
- image->features = image_feature_list_new();
+ buf_i = read_hdf5_data(f, path_i, line);
+ if ( r != 0 ) return 1;
- for ( pk=0; pk<num_peaks; pk++ ) {
+ if ( image->features != NULL ) {
+ image_feature_list_free(image->features);
+ }
+ image->features = image_feature_list_new();
- float fs, ss, val;
- struct panel *p;
+ for ( pk=0; pk<num_peaks; pk++ ) {
- fs = buf_x[pk];
- ss = buf_y[pk];
- val = buf_i[pk];
+ float fs, ss, val;
+ struct panel *p;
- p = find_orig_panel(image->det, fs, ss);
- if ( p == NULL ) continue;
- if ( p->no_index ) continue;
+ fs = buf_x[pk];
+ ss = buf_y[pk];
+ val = buf_i[pk];
- /* 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;
+ p = find_orig_panel(image->det, fs, ss);
+ if ( p == NULL ) continue;
+ if ( p->no_index ) continue;
- image_add_feature(image->features, fs, ss, image,
- val, NULL);
+ /* 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;
- }
+ image_add_feature(image->features, fs, ss, image,
+ val, NULL);
- } else {
+ }
- hid_t dh, sh;
- hsize_t size[2];
- hsize_t max_size[2];
- int i;
- float *buf;
- herr_t r;
- int tw;
+ return 0;
+}
- dh = H5Dopen2(f->fh, p, H5P_DEFAULT);
- if ( dh < 0 ) {
- ERROR("Peak list (%s) not found.\n", p);
- return 1;
- }
- sh = H5Dget_space(dh);
- if ( sh < 0 ) {
- H5Dclose(dh);
- ERROR("Couldn't get dataspace for peak list.\n");
- return 1;
- }
+int get_peaks(struct image *image, struct hdfile *f, const char *p)
+{
+ hid_t dh, sh;
+ hsize_t size[2];
+ hsize_t max_size[2];
+ int i;
+ float *buf;
+ herr_t r;
+ int tw;
- if ( H5Sget_simple_extent_ndims(sh) != 2 ) {
- ERROR("Peak list has the wrong dimensionality (%i).\n",
- H5Sget_simple_extent_ndims(sh));
- H5Sclose(sh);
- H5Dclose(dh);
- return 1;
- }
+ dh = H5Dopen2(f->fh, p, H5P_DEFAULT);
+ if ( dh < 0 ) {
+ ERROR("Peak list (%s) not found.\n", p);
+ return 1;
+ }
- H5Sget_simple_extent_dims(sh, size, max_size);
+ sh = H5Dget_space(dh);
+ if ( sh < 0 ) {
+ H5Dclose(dh);
+ ERROR("Couldn't get dataspace for peak list.\n");
+ return 1;
+ }
- tw = size[1];
- if ( (tw != 3) && (tw != 4) ) {
- H5Sclose(sh);
- H5Dclose(dh);
- ERROR("Peak list has the wrong dimensions.\n");
- return 1;
- }
+ if ( H5Sget_simple_extent_ndims(sh) != 2 ) {
+ ERROR("Peak list has the wrong dimensionality (%i).\n",
+ H5Sget_simple_extent_ndims(sh));
+ H5Sclose(sh);
+ H5Dclose(dh);
+ return 1;
+ }
- buf = malloc(sizeof(float)*size[0]*size[1]);
- if ( buf == NULL ) {
- H5Sclose(sh);
- H5Dclose(dh);
- ERROR("Couldn't reserve memory for the peak list.\n");
- return 1;
- }
- r = H5Dread(dh, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
- H5P_DEFAULT, buf);
- if ( r < 0 ) {
- ERROR("Couldn't read peak list.\n");
- free(buf);
- return 1;
- }
+ H5Sget_simple_extent_dims(sh, size, max_size);
- if ( image->features != NULL ) {
- image_feature_list_free(image->features);
- }
- image->features = image_feature_list_new();
+ tw = size[1];
+ if ( (tw != 3) && (tw != 4) ) {
+ H5Sclose(sh);
+ H5Dclose(dh);
+ ERROR("Peak list has the wrong dimensions.\n");
+ return 1;
+ }
- for ( i=0; i<size[0]; i++ ) {
+ buf = malloc(sizeof(float)*size[0]*size[1]);
+ if ( buf == NULL ) {
+ H5Sclose(sh);
+ H5Dclose(dh);
+ ERROR("Couldn't reserve memory for the peak list.\n");
+ return 1;
+ }
+ r = H5Dread(dh, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
+ H5P_DEFAULT, buf);
+ if ( r < 0 ) {
+ ERROR("Couldn't read peak list.\n");
+ free(buf);
+ return 1;
+ }
- float fs, ss, val;
- struct panel *p;
+ if ( image->features != NULL ) {
+ image_feature_list_free(image->features);
+ }
+ image->features = image_feature_list_new();
- fs = buf[tw*i+0];
- ss = buf[tw*i+1];
- val = buf[tw*i+2];
+ for ( i=0; i<size[0]; i++ ) {
- p = find_orig_panel(image->det, fs, ss);
- if ( p == NULL ) continue;
- if ( p->no_index ) continue;
+ float fs, ss, val;
+ struct panel *p;
- /* 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;
+ fs = buf[tw*i+0];
+ ss = buf[tw*i+1];
+ val = buf[tw*i+2];
- image_add_feature(image->features, fs, ss, image, val,
- NULL);
+ p = find_orig_panel(image->det, fs, ss);
+ 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;
- free(buf);
- H5Sclose(sh);
- H5Dclose(dh);
+ image_add_feature(image->features, fs, ss, image, val,
+ NULL);
}
+ free(buf);
+ H5Sclose(sh);
+ H5Dclose(dh);
+
return 0;
}
diff --git a/libcrystfel/src/hdf5-file.h b/libcrystfel/src/hdf5-file.h
index 4d7b223c..2988b929 100644
--- a/libcrystfel/src/hdf5-file.h
+++ b/libcrystfel/src/hdf5-file.h
@@ -3,11 +3,11 @@
*
* Read/write HDF5 data files
*
- * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2009-2012 Thomas White <taw@physics.org>
+ * 2009-2015 Thomas White <taw@physics.org>
* 2014 Valerio Mariani
*
@@ -79,8 +79,10 @@ extern void hdfile_close(struct hdfile *f);
extern int hdfile_is_scalar(struct hdfile *f, const char *name, int verbose);
char *hdfile_get_string_value(struct hdfile *f, const char *name,
struct event* ev);
-extern int get_peaks(struct image *image, struct hdfile *f, const char *p,
- int cxi_format, struct filename_plus_event *fpe);
+extern int get_peaks(struct image *image, struct hdfile *f, const char *p);
+
+extern int get_peaks_cxi(struct image *image, struct hdfile *f, const char *p,
+ struct filename_plus_event *fpe);
extern double get_value(struct hdfile *f, const char *name);
extern double get_ev_based_value(struct hdfile *f, const char *name,
diff --git a/libcrystfel/src/peaks.h b/libcrystfel/src/peaks.h
index 9900c232..ba724419 100644
--- a/libcrystfel/src/peaks.h
+++ b/libcrystfel/src/peaks.h
@@ -3,11 +3,11 @@
*
* Peak search and other image analysis
*
- * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2010-2014 Thomas White <taw@physics.org>
+ * 2010-2015 Thomas White <taw@physics.org>
*
* This file is part of CrystFEL.
*