X-shooter Pipeline Reference Manual 3.8.15
xsh_flexcomp.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/*
22 * $Author: amodigli $
23 * $Date: 2012-12-18 14:12:51 $
24 * $Revision: 1.59 $
25 * $Name: not supported by cvs2svn $
26 *
27 */
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32
33/*--------------------------------------------------------------------------*/
41/*--------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------
45 Includes
46 ---------------------------------------------------------------------------*/
47
48
49//#include <xsh_pfits.h>
50/* DRL steps */
51
52/* Error handling */
53#include <xsh_error.h>
54/* Utility fonctions */
55#include <xsh_utils.h>
56#include <xsh_msg.h>
57/* DFS functions */
58#include <xsh_dfs.h>
59#include <xsh_drl_check.h>
60/* DRL functions */
61#include <xsh_pfits.h>
62#include <xsh_data_order.h>
63#include <xsh_data_instrument.h>
64#include <xsh_drl.h>
65#include <xsh_model_kernel.h>
67
68/* Library */
69#include <cpl.h>
70
71/*---------------------------------------------------------------------------
72 Defines
73 ---------------------------------------------------------------------------*/
74
75#define RECIPE_ID "xsh_flexcomp"
76#define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer"
77#define RECIPE_CONTACT "amodigli@eso.org"
78
79#define XSH_AFC_UVB_XMIN 573
80#define XSH_AFC_UVB_YMIN 1501
81#define XSH_AFC_UVB_XMAX 1572
82#define XSH_AFC_UVB_YMAX 2500
83#define XSH_AFC_UVB_ORDER 18
84
85#define XSH_AFC_VIS_XMIN 534
86#define XSH_AFC_VIS_YMIN 2301
87#define XSH_AFC_VIS_XMAX 1533
88#define XSH_AFC_VIS_YMAX 3300
89#define XSH_AFC_VIS_ORDER 26
90
91/*---------------------------------------------------------------------------
92 Functions prototypes
93 ---------------------------------------------------------------------------*/
94
95/*
96 * Plugin initalization, execute and cleanup handlers
97 */
98
99static int xsh_flexcomp_create(cpl_plugin *);
100static int xsh_flexcomp_exec(cpl_plugin *);
101static int xsh_flexcomp_destroy(cpl_plugin *);
102
103/* The actual executor function */
104static void xsh_flexcomp(cpl_parameterlist *, cpl_frameset *);
105
106/*---------------------------------------------------------------------------
107 Static variables
108 ---------------------------------------------------------------------------*/
110"Compute the flexure of the instrument";
111
113"This recipe computes the flexure of the instrument and correct CAL files.\n\
114 Input Frames :\n\
115 - [UVB, VIS] One RAW frame (Format = RAW, Tag = AFF_ATT_arm)\n\
116 - [NIR] Two RAW frames ((Format = RAW, Tag = AFC_ATT_arm_ON,\
117AFC_ATT_arm_OFF)\n\
118 - An arc line list (Format = TABLE, Tag = ARC_LINE_LIST_AFC_arm)\n\
119 - A spectral format table frame (Format = TABLE, Tag = SPECTRAL_FORMAT_TAB_arm)\n\
120 - [UVB,VIS] A master bias (Format = PRE, Tag = MASTER_BIAS_arm)\n\
121 - [UVB,VIS] A master dark (Format = PRE, Tag = MASTER_DARK_arm)\n\
122 - An order table frame (Format = TABLE, Tag = ORDER_TAB_EDGES_IFU_arm)\n\
123 - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)\n\
124 - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)\n\
125 - [poly mode] A wave solution frame (Format = TABLE, Tag = WAVE_TAB_2D_arm)\n\
126 - [physical model mode] A model cfg table (Format = TABLE, Tag = XSH_MOD_CFG_OPT_2D_arm)\n\
127 Products : \n\
128 - [poly mode] An updated wave solution frame (Format = TABLE, Tag = WAVE_TAB_AFC_arm)\n\
129 - [physical model mode] An updated model cfg table (Format = TABLE, Tag = XSH_MOD_CFG_OPT_AFC_arm)\n\
130 - An updated order table frame (Format = TABLE, Tag = ORDER_TAB_AFC_IFU_arm)\n\
131 - [poly mode] A dispersion table frame (Format = TABLE, Tag = DISP_TAB_AFC_arm)\n";
132
133/*---------------------------------------------------------------------------
134 Functions code
135 ---------------------------------------------------------------------------*/
136/*--------------------------------------------------------------------------*/
145/*--------------------------------------------------------------------------*/
146
147int cpl_plugin_get_info(cpl_pluginlist *list) {
148 cpl_recipe *recipe = NULL;
149 cpl_plugin *plugin = NULL;
150
151 recipe = cpl_calloc(1, sizeof(*recipe));
152 if ( recipe == NULL ){
153 return -1;
154 }
155
156 plugin = &recipe->interface ;
157
158 cpl_plugin_init(plugin,
159 CPL_PLUGIN_API, /* Plugin API */
160 XSH_BINARY_VERSION, /* Plugin version */
161 CPL_PLUGIN_TYPE_RECIPE, /* Plugin type */
162 RECIPE_ID, /* Plugin name */
163 xsh_flexcomp_description_short, /* Short help */
164 xsh_flexcomp_description, /* Detailed help */
165 RECIPE_AUTHOR, /* Author name */
166 RECIPE_CONTACT, /* Contact address */
167 xsh_get_license(), /* Copyright */
171
172 cpl_pluginlist_append(list, plugin);
173
174 return (cpl_error_get_code() != CPL_ERROR_NONE);
175 }
176
177/*--------------------------------------------------------------------------*/
187/*--------------------------------------------------------------------------*/
188
189static int xsh_flexcomp_create(cpl_plugin *plugin){
190 cpl_recipe *recipe = NULL;
191 xsh_clipping_param detarc_clip_param = { 2.0, 10, 0.7, 0, 0.3};
192 xsh_detect_arclines_param detarc_param = { 6, 3, 0, 5, 5, 0, 2, 5.0,
193 XSH_GAUSSIAN_METHOD, FALSE};
194 xsh_dispersol_param dispsol_param = { 4, 5 } ;
195 char paramname[256];
196 cpl_parameter* p=NULL;
197 int ival=DECODE_BP_FLAG_DEF;
198
199 /* Reset library state */
200 xsh_init();
201
202 /* Check input */
203 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
204
205 /* Get the recipe out of the plugin */
206 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
207 CPL_ERROR_TYPE_MISMATCH,
208 "Plugin is not a recipe");
209
210 recipe = (cpl_recipe *)plugin;
211
212 /* Create the parameter list in the cpl_recipe object */
213 recipe->parameters = cpl_parameterlist_new();
214 assure( recipe->parameters != NULL,
215 CPL_ERROR_ILLEGAL_OUTPUT,
216 "Memory allocation failed!");
217
218 /* Set generic parameters (common to all recipes) */
219 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
220 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,ival);
221 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
222 /* General 2dmap parameters
223 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
224 "compute-disptab",
225 TRUE,
226 "Compute the wavemap and the slitmap and the dispersion table."));
227 */
228 /* detect arclines params */
230 detarc_param));
232 recipe->parameters, detarc_clip_param));
233
235 recipe->parameters,
236 dispsol_param ));
237
238 /* Annealing parameter */
239 check( xsh_parameters_new_int( recipe->parameters, RECIPE_ID,
240 "model-maxit",1000,
241 "Number/10 of annealing iterations "
242 "if in physical model mode."));
243
244 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
245 "model-anneal-factor",1.0,
246 "Multiplier applied to the automatic "
247 "parameter ranges (i.e. when scenario!=0). "
248 "For routine operations should be 1.0. "
249 "(physical model mode)."));
250
251
252 sprintf(paramname,"xsh.%s.%s",RECIPE_ID,"model-scenario");
253
254 check(p=cpl_parameter_new_enum(paramname,CPL_TYPE_INT,
255 "selects preset flag and range combinations "
256 "appropriate to common scenarios: "
257 "-1 - Only the position across the slit and"
258 " camera focal length are open\n"
259 " 0 - No scenario, input cfg flags and limits"
260 " used."
261 " 1 - scenario appropriate for the startup"
262 " recipe (large ranges for parameters "
263 " affecting single ph exposures, dist "
264 " coeff fixed)"
265 " 2 - Like 1, but includes parameters "
266 " affecting all ph positions"
267 " 3 - Scenario for use in fine tuning cfg"
268 " to match routine wavecal exposures. All"
269 " parameters affecting 1ph exposures"
270 " except dist coeffs are included and"
271 " parameter ranges are small. (For use by"
272 " flexcomp in 1ph case)."
273 " 4 - Like 3 but includes parameters"
274 " affecting all ph positions (Standard for"
275 " use by flexcomp in 9ph case and 2dmap)."
276 " 5 - Like 4 but includes also dist coeffs"
277 " 6 - Just dist coeffs (and chipx, chipy)",
278 RECIPE_ID,3,9,-1,0,1,2,3,4,5,6,8));
279
280
281 check(cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
282 "model-scenario"));
283 check(cpl_parameterlist_append(recipe->parameters,p));
284
285
286 cleanup:
287 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
288 xsh_error_dump(CPL_MSG_ERROR);
289 return 1;
290 }
291 else {
292 return 0;
293 }
294}
295
296/*--------------------------------------------------------------------------*/
302/*--------------------------------------------------------------------------*/
303
304static int xsh_flexcomp_exec(cpl_plugin *plugin) {
305 cpl_recipe *recipe = NULL;
306
307 /* Check parameter */
308 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
309
310 /* Get the recipe out of the plugin */
311 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
312 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
313
314 recipe = (cpl_recipe *)plugin;
315
316 /* Check recipe */
317 xsh_flexcomp(recipe->parameters, recipe->frames);
318
319 cleanup:
320 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
321 xsh_error_dump(CPL_MSG_ERROR);
322 cpl_error_reset();
323 return 1;
324 }
325 else {
326 return 0;
327 }
328}
329
330/*--------------------------------------------------------------------------*/
336/*--------------------------------------------------------------------------*/
337static int xsh_flexcomp_destroy(cpl_plugin *plugin)
338{
339 cpl_recipe *recipe = NULL;
340
341 /* Check parameter */
342 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
343
344 /* Get the recipe out of the plugin */
345 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
346 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
347
348 recipe = (cpl_recipe *)plugin;
349
350 xsh_free_parameterlist(&recipe->parameters);
351
352 cleanup:
353 if (cpl_error_get_code() != CPL_ERROR_NONE)
354 {
355 return 1;
356 }
357 else
358 {
359 return 0;
360 }
361}
362
363static cpl_error_code
364xsh_params_set_defaults(cpl_parameterlist* pars,
365 xsh_instrument* inst,
366 xsh_detect_arclines_param* detect_arclines_p)
367{
368 cpl_parameter* p=NULL;
369
370 check(p=xsh_parameters_find(pars,RECIPE_ID,"detectarclines-min-sn"));
371 if(cpl_parameter_get_double(p) <= 0) {
373 /* if the user has not set the parameter use default */
374 cpl_parameter_set_double(p,4);
375 detect_arclines_p->min_sn=4;
376 } else {
377 cpl_parameter_set_double(p,3);
378 detect_arclines_p->min_sn=3;
379 }
380 }
381
382 cleanup:
383
384 return cpl_error_get_code();
385
386}
387
388static cpl_error_code
389xsh_frame_check_is_right_afcatt(cpl_frame* afcatt_frame,
391{
392 cpl_propertylist* plist=NULL;
393 const char* name=NULL;
394 char* slit_value=NULL;
395 name=cpl_frame_get_filename(afcatt_frame);
396 plist=cpl_propertylist_load(name,0);
397 check(slit_value=xsh_pfits_get_slit_value (plist,instrument));
398 if (strcmp(slit_value,"Pin_0.5") != 0 ) {
399 xsh_msg_error("INS OPTIi NAME value=%s",slit_value);
400 xsh_msg_error("Your input AFC frame should be the 1st of the AFC sequence");
401 xsh_msg_error("Its INS OPTIi NAME key value should be 'Pin_0.5'");
402 cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT);
403 }
404
405cleanup:
406 xsh_free_propertylist(&plist);
407
408 return cpl_error_get_code();
409
410
411}
412
413/*--------------------------------------------------------------------------*/
421/*--------------------------------------------------------------------------*/
422static void xsh_flexcomp(cpl_parameterlist* parameters, cpl_frameset* frameset)
423{
424 const char* recipe_tags[1] = {XSH_AFC_ATT};
425 int recipe_tags_size = 1;
426
427 /* RECIPES parameters */
428 xsh_clipping_param* detect_arclines_clipping = NULL;
429 xsh_detect_arclines_param* detect_arclines_p = NULL;
430 xsh_dispersol_param *dispsol_param = NULL ;
431
432 /* ALLOCATED locally */
433 cpl_frameset* raws = NULL;
434 cpl_frameset* calib = NULL;
436
437 cpl_frame* arclist_frame = NULL;
438 cpl_frame* afcatt_frame = NULL;
439 cpl_frame* spectralformat_frame = NULL;
440 cpl_frame* order_tab_edges_frame = NULL;
441 cpl_frame* wave_tab_frame = NULL;
442 /* Not used */
443 cpl_frame* wave_map_frame = NULL;
444 cpl_frame* slit_map_frame = NULL;
445
446 cpl_frame* model_config_frame = NULL;
447 cpl_frame* masterbias_frame = NULL;
448 cpl_frame* masterdark_frame = NULL;
449 cpl_frame* bpmap_frame = NULL;
450
451 cpl_frame *subbpmap_frame = NULL;
452 cpl_frame *subbias_frame = NULL;
453 cpl_frame *subdark_frame = NULL;
454 int afc_xmin=1;
455
456 int afc_ymin=1;
457
458 int afc_order=0;
459 cpl_frame* afcatt_rmbias = NULL;
460 cpl_frame* afcatt_rmdark = NULL;
461 cpl_frame* att_cleanlines = NULL;
462 cpl_frame* att_resid_tab = NULL;
463 cpl_frame *afcthetab_frame = NULL;
464 const char *tag = NULL;
465 char filename [256];
466 cpl_frame *afc_wave_tab_frame = NULL;
467 cpl_frame *afc_order_tab_edges_frame = NULL;
468 cpl_frame *afc_disp_tab_frame = NULL;
469 cpl_frame *afc_config_tab_frame = NULL;
471 int pre_overscan_corr=0;
472
473 char wave_map_tag[256];
474 char slit_map_tag[256];
475 int nraws=0;
476 cpl_boolean mode_phys;
477
478 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
479 recipe_tags, recipe_tags_size,
480 RECIPE_ID, XSH_BINARY_VERSION,
482 nraws=cpl_frameset_get_size(raws);
483 assure(nraws > 0, CPL_ERROR_NULL_INPUT, "Provide an input AFC_ATT_ARM frame");
484
486 /**************************************************************************/
487 /* Recipe frames */
488 /**************************************************************************/
489 mode_phys=xsh_mode_is_physmod(calib,instrument);
491 check( arclist_frame = xsh_find_frame_with_tag( calib,
493 instrument));
494 XSH_ASSURE_NOT_NULL_MSG( arclist_frame,
495 "No input ARC_LINE_AFC_LIST_ARM arclines list provided");
496 check( spectralformat_frame = xsh_find_frame_with_tag( calib,
498 XSH_ASSURE_NOT_NULL_MSG( spectralformat_frame,
499 "No spectral format provided");
500 check( order_tab_edges_frame = xsh_find_order_tab_edges( calib,instrument));
501 XSH_ASSURE_NOT_NULL_MSG( order_tab_edges_frame,
502 "No input ORDER_TABLE_EDGES_MODE_ARM (MODE=IFU or SLIT) table provided");
503
504 /* Could be in sof */
505 if(!mode_phys) {
506 wave_tab_frame = xsh_find_wave_tab( calib, instrument);
507 } else {
508
509 if ( (model_config_frame = xsh_find_frame_with_tag( calib,
510 XSH_MOD_CFG_OPT_2D, instrument)) == NULL) {
512 if ((model_config_frame = xsh_find_frame_with_tag(calib,
513 XSH_MOD_CFG_TAB, instrument)) == NULL) {
515 }
516 }
517 }
518 if( (model_config_frame!=NULL) && (wave_tab_frame != NULL) ) {
519
520 xsh_msg_error("You cannot provide both a %s and a %s frame. Decide if you are in poly or physical model mode. We exit",
522 goto cleanup;
523 }
524
525 if((model_config_frame==NULL) && ( wave_tab_frame == NULL) ) {
526 xsh_msg_error("You must provide either a %s or a %s frame",
528 goto cleanup;
529 }
530
532 /* In UVB and VIS mode */
533 if ( arm != XSH_ARM_NIR){
534 if((masterbias_frame = xsh_find_frame_with_tag(calib,XSH_MASTER_BIAS,
535 instrument)) == NULL) {
536
537 xsh_msg_warning("Frame %s not provided",XSH_MASTER_BIAS);
539 }
540
541 if((masterdark_frame = xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,
542 instrument)) == NULL){
543 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
545 }
546 }
548 spectralformat_frame));
549 check( pre_overscan_corr = xsh_parameters_get_int( parameters, RECIPE_ID,
550 "pre-overscan-corr"));
551
552 /**************************************************************************/
553 /* Recipe parameters */
554 /**************************************************************************/
555 check(detect_arclines_clipping =
558 parameters));
559 check( dispsol_param = xsh_parameters_dispersol_get( RECIPE_ID, parameters));
560 check(xsh_params_set_defaults(parameters,instrument,detect_arclines_p));
561
562 /**************************************************************************/
563 /* Recipe code */
564 /**************************************************************************/
565 int afc_xmax=1;
566 int afc_ymax=1;
567 if (arm != XSH_ARM_NIR){
568 /* In UVB and VIS mode */
569 if ( arm == XSH_ARM_VIS){
570 afc_xmin = XSH_AFC_VIS_XMIN-10;
571 afc_xmax = XSH_AFC_VIS_XMAX-10;
572 afc_ymin = XSH_AFC_VIS_YMIN;
573 afc_ymax = XSH_AFC_VIS_YMAX;
574 afc_order = XSH_AFC_VIS_ORDER;
575 }
576 else {
577 afc_xmin = 2145-XSH_AFC_UVB_XMAX-48;
578 afc_xmax = 2145-XSH_AFC_UVB_XMIN-48;
579 afc_ymin = 3001-XSH_AFC_UVB_YMAX;
580 afc_ymax = 3001-XSH_AFC_UVB_YMIN;
581 afc_order = XSH_AFC_UVB_ORDER;
582 }
583 xsh_msg("AFC pre coordinates (%d,%d, %d,%d)",afc_xmin,afc_ymin,
584 afc_xmax,afc_ymax);
585 /* prepare bpmap */
586 if ( bpmap_frame != NULL){
587 check( subbpmap_frame = xsh_badpixelmap_extract( bpmap_frame,
588 afc_xmin, afc_ymin, afc_xmax, afc_ymax));
589 }
590 /* prepare bias */
591 if ( masterbias_frame != NULL){
592 check( subbias_frame = xsh_preframe_extract( masterbias_frame,
593 afc_xmin, afc_ymin, afc_xmax, afc_ymax,
594 "TEST_SUBBIAS.fits", instrument));
595 }
596 /* prepare dark */
597 if ( masterdark_frame != NULL){
598 check( subdark_frame = xsh_preframe_extract( masterdark_frame,
599 afc_xmin, afc_ymin, afc_xmax, afc_ymax,
600 "TEST_SUBDARK.fits", instrument));
601
602 }
603 }
604 check( xsh_prepare( raws, subbpmap_frame, subbias_frame, XSH_AFC_ATT,
605 instrument,pre_overscan_corr,CPL_TRUE));
606
607 check( afcatt_frame = cpl_frameset_get_frame( raws,0));
609
610 if( subbias_frame != NULL) {
611 /* subtract bias */
612 check( afcatt_rmbias = xsh_subtract_bias( afcatt_frame, subbias_frame,
613 instrument,"AFC_ATT_",
614 pre_overscan_corr,1));
615 }
616 else {
617 afcatt_rmbias =cpl_frame_duplicate( afcatt_frame);
618 }
619
620 if( subdark_frame != NULL) {
621 /* subtract dark */
622 sprintf( filename, "AFCATT_DARK_%s.fits",
624 check( afcatt_rmdark = xsh_subtract_dark( afcatt_rmbias, subdark_frame,
625 filename, instrument));
626 }
627 else {
628 afcatt_rmdark =cpl_frame_duplicate( afcatt_rmbias);
629 }
630 check( afcthetab_frame = xsh_afcthetab_create( wave_tab_frame,
631 model_config_frame, afc_order, spectralformat_frame,
632 arclist_frame, afc_xmin, afc_ymin,
633 instrument,1));
634
635 /* detect arclines */
636 check( xsh_detect_arclines( afcatt_rmdark, afcthetab_frame,
637 arclist_frame, NULL, NULL,
638 NULL, spectralformat_frame, NULL,
639 &att_cleanlines, NULL, &att_resid_tab, XSH_SOLUTION_RELATIVE,
640 detect_arclines_p,
641 detect_arclines_clipping,
642 instrument,RECIPE_ID,1,0));
643
644 /* compute the shift between CAl_RESID_TAB and ATT_RESID_TAB */
645 check( afc_wave_tab_frame = xsh_flexcor( afcatt_frame, wave_tab_frame,
646 model_config_frame,
647 order_tab_edges_frame, att_resid_tab,
648 afc_xmin, afc_ymin, instrument,
649 &afc_order_tab_edges_frame,
650 &afc_config_tab_frame));
651
652 if(model_config_frame == NULL) {
653
654
655 if ( wave_tab_frame != NULL){
656 check( xsh_create_poly_wavemap( NULL, wave_tab_frame,
657 afc_order_tab_edges_frame,
658 spectralformat_frame,
659 dispsol_param,
661 "AFC_",
662 &afc_disp_tab_frame, NULL));
663
665 check( cpl_frame_set_tag( afc_disp_tab_frame, tag));
666 }
667
668 } else {
669 /* Suppressed to prevent seg faults */
670 sprintf(slit_map_tag,"SLIT_MAP_%s",
672
673 sprintf(wave_map_tag,"WAVE_MAP_%s",
675 check(xsh_create_model_map(model_config_frame,instrument,
676 wave_map_tag,slit_map_tag,
677 &wave_map_frame, &slit_map_frame,1));
678
679 check(afc_disp_tab_frame=xsh_create_dispersol_physmod(afcatt_rmdark,
680 afc_order_tab_edges_frame,
681 model_config_frame,
682 wave_map_frame,
683 slit_map_frame,
684 dispsol_param,
685 spectralformat_frame,
686 instrument,1));
687
688 }
689
690 /**************************************************************************/
691 /* Products */
692 /**************************************************************************/
693 xsh_msg("Saving products");
694
695 if ( afc_wave_tab_frame != NULL){
696 check(xsh_add_product_table( afc_wave_tab_frame, frameset,
697 parameters, RECIPE_ID, instrument,NULL));
698 }
699 if ( afc_config_tab_frame != NULL){
700 cpl_msg_info(__func__,"Writing out afc_config_tab_frame as %s\n",cpl_frame_get_filename(afc_config_tab_frame));
701 check(xsh_add_product_table( afc_config_tab_frame, frameset,
702 parameters, RECIPE_ID, instrument,NULL));
703 }
704
705 if ( afc_order_tab_edges_frame != NULL){
706 check(xsh_add_product_table( afc_order_tab_edges_frame, frameset,
707 parameters, RECIPE_ID, instrument,NULL));
708 }
709 if (afc_disp_tab_frame != NULL){
710 check( xsh_add_product_table( afc_disp_tab_frame, frameset,
711 parameters,RECIPE_ID,instrument,NULL));
712 }
713
714 xsh_msg("xsh_flexcomp success !!");
715
716 cleanup:
717 xsh_end( RECIPE_ID, frameset, parameters);
718
719 XSH_FREE( detect_arclines_clipping);
720 XSH_FREE( detect_arclines_p);
721 XSH_FREE( dispsol_param);
722
723 xsh_free_frameset( &raws);
724 xsh_free_frameset( &calib);
725 xsh_free_frame( &bpmap_frame);
726 xsh_free_frame( &wave_map_frame);
727 xsh_free_frame( &slit_map_frame);
728 xsh_free_frame( &subbpmap_frame);
729 xsh_free_frame( &subbias_frame);
730 xsh_free_frame( &subdark_frame);
731 xsh_free_frame( &afcatt_rmbias);
732 xsh_free_frame( &afcatt_rmdark);
733 xsh_free_frame( &att_resid_tab);
734 xsh_free_frame( &att_cleanlines);
735 xsh_free_frame( &afc_wave_tab_frame);
736 xsh_free_frame( &afc_config_tab_frame);
737 xsh_free_frame( &afc_order_tab_edges_frame);
738 xsh_free_frame( &afc_disp_tab_frame);
739 xsh_free_frame( &afcthetab_frame);
741 return;
742}
743
static xsh_instrument * instrument
cpl_frame * xsh_badpixelmap_extract(cpl_frame *frame, int xmin, int ymin, int xmax, int ymax)
This function create a sub bad pixel map frame from input bad pixel map frame. the sub frame is descr...
void xsh_detect_arclines(cpl_frame *frame, cpl_frame *theo_tab_frame, cpl_frame *arc_lines_tab_frame, cpl_frame *wave_tab_guess_frame, cpl_frame *order_tab_recov_frame, cpl_frame *config_model_frame, cpl_frame *spectralformat_frame, cpl_frame **resid_tab_orders_frame, cpl_frame **arc_lines_clean_tab_frame, cpl_frame **wave_tab_frame, cpl_frame **resid_tab_frame, xsh_sol_wavelength solwave_type, xsh_detect_arclines_param *da, xsh_clipping_param *dac, xsh_instrument *instr, const char *rec_id, const int clean_tmp, const int resid_tab_name_sw)
detect the position on the detector of emission lines listed in a catalogue, from expected position v...
cpl_frame * xsh_preframe_extract(cpl_frame *frame, int xmin, int ymin, int xmax, int ymax, const char *name, xsh_instrument *instr)
This function create a sub frame from PRE frame. the sub frame is described by a box.
Definition: xsh_prepare.c:221
void xsh_prepare(cpl_frameset *frames, cpl_frame *bpmap, cpl_frame *mbias, const char *prefix, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
This function transform RAW frames dataset in PRE frames dataset attaching the default bad pixel map ...
Definition: xsh_prepare.c:122
#define XSH_ASSURE_NOT_NULL_MSG(pointer, msg)
Definition: xsh_error.h:103
#define assure(CONDITION, ERROR_CODE,...)
Definition: xsh_error.h:54
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define xsh_error_reset()
Definition: xsh_error.h:87
#define XSH_AFC_VIS_YMAX
Definition: xsh_flexcomp.c:88
#define XSH_AFC_VIS_ORDER
Definition: xsh_flexcomp.c:89
#define XSH_AFC_UVB_ORDER
Definition: xsh_flexcomp.c:83
#define RECIPE_CONTACT
Definition: xsh_flexcomp.c:77
#define XSH_AFC_UVB_YMIN
Definition: xsh_flexcomp.c:80
#define XSH_AFC_UVB_XMIN
Definition: xsh_flexcomp.c:79
static int xsh_flexcomp_create(cpl_plugin *)
Setup the recipe options.
Definition: xsh_flexcomp.c:189
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
Definition: xsh_flexcomp.c:147
#define XSH_AFC_VIS_XMIN
Definition: xsh_flexcomp.c:85
static int xsh_flexcomp_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
Definition: xsh_flexcomp.c:337
static cpl_error_code xsh_frame_check_is_right_afcatt(cpl_frame *afcatt_frame, xsh_instrument *instrument)
Definition: xsh_flexcomp.c:389
cpl_frame * xsh_afcthetab_create(cpl_frame *wave_tab_frame, cpl_frame *model_config_frame, int order, cpl_frame *spectralformat_frame, cpl_frame *arclines_frame, int xmin, int ymin, xsh_instrument *instr, const int clean_tmp)
Create a The tab for AFC.
Definition: xsh_flexcor.c:363
static int xsh_flexcomp_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
Definition: xsh_flexcomp.c:304
static cpl_error_code xsh_params_set_defaults(cpl_parameterlist *pars, xsh_instrument *inst, xsh_detect_arclines_param *detect_arclines_p)
Definition: xsh_flexcomp.c:364
static void xsh_flexcomp(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
Definition: xsh_flexcomp.c:422
cpl_frame * xsh_flexcor(cpl_frame *afc_frame, cpl_frame *wave_tab_frame, cpl_frame *model_config_frame, cpl_frame *order_tab_frame, cpl_frame *attresidtab_frame, int afc_xmin, int afc_ymin, xsh_instrument *instr, cpl_frame **afc_order_tab_frame, cpl_frame **afc_model_config_frame)
This function applies the computed shift betwwen AFC CAL and AFC ATT frame.
Definition: xsh_flexcor.c:91
#define XSH_AFC_VIS_YMIN
Definition: xsh_flexcomp.c:86
#define XSH_AFC_UVB_YMAX
Definition: xsh_flexcomp.c:82
static char xsh_flexcomp_description_short[]
Definition: xsh_flexcomp.c:109
#define XSH_AFC_VIS_XMAX
Definition: xsh_flexcomp.c:87
#define RECIPE_ID
Definition: xsh_flexcomp.c:75
#define RECIPE_AUTHOR
Definition: xsh_flexcomp.c:76
#define XSH_AFC_UVB_XMAX
Definition: xsh_flexcomp.c:81
static char xsh_flexcomp_description[]
Definition: xsh_flexcomp.c:112
void xsh_instrument_update_from_spectralformat(xsh_instrument *i, cpl_frame *spectralformat_frame)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
#define xsh_msg_warning(...)
Print an warning message.
Definition: xsh_msg.h:88
#define xsh_msg_error(...)
Print an error message.
Definition: xsh_msg.h:62
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
char * xsh_pfits_get_slit_value(const cpl_propertylist *plist, xsh_instrument *instrument)
find out the INS OPTIx NAME value (the width of the slit)
Definition: xsh_pfits.c:619
cpl_frame * xsh_subtract_bias(cpl_frame *frame, cpl_frame *bias, xsh_instrument *instr, const char *type, const int pre_overscan_corr, const int save_tmp)
Subtract the master bias frame from PRE frame.
Definition: xsh_subtract.c:120
cpl_frame * xsh_subtract_dark(cpl_frame *frame, cpl_frame *dark, const char *filename, xsh_instrument *instr)
subtract the master dark frame from PRE frame
Definition: xsh_subtract.c:247
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
Definition: xsh_utils.c:2224
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
const char * xsh_get_license(void)
Get the pipeline copyright and license.
Definition: xsh_utils.c:1193
void xsh_init(void)
Reset library state.
Definition: xsh_utils.c:1160
cpl_error_code xsh_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
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_error_code xsh_end(const char *recipe_id, cpl_frameset *frames, cpl_parameterlist *parameters)
Recipe termination.
Definition: xsh_utils.c:1519
cpl_frame * xsh_create_dispersol_physmod(cpl_frame *pre_frame, cpl_frame *order_tab_frame, cpl_frame *mod_cfg_frame, cpl_frame *wave_map_frame, cpl_frame *slit_map_frame, xsh_dispersol_param *dispsol_param, cpl_frame *spectral_format_frame, xsh_instrument *instrument, const int clean_tmp)
void xsh_create_model_map(cpl_frame *model_frame, xsh_instrument *instrument, const char *wtag, const char *stag, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const int save_tmp)
cpl_frame * xsh_create_poly_wavemap(cpl_frame *pre_frame, cpl_frame *wave_tab_2d_frame, cpl_frame *order_tab_frame, cpl_frame *spectral_format_frame, xsh_dispersol_param *dispsol_par, xsh_instrument *instrument, const char *wm_tag, cpl_frame **dispersol_frame, cpl_frame **slitmap_frame)
@ XSH_ARM_UNDEFINED
@ XSH_ARM_NIR
@ XSH_ARM_VIS
cpl_frame * xsh_find_order_tab_edges(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab EDGES.
Definition: xsh_dfs.c:3595
cpl_boolean xsh_mode_is_physmod(cpl_frameset *set, xsh_instrument *instrument)
Definition: xsh_dfs.c:4411
void xsh_add_product_table(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
Save Table product (input frame has several extensions, 1 table per extension)
Definition: xsh_dfs.c:3146
cpl_frame * xsh_find_wave_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D or a wave tab ARC.
Definition: xsh_dfs.c:3699
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
Definition: xsh_dfs.c:3347
#define XSH_ARC_LINE_LIST_AFC
Definition: xsh_dfs.h:950
#define XSH_MASTER_BIAS
Definition: xsh_dfs.h:549
#define XSH_MOD_CFG_OPT_2D
Definition: xsh_dfs.h:1233
#define XSH_MASTER_DARK
Definition: xsh_dfs.h:550
#define XSH_MOD_CFG_TAB
Definition: xsh_dfs.h:1251
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_SPECTRAL_FORMAT
Definition: xsh_dfs.h:1196
#define XSH_WAVE_TAB_2D
Definition: xsh_dfs.h:556
#define XSH_AFC_ATT
Definition: xsh_dfs.h:543
#define XSH_DISP_TAB_AFC
Definition: xsh_dfs.h:902
@ XSH_SOLUTION_RELATIVE
Definition: xsh_drl.h:233
cpl_frame * xsh_check_load_master_bpmap(cpl_frameset *calib, xsh_instrument *inst, const char *rec_id)
Definition: xsh_drl_check.c:51
cpl_parameter * xsh_parameters_find(cpl_parameterlist *list, const char *recipe_id, const char *name)
find a parameter
void xsh_parameters_pre_overscan(const char *recipe_id, cpl_parameterlist *plist)
void xsh_parameters_clipping_detect_arclines_create(const char *recipe_id, cpl_parameterlist *list, xsh_clipping_param p)
Create the arclines clipping parameters in a parameters list.
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
void xsh_parameters_new_double(cpl_parameterlist *list, const char *recipe_id, const char *name, double value, const char *comment)
xsh_detect_arclines_param * xsh_parameters_detect_arclines_get(const char *recipe_id, cpl_parameterlist *list)
get the detect arclines parameters in a parameters list
void xsh_parameters_dispersol_create(const char *recipe_id, cpl_parameterlist *list, xsh_dispersol_param p)
Create the dispersol compute parameters in a parameters list.
xsh_clipping_param * xsh_parameters_clipping_detect_arclines_get(const char *recipe_id, cpl_parameterlist *list)
Get the arclines clipping parameters in a parameters list.
int xsh_parameters_get_int(const cpl_parameterlist *list, const char *recipe_id, const char *name)
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
void xsh_parameters_detect_arclines_create(const char *recipe_id, cpl_parameterlist *list, xsh_detect_arclines_param p)
create the detect arclines parameters in a parameters list
cpl_error_code xsh_recipe_params_check(cpl_parameterlist *parameters, xsh_instrument *instrument, const char *rec_id)
void xsh_parameters_new_int(cpl_parameterlist *list, const char *recipe_id, const char *name, int value, const char *comment)
xsh_dispersol_param * xsh_parameters_dispersol_get(const char *recipe_id, cpl_parameterlist *list)
Get the dispersion solution compute parameters in a parameters list.
#define DECODE_BP_FLAG_DEF
@ XSH_GAUSSIAN_METHOD
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92