ERIS Pipeline Reference Manual 1.9.2
eris_ifu_stdstar.c
1/* $Id: eris_ifu_recipe.c,v 1.33 2013-03-26 17:00:45 jtaylor Exp $
2 *
3 * This file is part of the ERIS Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * $Author: jtaylor $
23 * $Date: 2013-03-26 17:00:45 $
24 * $Revision: 1.33 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35#include <cpl.h>
36#include <string.h>
37#include <strings.h>
38#include "eris_ifu_error.h"
39#include <eris_ifu_jitter_interface.h>
40#include <eris_ifu_jitter_static.h>
41#include <eris_ifu_stdstar_static.h>
42#include <eris_ifu_lambda_corr.h>
43#include <eris_ifu_resample.h>
44#include <eris_ifu_strehl.h>
45#include <eris_ifu_extract_spec_static.h>
46#include <eris_ifu_efficiency_response.h>
47#include <eris_utils.h>
48#define M1_RADIUS 8.15
49#define M2_RADIUS 0.9
50
51/*-----------------------------------------------------------------------------
52 Static variables
53 -----------------------------------------------------------------------------*/
54#define CONTEXT "eris.eris_ifu_stdstar"
55
56static const char eris_ifu_stdstar_description[] = "\
57This recipe performs ERIS/SPIFFIER science data reduction.\n\
58\n\
59When an OH_SPEC file is provided in the SOF the recipe will use the OH lines\n\
60to correct the lambda calibration.\n\
61\n\
62-----------------------------------------------------------------------------\n\
63Input files:\n\
64 DO CATG Explanation Required #Frames\n\
65 ------- ----------- -------- -------\n\
66 science exposures with corresponding sky exposures: \n\
67 OBJ Science object exposure Y ? \n\
68 SKY_OBJ Sky exposure Y ? \n\
69 or \n\
70 STD Standard star exposure Y ? \n\
71 SKY_STD Standard star sky exposure Y ? \n\
72 or \n\
73 PSF_CALIBRATOR PSF calibration source Y ? \n\
74 SKY_PSF_CALIBRATOR PSF calibration sky exposure Y ? \n\
75 \n\
76 and calibration frames: \n\
77 DISTORTION Table with distortion correction pars. Y 1 \n\
78 WAVE_MAP Wavelength calibration map Y 1 \n\
79 OH_SPEC Vector holding OH lines (note 4) Y 1 \n\
80 MASTER_DARK Optional master dark image N [0,1]\n\
81 MASTER_FLAT Optional master flat image N [0,1]\n\
82 BPM_DARK Optional bad pixel mask (note 1 & 3) N [0,1]\n\
83 BPM_FLAT Optional bad pixel mask (note 2 & 3) N [0,1]\n\
84 BPM_LINEARITY Optional bad pixel mask (note 3) N [0,1]\n\
85 EXTCOEFF_TABLE Table with atmospheric extinction N [0,1]\n\
86 FLUX_STD_CATALOG Table with ref flux std star spectra N [0,1]\n\
87 EFFICIENCY_WINDOWS Table with ranges to compute efficiency N [0,1]\n\
88 FIT_AREAS Table with ranges to perform fit N [0,1]\n\
89 QUALITY_AREAS Table with quality regions area N [0,1]\n\
90 RESP_FIT_POINTS_CATALOG Table with points where to fit resp N [0,1]\n\
91 RESPONSE_WINDOWS Table with regions for response computation N [0,1]\n\
92 TELL_MOD_CATALOG Catalog with tellurics models N [0,1]\n\
93\n\
94 and only in case of old SINFONIE way of distortion correction:\n\
95 DISTANCES Table with slitlet distances \n\
96 with cube.slitlet-detection=\"DIST\" Y 1 \n\
97 SLITLET_POS Table with slitlet edge positions \n\
98 with cube.slitlet-detection=\"EDGE\" Y 1 \n\
99\n\
100Output files:\n\
101 DO CATG Explanation Product Depth\n\
102 ------- ------------------------------------------- -------------\n\
103 OBJECT_CUBE reconstructed object expoure (note 5) PD_AUX\n\
104 SKY_CUBE reconstructed sky exposure (note 6) PD_AUX\n\
105\n\
106Note 1) When BPM_DARK is provided this will be used as hot bad pixel mask.\n\
107 Otherwise the qualiiy extension of MASTER_DARK will be used.\n\
108Note 2 When BPM_FLAT is provided this will be used as cold bad pixel mask.\n\
109 Otherwise the qualiiy extension of MASTER_FLAT will be used.\n\
110Note 3) All BPMs will be ORed.\n\
111Note 4) OH_SPEC can be a FITS file holding a single OH spectrum in the primary\n\
112 HDU or a FITS file with several extensions each of them holding an OH spectrum\n\
113 for one of the bands J,H,K,HK.\n\
114 The pipeline package provides the file eris_oh_spec.fits holding OH spectra\n\
115 for all bands.\n\
116Note 5) If SKY_TWEAK is selected no image will be subtracted, else if there is\n\
117 a matching sky exposure this exposure will be subtracted. Else if a masterDark\n\
118 image is available this image will be subtracted\n\
119Note 6) If SKY_TWEAK is selected no image will be subtracted. Else if a masterDark\n\
120 image is available this image will be subtracted\n\
121\n\
122Information on relevant parameters may be found with\n\
123 esorex --params "REC_NAME_STDSTAR"\n\
124 esorex --help "REC_NAME_STDSTAR"\n\
125\n\
126QC parameters:\n\
127ESO QC LAMBDA SHIFT UM OH based shift of the central wavelength in [um]\n\
128ESO QC LAMBDA SHIFT PIXEL OH based shift of the central wavelength in [pixel]\n\
129";
130
131/*-----------------------------------------------------------------------------
132 Private function prototypes
133 -----------------------------------------------------------------------------*/
134
135cpl_recipe_define(eris_ifu_stdstar, ERIS_BINARY_VERSION, "Erich Wiezorrek",
136 PACKAGE_BUGREPORT, "2019",
137 "This recipe reconstruct data cubes from std stars exposures",
138 eris_ifu_stdstar_description);
139
140#define RECIPE_NAME "eris_ifu_stdstar"
141
142
143/*-----------------------------------------------------------------------------
144 Function code
145 -----------------------------------------------------------------------------*/
146
147/*----------------------------------------------------------------------------*/
155/*----------------------------------------------------------------------------*/
156static cpl_error_code eris_ifu_stdstar_fill_parameterlist(cpl_parameterlist *pl)
157{
158 cpl_error_code err = CPL_ERROR_NONE;
159
160 TRY
161 {
164 REC_NAME_STDSTAR, M_STDSTAR, pl));
167 REC_NAME_STDSTAR, M_STDSTAR, pl));
168 } CATCH {
169 err = cpl_error_get_code();
170 }
171
172 return err;
173}
174
175static cpl_error_code
176eris_ifu_remove_noflat_products(const cpl_frameset *frameset_noflat){
177
178 cpl_size nframes = cpl_frameset_get_size(frameset_noflat);
179 const cpl_frame* frame = NULL;
180 const char* fname = NULL;
181 char* cmd;
182 for(cpl_size i = 0; i < nframes; i++) {
183 frame = cpl_frameset_get_position_const(frameset_noflat, i);
184 if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_PRODUCT) {
185 fname = cpl_frame_get_filename(frame);
186 cmd = cpl_sprintf("rm -f %s",fname);
187 system(cmd);
188 cpl_free(cmd);
189 }
190 }
191 eris_check_error_code("eris_ifu_remove_noflat_products");
192 return cpl_error_get_code();
193}
194
195/*----------------------------------------------------------------------------*/
202/*----------------------------------------------------------------------------*/
203static int eris_ifu_stdstar(cpl_frameset *frameset,
204 const cpl_parameterlist * parlist)
205{
206 /* check required input tags are present */
207 const int ntags = 1;
208 const char* required_tags[1] = {
209 ERIS_IFU_CALIB_OH_SPEC
210 };
211
212 cpl_ensure_code(CPL_ERROR_NONE ==
213 eris_dfs_check_input_tags(frameset, required_tags, ntags, 1),
214 CPL_ERROR_ILLEGAL_INPUT);
215
216 /* duplicate raw frameset BEFORE processing data */
217 cpl_frame* flat_frame = NULL;
218 cpl_frameset* frameset_noflat = NULL;
219 cpl_boolean is_std_flux = CPL_FALSE;
220 if(cpl_frameset_find(frameset,"STD") != NULL ||
221 cpl_frameset_find(frameset,"STD_FLUX") != NULL) {
222 is_std_flux = CPL_TRUE;
223 }
224 flat_frame = cpl_frameset_find(frameset, ERIS_IFU_CALIB_FLATFIELD);
225 if (flat_frame != NULL) {
226
227 frameset_noflat = cpl_frameset_duplicate(frameset);
228 cpl_frameset_erase(frameset_noflat,ERIS_IFU_CALIB_FLATFIELD);
229
230 }
231
232 eris_stdstar_reduction_common(frameset, parlist, CPL_TRUE, CONTEXT, RECIPE_NAME);
233
234 if (is_std_flux && flat_frame != NULL) {
235 /* repeat initial reduction with initial raw frameset without the flat
236 * field to compute efficiency properly */
237 eris_stdstar_reduction_common(frameset_noflat, parlist, CPL_FALSE, CONTEXT, RECIPE_NAME);
238 eris_print_rec_status(3);
239 cpl_frame* eff_frame = cpl_frameset_find(frameset_noflat,
240 ERIS_IFU_PRO_JITTER_EFFICIENCY);
241 if(eff_frame != NULL) {
242 cpl_frameset_insert(frameset, cpl_frame_duplicate(eff_frame));
243 cpl_frameset_erase_frame(frameset_noflat,eff_frame);
244 }
245 eris_ifu_remove_noflat_products(frameset_noflat);
246
247 }
248 if (flat_frame != NULL) {
249 cpl_frameset_delete(frameset_noflat);
250 }
251 eris_check_error_code("eris_ifu_stdstar");
252 return (int)cpl_error_get_code();
253}
254
255
256
#define BRK_IF_ERROR(function)
If function is or returns an error != CPL_ERROR_NONE, then the try-block is exited.
#define TRY
Beginning of a TRY-block.
#define CATCH
End of a TRY-block, beginning of a CATCH-block.
cpl_error_code eris_ifu_stdstar_fill_common_parameterlist(const char *recipeName, jitterModes jitterMode, cpl_parameterlist *pl)
Fill parameter list with standard star-specific parameters.
cpl_error_code eris_ifu_jitter_fill_common_parameterlist(const char *recipeName, jitterModes jitterMode, cpl_parameterlist *pl)
Fill parameter list with common jitter recipe parameters.
cpl_error_code eris_stdstar_reduction_common(cpl_frameset *frameset, const cpl_parameterlist *parlist, cpl_boolean apply_flat_field, const char *context, const char *recipe_name)
Main standard star data reduction pipeline orchestration function.
cpl_error_code eris_check_error_code(const char *func_id)
handle CPL errors
Definition: eris_utils.c:56