Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

extract/lib/proc_mask.c

Go to the documentation of this file.
00001 /* === Doxygen Comment ======================================= */
00013 /* =========================================================== */
00014 
00015 #include <IFU_io.h>
00016 #include <IFU_math.h>
00017 #include <snifs.h>
00018 #include <extract.h>
00019 
00020 #define LIMITS_RANGE 0.2
00021 
00022 /* === Doxygen Comment ======================================= */
00026 /* =========================================================== */
00027 
00028 void norm_mask_param(Channel channel, double par[16])
00029 {
00030   /* PARAMETERS: 
00031      Collimator: f,E,lc[3]          (0,1,2..4)
00032      Camera:     f,E,lc[3]          (5,6,7..9)
00033      Grism:      A,tiltx,tilty,rotz (10,11,12,13)
00034      Center:     x,y                (14,15)
00035      => Total = 16
00036   */
00037 
00038   /* One has to divide by ABS(default) for possible negative values */
00039 
00040   switch (channel) {
00041   case BLUE_CHANNEL:
00042     par[0] /= SNIFSB_COLL_F;
00043     par[1] /= ABS(SNIFSB_COLL_E);
00044     par[2] /= ABS(SNIFSB_COLL_A1);
00045     par[3] /= ABS(SNIFSB_COLL_A2);
00046     par[4] /= ABS(SNIFSB_COLL_A3);
00047 
00048     par[5] /= SNIFSB_CAM_F;
00049     par[6] /= ABS(SNIFSB_CAM_E);
00050     par[7] /= ABS(SNIFSB_CAM_A1);
00051     par[8] /= ABS(SNIFSB_CAM_A2);
00052     par[9] /= ABS(SNIFSB_CAM_A3);
00053 
00054     par[10] /= SNIFSB_GRISM_ANG*M_PI/180.;
00055 
00056     par[14] /= CCDB_NX/2.;
00057     par[15] /= CCDB_NY/2.;
00058     break;
00059   case RED_CHANNEL:
00060     par[0] /= SNIFSR_COLL_F;
00061     par[1] /= ABS(SNIFSR_COLL_E);
00062     par[2] /= ABS(SNIFSR_COLL_A1);
00063     par[3] /= ABS(SNIFSR_COLL_A2);
00064     par[4] /= ABS(SNIFSR_COLL_A3);
00065 
00066     par[5] /= SNIFSR_CAM_F;
00067     par[6] /= ABS(SNIFSR_CAM_E);
00068     par[7] /= ABS(SNIFSR_CAM_A1);
00069     par[8] /= ABS(SNIFSR_CAM_A2);
00070     par[9] /= ABS(SNIFSR_CAM_A3);
00071 
00072     par[10] /= SNIFSR_GRISM_ANG*M_PI/180.;
00073 
00074     par[14] /= CCDR_NX/2.;
00075     par[15] /= CCDR_NY/2.;
00076     break;
00077   case UNKNOWN_CHANNEL:
00078   case NB_CHANNELS:
00079     break;
00080   }
00081 }
00082 
00083 /* === Doxygen Comment ======================================= */
00087 /* =========================================================== */
00088 
00089 void unnorm_mask_param(Channel channel, double par[16])
00090 {
00091   /* One has to divide by ABS(default) for possible negative values */
00092 
00093   switch (channel) {
00094   case BLUE_CHANNEL:
00095     par[0]  *= SNIFSB_COLL_F;
00096     par[1]  *= ABS(SNIFSB_COLL_E);
00097     par[2]  *= ABS(SNIFSB_COLL_A1);
00098     par[3]  *= ABS(SNIFSB_COLL_A2);
00099     par[4]  *= ABS(SNIFSB_COLL_A3);
00100 
00101     par[5]  *= SNIFSB_CAM_F;
00102     par[6]  *= ABS(SNIFSB_CAM_E);
00103     par[7]  *= ABS(SNIFSB_CAM_A1);
00104     par[8]  *= ABS(SNIFSB_CAM_A2);
00105     par[9]  *= ABS(SNIFSB_CAM_A3);
00106                      
00107     par[10] *= SNIFSB_GRISM_ANG*M_PI/180.;
00108                      
00109     par[14] *= CCDB_NX/2.;
00110     par[15] *= CCDB_NY/2.;
00111     break;
00112   case RED_CHANNEL:
00113     par[0]  *= SNIFSR_COLL_F;
00114     par[1]  *= ABS(SNIFSR_COLL_E);
00115     par[2]  *= ABS(SNIFSR_COLL_A1);
00116     par[3]  *= ABS(SNIFSR_COLL_A2);
00117     par[4]  *= ABS(SNIFSR_COLL_A3);
00118 
00119     par[5]  *= SNIFSR_CAM_F;
00120     par[6]  *= ABS(SNIFSR_CAM_E);
00121     par[7]  *= ABS(SNIFSR_CAM_A1);
00122     par[8]  *= ABS(SNIFSR_CAM_A2);
00123     par[9]  *= ABS(SNIFSR_CAM_A3);
00124                      
00125     par[10] *= SNIFSR_GRISM_ANG*M_PI/180.;
00126                      
00127     par[14] *= CCDR_NX/2.;
00128     par[15] *= CCDR_NY/2.;
00129     break;
00130   case UNKNOWN_CHANNEL:
00131   case NB_CHANNELS:
00132     break;
00133   }
00134 }
00135 
00136 /* === Doxygen Comment ======================================= */
00140 /* =========================================================== */
00141 
00142 void set_mask_param_limits(double par[16], double parlb[16], double parub[16])
00143 {
00144   int i;
00145 
00146   /* ===== Setting limits ============================== */
00147 
00148   print_warning("Setting mask param limits to +-%d%% (non-tilts) "
00149                 "and +-5 (tilts)",(int)(LIMITS_RANGE*100));
00150   
00151   for (i=0; i<16; i++) {
00152     if (par[i]) {
00153       parlb[i] = par[i]*((par[i]>0)? (1-LIMITS_RANGE) : (1+LIMITS_RANGE));
00154       parub[i] = par[i]*((par[i]>0)? (1+LIMITS_RANGE) : (1-LIMITS_RANGE));
00155     }
00156     else {
00157       parlb[i] = -5./180.*M_PI;
00158       parub[i] = +5./180.*M_PI;
00159     }
00160   }
00161 
00162   /* DEBUG DEBUG DEBUG */
00163   print_warning("DEBUG DEBUG DEBUG: Lateral colors coeffs kept fixed");
00164   for (i=2; i<=4; i++) parlb[i] = parub[i] = par[i];
00165   for (i=7; i<=9; i++) parlb[i] = parub[i] = par[i];
00166   /* DEBUG DEBUG DEBUG */
00167 
00168 //  /* DEBUG DEBUG DEBUG */
00169 //  print_warning("DEBUG DEBUG DEBUG: Everything but center kept fixed");
00170 //  for (i=0; i<=13; i++) parlb[i] = parub[i] = par[i];
00171 //  /* DEBUG DEBUG DEBUG */
00172 }
00173 
00174 /* === Doxygen Comment ======================================= */
00178 /* =========================================================== */
00179 
00180 void optics2mask_param(SnifsOptics *optics, double par[16])
00181 {
00182   int i;
00183 
00184   /* Collimator */
00185   par[0] = optics->collimator.focal;
00186   par[1] = optics->collimator.distor;
00187   for (i=0; i<3; i++) 
00188     par[2+i] = optics->collimator.LateralColor.coef[i];
00189 
00190   /* Camera */
00191   par[5] = optics->camera.focal;
00192   par[6] = optics->camera.distor;
00193   for (i=0; i<3; i++) 
00194     par[7+i] = optics->camera.LateralColor.coef[i];
00195 
00196   /* Grism */
00197   par[10] = optics->grism.A;
00198   par[11] = optics->grism.tiltx;
00199   par[12] = optics->grism.tilty;
00200   par[13] = optics->grism.rotz;
00201 
00202   /* Center of distortion */
00203   par[14] = optics->center.xc;
00204   par[15] = optics->center.yc;
00205 }
00206 
00207 /* === Doxygen Comment ======================================= */
00211 /* =========================================================== */
00212 
00213 void mask_param2optics(double par[16], SnifsOptics *optics)
00214 {
00215   int i;
00216 
00217   /* Collimator */
00218   optics->collimator.focal  = par[0];
00219   optics->collimator.distor = par[1];
00220   for (i=0; i<3; i++) 
00221     optics->collimator.LateralColor.coef[i] = par[2+i];
00222 
00223   /* Camera */
00224   optics->camera.focal  = par[5];
00225   optics->camera.distor = par[6];
00226   for (i=0; i<3; i++) 
00227     optics->camera.LateralColor.coef[i] = par[7+i];
00228 
00229   /* Grism */
00230   optics->grism.A     = par[10];
00231   optics->grism.tiltx = par[11];
00232   optics->grism.tilty = par[12];
00233   optics->grism.rotz  = par[13];
00234 
00235   /* Center of distortion */
00236   optics->center.xc = par[14];
00237   optics->center.yc = par[15];
00238 }
00239 
00240 /* === Doxygen Comment ======================================= */
00244 /* =========================================================== */
00245 
00246 void print_mask_param(double par[16])
00247 {
00248   print_msg("Mask parameters:");
00249   print_msg("   Collimator: f = %.3g mm, E = %.3g",par[0],par[1]);
00250   print_msg("               lc = %10.3g, %10.3g, %10.3g",par[2],par[3],par[4]);
00251   print_msg("   Camera:     f = %.3g mm, E = %.3g",par[5],par[6]);
00252   print_msg("               lc = %10.3g, %10.3g, %10.3g",par[7],par[8],par[9]);
00253   print_msg("   Grism:      A = %.3g deg",par[10]/M_PI*180);
00254   print_msg("               x = %.3g deg, y = %.3g deg, z = %.3g deg",
00255             par[11]/M_PI*180,par[12]/M_PI*180,par[13]/M_PI*180);
00256   print_msg("   Center of dist.: %.2f x %.2f",par[14],par[15]);
00257 }
00258 
00259 /* === Doxygen Comment ======================================= */
00263 /* =========================================================== */
00264 
00265 void pmpin_line(char *format, double par, double parlb, double parub)
00266 {
00267   char fmt[lg_ident+1];
00268 
00269   sprintf(fmt,"%s %s",format,(parlb==parub)? "[FIXED]":"[%.3g,%.3g]");
00270   if (parlb == parub) {
00271     if (DEBUG) print_msg(fmt,par);
00272   }
00273   else print_msg(fmt,par,parlb,parub);
00274 }
00275 
00276 /* === Doxygen Comment ======================================= */
00280 /* =========================================================== */
00281 
00282 void print_mask_param_in(double par[16], double parlb[16], double parub[16])
00283 {
00284   print_msg("Input mask parameters [limits]:");
00285   pmpin_line("   Collimator: f  = %.3g mm",par[0],parlb[0],parub[0]);
00286   pmpin_line("               E  = %.3g",par[1],parlb[1],parub[1]);
00287   pmpin_line("               lc = %10.3g",par[2],parlb[2],parub[2]);
00288   pmpin_line("                    %10.3g",par[3],parlb[3],parub[3]);
00289   pmpin_line("                    %10.3g",par[4],parlb[4],parub[4]);
00290   pmpin_line("   Camera:     f  = %.3g mm",par[5],parlb[5],parub[5]);
00291   pmpin_line("               E  = %.3g",par[6],parlb[6],parub[6]);
00292   pmpin_line("               lc = %10.3g",par[7],parlb[7],parub[7]);
00293   pmpin_line("                    %10.3g",par[8],parlb[8],parub[8]);
00294   pmpin_line("                    %10.3g",par[9],parlb[9],parub[9]);
00295   pmpin_line("   Grism:      A = %.3g deg",
00296              par[10]/M_PI*180,parlb[10]/M_PI*180,parub[10]/M_PI*180);
00297   pmpin_line("               Tilt x = %.3g deg",
00298              par[11]/M_PI*180,parlb[11]/M_PI*180,parub[11]/M_PI*180);
00299   pmpin_line("               Tilt y = %.3g deg",
00300              par[12]/M_PI*180,parlb[12]/M_PI*180,parub[12]/M_PI*180);
00301   pmpin_line("               Rot  z = %.3g deg",
00302              par[13]/M_PI*180,parlb[13]/M_PI*180,parub[13]/M_PI*180);
00303   pmpin_line("   Center of dist.: x = %.3g",par[14],parlb[14],parub[14]);
00304   pmpin_line("                    y = %.3g",par[15],parlb[15],parub[15]);
00305 }
00306 
00307 /* === Doxygen Comment ======================================= */
00311 /* =========================================================== */
00312 
00313 void pmpout_line(char *format, double par, double epar)
00314 {
00315   char fmt[lg_ident+1];
00316 
00317   sprintf(fmt,"%s %s",format,(epar==0)? "[FIXED]":"[+- %.3g]");
00318   if (epar == 0) {
00319     if (DEBUG) print_msg(fmt,par);
00320   }
00321   else print_msg(fmt,par,epar);
00322 }
00323 
00324 /* === Doxygen Comment ======================================= */
00328 /* =========================================================== */
00329 
00330 void print_mask_param_out(double par[16], double epar[16])
00331 {
00332   print_msg("Output mask parameters [errors]:");
00333   pmpout_line("   Collimator: f  = %.3g mm",par[0],epar[0]);
00334   pmpout_line("               E  = %.3g",par[1],epar[1]);
00335   pmpout_line("               lc = %10.3g",par[2],epar[2]);
00336   pmpout_line("                    %10.3g",par[3],epar[3]);
00337   pmpout_line("                    %10.3g",par[4],epar[4]);
00338   pmpout_line("   Camera:     f  = %.3g mm",par[5],epar[5]);
00339   pmpout_line("               E  = %.3g",par[6],epar[6]);
00340   pmpout_line("               lc = %10.3g",par[7],epar[7]);
00341   pmpout_line("                    %10.3g",par[8],epar[8]);
00342   pmpout_line("                    %10.3g",par[9],epar[9]);
00343   pmpout_line("   Grism:      A = %.3g deg",
00344              par[10]/M_PI*180,epar[10]/M_PI*180);
00345   pmpout_line("               Tilt x = %.3g deg",
00346              par[11]/M_PI*180,epar[11]/M_PI*180);
00347   pmpout_line("               Tilt y = %.3g deg",
00348              par[12]/M_PI*180,epar[12]/M_PI*180);
00349   pmpout_line("               Rot  z = %.3g deg",
00350              par[13]/M_PI*180,epar[13]/M_PI*180);
00351   pmpout_line("   Center of dist.: x = %.3g",par[14],epar[14]);
00352   pmpout_line("                    y = %.3g",par[15],epar[15]);
00353 }
00354 
00355 /* === Doxygen Comment ======================================= */
00364 /* =========================================================== */
00365 
00366 int open_mask(char *maskname, TABLE *mask, char *mode)
00367 {
00368   int class;
00369   
00370   print_msg("Opening mask '%s' [%s]...", maskname,mode);
00371 
00372   if (open_table(mask,maskname,mode) < 0) {
00373     print_error("Unable to open mask %s",maskname);
00374     return(ERR_OPEN);
00375   }
00376 
00377   if ((class = read_file_class(mask)) != MSK_FILE) {
00378     print_error("Wrong file class: `%s' should be an `Extraction Mask' (%d)",
00379                 maskname,class);
00380     return(ERR_BAD_TYPE);
00381   }
00382 
00383   print_msg("   '%s': %d col, %d rows (%d selected)",
00384             mask->ident,mask->col,mask->allrow,mask->row);
00385 
00386   return(OK);
00387 }
00388 
00389 /* === Doxygen Comment ======================================= */
00398 /* =========================================================== */
00399 
00400 int read_local_model(TABLE *mask, int flag, double ***coeff)
00401 {
00402   char tmpname[lg_ident+1], desc[lg_label], pref[4];
00403   int nc;                         /* Nb of coefficients in local adjustment */
00404   int i,j, col;
00405   float *farr;
00406 
00407   switch(flag) {
00408   case 1: 
00409     print_msg("Reading local adjustment to mask positions..."); 
00410     strcpy(desc,MSK_DXNC);
00411     strcpy(pref,"DX");
00412     break;
00413   case 2:
00414     print_msg("Reading cross-dispersion chromatic model from max analysis...");
00415     strcpy(desc,MSK_SIGNC);
00416     strcpy(pref,"SIG");
00417     break;
00418   default:
00419     print_error("What are you talking about?...");
00420     return(ERR_NOIMPL);
00421   }
00422 
00423   nc = 0;
00424   *coeff = NULL;
00425 
00426   if (RD_desc(mask,desc,INT,1,&nc) < 0) {
00427     print_error("Cannot find descriptor %s in mask",desc);
00428     return(ERR_NODESC);
00429   }
00430   print_msg("   %s(lambda): %d coefficients",pref,nc);
00431 
00432   farr = (float *)malloc(mask->row*sizeof(float));
00433   alloc2d(coeff,mask->row,nc,DOUBLE);
00434 
00435   for (i=0; i<nc; i++) {                /* xx0,xx1,... columns */
00436     sprintf(tmpname,"%s%d",pref,i);
00437     col = get_col_ref(mask,tmpname);
00438     if (col < 0) {
00439       print_error("Unable to read column %s from mask",tmpname);
00440       return(ERR_BAD_COL);
00441     }
00442     RD_col(mask,col,farr);             /* Read the float column */
00443     for (j=0; j<mask->row; j++) (*coeff)[j][i] = farr[j];
00444   }
00445   free(farr);
00446 
00447   return(nc);
00448 }
00449 

Generated on Tue Nov 23 18:04:19 2004 for Snifs by doxygen 1.3.3