From 3fcc518b7efc9fb4e2e6fe95c0bdbf2d1bab035b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 16 Feb 2015 10:56:45 +0100 Subject: indexamajig: --peaks=cxi instead of --peaks=hdf5 --cxi-hdf5-peaks --- libcrystfel/src/hdf5-file.c | 255 ++++++++++++++++++++++---------------------- libcrystfel/src/hdf5-file.h | 10 +- libcrystfel/src/peaks.h | 4 +- 3 files changed, 136 insertions(+), 133 deletions(-) (limited to 'libcrystfel') 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; pkfeatures != NULL ) { + image_feature_list_free(image->features); + } + image->features = image_feature_list_new(); - float fs, ss, val; - struct panel *p; + for ( pk=0; pkdet, 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; ifeatures != 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; idet, 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 + * 2009-2015 Thomas White * 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 + * 2010-2015 Thomas White * * This file is part of CrystFEL. * -- cgit v1.2.3