From d004d970fc2f83e0bfd81af810fdcea35e47a4ac Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 14 Mar 2011 15:10:16 +0100 Subject: New stream writing --- src/hdf5-file.c | 18 +++---- src/image.h | 4 +- src/indexamajig.c | 37 ++++++++----- src/pattern_sim.c | 4 +- src/reflist.c | 1 + src/stream.c | 152 +++++++++++++++++++++++++++++++++++++++++++----------- src/stream.h | 14 +++++ 7 files changed, 176 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/hdf5-file.c b/src/hdf5-file.c index 20141522..eef85591 100644 --- a/src/hdf5-file.c +++ b/src/hdf5-file.c @@ -292,21 +292,21 @@ static double get_wavelength(struct hdfile *f) } -static double get_f0(struct hdfile *f) +static double get_i0(struct hdfile *f) { herr_t r; hid_t dh; - double f0; + double i0; dh = H5Dopen2(f->fh, "/LCLS/f_11_ENRC", H5P_DEFAULT); if ( dh < 0 ) return -1.0; r = H5Dread(dh, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &f0); + H5P_DEFAULT, &i0); H5Dclose(dh); if ( r < 0 ) return -1.0; - return f0; + return i0; } @@ -434,13 +434,13 @@ int hdf5_read(struct hdfile *f, struct image *image, int satcorr) /* Read wavelength from file */ image->lambda = get_wavelength(f); - image->f0 = get_f0(f); - if ( image->f0 < 0.0 ) { + image->i0 = get_i0(f); + if ( image->i0 < 0.0 ) { ERROR("Couldn't read incident intensity - using 1.0.\n"); - image->f0 = 1.0; - image->f0_available = 0; + image->i0 = 1.0; + image->i0_available = 0; } else { - image->f0_available = 1; + image->i0_available = 1; } if ( satcorr ) debodge_saturation(f, image); diff --git a/src/image.h b/src/image.h index 69c36de8..692ef7f8 100644 --- a/src/image.h +++ b/src/image.h @@ -76,8 +76,8 @@ struct image { double lambda; /* Wavelength in m */ double div; /* Divergence in radians */ double bw; /* Bandwidth as a fraction */ - double f0; /* Incident intensity */ - int f0_available; /* 0 if f0 wasn't available + double i0; /* Incident intensity */ + int i0_available; /* 0 if f0 wasn't available * from the input. */ double osf; /* Overall scaling factor */ double profile_radius; /* Radius of reflection */ diff --git a/src/indexamajig.c b/src/indexamajig.c index 72491450..320439b3 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -52,7 +52,7 @@ struct static_index_args int config_cmfilter; int config_noisefilter; int config_verbose; - int stream_flags; + int stream_flags; /* What goes into the output? */ int config_polar; int config_satcorr; int config_closer; @@ -62,7 +62,7 @@ struct static_index_args struct detector *det; IndexingMethod *indm; IndexingPrivate **ipriv; - int peaks; + int peaks; /* Peak detection method */ int cellr; struct beam_params *beam; const char *element; @@ -132,15 +132,20 @@ static void show_help(const char *s) " in the HDF5 file.\n" "\n\n" "You can control what information is included in the output stream using\n" -"' --record='. Possible flags are:\n" -"pixels Include a list of sums of pixel values within the\n" -" integration domain, correcting for individual pixel\n" -" solid angles.\n" -"integrated Include a list of reflection intensities, produced by\n" -" integrating around predicted peak locations.\n" -" The flags 'pixels' and 'integrated' are mutually exclusive.\n" -"peaks Include peak locations and intensities from the peak search.\n" -"peaksifindexed Include peak locations only if the pattern could be indexed.\n" +"' --record='. Possible flags are:\n\n" +" pixels Include a list of sums of pixel values within the\n" +" integration domain, correcting for individual pixel\n" +" solid angles.\n" +"\n" +" integrated Include a list of reflection intensities, produced by\n" +" integrating around predicted peak locations.\n" +"\n" +" peaks Include peak locations and intensities from the peak search.\n" +"\n" +" peaksifindexed As 'peaks', but only if the pattern could be indexed.\n\n" +"\n" +"The default is '--record=integrated'. The flags 'pixels' and 'integrated'\n" +"are mutually exclusive, as are the flags 'peaks' and 'peaksifindexed'.\n" "\n\n" "For more control over the process, you might need:\n\n" " --cell-reduction= Use as the cell reduction method. Choose from:\n" @@ -162,7 +167,7 @@ static void show_help(const char *s) " --min-gradient= Minimum gradient for Zaefferer peak search.\n" " Default: 100,000.\n" " -e, --image= Use this image from the HDF5 file.\n" -" Example: /data/data0." +" Example: /data/data0.\n" " Default: The first one found.\n" "\n" "\nOptions for greater performance or verbosity:\n\n" @@ -431,6 +436,7 @@ int main(int argc, char *argv[]) struct beam_params *beam = NULL; char *element = NULL; double nominal_photon_energy; + int stream_flags = STREAM_INTEGRATED; /* Long options */ const struct option longopts[] = { @@ -460,6 +466,7 @@ int main(int argc, char *argv[]) {"insane", 0, &config_insane, 1}, {"image", 1, NULL, 'e'}, {"basename", 0, &config_basename, 1}, + {"record", 1, NULL, 5}, {0, 0, NULL, 0} }; @@ -529,6 +536,11 @@ int main(int argc, char *argv[]) element = strdup(optarg); break; + case 5 : + stream_flags = parse_stream_flags(optarg); + if ( stream_flags < 0 ) return 1; + break; + case 0 : break; @@ -673,6 +685,7 @@ int main(int argc, char *argv[]) free(pdb); /* Start by writing the entire command line to stdout */ + fprintf(ofh, "CrystFEL stream format 2.0\n"); fprintf(ofh, "Command line:"); for ( i=0; ireflections, &iter); + refl != NULL; + refl = next_refl(refl, iter) ) { + + signed int h, k, l; + double intensity, esd_i, s; + + get_indices(refl, &h, &k, &l); + intensity = get_intensity(refl); + esd_i = 0.0; /* FIXME! */ + s = 0.0; /* FIXME! */ + + /* h, k, l, I, sigma(I), s */ + fprintf(ofh, "%3i %3i %3i %10.2f %s %10.2f %10.2f %7i\n", + h, k, l, intensity, " -", esd_i, s/1.0e9, 1); + + } } @@ -83,7 +165,7 @@ static void write_peaks(struct image *image, FILE *ofh) { int i; - fprintf(ofh, "Peaks from peak search in %s\n", image->filename); + fprintf(ofh, "Peaks from peak search\n"); fprintf(ofh, " x/px y/px (1/d)/nm^-1 Intensity\n"); for ( i=0; ifeatures); i++ ) { @@ -102,13 +184,10 @@ static void write_peaks(struct image *image, FILE *ofh) f->x, f->y, q/1.0e9, f->intensity); } - - fprintf(ofh, "\n"); } - -void write_chunk(FILE *ofh, struct image *image, int flags) +void write_chunk(FILE *ofh, struct image *i, int f) { double asx, asy, asz; double bsx, bsy, bsz; @@ -117,36 +196,51 @@ void write_chunk(FILE *ofh, struct image *image, int flags) fprintf(ofh, "----- Begin chunk -----\n"); - fprintf(ofh, "Image filename: %s\n", image->filename); - - cell_get_parameters(image->indexed_cell, &a, &b, &c, &al, &be, &ga); - fprintf(ofh, "Cell parameters %7.5f %7.5f %7.5f nm," - " %7.5f %7.5f %7.5f deg\n", - a*1.0e9, b*1.0e9, c*1.0e9, - rad2deg(al), rad2deg(be), rad2deg(ga)); - - cell_get_reciprocal(image->indexed_cell, &asx, &asy, &asz, - &bsx, &bsy, &bsz, - &csx, &csy, &csz); - fprintf(ofh, "astar = %+9.7f %+9.7f %+9.7f nm^-1\n", - asx/1e9, asy/1e9, asz/1e9); - fprintf(ofh, "bstar = %+9.7f %+9.7f %+9.7f nm^-1\n", - bsx/1e9, bsy/1e9, bsz/1e9); - fprintf(ofh, "cstar = %+9.7f %+9.7f %+9.7f nm^-1\n", - csx/1e9, csy/1e9, csz/1e9); - - if ( image->f0_available ) { - fprintf(ofh, "I0 = %7.5f (arbitrary gas detector units)\n", - image->f0); + fprintf(ofh, "Image filename: %s\n", i->filename); + + if ( i->indexed_cell != NULL ) { + cell_get_parameters(i->indexed_cell, &a, &b, &c, + &al, &be, &ga); + fprintf(ofh, "Cell parameters %7.5f %7.5f %7.5f nm," + " %7.5f %7.5f %7.5f deg\n", + a*1.0e9, b*1.0e9, c*1.0e9, + rad2deg(al), rad2deg(be), rad2deg(ga)); + + cell_get_reciprocal(i->indexed_cell, &asx, &asy, &asz, + &bsx, &bsy, &bsz, + &csx, &csy, &csz); + fprintf(ofh, "astar = %+9.7f %+9.7f %+9.7f nm^-1\n", + asx/1e9, asy/1e9, asz/1e9); + fprintf(ofh, "bstar = %+9.7f %+9.7f %+9.7f nm^-1\n", + bsx/1e9, bsy/1e9, bsz/1e9); + fprintf(ofh, "cstar = %+9.7f %+9.7f %+9.7f nm^-1\n", + csx/1e9, csy/1e9, csz/1e9); + + } else { + + fprintf(ofh, "No unit cell from indexing.\n"); + + } + + if ( i->i0_available ) { + fprintf(ofh, "I0 = %7.5f (arbitrary units)\n", i->i0); } else { fprintf(ofh, "I0 = invalid\n"); } fprintf(ofh, "photon_energy_eV = %f\n", - J_to_eV(ph_lambda_to_en(image->lambda))); + J_to_eV(ph_lambda_to_en(i->lambda))); + + if ( (f & STREAM_PEAKS) + || ((f & STREAM_PEAKS_IF_INDEXED) && (i->indexed_cell != NULL)) ) { + fprintf(ofh, "\n"); + write_peaks(i, ofh); + } - write_peaks(image, ofh); - write_reflections(image, ofh); + if ( (f & STREAM_PIXELS) || (f & STREAM_INTEGRATED) ) { + fprintf(ofh, "\n"); + write_reflections(i, ofh); + } fprintf(ofh, "----- End chunk -----\n\n"); } diff --git a/src/stream.h b/src/stream.h index b5f05b19..71ab4b79 100644 --- a/src/stream.h +++ b/src/stream.h @@ -19,9 +19,23 @@ struct image; +/* Possible options dictating what goes into the output stream */ +enum +{ + STREAM_NONE = 0, + STREAM_INTEGRATED = 1<<0, + STREAM_PIXELS = 1<<1, + STREAM_PEAKS = 1<<2, + STREAM_PEAKS_IF_INDEXED = 1<<3, +}; + + extern int count_patterns(FILE *fh); + extern int find_chunk(FILE *fh, UnitCell **cell, char **filename, double *ev); + extern void write_chunk(FILE *ofh, struct image *image, int flags); +extern int parse_stream_flags(const char *a); #endif /* STREAM_H */ -- cgit v1.2.3