00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "sinfo_functions.h"
00037 #include "sinfo_new_cube_ops.h"
00038 #include "sinfo_utl_cube2ima.h"
00039 #include "sinfo_key_names.h"
00040 #include <sinfo_error.h>
00041 #include <sinfo_utils_wrappers.h>
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00064
00071
00072 int sinfo_utl_cube2ima(
00073 cpl_parameterlist * parlist,
00074 cpl_frameset * framelist)
00075 {
00076 cpl_parameter * param =NULL ;
00077 const char * name_i =NULL;
00078 const char * name_o =NULL;
00079
00080 double ws=0 ;
00081 double we=0 ;
00082 double wc=0 ;
00083 double wd=0 ;
00084
00085
00086 int naxis3=0;
00087 double lams=0;
00088 double lame=0;
00089
00090 cpl_frame * frm_cub=NULL ;
00091
00092 cpl_propertylist * plist=NULL ;
00093 cpl_frame * product_frame=NULL;
00094
00095 cpl_imagelist * cube=NULL;
00096 cpl_image * img=NULL;
00097
00098
00099
00100
00101 name_o ="out_ima.fits";
00102
00103
00104 check_nomsg(param = cpl_parameterlist_find(parlist,
00105 "sinfoni.sinfo_utl_cube2ima.ws"));
00106 check_nomsg(ws = cpl_parameter_get_double(param)) ;
00107
00108
00109 check_nomsg(param = cpl_parameterlist_find(parlist,
00110 "sinfoni.sinfo_utl_cube2ima.we"));
00111 check_nomsg(we = cpl_parameter_get_double(param)) ;
00112
00113
00114 check(sinfo_dfs_set_groups(framelist),
00115 "Cannot identify RAW and CALIB frames");
00116
00117
00118 check(frm_cub = cpl_frameset_find(framelist, SI_UTL_CUBE2IMA_CUBE),
00119 "SOF does not have a file tagged as %s",SI_UTL_CUBE2IMA_CUBE);
00120
00121 check_nomsg(name_i = cpl_frame_get_filename(frm_cub));
00122
00123 plist=cpl_propertylist_load(name_i,0);
00124 naxis3=sinfo_pfits_get_naxis3(plist);
00125 wd=sinfo_pfits_get_cdelt3(plist);
00126 wc=sinfo_pfits_get_crval3(plist);
00127 sinfo_free_propertylist(&plist);
00128
00129 lams=wc-naxis3*wd/2+wd;
00130 lame=lams+(naxis3-2)*wd;
00131
00132 check_nomsg(param = cpl_parameterlist_find(parlist,
00133 "sinfoni.sinfo_utl_cube2ima.ws"));
00134
00135 if(ws != cpl_parameter_get_default_double(param)) {
00136 if (ws < lams) {
00137 sinfo_msg_warning("ws =%f too low set it to %f",ws,lams);
00138 ws=lams;
00139 }
00140 else if (ws >= lame) {
00141 sinfo_msg_warning("ws =%f too high set it to %f",ws,lams);
00142 ws=lams;
00143 }
00144 } else {
00145 ws=lams;
00146 }
00147
00148 check_nomsg(param = cpl_parameterlist_find(parlist,
00149 "sinfoni.sinfo_utl_cube2ima.we"));
00150 if(we != cpl_parameter_get_default_double(param)) {
00151 if (we > lame) {
00152 sinfo_msg_warning("we =%f too low set it to %f",we,lame);
00153 we=lame;
00154 }
00155 else if (we <= lams) {
00156 sinfo_msg_warning("we =%f too low set it to %f",we,lame);
00157 we=lame;
00158 }
00159 } else {
00160 we=lame;
00161 }
00162
00163 check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_cub),0),
00164 "Cannot read the FITS header") ;
00165
00166
00167 check_nomsg(cube = cpl_imagelist_load((char*)name_i,CPL_TYPE_FLOAT,0));
00168 if(NULL==(img=sinfo_new_average_cube_to_image_between_waves(cube,wd,wc,
00169 ws,we))) {
00170 sinfo_msg_error("Cannot average cube to image in wavelength "
00171 "range [%f,%f] um",ws,we) ;
00172
00173 sinfo_free_imagelist(&cube);
00174 sinfo_free_propertylist(&plist);
00175
00176 }
00177 sinfo_free_imagelist(&cube);
00178
00179
00180
00181 check_nomsg(product_frame = cpl_frame_new());
00182 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00183 check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE2IMA_PROIMA)) ;
00184 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
00185 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00186 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00187 "Error while initialising the product frame") ;
00188
00189
00190
00191 check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
00192 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)
00193 check(cpl_dfs_setup_product_header(plist,
00194 product_frame,
00195 framelist,
00196 parlist,
00197 "si_sinfo_utl_cube2ima",
00198 "SINFONI",
00199 KEY_VALUE_HPRO_DID,NULL),
00200 "Problem in the product DFS-compliance") ;
00201 #else
00202 check(cpl_dfs_setup_product_header(plist,
00203 product_frame,
00204 framelist,
00205 parlist,
00206 "si_sinfo_utl_cube2ima",
00207 "SINFONI",
00208 KEY_VALUE_HPRO_DID),
00209 "Problem in the product DFS-compliance") ;
00210 #endif
00211
00212
00213 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CTYPE3",0));
00214 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CRPIX3",0));
00215 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CRVAL3",0));
00216 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CDELT3",0));
00217 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CUNIT3",0));
00218
00219 check(cpl_image_save(img,
00220 name_o,
00221 CPL_BPP_IEEE_FLOAT,
00222 plist,
00223 CPL_IO_DEFAULT),
00224 "Could not save product");
00225
00226 check_nomsg(sinfo_free_propertylist(&plist)) ;
00227
00228
00229 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
00230 check_nomsg(sinfo_free_image(&img)) ;
00231
00232
00233
00234 cleanup:
00235 sinfo_free_imagelist(&cube);
00236 sinfo_free_propertylist(&plist);
00237 sinfo_free_image(&img);
00238
00239 if (cpl_error_get_code())
00240 return -1 ;
00241 else
00242 return 0 ;
00243 }