utl_cube_test.c

00001 /* $Id: utl_cube_test.c,v 1.8 2005/10/11 13:12:27 amodigli Exp $
00002  *
00003  * This file is part of the IIINSTRUMENT 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: 2005/10/11 13:12:27 $
00024  * $Revision: 1.8 $
00025  * $Name:  $
00026  */
00027 
00028 
00029 /*-----------------------------------------------------------------------------
00030                                 Includes
00031  -----------------------------------------------------------------------------*/
00032 
00033 
00034 #include "utl_cube_test.h"
00035 #include "eclipse.h"
00036 #include "utilities.h"
00037 #include <stdio.h>
00038 #include "sinfoni_key_names.h"
00039 #include "utilities_scired.h"
00040 #include "sinfoni_functions.h"
00041 #include "sinfoni_pro_save.h"
00042 #include <sinfoni_memory.h>
00043 
00044 /*-----------------------------------------------------------------------------
00045                                 defines
00046  -----------------------------------------------------------------------------*/
00047 
00048 #define sx 200
00049 #define sy 200
00050 #define sz  2
00051 #define nc   2
00052 
00053 /*-----------------------------------------------------------------------------
00054                             Functions prototypes
00055  -----------------------------------------------------------------------------*/
00056 
00057 
00058 /*-----------------------------------------------------------------------------
00059                             Static variables
00060  -----------------------------------------------------------------------------*/
00061 
00062 
00063 /*-----------------------------------------------------------------------------
00064                                 Functions code
00065  -----------------------------------------------------------------------------*/
00066 /*----------------------------------------------------------------------------*/
00073 /*----------------------------------------------------------------------------*/
00074 int si_utl_cube_test(
00075         cpl_parameterlist   *   parlist, 
00076         cpl_frameset        *   framelist)
00077 {
00078     const char          *   fctid = "si_utl_cube_test" ;
00079     cpl_parameter       *   param=NULL ;
00080     const char          *   operation=NULL ;
00081     const char          *   method=NULL ;
00082     double                  sigma=0 ;
00083 
00084     const char                *   name_o=NULL ;
00085     const char                *   name_i=NULL ;
00086    
00087   
00088  
00089     int xsize=0;
00090     int ysize=0;
00091 
00092     int i=0;
00093   
00094 
00095     OneCube** cube_src=NULL;
00096     OneCube** cube_sub=NULL;
00097     OneCube** cube_trm=NULL;
00098   
00099     double sig=5;
00100     double cx[nc];
00101     double cy[nc];
00102     float offx[nc];
00103     float offy[nc];
00104     float exptime[nc];
00105     char name[FILE_NAME_SZ];
00106 
00107     OneCube* cube_tmp=NULL;
00108     OneCube* cube_dum=NULL;
00109     OneCube* cube_res=NULL;
00110     OneCube* cube_vig=NULL;
00111     OneCube* csky=NULL;
00112     OneCube* mask=NULL;
00113 
00114 
00115     int offx_max=0;
00116     int offy_max=0;
00117     int rsx=0;
00118     int rsy=0;
00119     int rsz=0;
00120 
00121     int z=0;
00122     double off=1;
00123     pixelvalue sky_min=(pixelvalue)-10;
00124     pixelvalue sky_max=(pixelvalue)10;
00125     int sky_bkg=100;
00126     double amp=2000.;
00127     int z_min=0;
00128     int z_max=0;
00129     int zst=2;
00130     double kappa=2.0;
00131     cpl_table* qclog_tbl=NULL;
00132     cpl_imagelist* cub_ims=NULL;
00133 
00134     /* HOW TO RETRIEVE INPUT PARAMETERS */
00135     /* --stropt */
00136     param = cpl_parameterlist_find(parlist, "sinfoni.si_utl_cube_test.op");
00137     operation = cpl_parameter_get_string(param);
00138 
00139     param = cpl_parameterlist_find(parlist, "sinfoni.si_utl_cube_test.method");
00140     method = cpl_parameter_get_string(param);
00141 
00142 
00143     param = cpl_parameterlist_find(parlist, "sinfoni.si_utl_cube_test.name_o");
00144     name_o = cpl_parameter_get_string(param);
00145 
00146 
00147     param = cpl_parameterlist_find(parlist, "sinfoni.si_utl_cube_test.name_i");
00148     name_i = cpl_parameter_get_string(param);
00149 
00150     cube_src=(OneCube**) cpl_calloc(nc,sizeof(OneCube*));
00151 
00152     /* --doubleopt */
00153     param = cpl_parameterlist_find(parlist,"sinfoni.si_utl_cube_test.xsize");
00154     xsize = cpl_parameter_get_int(param) ;
00155 
00156     param = cpl_parameterlist_find(parlist,"sinfoni.si_utl_cube_test.ysize");
00157     ysize = cpl_parameter_get_int(param) ;
00158 
00159     param = cpl_parameterlist_find(parlist,"sinfoni.si_utl_cube_test.sigma");
00160     sigma = cpl_parameter_get_double(param) ;
00161 
00162     param = cpl_parameterlist_find(parlist,"sinfoni.objnod.kappa");
00163     kappa = cpl_parameter_get_double(param);
00164 
00165      /* generates dummy sources */
00166     for(i=0;i<nc;i++) {
00167       cube_tmp=new_cube(sx,sy,sz);
00168       exptime[i]=1;
00169 
00170       if(i==0 || i==2 || i==4) {
00171     cx[i]=sx/2+off*i;
00172     cy[i]=sy/2-off*i;
00173     offx[i]=off*i;
00174     offy[i]=-off*i;
00175          sig=5;
00176       } else {
00177          cx[i]=sx/2+off*i;
00178          cy[i]=sy/2-off*i;
00179          cx[i]=sx/2+off*i+5*sig;
00180          cy[i]=sy/2-off*i-5*sig;
00181          amp/=1;
00182          sig=2;
00183       }
00184    
00185 
00186 
00187      /*
00188       if(i==(nc-1)) {
00189 
00190          cx[i]=sx/2+off*i+5*sig;
00191          cy[i]=sy/2-off*i-5*sig;
00192          amp/=10;
00193     
00194          sig=1;
00195       }
00196       */
00197      
00198 
00199 
00200       for(z=0;z<sz;z++) {
00201         cube_tmp->plane[z]=generate_gaussian_pattern(sx,sy,cx[i],cy[i],sig);
00202       }
00203       sprintf(name,"%s%2.2d%s","out_cube_obj_",i,".fits");
00204       cst_op_cube(cube_tmp,amp,'*');
00205       cube_dum=copy_cube(cube_tmp);
00206 
00207       save_cube_to_fits(cube_tmp,name);
00208       destroy_cube(cube_tmp);
00209       cube_tmp=new_cube(sx,sy,sz);     
00210 
00211       for(z=0;z<sz;z++) {
00212         cube_tmp->plane[z]=generate_random_uniform(sx,sy,sky_min,sky_max);
00213       }
00214 
00215 
00216       sprintf(name,"%s%2.2d%s","out_cube_sky_",i,".fits");
00217       cst_op_cube(cube_tmp,i*exptime[i],'+');
00218       save_cube_to_fits(cube_tmp,name);
00219 
00220       sprintf(name,"%s%2.2d%s","out_cube_pre_",i,".fits");
00221       save_cube_to_fits(cube_dum,name);
00222 
00223       op_cube(&cube_dum,cube_tmp,'+');
00224 
00225       cube_src[i]=copy_cube(cube_dum);
00226 
00227 
00228       cst_op_cube(cube_src[i],sky_bkg,'+');
00229       sprintf(name,"%s%2.2d%s","out_cube_src_",i,".fits");
00230       save_cube_to_fits(cube_src[i],name);
00231 
00232       destroy_cube(cube_tmp);
00233       destroy_cube(cube_dum);
00234 
00235     }
00236     cube_sub=(OneCube**) cpl_calloc(nc,sizeof(OneCube*));
00237     cube_trm=(OneCube**) cpl_calloc(nc,sizeof(OneCube*));
00238 
00239 
00240 
00241 
00242     for(i=0;i<nc;i++) {
00243       /* subtract median */
00244 
00245       sinfoni_correct_median_it(&(cube_src[i]));
00246       sprintf(name,"%s%2.2d%s","out_cube_sub_",i,".fits");
00247       save_cube_to_fits(cube_src[i],name);
00248 
00249     }
00250     for(i=0;i<nc;i++) {
00251       if(abs(offx[i])<offx_max){
00252     offx_max=abs(offx[i]);
00253       }
00254       if(abs(offy[i])<offy_max){
00255     offy_max=abs(offy[i]);
00256       }
00257     }
00258 
00259 
00260 
00261     rsx=2*sx+4*offx_max;
00262     rsy=2*sy+4*offy_max;
00263     rsz=sz;
00264     cube_res=newCube(rsx,rsy,rsz);
00265     mask=newCube(rsx,rsy,rsz);
00266 
00267     for(z=0;z<sz;z+=zst) {
00268       z_min=z;
00269       z_max=z_min+zst;
00270 
00271       printf("processing plane %d\n",z);
00272       combineJitteredCubesThomasRange(cube_src,cube_res,mask,nc,
00273                                      offx,offy,exptime,
00274                                 (char*)"tanh",z_min,z_max,kappa);
00275     }
00276 
00277 
00278 
00279     /* save results */
00280     sprintf(name,"%s","out_res_msk.fits");
00281     save_cube_to_fits(mask,name);
00282     sprintf(name,"%s","out_res_src.fits");
00283     save_cube_to_fits(cube_res,name);
00284 
00285 
00286 
00287     qclog_tbl=sinfoni_qclog_init(1);
00288     cub_ims=sinfoni_cube2imglist(cube_res);
00289     sinfoni_qclog_add(qclog_tbl,0,"QC TEST","CPL_TYPE_STRING","test",
00290                                             "comment");
00291 
00292 
00293 /* Using direct command to save imset
00294     if (cpl_imagelist_save(cub_ims,"prova.fits",CPL_BPP_DEFAULT,NULL,
00295           CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
00296       cpl_table_delete(qclog_tbl);
00297       cpl_imagelist_delete(cub_ims); 
00298       for(i=0;i<nc;i++) {
00299     destroy_cube(cube_src[i]);
00300       }
00301       destroy_cube(cube_res);
00302       destroy_cube(mask);
00303       cpl_free(cube_src);
00304       cpl_free(cube_sub);
00305       destroy_cube(csky);
00306       return -1;
00307 
00308 
00309     }
00310 */
00311 /*
00312     if(-1 == sinfoni_pro_save_ims(cub_ims,framelist,framelist,"prova.fits",
00313             "PRO_PROVA",qclog_tbl,fctid,parlist)) {
00314       cpl_msg_error(fctid,"cannot dump ims %s", "prova.fits");   
00315 
00316       cpl_table_delete(qclog_tbl);
00317       cpl_imagelist_delete(cub_ims); 
00318       for(i=0;i<nc;i++) {
00319     destroy_cube(cube_src[i]);
00320       }
00321       destroy_cube(cube_res);
00322       destroy_cube(mask);
00323       cpl_free(cube_src);
00324       cpl_free(cube_sub);
00325       destroy_cube(csky);
00326       return -1;
00327 
00328     }
00329 */
00330 
00331     cpl_table_delete(qclog_tbl);
00332     cpl_imagelist_delete(cub_ims); 
00333 
00334     cube_vig=cube_getvig(cube_res,90,90,rsx-90,rsy-90);
00335  
00336     sprintf(name,"%s","out_res_vig.fits");
00337     save_cube_to_fits(cube_vig,name);
00338     for(i=0;i<nc;i++) {
00339       cube_trm[i]=cube_getvig(cube_src[i],2,3,sx-2,sy-3);
00340       sprintf(name,"%s%d%s","out_vig",i,".fits");
00341       save_cube_to_fits(cube_trm[i],name);
00342     }
00343 
00344 
00345     /* free memory */
00346     for(i=0;i<nc;i++) {
00347       destroy_cube(cube_src[i]);
00348       destroy_cube(cube_trm[i]);
00349     }
00350     destroy_cube(cube_vig);
00351     destroy_cube(cube_res);
00352     destroy_cube(mask);
00353 
00354     cpl_free(cube_trm);
00355     cpl_free(cube_src);
00356     cpl_free(cube_sub);
00357 
00358     destroy_cube(csky);
00359 
00360     sinfoni_memory_status();
00361     /* Return */
00362     if (cpl_error_get_code()) {
00363         return -1 ;
00364     }
00365     else { 
00366         return 0 ;
00367     }
00368 }

Generated on Wed Oct 26 13:08:56 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001