diff options
author | Thomas White <taw@physics.org> | 2019-03-14 15:28:39 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-03-14 16:43:50 +0100 |
commit | 75d8d522008429c4973c28a2c5a770a581f5efd5 (patch) | |
tree | 25a272e522a71c9f74e843442496516f6c8cac41 | |
parent | 1449feb1f5507e79c4259ab7e122451b07d147c8 (diff) |
indexamajig: Add --no-image-data
-rw-r--r-- | src/im-zmq.c | 191 | ||||
-rw-r--r-- | src/im-zmq.h | 6 | ||||
-rw-r--r-- | src/indexamajig.c | 2 | ||||
-rw-r--r-- | src/process_image.c | 3 | ||||
-rw-r--r-- | src/process_image.h | 1 |
5 files changed, 130 insertions, 73 deletions
diff --git a/src/im-zmq.c b/src/im-zmq.c index 3efb6607..ba3d58e5 100644 --- a/src/im-zmq.c +++ b/src/im-zmq.c @@ -272,80 +272,12 @@ static void im_zmq_fill_in_beam_parameters(struct beam_params *beam, } -/* Unpacks the raw panel data from a msgpack_object, applies panel geometry, - * and stores the resulting data in an image struct. Object has structure - * { - * "corr_data": - * { - * "data": binary_data, - * "shape": [data_height, data_width], - * ... - * ... - * }, - * "key2": val2, - * ... - * ... - * } - */ -int unpack_msgpack_data(msgpack_object *obj, struct image *image) +static int unpack_slab(struct image *image, double *data, + int data_width, int data_height) { - uint16_t *flags = NULL; float *sat = NULL; int pi; - int data_width, data_height; - double *data; - msgpack_object *corr_data_obj; - msgpack_object *data_obj; - msgpack_object *shape_obj; - - if ( image->det == NULL ) { - ERROR("Geometry not available.\n"); - return 1; - } - - if ( obj == NULL ) { - ERROR("No MessagePack object!\n"); - return 1; - } - - corr_data_obj = find_msgpack_kv(obj, "corr_data"); - if ( corr_data_obj == NULL ) { - ERROR("No corr_data MessagePack object found.\n"); - return 1; - } - - data_obj = find_msgpack_kv(corr_data_obj, "data"); - if ( data_obj == NULL ) { - ERROR("No data MessagePack object found inside corr_data.\n"); - return 1; - } - if ( data_obj->type != MSGPACK_OBJECT_STR ) { - ERROR("corr_data.data isn't a binary object.\n"); - return 1; - } - data = (double *)data_obj->via.str.ptr; - - shape_obj = find_msgpack_kv(corr_data_obj, "shape"); - if ( shape_obj == NULL ) { - ERROR("No shape MessagePack object found inside corr_data.\n"); - return 1; - } - if ( shape_obj->type != MSGPACK_OBJECT_ARRAY ) { - ERROR("corr_data.shape isn't an array object.\n"); - return 1; - } - if ( shape_obj->via.array.size != 2 ) { - ERROR("corr_data.shape is wrong size (%i, should be 2)\n", - shape_obj->via.array.size); - return 1; - } - if ( shape_obj->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER ) { - ERROR("corr_data.shape contains wrong type of element.\n"); - return 1; - } - data_height = shape_obj->via.array.ptr[0].via.i64; - data_width = shape_obj->via.array.ptr[1].via.i64; image->dp = malloc(image->det->n_panels*sizeof(float *)); image->bad = malloc(image->det->n_panels*sizeof(int *)); @@ -422,6 +354,125 @@ int unpack_msgpack_data(msgpack_object *obj, struct image *image) } + return 0; +} + + +static double *find_msgpack_data(msgpack_object *obj, int *width, int *height) +{ + msgpack_object *corr_data_obj; + msgpack_object *data_obj; + msgpack_object *shape_obj; + double *data; + + corr_data_obj = find_msgpack_kv(obj, "corr_data"); + if ( corr_data_obj == NULL ) { + ERROR("No corr_data MessagePack object found.\n"); + return NULL; + } + + data_obj = find_msgpack_kv(corr_data_obj, "data"); + if ( data_obj == NULL ) { + ERROR("No data MessagePack object found inside corr_data.\n"); + return NULL; + } + if ( data_obj->type != MSGPACK_OBJECT_STR ) { + ERROR("corr_data.data isn't a binary object.\n"); + return NULL; + } + data = (double *)data_obj->via.str.ptr; + + shape_obj = find_msgpack_kv(corr_data_obj, "shape"); + if ( shape_obj == NULL ) { + ERROR("No shape MessagePack object found inside corr_data.\n"); + return NULL; + } + if ( shape_obj->type != MSGPACK_OBJECT_ARRAY ) { + ERROR("corr_data.shape isn't an array object.\n"); + return NULL; + } + if ( shape_obj->via.array.size != 2 ) { + ERROR("corr_data.shape is wrong size (%i, should be 2)\n", + shape_obj->via.array.size); + return NULL; + } + if ( shape_obj->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER ) { + ERROR("corr_data.shape contains wrong type of element.\n"); + return NULL; + } + *height = shape_obj->via.array.ptr[0].via.i64; + *width = shape_obj->via.array.ptr[1].via.i64; + return data; +} + + +static double *zero_array(struct detector *det) +{ + int max_fs = 0; + int max_ss = 0; + int pi; + double *data; + + for ( pi=0; pi<det->n_panels; pi++ ) { + if ( det->panels[pi].orig_max_fs > max_fs ) { + max_fs = det->panels[pi].orig_max_fs; + } + if ( det->panels[pi].orig_max_ss > max_ss ) { + max_ss = det->panels[pi].orig_max_ss; + } + } + + data = calloc((max_fs+1)*(max_ss+1), sizeof(double)); + return data; +} + + +/* Unpacks the raw panel data from a msgpack_object, applies panel geometry, + * and stores the resulting data in an image struct. Object has structure + * { + * "corr_data": + * { + * "data": binary_data, + * "shape": [data_height, data_width], + * ... + * ... + * }, + * "key2": val2, + * ... + * ... + * } + */ +int unpack_msgpack_data(msgpack_object *obj, struct image *image, + int no_image_data) +{ + int data_width, data_height; + double *data; + + if ( image->det == NULL ) { + ERROR("Geometry not available.\n"); + return 1; + } + + if ( obj == NULL ) { + ERROR("No MessagePack object!\n"); + return 1; + } + + if ( !no_image_data ) { + data = find_msgpack_data(obj, &data_width, &data_height); + if ( data == NULL ) { + ERROR("No image data in MessagePack object.\n"); + return 1; + } + } else { + data = zero_array(image->det); + } + + if ( unpack_slab(image, data, data_width, data_height) ) { + ERROR("Failed to unpack data slab.\n"); + return 1; + } + if ( image->beam != NULL ) { im_zmq_fill_in_beam_parameters(image->beam, image); if ( image->lambda > 1000 ) { diff --git a/src/im-zmq.h b/src/im-zmq.h index 86181347..a7cbbfe9 100644 --- a/src/im-zmq.h +++ b/src/im-zmq.h @@ -53,7 +53,8 @@ extern msgpack_object *im_zmq_fetch(struct im_zmq *z); extern int get_peaks_msgpack(msgpack_object *obj, struct image *image, int half_pixel_shift); -extern int unpack_msgpack_data(msgpack_object *obj, struct image *image); +extern int unpack_msgpack_data(msgpack_object *obj, struct image *image, + int no_image_data); #else /* defined(HAVE_MSGPACK) && defined(HAVE_ZMQ) */ @@ -68,7 +69,8 @@ static UNUSED void *im_zmq_fetch(struct im_zmq *z) { return NULL; } static UNUSED int get_peaks_msgpack(void *obj, struct image *image, int half_pixel_shift) { return 0; } -static UNUSED int unpack_msgpack_data(void *obj, struct image *image) { return 1; } +static UNUSED int unpack_msgpack_data(void *obj, struct image *image, + int no_image_data) { return 1; } #endif /* defined(HAVE_MSGPACK) && defined(HAVE_ZMQ) */ diff --git a/src/indexamajig.c b/src/indexamajig.c index 37cec295..5b2f380e 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -400,6 +400,7 @@ int main(int argc, char *argv[]) iargs.fix_bandwidth = -1.0; iargs.fix_divergence = -1.0; iargs.profile = 0; + iargs.no_image_data = 0; iargs.taketwo_opts.member_thresh = -1; iargs.taketwo_opts.len_tol = -1.0; iargs.taketwo_opts.angle_tol = -1.0; @@ -461,6 +462,7 @@ int main(int argc, char *argv[]) {"multi", 0, &if_multi, 1}, {"overpredict", 0, &iargs.overpredict, 1}, {"zmq-msgpack", 0, &zmq, 1}, + {"no-image-data", 0, &iargs.no_image_data, 1}, /* Long-only options which don't actually do anything */ {"no-sat-corr", 0, &iargs.satcorr, 0}, diff --git a/src/process_image.c b/src/process_image.c index 5ad7dea8..78dd0fc4 100644 --- a/src/process_image.c +++ b/src/process_image.c @@ -217,7 +217,8 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, image.filename = pargs->filename_p_e->filename; image.event = pargs->filename_p_e->ev; if ( pargs->msgpack_obj != NULL ) { - if ( unpack_msgpack_data(pargs->msgpack_obj, &image) ) return; + if ( unpack_msgpack_data(pargs->msgpack_obj, &image, + iargs->no_image_data) ) return; } else { if ( file_wait_open_read(sb_shared, &image, taccs, last_task, iargs->wait_for_file, cookie, diff --git a/src/process_image.h b/src/process_image.h index a606fb0e..48160bb6 100644 --- a/src/process_image.h +++ b/src/process_image.h @@ -119,6 +119,7 @@ struct index_args struct felix_options felix_opts; struct spectrum *spectrum; signed int wait_for_file; /* -1 means wait forever */ + int no_image_data; }; |