diff options
Diffstat (limited to 'src/make_pixelmap.c')
-rw-r--r-- | src/make_pixelmap.c | 148 |
1 files changed, 80 insertions, 68 deletions
diff --git a/src/make_pixelmap.c b/src/make_pixelmap.c index 1a1ed5f3..903f17e2 100644 --- a/src/make_pixelmap.c +++ b/src/make_pixelmap.c @@ -3,11 +3,11 @@ * * Create a pixel map file from a CrystFEL geometry description * - * Copyright © 2012-2020 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2021 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2012-2018 Thomas White <taw@physics.org> + * 2012-2021 Thomas White <taw@physics.org> * 2016-2016 Omri Mor <omor1@asu.edu> * * This file is part of CrystFEL. @@ -41,8 +41,14 @@ #include <unistd.h> #include <getopt.h> #include <assert.h> +#include <hdf5.h> -#include "detector.h" +#include <utils.h> +#include <datatemplate.h> +#include <detgeom.h> +#include <image.h> + +#include "version.h" static void show_help(const char *s) @@ -126,7 +132,7 @@ static void create_scalar(hid_t gh, const char *name, float val) static void write_pixelmap_hdf5(const char *filename, float *x, float *y, float *z, - int width, int height, float res, float coffset) + int width, int height, float res) { hid_t fh; @@ -141,7 +147,6 @@ static void write_pixelmap_hdf5(const char *filename, create_array(fh, "z", z, H5T_NATIVE_FLOAT, width, height); create_scalar(fh, "res", res); - create_scalar(fh, "coffset", coffset); H5Fclose(fh); } @@ -171,12 +176,13 @@ int main(int argc, char *argv[]) int c; char *input_file = NULL; char *output_file = NULL; - struct detector *det = NULL; + DataTemplate *dtempl; + struct detgeom *detgeom; int fs, ss, w, h; float *x, *y, *z; uint16_t *b; - int i; - float res, coffset; + float res; + struct image *image; int badmap = 0; int good_pixel_val = 1; int bad_pixel_val = 0; @@ -188,6 +194,7 @@ int main(int argc, char *argv[]) {"badmap", 0, &badmap, 1}, {"good-pixel", 1, NULL, 301}, {"bad-pixel", 1, NULL, 302}, + {"version", 0, NULL, 2}, {0, 0, NULL, 0} }; @@ -205,6 +212,13 @@ int main(int argc, char *argv[]) output_file = strdup(optarg); break; + case 2 : + printf("CrystFEL: %s\n", + crystfel_version_string()); + printf("%s\n", + crystfel_licence_string()); + return 0; + case 301: if (sscanf(optarg, "%d", &good_pixel_val) != 1) { @@ -248,24 +262,28 @@ int main(int argc, char *argv[]) } /* Load geometry */ - det = get_detector_geometry(input_file, NULL); - if ( det == NULL ) { - ERROR("Failed to read geometry from '%s'\n", input_file); + dtempl = data_template_new_from_file(input_file); + if ( dtempl == NULL ) { + ERROR("Failed to read geometry from '%s'\n", + input_file); return 1; } free(input_file); + image = image_create_for_simulation(dtempl); + if ( image == NULL ) { + ERROR("Geometry file seems to contain references to " + "image header values.\n"); + return 1; + } + detgeom = image->detgeom; + /* Determine max orig fs and ss */ - w = 0; h = 0; - for ( i=0; i<det->n_panels; i++ ) { - if ( det->panels[i].orig_max_fs > w ) { - w = det->panels[i].orig_max_fs; - } - if ( det->panels[i].orig_max_ss > h ) { - h = det->panels[i].orig_max_ss; - } + if ( data_template_get_slab_extents(dtempl, &w, &h) ) { + ERROR("Pixel map can only be created if all panels " + "have their data in one \"slab\".\n"); + return 1; } - w += 1; h += 1; /* Inclusive -> Exclusive */ STATUS("Data slab size: %i x %i\n", w, h); x = malloc(w*h*sizeof(float)); @@ -277,66 +295,60 @@ int main(int argc, char *argv[]) return 1; } + /* For every pixel in the slab ... */ for ( ss=0; ss<h; ss++ ) { - for ( fs=0; fs<w; fs++ ) { - - double rx, ry; - struct panel *p; - double xs, ys; - double cfs, css; - int nfs, nss; - - p = find_orig_panel(det, fs, ss); - - /* Add half a pixel to fs and ss to get the fs,ss - * coordinates of the CENTRE of the pixel */ - cfs = fs + 0.5; - css = ss + 0.5; - xs = (cfs - p->orig_min_fs)*p->fsx - + (css - p->orig_min_ss)*p->ssx; - ys = (cfs - p->orig_min_fs)*p->fsy - + (css - p->orig_min_ss)*p->ssy; - - rx = (xs + p->cnx) / p->res; - ry = (ys + p->cny) / p->res; - - x[fs + w*ss] = rx; - y[fs + w*ss] = ry; - z[fs + w*ss] = 0.0; /* FIXME */ - - nfs = fs - p->orig_min_fs; - nss = ss - p->orig_min_ss; - if ( in_bad_region(det, p, nfs, nss) ) { - b[fs + w*ss] = bad_pixel_val; - } else { - b[fs + w*ss] = good_pixel_val; - } + for ( fs=0; fs<w; fs++ ) { + + double rx, ry; + double xs, ys; + float cfs, css; + int pn; + struct detgeom_panel *p; + + /* Add half a pixel to fs and ss to get the fs,ss + * coordinates of the CENTRE of the pixel */ + cfs = fs + 0.5; + css = ss + 0.5; + + if ( data_template_file_to_panel_coords(dtempl, + &cfs, &css, + &pn) ) + { + ERROR("Couldn't convert coordinates\n"); + return 1; + } + + p = &detgeom->panels[pn]; + + xs = cfs*p->fsx + css*p->ssx; + ys = cfs*p->fsy + css*p->ssy; + + rx = (xs + p->cnx) * p->pixel_pitch; + ry = (ys + p->cny) * p->pixel_pitch; + x[fs + w*ss] = rx; + y[fs + w*ss] = ry; + z[fs + w*ss] = 0.0; /* 2D part only */ + + if ( image->bad[pn][fs + w*ss] ) { + b[fs + w*ss] = bad_pixel_val; + } else { + b[fs + w*ss] = good_pixel_val; } - progress_bar(ss, h, "Converting"); } - STATUS("\n"); - - res = det->defaults.res; - /* use the res of the first panel if not in global definitions - * assumes one of these exist */ - if ( res == -1.0 ) { - res = det->panels[0].res; } - coffset = det->defaults.coffset; - /* use the coffset of the first panel if not in global definitions - * assumes one of these exist*/ - if ( coffset == 0.0 ) { - coffset = det->panels[0].coffset; - } + res = 1.0 / detgeom->panels[0].pixel_pitch; if ( badmap ) { write_badmap_hdf5(output_file, b, w, h); } else { - write_pixelmap_hdf5(output_file, x, y, z, w, h, res, coffset); + write_pixelmap_hdf5(output_file, x, y, z, w, h, res); } + data_template_free(dtempl); + image_free(image); + return 0; } |