X-shooter Pipeline Reference Manual 3.8.15
xsh_respon_slit_offset.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free 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:50:11 $
23 * $Revision: 1.105 $
24 *
25*/
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*----------------------------------------------------------------------------*/
39/*----------------------------------------------------------------------------*/
42/*-----------------------------------------------------------------------------
43 Includes
44 ----------------------------------------------------------------------------*/
45
46/* DRL steps */
47
48/* Error handling */
49#include <xsh_error.h>
50/* Utility fonctions */
51#include <xsh_utils.h>
52#include <xsh_utils_table.h>
54#include <xsh_msg.h>
55/* DFS functions */
56#include <xsh_dfs.h>
57#include <xsh_drl_check.h>
58#include <xsh_pfits.h>
59#include <xsh_data_spectrum1D.h>
61
62/* DRL functions */
63#include <xsh_drl.h>
64/* Library */
65#include <cpl.h>
66
67/*-----------------------------------------------------------------------------
68 Defines
69 ---------------------------------------------------------------------------*/
70
71#define RECIPE_ID "xsh_respon_slit_offset"
72#define RECIPE_AUTHOR "D. Bramich, A.Modigliani"
73#define RECIPE_CONTACT "amodigli@eso.org"
74
75/*-----------------------------------------------------------------------------
76 Functions prototypes
77 ----------------------------------------------------------------------------*/
78
79/*
80 * Plugin initalization, execute and cleanup handlers
81 */
82
83static int xsh_respon_slit_offset_create( cpl_plugin *);
84static int xsh_respon_slit_offset_exec( cpl_plugin *);
85static int xsh_respon_slit_offset_destroy( cpl_plugin *);
86
87/* The actual executor function */
88static cpl_error_code xsh_respon_slit_offset( cpl_parameterlist *, cpl_frameset *);
89
90/*-----------------------------------------------------------------------------
91 Static variables
92 ----------------------------------------------------------------------------*/
94"Compute the response function in SLIT and on/off mode";
95
97"This recipe reduces science exposure in SLIT configuration and on/off mode\n\
98Input Frames : \n\
99 - A set of n Science frames ( n even ), \
100 Tag = STD_FLUX_SLIT_OFFSET_arm, SKY_SLIT_arm\n\
101 - Spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
102 - A master flat frame (Tag = MASTER_FLAT_SLIT_arm)\n\
103 - An order table frame(Tag = ORDER_TABLE_EDGES_SLIT_arm)\n\
104 - A wavelength calibration solution frame(Tag = WAVE_TAB_2D_arm)\n\
105 - [OPTIONAL] Table with dispersion coefficients (Tag = DISP_TAB_arm)\n\
106 - [OPTIONAL] A telluric model catalog (Tag = TELL_MOD_CAT_arm arm=VIS,NIR)\n\
107 - A standard star fluxes catalog (Tag = FLUX_STD_CATALOG_arm Type = FLX)\n\
108 - A table to set response sampling points (Tag = RESP_FIT_POINTS_CAT_arm)\n\
109 - An atmospheric extinction table (Tag = ATMOS_EXT_arm)\n\
110 if provided this is the one used to flux calibrate the spectra\n\
111Products : \n\
112Products : \n\
113 - [If STD is in catal] The response ord-by-ord function (Tag = RESPONSE_ORDER1D_SLIT_arm)\n\
114 - [If STD is in catal] The response merged function (Tag = RESPONSE_MERGE1D_SLIT_arm)\n\
115 - PREFIX_ORDER2D_arm extracted spectrum, order-by-order, 2D\n\
116 - PREFIX_ORDER1D_arm extracted spectrum, order-by-order, 1D\n\
117 - PREFIX_MERGE2D_arm merged spectrum, 2D\n\
118 - PREFIX_MERGE1D_arm merged spectrum, 1D\n\
119 - [If STD is in catal] Flux calibrated order-by-order 2D spectrum (Tag = PREFIX_FLUX_ORDER2D_arm)\n\
120 - [If STD is in catal] Flux calibrated order-by-order 1D spectrum (Tag = PREFIX_FLUX_ORDER1D_arm)\n\
121 - [If STD is in catal] Flux calibrated merged 2D spectrum (Tag = PREFIX_FLUX_MERGE2D_arm)\n\
122 - [If STD is in catal] Flux calibrated merged 1D spectrum (Tag = PREFIX_FLUX_MERGE1D_arm)\n\
123 - PREFIX_SKY_arm, 2D sky frame\n\
124 - SKY_SLIT_ORDER2D_arm, 2D sky image (order-by-order)\n\
125 - SKY_SLIT_MERGE2D_arm, 2D sky image (merged)\n\
126 - [If STD is in catal] The efficiency (Tag = EFFICIENCY_arm)\n\
127 - PREFIX_WAVE_MAP_arm, wave map image\n\
128 - PREFIX_SLIT_MAP_arm, slit map image\n\
129 - where PREFIX is SCI, FLUX, TELL if input raw DPR.TYPE contains OBJECT or FLUX or TELLURIC";
130
131/*-----------------------------------------------------------------------------
132 Functions code
133 ----------------------------------------------------------------------------*/
134/*----------------------------------------------------------------------------*/
143/*----------------------------------------------------------------------------*/
144
145int cpl_plugin_get_info(cpl_pluginlist *list) {
146 cpl_recipe *recipe = NULL;
147 cpl_plugin *plugin = NULL;
148
149 recipe = cpl_calloc(1, sizeof(*recipe));
150 if ( recipe == NULL ){
151 return -1;
152 }
153
154 plugin = &recipe->interface ;
155
156 cpl_plugin_init(plugin,
157 CPL_PLUGIN_API, /* Plugin API */
158 XSH_BINARY_VERSION, /* Plugin version */
159 CPL_PLUGIN_TYPE_RECIPE, /* Plugin type */
160 RECIPE_ID, /* Plugin name */
162 xsh_respon_slit_offset_description, /* Detailed help */
163 RECIPE_AUTHOR, /* Author name */
164 RECIPE_CONTACT, /* Contact address */
165 xsh_get_license(), /* Copyright */
169
170 cpl_pluginlist_append(list, plugin);
171
172 return (cpl_error_get_code() != CPL_ERROR_NONE);
173}
174
175/*----------------------------------------------------------------------------*/
185/*----------------------------------------------------------------------------*/
186
187static int xsh_respon_slit_offset_create(cpl_plugin *plugin){
188 cpl_recipe *recipe = NULL;
189
190 /* First param (conv_kernel) should be initialized correctly ! */
191 xsh_remove_crh_single_param crh_single = { 0.1, 20, 2.0, 4} ;
192 xsh_rectify_param rectify = { "tanh",
193 CPL_KERNEL_DEFAULT,
194 2,
195 -1.0,
196 -1.0,
197 1,0,0.};
198 /* 2nd and 3rd params should be initialized correctly */
199 xsh_localize_obj_param loc_obj =
200 {10, 0.1, 0, 0, LOC_MANUAL_METHOD, 0, 2.0,3,3,FALSE};
201 //xsh_extract_param extract_par = { LOCALIZATION_METHOD};
202 xsh_interpolate_bp_param ipol_par = { 30};
203 xsh_combine_nod_param nod_param = { 5, TRUE, 5, 2, 0.1, "throwlist.asc",TRUE } ;
204
205 /* Reset library state */
206 xsh_init();
207
208 /* Check input */
209 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
210 /* Get the recipe out of the plugin */
211 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
212 CPL_ERROR_TYPE_MISMATCH,
213 "Plugin is not a recipe");
214
215 recipe = (cpl_recipe *)plugin;
216
217 /* Create the parameter list in the cpl_recipe object */
218 recipe->parameters = cpl_parameterlist_new();
219 assure( recipe->parameters != NULL,
220 CPL_ERROR_ILLEGAL_OUTPUT,
221 "Memory allocation failed!");
222
223 /* Set generic parameters (common to all recipes) */
224 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
225 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
226 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
227
228 /* remove_crh_single */
230 crh_single )) ;
231 /* xsh_rectify */
233 rectify )) ;
234 /* xsh_localize_object */
236 loc_obj )) ;
237 /* xsh_optimal_extract
238 check(xsh_parameters_optimal_extract_create(RECIPE_ID,
239 recipe->parameters,-1. )) ;
240 */
241 /* trivial extract (Just temporary)
242 check(xsh_parameters_extract_create(RECIPE_ID,
243 recipe->parameters,
244 extract_par,LOCALIZATION_METHOD )) ;
245 */
247 recipe->parameters,ipol_par)) ;
248
250 recipe->parameters,
251 nod_param )) ;
252 /*
253 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
254 "do-flatfield", TRUE,
255 "TRUE if we do the flatfielding"));
256*/
257
258 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
259 "gen-sky", TRUE,
260 "if TRUE a 2D sky frame, a 2D rectified, a 2D merged sky are generated"));
261
262 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
263 "correct-tellurics", TRUE,
264 "TRUE if during response computation we apply telluric correction"));
265
266
267 cleanup:
268 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
269 xsh_error_dump(CPL_MSG_ERROR);
270 return 1;
271 }
272 else {
273 return 0;
274 }
275}
276
277/*----------------------------------------------------------------------------*/
283/*----------------------------------------------------------------------------*/
284
285static int xsh_respon_slit_offset_exec(cpl_plugin *plugin) {
286 cpl_recipe *recipe = NULL;
287
288 /* Check parameter */
289
290 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
291
292 /* Get the recipe out of the plugin */
293 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
294 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
295
296 recipe = (cpl_recipe *)plugin;
297
298 /* Check recipe */
299 xsh_respon_slit_offset(recipe->parameters, recipe->frames);
300
301 cleanup:
302 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
303 xsh_error_dump(CPL_MSG_ERROR);
305 return 1;
306 }
307 else {
308 return 0;
309 }
310}
311
312/*----------------------------------------------------------------------------*/
318/*----------------------------------------------------------------------------*/
319static int xsh_respon_slit_offset_destroy(cpl_plugin *plugin)
320{
321 cpl_recipe *recipe = NULL;
322
323 /* reset error state before detroying recipe */
325 /* Check parameter */
326 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
327
328 /* Get the recipe out of the plugin */
329 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
330 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
331
332 recipe = (cpl_recipe *)plugin;
333
334 xsh_free_parameterlist(&recipe->parameters);
335
336 cleanup:
337 if (cpl_error_get_code() != CPL_ERROR_NONE)
338 {
339 return 1;
340 }
341 else
342 {
343 return 0;
344 }
345}
346
347
348static cpl_error_code
350 xsh_localize_obj_param * loc_obj_par)
351{
352
353 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
354 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
355 rectify_par->rectif_bin_space);
356
357 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
358 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
359
360 return cpl_error_get_code();
361
362}
363
364
365/*----------------------------------------------------------------------------*/
373/*----------------------------------------------------------------------------*/
374static cpl_error_code
375 xsh_respon_slit_offset( cpl_parameterlist* parameters,
376 cpl_frameset* frameset)
377{
378 const char* recipe_tags[2] = {XSH_STD_FLUX_SLIT_OFFSET, XSH_SKY_SLIT};
379 int recipe_tags_size = 2;
380
381 /* Input frames */
382 cpl_frameset* raws = NULL;
383
384 cpl_frameset * raw_object = NULL;
385 cpl_frameset * raw_sky = NULL;
386 cpl_frameset * calib = NULL;
387 int nb_sub_frames = 0;
388 /* Beware, do not "free" the following input frames, they are part
389 of the input frameset */
390 cpl_frame* bpmap = NULL;
391 cpl_frame* master_bias = NULL;
392 cpl_frame* master_dark = NULL;
393 cpl_frame* master_flat = NULL;
394 cpl_frame* order_tab_edges = NULL;
395 cpl_frame * wave_tab = NULL ;
396 cpl_frame * model_config_frame = NULL ;
397 cpl_frame * slitmap = NULL ;
398 cpl_frame *disp_tab_frame = NULL;
399 cpl_frame * spectral_format = NULL ;
400
401 /* Parameters */
402 xsh_remove_crh_single_param * crh_single_par = NULL ;
403 xsh_rectify_param * rectify_par = NULL ;
404 xsh_localize_obj_param * loc_obj_par = NULL ;
405
406 xsh_extract_param * extract_par = NULL ;
407 xsh_combine_nod_param * combine_nod_param = NULL ;
408
410
411 /* Intermediate frames */
412
413 cpl_frame * loc_table_frame = NULL ;
414 cpl_frame * clean_frame = NULL ;
415 cpl_frameset * sub_frameset = NULL ;
416 cpl_frameset * clean_frameset = NULL ;
417 cpl_frameset * rect_frameset = NULL ;
418 cpl_frameset * rect2_frameset_tables = NULL ;
420 /* Output Frames (results)*/
421 cpl_frame * res_1D_frame = NULL ;
422 cpl_frame * res_2D_frame = NULL ;
423 cpl_frame * ext_frame = NULL ;
424 cpl_frame * ext_frame_eso = NULL ;
425 cpl_frame * comb_frame = NULL ;
426 cpl_frame * comb_frame_eso = NULL ;
427
428 char file_name[256];
429 char arm_str[16] ;
430 char file_tag[40];
431
432 int i ;
433
434 int do_flatfield=1;
435 int gen_sky=0;
436 int generate_sdp_format=0;
437 char * prefix=NULL;
438 char rec_prefix[256];
439 char sky_prefix[256];
440 char sky_tag[256];
441 cpl_frame* avg_sky=NULL;
442 cpl_frame* rec_sky=NULL;
443 cpl_frame* rec_sky_eso=NULL;
444 cpl_frame* mer_sky=NULL;
445 cpl_frame * rectif_tab = NULL ;
446 cpl_frame * sky_divided = NULL ;
447 cpl_frameset* sky_bias=NULL;
448 cpl_frameset* sky_dark=NULL;
449 cpl_frame * wavemap = NULL ;
450
451
452 cpl_frame* std_flux_frame=NULL;
453 double exptime=1.;
454 cpl_frame* response_frame=NULL;
455 cpl_frame* response_ord_frame=NULL;
456
457 //int do_compute_eff = 0 ;
458 cpl_frame* frm_atmext=NULL;
459 cpl_frame* frm_std_cat=NULL;
460 cpl_frame* eff_frame=NULL;
461 cpl_frame* rect_eff_frame=NULL;
462 cpl_frame* ext_eff_frame=NULL;
463 cpl_frame* ext_eff_frame2=NULL;
464 cpl_frame* frm_eff=NULL;
465
466 cpl_frame * rect_eff_frame_eso = NULL ;
467 cpl_frame * rect_eff_frame_tab = NULL ;
468 cpl_frame * div_clean_frame = NULL ;
469 cpl_frame * fluxcal_rect_1D_frame = NULL ;
470 cpl_frame * fluxcal_rect_2D_frame = NULL ;
471 cpl_frame * fluxcal_1D_frame = NULL ;
472 cpl_frame * fluxcal_2D_frame = NULL ;
473 cpl_frame * nrm_1D_frame = NULL ;
474 cpl_frame * nrm_2D_frame = NULL ;
475 cpl_frame* high_abs_win=NULL;
476 int pre_overscan_corr=0;
477 int merge_par=0;
478 xsh_interpolate_bp_param *ipol_bp=NULL;
479 cpl_frame* tell_mod_cat=NULL;
480 cpl_frameset* crh_clean_obj = NULL;
481 cpl_frameset* crh_clean_sky = NULL;
482 cpl_frame* resp_fit_points_cat_frame=NULL;
483 cpl_frame* ext_sky_frame=NULL;
484 cpl_frame* ext_sky_frame_eso=NULL;
485 cpl_frame* res_1D_sky_frame=NULL;
486 cpl_frame* sky_map_frm =NULL;
487 int do_computemap=1;
488 int use_model=0;
489 int corr_tell=0;
490 int scale_nod=0;
491 cpl_propertylist* qclist = cpl_propertylist_new();
492 cpl_frame* reference_response = NULL;
493
494
495
496 /**************************************************************************/
497 /* DFS management */
498 /**************************************************************************/
499 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
500 recipe_tags, recipe_tags_size,
501 RECIPE_ID, XSH_BINARY_VERSION,
503
504 //get average airm and iwv from raws; add keywords to qclist
506
508 assure( instrument->mode == XSH_MODE_SLIT, CPL_ERROR_ILLEGAL_INPUT,
509 "Instrument NOT in Slit Mode" ) ;
510
512 if(instrument->arm == XSH_ARM_NIR) {
516 }
517
518 /* prepare RAW frames in XSH format: NB we moved this piece of REDUCTION here
519 * because we need to have the calib frameset with input frames already with correct binning
520 * that is done by xsh_set_recipe_file_prefix (which needs frames in PRE format)
521 */
522 /* But we also need to have pre-overscan-corr properly set */
523 check( pre_overscan_corr = xsh_parameters_get_int( parameters, RECIPE_ID,
524 "pre-overscan-corr"));
525
526
527
528
529 /* prepare RAW frames in PRE format */
530 check(xsh_prepare(raws, bpmap, master_bias, XSH_STD_FLUX_SLIT_OFFSET,
531 instrument,pre_overscan_corr,CPL_TRUE));
532
533 /* in case the input master flat/bias do not match in bin size with the raw data,
534 * correct the binning so that :
535 *
536 * 1x1 std 2x2 mflat,mbias --> correct bin of std
537 * 2x2 std 1x1 mflat,mbias --> correct bin of mflat,mbias
538 *
539 */
540 //check(xsh_frameset_uniform_bin(&raws, &calib,instrument));
541
542
543 /**************************************************************************/
544 /* Recipe frames */
545 /**************************************************************************/
546 /*
547 check(xsh_slit_offset_get_calibs(calib,instrument,&bpmap,&master_bias,
548 &master_dark,&order_tab_edges,
549 &model_config_frame,&wave_tab,&master_flat,
550 &wavemap,&slitmap,&spectral_format,RECIPE_ID));
551*/
552 {
553
554
555 xsh_get_normal_calibs(calib, instrument, RECIPE_ID, pre_overscan_corr,
556 &spectral_format, &master_bias, &bpmap, &order_tab_edges,
557 &master_flat);
558
559 /* TODO: Is mdark input really needed? */
560 if((master_dark=xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,
561 instrument))==NULL){
563 }
564
565 //The following need to be defined
566 int do_computemap=1;
567 xsh_get_dispersion_calibs(calib, instrument, do_computemap,
568 &model_config_frame,&wave_tab, &wavemap);
569 //The following is also present in xsh_get_dispersion_calibs
570 check( wavemap = xsh_find_wavemap( calib, instrument));
571 //The following should be removed to xsh_get_dispersion_calibs
572 check( slitmap = xsh_find_slitmap( calib, instrument));
573
574
575
576 }
577
578 /* QC extra frames */
579 resp_fit_points_cat_frame=xsh_find_frame_with_tag(calib,
581 if(resp_fit_points_cat_frame==NULL) {
582 xsh_msg_warning("Missing input %s_%s response will not be computed",
585 xsh_msg_warning("and data will not be flux calibrated");
586 }
587 /* response specific frames */
589 if(frm_atmext==NULL) {
590 xsh_msg_error("Provide atmospheric extinction frame");
591 return CPL_ERROR_DATA_NOT_FOUND;
592 }
593
595 if(frm_std_cat==NULL) {
596 xsh_msg_error("Provide std star catalog frame");
597 return CPL_ERROR_DATA_NOT_FOUND;
598 }
600
601 /* to compute efficiency */
602 if(NULL == (disp_tab_frame = xsh_find_disp_tab( calib, instrument))) {
603 xsh_msg("To compute efficiency, you must give a DISP_TAB_ARM input");
604 }
605
606
607
608 /**************************************************************************/
609 /* Recipe parameters */
610 /**************************************************************************/
612 &loc_obj_par,&rectify_par,&crh_single_par,
613 &extract_par,
614 &combine_nod_param,&do_flatfield,&gen_sky,
615 &generate_sdp_format));
616 /*
617 check( do_computemap = xsh_parameters_get_boolean( parameters, RECIPE_ID,
618 "compute-map"));
619 */
622 rectify_par->conserve_flux=FALSE;
623 check(xsh_params_monitor(rectify_par,loc_obj_par));
624 check( corr_tell = xsh_parameters_get_boolean( parameters,RECIPE_ID,
625 "correct-tellurics"));
626 reference_response=xsh_find_frame_with_tag(calib,"RRESPONSE_MERGE1D_SLIT",instrument);
627
628
629 /**************************************************************************/
630 /* Recipe code */
631 /**************************************************************************/
632
633 /* make sure each input raw frame has the same exp time */
635
636 /* TODO: No dark subrtracted: this is ok only is off frame and on frame have same exposure time */
637 /* Separate OBJECT and SKY frames */
639 XSH_SKY_SLIT, &raw_object,
640 &raw_sky ) ) ;
641
642 prefix=xsh_set_recipe_file_prefix(raw_object,"xsh_respon_slit_offset");
643 check(strcpy(rec_prefix,prefix));
644 XSH_FREE(prefix);
645
646 xsh_msg("cmap=%d wavemap=%p slitmap=%p",do_computemap,wavemap,slitmap);
647 if( (do_computemap == 1) && (wavemap ==NULL || slitmap ==NULL ) ) {
648 if (model_config_frame != NULL) {
649 use_model=1;
650 }
651 check( xsh_check_get_map( disp_tab_frame, order_tab_edges,
652 master_flat, model_config_frame, calib, instrument,
653 do_computemap, use_model, rec_prefix,
654 &wavemap, &slitmap));
655 }
656
657
658 /* remove crh on each obj or sky frame */
659 xsh_msg("rec_prefix=%s",rec_prefix);
660 sky_map_frm = xsh_find_frame_with_tag(calib,XSH_SKY_MAP, instrument);
661 crh_clean_obj = xsh_frameset_crh_single(raw_object, crh_single_par,
662 sky_map_frm,instrument, rec_prefix,"OBJ");
663 crh_clean_sky = xsh_frameset_crh_single(raw_sky, crh_single_par,
664 sky_map_frm, instrument,rec_prefix,"SKY");
665
666
667 check(
668 sub_frameset = xsh_subtract_sky_offset( crh_clean_obj, crh_clean_sky, nb_sub_frames,instrument));
669 xsh_free_frameset(&crh_clean_obj);
670 xsh_free_frameset(&crh_clean_sky);
671
673 "Nb of Subtracted Frames: %" CPL_SIZE_FORMAT "", cpl_frameset_get_size( sub_frameset ));
674
675 sprintf(arm_str, "%s", xsh_instrument_arm_tostring(instrument));
676
677
678 if(gen_sky) {
679 sprintf(sky_prefix,xsh_set_recipe_sky_file_prefix(rec_prefix));
680 }
681 if(nb_sub_frames==0) {
682 xsh_msg_error("nb_sub_frames=%d something wrong check your input raws",
683 nb_sub_frames);
684 goto cleanup;
685
686 }
687
688
689
690 xsh_msg_dbg_low( "Nb of Subtracted Frames: %" CPL_SIZE_FORMAT "",
691 cpl_frameset_get_size( sub_frameset ) ) ;
692
693 //check( clean_frameset = cpl_frameset_new() ) ;
694
695 sprintf( arm_str, "%s", xsh_instrument_arm_tostring(instrument) ) ;
696
697 if(gen_sky) {
698 /* Not yet working.. */
699 if(master_bias!= NULL && pre_overscan_corr ==0 ) {
700 check(sky_bias=xsh_pre_frameset_subtract_frame(raw_sky,master_bias,"MBIAS",instrument));
701 } else {
702 sky_bias=cpl_frameset_duplicate(raw_sky);
703 }
704
705 if(master_dark!= NULL) {
706 check(sky_dark=xsh_pre_frameset_subtract_frame(sky_bias,master_dark,"MDARK",instrument));
707 } else {
708 sky_dark=cpl_frameset_duplicate(sky_bias);
709 }
710
711 sprintf(sky_tag,"%s%s%s",rec_prefix,"_SKY_",arm_str);
712 check(xsh_frameset_uniform_bin(&sky_dark, &calib,instrument));
713 check(avg_sky=xsh_frameset_average_pre(sky_dark,instrument,sky_tag));
714 if(do_flatfield==1) {
715 sprintf(sky_tag,"%s%s%s",rec_prefix,"_FF_SKY_",arm_str);
716 sprintf(file_name,"%s.fits",sky_tag);
717
718 check( sky_divided = xsh_divide_flat( avg_sky,master_flat, sky_tag,
719 instrument ) ) ;
720 xsh_add_temporary_file(file_name);
721
722 } else {
723 sky_divided=cpl_frame_duplicate(avg_sky);
724 }
725 }
726
727
728
729 /* Get Exptime */
730 {
731 xsh_pre * xpre = NULL ;
732 std_flux_frame= cpl_frameset_get_frame( sub_frameset, 0 ) ;
733 check( xpre = xsh_pre_load( std_flux_frame, instrument ) ) ;
734 exptime = xpre->exptime ;
735 xsh_msg_dbg_medium( "EXPTIME: %lf", exptime ) ;
736
737 xsh_pre_free( &xpre ) ;
738 }
739 check(xsh_frameset_uniform_bin(&sub_frameset, &calib,instrument));
740 if (do_flatfield == 1) {
741 clean_frameset=xsh_frameset_mflat_divide(sub_frameset,master_flat,instrument);
742 } else {
743 clean_frameset = cpl_frameset_duplicate(sub_frameset);
744 }
745 /* as we copied results on clean_frameset we do not need the following
746 * frameset anymore
747 * */
748 xsh_free_frameset(&sub_frameset);
749
750 check(div_clean_frame = cpl_frameset_get_frame(clean_frameset,0));
751 /* Now rectify each clean frame */
752 check( rect_frameset = cpl_frameset_new() ) ;
753 for( i = 0 ; i < nb_sub_frames ; i++ ) {
754 cpl_frame * rectif = NULL ;
755 cpl_frame * rectif_eso = NULL ;
756 cpl_frame * clean = NULL ;
757 char str[16] ;
758
759 sprintf( str, "%d", i ) ;
760 check( clean = cpl_frameset_get_frame( clean_frameset, i ) ) ;
761 xsh_msg( "Rectifying Frame '%s'", cpl_frame_get_filename( clean ) ) ;
762 sprintf(file_name,"RECTIFIED_SLIT_OFFSET_%s_%s.fits",arm_str,str) ;
763 check( rectif = xsh_rectify( clean, order_tab_edges, wave_tab,
764 model_config_frame, instrument,
765 rectify_par, spectral_format,
766 disp_tab_frame,
767 file_name,&rectif_eso,&rectif_tab,
768 rec_prefix) ) ;
769 xsh_add_temporary_file(file_name);
770
771 check( cpl_frameset_insert( rect_frameset, cpl_frame_duplicate(rectif) ) ) ;
772 check( cpl_frameset_insert( rect_frameset, cpl_frame_duplicate(rectif_eso) ) ) ;
773 xsh_free_frame(&rectif);
774 xsh_free_frame(&rectif_tab);
775 xsh_free_frame(&rectif_eso);
776 }
777
778
779
780
781 /* Combine rectified Frames */
782 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_ORDER2D, arm_str) ;
783 check(rect2_frameset_tables=xsh_frameset_ext_table_frames(rect_frameset));
784
785 check( comb_frame = xsh_combine_nod(rect2_frameset_tables, combine_nod_param,
786 file_tag,instrument,&comb_frame_eso,scale_nod));
787 xsh_free_frameset(&rect2_frameset_tables);
788
789 if ( extract_par->method == LOCALIZATION_METHOD ||
790 extract_par->method == CLEAN_METHOD ) {
791 xsh_msg( "Localize before extraction" ) ;
792 sprintf(file_name,"LOCALIZE_%s_ALL.fits",arm_str) ;
793 check( loc_table_frame = xsh_localize_obj( comb_frame, NULL,instrument,
794 loc_obj_par, NULL,
795 file_name) ) ;
796 xsh_add_temporary_file(file_name);
797 }
798
799 if(gen_sky) {
800 xsh_msg("rectify sky frame");
801 sprintf(file_name,"%s_RECTIFIED_SKY_%s.fits",sky_prefix,arm_str) ;
802 check( rec_sky = xsh_rectify(sky_divided, order_tab_edges, wave_tab,
803 model_config_frame, instrument,
804 rectify_par, spectral_format,
805 disp_tab_frame,
806 file_name,&rec_sky_eso,&rectif_tab,
807 sky_prefix) ) ;
808 xsh_free_frame(&rectif_tab);
809 xsh_add_temporary_file(file_name);
810
811 xsh_msg("Merge 2D sky frame");
812 check( mer_sky = xsh_merge_ord( rec_sky, instrument,
813 merge_par,sky_prefix));
814
815 check(ext_sky_frame = xsh_extract_clean(rec_sky, loc_table_frame,
816 instrument, extract_par,ipol_bp,
817 &ext_sky_frame_eso,rec_prefix )) ;
818
819 check( res_1D_sky_frame = xsh_merge_ord( ext_sky_frame, instrument,
820 merge_par,sky_prefix));
821
822
823 }
824
825 xsh_msg( "Calling xsh_extract" ) ;
826
827 check(ext_frame = xsh_extract_clean(comb_frame, loc_table_frame,
828 instrument, extract_par,ipol_bp,&ext_frame_eso,
829 rec_prefix )) ;
830
831 xsh_msg( "Calling xsh_merge_ord with 1D frame" ) ;
832 check( res_1D_frame = xsh_merge_ord( ext_frame, instrument,
833 merge_par,rec_prefix));
834 /* More todo here
835 mark_telluric
836 calibrate_flux
837 */
838
839 xsh_msg( "Calling xsh_merge_ord with 2D frame" ) ;
840 check( res_2D_frame = xsh_merge_ord( comb_frame, instrument, merge_par,
841 rec_prefix) ) ;
842
843
844 /* Response computation */
845 if(frm_std_cat!=NULL && frm_atmext!=NULL &&
846 resp_fit_points_cat_frame != NULL) {
847 xsh_msg( "Calling xsh_compute_response" ) ;
848 if( (response_ord_frame = xsh_compute_response_ord( ext_frame_eso,
849 frm_std_cat,
850 frm_atmext,
851 high_abs_win,
853 exptime )) == NULL) {
854 xsh_msg_warning("Some error occurred during response computation");
856 cpl_error_reset();
857 }
858
859 if( ( response_frame = xsh_compute_response2( res_1D_frame,
860 frm_std_cat,
861 frm_atmext,
862 high_abs_win,
863 resp_fit_points_cat_frame,
864 tell_mod_cat,
866 exptime,
867 corr_tell )) == NULL) {
868 xsh_msg_warning("Some error occurred during response computation");
870 cpl_error_reset();
871 } else {
872
873 check(xsh_frame_table_monitor_flux_qc(response_frame,"LAMBDA",
874 "RESPONSE","RESP",instrument));
875 }
876
877 }
878
879
880 if( response_frame != NULL) {
881
882 check(xsh_flux_calibrate(comb_frame_eso,ext_frame_eso,frm_atmext,
883 response_frame,merge_par,instrument,rec_prefix,
884 &fluxcal_rect_2D_frame,&fluxcal_rect_1D_frame,
885 &fluxcal_2D_frame,&fluxcal_1D_frame));
886 if(reference_response != NULL){
887 //if an optional ref response has been added to the sof, try to load the table...
888 //TODO: Set error handling here to be robust (no errors introduced by this routine)
889 cpl_table* ref_resp = cpl_table_load(cpl_frame_get_filename(reference_response),1,0);
890 cpl_table* master_resp = cpl_table_load(cpl_frame_get_filename(response_frame),1,0);
891 if(ref_resp != NULL && master_resp != NULL){
892 if(instrument->arm == XSH_ARM_UVB) {
893 calc_resp_qc(master_resp,ref_resp,instrument,4741,13408,"QTH",qclist);
894 calc_resp_qc(master_resp,ref_resp,instrument,408,4074,"D2",qclist);
895 } else {
896 calc_resp_qc(master_resp,ref_resp,instrument,0,0,NULL,qclist);
897 }
898 }
899 cpl_error_reset();
900 }
901
902 }
903
904 /* efficiency part */
905 if(response_ord_frame != NULL && disp_tab_frame != NULL) {
906 int conserve_flux=rectify_par->conserve_flux;
907 xsh_msg( "Calling xsh_multiply_flat" ) ;
908
909 sprintf(file_tag,"SLIT_STARE_NOCRH_NOT_FF_%s",arm_str) ;
910 if(do_flatfield) {
911 check( eff_frame = xsh_multiply_flat( div_clean_frame, master_flat,
912 file_tag, instrument ) ) ;
913 } else {
914 check(eff_frame=cpl_frame_duplicate(div_clean_frame));
915 }
916 sprintf(file_name,"%s_EFF_%s_%s.fits",rec_prefix,XSH_ORDER2D,
918 xsh_add_temporary_file(file_name);
919
920 /* force flux conservation for efficiency computation */
921 rectify_par->conserve_flux=1;
922 check( rect_eff_frame = xsh_rectify( eff_frame,
923 order_tab_edges,
924 wave_tab,
925 model_config_frame,
927 rectify_par,
928 spectral_format,
929 disp_tab_frame,
930 file_name,
931 &rect_eff_frame_eso,
932 &rect_eff_frame_tab,
933 rec_prefix));
934
935 /*
936 xsh_msg( "Calling xsh_localize_obj" ) ;
937 check( loc_table_frame = xsh_localize_obj( rect_frame, instrument,
938 loc_obj_par, NULL,NULL));
939 */
940
941 xsh_msg( "Calling xsh_extract" ) ;
942 check( ext_eff_frame = xsh_extract_clean(rect_eff_frame,loc_table_frame,
943 instrument,extract_par, ipol_bp,
944 &ext_eff_frame2,rec_prefix)) ;
945
946
947 frm_eff=xsh_compute_efficiency(ext_eff_frame2,frm_std_cat,
948 frm_atmext,high_abs_win,instrument);
949 /* reset value to original default */
950 rectify_par->conserve_flux=conserve_flux;
951
952 }
953
954
955 if(model_config_frame!=NULL && wavemap != NULL&& slitmap != NULL) {
956
957 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,comb_frame_eso,instrument));
958 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,res_2D_frame,instrument));
959
960 check(xsh_compute_wavelength_resampling_accuracy(wavemap,order_tab_edges,model_config_frame,res_1D_frame,instrument));
961 check(xsh_compute_wavelength_resampling_accuracy(wavemap,order_tab_edges,model_config_frame,ext_frame_eso,instrument));
962
963 xsh_add_afc_info(model_config_frame,wavemap);
964 xsh_add_afc_info(model_config_frame,slitmap);
965
966 if(fluxcal_rect_2D_frame != NULL) {
967
968 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,fluxcal_rect_2D_frame,instrument));
969 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,fluxcal_2D_frame,instrument));
970
971 check(xsh_compute_wavelength_resampling_accuracy(wavemap,order_tab_edges,model_config_frame,fluxcal_rect_1D_frame,instrument));
972 check(xsh_compute_wavelength_resampling_accuracy(wavemap,order_tab_edges,model_config_frame,fluxcal_1D_frame,instrument));
973
974 }
975
976 if(gen_sky) {
977 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,rec_sky_eso,instrument));
978 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,mer_sky,instrument));
979 }
980
981 }
982
983 /* Save products */
984 xsh_msg( "Saving products") ;
985 if(response_ord_frame!=NULL) {
986 check( xsh_add_product_table(response_ord_frame, frameset, parameters,
987 RECIPE_ID, instrument,NULL));
988 }
989 if(response_frame!=NULL) {
990 check( xsh_add_product_table( response_frame, frameset, parameters,
991 RECIPE_ID, instrument,NULL));
992 }
993
994
995 /* Removed as format not easy to read
996 check( xsh_add_product_table( comb_frame, frameset,
997 parameters, RECIPE_ID, instrument));
998 *
999 */
1000
1001 check( xsh_add_product_image( comb_frame_eso, frameset,
1002 parameters, RECIPE_ID, instrument,NULL));
1003
1004 /* Removed as format not easy to read
1005 check( xsh_add_product_table( ext_frame, frameset,
1006 parameters, RECIPE_ID, instrument));
1007 */
1008
1009 check( xsh_add_product_orders_spectrum( ext_frame_eso, frameset,
1010 parameters, RECIPE_ID, instrument,NULL));
1011
1012 /* Calculate curvature QC params early */
1013 cpl_image* itmp = cpl_image_load(cpl_frame_get_filename(res_2D_frame),CPL_TYPE_DOUBLE,0,0);
1014 calc_curve_qc(itmp,instrument,qclist);
1015 cpl_image_delete(itmp);
1016
1017 check( xsh_add_product_spectrum( res_2D_frame, frameset, parameters,
1018 RECIPE_ID, instrument, NULL,qclist));
1019
1021
1022 check(get_chromatic_eff(frm_eff,qclist));
1023 check(xsh_monitor_spectrum1D_extra_qc(res_1D_frame,instrument,qclist));
1024 check( xsh_add_product_spectrum( res_1D_frame, frameset, parameters,
1025 RECIPE_ID, instrument, NULL,qclist));
1026
1027
1028 if(fluxcal_2D_frame != NULL) {
1029 check( xsh_add_product_image(fluxcal_rect_2D_frame,frameset,parameters,
1030 RECIPE_ID, instrument,NULL));
1031 check( xsh_add_product_orders_spectrum(fluxcal_rect_1D_frame,frameset,parameters,
1032 RECIPE_ID, instrument,NULL));
1033 check( xsh_add_product_spectrum( fluxcal_2D_frame, frameset, parameters,
1034 RECIPE_ID, instrument, NULL,qclist));
1035 check( xsh_add_product_spectrum( fluxcal_1D_frame, frameset, parameters,
1036 RECIPE_ID, instrument, NULL,qclist));
1037 }
1038
1039 if(gen_sky) {
1040 check( xsh_add_product_image( avg_sky, frameset, parameters,
1041 RECIPE_ID, instrument,NULL));
1042
1043 check( xsh_add_product_image( rec_sky_eso, frameset, parameters,
1044 RECIPE_ID, instrument,NULL));
1045
1046 check( xsh_add_product_image( mer_sky, frameset, parameters,
1047 RECIPE_ID, instrument,NULL));
1048
1049 check( xsh_add_product_spectrum( res_1D_sky_frame, frameset, parameters,
1050 RECIPE_ID, instrument, NULL,NULL));
1051 }
1052
1053 if(frm_eff!=NULL) {
1054 check(xsh_add_product_table(frm_eff, frameset,parameters,
1055 RECIPE_ID, instrument,NULL));
1056 }
1057
1058
1059 if (do_computemap){
1060 //sprintf(prefix,"%s_WAVE_MAP",rec_prefix);
1061
1062
1063 check(xsh_add_product_image( wavemap, frameset,
1064 parameters, RECIPE_ID, instrument, NULL));
1065
1066 //check(sprintf(prefix,"%s_SLIT_MAP",rec_prefix));
1067
1068 check(xsh_add_product_image( slitmap, frameset,
1069 parameters, RECIPE_ID, instrument,NULL));
1070 }
1071
1072 cleanup:
1073
1074 xsh_end( RECIPE_ID, frameset, parameters );
1075 XSH_FREE( crh_single_par ) ;
1076 XSH_FREE( rectify_par ) ;
1077 XSH_FREE( loc_obj_par ) ;
1078 XSH_FREE(extract_par);
1079
1080
1081 XSH_FREE(combine_nod_param);
1082 XSH_FREE(ipol_bp);
1083
1085 xsh_free_frameset(&rect2_frameset_tables);
1086 xsh_free_frameset(&raws);
1087
1088 /* the following two frees are dangerous in case of failure (e.g. nsky=0) */
1089 xsh_free_frameset( &raw_object);
1090 xsh_free_frameset( &raw_sky);
1091
1092 xsh_free_frameset(&calib);
1093 xsh_free_frameset(&clean_frameset);
1094
1095 xsh_free_frameset(&sky_bias);
1096 xsh_free_frameset(&sky_dark);
1097 xsh_free_frameset(&rect_frameset);
1098
1099 xsh_free_frame(&loc_table_frame) ;
1100 xsh_free_frame(&clean_frame) ;
1101 xsh_free_frame(&res_1D_frame) ;
1102 xsh_free_frame(&res_2D_frame) ;
1103 xsh_free_frame(&fluxcal_rect_1D_frame) ;
1104 xsh_free_frame(&fluxcal_rect_2D_frame) ;
1105 xsh_free_frame(&fluxcal_1D_frame) ;
1106 xsh_free_frame(&fluxcal_2D_frame) ;
1107 xsh_free_frame(&nrm_1D_frame) ;
1108 xsh_free_frame(&nrm_2D_frame) ;
1109
1110 xsh_free_frame( &comb_frame ) ;
1111 xsh_free_frame( &comb_frame_eso ) ;
1112 xsh_free_frame( &ext_frame ) ;
1113 xsh_free_frame( &ext_frame_eso ) ;
1114 xsh_free_frame( &eff_frame ) ;
1115 xsh_free_frame( &ext_sky_frame ) ;
1116 xsh_free_frame( &ext_sky_frame_eso ) ;
1117 xsh_free_frame( &res_1D_sky_frame ) ;
1118 xsh_free_frame( &rect_eff_frame ) ;
1119 xsh_free_frame( &rect_eff_frame_eso ) ;
1120 xsh_free_frame( &rect_eff_frame_tab ) ;
1121 xsh_free_frame( &bpmap );
1122 xsh_free_frame( &avg_sky ) ;
1123 xsh_free_frame( &wavemap ) ;
1124 xsh_free_frame( &slitmap ) ;
1125 xsh_free_frame( &avg_sky ) ;
1126 xsh_free_frame( &sky_divided ) ;
1127 xsh_free_frame( &rec_sky ) ;
1128 xsh_free_frame( &rec_sky_eso ) ;
1129 xsh_free_frame( &mer_sky ) ;
1130 xsh_free_frame( &ext_eff_frame ) ;
1131 xsh_free_frame( &ext_eff_frame2 ) ;
1132 xsh_free_frame( &rec_sky ) ;
1133 xsh_free_frame( &rec_sky_eso ) ;
1134 xsh_free_frame( &mer_sky ) ;
1135 xsh_free_frame( &frm_eff ) ;
1136 xsh_free_frame( &response_frame ) ;
1137 xsh_free_frame( &response_ord_frame ) ;
1138 return CPL_ERROR_NONE;
1139}
1140
static double exptime
static xsh_instrument * instrument
cpl_frame * xsh_combine_nod(cpl_frameset *nod_frames, xsh_combine_nod_param *nod_par, const char *tag, xsh_instrument *instrument, cpl_frame **res_frame_ext, const int scale_nod)
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_frameset_average_pre(cpl_frameset *set, xsh_instrument *instr, const char *tag)
Average set of frames in PRE format.
cpl_frameset * xsh_pre_frameset_subtract_frame(cpl_frameset *set, cpl_frame *sub, const char *spec, xsh_instrument *instr)
Subtract 2 frames (in XSH_PRE format) Just loads the 2 frames, subtract (xsh_pre_subtract) and save r...
cpl_frame * xsh_divide_flat(cpl_frame *frame, cpl_frame *flat, const char *tag, xsh_instrument *instr)
divide PRE frame with the master FLAT frame
Definition: xsh_divide.c:75
void xsh_prepare(cpl_frameset *frames, cpl_frame *bpmap, cpl_frame *mbias, const char *prefix, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
This function transform RAW frames dataset in PRE frames dataset attaching the default bad pixel map ...
Definition: xsh_prepare.c:122
#define assure(CONDITION, ERROR_CODE,...)
Definition: xsh_error.h:54
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define xsh_error_reset()
Definition: xsh_error.h:87
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.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
cpl_frame * xsh_localize_obj(cpl_frame *sci_frame, cpl_frame *skymask_frame, xsh_instrument *instrument, xsh_localize_obj_param *loc_obj_par, xsh_slit_limit_param *slit_limit_param, const char *fname)
Build the localization table.
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
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_params_monitor(xsh_rectify_param *rectify_par, xsh_localize_obj_param *loc_obj_par)
static char xsh_respon_slit_offset_description_short[]
static char xsh_respon_slit_offset_description[]
#define RECIPE_CONTACT
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_respon_slit_offset_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_respon_slit_offset_create(cpl_plugin *)
Setup the recipe options.
#define RECIPE_ID
#define RECIPE_AUTHOR
static cpl_error_code xsh_respon_slit_offset(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
static int xsh_respon_slit_offset_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
cpl_frameset * xsh_subtract_sky_offset(cpl_frameset *object_raws, cpl_frameset *sky_raws, int nraws, xsh_instrument *instrument)
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
Definition: xsh_utils.c:2224
const char * xsh_set_recipe_sky_file_prefix(char *rec_prefix)
Set recipe sky frames prefix.
Definition: xsh_utils.c:576
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 extract_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_frame * xsh_find_wavemap(cpl_frameset *frames, xsh_instrument *instr)
Find Wave Map frame. The frame returned should not be free by the caller.
Definition: xsh_dfs.c:3983
int xsh_dfs_split_offset(cpl_frameset *input, const char *object_tag, const char *sky_tag, cpl_frameset **object, cpl_frameset **sky)
split input RAW offset sof in OBJECT_... and SKY_... framesets
Definition: xsh_dfs.c:1357
cpl_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
cpl_frameset * xsh_frameset_ext_table_frames(cpl_frameset *set)
Extract frameset sub set containing only table frames.
Definition: xsh_dfs.c:207
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_slitmap(cpl_frameset *frames, xsh_instrument *instr)
Find a slit map.
Definition: xsh_dfs.c:3673
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_error_code xsh_ensure_raws_input_offset_recipe_is_proper(cpl_frameset **raws, xsh_instrument *instrument)
Make sure input frames is an even number (eventually removes the last from the input list)
Definition: xsh_dfs.c:352
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
Definition: xsh_dfs.c:3347
cpl_error_code xsh_frameset_check_uniform_exptime(cpl_frameset *raws, xsh_instrument *inst)
Definition: xsh_dfs.c:5119
#define XSH_TELL_MOD_CAT
Definition: xsh_dfs.h:181
#define XSH_MASTER_DARK
Definition: xsh_dfs.h:550
#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_ATMOS_EXT
Definition: xsh_dfs.h:1191
#define XSH_FLUX_STD_CAT
Definition: xsh_dfs.h:272
#define XSH_STD_FLUX_SLIT_OFFSET
Definition: xsh_dfs.h:493
#define XSH_RESP_FIT_POINTS_CAT
Definition: xsh_dfs.h:126
void xsh_check_get_map(cpl_frame *disp_tab_frame, cpl_frame *order_tab_edges, cpl_frame *crhm_frame, cpl_frame *model_config_frame, cpl_frameset *calib, xsh_instrument *instrument, int do_computemap, int recipe_use_model, const char *rec_prefix, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame)
Check function to get wave and slit maps.
void xsh_parameters_pre_overscan(const char *recipe_id, cpl_parameterlist *plist)
void xsh_parameters_new_boolean(cpl_parameterlist *list, const char *recipe_id, const char *name, int value, const char *comment)
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_combine_nod_create(const char *recipe_id, cpl_parameterlist *list, xsh_combine_nod_param p)
create the crh clipping parameters in a parameters list
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_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)
@ LOC_MANUAL_METHOD
@ LOCALIZATION_METHOD
@ CLEAN_METHOD
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
cpl_error_code xsh_slit_offset_get_params(cpl_parameterlist *parameters, const char *rec_id, xsh_localize_obj_param **loc_obj_par, xsh_rectify_param **rectify_par, xsh_remove_crh_single_param **crh_single_par, xsh_extract_param **extract_par, xsh_combine_nod_param **combine_nod_param, int *do_flatfield, int *gen_sky, int *generate_sdp_format)
cpl_error_code xsh_get_dispersion_calibs(cpl_frameset *calib, xsh_instrument *instrument, const int do_computemap, cpl_frame **model_config_frame, cpl_frame **wave_tab, cpl_frame **wavemap)
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_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_get_normal_calibs(cpl_frameset *calib, xsh_instrument *instrument, const char *recipe_id, int pscan, cpl_frame **spectral_format, cpl_frame **master_bias, cpl_frame **bpmap, cpl_frame **order_tab_edges, cpl_frame **master_flat)
cpl_frameset * xsh_frameset_mflat_divide(cpl_frameset *input, cpl_frame *mflat, xsh_instrument *instrument)
Generates a new frameset with each frame mflat divided input frameset.
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)