X-shooter Pipeline Reference Manual 3.8.15
xsh_util_ifu_offset.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 Sotware 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-20 15:43:22 $
23 * $Revision: 1.60 $
24 *
25*/
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*----------------------------------------------------------------------------*/
39/*----------------------------------------------------------------------------*/
42/*-----------------------------------------------------------------------------
43 Includes
44 ----------------------------------------------------------------------------*/
45
46/* DRL steps */
47
48/* Error handling */
49#include <xsh_error.h>
50/* Utility fonctions */
51#include <xsh_utils.h>
52#include <xsh_msg.h>
53/* DFS functions */
54#include <xsh_dfs.h>
55#include <xsh_pfits.h>
56#include <xsh_data_spectrum1D.h>
57#include <xsh_utils_image.h>
58#include <xsh_model_io.h>
59#include <xsh_model_utils.h>
60#include <xsh_utils_ifu.h>
63/* DRL functions */
64#include <xsh_drl.h>
65#include <xsh_drl_check.h>
66/* Library */
67#include <cpl.h>
68
69/*-----------------------------------------------------------------------------
70 Defines
71 ---------------------------------------------------------------------------*/
72
73#define RECIPE_ID "xsh_scired_ifu_offset"
74#define RECIPE_AUTHOR "A.Modigliani, J.Vernet, P. Bristow"
75#define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
76
77/*-----------------------------------------------------------------------------
78 Functions prototypes
79 ----------------------------------------------------------------------------*/
80
81/*
82 * Plugin initalization, execute and cleanup handlers
83 */
84
85static int xsh_scired_ifu_offset_create( cpl_plugin *);
86static int xsh_scired_ifu_offset_exec( cpl_plugin *);
87static int xsh_scired_ifu_offset_destroy( cpl_plugin *);
88
89/* The actual executor function */
90static void xsh_scired_ifu_offset( cpl_parameterlist *, cpl_frameset *);
91
92/*-----------------------------------------------------------------------------
93 Static variables
94 ----------------------------------------------------------------------------*/
96"Reduce science IFU on-off exposures and build a 3D cube";
97
99"This recipe Reduce science IFU on-off exposures and build a 3D cube\n\
100Input Frames : \n\
101 - A set of 2xn Science frames, \
102 Tag = OBJECT_IFU_OFFSET_arm, SKY_IFU_arm\n\
103 - A spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
104 - A master flat frame (Tag = MASTER_FLAT_IFU_arm)\n\
105 - An order table frame(Tag = ORDER_TABLE_EDGES_IFU_arm)\n\
106 - 3 wave solution frames, one per slitlet (Tag = WAVE_TAB_ARC_IFU_slitlet_arm)\n\
107 where 'slitlet' is DOWN, CEN or UP\n\
108 - [OPTIONAL] A dispersion table (Tag = DISP_TAB_IFU_arm)\n\
109 - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)\n\
110 - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)\n\
111Products : \n\
112 - Merged 3D data cube (PREFIX_MERGE3D_DATA_OBJ_arm)\n\
113 - QC Traces of 3D data cube (PREFIX_MERGE3D_TRACE_OBJ_arm)\n\
114 - Order by order 3D data cube (PREFIX_ORDER3D_DATA_OBJ_arm)\n\
115 - Order by order 3D qual cube (IFU_CFG_COR_arm)\n\
116 - Order by order 3D qual cube (PREFIX_MERGE3D_DATA_SKY_arm)\n\
117 - where PREFIX is SCI, FLUX, TELL if input raw DPR.TYPE contains OBJECT or FLUX or TELLURIC\n\
118 - 1 Spectrum merge 3D, PRO.CATG=MERGE3D_IFU_arm\n" ;
119
120/*-----------------------------------------------------------------------------
121 Functions code
122 ----------------------------------------------------------------------------*/
123/*----------------------------------------------------------------------------*/
132/*----------------------------------------------------------------------------*/
133
134int cpl_plugin_get_info(cpl_pluginlist *list) {
135 cpl_recipe *recipe = NULL;
136 cpl_plugin *plugin = NULL;
137
138 recipe = cpl_calloc(1, sizeof(*recipe));
139 if ( recipe == NULL ){
140 return -1;
141 }
142
143 plugin = &recipe->interface ;
144
145 cpl_plugin_init(plugin,
146 CPL_PLUGIN_API, /* Plugin API */
147 XSH_BINARY_VERSION, /* Plugin version */
148 CPL_PLUGIN_TYPE_RECIPE, /* Plugin type */
149 RECIPE_ID, /* Plugin name */
151 xsh_scired_ifu_offset_description, /* Detailed help */
152 RECIPE_AUTHOR, /* Author name */
153 RECIPE_CONTACT, /* Contact address */
154 xsh_get_license(), /* Copyright */
158
159 cpl_pluginlist_append(list, plugin);
160
161 return (cpl_error_get_code() != CPL_ERROR_NONE);
162}
163
164/*----------------------------------------------------------------------------*/
174/*----------------------------------------------------------------------------*/
175
176static int xsh_scired_ifu_offset_create(cpl_plugin *plugin){
177 cpl_recipe *recipe = NULL;
178
179 xsh_clipping_param crh_clip_param = {5.0, 5, 0.7, 0,0.3};
180 /* First param (conv_kernel) should be initialized correctly ! */
181 xsh_remove_crh_single_param crh_single = { 0.1, 5, 2.0, 4} ;
182 xsh_rectify_param rectify = { "tanh",
183 CPL_KERNEL_DEFAULT,
184 2,
185 -1.0,
186 -1.0,
187 1,0,0.};
188 /* 2nd and 3rd params should be initialized correctly */
189 xsh_localize_obj_param loc_obj =
190 {10, 0.1, 0, 0, LOC_MANUAL_METHOD, 0, 2.0,3,3,FALSE};
191 xsh_stack_param stack_param = {"median",5.,5.};
192/*
193 xsh_extract_param extract_par =
194 { LOCALIZATION_METHOD};
195*/
196 /* Reset library state */
197 xsh_bary_corr_param bary_corr = {BARY_CORR_NONE };
198 xsh_init();
199
200 /* Check input */
201 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
202 /* Get the recipe out of the plugin */
203 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
204 CPL_ERROR_TYPE_MISMATCH,
205 "Plugin is not a recipe");
206
207 recipe = (cpl_recipe *)plugin;
208
209 /* Create the parameter list in the cpl_recipe object */
210 recipe->parameters = cpl_parameterlist_new();
211 assure( recipe->parameters != NULL,
212 CPL_ERROR_ILLEGAL_OUTPUT,
213 "Memory allocation failed!");
214
215 /* Set generic parameters (common to all recipes) */
216 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
217 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
218 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
219 check(xsh_parameters_stack_create(RECIPE_ID,recipe->parameters,stack_param));
220 /* crh clipping params */
222 crh_clip_param));
223
224 /* subtract_background_params AMO removed these
225 check(xsh_parameters_background_create(RECIPE_ID,recipe->parameters));
226 */
227 /* remove_crh_single */
229 crh_single )) ;
230 /* xsh_rectify */
232 rectify )) ;
233 /* xsh_localize_object */
235 loc_obj )) ;
236
237 /* xsh_optimal_extract
238 check(xsh_parameters_optimal_extract_create(RECIPE_ID,
239 recipe->parameters,-1. )) ;
240 */
241 /* trivial extract (Just temporary)
242 check(xsh_parameters_extract_create(RECIPE_ID,
243 recipe->parameters,
244 extract_par,LOCALIZATION_METHOD )) ;
245
246 */
247
248 /* PIPE-10061 - barycentric correction param */
250 bary_corr)) ;
251
252 /* single rectify localization */
253 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
254 "compute-map", FALSE,
255 "if TRUE recompute (wave and slit) maps from the dispersion solution. If sky-subtract is set to TRUE this must be set to TRUE."));
256
257 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
258 "trace-obj", FALSE,
259 "if TRUE trace object position on each IFU slice. In this case order TAB edges is required"));
260
261
262 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
263 "check-afc", TRUE,
264 "Input AFC corrected model/wave solution and science frame check. If TRUE the recipe verify that the input mode/wave solution is AFC corrected, its INS.OPTIi.NAME is 'Pin_0.5 ', and its OBS.ID and OBS.TARG.NAME values matches with the corresponding values of the science frame."));
265
266 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
267 "cut-uvb-spectrum", TRUE,
268 "TRUE if recipe cuts the UVB spectrum at 556 nm (dichroich)"));
269
270 cleanup:
271 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
272 xsh_error_dump(CPL_MSG_ERROR);
273 return 1;
274 }
275 else {
276 return 0;
277 }
278}
279
280/*----------------------------------------------------------------------------*/
286/*----------------------------------------------------------------------------*/
287
288static int xsh_scired_ifu_offset_exec(cpl_plugin *plugin) {
289 cpl_recipe *recipe = NULL;
290
291 /* Check parameter */
292
293 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
294
295 /* Get the recipe out of the plugin */
296 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
297 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
298
299 recipe = (cpl_recipe *)plugin;
300
301 /* Check recipe */
302 xsh_scired_ifu_offset(recipe->parameters, recipe->frames);
303
304 cleanup:
305 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
306 xsh_error_dump(CPL_MSG_ERROR);
308 return 1;
309 }
310 else {
311 return 0;
312 }
313}
314
321static cpl_error_code
323{
324
325 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
326 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
327 rectify_par->rectif_bin_space);
328
329 return cpl_error_get_code();
330
331}
332#if 0
333/*--------------------------------------------------------------------------*/
341/*--------------------------------------------------------------------------*/
342
343static cpl_error_code
344xsh_params_bin_scale(cpl_frameset* raws,
346{
347
348 cpl_frame* frame=NULL;
349 const char* name=NULL;
350 cpl_propertylist* plist=NULL;
351 int binx=0;
352 int biny=0;
353
354 check(frame=cpl_frameset_get_frame(raws,0));
355 check(name=cpl_frame_get_filename(frame));
356 check(plist=cpl_propertylist_load(name,0));
359 xsh_free_propertylist(&plist);
360
361 if(biny>1) {
362
363 /*
364 backg->sampley=backg->sampley/biny;
365 Not bin dependent.
366 */
367
368 backg->radius_y=backg->radius_y/biny;
369 /*
370 if(backg->smooth_y>0) {
371 backg->smooth_y=backg->smooth_y/biny;
372 }
373 Smoothing radius' half size in y direction
374 For the moment not bin dependent, but for optimal results probably yes
375 */
376
377 /*
378 rectify_par->rectif_radius=rectify_par->rectif_radius/biny;
379 Rectify Interpolation radius.
380 For the moment not bin dependent, but for optimal results probably yes
381 */
382
383 /*
384 rectify_par->rectif_bin_lambda=rectify_par->rectif_bin_lambda/biny;
385 Rectify Wavelength Step.
386 For the moment not bin dependent, but for optimal results probably yes
387 */
388
389 }
390
391
392 if(binx>1) {
393
394 backg->radius_x=backg->radius_x/binx;
395 /*
396 if(backg->smooth_x>0) {
397 backg->smooth_x=backg->smooth_x/binx;
398 }
399 Smoothing radius' half size in x direction
400 For the moment not bin dependent, but for optimal results probably yes
401 */
402
403 /*
404 rectify_par->rectif_bin_space=rectify_par->rectif_bin_space/binx;
405 Rectify Position Step.
406 For the moment not bin dependent, but for optimal results probably yes
407 */
408
409 }
410
411 cleanup:
412 xsh_free_propertylist(&plist);
413 return cpl_error_get_code();
414
415}
416#endif
417
418/*----------------------------------------------------------------------------*/
424/*----------------------------------------------------------------------------*/
425static int xsh_scired_ifu_offset_destroy(cpl_plugin *plugin)
426{
427 cpl_recipe *recipe = NULL;
428
429 /* reset error state before detroying recipe */
431 /* Check parameter */
432 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
433
434 /* Get the recipe out of the plugin */
435 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
436 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
437
438 recipe = (cpl_recipe *)plugin;
439
440 xsh_free_parameterlist(&recipe->parameters);
441
442 cleanup:
443 if (cpl_error_get_code() != CPL_ERROR_NONE)
444 {
445 return 1;
446 }
447 else
448 {
449 return 0;
450 }
451}
452
453
454/*----------------------------------------------------------------------------*/
462/*----------------------------------------------------------------------------*/
463static void xsh_scired_ifu_offset( cpl_parameterlist* parameters,
464 cpl_frameset* frameset)
465{
467 int recipe_tags_size = 4;
468
469 /* Beware, do not "free" the following input frames, they are part
470 of the input frameset */
471 cpl_frame *spectral_format_frame = NULL;
472 cpl_frame *ifu_cfg_tab_frame = NULL ;
473 cpl_frame *ifu_cfg_cor_frame = NULL ;
474 //int nobj=0;
475 //int nsky=0;
476
477 /* Input frames */
478 cpl_frameset* raws = NULL;
479 cpl_frameset* calib = NULL;
480 /* Beware, do not "free" the following input frames, they are part
481 of the input frameset */
482 cpl_frame* bpmap = NULL;
483 cpl_frame * master_bias = NULL ;
484 cpl_frame * master_dark = NULL ;
485 cpl_frame* master_flat = NULL;
486 cpl_frame* order_tab_edges = NULL;
487 cpl_frame * wavesol_frame = NULL ;
488 cpl_frame * model_config_frame = NULL ;
489 //cpl_frame * spectral_format = NULL ;
490 cpl_frame * slice_offset_frame = NULL ;
491 cpl_frameset * raw_object = NULL, * raw_sky = NULL ;
492 xsh_stack_param* stack_par=NULL;
493 /* Parameters */
494 //xsh_background_param* backg_par = NULL;
495 xsh_remove_crh_single_param * crh_single_par = NULL ;
496 xsh_rectify_param * rectify_par = NULL ;
497 xsh_bary_corr_param * bary_par = NULL ;
498
500 int nb_sub_frames ;
501 int nb_raw_frames ;
502
503 /* Intermediate frames */
504
505 cpl_frameset * sub_frameset = NULL ;
506 //cpl_frameset * rmbkg_frameset = NULL ; /**< frameset of frames after subtract bkg */
507 cpl_frameset * clean_frameset = NULL ;
509 cpl_frame * comb_obj_frame = NULL ;
510 cpl_frameset * rect2_frameset = NULL ;
511 //cpl_frameset * loc_table_frameset = NULL ; /**< Output of xsh_localize_object */
512
513 /* Output Frames (results)*/
514 cpl_frameset * res_1D_frameset = NULL ;
515 cpl_frameset * res_2D_frameset = NULL ;
516 cpl_frame * data_cube = NULL ;
517 cpl_frameset * ext_frameset = NULL ;
518 cpl_frameset * ext_frameset_tables = NULL ;
519 char* prefix=NULL;
520
521 char arm_str[16] ;
522 char * file_tag = NULL;
523 cpl_frame* grid_backg=NULL;
524 cpl_frame* frame_backg=NULL;
525 cpl_frameset * ext_frameset_images = NULL ;
526 cpl_frameset * rect2_frameset_tables = NULL ;
527 //cpl_frameset * rect_frameset_tab=NULL;
528 //cpl_frameset * rect_frameset_eso=NULL;
529 char rec_prefix[256];
530 char sky_prefix[256];
531 //cpl_frame* object_frame=NULL;
532 //int check_afc = TRUE;
533 int do_compute_map = TRUE;
534 int recipe_use_model = FALSE;
535 //char wave_map_tag[256];
536 //char slit_map_tag[256];
537 cpl_frame *wavemap = NULL ;
538 cpl_frame *slitmap = NULL ;
539 cpl_frame *disp_tab_frame = NULL;
540 cpl_frame* comb_sky_frame=NULL;
541 int pre_overscan_corr=0;
542 cpl_frame* ifu_sky_map=NULL;
543 int do_computemap=1;
544 int use_model=0;
545 cpl_frameset* crh_clean_obj = NULL;
546 cpl_frameset* crh_clean_sky = NULL;
547 cpl_frame* sky_map_frm = NULL;
548 int do_flatfield = 1;
549 /**************************************************************************/
550 /* DFS management */
551 /**************************************************************************/
552 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
553 recipe_tags, recipe_tags_size,
554 RECIPE_ID, XSH_BINARY_VERSION,
556
558 assure( instrument->mode == XSH_MODE_IFU, CPL_ERROR_ILLEGAL_INPUT,
559 "Instrument NOT in Ifu Mode" ) ;
561 /* One should have a multiple of 2 input frames: A-B */
562 check( nb_raw_frames = cpl_frameset_get_size( raws ) ) ;
563 xsh_msg( "Nb of Raw frames: %d", nb_raw_frames ) ;
564
565 XSH_ASSURE_NOT_ILLEGAL( nb_raw_frames > 1 ) ;
566 {
567
568 int even_nb = nb_raw_frames % 2 ;
569 XSH_ASSURE_NOT_ILLEGAL( even_nb == 0 ) ;
570
571 }
572
573
574 /**************************************************************************/
575 /* Recipe frames */
576 /**************************************************************************/
577
578
579 /* IFU stuff (physmodel) */
582 check(spectral_format_frame=xsh_find_spectral_format( calib, instrument ) ) ;
583
584
586 /* In UVB and VIS mode */
588 /* RAWS frameset must have only one file */
589 check( master_bias = xsh_find_frame_with_tag(calib,XSH_MASTER_BIAS,
590 instrument));
591 }
592 /* IN NIR mode */
593 else {
594 /* split on and off files */
595 /*check(xsh_dfs_split_nir(raws,&on,&off));
596 XSH_ASSURE_NOT_ILLEGAL(cpl_frameset_get_size(on) >= 3);
597 XSH_ASSURE_NOT_ILLEGAL(cpl_frameset_get_size(off) >= 3);*/
598 }
599 check(order_tab_edges = xsh_find_order_tab_edges(calib,instrument));
600
601 /* one should have either model config frame or wave sol frame */
602 check(model_config_frame=xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
603 instrument));
604
605 if(model_config_frame==NULL) {
607 instrument));
608 }
609
610 /*
611 check( check_afc = xsh_parameters_get_boolean( parameters, RECIPE_ID,
612 "check-afc"));
613 */
614 check( do_compute_map = xsh_parameters_get_boolean( parameters, RECIPE_ID,
615 "compute-map"));
616
617 /*
618 One of model config and wave tab must be present, but only one !
619 */
620 XSH_ASSURE_NOT_ILLEGAL( (model_config_frame != NULL && wavesol_frame == NULL ) ||
621
622 (model_config_frame == NULL && wavesol_frame != NULL ) );
623
624 check( master_flat = xsh_find_master_flat( calib, instrument ) ) ;
625
626 if((master_dark = xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,
627 instrument)) == NULL){
628 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
630 }
631
632
633 if ((slice_offset_frame = xsh_find_frame_with_tag( calib, XSH_SLICE_OFFSET,
634 instrument) ) == NULL ) {
635 xsh_msg_warning("Frame %s not provided", XSH_SLICE_OFFSET );
637 }
638
639
640 /**************************************************************************/
641 /* Recipe parameters */
642 /**************************************************************************/
643 check( stack_par = xsh_stack_frames_get( RECIPE_ID, parameters));
644
645 /*
646 check( backg_par = xsh_parameters_background_get(RECIPE_ID,
647 parameters));
648 */
650 parameters));
651 rectify_par->conserve_flux=FALSE;
653 parameters));
654 if ( rectify_par->rectify_full_slit == 1 ) {
655 xsh_msg( "Use Full Slit" ) ;
656 }
657 else {
658 xsh_msg( "Use Max Possible Slit" ) ;
659 }
661
662 /* adjust relevant parameter to binning
663 if ( xsh_instrument_get_arm( instrument ) != XSH_ARM_NIR ) {
664 check(xsh_params_bin_scale(raws,backg_par));
665 }
666 */
667 check(xsh_params_monitor(rectify_par));
668
669 // PIPE-10061 - get barycentric corr param
670 check(bary_par = xsh_parameters_bary_corr_get( RECIPE_ID, parameters)) ;
671
672
673 /**************************************************************************/
674 /* Recipe code */
675 /**************************************************************************/
676
677 /* prepare RAW frames in PRE format */
678 check(xsh_prepare(raws, bpmap, master_bias, XSH_OBJECT_IFU_OFFSET,
679 instrument,pre_overscan_corr,CPL_TRUE));
680
681 /* make sure each input raw frame has the same exp time */
683
684 /* Separate OBJECT and SKY frames */
685 check( nb_sub_frames = xsh_dfs_split_offset( raws, "IFU_OFFSET",
686 XSH_SKY_IFU, &raw_object,
687 &raw_sky ) ) ;
688
689 //nobj=cpl_frameset_get_size(raw_object);
690 //nsky=cpl_frameset_get_size(raw_sky);
691 prefix=xsh_set_recipe_file_prefix(raws,"xsh_scired_ifu_offset");
692 sprintf(sky_prefix,xsh_set_recipe_sky_file_prefix(rec_prefix));
693 check(strcpy(rec_prefix,(const char*)prefix));
694 XSH_FREE(prefix);
695
696 //check(object_frame=cpl_frameset_get_frame(raw_object,0));
697 if ( model_config_frame == NULL){
698 xsh_msg("RECIPE USE WAVE SOLUTION");
699 recipe_use_model = FALSE;
700 do_compute_map = TRUE;
701 }
702 else{
703 xsh_msg("RECIPE USE MODEL");
704 recipe_use_model = TRUE;
705 }
706
707 if ( do_compute_map && recipe_use_model==FALSE){
708 check( disp_tab_frame = xsh_find_disp_tab( calib, instrument));
709 }
710
711
712
713 xsh_msg("cmap=%d wavemap=%p slitmap=%p",do_computemap,wavemap,slitmap);
714 if( (do_computemap == 1) &&
715 (wavemap ==NULL || slitmap ==NULL )
716 ) {
717 if (model_config_frame != NULL) {
718 use_model=1;
719 }
720
721 check( xsh_check_get_map( disp_tab_frame, order_tab_edges,
722 master_flat, model_config_frame, calib, instrument,
723 do_computemap, use_model, rec_prefix,
724 &wavemap, &slitmap));
725
726 }
727
728 if( nb_sub_frames==0 ) {
729 xsh_msg_error("nb_sub_frames=%d something wrong check your input raws",nb_sub_frames);
730 goto cleanup;
731
732 }
733
734 /* remove crh on each obj or sky frame */
735 sky_map_frm = xsh_find_frame_with_tag(calib,XSH_SKY_MAP, instrument);
736 crh_clean_obj = xsh_frameset_crh_single(raw_object, crh_single_par,sky_map_frm,
737 instrument,rec_prefix,"OBJ");
738 crh_clean_sky = xsh_frameset_crh_single(raw_sky, crh_single_par, sky_map_frm,
739 instrument,rec_prefix,"SKY");
740
741
742 /* For each pair, subtract OBJECT-SKY */
743 check( sub_frameset = xsh_subtract_sky_offset( crh_clean_obj, crh_clean_sky,
744 nb_sub_frames, instrument)) ;
745
746 xsh_free_frameset(&crh_clean_obj);
747 xsh_free_frameset(&crh_clean_sky);
748
749 /**************************************************************************/
750 /* Check that SCI IFU frame and AFC corrected CFG are proper */
751 /**************************************************************************/
752/*
753 if(check_afc) {
754 if(model_config_frame!=NULL) {
755 check(xsh_frame_check_model_cfg_is_afc_corrected(model_config_frame));
756 check(xsh_frame_check_model_cfg_is_proper_for_sci(model_config_frame,
757 object_frame,
758 instrument));
759 } else {
760 check(xsh_frame_check_model_cfg_is_afc_corrected(wavesol_frame));
761 check(xsh_frame_check_model_cfg_is_proper_for_sci(wavesol_frame,
762 object_frame,
763 instrument));
764 }
765 }
766*/
767
768 if (do_flatfield == 1) {
769 clean_frameset=xsh_frameset_mflat_divide(sub_frameset,master_flat,instrument);
770 } else {
771 clean_frameset = cpl_frameset_duplicate(sub_frameset);
772 }
773 /* now we have duplicate sub_frameset we do not need it anymore */
774 xsh_free_frameset(&sub_frameset);
775
776
777 //check( rmbkg_frameset = cpl_frameset_new() ) ;
778 //check( clean_frameset = cpl_frameset_new() ) ;
779
780 sprintf( arm_str, "%s_", xsh_instrument_arm_tostring(instrument) ) ;
781
782 /* AMO removed background subtraction
783 // For each sky subtracted frame
784 for( i = 0 ; i<nb_sub_frames ; i++ ) {
785 cpl_frame * a_b = NULL ;
786 cpl_frame * rm_bkg = NULL ;
787 char str[16] ;
788
789 sprintf( str, "%d", i ) ;
790 a_b = cpl_frameset_get_frame( sub_frameset, i ) ;
791 // subtract background
792
793 xsh_msg("Subtract inter-order background %d", i );
794 sprintf(file_name,"%s%s",rec_prefix, str) ;
795
796 check(rm_bkg = xsh_subtract_background( a_b,
797 order_tab_edges,
798 backg_par, instrument,
799 file_name,&grid_backg,
800 &frame_backg,0,0,0));
801 check( cpl_frameset_insert( rmbkg_frameset, rm_bkg ) ) ;
802 }
803 */
804
805 /* AMO removed this part doing CRH flagging and flat fielding
806 as these have been already performed
807 if ( nb_sub_frames < 3 && crh_single_par->nb_iter > 0 ) {
808 xsh_msg( "Less than 3 frames AND crh_single_niter > 0" ) ;
809 for ( i = 0 ; i < nb_sub_frames ; i++ ) {
810 cpl_frame * divided = NULL ;
811 cpl_frame * rm_crh = NULL ;
812 cpl_frame * a_b = NULL ;
813 char str[16] ;
814
815 check( a_b = cpl_frameset_get_frame( rmbkg_frameset, i ) ) ;
816 sprintf( str, "%d", i ) ;
817
818 file_tag = xsh_stringcat_any( "NO_CRH_IFU_OFFSET_", arm_str,str,
819 (void*)NULL ) ;
820 xsh_msg( "Remove crh (single frame)" ) ;
821
822 check( rm_crh = xsh_remove_crh_single( a_b,instrument,
823 crh_single_par,
824 file_tag ) ) ;
825
826
827 XSH_FREE( file_tag ) ;
828 xsh_add_temporary_file(cpl_frame_get_filename(rm_crh));
829 xsh_msg( "Divide by flat" ) ;
830 file_tag = xsh_stringcat_any( "FF_IFU_OFFSET_", arm_str,
831 str, (void*)NULL ) ;
832 check( divided = xsh_divide_flat( rm_crh,
833 master_flat, file_tag,
834 instrument ) ) ;
835 XSH_FREE( file_tag ) ;
836 check( cpl_frameset_insert( clean_frameset, divided ) ) ;
837 xsh_add_temporary_file(cpl_frame_get_filename(divided));
838 xsh_free_frame(&rm_crh);
839
840 }
841 }
842 else for( i = 0 ; i < nb_sub_frames ; i++ ) {
843 cpl_frame * divided = NULL ;
844 cpl_frame * a_b = NULL ;
845 char str[16] ;
846
847 // If enough frames, the CRH removal is done in xsh_combine_offset
848 a_b = cpl_frameset_get_frame( rmbkg_frameset, i ) ;
849 sprintf( str, "%d", i ) ;
850
852 xsh_msg( "Divide by flat" ) ;
853 file_tag = xsh_stringcat_any( "FF_IFU_OFFSET_", arm_str,
854 str, (void*)NULL ) ;
855 check( divided = xsh_divide_flat( a_b,
856 master_flat, file_tag,
857 instrument ) ) ;
858 XSH_FREE( file_tag ) ;
859 check( cpl_frameset_insert( clean_frameset, divided ) ) ;
860 xsh_add_temporary_file(cpl_frame_get_filename(divided));
861 }
862 */
863
864 /* Now combine all frames */
865 xsh_msg( "Combining all frames" ) ;
866 file_tag = xsh_stringcat_any( "COMBINED_IFU_OFFSET_", arm_str,
867 "ALL", (void*)NULL ) ;
868
869 check( comb_obj_frame = xsh_combine_offset( clean_frameset,
870 file_tag, stack_par,
871 instrument, NULL, NULL,1 ) ) ;
872 XSH_FREE( file_tag ) ;
873
874 check(comb_sky_frame=xsh_util_frameset_collapse_mean(raw_sky,instrument));
875
876
877 /* Now build the cube frame */
878
879 check(xsh_build_ifu_cube(comb_obj_frame,ifu_cfg_tab_frame,ifu_cfg_cor_frame,
880 spectral_format_frame,
881 model_config_frame,wavesol_frame,
883 frameset,
884 parameters,rectify_par,RECIPE_ID,rec_prefix,1));
885
886 /* Now build the cube sky frame: we need to pass a tag to
887 identify OBJ and SKY */
888
889 check(xsh_build_ifu_cube(comb_sky_frame,ifu_cfg_tab_frame,ifu_cfg_cor_frame,
890 spectral_format_frame,
891 model_config_frame,wavesol_frame,
893 frameset,
894 parameters,rectify_par,RECIPE_ID,rec_prefix,0));
895
896 if(do_compute_map) {
897 check(ifu_sky_map=xsh_build_ifu_map(comb_obj_frame,wavemap,slitmap,instrument));
898 check( xsh_add_product_image( ifu_sky_map, frameset,parameters, RECIPE_ID, instrument,NULL));
899 }
900 cleanup:
901
902 xsh_end( RECIPE_ID, frameset, parameters );
903 //XSH_FREE( backg_par ) ;
904 XSH_FREE( crh_single_par ) ;
905 XSH_FREE( rectify_par ) ;
906 XSH_FREE(stack_par);
907 XSH_FREE( bary_par);
908
910 xsh_free_frame(&wavemap);
911 xsh_free_frame(&slitmap);
912 xsh_free_frameset(&ext_frameset_images);
913 xsh_free_frameset(&rect2_frameset_tables);
914 xsh_free_frameset(&ext_frameset_tables);
915
916 xsh_free_frameset(&raw_object);
917 xsh_free_frameset(&raw_sky);
918 xsh_free_frameset(&raws);
919 xsh_free_frameset(&calib);
920 xsh_free_frameset( &sub_frameset ) ;
921 xsh_free_frameset( &clean_frameset ) ;
922 //xsh_free_frameset( &rmbkg_frameset ) ;
923 xsh_free_frameset(&res_1D_frameset) ;
924 xsh_free_frameset(&res_2D_frameset) ;
925 xsh_free_frameset(&rect2_frameset) ;
926 xsh_free_frameset(&ext_frameset) ;
927
928
929 xsh_free_frame( &comb_sky_frame);
930 xsh_free_frame( &comb_obj_frame);
931 xsh_free_frame( &grid_backg);
932 xsh_free_frame( &frame_backg);
933
934 xsh_free_frame( &data_cube ) ;
935
936 return;
937}
938
static xsh_instrument * instrument
int binx
int biny
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
Definition: xsh_2dmap.c:151
static cpl_error_code xsh_params_bin_scale(cpl_frameset *raws, xsh_background_param *backg, xsh_opt_extract_param *opt_extract_par, int *sub_sky_nbkpts1, int *sub_sky_nbkpts2)
Interpret the command line options and execute the data processing.
Definition: xsh_absorp.c:470
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_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
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
#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
cpl_frame * xsh_combine_offset(cpl_frameset *rawFrames, const char *result_name, xsh_stack_param *stack_par, xsh_instrument *instr, cpl_imagelist **list, cpl_image **crh_ima, const int save_tmp)
#define RECIPE_CONTACT
static cpl_error_code xsh_params_monitor(xsh_rectify_param *rectify_par)
monitor parameters value
static char xsh_scired_ifu_offset_description[]
static char xsh_scired_ifu_offset_description_short[]
#define RECIPE_ID
#define RECIPE_AUTHOR
cpl_frameset * xsh_subtract_sky_offset(cpl_frameset *object_raws, cpl_frameset *sky_raws, int nraws, xsh_instrument *instrument)
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
Definition: xsh_utils.c:2224
const char * xsh_set_recipe_sky_file_prefix(char *rec_prefix)
Set recipe sky frames prefix.
Definition: xsh_utils.c:576
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
cpl_frame * xsh_util_frameset_collapse_mean(cpl_frameset *set, xsh_instrument *instrument)
Compute mean frame from a list of (IMAGE) framesets.
Definition: xsh_utils.c:5538
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
cpl_frame * xsh_find_spectral_format(cpl_frameset *frames, xsh_instrument *instr)
Find spectral format frame.
Definition: xsh_dfs.c:4318
int xsh_dfs_split_offset(cpl_frameset *input, const char *object_tag, const char *sky_tag, cpl_frameset **object, cpl_frameset **sky)
split input RAW offset sof in OBJECT_... and SKY_... framesets
Definition: xsh_dfs.c:1357
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
cpl_frame * xsh_find_order_tab_edges(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab EDGES.
Definition: xsh_dfs.c:3595
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
cpl_error_code xsh_ensure_raws_input_offset_recipe_is_proper(cpl_frameset **raws, xsh_instrument *instrument)
Make sure input frames is an even number (eventually removes the last from the input list)
Definition: xsh_dfs.c:352
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_error_code xsh_frameset_check_uniform_exptime(cpl_frameset *raws, xsh_instrument *inst)
Definition: xsh_dfs.c:5119
#define XSH_MOD_CFG_OPT_AFC
Definition: xsh_dfs.h:1256
#define XSH_MASTER_BIAS
Definition: xsh_dfs.h:549
#define XSH_MASTER_DARK
Definition: xsh_dfs.h:550
#define XSH_SKY_MAP
Definition: xsh_dfs.h:282
#define XSH_STD_FLUX_IFU_OFFSET
Definition: xsh_dfs.h:499
#define XSH_WAVE_TAB_AFC
Definition: xsh_dfs.h:557
#define XSH_SKY_IFU
Definition: xsh_dfs.h:234
#define XSH_STD_TELL_IFU_OFFSET
Definition: xsh_dfs.h:475
#define XSH_IFU_CFG_COR
Definition: xsh_dfs.h:53
#define XSH_IFU_CFG_TAB
Definition: xsh_dfs.h:48
#define XSH_SLICE_OFFSET
Definition: xsh_dfs.h:601
#define XSH_OBJECT_IFU_OFFSET
Definition: xsh_dfs.h:231
cpl_frame * xsh_check_load_master_bpmap(cpl_frameset *calib, xsh_instrument *inst, const char *rec_id)
Definition: xsh_drl_check.c:51
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
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
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
void xsh_parameters_rectify_create(const char *recipe_id, cpl_parameterlist *plist, xsh_rectify_param p)
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)
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)
@ BARY_CORR_NONE
@ LOC_MANUAL_METHOD
static int xsh_scired_ifu_offset_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_scired_ifu_offset_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static void xsh_scired_ifu_offset(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
static int xsh_scired_ifu_offset_create(cpl_plugin *)
Setup the recipe options.
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
cpl_error_code xsh_build_ifu_cube(cpl_frame *div_frame, cpl_frame *ifu_cfg_tab_frame, cpl_frame *ifu_cfg_cor_frame, cpl_frame *spectral_format_frame, cpl_frame *model_config_frame, cpl_frame *wavesol_frame, xsh_instrument *instrument, cpl_frameset *frameset, cpl_parameterlist *parameters, xsh_rectify_param *rectify_par, const char *recipe_id, const char *rec_prefix, const int frame_is_object)
Reconstruct IFU cube.
cpl_frame * xsh_build_ifu_map(cpl_frame *div_frame, cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, xsh_instrument *instrument)
Reconstruct IFU cube.
cpl_frameset * xsh_frameset_crh_single(cpl_frameset *raws, xsh_remove_crh_single_param *crh_single_par, cpl_frame *sky_map_frm, xsh_instrument *instrument, const char *prefix, const char *spec)
Generates a new frameset with each frame CRH-single rejected from input frameset.
cpl_frameset * xsh_frameset_mflat_divide(cpl_frameset *input, cpl_frame *mflat, xsh_instrument *instrument)
Generates a new frameset with each frame mflat divided input frameset.