/*---------------------------------------------------------------------------- File name : lwjit_offset.c Author : N. Devillard Created on : July 2000 Description : frame offset estimation for jitter imaging ---------------------------------------------------------------------------*/ /* $Id: lwjit_offset.c,v 1.6 2001/10/22 12:23:33 ndevilla Exp $ $Author: ndevilla $ $Date: 2001/10/22 12:23:33 $ $Revision: 1.6 $ */ /*---------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include "lwjit_offset.h" #include "isaacp_lib.h" /*-------------------------------------------------------------------------*/ /** @name get_offsets_from_fits_header @memo Get an offset list from the FITS headers. @param bb Jitter blackboard. @return 1 new double3 object. @doc This function is SOFI/ISAAC specific. It recovers the offset information from the input file FITS headers. The returned object must be deallocated using double3_del(). */ /*--------------------------------------------------------------------------*/ double3 * get_offsets_from_fits_header(lwjit_bb * bb) { int i, j ; double3 * ret_offs ; int n_frames ; int nobj ; char * frame_name ; char * val ; double dval ; int use_isaac_dx, use_isaac_dy ; n_frames = bb->nnod; nobj = bb->nnod ; if (!strncmp(bb->off_hdr_xkey, "isaac", 5)) { use_isaac_dx = 1 ; } else { use_isaac_dx = 0 ; } if (!strncmp(bb->off_hdr_ykey, "isaac", 5)) { use_isaac_dy = 1 ; } else { use_isaac_dy = 0 ; } ret_offs = double3_new(nobj); j=0 ; for (i=0 ; ichop_a[i] ; if (use_isaac_dx) { val = isaac_get_cumoffsetx(frame_name) ; } else { val = qfits_query_hdr(frame_name, bb->off_hdr_xkey); } if (val==NULL) { e_error("getting X offset as %s from file [%s]", bb->off_hdr_xkey,frame_name); double3_del(ret_offs) ; return NULL ; } sscanf(val, "%lg", &dval); ret_offs->x[j] = dval ; if (use_isaac_dy) { val = isaac_get_cumoffsety(frame_name); } else { val = qfits_query_hdr(frame_name, bb->off_hdr_ykey); } if (val==NULL) { e_error("getting Y offset from file [%s]", frame_name); double3_del(ret_offs) ; return NULL ; } sscanf(val, "%lg", &dval); ret_offs->y[j] = dval ; ret_offs->z[j] = 0.0 ; j++ ; } return ret_offs ; } /*-------------------------------------------------------------------------*/ /** @name jitter_dump_offsets_file @memo Dump offset information to an ASCII file. @param bb Jitter blackboard. @param offs Offsets. @param estimates Initial estimates. @return void @doc This function dumps the offset information to an ASCII file for later control. It also updates the blackboard by storing the offset errors. */ /*--------------------------------------------------------------------------*/ void jitter_dump_offsets_file( lwjit_bb * bb, double3 * offs, double3 * estimates) { FILE * offs_file ; double3 * offs_errors ; int i ; char offsfile_name[FILENAMESZ] ; int noff ; /* Build up final offset list and list of offset errors if possible */ noff = bb->nnod; offs_errors = double3_new(noff); if (estimates != NULL) { for (i=0 ; ix[i] = offs->x[i] - estimates->x[i] ; offs_errors->y[i] = offs->y[i] - estimates->y[i] ; } } else { for (i=0 ; ix[i] = 0.00 ; offs_errors->y[i] = 0.00 ; offs_errors->z[i] = -1.00 ; } } /* Write out offset information to the jitter config */ if (bb->xcorr_x == NULL) bb->xcorr_x = malloc(noff * sizeof(double)); if (bb->xcorr_y == NULL) bb->xcorr_y = malloc(noff * sizeof(double)); if (bb->xcorr_errx == NULL) bb->xcorr_errx = malloc(noff * sizeof(double)); if (bb->xcorr_erry == NULL) bb->xcorr_erry = malloc(noff * sizeof(double)); if (bb->xcorr_dist == NULL) bb->xcorr_dist = malloc(noff * sizeof(double)); for (i=0 ; ixcorr_x[i] = offs->x[i] ; bb->xcorr_y[i] = offs->y[i] ; bb->xcorr_dist[i] = offs->z[i] ; bb->xcorr_errx[i] = offs_errors->x[i] ; bb->xcorr_erry[i] = offs_errors->y[i] ; } double3_del(offs_errors) ; /* Output the offsets to a file if needed */ if (bb->off_fileoutput) { sprintf(offsfile_name, "%s_off.ascii", bb->output_basename); offs_file = fopen(offsfile_name, "w") ; if (offs_file != NULL) { fprintf(offs_file, "# offset file\n") ; fprintf(offs_file, "# plane\tdx (err)\tdy (err)\tsimilarity\n") ; for (i=0 ; ixcorr_x[i], bb->xcorr_errx[i], bb->xcorr_y[i], bb->xcorr_erry[i], bb->xcorr_dist[i]) ; } fclose(offs_file) ; } else e_warning("cannot create file %s: no offset file output", offsfile_name); } /* Print out on stderr if Debug is active, with comments */ for (i=0 ; iz[i] < -0.5) { e_error("false match for plane %d", i+1) ; } if (debug_active()) { fprintf(stderr, "from plane 1 to plane %d:\t[%5.2f\t%5.2f]\t(%5.2f)\n", i+1, offs->x[i], offs->y[i], offs->z[i]) ; } } return ; }