diff options
-rw-r--r-- | libcrystfel/src/detector.c | 34 | ||||
-rw-r--r-- | libcrystfel/src/detector.h | 5 | ||||
-rw-r--r-- | libcrystfel/src/hdf5-file.c | 39 | ||||
-rw-r--r-- | libcrystfel/src/hdf5-file.h | 2 | ||||
-rw-r--r-- | src/dw-hdfsee.c | 64 | ||||
-rw-r--r-- | src/process_image.c | 2 |
6 files changed, 63 insertions, 83 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c index a7829474..e17c51a0 100644 --- a/libcrystfel/src/detector.c +++ b/libcrystfel/src/detector.c @@ -497,13 +497,13 @@ static struct panel *new_panel(struct detector *det, const char *name) } /* Create a new copy of the data location if needed */ - if ( new->data_from != NULL ) { - new->data_from = strdup(new->data_from); + if ( new->data != NULL ) { + new->data = strdup(new->data); } /* Create a new copy of the bad pixel mask location */ if ( new->mask != NULL ) { - new->mask = strdup(new->data_from); + new->mask = strdup(new->mask); } return new; @@ -676,12 +676,12 @@ static int parse_field_for_panel(struct panel *panel, const char *key, panel->clen_from = NULL; } - } else if ( strcmp(key, "data_from") == 0 ) { + } else if ( strcmp(key, "data") == 0 ) { if ( strncmp(val,"/",1) != 0 ) { ERROR("Invalid data location '%s'\n", val); reject = -1; } - panel->data_from = strdup(val); + panel->data = strdup(val); } else if ( strcmp(key, "mask") == 0 ) { if ( strncmp(val,"/",1) != 0 ) { @@ -911,7 +911,7 @@ struct detector *get_detector_geometry(const char *filename) det->defaults.adu_per_eV = NAN; det->defaults.max_adu = +INFINITY; det->defaults.mask = NULL; - det->defaults.data_from = NULL; + det->defaults.data = NULL; strncpy(det->defaults.name, "", 1023); do { @@ -1100,7 +1100,7 @@ out: det->max_ss = max_ss; free(det->defaults.clen_from); - free(det->defaults.data_from); + free(det->defaults.data); free(det->defaults.mask); /* Calculate matrix inverses and other stuff */ @@ -1190,8 +1190,8 @@ struct detector *copy_geom(const struct detector *in) p->clen_from = strdup(p->clen_from); } - if ( p->data_from != NULL ) { - /* Make a copy of the data_from fields unique to this + if ( p->data != NULL ) { + /* Make a copy of the data fields unique to this * copy of the structure. */ p->clen_from = strdup(p->clen_from); } @@ -1436,9 +1436,9 @@ int write_detector_geometry(const char *filename, struct detector *det) p->name, p->rigid_group->name); } - if ( p->data_from != NULL ) { - fprintf(fh, "%s/data_from = %s\n", - p->name, p->data_from); + if ( p->data != NULL ) { + fprintf(fh, "%s/data = %s\n", + p->name, p->data); } if ( p->mask != NULL ) { @@ -1490,32 +1490,32 @@ void mark_resolution_range_as_bad(struct image *image, } -extern int single_source (struct detector *det, char *element) +extern int single_panel_data_source (struct detector *det, const char *element) { int pi; char *first_datafrom = NULL; char *curr_datafrom = NULL; - if ( det->panels[0].data_from == NULL ) { + if ( det->panels[0].data == NULL ) { if ( element != NULL ) { first_datafrom = strdup(element); } else { first_datafrom = strdup("/data/data"); } } else { - first_datafrom = strdup(det->panels[0].data_from); + first_datafrom = strdup(det->panels[0].data); } for ( pi=1;pi<det->n_panels;pi++ ) { - if ( det->panels[pi].data_from == NULL ) { + if ( det->panels[pi].data == NULL ) { if ( element != NULL ) { curr_datafrom = strdup(element); } else { curr_datafrom = strdup("/data/data"); } } else { - curr_datafrom = strdup(det->panels[pi].data_from); + curr_datafrom = strdup(det->panels[pi].data); } if ( strcmp(curr_datafrom, first_datafrom) != 0 ) { diff --git a/libcrystfel/src/detector.h b/libcrystfel/src/detector.h index 6dc398d7..9245849f 100644 --- a/libcrystfel/src/detector.h +++ b/libcrystfel/src/detector.h @@ -87,7 +87,7 @@ struct panel struct rigid_group *rigid_group; /* Rigid group */ double adu_per_eV; /* Number of ADU per eV */ double max_adu; /* Treat pixel as unreliable if higher than this */ - char *data_from; + char *data; double fsx; double fsy; @@ -209,7 +209,8 @@ extern int write_detector_geometry(const char *filename, struct detector *det); extern void mark_resolution_range_as_bad(struct image *image, double min, double max); -extern int single_source (struct detector *det, char *element); + +extern int single_panel_data_source (struct detector *det, const char *element); #ifdef __cplusplus diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c index 3f90117d..a0fa8866 100644 --- a/libcrystfel/src/hdf5-file.c +++ b/libcrystfel/src/hdf5-file.c @@ -365,8 +365,8 @@ int hdf5_write_image(const char *filename, struct image *image, char *element) } locations[0].max_ss = 0; locations[0].max_fs = 0; - if ( image->det->panels[0].data_from != NULL ) { - locations[0].location = image->det->panels[0].data_from; + if ( image->det->panels[0].data != NULL ) { + locations[0].location = image->det->panels[0].data; } else { locations[0].location = default_location; } @@ -383,10 +383,10 @@ int hdf5_write_image(const char *filename, struct image *image, char *element) p = image->det->panels[pi]; - if ( p.data_from == NULL ) { + if ( p.data == NULL ) { p_location = default_location; } else { - p_location = p.data_from; + p_location = p.data; } panel_processed = 0; @@ -846,6 +846,12 @@ static int unpack_panels(struct image *image, struct detector *det) int hdf5_read(struct hdfile *f, struct image *image, const char* element, int satcorr) { + return hdf5_read2(f, image, element, satcorr, 0); +} + + +int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int satcorr, int override_data_and_mask) +{ herr_t r; float *buf; uint16_t *flags; @@ -857,6 +863,7 @@ int hdf5_read(struct hdfile *f, struct image *image, const char* element, int sa int pi; hid_t mask_dh = NULL; + if ( image->det == NULL ) { ERROR("Geometry not available\n"); return 1; @@ -908,12 +915,16 @@ int hdf5_read(struct hdfile *f, struct image *image, const char* element, int sa if ( p->orig_min_ss == -1 ) p->orig_min_ss = p->min_ss; if ( p->orig_max_ss == -1 ) p->orig_max_ss = p->max_ss; - if ( p->data_from != NULL ) { - fail = hdfile_set_image(f, p->data_from); - } else if ( element != NULL ) { + if ( override_data_and_mask ) { fail = hdfile_set_image(f, element); } else { - fail = hdfile_set_first_image(f,"/"); + if ( p->data != NULL ) { + fail = hdfile_set_image(f, p->data); + } else if ( element != NULL ) { + fail = hdfile_set_image(f, element); + } else { + fail = hdfile_set_first_image(f,"/"); + } } if ( fail ) { ERROR("Couldn't select path for panel %s\n", @@ -974,10 +985,8 @@ int hdf5_read(struct hdfile *f, struct image *image, const char* element, int sa H5Dclose(f->dh); f->data_open = 0; H5Sclose(dataspace); - H5Sclose(memspace); if ( p->mask != NULL ) { - mask_dh = H5Dopen2(f->fh, p->mask, H5P_DEFAULT); if ( mask_dh <= 0 ) { ERROR("Couldn't open flags for panel %s\n", @@ -985,7 +994,7 @@ int hdf5_read(struct hdfile *f, struct image *image, const char* element, int sa image->flags = NULL; } else { - mask_dataspace = H5Dget_space(H5Dget_space(mask_dh)); + mask_dataspace = H5Dget_space(mask_dh); check = H5Sselect_hyperslab(mask_dataspace, H5S_SELECT_SET, f_offset, NULL, f_count, NULL); if ( check < 0 ) { @@ -1000,12 +1009,16 @@ int hdf5_read(struct hdfile *f, struct image *image, const char* element, int sa } else { no_mask_loaded = 0; } - H5Dclose(mask_dataspace); + + H5Sclose(mask_dataspace); H5Dclose(mask_dh); - } + + } } + H5Sclose(memspace); + p->min_fs = m_min_fs; p->max_fs = m_max_fs; p->min_ss = curr_ss; diff --git a/libcrystfel/src/hdf5-file.h b/libcrystfel/src/hdf5-file.h index 1cac71a5..b5159fcf 100644 --- a/libcrystfel/src/hdf5-file.h +++ b/libcrystfel/src/hdf5-file.h @@ -52,6 +52,8 @@ extern int hdf5_write_image(const char *filename, struct image *image, char *ele extern int hdf5_read(struct hdfile *f, struct image *image, const char *element, int satcorr); +extern int hdf5_read2(struct hdfile *f, struct image *image, const char* element, int satcorr, int override_data_and_mask); + extern struct hdfile *hdfile_open(const char *filename); extern int hdfile_set_image(struct hdfile *f, const char *path); extern int16_t *hdfile_get_image_binned(struct hdfile *hdfile, diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 68e1b0a9..17c547b8 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -1756,16 +1756,6 @@ static void displaywindow_addmenubar(DisplayWindow *dw, GtkWidget *vbox, } - -//static int geometry_fits(struct image *image, struct detector *geom) -//{ -// if ( (1+geom->max_fs != image->width) -// || (1+geom->max_ss != image->height) ) return 0; - -// return 1; -//} - - static void do_filters(DisplayWindow *dw) { if ( dw->median_filter > 0 ) { @@ -1787,53 +1777,19 @@ struct newhdf { static gint displaywindow_newhdf(GtkMenuItem *item, struct newhdf *nh) { gboolean a; + int fail; if ( nh->dw->not_ready_yet ) return 0; a = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(nh->widget)); if ( !a ) return 0; - - hdf5_read(nh->dw->hdfile, nh->dw->image, nh->name, 0); - -// /* Check that the geometry still fits */ -// if ( !geometry_fits(nh->dw->image, nh->dw->simple_geom) ) { -// int using = 0; -// if ( nh->dw->simple_geom == nh->dw->image->det ) { -// using = 1; -// } -// free_detector_geometry(nh->dw->simple_geom); -// nh->dw->simple_geom = simple_geometry(nh->dw->image); -// if ( using ) { -// nh->dw->image->det = nh->dw->simple_geom; -// } -// } - -// if ( (nh->dw->loaded_geom != NULL ) -// && (!geometry_fits(nh->dw->image, nh->dw->loaded_geom)) ) { - -// GtkWidget *w; - -// free_detector_geometry(nh->dw->loaded_geom); -// nh->dw->loaded_geom = NULL; - -// /* Force out of "use geometry" mode */ -// w = gtk_ui_manager_get_widget(nh->dw->ui, -// "/ui/displaywindow/view/usegeom"); -// gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE); -// gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), FALSE); -// nh->dw->use_geom = 0; -// nh->dw->image->det = nh->dw->simple_geom; - -// } - -// if ( nh->dw->use_geom ) { -// nh->dw->image->det = nh->dw->loaded_geom; -// } else { -// nh->dw->image->det = nh->dw->simple_geom; -// } + fail = hdf5_read2(nh->dw->hdfile, nh->dw->image, nh->name, 0, 1); + if ( fail ) { + ERROR("Coun't load image"); + return 1; + } do_filters(nh->dw); - displaywindow_update(nh->dw); return 0; } @@ -2430,6 +2386,7 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, char *title; GtkWidget *vbox; int check; + GtkWidget *w; dw = calloc(1, sizeof(DisplayWindow)); if ( dw == NULL ) return NULL; @@ -2536,6 +2493,13 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks, gtk_window_set_resizable(GTK_WINDOW(dw->window), TRUE); gtk_widget_show_all(dw->window); + w = gtk_ui_manager_get_widget(dw->ui, + "/ui/displaywindow/view/images"); + + if ( !single_panel_data_source(dw->image->det, element) ) { + gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE); + } + displaywindow_update(dw); gtk_widget_add_events(GTK_WIDGET(dw->drawingarea), diff --git a/src/process_image.c b/src/process_image.c index 71c73357..914d79f3 100644 --- a/src/process_image.c +++ b/src/process_image.c @@ -104,7 +104,7 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, case PEAK_HDF5: /* Get peaks from HDF5 */ - if ( !single_source(iargs->det, iargs->element)) { + if ( !single_panel_data_source(iargs->det, iargs->element) ) { ERROR("Peaks from HDF5 file not supported with multiple panel data sources.\n"); } |