From cf074c7d62721ce324dfac93c1c9fca45577c142 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Nov 2010 15:27:13 +0100 Subject: facetron: Initial refinement stuff --- src/facetron.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/image.h | 2 +- 2 files changed, 200 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/facetron.c b/src/facetron.c index f4148ae1..ca58ea2a 100644 --- a/src/facetron.c +++ b/src/facetron.c @@ -22,6 +22,9 @@ #include #include #include +#include +#include +#include #include "utils.h" #include "hdf5-file.h" @@ -34,6 +37,13 @@ #include "beam-parameters.h" +/* Refineable parameters */ +enum { + REF_SCALE, + NUM_PARAMS +}; + + static void show_help(const char *s) { printf("Syntax: %s [options]\n\n", s); @@ -68,11 +78,197 @@ struct refine_args }; +/* Return the gradient of parameter 'k' given the current status of 'image'. */ +static double gradient(struct image *image, int k, + struct cpeak spot, double I_partial) +{ + switch ( k ) { + + case REF_SCALE : + return I_partial; + + } + + ERROR("No gradient defined for parameter %i\n", k); + abort(); +} + + +/* Apply the given shift to the 'k'th parameter of 'image'. */ +static void apply_shift(struct image *image, int k, double shift) +{ + switch ( k ) { + + case REF_SCALE : + image->osf += shift; + break; + + default : + ERROR("No gradient defined for parameter %i\n", k); + abort(); + + } +} + + +static double mean_partial_dev(struct image *image, struct cpeak *spots, int n, + const char *sym, double *i_full) +{ + int h; + double delta_I; + + for ( h=0; hindexed_cell, &n, 0); + return mean_partial_dev(image, spots, n, sym, i_full); +} + + static void refine_image(int mytask, void *tasks) { struct refine_args *all_args = tasks; struct refine_args *pargs = &all_args[mytask]; - /* Do, er, something. */ + struct image *image = pargs->image; + double nominal_photon_energy = pargs->image->beam->photon_energy; + struct hdfile *hdfile; + struct cpeak *spots; + int n; + double dev; + + hdfile = hdfile_open(image->filename); + if ( hdfile == NULL ) { + ERROR("Couldn't open '%s'\n", image->filename); + return; + } else if ( hdfile_set_image(hdfile, "/data/data0") ) { + ERROR("Couldn't select path\n"); + hdfile_close(hdfile); + return; + } + + if ( hdf5_read(hdfile, pargs->image, 0, nominal_photon_energy) ) { + ERROR("Couldn't read '%s'\n", image->filename); + hdfile_close(hdfile); + return; + } + + spots = find_intersections(image, image->indexed_cell, &n, 0); + dev = iterate(image, pargs->i_full, pargs->sym, spots, n); + STATUS("Iteration %2i: mean dev = %5.2f\n", 0, dev); + + free(image->data); + if ( image->flags != NULL ) free(image->flags); + hdfile_close(hdfile); + + /* Muppet proofing */ + image->data = NULL; + image->flags = NULL; } @@ -114,7 +310,7 @@ static void integrate_image(int mytask, void *tasks) } /* Figure out which spots should appear in this pattern */ - spots = find_intersections(image, image->indexed_cell, &n, 0); + spots = find_intersections(image, image->indexed_cell, &n, 1); /* For each reflection, estimate the partiality */ for ( j=0; jbandwidth; images[i].det = det; images[i].beam = beam; + images[i].osf = 1.0; /* Muppet proofing */ images[i].data = NULL; diff --git a/src/image.h b/src/image.h index 6b09dfc4..ae2f3179 100644 --- a/src/image.h +++ b/src/image.h @@ -94,7 +94,6 @@ struct image { /* Information about the crystal */ double m; /* Mosaicity in radians */ - /* Per-shot radiation values */ double lambda; /* Wavelength in m */ double div; /* Divergence in radians */ @@ -102,6 +101,7 @@ struct image { double f0; /* Incident intensity */ int f0_available; /* 0 if f0 wasn't available * from the input. */ + double osf; /* Overall scaling factor */ int width; int height; -- cgit v1.2.3