diff options
author | Thomas White <taw@physics.org> | 2015-02-16 10:56:45 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2015-02-16 15:15:31 +0100 |
commit | 3fcc518b7efc9fb4e2e6fe95c0bdbf2d1bab035b (patch) | |
tree | b0ef3148bdb516684c3b2a6bc6cee15539965370 | |
parent | 463c7cc933e9928fa825507f1a122a5a8dc013f4 (diff) |
indexamajig: --peaks=cxi instead of --peaks=hdf5 --cxi-hdf5-peaks
-rw-r--r-- | libcrystfel/src/hdf5-file.c | 255 | ||||
-rw-r--r-- | libcrystfel/src/hdf5-file.h | 10 | ||||
-rw-r--r-- | libcrystfel/src/peaks.h | 4 | ||||
-rw-r--r-- | src/indexamajig.c | 8 | ||||
-rw-r--r-- | src/process_image.c | 18 | ||||
-rw-r--r-- | src/process_image.h | 2 |
6 files changed, 154 insertions, 143 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. * diff --git a/src/indexamajig.c b/src/indexamajig.c index 4f28aec5..627dfa67 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -97,11 +97,9 @@ static void show_help(const char *s) " zaef : Use Zaefferer (2000) gradient detection.\n" " This is the default method.\n" " hdf5 : Get from a table in HDF5 file.\n" +" cxi : Get from CXI format HDF5 file.\n" " --hdf5-peaks=<p> Find peaks table in HDF5 file here.\n" " Default: /processing/hitfinder/peakinfo\n" -" --cxi-hdf5-peaks Peaks in the HDF5 file are in CXI file format.\n" -" Only used in conjunction with the --hdf5-peaks,\n" -" ignored otherwise." " --integration=<meth> Perform final pattern integration using <meth>.\n" "\n\n" "For more control over the process, you might need:\n\n" @@ -219,7 +217,6 @@ int main(int argc, char *argv[]) iargs.peaks = PEAK_ZAEF; iargs.beam = &beam; iargs.hdf5_peak_path = strdup("/processing/hitfinder/peakinfo"); - iargs.cxi_hdf5_peaks = 0; iargs.copyme = NULL; iargs.pk_inn = -1.0; iargs.pk_mid = -1.0; @@ -271,7 +268,6 @@ int main(int argc, char *argv[]) {"no-use-saturated", 0, &iargs.use_saturated, 0}, {"no-revalidate", 0, &iargs.no_revalidate, 1}, {"check-hdf5-snr", 0, &iargs.check_hdf5_snr, 1}, - {"cxi-hdf5-peaks", 0, &iargs.cxi_hdf5_peaks, 1}, /* Long-only options which don't actually do anything */ {"no-sat-corr", 0, &iargs.satcorr, 0}, @@ -513,6 +509,8 @@ int main(int argc, char *argv[]) iargs.peaks = PEAK_ZAEF; } else if ( strcmp(speaks, "hdf5") == 0 ) { iargs.peaks = PEAK_HDF5; + } else if ( strcmp(speaks, "cxi") == 0 ) { + iargs.peaks = PEAK_CXI; } else { ERROR("Unrecognised peak detection method '%s'\n", speaks); return 1; diff --git a/src/process_image.c b/src/process_image.c index d5133a0c..847cc9f4 100644 --- a/src/process_image.c +++ b/src/process_image.c @@ -225,10 +225,7 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, switch ( iargs->peaks ) { case PEAK_HDF5: - /* Get peaks from HDF5 */ - - if ( get_peaks(&image, hdfile, iargs->hdf5_peak_path, - iargs->cxi_hdf5_peaks, pargs->filename_p_e) ) { + if ( get_peaks(&image, hdfile, iargs->hdf5_peak_path) ) { ERROR("Failed to get peaks from HDF5 file.\n"); } if ( !iargs->no_revalidate ) { @@ -239,6 +236,19 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, } break; + case PEAK_CXI: + if ( get_peaks_cxi(&image, hdfile, iargs->hdf5_peak_path, + pargs->filename_p_e) ) { + ERROR("Failed to get peaks from CXI file.\n"); + } + if ( !iargs->no_revalidate ) { + validate_peaks(&image, iargs->min_snr, + iargs->pk_inn, iargs->pk_mid, + iargs->pk_out, iargs->use_saturated, + iargs->check_hdf5_snr); + } + break; + case PEAK_ZAEF: search_peaks(&image, iargs->threshold, iargs->min_gradient, iargs->min_snr, diff --git a/src/process_image.h b/src/process_image.h index 53e2c66a..68254485 100644 --- a/src/process_image.h +++ b/src/process_image.h @@ -41,6 +41,7 @@ enum { PEAK_ZAEF, PEAK_HDF5, + PEAK_CXI, }; @@ -63,7 +64,6 @@ struct index_args float tols[4]; struct beam_params *beam; char *hdf5_peak_path; - int cxi_hdf5_peaks; float pk_inn; float pk_mid; float pk_out; |