From 660df71395d06e7ec7d3974713db4da8ff720cd2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 5 Jun 2020 17:19:00 +0200 Subject: Convert make_pixelmap to DataTemplate NB The coffset is no longer written to the HDF5 file. This was a terrible hack anyway. The resolution field is just as bad, but as least easy to get from the detgeom. --- src/make_pixelmap.c | 133 ++++++++++++++++++++++++++-------------------------- 1 file changed, 66 insertions(+), 67 deletions(-) (limited to 'src/make_pixelmap.c') diff --git a/src/make_pixelmap.c b/src/make_pixelmap.c index 1a1ed5f3..eedcb439 100644 --- a/src/make_pixelmap.c +++ b/src/make_pixelmap.c @@ -7,7 +7,7 @@ * a research centre of the Helmholtz Association. * * Authors: - * 2012-2018 Thomas White + * 2012-2020 Thomas White * 2016-2016 Omri Mor * * This file is part of CrystFEL. @@ -41,8 +41,11 @@ #include #include #include +#include -#include "detector.h" +#include "utils.h" +#include "datatemplate.h" +#include "detgeom.h" static void show_help(const char *s) @@ -126,7 +129,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 +144,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 +173,12 @@ 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; int badmap = 0; int good_pixel_val = 1; int bad_pixel_val = 0; @@ -248,24 +250,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); + detgeom = data_template_to_detgeom(dtempl); + if ( detgeom == NULL ) { + ERROR("Could not make detector structure.\n"); + ERROR("Geometry file must not contain references to " + "image header values\n"); + return 1; + } + /* Determine max orig fs and ss */ - w = 0; h = 0; - for ( i=0; in_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 +283,59 @@ int main(int argc, char *argv[]) return 1; } + /* For every pixel in the slab ... */ for ( ss=0; ssorig_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; fspanels[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 ( data_template_in_bad_region(dtempl, pn, cfs, css) ) { + 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); + return 0; } -- cgit v1.2.3