sinfo_utl_cube_create.c

00001 /* $Id: sinfo_utl_cube_create.c,v 1.5 2008/08/29 11:34:03 amodigli Exp $
00002  *
00003  * This file is part of the SINFONI Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: amodigli $
00023  * $Date: 2008/08/29 11:34:03 $
00024  * $Revision: 1.5 $
00025  * $Name: HEAD $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  ----------------------------------------------------------------------------*/
00035 
00036 
00037 /* cpl */
00038 #include <cpl.h>
00039 
00040 /* irplib */
00041 #include <irplib_utils.h>
00042 
00043 #include <sinfo_tpl_utils.h>
00044 #include <sinfo_pfits.h>
00045 #include <sinfo_tpl_dfs.h>
00046 #include <sinfo_msg.h>
00047 #include <sinfo_error.h>
00048 #include <sinfo_utils_wrappers.h>
00049 #include <sinfo_image_ops.h>
00050 #include <sinfo_wave_calibration.h>
00051 #include <sinfo_pro_save.h>
00052 #include <sinfo_raw_types.h>
00053 #include <sinfo_pro_types.h>
00054 #include <sinfo_coltilt.h>
00055 #include <sinfo_utilities_scired.h>
00056 /*-----------------------------------------------------------------------------
00057                             Functions prototypes
00058  ----------------------------------------------------------------------------*/
00059 
00060 static int sinfo_utl_cube_create_create(cpl_plugin *) ;
00061 static int sinfo_utl_cube_create_exec(cpl_plugin *) ;
00062 static int sinfo_utl_cube_create_destroy(cpl_plugin *) ;
00063 
00064 static int 
00065 sinfo_cube_create(cpl_parameterlist * parameters, cpl_frameset * frames);
00066 
00067 /*-----------------------------------------------------------------------------
00068                             Static variables
00069  ----------------------------------------------------------------------------*/
00070 
00071 static char sinfo_utl_cube_create_description[] =
00072 "This recipe perform cubes creation.\n"
00073 "The input files are:\n"
00074 "A raw frame on tagged as RAW_ON\n"
00075 "[optional] A raw frame off RAW_OFF\n"
00076 "A wavelength map, tagged as WAVE_MAP\n"
00077 "A wavelength map, tagged as WAVE_MAP\n"
00078 "A distortion table, tagged as DISTORTION\n"
00079 "A slitlets position table, tagged as SLIT_POS\n"
00080 "Information on relevant parameters can be found with\n"
00081 "esorex --params sinfo_utl_cube_create\n"
00082 "esorex --help sinfo_utl_cube_create\n"
00083 "\n";
00084 
00085 /*-----------------------------------------------------------------------------
00086                                 Functions code
00087  ----------------------------------------------------------------------------*/
00088 /*---------------------------------------------------------------------------*/
00092 /*---------------------------------------------------------------------------*/
00093 
00095 /*---------------------------------------------------------------------------*/
00103 /*---------------------------------------------------------------------------*/
00104 int cpl_plugin_get_info(cpl_pluginlist * list)
00105 {
00106     cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
00107     cpl_plugin  *   plugin = &recipe->interface ;
00108 
00109     cpl_plugin_init(plugin,
00110                     CPL_PLUGIN_API,
00111                     SINFONI_BINARY_VERSION,
00112                     CPL_PLUGIN_TYPE_RECIPE,
00113                     "sinfo_utl_cube_create",
00114                     "Generate a cube",
00115                     sinfo_utl_cube_create_description,
00116                     "Andrea Modigliani",
00117                     "Andrea.Modigliani@eso.org",
00118                     sinfo_get_license(),
00119                     sinfo_utl_cube_create_create,
00120                     sinfo_utl_cube_create_exec,
00121                     sinfo_utl_cube_create_destroy) ;
00122 
00123     cpl_pluginlist_append(list, plugin) ;
00124     
00125     return 0;
00126 }
00127 
00128 /*---------------------------------------------------------------------------*/
00137 /*---------------------------------------------------------------------------*/
00138 static int sinfo_utl_cube_create_create(cpl_plugin * plugin)
00139 {
00140     cpl_recipe      * recipe ;
00141     cpl_parameter   * p ;
00142     cpl_parameterlist   * list ;
00143 
00144     /* Get the recipe out of the plugin */
00145     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00146         recipe = (cpl_recipe *)plugin ;
00147     else return -1 ;
00148     cpl_error_reset();
00149     irplib_reset();
00150 
00151     /* Create the parameters list in the cpl_recipe object */
00152     recipe->parameters = cpl_parameterlist_new() ; 
00153 
00154     list=recipe->parameters;
00155   /* jitter mode indicator: yes: Auto-Jitter, no: user defined jitter
00156      The next three parameters are only used if jitterInd is set to yes, 
00157      that means in auto-jittering mode!
00158   */
00159   p = cpl_parameter_new_value("sinfoni.objnod.jitter_index",
00160                   CPL_TYPE_BOOL,
00161                               "jitter mode indicator: "
00162                               "TRUE: Auto-Jitter, "
00163                               "FALSE: user defined jitter. "
00164                               "The size_x size_y kernel_type parameters "
00165                               "are only used if jitterInd is set to yes, "
00166                               "that means in auto-jittering mode.",
00167                               "sinfoni.objnod",
00168                               TRUE);
00169 
00170   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-jit_ind");
00171   cpl_parameterlist_append(list, p);
00172 
00173 
00174   /* Kernel Type */
00175   /* the name of the interpolation kernel to shift the single cubes  to the 
00176      correct places inside the big combined cube. That you want to generate 
00177      using the eclipse routine sinfo_generate_interpolation_kernel()
00178      Supported kernels are:
00179 
00180                                      NULL:      default kernel, currently tanh
00181                                      default: dito
00182                                      tanh:    Hyperbolic tangent
00183                                      sinc2:   Square sinc
00184                                      lanczos: Lanczos2 kernel
00185                                      hamming: Hamming kernel
00186                                      hann:    Hann kernel
00187   */
00188   p = cpl_parameter_new_enum("sinfoni.objnod.kernel_type",
00189                   CPL_TYPE_STRING,
00190                               "Kernel Type:"
00191                               "the name of the interpolation kernel to shift "
00192                               "the single cubes  to the correct places inside "
00193                              "the big combined cube",
00194                               "sinfoni.objnod",
00195                               "tanh",
00196                                7,
00197                               "NULL","default","tanh","sinc2",
00198                               "lanczos","hamming","hann");
00199 
00200   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-kernel_typ");
00201   cpl_parameterlist_append(list, p);
00202 
00203   /*Resampling */
00204  /* number of coefficients for the polynomial interpolation */
00205   p = cpl_parameter_new_value("sinfoni.objnod.n_coeffs",
00206                   CPL_TYPE_INT,
00207                               "number of coefficients for the polynomial "
00208                               "interpolation ",
00209                               "sinfoni.objnod",
00210                                3);
00211 
00212   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-no_coeffs");
00213   cpl_parameterlist_append(list, p);
00214 
00215   /* Cube Creation */
00216   /*indicates if the slitlet distances are determined by a north-south-test 
00217      (yes) or slitlet edge fits (no)
00218   */
00219   p = cpl_parameter_new_value("sinfoni.objnod.nord_south_index",
00220                   CPL_TYPE_BOOL,
00221                               "Nord South Index Switch: "
00222                               "indicates if the slitlet distances are "
00223                               "determined by a north-south-test (TRUE) "
00224                               "or slitlet edge fits (FALSE)",
00225                               "sinfoni.objnod",
00226                               TRUE);
00227 
00228 
00229   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-ns_ind");
00230   cpl_parameterlist_append(list, p);
00231 
00232 
00233   /* Cube Creation */
00234   /*indicates if the slitlet distances are determined by a north-south-test 
00235      (yes) or slitlet edge fits (no)
00236   */
00237   p = cpl_parameter_new_value("sinfoni.objnod.flux_cor",
00238                               CPL_TYPE_BOOL,
00239                               "Flux correction: ",
00240                               "sinfoni.objnod",
00241                               FALSE);
00242 
00243 
00244   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-flux_cor");
00245   cpl_parameterlist_append(list, p);
00246 
00247 
00248 
00249 
00250  /* Fine tuning */
00251   /* Method */
00252   p = cpl_parameter_new_enum("sinfoni.objnod.fine_tuning_method",
00253                   CPL_TYPE_STRING,
00254                               "Fine Tuning Method: "
00255                               "indicator for the shifting method to use "
00256                               "(P: polynomial interpolation, "
00257                  /* " F: FFT, " */
00258                               " S: cubic spline interpolation)",
00259                               "sinfoni.objnod",
00260                               "P",
00261                                2,
00262                               "P","S");
00263 
00264   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-fine_tune_mtd");
00265   cpl_parameterlist_append(list, p);
00266 
00267   p = cpl_parameter_new_value("sinfoni.objnod.order",
00268                   CPL_TYPE_INT,
00269                               "Fine Tuning polynomial order: " 
00270                               "order of the polynomial if the polynomial "
00271                               "interpolation shifting method is used.",
00272                               "sinfoni.objnod",
00273                               2);
00274 
00275   cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"objnod-order");
00276   cpl_parameterlist_append(list, p);
00277 
00278     /* Fill the parameters list */
00279     /* --stropt */
00280 
00281   
00282     /* Return */
00283     return 0;
00284 }
00285 
00286 /*---------------------------------------------------------------------------*/
00292 /*---------------------------------------------------------------------------*/
00293 static int sinfo_utl_cube_create_exec(cpl_plugin * plugin)
00294 {
00295     cpl_recipe  *   recipe ;
00296     int result=0;    
00297     cpl_errorstate initial_errorstate = cpl_errorstate_get();
00298 
00299     /* Get the recipe out of the plugin */
00300     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00301         recipe = (cpl_recipe *)plugin ;
00302     else return -1 ;
00303        sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00304         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00305 
00306     result=sinfo_cube_create(recipe->parameters, recipe->frames) ;
00307     if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
00308         /* Dump the error history since recipe execution start.                
00309            At this point the recipe cannot recover from the error */           
00310         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
00311     } 
00312     return result;
00313 }
00314 
00315 /*---------------------------------------------------------------------------*/
00321 /*---------------------------------------------------------------------------*/
00322 static int sinfo_utl_cube_create_destroy(cpl_plugin * plugin)
00323 {
00324     cpl_recipe  *   recipe ;
00325     
00326     /* Get the recipe out of the plugin */
00327     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00328         recipe = (cpl_recipe *)plugin ;
00329     else return -1 ;
00330 
00331     cpl_parameterlist_delete(recipe->parameters) ; 
00332     return 0 ;
00333 }
00334 
00335 
00336 /*---------------------------------------------------------------------------*/
00343 /*---------------------------------------------------------------------------*/
00344 static int 
00345 sinfo_cube_create(cpl_parameterlist * parameters, cpl_frameset * frames)
00346 {
00347 
00348    cpl_frame* frm_raw_on=NULL;
00349    cpl_frame* frm_raw_off=NULL;
00350    cpl_frame* frm_wav_map=NULL;
00351    cpl_frame* frm_mflat=NULL;
00352    cpl_frame* frm_distortion=NULL;
00353    cpl_frame* frm_slit_pos=NULL;
00354    cpl_frame* frm_slitlets_distance=NULL;
00355 
00356    cpl_image* ima_raw_on=NULL;
00357    cpl_image* ima_raw_off=NULL;
00358    cpl_image* ima_wav_map=NULL;
00359    cpl_image* ima_mflat=NULL;
00360    cpl_image* ima_mflat_dist=NULL;
00361    cpl_image* ima_obj_mflat=NULL;
00362    cpl_image* ima_obj_dist=NULL;
00363    cpl_image* ima_obj_res=NULL;
00364    cpl_image* ima_wav_res=NULL;
00365    cpl_image* ima_wav_dif=NULL;
00366 
00367    cpl_imagelist* cube=NULL;
00368    cpl_imagelist* outcube=NULL;
00369    cpl_imagelist* outcube2=NULL;
00370 
00371    //cpl_table* tab_distortion=NULL;
00372    //cpl_table* tab_slit_pos=NULL;
00373 
00374    float mi=0;
00375    float ma=0;
00376    double dis=0 ;
00377    double cwav=0 ;
00378    int cpix=0 ;
00379    int nx=0;
00380    int ny=0;
00381     float fcol=0;
00382    float* pd=NULL;
00383    float* pw=NULL;
00384    int i=0;
00385    int j=0;
00386    float** slit_edges=NULL;
00387    float* distances=NULL;
00388    float* correct_dist=NULL;
00389    char kernel[80];
00390    char poly_file[80];
00391    char pos_list[80];
00392    char dist_list[80];
00393 
00394 
00395     int jit_ind=0;
00396    int ns_index=0;
00397    int n_coeffs=0;
00398    int nrows=0;
00399    cpl_parameter* p=NULL;
00400    int nslits=32;
00401    int flux_cor=0;
00402    const char* fine_tuning_method=NULL;
00403    int fine_tuning_pol_order=0;
00404    float center_x=0;
00405    float center_y=0;
00406 
00407    /* Identify the RAW and CALIB frames in the input frameset */
00408     check(sinfo_dfs_set_groups(frames),
00409          "Cannot identify RAW and CALIB frames") ;
00410 
00411    check_nomsg(p=cpl_parameterlist_find(parameters,
00412                                         "sinfoni.objnod.flux_cor"));
00413    check_nomsg(flux_cor=cpl_parameter_get_bool(p));
00414 
00415    check_nomsg(p=cpl_parameterlist_find(parameters,
00416                                         "sinfoni.objnod.jitter_index"));
00417    check_nomsg(jit_ind=cpl_parameter_get_bool(p));
00418 
00419    check_nomsg(p=cpl_parameterlist_find(parameters,
00420                                         "sinfoni.objnod.kernel_type"));
00421    check_nomsg(strcpy(kernel,cpl_parameter_get_string(p)));
00422 
00423    check_nomsg(p=cpl_parameterlist_find(parameters,"sinfoni.objnod.n_coeffs"));
00424    check_nomsg(n_coeffs=cpl_parameter_get_int(p));
00425 
00426 
00427    check_nomsg(p=cpl_parameterlist_find(parameters,
00428                                         "sinfoni.objnod.nord_south_index"));
00429    check_nomsg(ns_index=cpl_parameter_get_bool(p));
00430 
00431 
00432    check_nomsg(p=cpl_parameterlist_find(parameters,
00433                                         "sinfoni.objnod.fine_tuning_method"));
00434    check_nomsg(fine_tuning_method=cpl_parameter_get_string(p));
00435 
00436    check_nomsg(p=cpl_parameterlist_find(parameters,
00437                                         "sinfoni.objnod.order"));
00438    check_nomsg(fine_tuning_pol_order=cpl_parameter_get_int(p));
00439 
00440  
00441    cknull(frm_raw_on=cpl_frameset_find(frames,RAW_ON),
00442           "Missing required input %s",RAW_ON);
00443    cknull(frm_raw_off=cpl_frameset_find(frames,RAW_OFF),
00444           "Missing required input %s",RAW_OFF);
00445    cknull(frm_wav_map=cpl_frameset_find(frames,PRO_WAVE_MAP),
00446                 "Missing required input %s",PRO_WAVE_MAP);
00447    cknull(frm_mflat=cpl_frameset_find(frames,PRO_MASTER_FLAT_LAMP),
00448                 "Missing required input %s",PRO_WAVE_MAP);
00449 
00450    check_nomsg(frm_distortion=cpl_frameset_find(frames,PRO_DISTORTION));
00451    check_nomsg(frm_slit_pos=cpl_frameset_find(frames,PRO_SLIT_POS));
00452    check_nomsg(frm_slitlets_distance=
00453                cpl_frameset_find(frames,PRO_SLITLETS_DISTANCE));
00454 
00455    strcpy(pos_list,cpl_frame_get_filename(frm_slit_pos));
00456    strcpy(dist_list,cpl_frame_get_filename(frm_slitlets_distance));
00457    strcpy(poly_file,cpl_frame_get_filename(frm_distortion));
00458 
00459  
00460    check_nomsg(ima_raw_on=cpl_image_load(cpl_frame_get_filename(frm_raw_on),
00461                                          CPL_TYPE_FLOAT,0,0));
00462  
00463    check_nomsg(ima_raw_off=cpl_image_load(cpl_frame_get_filename(frm_raw_off),
00464                                           CPL_TYPE_FLOAT,0,0));
00465 
00466  
00467    check_nomsg(ima_wav_map=cpl_image_load(cpl_frame_get_filename(frm_wav_map),
00468                                           CPL_TYPE_FLOAT,0,0));
00469  
00470    check_nomsg(ima_mflat=cpl_image_load(cpl_frame_get_filename(frm_mflat),
00471                                           CPL_TYPE_FLOAT,0,0));
00472 
00473  
00474 
00475    check_nomsg(cpl_image_subtract(ima_raw_on,ima_raw_off));
00476    cpl_image_save(ima_raw_on,"ima_sub.fits", CPL_BPP_IEEE_FLOAT, 
00477                   NULL,CPL_IO_DEFAULT);
00478 
00479    cknull_nomsg(ima_obj_mflat=sinfo_new_div_images_robust(ima_raw_on,
00480                                                          ima_mflat));
00481    cpl_image_save(ima_obj_mflat,"ima_obj_mflat.fits", CPL_BPP_IEEE_FLOAT, 
00482                   NULL,CPL_IO_DEFAULT);
00483  
00484 
00485 //The following is not needed
00486    cknull_nomsg(ima_mflat_dist=sinfo_new_image_warp_fits(ima_mflat,kernel,
00487                                                          poly_file));
00488 
00489    cpl_image_save(ima_mflat_dist,"ima_mflat_dist.fits", CPL_BPP_IEEE_FLOAT, 
00490                   NULL,CPL_IO_DEFAULT);
00491 
00492    cknull_nomsg(ima_obj_dist=sinfo_new_image_warp_fits(ima_obj_mflat, 
00493                                                        kernel, 
00494                                                        poly_file));
00495 
00496    cpl_image_save(ima_obj_dist,"ima_obj_dist.fits", CPL_BPP_IEEE_FLOAT, 
00497                   NULL,CPL_IO_DEFAULT);
00498  
00499    cknull(ima_obj_res = sinfo_new_defined_resampling(ima_obj_dist, 
00500                             ima_wav_map, 
00501                             n_coeffs,
00502                             &nrows,
00503                             &dis,
00504                             &mi,
00505                             &ma,
00506                             &cwav,
00507                             &cpix),
00508          " sinfo_definedResampling() failed" ) ;
00509 
00510 
00511 
00512   cpl_image_save(ima_obj_res,"ima_obj_res.fits", CPL_BPP_IEEE_FLOAT, 
00513                   NULL,CPL_IO_DEFAULT);
00514 
00515 
00516     //We create an image with the derivatives
00517   nx=cpl_image_get_size_x(ima_wav_map);
00518   ny=cpl_image_get_size_y(ima_wav_map);
00519 
00520       check_nomsg(ima_wav_dif=cpl_image_new(nx,ny,CPL_TYPE_FLOAT));
00521       pw=cpl_image_get_data(ima_wav_map);
00522       pd=cpl_image_get_data(ima_wav_dif);
00523 
00524     
00525       for(i=1;i<nx-1;i++) {
00526     for(j=1;j<ny-1;j++) {
00527       if(!isnan(pd[nx*j+i])) {
00528         pd[nx*j+i]=2.0*dis/(pw[nx*(j+1)+i]-pw[nx*(j-1)+i]);
00529       }
00530     }
00531     if(!isnan(pd[i])) {
00532       pd[i]=dis/(pw[nx+i]-pw[i]);
00533     }
00534     if(!isnan(pd[nx*(ny-1)+i])) {
00535       pd[nx*(ny-1)+i]=dis/(pw[nx*(ny-1)+i]-pw[nx*(ny-2)+i]);
00536     }
00537       }
00538     
00539 
00540       //cpl_image_save(ima_wav_dif,"diff.fits", 
00541       //CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
00542 
00543 
00544 
00545       cknull(ima_wav_res = sinfo_new_defined_resampling(ima_wav_dif, 
00546                             ima_wav_map, 
00547                             n_coeffs,
00548                             &nrows,
00549                             &dis,
00550                             &mi,
00551                             &ma,
00552                             &cwav,
00553                             &cpix),
00554          " sinfo_definedResampling() failed" ) ;
00555 
00556       if(flux_cor) {
00557     sinfo_msg("Apply flux correction");
00558     cpl_image_divide(ima_obj_res,ima_wav_res);
00559       }
00560 
00561 
00562       //cpl_image_save(ima_wav_res,"res_diff.fits", 
00563       //CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
00564 
00565 
00566 
00567   cpl_image_save(ima_wav_res,"ima_wav_res.fits", CPL_BPP_IEEE_FLOAT, 
00568                   NULL,CPL_IO_DEFAULT);
00569 
00570 
00571       //To rescale in flux we divide the resampled image and 
00572       //the resampled derivatives. At this point ima_obj_res should have same 
00573       //flux as input image (im.diff)
00574 
00575       //ima_obj_res=cpl_image_duplicate(ima_wav_res);
00576       //sinfo_free_image(&ima_wav_res);
00577       if(flux_cor) {
00578     sinfo_msg("Apply flux correction");
00579     cpl_image_divide(ima_obj_res,ima_wav_res);
00580       }
00581 
00582 
00583 
00584 
00585       /*---select north-south-test or fitting of slitlet edges--*/
00586       if (ns_index == 0) {
00587     sinfo_msg("cfg->northsouthInd == 0");
00588     cknull(slit_edges=sinfo_read_slitlets_edges(nslits,pos_list),
00589            "error reading slitlets edges");
00590       } else {
00591     sinfo_msg("cfg->northsouthInd != 0");
00592     cknull(distances = sinfo_read_distances(nslits,dist_list),
00593            "error reading distances");
00594       }
00595  
00596       cknull(correct_dist = (float*) cpl_calloc(nslits, sizeof (float)),
00597          " could not allocate memory!") ;
00598 
00599       sinfo_msg("Create cube object");
00600       if (ns_index ==0 ) {
00601 
00602         cknull(cube = sinfo_new_make_cube_spi(ima_obj_res,slit_edges,
00603                           correct_dist),
00604            "could not construct data cube!") ;
00605 
00606       }  else {
00607     cknull(cube = sinfo_new_make_cube_dist(ima_obj_res,fcol,distances,
00608                            correct_dist),
00609            "could not construct a data cube!") ;
00610       }
00611       sinfo_free_image(&ima_obj_res);
00612 
00613 
00614      cknull(outcube2=sinfo_new_fine_tune(cube,
00615                       correct_dist,
00616                       fine_tuning_method,
00617                       fine_tuning_pol_order,
00618                       nslits),
00619          " could not fine tune the data cube") ;
00620 
00621       sinfo_msg("Stretch output cube along Y direction");
00622       cknull(outcube = sinfo_new_bin_cube(outcube2,1,2,0,63,0,63),
00623          "Error binning cube");
00624       sinfo_free_imagelist(&cube);
00625 
00626       ck0(sinfo_pro_save_ims(outcube,frames,frames,"out_cube.fits","CUBE",NULL,
00627                              "sinfo_utl_cube_create",parameters),
00628           "cannot save cube %s", "out_cube.fits");
00629 
00630 
00631       check_nomsg(center_x = cpl_image_get_size_x(
00632                           cpl_imagelist_get(outcube,0))/2.+0.5) ;
00633       check_nomsg(center_y = cpl_image_get_size_y(
00634                           cpl_imagelist_get(outcube,0))/2.+0.5 );
00635 
00636      sinfo_new_set_wcs_cube(outcube,"out_cube.fits", cwav, dis, 
00637                  cpix, center_x, center_y);
00638 
00639 
00640   cleanup:      
00641 
00642     if (ns_index ==0 ) {
00643       if(slit_edges != NULL) {
00644     sinfo_new_destroy_2Dfloatarray(&slit_edges,nslits);
00645       }
00646     } else {
00647       if (distances != NULL ) {
00648     sinfo_new_destroy_array(&distances);
00649       }
00650     }
00651 
00652 
00653 
00654    
00655       sinfo_free_float(&correct_dist) ;
00656       sinfo_free_imagelist(&cube);
00657       sinfo_free_imagelist(&outcube);
00658       sinfo_free_imagelist(&outcube2);
00659       sinfo_free_image(&ima_raw_on);
00660       sinfo_free_image(&ima_raw_off);
00661       sinfo_free_image(&ima_wav_map);
00662       sinfo_free_image(&ima_mflat);
00663       sinfo_free_image(&ima_mflat_dist);
00664       sinfo_free_image(&ima_obj_res);
00665       sinfo_free_image(&ima_obj_mflat);
00666       sinfo_free_image(&ima_obj_dist);
00667       sinfo_free_image(&ima_obj_res);
00668       sinfo_free_image(&ima_wav_res);
00669       sinfo_free_image(&ima_wav_dif);
00670     
00671       return 0 ;
00672 
00673 }
00674 
00675 

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1