X-shooter Pipeline Reference Manual 3.8.15
xsh_respon_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 PURsPOSE. 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:22 $
23 * $Revision: 1.72 $
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 */
52#include <xsh_model_utils.h>
53#include <xsh_utils.h>
54#include <xsh_utils_table.h>
55#include <xsh_msg.h>
56/* DFS functions */
57#include <xsh_dfs.h>
58/* DRL functions */
59#include <xsh_drl.h>
60#include <xsh_drl_check.h>
61#include <xsh_pfits.h>
62#include <xsh_data_spectrum1D.h>
64#include <xsh_parameters.h>
65
66/* Library */
67#include <cpl.h>
68/* CRH Remove */
69
70
71/*-----------------------------------------------------------------------------
72 Defines
73 ----------------------------------------------------------------------------*/
74
75#define RECIPE_ID "xsh_respon_slit_stare"
76#define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, D. Bramich, A. Modigliani"
77#define RECIPE_CONTACT "amodigli@eso.org "
78
79/*-----------------------------------------------------------------------------
80 Functions prototypes
81 ----------------------------------------------------------------------------*/
82
83/*
84 * Plugin initalization, execute and cleanup handlers
85 */
86
87static int xsh_respon_slit_stare_create(cpl_plugin *);
88static int xsh_respon_slit_stare_exec(cpl_plugin *);
89static int xsh_respon_slit_stare_destroy(cpl_plugin *);
90
91/* The actual executor function */
92static cpl_error_code xsh_respon_slit_stare(cpl_parameterlist *, cpl_frameset *);
93
94/*-----------------------------------------------------------------------------
95 Static variables
96 ----------------------------------------------------------------------------*/
98"Compute the response function in SLIT stare mode";
99
101"This recipe computes the response function for arm\n\
102Input Frames : \n\
103 - A RAW frame (Tag = STD_FLUX_SLIT_STARE_arm, Type = RAW)\n\
104 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm, Type = PRE)\n\
105 - A master dark frame (Tag = MASTER_DARK_arm Type = PRE)\n\
106 - A master flat frame (Tag = MASTER_FLAT_SLIT_arm Type = PRE)\n\
107 - An order table frame(Tag = ORDER_TAB_EDGES_arm Type = ORD)\n\
108 - A wave solution frame(Tag = WAVE_TAB_2D_arm, Type = WAV)\n\
109 - [OPTIONAL] Table with dispersion coefficients (Tag = DISP_TAB_arm)\n\
110 - [OPTIONAL] A telluric model catalog (Tag = TELL_MOD_CAT_arm arm=VIS,NIR)\n\
111 - A standard star fluxes catalog (Tag = FLUX_STD_CATALOG_arm Type = FLX)\n\
112 - A table to set response sampling points (Tag = RESP_FIT_POINTS_CAT_arm)\n\
113 - An atmospheric extinction table (Tag = ATMOS_EXT_arm)\n\
114 if provided this is the one used to flux calibrate the spectra\n\
115 - [OPTIONAL,physmod mode] A table listing sky line positions (Tag = SKY_LINE_LIST_arm)\n\
116 this is used to be able to control quality of sky subtraction, for example\n\
117 projecting guess positions on the product SCI_SLIT_STARE_SUB_SKY_arm\n\
118 and is required if sky-method=BSPLINE\n\
119Products : \n\
120 - [If STD is in catal] The response ord-by-ord function (Tag = PREFIX_RESPONSE_ORDER1D_SLIT_arm)\n\
121 - [If STD is in catal] The response merged function (Tag = PREFIX_RESPONSE_MERGE1D_SLIT_arm)\n\
122 - The extracted 2D specturm (Tag = PREFIX_ORDER2D_arm)\n\
123 - The extracted 1D specturm (Tag = PREFIX_ORDER1D_arm)\n\
124 - The merged 2D specturm (Tag = PREFIX_MERGE2D_arm)\n\
125 - The merged 1D specturm (Tag = PREFIX_MERGE1D_arm)\n\
126 - The merged 2D sky frame (Tag = SLY_SLIT_MERGED2D)\n\
127 - [If STD is in catal] Flux calibrated merged 2D spectrum (Tag = PREFIX_FLUX_ORDER2D_arm)\n\
128 - [If STD is in catal] Flux calibrated merged 1D spectrum (Tag = PREFIX_FLUX_ORDER1D_arm)\n\
129 - [If STD is in catal] Flux calibrated merged 2D spectrum (Tag = PREFIX_FLUX_MERGE2D_arm)\n\
130 - [If STD is in catal] Flux calibrated merged 1D spectrum (Tag = PREFIX_FLUX_MERGE1D_arm)\n\
131 - [If STD is in catal] The efficiency (Tag = EFFICIENCY_SLIT_arm)\n\
132 - where PREFIX is SCI, FLUX, TELL if input raw DPR.TYPE contains OBJECT or FLUX or TELLURIC";
133
134/*-----------------------------------------------------------------------------
135 Functions code
136 ----------------------------------------------------------------------------*/
137/*----------------------------------------------------------------------------*/
146/*----------------------------------------------------------------------------*/
147
148int cpl_plugin_get_info(cpl_pluginlist *list) {
149 cpl_recipe *recipe = NULL;
150 cpl_plugin *plugin = NULL;
151
152 recipe = cpl_calloc(1, sizeof(*recipe));
153 if ( recipe == NULL ){
154 return -1;
155 }
156
157 plugin = &recipe->interface ;
158
159 cpl_plugin_init(plugin,
160 CPL_PLUGIN_API, /* Plugin API */
161 XSH_BINARY_VERSION, /* Plugin version */
162 CPL_PLUGIN_TYPE_RECIPE, /* Plugin type */
163 RECIPE_ID, /* Plugin name */
165 xsh_respon_slit_stare_description, /* Detailed help */
166 RECIPE_AUTHOR, /* Author name */
167 RECIPE_CONTACT, /* Contact address */
168 xsh_get_license(), /* Copyright */
172
173 cpl_pluginlist_append(list, plugin);
174
175 return (cpl_error_get_code() != CPL_ERROR_NONE);
176}
177
178/*----------------------------------------------------------------------------*/
188/*----------------------------------------------------------------------------*/
189
190static int xsh_respon_slit_stare_create(cpl_plugin *plugin){
191 cpl_recipe *recipe = NULL;
192
193 xsh_remove_crh_single_param crh_single = {0.1, 20,2.0, 4} ;
194 /* First param (conv_kernel) should be initialized correctly ! */
195 xsh_rectify_param rectify = { "tanh",
196 CPL_KERNEL_DEFAULT,
197 2,
198 -1.0,
199 -1.0,
200 1,
201 0, 0.} ;
202
203
204 xsh_subtract_sky_single_param sky_single = {3000, 3000,7,20, 5., -1, -1,
205 MEDIAN_METHOD, FINE,20, 0.5,
206 0.0, 0.0,
207 0.0, 0.0} ;
208
209
210 /* 2nd and 3rd params should be initialized correctly */
211 xsh_localize_obj_param loc_obj =
212 {10, 0.1, 0, 0, LOC_MANUAL_METHOD, 0, 2.0,3,3,FALSE};
213
214 xsh_opt_extract_param opt_extract_par =
215 { 5, 10, 10, 0.01, 10.0, 1., 2, 2, GAUSS_METHOD };
216
217 xsh_interpolate_bp_param ipol_par = {30 };
218 /* Parameters init */
219 opt_extract_par.oversample = 5;
220 opt_extract_par.box_hsize = 10;
221 opt_extract_par.chunk_size = 50;
222 opt_extract_par.lambda_step = 0.02;
223 opt_extract_par.clip_kappa = 3;
224 opt_extract_par.clip_frac = 0.4;
225 opt_extract_par.clip_niter = 2;
226 opt_extract_par.niter = 1;
227 opt_extract_par.method = GAUSS_METHOD;
228
229 /* Reset library state */
230 xsh_init();
231
232 /* Check input */
233 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
234
235 /* Get the recipe out of the plugin */
236 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
237 CPL_ERROR_TYPE_MISMATCH,
238 "Plugin is not a recipe");
239
240 recipe = (cpl_recipe *)plugin;
241
242 /* Create the parameter list in the cpl_recipe object */
243 recipe->parameters = cpl_parameterlist_new();
244 assure( recipe->parameters != NULL,
245 CPL_ERROR_ILLEGAL_OUTPUT,
246 "Memory allocation failed!");
247
248 /* Set generic parameters (common to all recipes) */
249 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
250 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
251 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
252
253
254 /* subtract_background_params */
256
257 /* remove_crh_single */
259 crh_single )) ;
260
261 /* xsh_rectify */
263 rectify )) ;
264
265 /* xsh_localize_object */
267 loc_obj )) ;
268
269 /* xsh_remove_sky_single */
271 sky_single )) ;
272
273
275 recipe->parameters,ipol_par)) ;
276
277 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
278 "do-optextract", FALSE,
279 "TRUE if we do the optimal extraction"));
280
282 opt_extract_par));
283
284 /*
285 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
286 "do-flatfield", TRUE,
287 "TRUE if we do the flatfielding"));
288*/
289 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
290 "correct-tellurics", TRUE,
291 "TRUE if during response computation we apply telluric correction"));
292
293 cleanup:
294 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
295 xsh_error_dump(CPL_MSG_ERROR);
296 return 1;
297 }
298 else {
299 return 0;
300 }
301}
302
303/*----------------------------------------------------------------------------*/
309/*----------------------------------------------------------------------------*/
310
311static int xsh_respon_slit_stare_exec(cpl_plugin *plugin) {
312 cpl_recipe *recipe = NULL;
313
314 /* Check parameter */
315
316 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
317
318 /* Get the recipe out of the plugin */
319 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
320 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
321
322 recipe = (cpl_recipe *)plugin;
323
324 /* Check recipe */
325 xsh_respon_slit_stare(recipe->parameters, recipe->frames);
326
327 cleanup:
328 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
329 xsh_error_dump(CPL_MSG_ERROR);
331 return 1;
332 }
333 else {
334 return 0;
335 }
336}
337
338/*----------------------------------------------------------------------------*/
344/*----------------------------------------------------------------------------*/
345static int xsh_respon_slit_stare_destroy(cpl_plugin *plugin)
346{
347 cpl_recipe *recipe = NULL;
348
349 /* reset error state before detroying recipe */
351 /* Check parameter */
352 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
353
354 /* Get the recipe out of the plugin */
355 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
356 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
357
358 recipe = (cpl_recipe *)plugin;
359
360 xsh_free_parameterlist(&recipe->parameters);
361
362 cleanup:
363 if (cpl_error_get_code() != CPL_ERROR_NONE)
364 {
365 return 1;
366 }
367 else
368 {
369 return 0;
370 }
371}
372
373
374static cpl_error_code
376 xsh_rectify_param * rectify_par,
377 xsh_localize_obj_param * loc_obj_par,
378 xsh_opt_extract_param *opt_extract_par,
379 int sub_sky_nbkpts1,
380 int sub_sky_nbkpts2)
381{
382
383
384
385 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
386 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
387 rectify_par->rectif_bin_space);
388
389 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
390 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
391
392 xsh_msg_dbg_low("opt extract params: chunk_size=%d lambda_step=%g box_hsize=%d",
393 opt_extract_par->chunk_size,opt_extract_par->lambda_step,
394 opt_extract_par->box_hsize);
395
396 xsh_msg_dbg_low("sky params: nbkpts1=%d nbkpts2=%d",
397 sub_sky_nbkpts1,sub_sky_nbkpts2);
398
399 return cpl_error_get_code();
400
401}
402
403/*----------------------------------------------------------------------------*/
411/*----------------------------------------------------------------------------*/
412static cpl_error_code
413xsh_respon_slit_stare(cpl_parameterlist* parameters,
414 cpl_frameset* frameset)
415{
416 const char* recipe_tags[2] = {XSH_STD_FLUX_SLIT_STARE,XSH_STD_TELL_SLIT_STARE};
417 int recipe_tags_size = 2;
418
419 /* Input frames */
420 cpl_frameset* raws = NULL;
421 cpl_frameset* calib = NULL;
422 /* Beware, do not "free" the following input frames, they are part
423 of the input frameset */
424 cpl_frame * bpmap = NULL;
425 cpl_frame * master_bias = NULL;
426 cpl_frame * master_dark = NULL;
427 cpl_frame * master_flat = NULL;
428 cpl_frame * order_tab_edges = NULL;
429 cpl_frame * wave_tab = NULL ;
430 cpl_frame * model_config_frame = NULL ;
431 cpl_frame * wavemap_frame = NULL ;
432 cpl_frame * slitmap_frame = NULL ;
433 cpl_frame * disp_tab_frame = NULL;
434 cpl_frame * spectralformat_frame = NULL ;
435 cpl_frame * fluxcal_1D_frame = NULL ;
436 cpl_frame * fluxcal_2D_frame = NULL ;
437 cpl_frame * fluxcal_rect_1D_frame = NULL ;
438 cpl_frame * fluxcal_rect_2D_frame = NULL ;
439
440 cpl_frame* sky_list_frame=NULL;
441 cpl_frame* qc_sky_frame=NULL;
442
443 /* Parameters */
444 xsh_background_param* backg_par = NULL;
445 xsh_remove_crh_single_param * crh_single_par = NULL ;
446 cpl_frame* high_abs_win=NULL;
447 xsh_rectify_param * rectify_par = NULL ;
448 xsh_localize_obj_param * loc_obj_par = NULL ;
449 int sub_sky_nbkpts1 = SUBTRACT_SKY_SINGLE_NBKPTS ;
452 int sub_sky_nbkpts2 = SUBTRACT_SKY_SINGLE_NBKPTS ;
456 int do_sub_sky = FALSE;
457 int recipe_use_model = 0 ;
458 int do_optextract = 0;
459 int do_flatfield = 1;
460 int do_compute_map = FALSE ;
461 int generate_sdp_format = 0;
462 // int do_compute_eff = 0 ;
463 xsh_extract_param extract_par = { LOCALIZATION_METHOD};
464
465 //xsh_extract_param *extract_par = NULL ;
466 xsh_subtract_sky_single_param *sky_par = NULL;
467
469 int nb_raw_frames ;
470 char rec_name[256];
471
472 /* Intermediate frames */
473 cpl_frame * std_flux_frame = NULL ;
475 cpl_frame * rmbias = NULL;
476 cpl_frame * rmdark = NULL;
477 cpl_frame * rmbkg = NULL ;
478 cpl_frame * div_frame = NULL ;
479 cpl_frame * sub_sky_frame = NULL ;
480 cpl_frame * sub_sky2_frame = NULL ;
483 cpl_frame * rect_frame = NULL ;
484 cpl_frame * loc_table_frame = NULL ;
485 cpl_frame * clean_frame = NULL ;
486 cpl_frame * rect2_frame = NULL ;
487 cpl_frame * rect2_frame_eso = NULL ;
488 cpl_frame * rect2_frame_tab = NULL ;
489
490 cpl_frame * rect2_sky_frame = NULL ;
491 cpl_frame * rect2_sky_frame_eso = NULL ;
492 cpl_frame * rect2_sky_frame_tab = NULL ;
493
494
495 cpl_frame * rect_eff_frame_eso = NULL ;
496 cpl_frame * rect_frame_tab = NULL ;
497 cpl_frame * rect_eff_frame_tab = NULL ;
499 cpl_frame * div_clean_frame = NULL ;
500 cpl_frame * tell_frame = NULL ;
501 cpl_frame * res_1D_frame = NULL ;
503 /* Output Frames (results) */
504 cpl_frame * sky_frame = NULL ;
505 cpl_frame * sky_frame_eso = NULL ;
507 cpl_frame * response_frame = NULL ;
509 cpl_frame * response_ord_frame = NULL ;
510 cpl_frame* sky_frame_ima=NULL;
511 cpl_frame* clean_obj=NULL;
512
513 cpl_frame * ext_frame = NULL ;
514 cpl_frame * ext_frame_eso = NULL ;
515
516 cpl_frame *orderext1d_frame = NULL;
517 cpl_frame *orderoxt1d_frame = NULL;
518 cpl_frame *orderoxt1d_eso_frame = NULL;
519
520 cpl_frame *mergeoxt1d_frame = NULL;
521// cpl_frame *mergeoxt1d_frame = NULL;
522
523 /* Miscelleanious */
524 char file_name[256];
525 char file_tag[256];
526 char arm_str[8] ;
527
528 char prefix[256];
529 double exptime = 1. ;
530 cpl_frame* grid_backg=NULL;
531 cpl_frame* frame_backg=NULL;
532 cpl_frame* res_2D_frame=NULL;
533 cpl_frame* res_2D_sky_frame=NULL;
534
535 char* rec_prefix=NULL;
536 char sky_prefix[256];
537
538 cpl_frame* frm_atmext=NULL;
539 cpl_frame* frm_std_cat=NULL;
540 cpl_frame* frm_eff=NULL;
541
542
543 cpl_frame* eff_frame=NULL;
544 cpl_frame* rect_eff_frame=NULL;
545 cpl_frame* ext_eff_frame=NULL;
546 cpl_frame* ext_eff_frame2=NULL;
547 int pre_overscan_corr=0;
548 cpl_frame* single_frame_sky_sub_tab_frame=NULL;
549 xsh_opt_extract_param *opt_extract_par = NULL;
550 cpl_frame *fluxcal_rect_opt1D_frame = NULL;
551 cpl_frame *fluxcal_merg_opt1D_frame = NULL;
552 cpl_frame *qc_subex_frame = NULL;
553 cpl_frame *qc_s2ddiv1d_frame = NULL;
554 cpl_frame *qc_model_frame = NULL;
555 cpl_frame *qc_weight_frame = NULL;
556 cpl_frame* tell_mod_cat=NULL;
557 cpl_frame* rm_crh = NULL;
558 cpl_frame* frame_ord_by_ord=NULL;
559 cpl_frame* frame_merged=NULL;
560 cpl_frame* resp_fit_points_cat_frame=NULL;
561 cpl_frame* ext_sky_frame=NULL;
562 cpl_frame* res_1D_sky_frame=NULL;
563
564 char ftag[256];
565 char fname[256];
566
567 int merge_par=0;
568 xsh_interpolate_bp_param *ipol_bp=NULL;
569 int corr_tell=0;
570 cpl_frame* sky_orders_chunks =NULL;
571 cpl_propertylist* qclist = cpl_propertylist_new();
572 cpl_frame* reference_response = NULL;
573
574 /**************************************************************************/
575 /* DFS management */
576 /**************************************************************************/
577 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
578 recipe_tags, recipe_tags_size,
579 RECIPE_ID, XSH_BINARY_VERSION,
581
582
583 //get average airm and iwv from raws; add keywords to qclist
585
587 assure( instrument->mode == XSH_MODE_SLIT, CPL_ERROR_ILLEGAL_INPUT,
588 "Instrument NOT in Slit Mode" ) ;
589
591 if(instrument->arm == XSH_ARM_NIR) {
595 }
596 sprintf( arm_str, "%s", xsh_instrument_arm_tostring(instrument) ) ;
597
598
599
600 /**************************************************************************/
601 /* Recipe parameters */
602 /**************************************************************************/
603 check(xsh_slit_stare_get_params(parameters,RECIPE_ID, &pre_overscan_corr,
604 &backg_par,&loc_obj_par,
605 &rectify_par,&crh_single_par,&sub_sky_nbkpts1,
606 &do_flatfield,&sub_sky_nbkpts2,&sky_par,
607 &do_optextract,
608 &opt_extract_par,
609 &generate_sdp_format));
610 /* TODO: we should remove this internal parameter that actually confuses the code */
611 rectify_par->conserve_flux=FALSE;
612 backg_par->method=TRUE;
614
616
618 parameters));
619
620 if ( do_sub_sky == 1 && (wavemap_frame == NULL || slitmap_frame == NULL) ) {
621 xsh_msg_warning( "sky-subtract is true but wave,slits maps missing create them");
622 do_compute_map = TRUE;
623
624 }
625
626
627 /* adjust relevant parameter to binning */
629 check(xsh_stare_params_bin_scale(raws,backg_par,
630 opt_extract_par,
631 &sub_sky_nbkpts1,&sub_sky_nbkpts2));
632 }
633
634
635 check(xsh_params_monitor(backg_par,rectify_par,loc_obj_par,opt_extract_par,
636 sub_sky_nbkpts1,sub_sky_nbkpts2));
637
638 check( pre_overscan_corr = xsh_parameters_get_int( parameters, RECIPE_ID,
639 "pre-overscan-corr"));
640
641
642 check( corr_tell = xsh_parameters_get_boolean( parameters, RECIPE_ID,
643 "correct-tellurics"));
644
645
646 /**************************************************************************/
647 /* Recipe frames */
648 /**************************************************************************/
649 /* only one RAW frames: AMO in scired we allow also more than one frame */
650 check( nb_raw_frames = cpl_frameset_get_size( raws));
651 xsh_msg_dbg_low("nb_raw_frames=%d",nb_raw_frames);
652
653 XSH_ASSURE_NOT_ILLEGAL_MSG( nb_raw_frames == 1,
654 "Pls provide a STD FLUX frame in input");
655
656
657
658 /* prepare RAW frames in XSH format: NB we moved this piece of REDUCTION here
659 * because we need to have the calib frameset with input frames already with correct binning
660 * that is done by xsh_set_recipe_file_prefix (which needs frames in PRE format)
661 */
662 xsh_msg( "Calling xsh_prepare" ) ;
663 check( xsh_prepare( raws, bpmap, master_bias, XSH_STD_FLUX_SLIT_STARE,
664 instrument,pre_overscan_corr,CPL_TRUE));
665
666 check(rec_prefix = xsh_set_recipe_file_prefix(raws,
667 "xsh_respon_slit_stare"));
668 /* in case the input master flat/bias do not match in bin size with the raw data,
669 * correct the binning so that :
670 *
671 * 1x1 std 2x2 mflat,mbias --> correct bin of std
672 * 2x2 std 1x1 mflat,mbias --> correct bin of mflat,mbias
673 *
674 */
675
676
677 check(xsh_slit_stare_get_calibs(calib,instrument, &spectralformat_frame,
678 &master_bias,&master_dark,&master_flat,
679 &order_tab_edges,&model_config_frame,
680 &wave_tab,&sky_list_frame,&sky_orders_chunks,&qc_sky_frame,
681 &bpmap,&single_frame_sky_sub_tab_frame,
682 &wavemap_frame,&slitmap_frame,RECIPE_ID,
683 &recipe_use_model,pre_overscan_corr));
684 /* QC extra frames */
685 resp_fit_points_cat_frame=xsh_find_frame_with_tag(calib,XSH_RESP_FIT_POINTS_CAT,instrument);
686 if(resp_fit_points_cat_frame==NULL) {
687 xsh_msg_warning("Missing input %s_%s response will not be computed",
690 xsh_msg_warning("and data will not be flux calibrated");
691 }
692 /* response extra frames */
694 if(frm_atmext==NULL) {
695 xsh_msg_error("Provide atmospheric extinction frame");
696 return CPL_ERROR_DATA_NOT_FOUND;
697 }
698
700 if(frm_std_cat==NULL) {
701 xsh_msg_error("Provide std star catalog frame");
702 return CPL_ERROR_DATA_NOT_FOUND;
703 }
704
706
707 /* to compute efficiency */
708 if(NULL == (disp_tab_frame = xsh_find_disp_tab( calib, instrument))) {
709 xsh_msg("To compute efficiency, you must provide a DISP_TAB_ARM input");
710 }
711
712
713 /*
714 - A telluric mask (Tag = TELL_MASK_arm Type = LIN)\n\
715 - A standard star fluxes table (Tag = STD_STAR_FLUX_arm Type = FLX)\n\
716 - A master response (Tag = RESPONSE_mode_arm Type = RES)\n\
717 - An atmospheric extinction table (Tag = Type = ATM)\n\
718 */
719
720
721
722 /* parameters dependent input */
723 if ( do_compute_map && recipe_use_model == FALSE){
724 check( disp_tab_frame = xsh_find_disp_tab( calib, instrument));
725 }
726
727 reference_response=xsh_find_frame_with_tag(calib,"RRESPONSE_MERGE1D_SLIT",instrument);
728
729 /**************************************************************************/
730 /* Recipe code */
731 /**************************************************************************/
732
733
734
735 xsh_msg( "Calling xsh_find_std_flux" ) ;
736 check_msg( std_flux_frame = xsh_find_std_flux( raws ),
737 "Pls provide a STD FLUX telluric" ) ;
738 /* Get Exptime */
739 {
740 xsh_pre * xpre = NULL ;
741 check( xpre = xsh_pre_load( std_flux_frame, instrument ) ) ;
742 exptime = xpre->exptime ;
743 xsh_msg_dbg_medium( "EXPTIME: %lf", exptime ) ;
744
745 xsh_pre_free( &xpre ) ;
746 }
747
749 do_compute_map,recipe_use_model,rec_prefix,
750 instrument,model_config_frame,std_flux_frame,
751 disp_tab_frame,order_tab_edges,
752 &wavemap_frame, &slitmap_frame));
753 sprintf(prefix,"%s",rec_prefix);
754 /* Subtract bias if necessary */
755 check( rmbias = xsh_check_subtract_bias( std_flux_frame, master_bias,
756 instrument, "STD_FLUX_",pre_overscan_corr,1));
757
758
759 /* Subtract Dark if necessary */
760 check( rmdark = xsh_check_subtract_dark( rmbias, master_dark,
761 instrument, "STD_FLUX_STARE_DARK"));
762
763
764
765 sprintf(ftag,"%s_STD_NO_CRH_%s",rec_prefix,xsh_instrument_arm_tostring(instrument));
766 sprintf(fname,"%s.fits",ftag) ;
767 rm_crh = xsh_remove_crh_single(rmdark,instrument,NULL,crh_single_par,ftag) ;
769
770 //xsh_add_temporary_file(cpl_frame_get_filename( rmbias));
771 /* subtract inter-order background */
772 xsh_msg("Subtract inter-order background");
773 check( rmbkg = xsh_subtract_background( rm_crh,
774 order_tab_edges,
775 backg_par,instrument,rec_prefix,
776 &grid_backg,&frame_backg,0,0,0));
777
778 /* In case CRH single or localize auto do preliminar sky subtraction */
779 /* CHECK LEAKS: next call creates small leack */
780 cpl_frame* sky_map_frm = xsh_find_frame_with_tag(calib,XSH_SKY_MAP, instrument);
781 check(xsh_slit_stare_correct_crh_and_sky(loc_obj_par,crh_single_par,
782 rectify_par,
783 do_sub_sky,rec_prefix,rmbkg,
784 order_tab_edges, slitmap_frame,
785 wavemap_frame,sky_map_frm,model_config_frame,
786 single_frame_sky_sub_tab_frame,
787 instrument,sub_sky_nbkpts1, sky_par,
788 sky_list_frame,
789 sky_orders_chunks,
790 &sky_frame,&sky_frame_eso,
791 &sky_frame_ima,
792 wave_tab,disp_tab_frame,
793 spectralformat_frame,nb_raw_frames,
794 &loc_table_frame,&clean_frame,
795 &clean_obj,1
796));
797
798 xsh_free_frame(&rmbkg);
799 /* now we divide by the flat for proper sky subtraction */
800 cpl_frameset* extra=cpl_frameset_new();
801 cpl_frameset_insert(extra,cpl_frame_duplicate(clean_obj));
803 clean_obj=cpl_frameset_get_frame(extra,0);
804 check( div_frame = xsh_check_divide_flat( do_flatfield, clean_obj,
805 master_flat, instrument, prefix));
806 cpl_frameset_delete(extra);
807 xsh_add_temporary_file(cpl_frame_get_filename(div_frame));
808 xsh_free_frame(&sky_frame);
809 xsh_free_frame(&sky_frame_eso);
810 xsh_free_frame(&sky_frame_ima);
811 check( sub_sky2_frame = xsh_check_subtract_sky_single( do_sub_sky,
812 div_frame,
813 order_tab_edges,
814 slitmap_frame,
815 wavemap_frame,
816 loc_table_frame,
817 single_frame_sky_sub_tab_frame,
819 sub_sky_nbkpts2,
820 sky_par,
821 sky_list_frame,
822 sky_orders_chunks,
823 &sky_frame,
824 &sky_frame_eso,
825 &sky_frame_ima,
826 rec_prefix,
827 1));
828
829 if(slitmap_frame) {
830 xsh_add_temporary_file(cpl_frame_get_filename(slitmap_frame));
831 }
832
833 if(wavemap_frame) {
834 xsh_add_temporary_file(cpl_frame_get_filename(wavemap_frame));
835 }
836
837 xsh_add_temporary_file(cpl_frame_get_filename(sub_sky2_frame));
838
839
840 if(do_sub_sky) {
841 xsh_add_temporary_file(cpl_frame_get_filename(sky_frame_ima));
842 }
843
844
845 check( div_clean_frame = cpl_frame_duplicate( sub_sky2_frame ) ) ;
846
847 xsh_msg( "Prepare S2D products" ) ;
848 xsh_msg( "Rectify") ;
849 sprintf(rec_name,"%s_%s_%s.fits",rec_prefix,XSH_ORDER2D,
851
852 check( rect2_frame = xsh_rectify( sub_sky2_frame, order_tab_edges,
853 wave_tab, model_config_frame, instrument,
854 rectify_par,spectralformat_frame,
855 disp_tab_frame,rec_name,
856 &rect2_frame_eso,&rect2_frame_tab,rec_prefix));
857
858 if(sky_frame_ima) {
859 /* rectify sky frame for QC */
860 sprintf(sky_prefix,xsh_set_recipe_sky_file_prefix(rec_prefix));
861 sprintf(rec_name,"%s_%s_%s.fits",sky_prefix,XSH_ORDER2D,
863
864 check( rect2_sky_frame = xsh_rectify( sky_frame_ima, order_tab_edges,
865 wave_tab, model_config_frame, instrument,
866 rectify_par,spectralformat_frame,
867 disp_tab_frame,rec_name,
868 &rect2_sky_frame_eso,&rect2_sky_frame_tab,
869 sky_prefix));
870 xsh_add_temporary_file(cpl_frame_get_filename(rect2_sky_frame_eso));
871 xsh_msg("rec2=%p loc=%p rec2_eso=%p",rect2_sky_frame,loc_table_frame,rect2_sky_frame_eso);
872 /* the following frame is recreated by next function: we need to deallocate
873 * it first */
874 xsh_free_frame(&rect2_sky_frame_eso);
875 check(ext_sky_frame = xsh_extract_clean(rect2_sky_frame, loc_table_frame,
876 instrument, &extract_par,ipol_bp,
877 &rect2_sky_frame_eso,rec_prefix )) ;
878
879 check( res_1D_sky_frame = xsh_merge_ord( ext_sky_frame, instrument,
880 merge_par,sky_prefix));
881 xsh_free_frame(&ext_sky_frame);
882 }
883 xsh_msg( "Extract" ) ;
884 check(ext_frame=xsh_extract_clean(rect2_frame, loc_table_frame,
885 instrument, &extract_par,ipol_bp,&ext_frame_eso,
886 rec_prefix)) ;
887
888 xsh_msg( "Merge orders with 1D frame" ) ;
889 check( res_1D_frame = xsh_merge_ord( ext_frame, instrument,
890 merge_par,rec_prefix));
892
893
894 xsh_msg( "Calling xsh_merge_ord with 2D frame" ) ;
895 check( res_2D_frame = xsh_merge_ord( rect2_frame, instrument,
896 merge_par,rec_prefix));
897 if(rect2_sky_frame) {
898 check( res_2D_sky_frame = xsh_merge_ord( rect2_sky_frame, instrument,
899 merge_par,sky_prefix));
900 }
901 xsh_msg("Prepare S1D products" ) ;
902 /* doing optimal extraction */
903
904 if ( do_optextract){
905 xsh_msg( "Optimal extraction");
906 check( xsh_opt_extract( sub_sky2_frame, order_tab_edges,
907 wave_tab, model_config_frame, wavemap_frame,
908 slitmap_frame, loc_table_frame,
909 spectralformat_frame, master_flat, instrument,
910 opt_extract_par, rec_prefix,
911 &orderext1d_frame, &orderoxt1d_frame,
912 &orderoxt1d_eso_frame,
913 &qc_subex_frame,
914 &qc_s2ddiv1d_frame,
915 &qc_model_frame,
916 &qc_weight_frame));
917/*
918 check( mergeext1d_frame = xsh_merge_ord( orderext1d_frame, instrument,
919 merge_par,rec_prefix));
920*/
921 check( mergeoxt1d_frame = xsh_merge_ord( orderoxt1d_frame, instrument,
922 merge_par,rec_prefix));
923 }
924
925
926 /* Telluric correction */
927 xsh_msg( "Calling xsh_mark_tell (TBW)" ) ;
928 //check( tell_frame = xsh_mark_tell(ext_frame, tell_mask, tell_params )) ;
929 check( tell_frame = cpl_frame_duplicate( ext_frame ) ) ;
930
931 /* Response computation */
932 if(frm_std_cat!=NULL && frm_atmext!=NULL &&
933 resp_fit_points_cat_frame != NULL) {
934 xsh_msg( "Calling xsh_compute_response" ) ;
935
936
937 if ( do_optextract){
938 frame_ord_by_ord=orderoxt1d_eso_frame;
939 frame_merged= mergeoxt1d_frame;
940 } else {
941 frame_ord_by_ord=ext_frame_eso;
942 frame_merged=res_1D_frame;
943 }
944 if( (response_ord_frame = xsh_compute_response_ord(frame_ord_by_ord,
945 frm_std_cat,
946 frm_atmext,
947 high_abs_win,
949 exptime )) == NULL) {
950 xsh_msg_warning("Some error occurred computing response frame. Recover from it.");
952 cpl_error_reset();
953 }
954
955 if( (response_frame = xsh_compute_response2(frame_merged,
956 frm_std_cat,
957 frm_atmext,
958 high_abs_win,
959 resp_fit_points_cat_frame,
960 tell_mod_cat,
962 exptime,corr_tell )) == NULL) {
963 xsh_msg_warning("Some error occurred computing response frame. Recover from it.");
965 cpl_error_reset();
966 } else {
967
968 check(xsh_frame_table_monitor_flux_qc(response_frame,"LAMBDA",
969 "RESPONSE","RESP",instrument));
970 }
971 }
972
973 if( response_frame != NULL) {
974
975 check(xsh_flux_calibrate(rect2_frame_eso,ext_frame_eso,frm_atmext,
976 response_frame,merge_par,instrument,rec_prefix,
977 &fluxcal_rect_2D_frame,&fluxcal_rect_1D_frame,
978 &fluxcal_2D_frame,&fluxcal_1D_frame));
979
980 if(reference_response != NULL){
981 //if an optional ref response has been added to the sof, try to load the table...
982 //TODO: Set error handling here to be robust (no errors introduced by this routine)
983 cpl_table* ref_resp = cpl_table_load(cpl_frame_get_filename(reference_response),1,0);
984 cpl_table* master_resp = cpl_table_load(cpl_frame_get_filename(response_frame),1,0);
985 if(ref_resp != NULL && master_resp != NULL){
986 if(instrument->arm == XSH_ARM_UVB) {
987 calc_resp_qc(master_resp,ref_resp,instrument,4741,13408,"QTH",qclist);
988 calc_resp_qc(master_resp,ref_resp,instrument,408,4074,"D2",qclist);
989 } else {
990 calc_resp_qc(master_resp,ref_resp,instrument,0,0,NULL,qclist);
991 }
992 }
993 cpl_error_reset();
994 }
995
996 if ( do_optextract){
997
998 check(xsh_flux_calibrate1D(orderoxt1d_eso_frame,frm_atmext,
999 response_frame,merge_par,instrument,rec_prefix,
1000 &fluxcal_rect_opt1D_frame,
1001 &fluxcal_merg_opt1D_frame));
1002
1003 }
1004 }
1005
1006 /* efficiency part */
1007 if(response_ord_frame != NULL && disp_tab_frame != NULL) {
1008 int conserve_flux=rectify_par->conserve_flux;
1009 xsh_msg( "Calling xsh_multiply_flat" ) ;
1010 sprintf(file_tag,"SLIT_STARE_NOCRH_NOT_FF_%s",arm_str) ;
1011 if(do_flatfield) {
1012 check( eff_frame = xsh_multiply_flat( div_clean_frame, master_flat,
1013 file_tag, instrument ) ) ;
1014 } else {
1015 check(eff_frame=cpl_frame_duplicate(div_clean_frame));
1016 }
1017 sprintf(file_name,"%s_EFF_%s_%s.fits",rec_prefix,XSH_ORDER2D,
1019 rectify_par->conserve_flux=1;
1020 xsh_add_temporary_file(file_name);
1021 check( rect_eff_frame = xsh_rectify( eff_frame,
1022 order_tab_edges,
1023 wave_tab,
1024 model_config_frame,
1025 instrument,
1026 rectify_par,
1027 spectralformat_frame,
1028 disp_tab_frame,
1029 file_name,
1030 &rect_eff_frame_eso,
1031 &rect_eff_frame_tab,
1032 rec_prefix));
1033 xsh_msg( "Calling xsh_extract" ) ;
1034 check( ext_eff_frame = xsh_extract_clean(rect_eff_frame,loc_table_frame,
1035 instrument,&extract_par, ipol_bp,
1036 &ext_eff_frame2,rec_prefix)) ;
1037 xsh_msg("name %s",cpl_frame_get_filename(ext_eff_frame2));
1038
1039 frm_eff=xsh_compute_efficiency(ext_eff_frame2,frm_std_cat,
1040 frm_atmext,high_abs_win,instrument);
1041 rectify_par->conserve_flux=conserve_flux;
1042
1043 }
1044
1045 if(model_config_frame!=NULL && wavemap_frame != NULL&& slitmap_frame != NULL) {
1046
1047 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,res_2D_frame,instrument));
1048 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,rect2_frame_eso,instrument));
1049
1050 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,res_1D_frame,instrument));
1051 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,ext_frame_eso,instrument));
1052
1053 xsh_add_afc_info(model_config_frame,wavemap_frame);
1054 xsh_add_afc_info(model_config_frame,slitmap_frame);
1055
1056 if(fluxcal_rect_2D_frame != NULL) {
1057
1058 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,fluxcal_rect_2D_frame,instrument));
1059 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,fluxcal_2D_frame,instrument));
1060
1061 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,fluxcal_rect_1D_frame,instrument));
1062 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,fluxcal_1D_frame,instrument));
1063
1064 }
1065
1066 if(res_2D_sky_frame) {
1067 check(xsh_compute_resampling_accuracy(wavemap_frame,slitmap_frame,order_tab_edges,model_config_frame,res_2D_sky_frame,instrument));
1068 }
1069
1070 if ( do_sub_sky == 1 ) {
1071 check(xsh_compute_wavelength_resampling_accuracy(wavemap_frame,order_tab_edges,model_config_frame,sky_frame_eso,instrument));
1072 }
1073 }
1074
1075
1076
1077 xsh_msg( "Save products.");
1078 if(response_ord_frame!=NULL) {
1079 check( xsh_add_product_table(response_ord_frame,frameset,parameters,
1080 RECIPE_ID,instrument,NULL));
1081 }
1082
1083 if(response_frame!=NULL) {
1084 check( xsh_add_product_table(response_frame,frameset,parameters,
1085 RECIPE_ID,instrument,NULL));
1086 }
1087
1088 check( xsh_add_product_image(rect2_frame_eso, frameset, parameters,
1089 RECIPE_ID, instrument,NULL));
1090
1091 check( xsh_add_product_orders_spectrum(ext_frame_eso, frameset, parameters,
1092 RECIPE_ID, instrument,NULL));
1093
1094 /* Calculate curvature QC params early */
1095 cpl_image* itmp = cpl_image_load(cpl_frame_get_filename(res_2D_frame),CPL_TYPE_DOUBLE,0,0);
1096 calc_curve_qc(itmp,instrument,qclist);
1097 cpl_image_delete(itmp);
1098
1099 check( xsh_add_product_spectrum(res_2D_frame, frameset, parameters,
1100 RECIPE_ID, instrument, NULL,qclist));
1101
1102 check(get_chromatic_eff(frm_eff,qclist));
1103 check(xsh_monitor_spectrum1D_extra_qc(res_1D_frame,instrument,qclist));
1104 check( xsh_add_product_spectrum(res_1D_frame, frameset, parameters,
1105 RECIPE_ID, instrument, NULL,qclist));
1106
1107 if(res_2D_sky_frame) {
1108 check( xsh_add_product_spectrum( res_2D_sky_frame, frameset, parameters,
1109 RECIPE_ID, instrument, NULL,NULL));
1110 check( xsh_add_product_spectrum( res_1D_sky_frame, frameset, parameters,
1111 RECIPE_ID, instrument, NULL,NULL));
1112 }
1113 if(fluxcal_2D_frame != NULL) {
1114
1115
1116 check( xsh_add_product_image( fluxcal_rect_2D_frame, frameset, parameters,
1117 RECIPE_ID, instrument,NULL));
1118
1119 check( xsh_add_product_orders_spectrum( fluxcal_rect_1D_frame, frameset, parameters,
1120 RECIPE_ID, instrument,NULL));
1121
1122 check( xsh_add_product_spectrum( fluxcal_2D_frame, frameset, parameters,
1123 RECIPE_ID, instrument, NULL,qclist));
1124
1125 check( xsh_add_product_spectrum( fluxcal_1D_frame, frameset, parameters,
1126 RECIPE_ID, instrument, NULL,qclist));
1127
1128 if ( do_optextract){
1129
1130 check( xsh_add_product_orders_spectrum( fluxcal_rect_opt1D_frame, frameset,
1131 parameters, RECIPE_ID, instrument,NULL));
1132
1133 check( xsh_add_product_spectrum( fluxcal_merg_opt1D_frame, frameset,
1134 parameters, RECIPE_ID, instrument, NULL,qclist));
1135 check( xsh_add_product_image( qc_subex_frame, frameset, parameters,
1137 cpl_frame_get_tag(qc_subex_frame)));
1138 check( xsh_add_product_image( qc_s2ddiv1d_frame, frameset, parameters,
1140 cpl_frame_get_tag(qc_s2ddiv1d_frame)));
1141 check( xsh_add_product_image( qc_model_frame, frameset, parameters,
1143 cpl_frame_get_tag(qc_model_frame)));
1144 check( xsh_add_product_image( qc_weight_frame, frameset, parameters,
1146 cpl_frame_get_tag(qc_weight_frame)));
1147
1148 }
1149
1150 }
1151
1152 if(frm_eff!=NULL) {
1153 check(xsh_add_product_table(frm_eff, frameset,parameters,
1154 RECIPE_ID, instrument,NULL));
1155 }
1156
1157cleanup:
1158
1159 xsh_end( RECIPE_ID, frameset, parameters );
1160 XSH_FREE(rec_prefix);
1161 XSH_FREE(ipol_bp);
1162 XSH_FREE( backg_par ) ;
1163 XSH_FREE( crh_single_par ) ;
1164 XSH_FREE( rectify_par ) ;
1165 XSH_FREE( loc_obj_par ) ;
1166 XSH_FREE( sky_par ) ;
1167 XSH_FREE( opt_extract_par ) ;
1169
1170 xsh_free_frameset( &raws);
1171 xsh_free_frameset( &calib);
1172 xsh_free_frame( &rmbias);
1173 xsh_free_frame( &rmdark);
1174 xsh_free_frame( &rmbkg);
1175
1176 xsh_free_frame( &rm_crh);
1177 xsh_free_frame( &bpmap);
1178 xsh_free_frame( &div_frame);
1179 xsh_free_frame( &wavemap_frame);
1180 xsh_free_frame( &slitmap_frame);
1181 xsh_free_frame( &sky_frame);
1182 xsh_free_frame( &sky_frame_eso);
1183 xsh_free_frame( &sky_frame_ima);
1184
1185 xsh_free_frame( &sub_sky_frame);
1186 xsh_free_frame( &sub_sky2_frame);
1187 xsh_free_frame( &rect_frame_tab) ;
1188 xsh_free_frame( &rect_frame) ;
1189
1190 xsh_free_frame(&rect2_frame) ;
1191 xsh_free_frame(&rect2_frame_eso) ;
1192 xsh_free_frame(&rect2_frame_tab) ;
1193
1194 xsh_free_frame(&rect2_sky_frame) ;
1195 xsh_free_frame(&rect2_sky_frame_eso) ;
1196 xsh_free_frame(&rect2_sky_frame_tab) ;
1197
1198
1199 xsh_free_frame( &loc_table_frame) ;
1200 xsh_free_frame( &response_frame) ;
1201 xsh_free_frame( &response_ord_frame) ;
1202
1203 xsh_free_frame(& eff_frame);
1204 xsh_free_frame(& rect_eff_frame);
1205 xsh_free_frame(& rect_eff_frame_eso);
1206 xsh_free_frame(& rect_eff_frame_tab);
1207 xsh_free_frame(& ext_eff_frame);
1208 xsh_free_frame(& ext_eff_frame2);
1209 xsh_free_frame(&fluxcal_rect_1D_frame) ;
1210 xsh_free_frame(&fluxcal_rect_2D_frame) ;
1211 xsh_free_frame(&fluxcal_1D_frame) ;
1212 xsh_free_frame(&fluxcal_2D_frame) ;
1213
1214 xsh_free_frame( &ext_frame ) ;
1215 xsh_free_frame( &frm_eff ) ;
1216 xsh_free_frame( &ext_frame_eso ) ;
1217 xsh_free_frame( &clean_frame) ;
1218 xsh_free_frame( &div_clean_frame) ;
1219 //xsh_free_frame( &clean_obj) ;
1220 xsh_free_frame( &res_1D_frame) ;
1221 xsh_free_frame( &res_2D_frame) ;
1222 xsh_free_frame(&res_2D_sky_frame) ;
1223 xsh_free_frame(&res_1D_sky_frame) ;
1224
1225 xsh_free_frame( &tell_frame ) ;
1226 xsh_free_frame( &grid_backg ) ;
1227 xsh_free_frame( &frame_backg ) ;
1228 xsh_free_frame( &qc_subex_frame);
1229 xsh_free_frame(&qc_s2ddiv1d_frame);
1230 xsh_free_frame(&qc_model_frame);
1231 xsh_free_frame(&qc_weight_frame);
1232
1233 /*
1234 xsh_free_frame( &spectralformat_frame ) ;
1235 */
1236 return CPL_ERROR_NONE;
1237}
1238
static double exptime
static xsh_instrument * instrument
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
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
#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg)
Definition: xsh_error.h:111
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
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_dbg_medium(...)
Definition: xsh_msg.h:44
#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
cpl_frame * xsh_multiply_flat(cpl_frame *frame, cpl_frame *flat, const char *filename, xsh_instrument *instr)
multiply PRE frame with the master FLAT frame
Definition: xsh_multiply.c:77
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
cpl_frame * xsh_remove_crh_single(cpl_frame *sci_frame, xsh_instrument *instrument, cpl_mask *sky_map, xsh_remove_crh_single_param *single_par, const char *name)
Remove cosmic rays from a single frame.
static cpl_error_code xsh_respon_slit_stare(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
#define RECIPE_CONTACT
static char xsh_respon_slit_stare_description_short[]
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_respon_slit_stare_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_respon_slit_stare_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static cpl_error_code xsh_params_monitor(xsh_background_param *backg, xsh_rectify_param *rectify_par, xsh_localize_obj_param *loc_obj_par, xsh_opt_extract_param *opt_extract_par, int sub_sky_nbkpts1, int sub_sky_nbkpts2)
static int xsh_respon_slit_stare_create(cpl_plugin *)
Setup the recipe options.
static char xsh_respon_slit_stare_description[]
#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
cpl_error_code get_chromatic_eff(cpl_frame *eff, cpl_propertylist *qclist)
Definition: xsh_utils.c:7306
void xsh_init(void)
Reset library state.
Definition: xsh_utils.c:1160
cpl_error_code xsh_frame_table_monitor_flux_qc(cpl_frame *frm, const char *colw, const char *colf, const char *prefix, xsh_instrument *instrument)
Computes statistics on spectrum for QC.
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
cpl_error_code calc_resp_qc(cpl_table *mtab, cpl_table *rtab, xsh_instrument *instrument, int lower, int upper, const char *label, cpl_propertylist *qclist)
Definition: xsh_utils.c:7504
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
float exptime
Definition: xsh_data_pre.h:92
cpl_frame * xsh_compute_response_ord(cpl_frame *spectrum_frame, cpl_frame *flux_std_star_cat_frame, cpl_frame *atmos_ext_frame, cpl_frame *high_abs_win_frame, xsh_instrument *instrument, double exptime)
cpl_frame * xsh_compute_response2(cpl_frame *obs_std_star, cpl_frame *flux_std_star_cat, cpl_frame *atmos_ext, cpl_frame *high_abs, cpl_frame *resp_fit_points, cpl_frame *tell_mod_cat, xsh_instrument *instrument, double exptime, const int tell_corr)
@ XSH_ARM_UVB
@ XSH_ARM_NIR
@ XSH_MODE_SLIT
cpl_error_code xsh_calib_nir_respon_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr)
Definition: xsh_dfs.c:4974
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_error_code xsh_calib_nir_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr, const char *recid)
Definition: xsh_dfs.c:5014
cpl_error_code xsh_frameset_uniform_bin(cpl_frameset **raws, cpl_frameset **calib, xsh_instrument *instrument)
Definition: xsh_dfs.c:4664
int xsh_print_rec_status(const int val)
Check if an error has happened and returns error kind and location.
Definition: xsh_dfs.c:877
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
cpl_frame * xsh_find_std_flux(cpl_frameset *frames)
Find standard star frame.
Definition: xsh_dfs.c:3262
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
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
#define XSH_TELL_MOD_CAT
Definition: xsh_dfs.h:181
#define XSH_ORDER2D
Definition: xsh_dfs.h:588
#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_FLUX_STD_CAT
Definition: xsh_dfs.h:272
#define XSH_STD_FLUX_SLIT_STARE
Definition: xsh_dfs.h:449
#define XSH_RESP_FIT_POINTS_CAT
Definition: xsh_dfs.h:126
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)
int xsh_parameters_get_boolean(const cpl_parameterlist *list, const char *recipe_id, const char *name)
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
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)
void xsh_parameters_remove_crh_single_create(const char *recipe_id, cpl_parameterlist *plist, xsh_remove_crh_single_param p)
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_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
@ LOC_MANUAL_METHOD
@ LOCALIZATION_METHOD
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
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_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_frame * xsh_compute_efficiency(cpl_frame *mer1D, cpl_frame *std_cat, cpl_frame *atm_ext, cpl_frame *high_abs_win, xsh_instrument *instr)
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)