X-shooter Pipeline Reference Manual 3.8.15
xsh_scired_ifu_stare.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: 2013-02-04 12:44:59 $
23 * $Revision: 1.113 $
24 *
25*/
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*----------------------------------------------------------------------------*/
39/*----------------------------------------------------------------------------*/
42/*-----------------------------------------------------------------------------
43 Includes
44 ----------------------------------------------------------------------------*/
45
46
47/* DRL steps */
48
49/* Error handling */
50#include <xsh_error.h>
51/* Utility fonctions */
52#include <xsh_utils_image.h>
53#include <xsh_utils_ifu.h>
54#include <xsh_msg.h>
55/* DFS functions */
56#include <xsh_dfs.h>
57#include <xsh_pfits.h>
58/* DRL functions */
59#include <xsh_drl_check.h>
60#include <xsh_drl.h>
61#include <xsh_data_spectrum1D.h>
63#include <xsh_blaze.h>
64/* Library */
65#include <cpl.h>
66/* CRH Remove */
67
68/*-----------------------------------------------------------------------------
69 Defines
70 ----------------------------------------------------------------------------*/
71
72#define RECIPE_ID "xsh_scired_ifu_stare_drl"
73#define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer"
74#define RECIPE_CONTACT "amodigli@eso.org"
75
76/*-----------------------------------------------------------------------------
77 Functions prototypes
78 ----------------------------------------------------------------------------*/
79
80/*
81 * Plugin initalization, execute and cleanup handlers
82 */
83
84static int xsh_scired_ifu_stare_create(cpl_plugin *);
85static int xsh_scired_ifu_stare_exec(cpl_plugin *);
86static int xsh_scired_ifu_stare_destroy(cpl_plugin *);
87
88/* The actual executor function */
89static void xsh_scired_ifu_stare(cpl_parameterlist *, cpl_frameset *);
90
91/*-----------------------------------------------------------------------------
92 Static variables
93 ----------------------------------------------------------------------------*/
95"Reduce science exposure in IFU configuration and stare mode";
96
98"This recipe reduces science exposure in IFU configuration and stare mode\n\
99Input Frames : \n\
100 - A set of n Science frames ( n == 1 or >=3, \
101Tag = OBJECT_IFU_STARE_arm or STD_TELL_IFU_STARE_arm or STD_FLUX_IFU_STARE_arm)\n\
102 - A spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
103 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)\n\
104 - [OPTIONAL]A master dark frame (Tag = MASTER_DARK_arm)\n\
105 - A master flat frame (Tag = MASTER_FLAT_IFU_arm)\n\
106 - An AFC corrected order table frame (Tag = ORDER_TAB_AFC_IFU_arm)\n\
107 - [physmod] An AFC corrected model cfg frame (Tag = XSH_MOD_CFG_OPT_AFC_arm)\n\
108 - [poly] An AFC corrected model wavesol frame (Tag = WAVE_TAB_AFC_arm) \n\
109 - [OPTIONAL] An AFC corrected dispersion solution frame (Tag = DISP_TAB_AFC_arm)\n\
110 - [OPTIONAL] A slit map (Tag = SLIT_MAP_arm)\n\
111 - [OPTIONAL] A badpixel map (Tag = BADPIXEL_MAP_arm)\n\
112 - [OPTIONAL] A mask of telluric lines (Tag = TELL_MASK_arm)\n\
113Products : \n\
114 - 3 Spectrum order tables 2D (1 per slitlet), PRO.CATG=ORDER2D_slitlet_IFU_arm\n\
115 - 3 Spectrum merge tables 2D (1 per slitlet), PRO.CATG=MERGE2D_slitlet_IFU_arm\n\
116 - 1 Spectrum merge 3D, PRO.CATG=MERGE3D_IFU_arm\n" ;
117
118
119/*-----------------------------------------------------------------------------
120 Functions code
121 ----------------------------------------------------------------------------*/
122/*----------------------------------------------------------------------------*/
131/*----------------------------------------------------------------------------*/
132
133int cpl_plugin_get_info(cpl_pluginlist *list) {
134 cpl_recipe *recipe = NULL;
135 cpl_plugin *plugin = NULL;
136
137 recipe = cpl_calloc(1, sizeof(*recipe));
138 if ( recipe == NULL ){
139 return -1;
140 }
141
142 plugin = &recipe->interface ;
143
144 cpl_plugin_init(plugin,
145 CPL_PLUGIN_API, /* Plugin API */
146 XSH_BINARY_VERSION, /* Plugin version */
147 CPL_PLUGIN_TYPE_RECIPE, /* Plugin type */
148 RECIPE_ID, /* Plugin name */
150 xsh_scired_ifu_stare_description, /* Detailed help */
151 RECIPE_AUTHOR, /* Author name */
152 RECIPE_CONTACT, /* Contact address */
153 xsh_get_license(), /* Copyright */
157
158 cpl_pluginlist_append(list, plugin);
159
160 return (cpl_error_get_code() != CPL_ERROR_NONE);
161}
162
163/*----------------------------------------------------------------------------*/
173/*----------------------------------------------------------------------------*/
174
175static int xsh_scired_ifu_stare_create(cpl_plugin *plugin){
176 cpl_recipe *recipe = NULL;
177 cpl_parameter* p=NULL;
178 char paramname[256];
179 char recipename[256];
180 xsh_clipping_param crh_clip_param = {5.0, 5, 0.7, 0,0.3};
181 /* First param (conv_kernel) should be initialized correctly ! */
182 xsh_remove_crh_single_param crh_single = { 0.1, 5, 2.0, 4} ;
183 xsh_rectify_param rectify = { "tanh",
184 CPL_KERNEL_DEFAULT,
185 2,
188 1,
189 0, 0.};
190
191 xsh_stack_param stack_param = {"median",5.,5.};
192 /* 2nd and 3rd params should be initialized correctly */
193 xsh_localize_obj_param loc_obj =
194 {10, 0.1, 0, 0, LOC_MANUAL_METHOD, 0, 2.0,3,3,FALSE};
195 xsh_extract_param extract_par =
197 xsh_interpolate_bp_param ipol_par = {30 };
198 xsh_bary_corr_param bary_corr = {BARY_CORR_NONE };
199 /* Reset library state */
200 xsh_init();
201
202 /* Check input */
203 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
204
205 /* Get the recipe out of the plugin */
206 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
207 CPL_ERROR_TYPE_MISMATCH,
208 "Plugin is not a recipe");
209
210 recipe = (cpl_recipe *)plugin;
211
212 /* Create the parameter list in the cpl_recipe object */
213 recipe->parameters = cpl_parameterlist_new();
214 assure( recipe->parameters != NULL,
215 CPL_ERROR_ILLEGAL_OUTPUT,
216 "Memory allocation failed!");
217
218 /* Set generic parameters (common to all recipes) */
219 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
220 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
221 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
222 check(xsh_parameters_stack_create(RECIPE_ID,recipe->parameters,stack_param));
223 /* crh clipping params */
225 crh_clip_param));
226
227 /* subtract_background_params */
229
230 /* remove_crh_single */
232 crh_single )) ;
233
234 /* xsh_rectify */
236 rectify )) ;
237
238 /* xsh_localize_object */
240 loc_obj )) ;
241
242
243 /* trivial extract (Just temporary) */
245 recipe->parameters,
246 extract_par,LOCALIZATION_METHOD )) ;
247
248 /* PIPE-10061 - barycentric correction param */
250 bary_corr)) ;
251
253 recipe->parameters,ipol_par)) ;
254 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
255 "shift-offsettab-low", 0.0,
256 "Global shift of the lower slitlet slit positions, relative to the central one[arcsec]."));
257check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
258 "shift-offsettab-up", 0.0,
259 "Global shift of the upper slitlet slit positions, relative to the central one[arcsec]."));
260
261 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
262 "compute-map", TRUE,
263 "if TRUE recompute (wave and slit) maps from the dispersion solution. If sky-subtract is set to TRUE this must be set to TRUE."));
264
265 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
266 "check-afc", TRUE,
267 "Input AFC corrected model/wave solution and science frame check."\
268 "If TRUE the recipe verify that the input mode/wave solution is AFC corrected,"\
269 " its INS.OPTIi.NAME is 'Pin_0.5 ', and its OBS.ID and OBS.TARG.NAME values"\
270 " matches with the corresponding values of the science frame."));
271
272 sprintf(recipename,"xsh.%s",RECIPE_ID);
273 sprintf(paramname,"%s.%s",recipename,"flat-method");
274 check( p = cpl_parameter_new_enum( paramname,CPL_TYPE_STRING,
275 "method adopted for flat:",
276 recipename,"master",
277 2,"master","blaze"));
278
279 check(cpl_parameter_set_alias( p,CPL_PARAMETER_MODE_CLI,
280 "flat-method"));
281 check(cpl_parameterlist_append( recipe->parameters, p));
282
283 cleanup:
284 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
285 xsh_error_dump(CPL_MSG_ERROR);
286 return 1;
287 }
288 else {
289 return 0;
290 }
291}
292
293/*----------------------------------------------------------------------------*/
299/*----------------------------------------------------------------------------*/
300
301static int xsh_scired_ifu_stare_exec(cpl_plugin *plugin) {
302 cpl_recipe *recipe = NULL;
303
304 /* Check parameter */
305
306 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
307
308 /* Get the recipe out of the plugin */
309 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
310 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
311
312 recipe = (cpl_recipe *)plugin;
313
314 /* Check recipe */
315 xsh_scired_ifu_stare(recipe->parameters, recipe->frames);
316
317 cleanup:
318 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
319 xsh_error_dump(CPL_MSG_ERROR);
321 return 1;
322 }
323 else {
324 return 0;
325 }
326}
327
328/*----------------------------------------------------------------------------*/
334/*----------------------------------------------------------------------------*/
335static int xsh_scired_ifu_stare_destroy(cpl_plugin *plugin)
336{
337 cpl_recipe *recipe = NULL;
338
339 /* reset error state before detroying recipe */
341 /* Check parameter */
342 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
343
344 /* Get the recipe out of the plugin */
345 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
346 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
347
348 recipe = (cpl_recipe *)plugin;
349
350 xsh_free_parameterlist(&recipe->parameters);
351
352 cleanup:
353 if (cpl_error_get_code() != CPL_ERROR_NONE)
354 {
355 return 1;
356 }
357 else
358 {
359 return 0;
360 }
361}
362
363
364static cpl_error_code
366 xsh_rectify_param * rectify_par,
367 xsh_localize_obj_param * loc_obj_par)
368{
369
370
371 xsh_msg_dbg_low("bkg params: sampley=%d radius_y=%d",
372 backg->sampley,backg->radius_y);
373
374 xsh_msg_dbg_low("bkg params: radius_x=%d",
375 backg->radius_x);
376
377 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
378 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
379 rectify_par->rectif_bin_space);
380
381 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
382 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
383
384 return cpl_error_get_code();
385
386}
387/*--------------------------------------------------------------------------*/
395/*--------------------------------------------------------------------------*/
396
397static cpl_error_code
398xsh_params_bin_scale(cpl_frameset* raws,
400{
401
402 cpl_frame* frame=NULL;
403 const char* name=NULL;
404 cpl_propertylist* plist=NULL;
405 int binx=0;
406 int biny=0;
407
408 check(frame=cpl_frameset_get_frame(raws,0));
409 check(name=cpl_frame_get_filename(frame));
410 check(plist=cpl_propertylist_load(name,0));
413 xsh_free_propertylist(&plist);
414
415 if(biny>1) {
416
417 /* backg->sampley=backg->sampley/biny;
418 number of points of the grid in y direction.
419 Not to be bin dependent
420 */
421
422 backg->radius_y=backg->radius_y/biny;
423
424 /* bin dependent */
425
426
427 /*
428 rectify_par->rectif_radius=rectify_par->rectif_radius/biny;
429 Rectify Interpolation radius
430 For the moment not bin dependent, but for optimal results probably yes
431 */
432
433 /*
434 rectify_par->rectif_bin_lambda=rectify_par->rectif_bin_lambda/biny;
435 Rectify Wavelength Step
436 For the moment not bin dependent, but for optimal results probably yes
437 */
438
439 /*
440 loc_obj_par->loc_chunk_nb=loc_obj_par->loc_chunk_nb/biny;
441 Localization Nb of chunks
442 Not bin dependent
443 */
444
445 }
446
447
448 if(binx>1) {
449
450 backg->radius_x=backg->radius_x/binx;
451
452 /*
453 rectify_par->rectif_bin_space=rectify_par->rectif_bin_space/binx;
454 Rectify Position Step
455 For the moment not bin dependent, but for optimal results probably yes
456 */
457
458 /*
459 loc_obj_par->nod_step=loc_obj_par->nod_step/binx;
460 Step (arcsec) between A and B images in nodding mode
461 Not bin dependent
462 */
463
464 }
465
466 cleanup:
467 xsh_free_propertylist(&plist);
468 return cpl_error_get_code();
469
470}
471
472/*----------------------------------------------------------------------------*/
480/*----------------------------------------------------------------------------*/
481static void xsh_scired_ifu_stare(cpl_parameterlist* parameters,
482 cpl_frameset* frameset)
483{
484 const char* recipe_tags[3] = {XSH_OBJECT_IFU_STARE,
487 int recipe_tags_size = 3;
488
489 /* Input frames */
491 int nb_raw_frames ;
492 cpl_frameset *raws = NULL;
493 cpl_frameset *calib = NULL;
494 /* Beware, do not "free" the following input frames, they are part
495 of the input frameset */
496 cpl_frame *bpmap = NULL;
497 cpl_frame *master_bias = NULL;
498 cpl_frame *master_dark = NULL;
499 cpl_frame *master_flat = NULL;
500 cpl_frame *order_tab_edges = NULL;
501 cpl_frame *wavetab_frame = NULL;
502 cpl_frameset *wavetab_frameset = NULL ;
503 cpl_frame *model_config_frame = NULL ;
504 cpl_frame *spectral_format = NULL ;
505 cpl_frame *disp_tab_frame = NULL;
506 cpl_frame *shifttab_frame = NULL;
507
508 /* Parameters */
509 xsh_clipping_param *crh_clipping_par = NULL;
510 xsh_background_param *backg_par = NULL;
511 xsh_remove_crh_single_param *crh_single_par = NULL ;
512 xsh_rectify_param *rectify_par = NULL ;
513 xsh_localize_obj_param *loc_obj_par = NULL ;
514 int merge_par = 0;
515 xsh_extract_param *extract_par = NULL ;
516 xsh_bary_corr_param * bary_par = NULL ;
517 double offset_low =0.0;
518 double offset_up =0.0;
519
520 xsh_stack_param* stack_par=NULL;
521
522 int recipe_use_model = FALSE;
523 int do_computemap = 0;
524 int check_afc = TRUE;
525
526 /* Intermediate frames */
527 cpl_frame *slitmap_frame = NULL;
528 cpl_frame *wavemap_frame = NULL;
529 cpl_frame *crhm_frame = NULL ;
530 cpl_frame *rmbias = NULL;
531 cpl_frame *rmdark = NULL;
532 cpl_frame *rmbkg = NULL ;
533 cpl_frame *clean_frame = NULL ;
534 cpl_frame *div_frame = NULL ;
535 cpl_frameset *rect_frameset = NULL ;
536 cpl_frameset *loc_table_frameset = NULL ;
538 /* Output Frames (results)*/
539 cpl_frameset *res_2D_frameset = NULL ;
540 cpl_frame *data_cube = NULL ;
541 char div_tag[256];
542 char prefix[256];
543 const char * ftag=NULL;
544 cpl_frame* grid_backg=NULL;
545 cpl_frame* frame_backg=NULL;
546 cpl_frameset* rect_frameset_eso=NULL;
547 cpl_frameset* rect_frameset_tab=NULL;
548 char *rec_prefix = NULL;
549 int pre_overscan_corr=0;
550
551 cpl_frameset *shiftifu_frameset = NULL;
552 cpl_frameset *nshiftifu_frameset = NULL;
553 int i;
554
555 cpl_propertylist* plist=NULL;
556 const char* name=NULL;
557 const char* tag="";
558 int naxis2=0;
559 cpl_frame* qc_trace_frame=NULL;
560 int save_size=0;
561 const int peack_search_hsize=5;
562 int method=0;
563 char* flat_method = NULL;
564
565 //cpl_frame *tellmask_frame = NULL;
566 cpl_frame * blaze_frame = NULL;
567
568 /**************************************************************************/
569 /* DFS management */
570 /**************************************************************************/
571 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
572 recipe_tags, recipe_tags_size,
573 RECIPE_ID, XSH_BINARY_VERSION,
575
576 assure( instrument->mode == XSH_MODE_IFU, CPL_ERROR_ILLEGAL_INPUT,
577 "Instrument NOT in IFU Mode" ) ;
578
580 /* One should have 1 or >=3 input frames. 2 is not permitted */
581 check( nb_raw_frames = cpl_frameset_get_size( raws));
582
583 XSH_ASSURE_NOT_ILLEGAL_MSG( nb_raw_frames == 1 || nb_raw_frames >= 3,
584 "This recipe expects either one or at least 3 input raw frames" );
585
586 /**************************************************************************/
587 /* Recipe frames */
588 /**************************************************************************/
589
590 bpmap = xsh_find_master_bpmap(calib);
591
592 /* In UVB and VIS mode */
594 /* RAWS frameset must have only one file */
595 check( master_bias = xsh_find_frame_with_tag(calib,XSH_MASTER_BIAS,
596 instrument));
597 }
598
599 if(NULL==(order_tab_edges=xsh_find_frame_with_tag(calib,XSH_ORDER_TAB_AFC_IFU,
600 instrument))) {
601 xsh_msg_error("Missing frame %s_%s", XSH_ORDER_TAB_AFC_IFU,
603 goto cleanup;
604 }
605
606 /* one should have either model config frame or wave sol frame */
607 check(model_config_frame=xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
608 instrument));
609 if(model_config_frame==NULL) {
610 wavetab_frame = xsh_find_wave_tab( calib, instrument);
611 }
612 /*
613 One of model config and wave tab must be present, but only one !
614 */
615 if ( model_config_frame == NULL){
616 xsh_msg("RECIPE USE WAVE SOLUTION");
617 recipe_use_model = FALSE;
618 }
619 else{
620 xsh_msg("RECIPE USE MODEL");
621 recipe_use_model = TRUE;
622 }
623 XSH_ASSURE_NOT_ILLEGAL( (model_config_frame != NULL && wavetab_frame == NULL ) ||
624 (model_config_frame == NULL && wavetab_frame != NULL ) );
625
626 check( master_flat = xsh_find_master_flat( calib, instrument ) ) ;
627 if((master_dark = xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,
628 instrument)) == NULL){
629 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
631 }
632 check(spectral_format=xsh_find_spectral_format( calib, instrument ) ) ;
634 spectral_format));
635
636 /* OPTIONAL */
637 shiftifu_frameset = xsh_find_offset_tab_ifu( calib,
638 instrument);
640 /*
641 tellmask_frame = xsh_find_frame_with_tag( calib, XSH_TELL_MASK,
642 instrument);
643 xsh_error_reset() ;
644 */
645 shifttab_frame = xsh_find_frame_with_tag( calib, XSH_SHIFT_TAB_IFU,
646 instrument);
648
649 if ( recipe_use_model == FALSE){
650 check( wavetab_frameset = xsh_ifu_wavetab_create( wavetab_frame,
651 shifttab_frame, instrument));
652 }
653
654 /**************************************************************************/
655 /* Recipe parameters */
656 /**************************************************************************/
657 check( stack_par = xsh_stack_frames_get( RECIPE_ID, parameters));
659 parameters));
661 parameters));
662
664 parameters));
666 parameters));
667 rectify_par->conserve_flux=FALSE;
668 backg_par->method=TRUE;
670 parameters));
671
672 check( extract_par = xsh_parameters_extract_get( RECIPE_ID, parameters));
673
674 check( do_computemap = xsh_parameters_get_boolean( parameters, RECIPE_ID,
675 "compute-map"));
676
677 check( check_afc = xsh_parameters_get_boolean( parameters, RECIPE_ID,
678 "check-afc"));
679
680 if ( do_computemap && recipe_use_model==FALSE){
681 check( disp_tab_frame = xsh_find_disp_tab( calib, instrument));
682 }
683
685
686 /* adjust relevant parameter to binning */
688 check(xsh_params_bin_scale(raws,backg_par));
689 }
690 check(xsh_params_monitor(backg_par,rectify_par,loc_obj_par));
691
692 check( offset_low = xsh_parameters_get_double( parameters, RECIPE_ID,
693 "shift-offsettab-low"));
694
695 check( offset_up = xsh_parameters_get_double( parameters, RECIPE_ID,
696 "shift-offsettab-up"));
697
698 /* update slitlets with manual shift */
699 if ( shiftifu_frameset != NULL){
700 xsh_msg("offset low %f up %f", offset_low, offset_up);
701 check( nshiftifu_frameset = xsh_shift_offsettab( shiftifu_frameset,
702 offset_low, offset_up));
703 }
704
705 // PIPE-10061 - get barycentric corr param
706 check(bary_par = xsh_parameters_bary_corr_get( RECIPE_ID, parameters)) ;
707
708 /**************************************************************************/
709 /* Recipe code */
710 /**************************************************************************/
711
712 /* prepare RAW frames in XSH format */
713 check( xsh_prepare( raws, bpmap, master_bias, XSH_OBJECT_IFU_STARE,
714 instrument,pre_overscan_corr,CPL_TRUE));
715
716 check( rec_prefix = xsh_set_recipe_file_prefix( raws,
717 RECIPE_ID));
718
719 /* Removing Cosmic Rays (if more than 2 frames */
721 check( crhm_frame = xsh_check_remove_crh_multiple( raws, ftag,
722 stack_par,NULL, instrument, NULL, NULL));
723
724 /* Get wavemap and slitmap */
725 check( xsh_check_get_map( disp_tab_frame, order_tab_edges,
726 crhm_frame, model_config_frame, calib, instrument,
727 do_computemap, recipe_use_model, rec_prefix,
728 &wavemap_frame, &slitmap_frame));
729
730 /* Subtract bias if necessary */
731 sprintf(prefix,"%s_",rec_prefix);
732 /* AMO: here one schould check is pre-overscan was corrected */
733 check( rmbias = xsh_check_subtract_bias( crhm_frame, master_bias,
734 instrument, rec_prefix,
735 pre_overscan_corr,0));
736
737 /**************************************************************************/
738 /* Check that SCI IFU frame and AFC corrected CFG are proper */
739 /**************************************************************************/
740 check( xsh_check_afc( check_afc, model_config_frame,
741 rmbias, wavetab_frameset, order_tab_edges, disp_tab_frame,
742 instrument));
743
744 /* Subtract dark if necessary */
745 check( rmdark = xsh_check_subtract_dark( rmbias, master_dark,
746 instrument, rec_prefix));
747
748 /* Subtract background */
749 xsh_msg("Subtract inter-order background");
750 check(rmbkg = xsh_subtract_background( rmdark,
751 order_tab_edges,
752 backg_par, instrument,
753 rec_prefix,&grid_backg,
754 &frame_backg,1,1,1 ));
755
756 if ( nb_raw_frames == 1 ) {
757 char * nocrh_tag = NULL ;
758
759 nocrh_tag = xsh_stringcat_any("NOCRH_",
761 (void*)NULL) ;
762 xsh_msg( "Remove crh (single frame)" ) ;
763 check( clean_frame = xsh_remove_crh_single( rmbkg,
764 instrument,NULL,
765 crh_single_par,
766 nocrh_tag ) ) ;
767 XSH_FREE( nocrh_tag ) ;
768 }
769 else {
770 clean_frame = cpl_frame_duplicate( rmbkg) ;
771 }
772
773 xsh_msg( "---Divide by flat" ) ;
774 sprintf(div_tag,"%s_DIV_FF_%s",
776
777 check( flat_method = xsh_parameters_get_string( parameters, RECIPE_ID,
778 "flat-method"));
779
780 xsh_msg("method %s", flat_method);
781
782 if ( strcmp( flat_method, "master") == 0){
783 check( div_frame = xsh_divide_flat( clean_frame, master_flat,
784 div_tag, instrument));
785 }
786 else{
787 xsh_msg("---Create blaze image");
788 check( blaze_frame = xsh_blaze_image( master_flat, order_tab_edges,
789 instrument));
790 check( div_frame = xsh_divide_by_blaze( clean_frame,
791 blaze_frame, instrument));
792 }
793
794
795
796 xsh_msg( "---Rectify ifu");
797 rect_frameset_eso=cpl_frameset_new();
798 rect_frameset_tab=cpl_frameset_new();
799 check( rect_frameset = xsh_rectify_ifu( div_frame, order_tab_edges,
800 wavetab_frameset,
801 nshiftifu_frameset,
802 model_config_frame,
803 instrument, rectify_par,
804 spectral_format,
805 slitmap_frame, &rect_frameset_eso,
806 &rect_frameset_tab,rec_prefix ));
807
808
809 check( loc_table_frameset = xsh_localize_obj_ifu( rect_frameset, NULL,
811 loc_obj_par, NULL));
812 xsh_msg( "Merge orders with 2D frame" ) ;
813 check( res_2D_frameset = xsh_merge_ord_ifu( rect_frameset,instrument,
814 merge_par,rec_prefix ));
815
816 xsh_msg( "Build data cube");
817 /* Building 3D (data cube) */
818 check( data_cube = xsh_cube( res_2D_frameset, instrument, rec_prefix));
819
820 xsh_msg( "Saving Products for IFU" ) ;
821
822 for( i = 0 ; i<3 ; i++ ) {
823 cpl_frame * rec_frame = NULL ;
824 cpl_frame * res2d_frame = NULL ;
825
826 check( rec_frame = cpl_frameset_get_frame( rect_frameset_eso, i ) ) ;
827 check( xsh_add_product_image( rec_frame, frameset, parameters,
828 RECIPE_ID, instrument,NULL));
829
830 check( res2d_frame = cpl_frameset_get_frame( res_2D_frameset, i ) ) ;
831 check( xsh_add_product_pre( res2d_frame, frameset, parameters,
832 RECIPE_ID, instrument,NULL));
833 }
834
835 check( xsh_add_product_pre_3d( data_cube, frameset, parameters,
837
838 name=cpl_frame_get_filename(data_cube);
839 plist=cpl_propertylist_load(name,0);
840 naxis2=xsh_pfits_get_naxis2(plist);
841 xsh_free_propertylist(&plist);
842 check( qc_trace_frame=xsh_cube_qc_trace_window(data_cube,
843 instrument,tag,rec_prefix,
844 save_size+1,
845 naxis2-save_size,
846 peack_search_hsize,
847 method,0));
848
849
850#if 1
851
852 check( xsh_add_product_pre( rmbias, frameset, parameters,
853 RECIPE_ID, instrument,NULL));
854
855 check( xsh_add_product_image( rmbkg, frameset, parameters,
856 RECIPE_ID, instrument,NULL));
857
858 check( xsh_add_product_image( div_frame, frameset, parameters,
859 RECIPE_ID, instrument,NULL));
860
861 if(qc_trace_frame) {
862 check( xsh_add_product_table( qc_trace_frame, frameset,parameters,
863 RECIPE_ID, instrument,NULL));
864 }
865
866#endif
867
868 cleanup:
869 XSH_REGDEBUG("scired_ifu_stare cleanup");
870 xsh_end( RECIPE_ID, frameset, parameters );
871
872 XSH_FREE( rec_prefix);
873 XSH_FREE(crh_clipping_par);
874 XSH_FREE( backg_par ) ;
875 XSH_FREE( crh_single_par ) ;
876 XSH_FREE( rectify_par ) ;
877 XSH_FREE( loc_obj_par );
878 XSH_FREE( extract_par);
879 XSH_FREE( stack_par);
880 XSH_FREE( bary_par);
881
883 xsh_free_frameset( &raws);
884 xsh_free_frameset( &calib);
885 xsh_free_frame( &qc_trace_frame);
886 xsh_free_frame( &crhm_frame);
887 xsh_free_frame( &slitmap_frame);
888 xsh_free_frame( &wavemap_frame);
889 xsh_free_frame( &rmbias);
890 xsh_free_frame( &rmdark);
891 xsh_free_frame( &rmbkg);
892 xsh_free_frame( &grid_backg);
893 xsh_free_frame( &frame_backg);
894 xsh_free_frame( &clean_frame);
895 xsh_free_frame( &div_frame);
896 xsh_free_frameset( &wavetab_frameset) ;
897 xsh_free_frameset( &rect_frameset) ;
898 xsh_free_frameset( &loc_table_frameset) ;
899 xsh_free_frameset( &shiftifu_frameset);
900 xsh_free_frameset( &nshiftifu_frameset);
901
902 xsh_free_frameset( &res_2D_frameset) ;
903 xsh_free_frameset(&rect_frameset_eso) ;
904 xsh_free_frameset(&rect_frameset_tab) ;
905
906 xsh_free_frame( &data_cube ) ;
907 xsh_free_frame( &grid_backg ) ;
908 xsh_free_frame( &frame_backg ) ;
909 xsh_free_frame( &blaze_frame);
910 return;
911}
912
static xsh_instrument * instrument
int binx
int biny
cpl_frame * xsh_divide_by_blaze(cpl_frame *pre_frame, cpl_frame *blaze_frame, xsh_instrument *instrument)
Divide a pre image by the blaze image.
Definition: xsh_blaze.c:71
cpl_frame * xsh_blaze_image(cpl_frame *masterflat_frame, cpl_frame *order_frame, xsh_instrument *instrument)
Normalize a master flat frame order by order.
Definition: xsh_blaze.c:143
cpl_frame * xsh_divide_flat(cpl_frame *frame, cpl_frame *flat, const char *tag, xsh_instrument *instr)
divide PRE frame with the master FLAT frame
Definition: xsh_divide.c:75
void xsh_prepare(cpl_frameset *frames, cpl_frame *bpmap, cpl_frame *mbias, const char *prefix, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
This function transform RAW frames dataset in PRE frames dataset attaching the default bad pixel map ...
Definition: xsh_prepare.c:122
#define XSH_REGDEBUG(...)
Definition: xsh_error.h:132
#define XSH_ASSURE_NOT_ILLEGAL(cond)
Definition: xsh_error.h:107
#define assure(CONDITION, ERROR_CODE,...)
Definition: xsh_error.h:54
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define xsh_error_reset()
Definition: xsh_error.h:87
#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg)
Definition: xsh_error.h:111
cpl_frame * xsh_cube(cpl_frameset *merge2d_frameset, xsh_instrument *instrument, const char *rec_prefix)
Create a cube.
Definition: xsh_format.c:472
cpl_frameset * xsh_ifu_wavetab_create(cpl_frame *wave_tab_frame, cpl_frame *shift_tab_frame, xsh_instrument *instr)
Create an IFU wave tab frame set.
Definition: xsh_ifu.c:71
void xsh_instrument_update_from_spectralformat(xsh_instrument *i, cpl_frame *spectralformat_frame)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
cpl_frameset * xsh_localize_obj_ifu(cpl_frameset *sci_frame, cpl_frame *skymask_frame, xsh_instrument *instrument, xsh_localize_obj_param *loc_obj_par, xsh_slit_limit_param *slit_limit_param)
cpl_frameset * xsh_merge_ord_ifu(cpl_frameset *rec_frameset, xsh_instrument *instrument, int merge_par, const char *rec_prefix)
Merge orders of the rectified frame using merge parameters.
#define xsh_msg_warning(...)
Print an warning message.
Definition: xsh_msg.h:88
#define xsh_msg_error(...)
Print an error message.
Definition: xsh_msg.h:62
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
#define xsh_msg_dbg_low(...)
Definition: xsh_msg.h:48
int xsh_pfits_get_binx(const cpl_propertylist *plist)
find out the BINX value
Definition: xsh_pfits.c:289
int xsh_pfits_get_biny(const cpl_propertylist *plist)
find out the BINY value
Definition: xsh_pfits.c:306
int xsh_pfits_get_naxis2(const cpl_propertylist *plist)
find out the NAXIS2 value
Definition: xsh_pfits.c:244
cpl_frameset * xsh_rectify_ifu(cpl_frame *sci_frame, cpl_frame *order_table_frame, cpl_frameset *wavesol_frame_set, cpl_frameset *shiftifu_frameset, cpl_frame *model_config_frame, xsh_instrument *instrument, xsh_rectify_param *rectify_par, cpl_frame *spectral_format, cpl_frame *slitmap_frame, cpl_frameset **rec_frameset_ext, cpl_frameset **rec_frameset_tab, const char *rec_prefix)
Definition: xsh_rectify.c:1014
cpl_frame * xsh_remove_crh_single(cpl_frame *sci_frame, xsh_instrument *instrument, cpl_mask *sky_map, xsh_remove_crh_single_param *single_par, const char *name)
Remove cosmic rays from a single frame.
#define RECIPE_CONTACT
static int xsh_scired_ifu_stare_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static cpl_error_code xsh_params_monitor(xsh_background_param *backg, xsh_rectify_param *rectify_par, xsh_localize_obj_param *loc_obj_par)
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_scired_ifu_stare_create(cpl_plugin *)
Setup the recipe options.
static char xsh_scired_ifu_stare_description[]
static int xsh_scired_ifu_stare_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static char xsh_scired_ifu_stare_description_short[]
static cpl_error_code xsh_params_bin_scale(cpl_frameset *raws, xsh_background_param *backg)
Scales input parameters for binning.
static void xsh_scired_ifu_stare(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
#define RECIPE_ID
#define RECIPE_AUTHOR
cpl_frame * xsh_subtract_background(cpl_frame *frame, cpl_frame *ordertable, xsh_background_param *bckg, xsh_instrument *instr, const char *prefix, cpl_frame **grid_frame, cpl_frame **frame_backg, const int save_bkg, const int save_grid, const int save_sub_bkg)
Subtract the inter-order background from PRE frame.
Definition: xsh_subtract.c:947
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
Definition: xsh_utils.c:2224
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
char * xsh_set_recipe_file_prefix(cpl_frameset *raw, const char *recipe)
Set recipe frames prefix.
Definition: xsh_utils.c:601
const char * xsh_get_license(void)
Get the pipeline copyright and license.
Definition: xsh_utils.c:1193
char * xsh_stringcat_any(const char *s,...)
Concatenate an arbitrary number of strings.
Definition: xsh_utils.c:1925
void xsh_init(void)
Reset library state.
Definition: xsh_utils.c:1160
cpl_error_code xsh_begin(cpl_frameset *frames, const cpl_parameterlist *parameters, xsh_instrument **instrument, cpl_frameset **raws, cpl_frameset **calib, const char *tag_list[], int tag_list_size, const char *recipe_id, unsigned int binary_version, const char *short_descr)
Recipe initialization.
Definition: xsh_utils.c:1244
cpl_error_code xsh_rectify_params_set_defaults(cpl_parameterlist *pars, const char *rec_id, xsh_instrument *inst, xsh_rectify_param *rectify_par)
Definition: xsh_utils.c:6681
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_error_code xsh_end(const char *recipe_id, cpl_frameset *frames, cpl_parameterlist *parameters)
Recipe termination.
Definition: xsh_utils.c:1519
@ XSH_ARM_NIR
@ XSH_MODE_IFU
const char * method
Definition: xsh_detmon_lg.c:78
cpl_frame * xsh_find_spectral_format(cpl_frameset *frames, xsh_instrument *instr)
Find spectral format frame.
Definition: xsh_dfs.c:4318
cpl_frame * xsh_find_disp_tab(cpl_frameset *frames, xsh_instrument *instr)
Find Dispersol tab frame. The frame returned should not be free by the caller.
Definition: xsh_dfs.c:4066
void xsh_add_product_pre(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr, cpl_propertylist *qclist)
Add DFS keywords to a product frame.
Definition: xsh_dfs.c:2465
void xsh_add_product_pre_3d(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr)
Add 3d product frame.
Definition: xsh_dfs.c:2627
void xsh_add_product_image(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
Definition: xsh_dfs.c:2965
void xsh_add_product_table(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
Save Table product (input frame has several extensions, 1 table per extension)
Definition: xsh_dfs.c:3146
cpl_frameset * xsh_find_offset_tab_ifu(cpl_frameset *frames, xsh_instrument *instr)
Find offset tab (One for each slitlet)
Definition: xsh_dfs.c:3832
cpl_frame * xsh_find_wave_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D or a wave tab ARC.
Definition: xsh_dfs.c:3699
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
Definition: xsh_dfs.c:3347
cpl_frame * xsh_find_master_flat(cpl_frameset *frames, xsh_instrument *instr)
Find master flat frame.
Definition: xsh_dfs.c:3426
cpl_frame * xsh_find_master_bpmap(cpl_frameset *set)
find the master bad pixel map in a set of files
Definition: xsh_dfs.c:1621
#define XSH_MOD_CFG_OPT_AFC
Definition: xsh_dfs.h:1256
#define XSH_ORDER_TAB_AFC_IFU
Definition: xsh_dfs.h:719
#define XSH_MASTER_BIAS
Definition: xsh_dfs.h:549
#define XSH_MASTER_DARK
Definition: xsh_dfs.h:550
#define XSH_STD_FLUX_IFU_STARE
Definition: xsh_dfs.h:455
#define XSH_STD_TELL_IFU_STARE
Definition: xsh_dfs.h:469
#define XSH_SHIFT_TAB_IFU
Definition: xsh_dfs.h:578
#define XSH_SLIT_BIN_SIZE_PIPE_NIR
Definition: xsh_dfs.h:101
#define XSH_OBJECT_IFU_STARE
Definition: xsh_dfs.h:230
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_WAVE_BIN_SIZE_PIPE_NIR
Definition: xsh_dfs.h:105
#define XSH_IFU_STARE_REMOVE_CRH
Definition: xsh_dfs.h:161
cpl_frame * xsh_check_remove_crh_multiple(cpl_frameset *raws, const char *ftag, xsh_stack_param *stack_par, xsh_clipping_param *crh_clipping_par, xsh_instrument *instr, cpl_imagelist **lista, cpl_image **listb)
Check function.
void xsh_check_afc(int check_flag, cpl_frame *model_frame, cpl_frame *sci_frame, cpl_frameset *wave_frameset, cpl_frame *order_tab_frame, cpl_frame *disp_tab_frame, xsh_instrument *instrument)
Check AFC frame.
cpl_frame * xsh_check_subtract_bias(cpl_frame *crhm_frame, cpl_frame *master_bias, xsh_instrument *instrument, const char *prefix, const int pre_overscan_corr, const int save_tmp)
Check function to subtract bias.
cpl_frame * xsh_check_subtract_dark(cpl_frame *rmbias_frame, cpl_frame *master_dark, xsh_instrument *instrument, const char *prefix)
Check function for dark subtraction.
void xsh_check_get_map(cpl_frame *disp_tab_frame, cpl_frame *order_tab_edges, cpl_frame *crhm_frame, cpl_frame *model_config_frame, cpl_frameset *calib, xsh_instrument *instrument, int do_computemap, int recipe_use_model, const char *rec_prefix, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame)
Check function to get wave and slit maps.
void xsh_parameters_pre_overscan(const char *recipe_id, cpl_parameterlist *plist)
void xsh_parameters_new_boolean(cpl_parameterlist *list, const char *recipe_id, const char *name, int value, const char *comment)
void xsh_parameters_stack_create(const char *recipe_id, cpl_parameterlist *list, xsh_stack_param sp)
create the RON determination parameters in a parameters list
int xsh_parameters_get_boolean(const cpl_parameterlist *list, const char *recipe_id, const char *name)
xsh_stack_param * xsh_stack_frames_get(const char *recipe_id, cpl_parameterlist *list)
get the detect arclines parameters in a parameters list
double xsh_parameters_get_double(const cpl_parameterlist *list, const char *recipe_id, const char *name)
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
xsh_localize_obj_param * xsh_parameters_localize_obj_get(const char *recipe_id, cpl_parameterlist *list)
void xsh_parameters_new_double(cpl_parameterlist *list, const char *recipe_id, const char *name, double value, const char *comment)
void xsh_parameters_localize_obj_create(const char *recipe_id, cpl_parameterlist *plist, xsh_localize_obj_param p)
void xsh_parameters_clipping_crh_create(const char *recipe_id, cpl_parameterlist *list, xsh_clipping_param p)
create the crh clipping parameters in a parameters list
xsh_extract_param * xsh_parameters_extract_get(const char *recipe_id, cpl_parameterlist *list)
void xsh_parameters_rectify_create(const char *recipe_id, cpl_parameterlist *plist, xsh_rectify_param p)
void xsh_parameters_background_create(const char *recipe_id, cpl_parameterlist *list)
create the subtract background parameters in a parameters list
void xsh_parameters_interpolate_bp_create(const char *recipe_id, cpl_parameterlist *plist, xsh_interpolate_bp_param p)
void xsh_parameters_extract_create(const char *recipe_id, cpl_parameterlist *plist, xsh_extract_param p, enum extract_method method)
xsh_bary_corr_param * xsh_parameters_bary_corr_get(const char *recipe_id, cpl_parameterlist *list)
get the barycentric correction parameters in a parameters list
xsh_rectify_param * xsh_parameters_rectify_get(const char *recipe_id, cpl_parameterlist *list)
void xsh_parameters_bary_corr_create(const char *recipe_id, cpl_parameterlist *list, xsh_bary_corr_param p)
create the barycentric correction parameters in a parameters list
void xsh_parameters_remove_crh_single_create(const char *recipe_id, cpl_parameterlist *plist, xsh_remove_crh_single_param p)
xsh_remove_crh_single_param * xsh_parameters_remove_crh_single_get(const char *recipe_id, cpl_parameterlist *list)
xsh_clipping_param * xsh_parameters_clipping_crh_get(const char *recipe_id, cpl_parameterlist *list)
get the crh clipping parameters in a parameters list
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
cpl_error_code xsh_recipe_params_check(cpl_parameterlist *parameters, xsh_instrument *instrument, const char *rec_id)
xsh_background_param * xsh_parameters_background_get(const char *recipe_id, cpl_parameterlist *list)
get the background parameters in a parameters list
char * xsh_parameters_get_string(const cpl_parameterlist *list, const char *recipe_id, const char *name)
@ BARY_CORR_NONE
@ LOC_MANUAL_METHOD
@ LOCALIZATION_METHOD
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
cpl_frameset * xsh_shift_offsettab(cpl_frameset *shiftifu_frameset, double offset_low, double offset_up)
Do a wavelet decomposition using atrous from IDL.
cpl_frame * xsh_cube_qc_trace_window(cpl_frame *frm_cube, xsh_instrument *instrument, const char *suffix, const char *rec_prefix, const int win_min, const int win_max, const int hsize, const int method, const int compute_qc)
Trace object position in a cube.