X-shooter Pipeline Reference Manual 3.8.15
xsh_format.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2012-12-18 14:15:45 $
23 * $Revision: 1.23 $
24*/
25
32/*----------------------------------------------------------------------------*/
35/*-----------------------------------------------------------------------------
36 Includes
37 -----------------------------------------------------------------------------*/
38
39#include <math.h>
40#include <xsh_drl.h>
41
42#include <xsh_utils_table.h>
43#include <xsh_badpixelmap.h>
44#include <xsh_data_pre.h>
45#include <xsh_dfs.h>
46#include <xsh_pfits.h>
47#include <xsh_error.h>
48#include <xsh_msg.h>
49#include <xsh_fit.h>
50#include <xsh_data_instrument.h>
52#include <xsh_data_rec.h>
53#include <xsh_ifu_defs.h>
54#include <xsh_data_image_3d.h>
55#include <xsh_data_pre_3d.h>
56
57#include <cpl.h>
58
59/*-----------------------------------------------------------------------------
60 Functions prototypes
61 -----------------------------------------------------------------------------*/
62
63/*-----------------------------------------------------------------------------
64 Implementation
65 -----------------------------------------------------------------------------*/
66
67static void fill_img( cpl_image * img, int ilambda, cpl_image * down,
68 cpl_image * cen, cpl_image * up, int up_shift, int cen_shift)
69{
70 int nx, ny, j ;
71
72
73 check(nx = cpl_image_get_size_x( down ));
74 check(ny = cpl_image_get_size_y( down));
75 xsh_msg_dbg_high( "fill image at %d (%d x %d )", ilambda, nx, ny ) ;
76
77 for( j = 1 ; j <= ny ; j++ ) {
78 int rej ;
79 double flux ;
80
81 check(flux = cpl_image_get( down, ilambda+1, j, &rej )) ;
82 check(cpl_image_set( img, 1, j+cen_shift, flux )) ;
83 }
84
85 check(nx = cpl_image_get_size_x( cen));
86 check(ny = cpl_image_get_size_y( cen));
87
88 for( j = 1 ; j <= ny ; j++ ) {
89 int rej ;
90 double flux ;
91
92 check(flux = cpl_image_get( cen, ilambda+1, j, &rej )) ;
93 check(cpl_image_set( img, 2, j+cen_shift, flux ) );
94 }
95
96 check(nx = cpl_image_get_size_x( up ));
97 check(ny = cpl_image_get_size_y( up));
98 for( j = 1 ; j <= ny ; j++ ) {
99 int rej ;
100 double flux ;
101
102 check(flux = cpl_image_get( up, ilambda+1, j, &rej )) ;
103 check(cpl_image_set( img, 3, j+up_shift, flux ) );
104 }
105
106 cleanup:
107 return ;
108}
109
110static void make_data_cube( xsh_pre_3d * pre_3d, xsh_pre * pre_down,
111 xsh_pre * pre_cen, xsh_pre * pre_up )
112{
113 int nx, ny, nz, i ;
114 cpl_image * cur_img = NULL ;
115 int up_shift=0;
116 int cen_shift =0;
117
118 nx = xsh_pre_3d_get_nx( pre_3d ) ;
119 ny = xsh_pre_3d_get_ny( pre_3d ) ;
120 nz = xsh_pre_3d_get_nz( pre_3d ) ;
121
122 xsh_msg( "Build data cube: %d x %d x %d", nx, ny, nz);
123
124 for( i = 0 ; i<nz ; i++ ) {
125 /* Data */
126 /* fill pseudo image and insert into data cube */
127 check( cur_img = cpl_image_new( nx, ny, CPL_TYPE_FLOAT ) ) ;
128 check(fill_img( cur_img, i, pre_down->data, pre_cen->data, pre_up->data,
129 up_shift,cen_shift)) ;
130 check( xsh_image_3d_insert( pre_3d->data, cur_img, i ) ) ;
131 xsh_free_image( &cur_img ) ;
132 /* Errs */
133 check( cur_img = cpl_image_new( nx, ny, CPL_TYPE_FLOAT ) ) ;
134 check(fill_img( cur_img, i, pre_down->errs, pre_cen->errs, pre_up->errs,
135 up_shift,cen_shift)) ;
136 check( xsh_image_3d_insert( pre_3d->errs, cur_img, i ) ) ;
137 xsh_free_image( &cur_img ) ;
138 /* Qual */
139 check( cur_img = cpl_image_new( nx, ny, CPL_TYPE_INT ) ) ;
140 check(fill_img( cur_img, i, pre_down->qual, pre_cen->qual, pre_up->qual,
141 up_shift,cen_shift)) ;
142 check( xsh_image_3d_insert( pre_3d->qual, cur_img, i ) ) ;
143 xsh_free_image( &cur_img ) ;
144 }
145
146 cleanup:
147 xsh_free_image( &cur_img ) ;
148 return ;
149}
150
151
152cpl_frame* xsh_format( cpl_frameset *spectrum_frame_set,
153 const char *result_name, xsh_instrument * instrument,
154 const char* rec_prefix)
155{
156 cpl_frame * result = NULL ;
157 //xsh_image_3d * flux_3d = NULL;
158 //xsh_image_3d * errs_3d = NULL;
159 //xsh_image_3d * qual_3d = NULL ;
160 xsh_pre * pre_down = NULL, * pre_cen = NULL, * pre_up = NULL ;
161 cpl_frame * frame_down = NULL, * frame_cen = NULL, * frame_up = NULL ;
162 int nslitlet = 3, nslit, nlambda ;
163 int nslit_up, nslit_lo, nslit_cen;
164 char tag[256];
165 char pcatg[256];
166 xsh_pre_3d * pre_3d = NULL ;
167 double lambda_min, lambda_max, lambda_step ;
168 double crval2 = 0.0, cdelt2=0.0;
169
170
171 XSH_ASSURE_NOT_NULL( spectrum_frame_set ) ;
172 XSH_ASSURE_NOT_NULL( result_name ) ;
174
175 check( frame_down = cpl_frameset_get_frame( spectrum_frame_set, 0));
176 check( pre_down = xsh_pre_load( frame_down, instrument));
177 check( frame_cen = cpl_frameset_get_frame( spectrum_frame_set, 1));
178 check( pre_cen = xsh_pre_load( frame_cen, instrument));
179 check( frame_up = cpl_frameset_get_frame( spectrum_frame_set, 2));
180 check( pre_up = xsh_pre_load( frame_up, instrument));
181
182 /* Retrieve lambda_min, max and step for calculation of
183 KeyWords CDELT3, CRVAL3, etc*/
184 check(lambda_min=xsh_pfits_get_rectify_lambda_min( pre_down->data_header));
185 check(lambda_max=xsh_pfits_get_rectify_lambda_max( pre_down->data_header));
187 xsh_msg( "Rect Lambda min, max, bin: %lf, %lf, %lf", lambda_min, lambda_max,
188 lambda_step) ;
189
190 nslit_lo = xsh_pre_get_ny( pre_down);
191 nslit_up = xsh_pre_get_ny( pre_up);
192 nslit_cen = xsh_pre_get_ny( pre_cen);
193
194 nslit = nslit_cen;
195 check( crval2 = xsh_pfits_get_crval2(pre_cen->data_header));
196 check( cdelt2 = xsh_pfits_get_cdelt2(pre_cen->data_header));
197
198 if (nslit_up > nslit_cen){
199 nslit += nslit_up-nslit_cen;
200 crval2 -= (nslit_up-nslit_cen)*cdelt2;
201 }
202 if (nslit_lo > nslit_cen){
203 nslit += nslit_lo-nslit_cen;
204 }
205
206 nlambda = xsh_pre_get_nx( pre_down);
207
208 xsh_msg("nslit : lo %d cen %d up %d",nslit_lo,nslit_cen,nslit_up);
209
210 check( pre_3d = xsh_pre_3d_new( nslitlet, nslit, nlambda));
211 xsh_msg( "Pre_3d created: %dx%dx%d", nslitlet, nslit, nlambda);
212
213 //check( flux_3d = xsh_pre_3d_get_data( pre_3d));
214 //check( errs_3d = xsh_pre_3d_get_errs( pre_3d));
215 //check( qual_3d = xsh_pre_3d_get_qual( pre_3d));
216
217 /* Rotate up and down by 180 degress */
218 check( xsh_pre_flip( pre_down, 0));
219 check( xsh_pre_flip( pre_up, 0));
220
221 make_data_cube( pre_3d, pre_down, pre_cen, pre_up);
222
223 /* Get headers and set PRO.CATG */
224 check( cpl_propertylist_append( pre_3d->data_header,
225 pre_cen->data_header));
226 check( cpl_propertylist_append( pre_3d->errs_header,
227 pre_cen->errs_header));
228 check( cpl_propertylist_append( pre_3d->qual_header,
229 pre_cen->qual_header));
230
231 sprintf(pcatg,"%s_%s",rec_prefix,
233
234 xsh_msg( " Setting PRO.CATG '%s'", pcatg ) ;
235 check( xsh_pfits_set_pcatg( pre_3d->data_header, pcatg));
236 check( xsh_pfits_set_pcatg( pre_3d->errs_header, pcatg));
237 check( xsh_pfits_set_pcatg( pre_3d->qual_header, pcatg));
238
239 check(xsh_pfits_set_wcs1(pre_3d->data_header, 1.0, -0.6, 0.6));
240 check(xsh_pfits_set_wcs1(pre_3d->errs_header, 1.0, -0.6, 0.6));
241 check(xsh_pfits_set_wcs1(pre_3d->qual_header, 1.0, -0.6, 0.6));
242
243 check( xsh_pfits_set_crval2( pre_3d->data_header, crval2));
244 check( xsh_pfits_set_crval2( pre_3d->errs_header, crval2));
245 check( xsh_pfits_set_crval2( pre_3d->qual_header, crval2));
246
247 check(xsh_pfits_set_wcs3(pre_3d->data_header, 0.5, lambda_min, lambda_step));
248 check(xsh_pfits_set_wcs3(pre_3d->errs_header, 0.5, lambda_min, lambda_step));
249 check(xsh_pfits_set_wcs3(pre_3d->qual_header, 0.5, lambda_min, lambda_step));
250
251
252/* the fdollowing should be done using more compact functions as: */
256
257 xsh_msg( "Saving %s", result_name) ;
258
259 check( result = xsh_pre_3d_save( pre_3d, result_name, 0));
260
261 sprintf(tag,"%s_%s",rec_prefix,
263
264 xsh_msg( " Setting TAG '%s'", tag);
265 check( cpl_frame_set_tag( result, tag));
266 check( cpl_frame_set_group( result, CPL_FRAME_GROUP_PRODUCT));
267 check( cpl_frame_set_level( result, CPL_FRAME_LEVEL_FINAL));
268 check(cpl_frame_set_type( result, CPL_FRAME_TYPE_IMAGE));
269
270 cleanup:
271 xsh_pre_free( &pre_down);
272 xsh_pre_free( &pre_cen);
273 xsh_pre_free( &pre_up);
274 xsh_pre_3d_free( &pre_3d);
275 return result;
276}
277/*---------------------------------------------------------------------------*/
278
279/*---------------------------------------------------------------------------*/
286/*---------------------------------------------------------------------------*/
287static int* create_sky_mask( cpl_frame *sky_line_frame, int size,
288 double lambda_min, double lambda_step,
290{
291 int *sky_mask = NULL;
292 const char* skymask_name = NULL;
293 cpl_table *skymask_table = NULL;
294 float *skymask_data = NULL;
295 int irow, nrow;
296 double fwhm =0.0, sky_min, sky_max;
297 int isky_min, isky_max, imask;
298 double resolution;
299
300 XSH_CALLOC( sky_mask, int, size);
301
303 if ( sky_line_frame != NULL){
304 resolution = xsh_resolution_get( instrument, 0);
305 check( skymask_name = cpl_frame_get_filename( sky_line_frame));
306 XSH_TABLE_LOAD( skymask_table, skymask_name);
307 /* sort wavelength */
308 check( xsh_sort_table_1( skymask_table, "WAVELENGTH", CPL_FALSE));
309 check( skymask_data = cpl_table_get_data_float( skymask_table,
310 "WAVELENGTH"));
311 check( nrow = cpl_table_get_nrow( skymask_table));
312
313 xsh_msg_dbg_low("lambda min %f, step %f", lambda_min, lambda_step);
314
315 for( irow=0; irow < nrow; irow++){
316 fwhm = skymask_data[irow]/resolution;
317 sky_min = skymask_data[irow]-fwhm;
318 sky_max = skymask_data[irow]+fwhm;
319 isky_min = (int)xsh_round_double((sky_min-lambda_min)/lambda_step);
320 isky_max = (int)xsh_round_double((sky_max-lambda_min)/lambda_step);
321 for( imask=isky_min; imask <=isky_max; imask++){
322 sky_mask[imask] = 1;
323 }
324 }
325 }
326 cleanup:
327 if ( cpl_error_get_code() != CPL_ERROR_NONE){
328 XSH_FREE( sky_mask);
329 }
330 XSH_TABLE_FREE( skymask_table);
331 return sky_mask;
332}
333/*---------------------------------------------------------------------------*/
334
335/*---------------------------------------------------------------------------*/
342/*---------------------------------------------------------------------------*/
343void xsh_center_cube( cpl_frame *cube_frame, cpl_frame *sky_line_frame,
344 int chunk_size, xsh_instrument *instrument)
345{
346 xsh_pre_3d *cube = NULL;
347 xsh_image_3d *cube_data_img = NULL;
348 int cube_x, cube_y, cube_z;
349 float *cube_data = NULL;
350 cpl_propertylist *header = NULL;
351 //double crval1;
352 double crval2, crval3;
353 //double crpix1;
354 //double crpix2;
355 //double crpix3;
356 //double cdelt1;
357 double cdelt2, cdelt3;
358 double *median = NULL;
359 int y, z, zmed;
360 cpl_vector *coadd_vect = NULL;
361 cpl_vector *positions = NULL;
362 double x0= 0.0,sigma =0.0, area=0.0, offset=0.0;
363 int median_size, bad_fit, sky_line;
364 cpl_vector *med_vect = NULL;
365 double shift_z;
366 int *sky_mask = NULL;
367
368 XSH_ASSURE_NOT_NULL( cube_frame);
370
371 check( cube = xsh_pre_3d_load( cube_frame));
372 header = cube->data_header;
373
374 check( cube_data_img = xsh_pre_3d_get_data( cube));
375 check( cube_x = xsh_image_3d_get_size_x( cube_data_img));
376 check( cube_y = xsh_image_3d_get_size_y( cube_data_img));
377 check( cube_z = xsh_image_3d_get_size_z( cube_data_img));
378
379 //check( crpix1 = xsh_pfits_get_crpix1( header));
380 //check( crval1 = xsh_pfits_get_crval1( header));
381 //check( cdelt1 = xsh_pfits_get_cdelt1( header));
382
383 //check( crpix2 = xsh_pfits_get_crpix2( header));
384 check( crval2 = xsh_pfits_get_crval2( header));
385 check( cdelt2 = xsh_pfits_get_cdelt2( header));
386
387 //check( crpix3 = xsh_pfits_get_crpix3( header));
388 check( crval3 = xsh_pfits_get_crval3( header));
389 check( cdelt3 = xsh_pfits_get_cdelt3( header));
390
391 check( cube_data = (float*)xsh_image_3d_get_data( cube_data_img));
392
393
394 /* create sky mask */
395 check( sky_mask = create_sky_mask( sky_line_frame, cube_z, crval3, cdelt3,
396 instrument));
397
398 XSH_MALLOC( median, double, cube_z);
399 median_size = 0;
400 bad_fit = 0;
401 sky_line = 0;
402 check( coadd_vect = cpl_vector_new( cube_y));
403 check( positions = cpl_vector_new( cube_y));
404
405 for( y=0; y<cube_y; y++){
406 cpl_vector_set( positions, y, y);
407 }
408
409 for(z=0; z< (cube_z-chunk_size); z+=chunk_size){
410 for( y=0; y<cube_y; y++){
411 cpl_vector_set( coadd_vect, y, 0);
412 }
413 for( zmed=z; zmed< (z+chunk_size); zmed++){
414 if (sky_mask[zmed] == 0){
415 for( y=0; y<cube_y; y++){
416 double y_val;
417
418 y_val = cpl_vector_get( coadd_vect, y);
419 y_val += cube_data[cube_x*cube_y*zmed+cube_x*y+1];
420 cpl_vector_set( coadd_vect, y, y_val);
421 }
422 }
423 else{
424 sky_line++;
425 }
426 }
427 cpl_vector_fit_gaussian( positions, NULL, coadd_vect, NULL,CPL_FIT_ALL,
428 &x0,&sigma,&area,&offset,NULL,NULL,NULL);
429
430 if (cpl_error_get_code() != CPL_ERROR_NONE){
432 bad_fit++;
433 }
434 else{
435 double slit_cen_fit;
436
437 slit_cen_fit = crval2+x0*cdelt2;
438 median[median_size] = slit_cen_fit;
439 median_size++;
440 }
441 }
442 xsh_msg(" Statistics of gaussian fit bad %d lines, good %d lines, sky lines %d",
443 bad_fit, median_size, sky_line);
444 check( med_vect = cpl_vector_wrap( median_size, median));
445 shift_z = cpl_vector_get_median( med_vect);
446 xsh_msg(" Measured object shift from gaussian fit: %f arcsec\n", shift_z);
447
448 /* apply shift in wcs */
449 crval2 += shift_z;
450
451 cleanup:
452 xsh_pre_3d_free( &cube);
453 XSH_FREE( sky_mask);
454 XSH_FREE( median);
455 xsh_free_vector( &positions);
456 xsh_free_vector( &coadd_vect);
457 xsh_unwrap_vector( &med_vect);
458 return;
459}
460/*---------------------------------------------------------------------------*/
461
462
463/*---------------------------------------------------------------------------*/
471/*---------------------------------------------------------------------------*/
472cpl_frame* xsh_cube( cpl_frameset *merge2d_frameset,
474 const char* rec_prefix)
475{
476
477 cpl_frame *down_frame = NULL, *cen_frame = NULL, *up_frame = NULL;
478 cpl_frame *result = NULL;
479 xsh_pre *pre_down = NULL, *pre_cen = NULL, *pre_up = NULL;
480 int nslitlet = 3, nslit, nlambda;
481 xsh_pre_3d * pre_3d = NULL;
482 double crpix2=0.0, crval2=0.0, cdelt2=0.0;
483 double crpix3=0.0, crval3=0.0, cdelt3=0.0;
484 char pcatg[256];
485 char result_name[256];
486 double waveref, sref_down, sref_up, sref_cen;
487
488 XSH_ASSURE_NOT_NULL( merge2d_frameset);
490 XSH_ASSURE_NOT_NULL( rec_prefix);
491
492 check( down_frame = cpl_frameset_get_frame( merge2d_frameset, 0));
493 check( pre_down = xsh_pre_load( down_frame, instrument));
494 check( cen_frame = cpl_frameset_get_frame( merge2d_frameset, 1));
495 check( pre_cen = xsh_pre_load( cen_frame, instrument));
496 check( up_frame = cpl_frameset_get_frame( merge2d_frameset, 2));
497 check( pre_up = xsh_pre_load( up_frame, instrument));
498
499 /* flip UP and DOWN images around the horizontal */
500 check( xsh_pre_flip( pre_down, 0));
501 check( xsh_pre_flip( pre_up, 0));
502
503 /* Retrieve lambda_min, max and step for calculation of
504 KeyWords CDELT3, CRVAL3, etc*/
505 check( crpix3 = xsh_pfits_get_crpix1( pre_cen->data_header));
506 check( crval3 = xsh_pfits_get_crval1( pre_cen->data_header));
507 check( cdelt3 = xsh_pfits_get_cdelt1( pre_cen->data_header));
508
509 check( nlambda = xsh_pre_get_nx( pre_down));
510 check( nslit = xsh_pre_get_ny( pre_down));
511
512 check( pre_3d = xsh_pre_3d_new( nslitlet, nslit, nlambda));
513 make_data_cube( pre_3d, pre_down, pre_cen, pre_up);
514
515 /* Get headers and set PRO.CATG */
516 check( cpl_propertylist_append( pre_3d->data_header,
517 pre_cen->data_header));
518 check( cpl_propertylist_append( pre_3d->errs_header,
519 pre_cen->errs_header));
520 check( cpl_propertylist_append( pre_3d->qual_header,
521 pre_cen->qual_header));
522
523 sprintf(pcatg, "%s_%s",rec_prefix,
525
526 check( xsh_pfits_set_pcatg( pre_3d->data_header, pcatg));
527 check( xsh_pfits_set_pcatg( pre_3d->errs_header, pcatg));
528 check( xsh_pfits_set_pcatg( pre_3d->qual_header, pcatg));
529
530 /* slitlet direction */
531 check(xsh_pfits_set_wcs1(pre_3d->data_header, 1.0, -0.6, 0.6));
532 check(xsh_pfits_set_wcs1(pre_3d->errs_header, 1.0, -0.6, 0.6));
533 check(xsh_pfits_set_wcs1(pre_3d->qual_header, 1.0, -0.6, 0.6));
534
535 check( xsh_pfits_set_cunit1( pre_3d->data_header, "arcsec"));
536 check( xsh_pfits_set_cunit1( pre_3d->errs_header, "arcsec"));
537 check( xsh_pfits_set_cunit1( pre_3d->qual_header, "arcsec"));
538
539 /* slit direction */
540 check( crpix2 = xsh_pfits_get_crpix2(pre_cen->data_header));
541 check( crval2 = xsh_pfits_get_crval2(pre_cen->data_header));
542 check( cdelt2 = xsh_pfits_get_cdelt2(pre_cen->data_header));
543
544 check(xsh_pfits_set_wcs2(pre_3d->data_header, crpix2, crval2, cdelt2));
545 check(xsh_pfits_set_wcs2(pre_3d->errs_header, crpix2, crval2, cdelt2));
546 check(xsh_pfits_set_wcs2(pre_3d->qual_header, crpix2, crval2, cdelt2));
547
548 check( xsh_pfits_set_cunit2( pre_3d->data_header, "arcsec"));
549 check( xsh_pfits_set_cunit2( pre_3d->errs_header, "arcsec"));
550 check( xsh_pfits_set_cunit2( pre_3d->qual_header, "arcsec"));
551
552 /* wavelength direction */
553 check( crpix3 = xsh_pfits_get_crpix1( pre_cen->data_header));
554
555 check(xsh_pfits_set_wcs3(pre_3d->data_header, crpix3, crval3, cdelt3));
556 check(xsh_pfits_set_wcs3(pre_3d->errs_header, crpix3, crval3, cdelt3));
557 check(xsh_pfits_set_wcs3(pre_3d->qual_header, crpix3, crval3, cdelt3));
558
559 check( xsh_pfits_set_cunit3( pre_3d->data_header, "nm"));
560 check( xsh_pfits_set_cunit3( pre_3d->errs_header, "nm"));
561 check( xsh_pfits_set_cunit3( pre_3d->qual_header, "nm"));
562
563 /* the fdollowing should be done using more compact functions as: */
567
568
569 /* add LAMBDA_REF / SLIT_REF if they are relevant */
570 waveref = xsh_pfits_get_shiftifu_lambdaref( pre_down->data_header);
571 sref_down = xsh_pfits_get_shiftifu_slitref( pre_down->data_header);
572 sref_cen = xsh_pfits_get_shiftifu_slitref( pre_cen->data_header);
573 sref_up = xsh_pfits_get_shiftifu_slitref( pre_up->data_header);
574
575 if ( cpl_error_get_code() == CPL_ERROR_NONE){
580 }
582
583 sprintf( result_name, "%s.fits", pcatg);
584
585 check( result = xsh_pre_3d_save( pre_3d, result_name, 1));
586
587 check( cpl_frame_set_tag( result, pcatg));
588 check( cpl_frame_set_group( result, CPL_FRAME_GROUP_PRODUCT));
589 check( cpl_frame_set_level( result, CPL_FRAME_LEVEL_FINAL));
590 check(cpl_frame_set_type( result, CPL_FRAME_TYPE_IMAGE));
591
592 cleanup:
593 if ( cpl_error_get_code() != CPL_ERROR_NONE){
594 xsh_free_frame( &result);
595 }
596 xsh_pre_free( &pre_down);
597 xsh_pre_free( &pre_cen);
598 xsh_pre_free( &pre_up);
599 xsh_pre_3d_free( &pre_3d);
600 return result;
601}
602/*---------------------------------------------------------------------------*/
603
static double sigma
static xsh_instrument * instrument
static float lambda_step
void * xsh_image_3d_get_data(xsh_image_3d *img_3d)
cpl_error_code xsh_image_3d_insert(xsh_image_3d *img_3d, cpl_image *img, int iz)
int xsh_image_3d_get_size_x(xsh_image_3d *img_3d)
int xsh_image_3d_get_size_y(xsh_image_3d *img_3d)
int xsh_image_3d_get_size_z(xsh_image_3d *img_3d)
void xsh_pre_3d_free(xsh_pre_3d **pre_3d)
int xsh_pre_3d_get_nx(const xsh_pre_3d *pre)
Get nx of pre_3d structure.
xsh_pre_3d * xsh_pre_3d_load(cpl_frame *frame)
Load a xsh_pre_3d structure from a frame.
int xsh_pre_3d_get_nz(const xsh_pre_3d *pre)
Get nz of pre_3d structure.
cpl_frame * xsh_pre_3d_save(const xsh_pre_3d *pre, const char *filename, int temp)
Save PRE_3D on disk.
xsh_pre_3d * xsh_pre_3d_new(int nx, int ny, int nz)
Create new PRE image.
int xsh_pre_3d_get_ny(const xsh_pre_3d *pre)
Get ny of pre_3d structure.
xsh_image_3d * xsh_pre_3d_get_data(xsh_pre_3d *pre_3d)
Get data.
void xsh_pre_flip(xsh_pre *pre, int angle)
Flip an image on a given miror line.
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
Definition: xsh_data_pre.c:849
int xsh_pre_get_ny(const xsh_pre *pre)
Get ny of pre structure.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
Definition: xsh_data_pre.c:823
int xsh_pre_get_nx(const xsh_pre *pre)
Get nx of pre structure.
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_reset()
Definition: xsh_error.h:87
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
static void make_data_cube(xsh_pre_3d *pre_3d, xsh_pre *pre_down, xsh_pre *pre_cen, xsh_pre *pre_up)
Definition: xsh_format.c:110
static int * create_sky_mask(cpl_frame *sky_line_frame, int size, double lambda_min, double lambda_step, xsh_instrument *instrument)
Create a sky mask from a SKY LINE lIST where flag sky lines are 1.
Definition: xsh_format.c:287
cpl_frame * xsh_cube(cpl_frameset *merge2d_frameset, xsh_instrument *instrument, const char *rec_prefix)
Create a cube.
Definition: xsh_format.c:472
cpl_frame * xsh_format(cpl_frameset *spectrum_frame_set, const char *result_name, xsh_instrument *instrument, const char *rec_prefix)
Definition: xsh_format.c:152
void xsh_center_cube(cpl_frame *cube_frame, cpl_frame *sky_line_frame, int chunk_size, xsh_instrument *instrument)
Shift a cube to center object at 0 arcsec.
Definition: xsh_format.c:343
static void fill_img(cpl_image *img, int ilambda, cpl_image *down, cpl_image *cen, cpl_image *up, int up_shift, int cen_shift)
Definition: xsh_format.c:67
const char * xsh_instrument_mode_tostring(xsh_instrument *i)
Get the string associated with a mode.
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
double xsh_resolution_get(xsh_instrument *instrument, double slit)
Get the resoltion.
int size
int * y
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
#define xsh_msg_dbg_low(...)
Definition: xsh_msg.h:48
#define xsh_msg_dbg_high(...)
Definition: xsh_msg.h:40
cpl_error_code xsh_pfits_set_wcs2(cpl_propertylist *header, const double crpix2, const double crval2, const double cdelt2)
Definition: xsh_pfits.c:4322
double xsh_pfits_get_crval2(const cpl_propertylist *plist)
find out the crval2
Definition: xsh_pfits.c:1926
void xsh_pfits_set_shiftifu_slitcenref(cpl_propertylist *plist, double value)
Definition: xsh_pfits.c:4074
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
Definition: xsh_pfits.c:1008
double xsh_pfits_get_cdelt2(const cpl_propertylist *plist)
find out the cdelt2
Definition: xsh_pfits.c:2216
double xsh_pfits_get_rectify_lambda_min(cpl_propertylist *plist)
find out the rectify lambda min
Definition: xsh_pfits.c:3319
double xsh_pfits_get_shiftifu_lambdaref(cpl_propertylist *plist)
Definition: xsh_pfits.c:4030
double xsh_pfits_get_cdelt3(const cpl_propertylist *plist)
find out the cdelt3
Definition: xsh_pfits.c:2235
double xsh_pfits_get_rectify_bin_lambda(cpl_propertylist *plist)
find out the rectify lambda binning
Definition: xsh_pfits.c:3284
void xsh_pfits_set_shiftifu_lambdaref(cpl_propertylist *plist, double value)
Definition: xsh_pfits.c:4015
void xsh_pfits_set_shiftifu_slitdownref(cpl_propertylist *plist, double value)
Definition: xsh_pfits.c:4059
cpl_error_code xsh_pfits_set_wcs3(cpl_propertylist *header, const double crpix3, const double crval3, const double cdelt3)
Definition: xsh_pfits.c:4336
double xsh_pfits_get_shiftifu_slitref(cpl_propertylist *plist)
Definition: xsh_pfits.c:4104
void xsh_pfits_set_cunit3(cpl_propertylist *plist, const char *value)
Write the CUNIT1 value.
Definition: xsh_pfits.c:2652
void xsh_pfits_set_shiftifu_slitupref(cpl_propertylist *plist, double value)
Definition: xsh_pfits.c:4089
double xsh_pfits_get_crpix1(const cpl_propertylist *plist)
find out the CRPIX1 value
Definition: xsh_pfits.c:1965
cpl_error_code xsh_pfits_set_wcs1(cpl_propertylist *header, const double crpix1, const double crval1, const double cdelt1)
Definition: xsh_pfits.c:4307
double xsh_pfits_get_cdelt1(const cpl_propertylist *plist)
find out the cdelt1
Definition: xsh_pfits.c:2196
void xsh_pfits_set_cunit1(cpl_propertylist *plist, const char *value)
Write the CUNIT1 value.
Definition: xsh_pfits.c:2622
void xsh_pfits_set_cunit2(cpl_propertylist *plist, const char *value)
Write the CUNIT2 value.
Definition: xsh_pfits.c:2637
double xsh_pfits_get_crpix2(const cpl_propertylist *plist)
find out the CRPIX2 value
Definition: xsh_pfits.c:1982
double xsh_pfits_get_crval1(const cpl_propertylist *plist)
find out the crval1
Definition: xsh_pfits.c:1907
void xsh_pfits_set_crval2(cpl_propertylist *plist, double value)
Write the CRVAL2 value.
Definition: xsh_pfits.c:2544
double xsh_pfits_get_rectify_lambda_max(cpl_propertylist *plist)
find out the rectify lambda max
Definition: xsh_pfits.c:3336
double xsh_pfits_get_crval3(const cpl_propertylist *plist)
find out the crval3
Definition: xsh_pfits.c:1946
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
Definition: xsh_utils.c:2345
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
Definition: xsh_utils.c:2284
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
cpl_error_code xsh_sort_table_1(cpl_table *t, const char *column, cpl_boolean reverse)
Sort a table by one column.
cpl_error_code xsh_set_cd_matrix3d(cpl_propertylist *plist)
Set CD matrix.
Definition: xsh_utils.c:744
long xsh_round_double(double x)
Computes round(x)
Definition: xsh_utils.c:4383
cpl_propertylist * data_header
cpl_propertylist * errs_header
xsh_image_3d * data
xsh_image_3d * errs
cpl_propertylist * qual_header
xsh_image_3d * qual
cpl_image * qual
Definition: xsh_data_pre.h:71
cpl_image * data
Definition: xsh_data_pre.h:65
cpl_propertylist * data_header
Definition: xsh_data_pre.h:66
cpl_image * errs
Definition: xsh_data_pre.h:68
int nx
int ny
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_MERGE3D_IFU
Definition: xsh_dfs.h:595
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
#define XSH_MALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:49
#define XSH_CALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:56
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)