36 #include "sinfo_utl_cube_combine.h"
37 #include "sinfo_utilities.h"
38 #include "sinfo_utilities_scired.h"
40 #include "sinfo_key_names.h"
41 #include "sinfo_error.h"
42 #include "sinfo_utils_wrappers.h"
43 #include "sinfo_pro_save.h"
74 int sinfo_utl_cube_combine(
75 cpl_parameterlist * parlist,
76 cpl_frameset * framelist)
78 cpl_parameter * param=NULL ;
79 const char * name_o=NULL ;
80 const char * name_i=NULL ;
81 const char * name_m=NULL ;
83 cpl_propertylist * plist=NULL ;
84 cpl_image * image=NULL ;
85 cpl_frame * product_frame=NULL;
86 cpl_frame * prod_frm=NULL;
87 cpl_frame * frame=NULL;
106 cpl_image* j_img=NULL;
107 cpl_image* m_img=NULL;
109 cpl_imagelist ** cube_object=NULL;
110 cpl_imagelist * cube_jitter=NULL;
111 cpl_imagelist * cube_mask=NULL;
113 const char** files=NULL;
117 float * offsetx=NULL;
118 float * offsety=NULL;
127 const char* name=NULL;
130 FILE* file_list=NULL;
136 check_nomsg(param = cpl_parameterlist_find(parlist,
137 "sinfoni.sinfo_utl_cube_combine.ks_clip"));
138 check_nomsg(ks_clip = cpl_parameter_get_bool(param));
140 check_nomsg(param = cpl_parameterlist_find(parlist,
141 "sinfoni.sinfo_utl_cube_combine.scale_sky"));
142 check_nomsg(scales_sky = cpl_parameter_get_bool(param));
145 check_nomsg(param = cpl_parameterlist_find(parlist,
146 "sinfoni.sinfo_utl_cube_combine.kappa"));
147 check_nomsg(kappa = cpl_parameter_get_double(param));
149 check_nomsg(param = cpl_parameterlist_find(parlist,
150 "sinfoni.sinfo_utl_cube_combine.name_i"));
151 check_nomsg(name_i = cpl_parameter_get_string(param));
153 check_nomsg(param = cpl_parameterlist_find(parlist,
154 "sinfoni.sinfo_utl_cube_combine.name_o"));
155 check_nomsg(name_o = cpl_parameter_get_string(param));
169 check(sinfo_dfs_set_groups(framelist),
170 "Cannot identify RAW and CALIB frames") ;
174 n=cpl_frameset_get_size(framelist);
180 frame=cpl_frameset_get_frame(framelist,i);
181 cpl_frame_set_group(frame,CPL_FRAME_GROUP_RAW);
189 if ( NULL == (file_list = fopen (name_i,
"r" ) ) )
196 while ( fscanf( file_list,
"%10f %10f",&tmpoffx, &tmpoffy) != EOF )
203 cknull(times = (
double*) cpl_calloc (nframes,
sizeof (
double)),
204 " could not allocate memory!") ;
206 cknull(offsetx = (
float*) cpl_calloc (nframes,
sizeof(
float)),
207 " could not allocate memory!") ;
209 cknull(offsety = (
float*) cpl_calloc (nframes,
sizeof(
float)),
210 " could not allocate memory!") ;
212 files = (
const char**) cpl_calloc(MAX_NAME_SIZE,
sizeof(
const char*));
213 if ( NULL == (file_list = fopen (name_i,
"r" ) ) )
225 while ( fscanf( file_list,
"%f %f",&tmpoffx,&tmpoffy ) != EOF ) {
226 frame=cpl_frameset_get_frame(framelist,cnt);
227 files[cnt]= cpl_frame_get_filename(frame);
228 times[cnt]=sinfo_pfits_get_exptime(files[cnt]);
229 offsetx[cnt]=tmpoffx;
230 offsety[cnt]=tmpoffy;
231 plist=cpl_propertylist_load(files[cnt],0);
232 size_x=sinfo_pfits_get_naxis1(plist);
233 size_y=sinfo_pfits_get_naxis2(plist);
234 sinfo_free_propertylist(&plist);
235 if(size_x < min_size_x) min_size_x=size_x;
236 if(size_y < min_size_y) min_size_y=size_y;
239 sinfo_msg(
"Min input cube size x=%d y=%d",min_size_x,min_size_y);
244 ck0(sinfo_auto_size_cube(offsetx,offsety,nframes,
245 &ref_offx,&ref_offy,&size_x,&size_y),
246 "Error resizing cube");
247 sinfo_msg(
"output ima size=%dx%d",size_x,size_y);
248 cknull(cube_object = cpl_calloc(nframes,
sizeof(cpl_imagelist*)),
249 "could not allocate memory") ;
251 for (i=0;i<nframes;i++) {
252 frame=cpl_frameset_get_frame(framelist,i);
253 name=cpl_frame_get_filename(frame);
254 check_nomsg(cube_object[i]=cpl_imagelist_load(name,CPL_TYPE_FLOAT,0));
255 ck0(sinfo_new_assign_offset2(i,name,offsetx,offsety,
257 "Error assigning offsets");
259 onp = cpl_imagelist_get_size(cube_object[0]);
262 check(cube_jitter = cpl_imagelist_new(),
"allocating new data cube object");
263 check(cube_mask = cpl_imagelist_new(),
"allocating new data cube mask");
265 check(plist=cpl_propertylist_load(files[0],0),
266 "Cannot read the FITS header") ;
268 if(scales_sky == 1) {
269 sinfo_msg(
"Subtract spatial sinfo_median to each cube plane");
270 for(n=0;n<nframes;n++) {
271 sinfo_msg(
"process cube %d\n",n);
272 sinfo_new_sinfoni_correct_median_it(&(cube_object[n]));
276 for(z=0;z<onp;z+=z_stp) {
277 z_siz=(z_stp < (onp-z)) ? z_stp : (onp-z);
280 sinfo_msg(
"Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n",
283 for(j=z_min;j<z_max;j++) {
285 check_nomsg(j_img=cpl_image_new(size_x,size_y,CPL_TYPE_FLOAT));
286 check_nomsg(cpl_imagelist_set(cube_jitter,j_img,j));
287 check_nomsg(m_img = cpl_image_new(size_x,size_y,CPL_TYPE_FLOAT));
288 check_nomsg(cpl_imagelist_set(cube_mask,m_img,j));
291 sinfo_new_combine_jittered_cubes_thomas_range(cube_object,
302 sinfo_new_combine_jittered_cubes_range(cube_object,
315 sinfo_new_convert_0_to_ZERO_for_cubes(cube_jitter) ;
317 name_m=
"out_cube_mask.fits";
321 check_nomsg(product_frame = cpl_frame_new());
322 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
323 check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE_COMBINE_PROCUBE));
324 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
325 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
326 check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL)) ;
329 check(cpl_dfs_setup_product_header(plist, product_frame,
331 "sinfo_utl_cube_combine",
332 "SINFONI", KEY_VALUE_HPRO_DID,NULL),
333 "Problem in the product DFS-compliance") ;
335 check(cpl_imagelist_save(cube_jitter, name_o, CPL_BPP_IEEE_FLOAT, plist,
336 CPL_IO_DEFAULT),
"Could not save product");
337 check_nomsg(cpl_frameset_insert(framelist, product_frame));
340 check_nomsg(prod_frm = cpl_frame_new());
341 check_nomsg(cpl_frame_set_filename(prod_frm, name_m)) ;
342 check_nomsg(cpl_frame_set_tag(prod_frm, SI_UTL_CUBE_COMBINE_PROMASK)) ;
343 check_nomsg(cpl_frame_set_type(prod_frm, CPL_FRAME_TYPE_IMAGE)) ;
344 check_nomsg(cpl_frame_set_group(prod_frm, CPL_FRAME_GROUP_PRODUCT)) ;
345 check_nomsg(cpl_frame_set_level(prod_frm, CPL_FRAME_LEVEL_FINAL)) ;
347 check(cpl_imagelist_save(cube_mask, name_m, CPL_BPP_IEEE_FLOAT, plist,
348 CPL_IO_DEFAULT),
"Could not save product");
349 check_nomsg(cpl_frameset_insert(framelist, prod_frm));
352 sinfo_free_imagelist(&cube_jitter) ;
353 sinfo_free_image(&image) ;
354 sinfo_free_imagelist(&cube_mask) ;
357 if(cube_object != NULL) {
358 for (i=0;i< nframes;i++){
359 sinfo_free_imagelist(&(cube_object[i]));
361 sinfo_free_array_imagelist(&cube_object);
363 sinfo_free_propertylist(&plist);
368 sinfo_free_double(×);
369 sinfo_free_float(&offsetx);
370 sinfo_free_float(&offsety);
373 if (cpl_error_get_code()) {
#define sinfo_msg_error(...)
Print an error message.