X-shooter Pipeline Reference Manual 3.8.15
xsh_scired_slit_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-08-29 10:51:41 $
23 * $Revision: 1.277 $
24*/
25
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
30/*----------------------------------------------------------------------------*/
38/*----------------------------------------------------------------------------*/
41/*-----------------------------------------------------------------------------
42 Includes
43 ----------------------------------------------------------------------------*/
44
45
46/* DRL steps */
47
48/* Error handling */
49#include <xsh_error.h>
50/* Utility fonctions */
51#include <xsh_utils.h>
53#include <xsh_msg.h>
54/* DFS functions */
55#include <xsh_dfs.h>
56#include <xsh_pfits.h>
57/* DRL functions */
58#include <xsh_utils_image.h>
60#include <xsh_data_instrument.h>
61#include <xsh_data_spectrum1D.h>
62#include <xsh_data_spectrum.h>
63#include <xsh_drl_check.h>
64#include <xsh_drl.h>
65#include <xsh_model_utils.h>
67
68/* Library */
69#include <cpl.h>
70/* CRH Remove */
71
72/*-----------------------------------------------------------------------------
73 Defines
74 ----------------------------------------------------------------------------*/
75
76#define RECIPE_ID "xsh_scired_slit_stare"
77#define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, D. Bramich, A. Modigliani"
78#define RECIPE_CONTACT "amodigli@eso.org"
79
80/*-----------------------------------------------------------------------------
81 Functions prototypes
82 ----------------------------------------------------------------------------*/
83
84/*
85 * Plugin initalization, execute and cleanup handlers
86 */
87
88
89static int xsh_scired_slit_stare_create(cpl_plugin *);
90static int xsh_scired_slit_stare_exec(cpl_plugin *);
91static int xsh_scired_slit_stare_destroy(cpl_plugin *);
92
93/* The actual executor function */
94static cpl_error_code xsh_scired_slit_stare(cpl_parameterlist *, cpl_frameset *);
95
96/*-----------------------------------------------------------------------------
97 Static variables
98 ----------------------------------------------------------------------------*/
100"Reduce science exposure in SLIT configuration and stare mode";
101
103"This recipe reduces science exposure in SLIT configuration and stare mode\n\
104Input Frames : \n\
105 - A set of n Science frames ( n == 1 or >=3, \
106Tag = OBJECT_SLIT_STARE_UVB)\n\
107 - A spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
108 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)\n\
109 - [OPTIONAL]A master dark frame (Tag = MASTER_DARK_arm)\n\
110 - A master flat frame (Tag = MASTER_FLAT_SLIT_arm)\n\
111 - An order table frame(Tag = ORDER_TAB_EDGES_SLIT_arm)\n\
112 - [OPTIONAL] A table with dispersion coefficients (Tag = DISP_TAB_arm,\n\
113 required in poly mode\n\
114 - [poly mode] A wave solution frame(Tag = WAVE_TAB_2D_arm)\n\
115 - [physical model mode] A model cfg table (Format = TABLE, Tag = XSH_MOD_CFG_TAB_arm)\n\
116 - [OPTIONAL] A table specifying multiplying factor for break points \n\
117 (Tag = SKY_SUB_BKPTS_arm) to generate\n\
118 - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)\n\
119 - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)\n\
120 - [OPTIONAL,physmod mode] A table listing sky line positions (Tag = SKY_LINE_LIST_arm)\n\
121 this is used to be able to control quality of sky subtraction, for example\n\
122 projecting guess positions on the product SCI_SLIT_STARE_SUB_SKY_arm\n\
123 and is required if sky-method=BSPLINE\n\
124 - [OPTIONAL] The instrument response table (Tag = RESPONSE_MERGE1D_SLIT_arm)\n\
125 - [OPTIONAL] An atmospheric extinction table (Tag = ATMOS_EXT_arm)\n\
126 - [OPTIONAL] A telluric mask (Tag = TELL_MASK_arm)\n\
127 - [OPTIONAL] The instrument master response table (Tag = MRESPONSE_MERGE1D_SLIT_arm).\n\
128 If both master and individual response are provided the individual response is preferred.\n\
129Products : \n\
130 - PREFIX_ORDER2D_arm extracted spectrum, order-by-order, 2D\n\
131 - PREFIX_ORDER1D_arm extracted spectrum, order-by-order, 1D\n\
132 - PREFIX_MERGE2D_arm merged spectrum, 2D\n\
133 - PREFIX_MERGE1D_arm merged spectrum, 1D\n\
134 - SKY_SLIT_MERGE2D_arm merged spectrum sky, 2D\n\
135 - PREFIX_SUB_BACK_SLIT_arm sci frame bias, (dark), inter-order bkg subtracted\n\
136 - PREFIX_WAVE_MAP_arm, wave map image\n\
137 - PREFIX_SLIT_MAP_arm, slit map image\n\
138 - PREFIX_DIVFF_arm as PREFIX_SUB_BACK_SLIT_arm, flat fielded\n\
139 - PREFIX_SUB_SKY_arm, as PREFIX_DIVFF_arm, sky subtracted\n\
140 - PREFIX_SKY_arm, 2D sky frame\n\
141 - PREFIX_SKY_ORD1D_arm, 1D sky image (order-by-order)\n\
142 - PREFIX_BACK_SLIT_arm, inter order background image \n\
143 - where PREFIX is SCI, FLUX, TELL if input raw DPR.TYPE contains OBJECT or FLUX or TELLURIC\n\
144 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUX_ORDER2D_arm (2 dimension)\n\
145 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUX_ORDER1D_arm (1 dimension)\n\
146 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUX_MERGE2D_arm (2 dimension)\n\
147 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUX_MERGE1D_arm (1 dimension)\n\
148 - PREFIX_ON_arm bias (dark) subtracted sci frame";
149
150/*-----------------------------------------------------------------------------
151 Functions code
152 ----------------------------------------------------------------------------*/
153/*----------------------------------------------------------------------------*/
162/*----------------------------------------------------------------------------*/
163
164int cpl_plugin_get_info(cpl_pluginlist *list) {
165 cpl_recipe *recipe = NULL;
166 cpl_plugin *plugin = NULL;
167
168 recipe = cpl_calloc(1, sizeof(*recipe));
169 if ( recipe == NULL ){
170 return -1;
171 }
172
173 plugin = &recipe->interface ;
174
175 cpl_plugin_init(plugin,
176 CPL_PLUGIN_API, /* Plugin API */
177 XSH_BINARY_VERSION, /* Plugin version */
178 CPL_PLUGIN_TYPE_RECIPE, /* Plugin type */
179 RECIPE_ID, /* Plugin name */
181 xsh_scired_slit_stare_description, /* Detailed help */
182 RECIPE_AUTHOR, /* Author name */
183 RECIPE_CONTACT, /* Contact address */
184 xsh_get_license(), /* Copyright */
188
189 cpl_pluginlist_append(list, plugin);
190
191 return (cpl_error_get_code() != CPL_ERROR_NONE);
192}
193
194/*----------------------------------------------------------------------------*/
204/*----------------------------------------------------------------------------*/
205
206static int xsh_scired_slit_stare_create(cpl_plugin *plugin){
207 cpl_recipe *recipe = NULL;
208
209 /* First param (conv_kernel) should be initialized correctly ! */
210 xsh_remove_crh_single_param crh_single = { 0.1, 5.0, 2.0, -1 } ;
211 xsh_rectify_param rectify = { "tanh",
212 CPL_KERNEL_DEFAULT,
213 2,
214 -1.0,
215 -1.0,
216 1,
217 0, 0. };
218
219 xsh_subtract_sky_single_param sky_single = {3000, 3000,7,20, 5., -1, -1,
220 MEDIAN_METHOD, FINE,20, 0.5,
221 0.0, 0.0,
222 0.0, 0.0} ;
223
224 /* 2nd and 3rd params should be initialized correctly */
225 xsh_localize_obj_param loc_obj =
226 {10, 0.1, 0, 0, LOC_MANUAL_METHOD, 0, 2.0,3,3, FALSE};
227
228 xsh_opt_extract_param opt_extract_par =
229 { 5, 10, 10, 0.01, 10.0, 1., 2, 2, GAUSS_METHOD };
230 xsh_stack_param stack_param = {"median",5.,5.};
231 xsh_interpolate_bp_param ipol_par = {30 };
232 /* Parameters init */
233 opt_extract_par.oversample = 5;
234 opt_extract_par.box_hsize = 10;
235 opt_extract_par.chunk_size = 50;
236 opt_extract_par.lambda_step = 0.02;
237 opt_extract_par.clip_kappa = 3;
238 opt_extract_par.clip_frac = 0.4;
239 opt_extract_par.clip_niter = 2;
240 opt_extract_par.niter = 1;
241 opt_extract_par.method = GAUSS_METHOD;
242 xsh_bary_corr_param bary_corr = {BARY_CORR_NONE };
243 /* Reset library state */
244 xsh_init();
245
246 /* Check input */
247 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
248
249 /* Get the recipe out of the plugin */
250 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
251 CPL_ERROR_TYPE_MISMATCH,
252 "Plugin is not a recipe");
253
254 recipe = (cpl_recipe *)plugin;
255
256 /* Create the parameter list in the cpl_recipe object */
257 recipe->parameters = cpl_parameterlist_new();
258 assure( recipe->parameters != NULL,
259 CPL_ERROR_ILLEGAL_OUTPUT,
260 "Memory allocation failed!");
261
262 /* Set generic parameters (common to all recipes) */
263 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
264 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
265 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
266 check(xsh_parameters_stack_create(RECIPE_ID,recipe->parameters,stack_param));
267
268 /* subtract_background_params */
270
271 /* remove_crh_single */
273 crh_single )) ;
274
275 /* xsh_rectify */
277 rectify )) ;
278
279 /* xsh_localize_object */
281 loc_obj )) ;
282
283 /* xsh_remove_sky_single */
285 sky_single )) ;
286
287 /* trivial extract (Just temporary)
288 check(xsh_parameters_extract_create(RECIPE_ID,
289 recipe->parameters,
290 extract_par,LOCALIZATION_METHOD )) ;
291 */
292
294 recipe->parameters,ipol_par)) ;
295
296 /* PIPE-10061 - barycentric correction param */
298 bary_corr)) ;
299
300 /* optimal extract */
301 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
302 "do-optextract", FALSE,
303 "TRUE if we do the optimal extraction"));
304
306 opt_extract_par));
307
308 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
309 "cut-uvb-spectrum", TRUE,
310 "TRUE if recipe cuts the UVB spectrum at 556 nm (dichroich)"));
311
312
313 /* Flag for generation of data in SDP format. */
314 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
315 "generate-SDP-format", FALSE,
316 "TRUE if additional files should be generated in Science Data Product"
317 " (SDP) format."));
318
319 /* Flag for adding dummy ASSO[NCM]i keywords. */
320 check( xsh_parameters_new_int( recipe->parameters, RECIPE_ID,
321 "dummy-association-keys", 0,
322 "Sets the number of dummy (empty) ASSONi, ASSOCi and ASSOMi keywords to"
323 " create."));
324
325 cleanup:
326 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
327 xsh_error_dump(CPL_MSG_ERROR);
328 return 1;
329 }
330 else {
331 return 0;
332 }
333}
334
335/*----------------------------------------------------------------------------*/
341/*----------------------------------------------------------------------------*/
342
343static int xsh_scired_slit_stare_exec(cpl_plugin *plugin) {
344 cpl_recipe *recipe = NULL;
345
346 /* Check parameter */
347
348 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
349
350 /* Get the recipe out of the plugin */
351 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
352 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
353
354 recipe = (cpl_recipe *)plugin;
355
356 /* Check recipe */
357 xsh_scired_slit_stare(recipe->parameters, recipe->frames);
358
359 cleanup:
360 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
361 xsh_error_dump(CPL_MSG_ERROR);
363 return 1;
364 }
365 else {
366 return 0;
367 }
368}
369
370/*----------------------------------------------------------------------------*/
376/*----------------------------------------------------------------------------*/
377static int xsh_scired_slit_stare_destroy(cpl_plugin *plugin)
378{
379 cpl_recipe *recipe = NULL;
380
381 /* reset error state before detroying recipe */
383 /* Check parameter */
384 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
385
386 /* Get the recipe out of the plugin */
387 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
388 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
389
390 recipe = (cpl_recipe *)plugin;
391
392 xsh_free_parameterlist(&recipe->parameters);
393
394 cleanup:
395 if (cpl_error_get_code() != CPL_ERROR_NONE)
396 {
397 return 1;
398 }
399 else
400 {
401 return 0;
402 }
403}
404
405static cpl_error_code
407 xsh_localize_obj_param * loc_obj_par,
408 xsh_opt_extract_param *opt_extract_par,
409 int sub_sky_nbkpts1,
410 int sub_sky_nbkpts2)
411{
412
413 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
414 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
415 rectify_par->rectif_bin_space);
416
417 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
418 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
419
420 xsh_msg_dbg_low("opt extract params: chunk_size=%d lambda_step=%g box_hsize=%d",
421 opt_extract_par->chunk_size,opt_extract_par->lambda_step,
422 opt_extract_par->box_hsize);
423
424 xsh_msg_dbg_low("sky params: nbkpts1=%d nbkpts2=%d",
425 sub_sky_nbkpts1,sub_sky_nbkpts2);
426
427 return cpl_error_get_code();
428
429}
430
431/*----------------------------------------------------------------------------*/
439/*----------------------------------------------------------------------------*/
440static cpl_error_code
441xsh_scired_slit_stare(cpl_parameterlist* parameters,
442 cpl_frameset* frameset)
443{
444
445 const int recipe_tags_size = 4;
446 const char* recipe_tags[4] = {XSH_OBJECT_SLIT_STARE,
450
451 /* Input frames */
452 cpl_frameset *raws = NULL;
453 cpl_frameset *calib = NULL;
454 cpl_frameset *usedframes = NULL;
455 /* Beware, do not "free" the following input frames, they are part
456 of the input frameset */
457 cpl_frame *bpmap = NULL;
458 cpl_frame *master_bias = NULL;
459 cpl_frame *master_dark = NULL;
460 cpl_frame *master_flat = NULL;
461 cpl_frame *order_tab_edges = NULL;
462 cpl_frame *wave_tab = NULL ;
463 cpl_frame *model_config_frame = NULL ;
464 cpl_frame *wavemap_frame = NULL ;
465 cpl_frame *slitmap_frame = NULL ;
466 cpl_frame *disp_tab_frame = NULL;
467
468 cpl_frame *spectralformat_frame = NULL ;
469 cpl_frame *tellmask_frame = NULL;
470
471 /* Parameters */
472 xsh_background_param* backg_par = NULL;
473 xsh_rectify_param * rectify_par = NULL ;
474 xsh_stack_param* stack_par=NULL;
475
476 xsh_remove_crh_single_param * crh_single_par = NULL ;
477 xsh_localize_obj_param * loc_obj_par = NULL ;
478 xsh_bary_corr_param * bary_par = NULL ;
479
480 int sub_sky_nbkpts1 = SUBTRACT_SKY_SINGLE_NBKPTS ;
483 int sub_sky_nbkpts2 = SUBTRACT_SKY_SINGLE_NBKPTS ;
487 int do_compute_map = 0;
488
489 int recipe_use_model = 0;
490
491 int do_flatfield = 1;
492 int do_optextract = 0;
493 int do_sub_sky = FALSE;
494 int generate_sdp_format = 0;
495 xsh_extract_param extract_par = { LOCALIZATION_METHOD };
496
497 xsh_opt_extract_param *opt_extract_par = NULL;
498 xsh_subtract_sky_single_param *sky_par = NULL;
499
501 int nb_raw_frames ;
502 char rec_name[256];
503
504 /* Intermediate frames */
505 cpl_frame * crhm_frame = NULL ;
506 //cpl_frame * rmbias = NULL; /**< Output of subtract bias */
507 cpl_frame * rmdark = NULL;
508 cpl_frame * rmbkg = NULL ;
509 cpl_frame * div_frame = NULL ;
512 cpl_frame * sub_sky_frame = NULL ;
513 cpl_frame * sub_sky2_frame = NULL ;
515 cpl_frame * rect_frame = NULL ;
516 cpl_frame * loc_table_frame = NULL ;
517 cpl_frame * clean_frame = NULL ;
518 cpl_frame * rect2_frame = NULL ;
519 cpl_frame * rect2_frame_eso = NULL ;
520 cpl_frame * rect2_frame_tab = NULL ;
521
522
523 cpl_frame * rect2_sky_frame = NULL ;
524 cpl_frame * rect2_sky_frame_eso = NULL ;
525 cpl_frame * rect2_sky_frame_tab = NULL ;
526
527 /* Output Frames (results)*/
528 cpl_frame * sky_frame = NULL ;
529 cpl_frame * sky_frame_eso = NULL ;
530 cpl_frame * res_1D_frame = NULL ;
531 cpl_frame * res_2D_frame = NULL ;
532 cpl_frame * res_2D_sky_frame = NULL ;
533
534 cpl_frame * fluxcal_rect_1D_frame = NULL ;
535 cpl_frame * fluxcal_rect_2D_frame = NULL ;
536 cpl_frame * fluxcal_1D_frame = NULL ;
537 cpl_frame * fluxcal_2D_frame = NULL ;
538
539 cpl_frame * ext_frame = NULL ;
540 cpl_frame * ext_frame_eso = NULL ;
541
542 cpl_frame *orderext1d_frame = NULL;
543 cpl_frame *orderoxt1d_frame = NULL;
544 cpl_frame *orderoxt1d_eso_frame = NULL;
545
546 cpl_frame *mergeext1d_frame = NULL;
547 cpl_frame *mergeoxt1d_frame = NULL;
548 cpl_frame *fluxcal_rect_opt1D_frame = NULL;
549 cpl_frame *fluxcal_merg_opt1D_frame = NULL;
550 cpl_frame* ext_sky_frame=NULL;
551 cpl_frame* res_1D_sky_frame=NULL;
552
553 cpl_frame * fluxframe = NULL;
554 cpl_frame * uncalframe = NULL;
555
556
557
558
559
560 cpl_frame* grid_backg=NULL;
561 cpl_frame* frame_backg=NULL;
562 cpl_frame* sky_frame_ima=NULL;
563 char prefix[256];
564 char fname[256];
565 char tag[256];
566
567 const char* ftag=NULL;
568
569 cpl_frame* single_frame_sky_sub_tab_frame=NULL;
570/*
571 char sky_name[256];
572*/
573 cpl_frame* clean_obj=NULL;
574 char *rec_prefix = NULL;
575 char sky_prefix[256];
576 cpl_frame* sky_list_frame=NULL;
577 cpl_frame* qc_sky_frame=NULL;
578 cpl_propertylist* plist=NULL;
579
580 xsh_pre* pre_sci=NULL;
581
582 cpl_frame* response_frame=NULL;
583 cpl_frame* frm_atmext=NULL;
584 int pre_overscan_corr=0;
585 cpl_frame *qc_subex_frame = NULL;
586 cpl_frame *qc_s2ddiv1d_frame = NULL;
587 cpl_frame *qc_model_frame = NULL;
588 cpl_frame *qc_weight_frame = NULL;
589 int merge_par=0;
590 xsh_interpolate_bp_param *ipol_bp=NULL;
591 cpl_frameset* crh_clean_lacosmic = NULL;
592 cpl_frameset *sub_bias_set = NULL;
593 cpl_frameset *sub_dark_set = NULL;
594 cpl_frame* sky_map_frm = NULL;
595 cpl_frame* sky_orders_chunks =NULL;
596 int cut_uvb_spectrum=0;
597 cpl_propertylist* qclist = cpl_propertylist_new();
598
599 /**************************************************************************/
600 /* DFS management */
601 /**************************************************************************/
602 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
603 recipe_tags, recipe_tags_size,
604 RECIPE_ID, XSH_BINARY_VERSION,
606
607 //get average airm, iwv and fwhm from raws; add keywords to qclist
609
610 /*
611 assure( instrument->mode == XSH_MODE_SLIT, CPL_ERROR_ILLEGAL_INPUT,
612 "Instrument NOT in Slit Mode" ) ;
613 */
615 if(instrument->arm == XSH_ARM_NIR) {
617 }
618 /**************************************************************************/
619 /* Recipe frames */
620 /**************************************************************************/
621
622 check( nb_raw_frames = cpl_frameset_get_size( raws ) ) ;
623 xsh_msg_dbg_low("nb_raw_frames=%d",nb_raw_frames);
624
625 if(nb_raw_frames>1) {
627 }
628
629 check( pre_overscan_corr = xsh_parameters_get_int( parameters, RECIPE_ID,
630 "pre-overscan-corr"));
631
632
633 check(xsh_slit_stare_get_calibs(calib,instrument, &spectralformat_frame,
634 &master_bias,&master_dark,&master_flat,
635 &order_tab_edges,&model_config_frame,
636 &wave_tab,&sky_list_frame,&sky_orders_chunks,
637 &qc_sky_frame,
638 &bpmap,&single_frame_sky_sub_tab_frame,
639 &wavemap_frame,&slitmap_frame,RECIPE_ID,
640 &recipe_use_model,pre_overscan_corr));
641
642 /* scired extra frames */
643
644 if((response_frame=xsh_find_frame_with_tag(calib,XSH_RESPONSE_MERGE1D_SLIT,
645 instrument)) == NULL ) {
647 instrument));
648 }
649 if(response_frame != NULL) {
651 if( frm_atmext==NULL ) {
652 xsh_msg_error("Provide atmospheric extinction frame");
653 return CPL_ERROR_DATA_NOT_FOUND;
654 }
655 }
656
657
658 tellmask_frame = xsh_find_frame_with_tag(calib,XSH_TELL_MASK, instrument);
659 /**************************************************************************/
660 /* Recipe parameters */
661 /**************************************************************************/
662 check(xsh_slit_stare_get_params(parameters,RECIPE_ID, &pre_overscan_corr,
663 &backg_par,&loc_obj_par,
664 &rectify_par,&crh_single_par,&sub_sky_nbkpts1,
665 &do_flatfield,&sub_sky_nbkpts2,&sky_par,
666 &do_optextract,
667 &opt_extract_par,
668 &generate_sdp_format));
669 cut_uvb_spectrum=xsh_parameters_cut_uvb_spectrum_get(RECIPE_ID,parameters);
670 backg_par->method=TRUE;
671 rectify_par->conserve_flux=FALSE;
673
674 check( stack_par = xsh_stack_frames_get( RECIPE_ID, parameters));
675
677 instrument,rectify_par));
678 /* PIPE-9833 */
680 instrument, crh_single_par));
681
683 parameters));
684 if ( (do_sub_sky && !do_compute_map) &&
685 (wavemap_frame == NULL || slitmap_frame == NULL) ) {
686 xsh_msg_warning( "sky-subtract is true but wave,slits maps missing create them");
687 do_compute_map = TRUE;
688
689 }
690
691 /* adjust relevant parameter to binning */
693 check(xsh_stare_params_bin_scale(raws,backg_par,
694 opt_extract_par,
695 &sub_sky_nbkpts1,&sub_sky_nbkpts2));
696 }
697
698 /* parameters dependent input */
699 if ( do_compute_map && recipe_use_model==FALSE){
700 check_msg(disp_tab_frame = xsh_find_disp_tab( calib, instrument),
701 "compute-map=TRUE, physmodel mode, you must give a DISP_TAB_ARM input");
702 }
703
704 check(xsh_params_monitor(rectify_par,loc_obj_par,opt_extract_par,
705 sub_sky_nbkpts1,sub_sky_nbkpts2));
706
707 // PIPE-10061 - get barycentric corr param
708 check(bary_par = xsh_parameters_bary_corr_get( RECIPE_ID, parameters)) ;
709
710 /**************************************************************************/
711 /* Recipe code */
712 /**************************************************************************/
713 /* prepare RAW frames in XSH format */
714 check(xsh_prepare(raws, bpmap, master_bias, XSH_OBJECT_SLIT_STARE,
715 instrument,pre_overscan_corr,CPL_TRUE));
716
717
718
719
720 /* subtract bias from each raw frame, checking if overscan correction was already made */
721 cpl_frame* frm = NULL;
722 cpl_frame* sub = NULL;
723
724 int i = 0;
725 int nraws = 0;
726 if (master_bias != NULL) {
727
728 xsh_msg( "Subtract bias");
729 sub_bias_set = cpl_frameset_new();
730 nraws = cpl_frameset_get_size(raws);
731
732 for (i = 0; i < nraws; i++) {
733 sprintf(prefix, "SCI_SUB_%d_", i);
734 frm = cpl_frameset_get_frame(raws, i);
735 //xsh_free_frame(&sub);
736 sub = xsh_check_subtract_bias(frm, master_bias, instrument, prefix,
737 pre_overscan_corr, 0);
738 cpl_frameset_insert(sub_bias_set, sub);
739 }
740 } else {
741 sub_bias_set = cpl_frameset_duplicate(raws);
742 }
743 //rmbias=cpl_frameset_get_frame(sub_bias_set,0);
744
745 /* subtract dark from each raw frame */
746 if (master_dark != NULL) {
747 xsh_msg( "Subtract dark");
748
749 sub_dark_set = cpl_frameset_new();
750 nraws = cpl_frameset_get_size(sub_bias_set);
751
752 for (i = 0; i < nraws; i++) {
753 sprintf(prefix, "SCI_%d_SUBTRACT", i);
754 frm = cpl_frameset_get_frame(sub_bias_set, i);
755 //xsh_free_frame(&sub);
756 sub = xsh_check_subtract_dark(frm, master_dark, instrument, prefix);
757 cpl_frameset_insert(sub_dark_set, sub);
758 }
759
760 } else {
761 sub_dark_set = cpl_frameset_duplicate(sub_bias_set);
762 }
763 xsh_free_frameset(&sub_bias_set);
764 rmdark=cpl_frameset_get_frame(sub_dark_set,0);
765
766 check( rec_prefix = xsh_set_recipe_file_prefix( raws,
767 "xsh_scired_slit_stare"));
768 sprintf(prefix,"%s_",rec_prefix);
769 sky_map_frm = xsh_find_frame_with_tag(calib,XSH_SKY_MAP, instrument);
770 crh_clean_lacosmic = xsh_frameset_crh_single(sub_dark_set, crh_single_par,
771 sky_map_frm, instrument, rec_prefix, "OBJ");
772
773
774
775 /* pre CRH removal (method multi) as scired may have more than 2 in frames */
777 check( crhm_frame = xsh_check_remove_crh_multiple( crh_clean_lacosmic, ftag,
778 stack_par,NULL, instrument, NULL, NULL));
779
781 do_compute_map,recipe_use_model,rec_prefix,
782 instrument,model_config_frame,crhm_frame,
783 disp_tab_frame,order_tab_edges,
784 &wavemap_frame, &slitmap_frame));
785
786 if( backg_par->method ) {
787 /* subtract inter-order background */
788 xsh_msg("Subtract inter-order background");
789 check(rmbkg = xsh_subtract_background( crhm_frame,
790 order_tab_edges,
791 backg_par, instrument,rec_prefix,
792 &grid_backg,&frame_backg,1,0,1));
793
794 } else {
795 cpl_frame* frm_tmp=NULL;
796 rmbkg = cpl_frame_duplicate( rmdark );
797 pre_sci=xsh_pre_load(rmbkg,instrument);
798 sprintf(tag,"%sNO_SUB_BACK_%s",prefix,
800 sprintf(fname,"%s.fits",tag);
801 frm_tmp=xsh_pre_save(pre_sci,fname,tag,0);
802 cpl_frame_set_filename(rmbkg,fname);
803 cpl_frame_set_tag(rmbkg,tag);
804 xsh_free_frame(&frm_tmp);
805 xsh_pre_free(&pre_sci);
806 }
807
808 /* In case CRH single or localize auto do preliminary sky subtraction */
809 xsh_slit_stare_correct_crh_and_sky(loc_obj_par,crh_single_par,rectify_par,
810 do_sub_sky,rec_prefix,rmbkg,
811 order_tab_edges, slitmap_frame,
812 wavemap_frame,sky_map_frm,model_config_frame,
813 single_frame_sky_sub_tab_frame,instrument,
814 sub_sky_nbkpts1, sky_par,sky_list_frame,sky_orders_chunks,
815 &sky_frame,&sky_frame_eso,&sky_frame_ima,
816 wave_tab,disp_tab_frame,
817 spectralformat_frame,nb_raw_frames,
818 &loc_table_frame,&clean_frame,&clean_obj,0);
819
820 /* now we divide by the flat for proper sky subtraction */
821 check( div_frame = xsh_check_divide_flat( do_flatfield, clean_obj,
822 master_flat, instrument, rec_prefix));
823 xsh_free_frame(&sky_frame);
824 xsh_free_frame(&sky_frame_eso);
825 xsh_free_frame(&sky_frame_ima);
826 check( sub_sky2_frame = xsh_check_subtract_sky_single( do_sub_sky,
827 div_frame,
828 order_tab_edges,
829 slitmap_frame,
830 wavemap_frame,
831 loc_table_frame,
832 single_frame_sky_sub_tab_frame,
834 sub_sky_nbkpts2,
835 sky_par,
836 sky_list_frame,sky_orders_chunks,
837 &sky_frame,
838 &sky_frame_eso,
839 &sky_frame_ima,
840 rec_prefix,
841 0));
842
843 xsh_msg( "Prepare S2D products" ) ;
844 xsh_msg( "Rectify") ;
845 sprintf(rec_name,"%s_%s_%s.fits",rec_prefix,XSH_ORDER2D,
847
848 check( rect2_frame = xsh_rectify( sub_sky2_frame, order_tab_edges,
849 wave_tab, model_config_frame, instrument,
850 rectify_par,spectralformat_frame,
851 disp_tab_frame,rec_name,
852 &rect2_frame_eso,&rect2_frame_tab,
853 rec_prefix));
854
855 if(sky_frame_ima) {
856 /* rectify sky frame for QC */
857 sprintf(sky_prefix,xsh_set_recipe_sky_file_prefix(rec_prefix));
858 sprintf(rec_name,"%s_%s_%s.fits",sky_prefix,XSH_ORDER2D,
860
861 check( rect2_sky_frame = xsh_rectify( sky_frame_ima, order_tab_edges,
862 wave_tab, model_config_frame,
863 instrument,rectify_par,
864 spectralformat_frame,disp_tab_frame,
865 rec_name,&rect2_sky_frame_eso,
866 &rect2_sky_frame_tab,rec_prefix));
867
868 xsh_add_temporary_file(cpl_frame_get_filename(rect2_sky_frame_eso));
869 /* the following frame is re-created by next function */
870 xsh_free_frame(&rect2_sky_frame_eso);
871 check(ext_sky_frame = xsh_extract_clean(rect2_sky_frame, loc_table_frame,
872 instrument, &extract_par,ipol_bp,
873 &rect2_sky_frame_eso,rec_prefix ));
874
875 check( res_1D_sky_frame = xsh_merge_ord( ext_sky_frame, instrument,
876 merge_par,sky_prefix));
877
878 }
879
880 xsh_msg( "Extract" ) ;
881 check(ext_frame=xsh_extract_clean(rect2_frame, loc_table_frame,
882 instrument, &extract_par,ipol_bp,
883 &ext_frame_eso,rec_prefix)) ;
884
885 xsh_msg( "Merge orders with 1D frame" ) ;
886 check( res_1D_frame = xsh_merge_ord( ext_frame, instrument,
887 merge_par,rec_prefix));
888 check( xsh_mark_tell( res_1D_frame, tellmask_frame));
889
890
891
892
893 xsh_msg( "Calling xsh_merge_ord with 2D frame" ) ;
894 if( rect2_sky_frame ) {
895 check( res_2D_sky_frame = xsh_merge_ord( rect2_sky_frame, instrument,
896 merge_par,sky_prefix));
897 }
898 check( res_2D_frame = xsh_merge_ord( rect2_frame, instrument,
899 merge_par,rec_prefix));
900
901
902
903 xsh_msg("Prepare S1D products" ) ;
904 /* doing optimal extraction */
905 if ( do_optextract){
906 xsh_msg( "Optimal extraction");
907 check( xsh_opt_extract( sub_sky2_frame, order_tab_edges,
908 wave_tab, model_config_frame, wavemap_frame,
909 slitmap_frame, loc_table_frame,
910 spectralformat_frame, master_flat, instrument,
911 opt_extract_par, rec_prefix,
912 &orderext1d_frame, &orderoxt1d_frame,
913 &orderoxt1d_eso_frame,
914 &qc_subex_frame,
915 &qc_s2ddiv1d_frame,
916 &qc_model_frame,
917 &qc_weight_frame));
918
919 check( mergeext1d_frame = xsh_merge_ord( orderext1d_frame, instrument,
920 merge_par,rec_prefix));
921 check( mergeoxt1d_frame = xsh_merge_ord( orderoxt1d_frame, instrument,
922 merge_par,rec_prefix));
923
924 check( xsh_mark_tell( mergeext1d_frame, tellmask_frame));
925 check( xsh_mark_tell( mergeoxt1d_frame, tellmask_frame));
926 }
927
928 cpl_boolean flux_available = CPL_FALSE;
929 if(response_frame != NULL && frm_atmext != NULL) {
930 check(xsh_flux_calibrate(rect2_frame_eso,ext_frame_eso,frm_atmext,
931 response_frame,merge_par,instrument,rec_prefix,
932 &fluxcal_rect_2D_frame,&fluxcal_rect_1D_frame,
933 &fluxcal_2D_frame,&fluxcal_1D_frame));
934 flux_available = CPL_TRUE;
935
936 if ( do_optextract){
937
938 check(xsh_flux_calibrate1D(orderoxt1d_eso_frame,frm_atmext,
939 response_frame,merge_par,instrument,rec_prefix,
940 &fluxcal_rect_opt1D_frame,
941 &fluxcal_merg_opt1D_frame));
942
943 }
944
945 }
946
947 cpl_propertylist_append_bool(qclist,"ESO QC FLUX AVAILABLE",flux_available);
948
949
950 //xsh_msg( "Calling xsh_mark_tell (TBW)" ) ;
951 // check( tell_frame = xsh_mark_tell(merge_frame, tell_mask, tell_params )) ;
952
953 //xsh_msg( "Calling xsh_calibrate_flux (TBW)" ) ;
954 //check( res_2d_frame = xsh_calibrate_flux( tell_frame, response, ??? ) ) ;
955
956 if(model_config_frame!=NULL && wavemap_frame != NULL&& slitmap_frame != NULL) {
957
958 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,res_2D_frame,instrument));
959 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,rect2_frame_eso,instrument));
960
961 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,res_1D_frame,instrument));
962 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,ext_frame_eso,instrument));
963
964 xsh_add_afc_info(model_config_frame,wavemap_frame);
965 xsh_add_afc_info(model_config_frame,slitmap_frame);
966
967 if(fluxcal_rect_2D_frame != NULL) {
968
969 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,fluxcal_rect_2D_frame,instrument));
970 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,fluxcal_2D_frame,instrument));
971
972 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,fluxcal_rect_1D_frame,instrument));
973 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,fluxcal_1D_frame,instrument));
974
975 }
976
977 if(res_2D_sky_frame) {
978 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,res_2D_sky_frame,instrument));
979 }
980
981 if ( do_sub_sky == 1 ) {
982 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,sky_frame_eso,instrument));
983 }
984 }
985
986 if(cut_uvb_spectrum) {
987 if(instrument->arm == XSH_ARM_UVB) {
988 xsh_image_cut_dichroic_uvb(rect2_frame_eso);
990 xsh_spectrum_cut_dichroic_uvb(res_1D_frame);
991 xsh_spectrum_cut_dichroic_uvb(res_2D_frame);
992
993 if(res_2D_sky_frame) {
994 xsh_spectrum_cut_dichroic_uvb(res_2D_sky_frame);
995 xsh_spectrum_cut_dichroic_uvb(res_1D_sky_frame);
996 }
997
998 if ( do_optextract){
999 xsh_spectrum_cut_dichroic_uvb(mergeext1d_frame);
1000 xsh_spectrum_cut_dichroic_uvb(mergeoxt1d_frame);
1001 }
1002
1003 if(fluxcal_rect_2D_frame != NULL) {
1004 xsh_image_cut_dichroic_uvb(fluxcal_rect_2D_frame);
1005 xsh_spectrum_orders_cut_dichroic_uvb(fluxcal_rect_1D_frame,instrument);
1006 xsh_spectrum_cut_dichroic_uvb(fluxcal_2D_frame);
1007 xsh_spectrum_cut_dichroic_uvb(fluxcal_1D_frame);
1008 if ( do_optextract){
1009 //xsh_spectrum_cut_dichroic_uvb(fluxcal_rect_opt1D_frame);
1010 //xsh_spectrum_cut_dichroic_uvb(fluxcal_merg_opt1D_frame);
1011 }
1012
1013 }
1014
1015 }
1016 }
1018
1019 /* saving products */
1020
1021 xsh_msg( "Save products" ) ;
1022 usedframes = cpl_frameset_duplicate(frameset);
1023
1024 sprintf(prefix,"%s_ORDER2D",rec_prefix);
1025 check( xsh_add_product_image(rect2_frame_eso, frameset, parameters,
1026 RECIPE_ID, instrument,prefix));
1027 xsh_add_product_orders_spectrum(ext_frame_eso, frameset, parameters,
1028 RECIPE_ID, instrument,NULL);
1029
1030 /* Calculate curvature QC params early */
1031 cpl_image* itmp = cpl_image_load(cpl_frame_get_filename(res_2D_frame),CPL_TYPE_DOUBLE,0,0);
1032 calc_curve_qc(itmp,instrument,qclist);
1033 cpl_image_delete(itmp);
1034
1035 check( xsh_add_product_spectrum( res_2D_frame, frameset, parameters,
1036 RECIPE_ID, instrument, NULL,qclist));
1037
1038 xsh_monitor_spectrum1D_extra_qc(res_1D_frame,instrument,qclist);
1039 check( xsh_add_product_spectrum(res_1D_frame, frameset, parameters,
1040 RECIPE_ID, instrument, &uncalframe,qclist));
1041
1042 if(res_2D_sky_frame) {
1043 check( xsh_add_product_spectrum( res_2D_sky_frame, frameset, parameters,
1044 RECIPE_ID, instrument, NULL,NULL));
1045 check( xsh_add_product_spectrum( res_1D_sky_frame, frameset, parameters,
1046 RECIPE_ID, instrument, NULL,NULL));
1047 }
1048
1049 check( xsh_add_product_image( rmbkg, frameset, parameters,
1050 RECIPE_ID, instrument,NULL));
1051
1052 if (do_compute_map){
1053 //sprintf(prefix,"%s_WAVE_MAP",rec_prefix);
1054
1055
1056 check(xsh_add_product_image( wavemap_frame, frameset,
1057 parameters, RECIPE_ID, instrument, NULL));
1058
1059 //check(sprintf(prefix,"%s_SLIT_MAP",rec_prefix));
1060
1061 check(xsh_add_product_image( slitmap_frame, frameset,
1062 parameters, RECIPE_ID, instrument,NULL));
1063 }
1064 if(do_flatfield) {
1065
1066 check( xsh_add_product_image( div_frame, frameset, parameters,
1067 RECIPE_ID, instrument,NULL));
1068 }
1069
1070 if ( do_optextract){
1071 check( xsh_add_product_table( orderext1d_frame, frameset,parameters,
1072 RECIPE_ID, instrument,NULL));
1073 check( xsh_add_product_table( orderoxt1d_frame, frameset,parameters,
1074 RECIPE_ID, instrument,NULL));
1075 check( xsh_add_product_spectrum( mergeext1d_frame, frameset, parameters,
1076 RECIPE_ID, instrument, NULL,NULL));
1077 check( xsh_add_product_spectrum( mergeoxt1d_frame, frameset,
1078 parameters, RECIPE_ID, instrument, NULL,NULL));
1079 check( xsh_add_product_image( qc_subex_frame, frameset, parameters,
1081 cpl_frame_get_tag(qc_subex_frame)));
1082 check( xsh_add_product_image( qc_s2ddiv1d_frame, frameset, parameters,
1084 cpl_frame_get_tag(qc_s2ddiv1d_frame)));
1085 check( xsh_add_product_image( qc_model_frame, frameset, parameters,
1087 cpl_frame_get_tag(qc_model_frame)));
1088 check( xsh_add_product_image( qc_weight_frame, frameset, parameters,
1090 cpl_frame_get_tag(qc_weight_frame)));
1091 }
1092 if ( do_sub_sky == 1 ) {
1093 check( xsh_add_product_pre( sub_sky2_frame, frameset, parameters,
1094 RECIPE_ID, instrument,NULL));
1095 check( xsh_add_product_image( sky_frame_ima, frameset, parameters,
1096 RECIPE_ID, instrument,NULL));
1097 xsh_add_product_table(sky_frame_eso, frameset, parameters, RECIPE_ID,
1098 instrument, NULL);
1099 }
1100 if(frame_backg != NULL) {
1101 check( xsh_add_product_image( frame_backg, frameset, parameters,
1102 RECIPE_ID, instrument,NULL));
1103 }
1104 if(crhm_frame != NULL) {
1105 sprintf(tag,"%s_ON",rec_prefix);
1106 check( xsh_add_product_image( crhm_frame, frameset, parameters,
1107 RECIPE_ID, instrument,tag));
1108
1109 }
1110
1111 if(qc_sky_frame != NULL) {
1112 check( xsh_add_product_table(qc_sky_frame, frameset,parameters,
1113 RECIPE_ID, instrument,NULL));
1114
1115 }
1116
1117 if(fluxcal_rect_2D_frame != NULL) {
1118 check( xsh_add_product_image( fluxcal_rect_2D_frame, frameset, parameters,
1119 RECIPE_ID, instrument,NULL));
1120
1121 check( xsh_add_product_orders_spectrum( fluxcal_rect_1D_frame, frameset, parameters,
1122 RECIPE_ID, instrument,NULL));
1123
1124 check( xsh_add_product_spectrum( fluxcal_2D_frame, frameset, parameters,
1125 RECIPE_ID, instrument, NULL,qclist));
1126
1127 xsh_monitor_spectrum1D_extra_qc(fluxcal_1D_frame,instrument,qclist);
1128 check( xsh_add_product_spectrum( fluxcal_1D_frame, frameset, parameters,
1129 RECIPE_ID, instrument, &fluxframe,qclist));
1130
1131 if ( do_optextract){
1132
1133 check( xsh_add_product_orders_spectrum( fluxcal_rect_opt1D_frame, frameset,
1134 parameters, RECIPE_ID, instrument,
1135 NULL));
1136
1137 check( xsh_add_product_spectrum( fluxcal_merg_opt1D_frame, frameset,
1138 parameters, RECIPE_ID, instrument,
1139 NULL,qclist));
1140
1141 }
1142 }
1143
1144 if (generate_sdp_format) {
1145 cpl_frame * fluxframe_copy = fluxframe;
1146 cpl_frame * uncalframe_copy = uncalframe;
1147 if (fluxframe != NULL) {
1148 check( cpl_frameset_insert(usedframes, fluxframe) );
1149 fluxframe = NULL; /* prevent direct deletion in cleanup section,
1150 will be deleted together with usedframes. */
1151 }
1152 if (uncalframe != NULL) {
1153 check( cpl_frameset_insert(usedframes, uncalframe) );
1154 uncalframe = NULL; /* prevent direct deletion in cleanup section,
1155 will be deleted together with usedframes. */
1156 }
1157 check( xsh_add_sdp_product_spectrum(fluxframe_copy, uncalframe_copy,
1158 frameset, usedframes, parameters, RECIPE_ID, instrument,qclist) );
1159 /* Restore usedframes to what it was before in case we want to reuse it */
1160 if (fluxframe_copy != NULL) {
1161 check( cpl_frameset_erase_frame(usedframes, fluxframe_copy) );
1162 }
1163 if (uncalframe_copy != NULL) {
1164 check( cpl_frameset_erase_frame(usedframes, uncalframe_copy) );
1165 }
1166 }
1167
1168 cleanup:
1169
1170 xsh_end( RECIPE_ID, frameset, parameters );
1171
1172 XSH_FREE( rec_prefix);
1173 XSH_FREE( backg_par);
1174 XSH_FREE(ipol_bp);
1175 XSH_FREE( crh_single_par);
1176 XSH_FREE( rectify_par);
1177 XSH_FREE( stack_par);
1178 XSH_FREE( sky_par);
1179 XSH_FREE( loc_obj_par);
1180 XSH_FREE( opt_extract_par);
1182 XSH_FREE( bary_par);
1183
1184 xsh_free_frameset(&usedframes);
1185 xsh_free_frameset(&raws);
1186 xsh_free_frameset(&calib);
1187 xsh_free_frame( &crhm_frame);
1188 xsh_free_frame( &qc_sky_frame);
1189 xsh_free_frame(&res_1D_sky_frame);
1190 xsh_free_frame(&ext_sky_frame);
1191 xsh_free_frameset(&crh_clean_lacosmic);
1192
1193 if(do_compute_map) {
1194 xsh_free_frame( &wavemap_frame);
1195 xsh_free_frame( &slitmap_frame);
1196 }
1197
1198 xsh_free_frameset(&sub_bias_set);
1199 xsh_free_frameset(&sub_dark_set);
1200 //xsh_free_frame(&rmbias);
1201
1202 //xsh_free_frame(&rmdark);
1203 xsh_free_frame(&rmbkg);
1204 xsh_free_frame(&div_frame);
1205 xsh_free_frame(&sub_sky_frame);
1206
1207 xsh_free_frame(&bpmap);
1208 xsh_free_frame(&sub_sky2_frame);
1209 xsh_free_frame(&sky_frame);
1210 xsh_free_frame(&sky_frame_eso);
1211 xsh_free_frame(&sky_frame_ima);
1212
1213 xsh_free_frame(&rect_frame) ;
1214 xsh_free_frame(&rect2_frame_eso) ;
1215 xsh_free_frame(&rect2_frame_tab) ;
1216
1217 xsh_free_frame(&rect2_sky_frame) ;
1218 xsh_free_frame(&rect2_sky_frame_eso) ;
1219 xsh_free_frame(&rect2_sky_frame_tab) ;
1220
1221
1222 xsh_free_frame( &orderext1d_frame);
1223 xsh_free_frame( &orderoxt1d_frame);
1224 xsh_free_frame( &mergeext1d_frame);
1225 xsh_free_frame( &mergeoxt1d_frame);
1226
1227 xsh_free_frame(&loc_table_frame) ;
1228 xsh_free_frame( &clean_frame);
1229 xsh_free_frame( &clean_obj);
1230 xsh_free_frame( &ext_frame);
1231 xsh_free_frame( &ext_frame_eso);
1232
1233 xsh_free_frame(&res_1D_frame) ;
1234 xsh_free_frame(&res_2D_frame) ;
1235
1236 xsh_free_frame(&res_2D_sky_frame) ;
1237
1238 xsh_free_frame(&fluxcal_rect_1D_frame) ;
1239 xsh_free_frame(&fluxcal_rect_2D_frame) ;
1240 xsh_free_frame(&fluxcal_1D_frame) ;
1241 xsh_free_frame(&fluxcal_2D_frame) ;
1242
1243 //xsh_free_frame(&frm_atmext) ;
1244 xsh_free_frame(&rect2_frame) ;
1245 xsh_free_frame(&grid_backg) ;
1246 xsh_free_frame(&frame_backg) ;
1247 xsh_free_propertylist(&plist);
1248 xsh_free_frame( &qc_subex_frame);
1249 xsh_free_frame(&qc_s2ddiv1d_frame);
1250 xsh_free_frame(&qc_model_frame);
1251 xsh_free_frame(&qc_weight_frame);
1252
1253 xsh_free_frame(&fluxframe);
1254 xsh_free_frame(&uncalframe);
1255
1256 return CPL_ERROR_NONE;
1257}
1258
static xsh_instrument * instrument
void xsh_mark_tell(cpl_frame *s1d_frame, cpl_frame *tellmask_frame)
Mark telluric in spectrum.
cpl_error_code xsh_monitor_spectrum1D_extra_qc(cpl_frame *in_frm, xsh_instrument *instrument, cpl_propertylist *qclist)
cpl_error_code xsh_monitor_spectrum1D_flux(cpl_frame *in_frm, xsh_instrument *instrument)
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
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
Definition: xsh_data_pre.c:823
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
cpl_error_code xsh_spectrum_cut_dichroic_uvb(cpl_frame *frame1d)
cpl_error_code xsh_spectrum_orders_cut_dichroic_uvb(cpl_frame *frame1d, xsh_instrument *instr)
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 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 check_msg(COMMAND,...)
Definition: xsh_error.h:62
#define xsh_error_reset()
Definition: xsh_error.h:87
cpl_frame * xsh_extract_clean(cpl_frame *rec_frame, cpl_frame *loc_frame, xsh_instrument *instrument, xsh_extract_param *extract_par, xsh_interpolate_bp_param *ipol_bp, cpl_frame **res_frame_ext, const char *rec_prefix)
simple 1D extraction of point source like object
Definition: xsh_extract.c:836
cpl_error_code xsh_instrument_nir_corr_if_JH(cpl_frameset *raws, xsh_instrument *instr)
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_frame * xsh_merge_ord(cpl_frame *sci_frame, xsh_instrument *instrument, int merge, 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
void xsh_opt_extract(cpl_frame *sci_frame, cpl_frame *order_table_frame, cpl_frame *wavesol_frame, cpl_frame *model_frame, cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, cpl_frame *loc_frame, cpl_frame *spectralformat_frame, cpl_frame *masterflat_frame, xsh_instrument *instrument, xsh_opt_extract_param *opt_extract_par, const char *rec_prefix, cpl_frame **orderext1d_frame, cpl_frame **orderoxt1d_frame, cpl_frame **orderoxt1d_eso_frame, cpl_frame **qc_subextract_frame, cpl_frame **qc_s2ddiv1d_frame, cpl_frame **qc_model_frame, cpl_frame **qc_weight_frame)
Create a SPECTRUM 1D from a Science frame.
cpl_frame * xsh_rectify(cpl_frame *sci_frame, cpl_frame *order_table_frame, cpl_frame *wavesol_frame, cpl_frame *model_config_frame, xsh_instrument *instrument, xsh_rectify_param *rectify_par, cpl_frame *spectral_format, cpl_frame *disp_tab_frame, const char *fname, cpl_frame **res_frame_ext, cpl_frame **res_frame_tab, const char *prefix)
Create a grid in wavelength with the step in lambda and slit. Steps are defined in the parameters....
Definition: xsh_rectify.c:867
static cpl_error_code xsh_scired_slit_stare(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
static int xsh_scired_slit_stare_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
#define RECIPE_CONTACT
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_scired_slit_stare_create(cpl_plugin *)
Setup the recipe options.
static cpl_error_code xsh_params_monitor(xsh_rectify_param *rectify_par, xsh_localize_obj_param *loc_obj_par, xsh_opt_extract_param *opt_extract_par, int sub_sky_nbkpts1, int sub_sky_nbkpts2)
static char xsh_scired_slit_stare_description[]
static char xsh_scired_slit_stare_description_short[]
static int xsh_scired_slit_stare_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
#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
const char * xsh_set_recipe_sky_file_prefix(char *rec_prefix)
Set recipe sky frames prefix.
Definition: xsh_utils.c:576
cpl_error_code get_average_qc_from_raws(cpl_frameset *fset, xsh_instrument *instrument, cpl_propertylist *qclist)
Definition: xsh_utils.c:7216
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
cpl_error_code calc_curve_qc(cpl_image *im, xsh_instrument *instrument, cpl_propertylist *qclist)
Definition: xsh_utils.c:7322
const char * xsh_get_license(void)
Get the pipeline copyright and license.
Definition: xsh_utils.c:1193
void xsh_init(void)
Reset library state.
Definition: xsh_utils.c:1160
cpl_error_code xsh_remove_crh_single_params_set_defaults(cpl_parameterlist *pars, const char *rec_id, xsh_instrument *inst, xsh_remove_crh_single_param *crh_single_par)
Definition: xsh_utils.c:6723
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
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
Definition: xsh_utils.c:1432
enum optextract_method method
@ XSH_ARM_UVB
@ XSH_ARM_NIR
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_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
void xsh_add_product_spectrum(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr, cpl_frame **result_frame, cpl_propertylist *qclist)
Definition: xsh_dfs.c:2067
void xsh_add_product_orders_spectrum(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr, cpl_frame **result_frame)
Definition: xsh_dfs.c:2260
cpl_error_code xsh_add_afc_info(cpl_frame *frm_m, cpl_frame *frm_o)
Definition: xsh_dfs.c:5199
void xsh_add_sdp_product_spectrum(const cpl_frame *flux_cal_frame, const cpl_frame *uncal_frame, cpl_frameset *frameset, const cpl_frameset *usedframes, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, cpl_propertylist *qclist)
Creates a 1D spectrum product in the Science Data Product format.
Definition: xsh_dfs.c:6326
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_error_code xsh_frameset_check_uniform_exptime(cpl_frameset *raws, xsh_instrument *inst)
Definition: xsh_dfs.c:5119
#define XSH_TELL_MASK
Definition: xsh_dfs.h:1183
#define XSH_ORDER2D
Definition: xsh_dfs.h:588
#define XSH_SKY_SLIT
Definition: xsh_dfs.h:233
#define XSH_SKY_MAP
Definition: xsh_dfs.h:282
#define XSH_STD_TELL_SLIT_STARE
Definition: xsh_dfs.h:462
#define XSH_ATMOS_EXT
Definition: xsh_dfs.h:1191
#define XSH_SLIT_STARE_REMOVE_CRH
Definition: xsh_dfs.h:156
#define XSH_STD_FLUX_SLIT_STARE
Definition: xsh_dfs.h:449
#define XSH_RESPONSE_MERGE1D_SLIT
Definition: xsh_dfs.h:1149
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_MRESPONSE_MERGE1D_SLIT
Definition: xsh_dfs.h:1159
#define XSH_OBJECT_SLIT_STARE
Definition: xsh_dfs.h:226
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.
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_sky_single(int do_subsky, cpl_frame *src_frame, cpl_frame *ordertabedges_frame, cpl_frame *slitmap_frame, cpl_frame *wavemap_frame, cpl_frame *loctab_frame, cpl_frame *definedbreakpoints_frame, xsh_instrument *instrument, int nbkpts, xsh_subtract_sky_single_param *sky_par, cpl_frame *ref_sky_list, cpl_frame *sky_orders_chunks, cpl_frame **sky_spectrum, cpl_frame **sky_spectrum_eso, cpl_frame **sky_img, const char *prefix, const int clean_tmp)
Check function sky subtraction on single frame.
cpl_frame * xsh_check_divide_flat(int do_flatfield, cpl_frame *clean_frame, cpl_frame *master_flat, xsh_instrument *instrument, const char *prefix)
Check function.
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_parameters_subtract_sky_single_create(const char *recipe_id, cpl_parameterlist *plist, xsh_subtract_sky_single_param p)
void xsh_parameters_pre_overscan(const char *recipe_id, cpl_parameterlist *plist)
int xsh_parameters_subtract_sky_single_get_true(const char *recipe_id, cpl_parameterlist *list)
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
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)
xsh_interpolate_bp_param * xsh_parameters_interpolate_bp_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)
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
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)
int xsh_parameters_cut_uvb_spectrum_get(const char *recipe_id, const cpl_parameterlist *list)
int xsh_parameters_get_int(const cpl_parameterlist *list, const char *recipe_id, const char *name)
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)
void xsh_parameters_new_int(cpl_parameterlist *list, const char *recipe_id, const char *name, int value, const char *comment)
void xsh_parameters_opt_extract_create(const char *recipe_id, cpl_parameterlist *list, xsh_opt_extract_param p)
Create the optimal extraction parameters in a parameters list.
@ FINE
#define SUBTRACT_SKY_SINGLE_NBKPTS
@ GAUSS_METHOD
@ MEDIAN_METHOD
@ BARY_CORR_NONE
@ LOC_MANUAL_METHOD
@ LOCALIZATION_METHOD
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
cpl_error_code xsh_image_cut_dichroic_uvb(cpl_frame *frame1d)
cpl_error_code xsh_stare_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)
Corrects parameters for binning.
cpl_error_code xsh_slit_stare_get_params(cpl_parameterlist *parameters, const char *rec_id, int *pre_overscan_corr, xsh_background_param **backg_par, xsh_localize_obj_param **loc_obj_par, xsh_rectify_param **rectify_par, xsh_remove_crh_single_param **crh_single_par, int *sub_sky_nbkpts1, int *do_flatfield, int *sub_sky_nbkpts2, xsh_subtract_sky_single_param **sky_par, int *do_optextract, xsh_opt_extract_param **opt_extract_par, int *generate_sdp_format)
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_error_code xsh_flux_calibrate(cpl_frame *rect2D, cpl_frame *rect1D, cpl_frame *atmext, cpl_frame *response, int mpar, xsh_instrument *inst, const char *rec_prefix, cpl_frame **fcal_rect_2D, cpl_frame **fcal_rect_1D, cpl_frame **fcal_2D, cpl_frame **fcal_1D)
cpl_error_code xsh_slit_stare_get_maps(cpl_frameset *calib, int do_compute_map, int recipe_use_model, const char *rec_prefix, xsh_instrument *instrument, cpl_frame *model_config_frame, cpl_frame *crhm_frame, cpl_frame *disp_tab_frame, cpl_frame *order_tab_edges, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame)
cpl_error_code xsh_compute_resampling_accuracy(cpl_frame *wavemap, cpl_frame *slitmap, cpl_frame *order_tab_edges, cpl_frame *model_config, cpl_frame *science, xsh_instrument *instrument)
cpl_error_code xsh_compute_wavelength_resampling_accuracy(cpl_frame *wavemap, cpl_frame *order_tab_edges, cpl_frame *model_config, cpl_frame *science, xsh_instrument *instrument)
cpl_error_code xsh_slit_stare_correct_crh_and_sky(xsh_localize_obj_param *loc_obj_par, xsh_remove_crh_single_param *crh_single_par, xsh_rectify_param *rectify_par, int do_sub_sky, const char *rec_prefix, cpl_frame *rmbkg, cpl_frame *order_tab_edges, cpl_frame *slitmap, cpl_frame *wavemap, cpl_frame *sky_map, cpl_frame *model_config, cpl_frame *single_frame_sky_sub_tab, xsh_instrument *instrument, int sub_sky_nbkpts1, xsh_subtract_sky_single_param *sky_par, cpl_frame *ref_sky_list, cpl_frame *sky_orders_chunks, cpl_frame **sky, cpl_frame **sky_eso, cpl_frame **sky_ima, cpl_frame *wave_tab, cpl_frame *disp_tab, cpl_frame *spectral_format, int nb_raw_frames, cpl_frame **loc_table, cpl_frame **clean, cpl_frame **clean_obj, const int clean_tmp)
correct CRH and sky lines (1st iteration)
cpl_error_code xsh_slit_stare_get_calibs(cpl_frameset *calib, xsh_instrument *instrument, cpl_frame **spectralformat, cpl_frame **mbias, cpl_frame **mdark, cpl_frame **mflat, cpl_frame **otab_edges, cpl_frame **model_cfg, cpl_frame **wave_tab, cpl_frame **sky_list, cpl_frame **sky_orders_chunks, cpl_frame **qc_sky, cpl_frame **bpmap, cpl_frame **sframe_sky_sub_tab, cpl_frame **wmap, cpl_frame **smap, const char *rec_id, int *recipe_use_model, int pscan)
cpl_error_code xsh_flux_calibrate1D(cpl_frame *rect1D, cpl_frame *atmext, cpl_frame *response, int mpar, xsh_instrument *inst, const char *rec_prefix, cpl_frame **fcal_rect_1D, cpl_frame **fcal_1D)