CR2RE Pipeline Reference Manual 1.6.11
cr2res_obs_staring.c
1/*
2 * This file is part of the CR2RES Pipeline
3 * Copyright (C) 2002,2003 European Southern Observatory
4 *
5 * This program 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, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <cpl.h>
29
30#include "cr2res_utils.h"
31#include "cr2res_idp.h"
32#include "cr2res_calib.h"
33#include "cr2res_pfits.h"
34#include "cr2res_dfs.h"
35#include "cr2res_bpm.h"
36#include "cr2res_trace.h"
37#include "cr2res_extract.h"
38#include "cr2res_io.h"
39#include "cr2res_qc.h"
40
41/*-----------------------------------------------------------------------------
42 Define
43 -----------------------------------------------------------------------------*/
44
45#define RECIPE_STRING "cr2res_obs_staring"
46
47/*-----------------------------------------------------------------------------
48 Plugin registration
49 -----------------------------------------------------------------------------*/
50
51int cpl_plugin_get_info(cpl_pluginlist * list);
52
53/*-----------------------------------------------------------------------------
54 Private function prototypes
55 -----------------------------------------------------------------------------*/
56
57static cpl_frameset * cr2res_obs_staring_find_RAW(
58 const cpl_frameset * in) ;
59static int cr2res_obs_staring_check_inputs_validity(
60 const cpl_frameset * rawframes) ;
61static int cr2res_obs_staring_reduce(
62 const cpl_frameset * rawframes,
63 const cpl_frame * trace_wave_frame,
64 const cpl_frame * detlin_frame,
65 const cpl_frame * master_dark_frame,
66 const cpl_frame * master_flat_frame,
67 const cpl_frame * bpm_frame,
68 const cpl_frame * blaze_frame,
69 const cpl_array * slit_frac,
70 int subtract_nolight_rows,
71 int subtract_interorder_column,
72 int cosmics,
73 int extract_oversample,
74 double extract_pclip,
75 int extract_swath_width,
76 int extract_height,
77 double extract_smooth_slit,
78 double extract_smooth_spec,
79 int reduce_det,
80 hdrl_image ** combined,
81 cpl_table ** extract,
82 cpl_table ** slitfunc,
83 hdrl_image ** model,
84 cpl_propertylist ** ext_plist) ;
85static int cr2res_obs_staring_create(cpl_plugin *);
86static int cr2res_obs_staring_exec(cpl_plugin *);
87static int cr2res_obs_staring_destroy(cpl_plugin *);
88static int cr2res_obs_staring(cpl_frameset *, const cpl_parameterlist *);
89
90/*-----------------------------------------------------------------------------
91 Static variables
92 -----------------------------------------------------------------------------*/
93
94static char cr2res_obs_staring_description[] = "\
95Staring Observation \n\
96 This recipe handles staring observations. \n\
97 \n\
98 Inputs \n\
99 raw.fits " CR2RES_OBS_STARING_OTHER_RAW" [1 to n] \n\
100 or " CR2RES_OBS_STARING_JITTER_RAW" [1 to n] \n\
101 or " CR2RES_OBS_STARING_WAVE_SKY_RAW" [1 to n] \n\
102 trace.fits " CR2RES_CAL_FLAT_TW_PROCATG " [1] \n\
103 or " CR2RES_CAL_FLAT_TW_MERGED_PROCATG " \n\
104 or " CR2RES_UTIL_TRACE_TW_PROCATG " \n\
105 or " CR2RES_UTIL_WAVE_TW_PROCATG " \n\
106 or " CR2RES_CAL_WAVE_TW_PROCATG " \n\
107 or " CR2RES_UTIL_SLIT_CURV_TW_PROCATG " \n\
108 detlin.fits " CR2RES_CAL_DETLIN_COEFFS_PROCATG " [0 to 1] \n\
109 bpm.fits " CR2RES_CAL_DARK_BPM_PROCATG " [0 to 1] \n\
110 or " CR2RES_CAL_FLAT_BPM_PROCATG " \n\
111 or " CR2RES_CAL_DETLIN_BPM_PROCATG " \n\
112 or " CR2RES_UTIL_BPM_MERGE_PROCATG " \n\
113 or " CR2RES_UTIL_BPM_SPLIT_PROCATG " \n\
114 master_dark.fits " CR2RES_CAL_DARK_MASTER_PROCATG " [0 to 1] \n\
115 master_flat.fits " CR2RES_CAL_FLAT_MASTER_PROCATG " [0 to 1] \n\
116 blaze.fits " CR2RES_CAL_FLAT_EXTRACT_1D_PROCATG " [0 to 1] \n\
117 \n\
118 Outputs \n\
119 cr2res_obs_staring_slitfunc.fits "
120 CR2RES_OBS_STARING_SLITFUNC_PROCATG "\n\
121 cr2res_obs_staring_model.fits "
122 CR2RES_OBS_STARING_SLITMODEL_PROCATG "\n\
123 cr2res_obs_staring_extracted.fits "
124 CR2RES_OBS_STARING_EXTRACT_PROCATG "\n\
125 \n\
126 Algorithm \n\
127 loop on detectors d: \n\
128 call cr2res_obs_staring_reduce() \n\
129 -> combined(d) \n\
130 -> extract(d) \n\
131 -> slitfunc(d) \n\
132 -> model(d) \n\
133 Save extract \n\
134 Save slitfunc \n\
135 Save model \n\
136 \n\
137 cr2res_obs_staring_reduce() \n\
138 Load the input raw frames in an image list \n\
139 Apply the calibrations to the image list \n\
140 Collapse the image list \n\
141 Load the input trace wave \n\
142 Recompute a new trace wave with the specified slit fraction \n\
143 (--slit_frac) if needed \n\
144 Extract the spectra from the collapsed image \n\
145 -> combined \n\
146 -> extracted \n\
147 -> slit_func \n\
148 -> model_master \n\
149 Compute QC parameters \n\
150 \n\
151 Library functions used \n\
152 cr2res_io_find_TRACE_WAVE() \n\
153 cr2res_io_find_BPM() \n\
154 cr2res_obs_staring_reduce() \n\
155 cr2res_io_read_dits() \n\
156 cr2res_io_load_image_list_from_set() \n\
157 cr2res_calib_imagelist() \n\
158 cr2res_io_load_TRACE_WAVE() \n\
159 cr2res_extract_traces() \n\
160 cr2res_io_save_COMBINED() \n\
161 cr2res_io_save_EXTRACT_1D() \n\
162 cr2res_io_save_SLIT_FUNC() \n\
163";
164
165/*-----------------------------------------------------------------------------
166 Function code
167 -----------------------------------------------------------------------------*/
168
169/*----------------------------------------------------------------------------*/
179/*----------------------------------------------------------------------------*/
180int cpl_plugin_get_info(cpl_pluginlist * list)
181{
182 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe );
183 cpl_plugin * plugin = &recipe->interface;
184
185 if (cpl_plugin_init(plugin,
186 CPL_PLUGIN_API,
187 CR2RES_BINARY_VERSION,
188 CPL_PLUGIN_TYPE_RECIPE,
189 RECIPE_STRING,
190 "Staring Observation recipe",
191 cr2res_obs_staring_description,
192 CR2RES_PIPELINE_AUTHORS,
193 PACKAGE_BUGREPORT,
195 cr2res_obs_staring_create,
196 cr2res_obs_staring_exec,
197 cr2res_obs_staring_destroy)) {
198 cpl_msg_error(cpl_func, "Plugin initialization failed");
199 (void)cpl_error_set_where(cpl_func);
200 return 1;
201 }
202
203 if (cpl_pluginlist_append(list, plugin)) {
204 cpl_msg_error(cpl_func, "Error adding plugin to list");
205 (void)cpl_error_set_where(cpl_func);
206 return 1;
207 }
208
209 return 0;
210}
211
212/*----------------------------------------------------------------------------*/
220/*----------------------------------------------------------------------------*/
221static int cr2res_obs_staring_create(cpl_plugin * plugin)
222{
223 cpl_recipe * recipe ;
224 cpl_parameter * p ;
225
226 /* Check that the plugin is part of a valid recipe */
227 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
228 recipe = (cpl_recipe *)plugin;
229 else
230 return -1;
231
232 /* Create the parameters list in the cpl_recipe object */
233 recipe->parameters = cpl_parameterlist_new();
234
235 /* Fill the parameters list */
236
237 p = cpl_parameter_new_value(
238 "cr2res.cr2res_obs_staring.subtract_nolight_rows",
239 CPL_TYPE_BOOL,
240 "Subtract median row from baffled region at detector bottom",
241 "cr2res.cr2res_obs_staring", FALSE);
242 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "subtract_nolight_rows");
243 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
244 cpl_parameterlist_append(recipe->parameters, p);
245
246 p = cpl_parameter_new_value(
247 "cr2res.cr2res_obs_staring.subtract_interorder_column",
248 CPL_TYPE_BOOL,
249 "Subtract column-by-column fit to the pixel values between"
250 " spectral orders",
251 "cr2res.cr2res_obs_staring", TRUE);
252 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
253 "subtract_interorder_column");
254 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
255 cpl_parameterlist_append(recipe->parameters, p);
256
257 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.cosmics",
258 CPL_TYPE_BOOL, "Find and mark cosmic rays hits as bad",
259 "cr2res.cr2res_obs_staring", FALSE);
260 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "cosmics");
261 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
262 cpl_parameterlist_append(recipe->parameters, p);
263
264 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.slit_frac",
265 CPL_TYPE_STRING, "Wished slit fraction",
266 "cr2res.cr2res_obs_staring", "-1.0, -1.0");
267 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slit_frac");
268 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
269 cpl_parameterlist_append(recipe->parameters, p);
270
271 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.extract_oversample",
272 CPL_TYPE_INT, "factor by which to oversample the extraction",
273 "cr2res.cr2res_obs_staring", 5);
274 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "extract_oversample");
275 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
276 cpl_parameterlist_append(recipe->parameters, p);
277
278 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.extract_pclip",
279 CPL_TYPE_DOUBLE, "percentage of high and low pixels to clip on first iteration",
280 "cr2res.cr2res_obs_staring", 0.1);
281 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "extract_pclip");
282 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
283 cpl_parameterlist_append(recipe->parameters, p);
284
285 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.extract_swath_width",
286 CPL_TYPE_INT, "The swath width", "cr2res.cr2res_obs_staring", 2048);
287 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "extract_swath_width");
288 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
289 cpl_parameterlist_append(recipe->parameters, p);
290
291 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.extract_height",
292 CPL_TYPE_INT, "Extraction height",
293 "cr2res.cr2res_obs_staring", -1);
294 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "extract_height");
295 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
296 cpl_parameterlist_append(recipe->parameters, p);
297
298 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.extract_smooth_slit",
299 CPL_TYPE_DOUBLE,
300 "Smoothing along the slit (1 for high S/N, 5 for low)",
301 "cr2res.cr2res_obs_staring", 2.0);
302 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "extract_smooth_slit");
303 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
304 cpl_parameterlist_append(recipe->parameters, p);
305
306 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.extract_smooth_spec",
307 CPL_TYPE_DOUBLE, "Smoothing along the spectrum",
308 "cr2res.cr2res_obs_staring", 0.0);
309 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "extract_smooth_spec");
310 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
311 cpl_parameterlist_append(recipe->parameters, p);
312
313 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.detector",
314 CPL_TYPE_INT, "Only reduce the specified detector",
315 "cr2res.cr2res_obs_staring", 0);
316 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "detector");
317 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
318 cpl_parameterlist_append(recipe->parameters, p);
319
320 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.create_idp",
321 CPL_TYPE_BOOL, "Flag to produce IDP files",
322 "cr2res.cr2res_obs_staring", FALSE);
323 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "idp");
324 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
325 cpl_parameterlist_append(recipe->parameters, p);
326
327 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.display_order",
328 CPL_TYPE_INT, "Apply the display for the specified order",
329 "cr2res.cr2res_obs_staring", 0);
330 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "display_order");
331 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
332 cpl_parameterlist_append(recipe->parameters, p);
333
334 p = cpl_parameter_new_value("cr2res.cr2res_obs_staring.display_trace",
335 CPL_TYPE_INT, "Apply the display for the specified trace",
336 "cr2res.cr2res_obs_staring", 0);
337 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "display_trace");
338 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
339 cpl_parameterlist_append(recipe->parameters, p);
340
341 return 0;
342}
343
344/*----------------------------------------------------------------------------*/
350/*----------------------------------------------------------------------------*/
351static int cr2res_obs_staring_exec(cpl_plugin * plugin)
352{
353 cpl_recipe *recipe;
354
355 /* Get the recipe out of the plugin */
356 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
357 recipe = (cpl_recipe *)plugin;
358 else return -1;
359
360 return cr2res_obs_staring(recipe->frames, recipe->parameters);
361}
362
363/*----------------------------------------------------------------------------*/
369/*----------------------------------------------------------------------------*/
370static int cr2res_obs_staring_destroy(cpl_plugin * plugin)
371{
372 cpl_recipe *recipe;
373
374 /* Get the recipe out of the plugin */
375 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
376 recipe = (cpl_recipe *)plugin;
377 else return -1 ;
378
379 cpl_parameterlist_delete(recipe->parameters);
380 return 0 ;
381}
382
383/*----------------------------------------------------------------------------*/
390/*----------------------------------------------------------------------------*/
391static int cr2res_obs_staring(
392 cpl_frameset * frameset,
393 const cpl_parameterlist * parlist)
394{
395 const cpl_parameter * param ;
396 int subtract_nolight_rows, subtract_interorder_column,
397 extract_oversample, create_idp, cosmics,
398 extract_swath_width, extract_height, reduce_det;
399 double extract_smooth_slit, extract_smooth_spec,
400 extract_pclip, slit_low, slit_up ;
401 double barycorr;
402 cpl_array * slit_frac ;
403 cpl_frameset * rawframes ;
404 const cpl_frame * trace_wave_frame ;
405 const cpl_frame * detlin_frame ;
406 const cpl_frame * master_dark_frame ;
407 const cpl_frame * master_flat_frame ;
408 const cpl_frame * bpm_frame ;
409 const cpl_frame * blaze_frame ;
410 const char * sval ;
411 hdrl_image * combined[CR2RES_NB_DETECTORS] ;
412 cpl_table * extract[CR2RES_NB_DETECTORS] ;
413 cpl_table * slitfunc[CR2RES_NB_DETECTORS] ;
414 hdrl_image * model[CR2RES_NB_DETECTORS] ;
415 cpl_propertylist * qc_main ;
416 cpl_propertylist * ext_plist[CR2RES_NB_DETECTORS] ;
417 char * out_file;
418 cpl_table * eop_table ;
419 int det_nr;
420
421 /* RETRIEVE INPUT PARAMETERS */
422 param = cpl_parameterlist_find_const(parlist,
423 "cr2res.cr2res_obs_staring.subtract_nolight_rows");
424 subtract_nolight_rows = cpl_parameter_get_bool(param);
425 param = cpl_parameterlist_find_const(parlist,
426 "cr2res.cr2res_obs_staring.subtract_interorder_column");
427 subtract_interorder_column = cpl_parameter_get_bool(param);
428 param = cpl_parameterlist_find_const(parlist,
429 "cr2res.cr2res_obs_staring.cosmics");
430 cosmics = cpl_parameter_get_bool(param);
431 param = cpl_parameterlist_find_const(parlist,
432 "cr2res.cr2res_obs_staring.extract_oversample");
433 extract_oversample = cpl_parameter_get_int(param);
434 param = cpl_parameterlist_find_const(parlist,
435 "cr2res.cr2res_obs_staring.extract_pclip");
436 extract_pclip = cpl_parameter_get_double(param);
437 param = cpl_parameterlist_find_const(parlist,
438 "cr2res.cr2res_obs_staring.extract_swath_width");
439 extract_swath_width = cpl_parameter_get_int(param);
440 param = cpl_parameterlist_find_const(parlist,
441 "cr2res.cr2res_obs_staring.extract_height");
442 extract_height = cpl_parameter_get_int(param);
443 param = cpl_parameterlist_find_const(parlist,
444 "cr2res.cr2res_obs_staring.extract_smooth_slit");
445 extract_smooth_slit = cpl_parameter_get_double(param);
446 param = cpl_parameterlist_find_const(parlist,
447 "cr2res.cr2res_obs_staring.extract_smooth_spec");
448 extract_smooth_spec = cpl_parameter_get_double(param);
449 param = cpl_parameterlist_find_const(parlist,
450 "cr2res.cr2res_obs_staring.detector");
451 reduce_det = cpl_parameter_get_int(param);
452 param = cpl_parameterlist_find_const(parlist,
453 "cr2res.cr2res_obs_staring.create_idp");
454 create_idp = cpl_parameter_get_bool(param);
455 /*param = cpl_parameterlist_find_const(parlist,
456 "cr2res.cr2res_obs_staring.display_order");
457 disp_order = cpl_parameter_get_int(param);
458 param = cpl_parameterlist_find_const(parlist,
459 "cr2res.cr2res_obs_staring.display_trace");
460 disp_trace = cpl_parameter_get_int(param);*/
461 param = cpl_parameterlist_find_const(parlist,
462 "cr2res.cr2res_obs_staring.slit_frac");
463 sval = cpl_parameter_get_string(param) ;
464 if (sscanf(sval, "%lg,%lg", &slit_low, &slit_up) != 2) {
465 cpl_msg_error(__func__, "Invalid Slit Fraction specified");
466 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
467 return -1 ;
468 }
469
470 /* Check Parameters */
471 if (slit_low >= 0.0 && slit_up >= 0.0 && slit_low <= 1.0 && slit_up <= 1.0
472 && slit_up > slit_low) {
473 slit_frac = cpl_array_new(3, CPL_TYPE_DOUBLE) ;
474 cpl_array_set(slit_frac, 0, slit_low) ;
475 cpl_array_set(slit_frac, 1, (slit_low+slit_up)/2.0) ;
476 cpl_array_set(slit_frac, 2, slit_up) ;
477 } else {
478 slit_frac = NULL ;
479 }
480
481 /* Identify the RAW and CALIB frames in the input frameset */
482 if (cr2res_dfs_set_groups(frameset)) {
483 if (slit_frac != NULL) cpl_array_delete(slit_frac) ;
484 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
485 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
486 return -1 ;
487 }
488
489 /* Get Calibration frames */
490 trace_wave_frame = cr2res_io_find_TRACE_WAVE(frameset) ;
491 if (trace_wave_frame == NULL) {
492 if (slit_frac != NULL) cpl_array_delete(slit_frac) ;
493 cpl_msg_error(__func__, "Could not find TRACE_WAVE frame") ;
494 return -1 ;
495 }
496 detlin_frame = cpl_frameset_find_const(frameset,
497 CR2RES_CAL_DETLIN_COEFFS_PROCATG);
498 master_dark_frame = cpl_frameset_find_const(frameset,
499 CR2RES_CAL_DARK_MASTER_PROCATG) ;
500 master_flat_frame = cpl_frameset_find_const(frameset,
501 CR2RES_CAL_FLAT_MASTER_PROCATG) ;
502 bpm_frame = cr2res_io_find_BPM(frameset) ;
503 blaze_frame = cpl_frameset_find_const(frameset,
504 CR2RES_CAL_FLAT_EXTRACT_1D_PROCATG) ;
505
506 /* Get the RAW Frames */
507 rawframes = cr2res_obs_staring_find_RAW(frameset) ;
508 if (rawframes == NULL) {
509 if (slit_frac != NULL) cpl_array_delete(slit_frac) ;
510 cpl_msg_error(__func__, "Could not find RAW frames") ;
511 return -1 ;
512 }
513
514 /* Loop on the detectors */
515 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
516 /* Initialise */
517 combined[det_nr-1] = NULL ;
518 extract[det_nr-1] = NULL ;
519 slitfunc[det_nr-1] = NULL ;
520 model[det_nr-1] = NULL ;
521 ext_plist[det_nr-1] = NULL ;
522
523 /* Compute only one detector */
524 if (reduce_det != 0 && det_nr != reduce_det) continue ;
525
526 cpl_msg_info(__func__, "Process Detector %d", det_nr) ;
527 cpl_msg_indent_more() ;
528
529 /* Call the reduction function */
530 if (cr2res_obs_staring_reduce(rawframes,
531 trace_wave_frame, detlin_frame, master_dark_frame,
532 master_flat_frame, bpm_frame, blaze_frame, slit_frac,
533 subtract_nolight_rows, subtract_interorder_column,
534 cosmics, extract_oversample, extract_pclip,
535 extract_swath_width, extract_height, extract_smooth_slit,
536 extract_smooth_spec, det_nr,
537 &(combined[det_nr-1]),
538 &(extract[det_nr-1]),
539 &(slitfunc[det_nr-1]),
540 &(model[det_nr-1]),
541 &(ext_plist[det_nr-1])) == -1) {
542 cpl_msg_warning(__func__, "Failed to reduce detector %d", det_nr);
543 cpl_error_reset() ;
544 cpl_msg_indent_less() ;
545 }
546 cpl_msg_indent_less() ;
547 }
548 if (slit_frac != NULL) cpl_array_delete(slit_frac) ;
549
550 /* Save Products */
551
552 /* Add ESO.DRS.TMID in the Main Header */
553 qc_main = cpl_propertylist_new();
554 cpl_propertylist_append_double(qc_main,
555 CR2RES_HEADER_DRS_TMID,
556 cr2res_utils_get_center_mjd(rawframes)) ;
557
558 /* Add barycentric correction */
559 eop_table = cr2res_io_get_eop_table() ;
560 if (eop_table != NULL) {
561 double ra, dec, mjd_obs, geolon, geolat, geoelev;
562 cpl_propertylist *plist;
563 plist=cpl_propertylist_load(cpl_frame_get_filename(
564 cpl_frameset_get_position_const(rawframes, 0)), 0) ;
565
566 ra = cpl_propertylist_get_double(plist, "RA") ;
567 dec = cpl_propertylist_get_double(plist, "DEC") ;
568 mjd_obs = cpl_propertylist_get_double(plist, "MJD-OBS") ;
569 geolon = cpl_propertylist_get_double(plist, "ESO TEL GEOLON") ;
570 geolat = cpl_propertylist_get_double(plist, "ESO TEL GEOLAT") ;
571 geoelev = cpl_propertylist_get_double(plist, "ESO TEL GEOELEV") ;
572
573 cpl_propertylist_delete(plist) ;
574
575 barycorr = 0.0 ;
576 if (!cpl_error_get_code()) {
577 double mjd_cen;
578 mjd_cen = cr2res_utils_get_center_mjd(rawframes) ;
579 hdrl_barycorr_compute(ra, dec, eop_table, mjd_obs,
580 (mjd_cen-mjd_obs)*24*3600, geolon, geolat, geoelev,
581 0.0, 0.0, 0.0, 0.0, &barycorr);
582
583 cpl_msg_info(__func__, "Barycentric correction: %g m/s",
584 barycorr);
585 }
586 else {
587 cpl_msg_info(__func__, "Cannot derive Barycentric correction");
588 cpl_error_reset() ;
589 }
590 cpl_table_delete(eop_table) ;
591 cpl_propertylist_append_double(qc_main, CR2RES_HEADER_DRS_BARYCORR,
592 barycorr);
593 }
594
595 /* Add QC NUMSAT */
596 cpl_propertylist_append_int(qc_main,
597 CR2RES_HEADER_QC_NUMSAT,
598 cr2res_qc_numsat(rawframes)) ;
599
600 /* Save only the used RAW - fill raw_one_angle with CALIBS */
601 if (trace_wave_frame != NULL)
602 cpl_frameset_insert(rawframes,
603 cpl_frame_duplicate(trace_wave_frame)) ;
604 if (detlin_frame != NULL)
605 cpl_frameset_insert(rawframes,
606 cpl_frame_duplicate(detlin_frame)) ;
607 if (master_dark_frame != NULL)
608 cpl_frameset_insert(rawframes,
609 cpl_frame_duplicate(master_dark_frame)) ;
610 if (master_flat_frame!= NULL)
611 cpl_frameset_insert(rawframes,
612 cpl_frame_duplicate(master_flat_frame)) ;
613 if (bpm_frame!= NULL)
614 cpl_frameset_insert(rawframes,
615 cpl_frame_duplicate(bpm_frame)) ;
616 if (blaze_frame!= NULL)
617 cpl_frameset_insert(rawframes,
618 cpl_frame_duplicate(blaze_frame)) ;
619
620 out_file = cpl_sprintf("%s_combined.fits", RECIPE_STRING) ;
621 cr2res_io_save_COMBINED(out_file, frameset, rawframes, parlist,
622 combined, qc_main, ext_plist,
623 CR2RES_OBS_STARING_COMBINED_PROCATG, RECIPE_STRING) ;
624 cpl_free(out_file);
625
626 out_file = cpl_sprintf("%s_slitfunc.fits", RECIPE_STRING) ;
627 cr2res_io_save_SLIT_FUNC(out_file, frameset, rawframes, parlist,
628 slitfunc, qc_main, ext_plist, CR2RES_OBS_STARING_SLITFUNC_PROCATG,
629 RECIPE_STRING) ;
630 cpl_free(out_file);
631
632 out_file = cpl_sprintf("%s_model.fits", RECIPE_STRING) ;
633 cr2res_io_save_SLIT_MODEL(out_file, frameset, rawframes, parlist,
634 model, qc_main, ext_plist, CR2RES_OBS_STARING_SLITMODEL_PROCATG,
635 RECIPE_STRING) ;
636 cpl_free(out_file);
637
638 out_file = cpl_sprintf("%s_extracted.fits", RECIPE_STRING) ;
639 cr2res_io_save_EXTRACT_1D(out_file, frameset, rawframes, parlist, extract,
640 qc_main, ext_plist, CR2RES_OBS_STARING_EXTRACT_PROCATG,
641 RECIPE_STRING);
642 if (create_idp) {
643 cr2res_idp_save(out_file, frameset, rawframes, parlist,
644 extract, qc_main, ext_plist,
645 CR2RES_OBS_STARING_IDP_PROCATG,
646 RECIPE_STRING) ;
647 }
648 cpl_free(out_file);
649 cpl_frameset_delete(rawframes) ;
650
651 /* Free */
652 cpl_propertylist_delete(qc_main) ;
653 for (det_nr=1 ; det_nr<=CR2RES_NB_DETECTORS ; det_nr++) {
654 if (combined[det_nr-1] != NULL)
655 hdrl_image_delete(combined[det_nr-1]) ;
656 if (extract[det_nr-1] != NULL)
657 cpl_table_delete(extract[det_nr-1]) ;
658 if (slitfunc[det_nr-1] != NULL)
659 cpl_table_delete(slitfunc[det_nr-1]) ;
660 if (model[det_nr-1] != NULL)
661 hdrl_image_delete(model[det_nr-1]) ;
662 if (ext_plist[det_nr-1] != NULL)
663 cpl_propertylist_delete(ext_plist[det_nr-1]) ;
664 }
665
666 return (int)cpl_error_get_code();
667}
668
669/*----------------------------------------------------------------------------*/
694/*----------------------------------------------------------------------------*/
695static int cr2res_obs_staring_reduce(
696 const cpl_frameset * rawframes,
697 const cpl_frame * trace_wave_frame,
698 const cpl_frame * detlin_frame,
699 const cpl_frame * master_dark_frame,
700 const cpl_frame * master_flat_frame,
701 const cpl_frame * bpm_frame,
702 const cpl_frame * blaze_frame,
703 const cpl_array * slit_frac,
704 int subtract_nolight_rows,
705 int subtract_interorder_column,
706 int cosmics,
707 int extract_oversample,
708 double extract_pclip,
709 int extract_swath_width,
710 int extract_height,
711 double extract_smooth_slit,
712 double extract_smooth_spec,
713 int reduce_det,
714 hdrl_image ** combined,
715 cpl_table ** extract,
716 cpl_table ** slitfunc,
717 hdrl_image ** model,
718 cpl_propertylist ** ext_plist)
719{
720 hdrl_imagelist * in ;
721 hdrl_imagelist * in_calib ;
722 cpl_vector * dits ;
723 cpl_vector * ndits ;
724 cpl_table * blaze_table ;
725 cpl_table * trace_wave ;
726 cpl_table * trace_wave_new ;
727 hdrl_image * collapsed ;
728 cpl_image * contrib ;
729 cpl_propertylist * plist ;
730 cpl_size i ;
731 hdrl_image * model_master ;
732 cpl_table * slit_func ;
733 cpl_table * extracted ;
734 int * order_idx_values ;
735 double * qc_snrs ;
736 cpl_array * fwhm_array ;
737 char * key_name ;
738 const char * first_fname ;
739 double qc_signal, qc_fwhm, gain, error_factor, blaze_norm ;
740 int order_zp, nb_order_idx_values,
741 order_idx, order_idxp ;
742
743 /* Check Inputs */
744 if (combined == NULL || extract == NULL || ext_plist == NULL ||
745 rawframes == NULL || trace_wave_frame == NULL) return -1 ;
746
747 /* Get the Gain */
748 if (reduce_det == 1) gain = CR2RES_GAIN_CHIP1 ;
749 else if (reduce_det == 2) gain = CR2RES_GAIN_CHIP2 ;
750 else if (reduce_det == 3) gain = CR2RES_GAIN_CHIP3 ;
751 else {
752 cpl_msg_error(__func__, "Failed to get the Gain value") ;
753 return -1 ;
754 }
755
756 /* Check raw frames consistency */
757 if (cr2res_obs_staring_check_inputs_validity(rawframes) != 1) {
758 cpl_msg_error(__func__, "Invalid Inputs") ;
759 return -1 ;
760 }
761
762 /* Initialise */
763 first_fname = cpl_frame_get_filename(
764 cpl_frameset_get_position_const(rawframes, 0)) ;
765
766 /* Get the order zeropoint */
767 if ((plist = cpl_propertylist_load(cpl_frame_get_filename(trace_wave_frame),
768 0)) == NULL) {
769 cpl_msg_error(__func__, "Cannot read the ORDER_ZP from the input TW") ;
770 return -1 ;
771 }
772 order_zp = cr2res_pfits_get_order_zp(plist) ;
773 cpl_propertylist_delete(plist) ;
774 if (cpl_error_get_code()) {
775 cpl_msg_error(__func__, "Missing ORDER_ZP in the header - Skip") ;
776 cpl_error_reset() ;
777 /* Negative Zerop to log the fact that it is missing */
778 order_zp = -100 ;
779 }
780
781 /* Load the DITs if necessary */
782 if (master_dark_frame != NULL) dits = cr2res_io_read_dits(rawframes) ;
783 else dits = NULL ;
784 if (cpl_msg_get_level() == CPL_MSG_DEBUG && dits != NULL)
785 cpl_vector_dump(dits, stdout) ;
786
787 /* Load NDITs */
788 ndits = cr2res_io_read_ndits(rawframes) ;
789
790 /* Load image list */
791 if ((in = cr2res_io_load_image_list_from_set(rawframes,
792 reduce_det)) == NULL) {
793 cpl_msg_error(__func__, "Cannot load images") ;
794 if (dits != NULL) cpl_vector_delete(dits) ;
795 return -1 ;
796 }
797 if (hdrl_imagelist_get_size(in) != cpl_frameset_get_size(rawframes)) {
798 cpl_msg_error(__func__, "Inconsistent number of loaded images") ;
799 if (dits != NULL) cpl_vector_delete(dits) ;
801 return -1 ;
802 }
803
804 /* Set the error factor. */
805 error_factor = gain * cpl_vector_get(ndits, 0) *
806 cpl_frameset_get_size(rawframes) ;
807
808 for (i=0; i<cpl_vector_get_size(ndits); i++){
809 if (cpl_vector_get(ndits,i) != cpl_vector_get(ndits, 0))
810 cpl_msg_warning(__func__, "Raw frames have different NDIT! "
811 "Error spectrum will likely be scaled incorrectly.");
812 }
813
814 /* Calibrate the images */
815 if ((in_calib = cr2res_calib_imagelist(in, reduce_det, 0,
816 subtract_nolight_rows, subtract_interorder_column, cosmics,
817 master_flat_frame, master_dark_frame, bpm_frame, detlin_frame,
818 dits, ndits))==NULL) {
819 cpl_msg_error(__func__, "Failed to apply the calibrations") ;
820 if (dits != NULL) cpl_vector_delete(dits) ;
821 if (ndits != NULL) cpl_vector_delete(ndits) ;
823 return -1 ;
824 }
826 if (dits != NULL) cpl_vector_delete(dits) ;
827 if (ndits != NULL) cpl_vector_delete(ndits) ;
828
829 /* Collapse the image list */
830 cpl_msg_info(__func__, "Collapse") ;
831 cpl_msg_indent_more() ;
832 if (hdrl_imagelist_collapse_mean(in_calib, &collapsed, &contrib) !=
833 CPL_ERROR_NONE) {
834 cpl_msg_error(__func__, "Failed to Collapse") ;
835 hdrl_imagelist_delete(in_calib) ;
836 cpl_msg_indent_less() ;
837 return -1 ;
838 }
839 cpl_image_delete(contrib) ;
840 hdrl_imagelist_delete(in_calib) ;
841 cpl_msg_indent_less() ;
842
843 /* Load the trace wave */
844 cpl_msg_info(__func__, "Load the TRACE WAVE") ;
845 if ((trace_wave = cr2res_io_load_TRACE_WAVE(cpl_frame_get_filename(
846 trace_wave_frame), reduce_det)) == NULL) {
847 cpl_msg_error(__func__, "Failed to Load the traces file") ;
848 hdrl_image_delete(collapsed) ;
849 return -1 ;
850 }
851
852 /* Extract at the specified slit fraction */
853 if (slit_frac != NULL) {
854 if ((trace_wave_new = cr2res_trace_new_slit_fraction(
855 trace_wave, slit_frac)) == NULL) {
856 cpl_msg_warning(__func__,
857 "Failed to compute the traces for user specified slit fraction") ;
858 cpl_error_reset() ;
859 } else {
860 cpl_table_delete(trace_wave) ;
861 trace_wave = trace_wave_new ;
862 trace_wave_new = NULL ;
863 }
864 }
865
866 /* Load Blaze */
867 blaze_table = NULL ;
868 blaze_norm = 0;
869 if (blaze_frame != NULL) {
870 cpl_msg_info(__func__, "Load the BLAZE") ;
871 if ((blaze_table = cr2res_io_load_EXTRACT_1D(cpl_frame_get_filename(
872 blaze_frame), reduce_det)) == NULL) {
873 cpl_msg_error(__func__, "Failed to Load the Blaze file") ;
874 hdrl_image_delete(collapsed) ;
875 cpl_table_delete(trace_wave) ;
876 return -1 ;
877 }
878 cpl_propertylist * blaze_plist ;
879 blaze_plist = cpl_propertylist_load_regexp(cpl_frame_get_filename(
880 blaze_frame),0,CR2RES_HEADER_QC_BLAZE_NORM,0);
881 if(cpl_propertylist_get_size(blaze_plist)>0){
882 blaze_norm = cpl_propertylist_get_double(blaze_plist, CR2RES_HEADER_QC_BLAZE_NORM);
883 }
884 else {
885 blaze_norm = -1;
886 cpl_msg_warning(__func__, "QC BLAZE NORM value not found, reverting to per trace normalization") ;
887 }
888 if(blaze_plist!=NULL){
889 cpl_propertylist_delete(blaze_plist);
890 }
891 }
892
893 /* TODO, make parameters */
894 int extract_niter = 10;
895 double extract_kappa = 10;
896
897 /* Execute the extraction */
898 cpl_msg_info(__func__, "Spectra Extraction") ;
899 if (cr2res_extract_traces(collapsed, trace_wave, NULL, blaze_table, blaze_norm, -1, -1,
900 CR2RES_EXTR_OPT_CURV, extract_height, extract_swath_width,
901 extract_oversample, extract_pclip, extract_smooth_slit, extract_smooth_spec,
902 extract_niter, extract_kappa, error_factor,
903 0, 0, 0, &extracted, &slit_func, &model_master) == -1) {
904 cpl_msg_error(__func__, "Failed to extract");
905 hdrl_image_delete(collapsed) ;
906 cpl_table_delete(trace_wave) ;
907 return -1 ;
908 }
909 if (blaze_table != NULL) cpl_table_delete(blaze_table) ;
910
911 /* Store the extension header for product saving */
912 plist = cpl_propertylist_load(first_fname,
913 cr2res_io_get_ext_idx(first_fname, reduce_det, 1)) ;
914
915 /* QC - Signal and FWHM */
916 qc_signal = cr2res_qc_obs_nodding_signal(extracted) ;
917 cpl_propertylist_append_double(plist, CR2RES_HEADER_QC_SIGNAL, qc_signal) ;
918
919 /* QC - SNR */
920 qc_snrs = cr2res_qc_snr(trace_wave, extracted, &order_idx_values,
921 &nb_order_idx_values) ;
922 for (i=0 ; i<nb_order_idx_values ; i++) {
923 order_idx = order_idx_values[i] ;
924 order_idxp = cr2res_io_convert_order_idx_to_idxp(order_idx) ;
925 key_name = cpl_sprintf(CR2RES_HEADER_QC_SNR, order_idxp) ;
926 cpl_propertylist_append_double(plist, key_name, qc_snrs[i]) ;
927 cpl_free(key_name) ;
928 }
929 cpl_free(order_idx_values) ;
930 cpl_free(qc_snrs) ;
931
932 /* Get the order numbers from the TW rows */
933 order_idx_values = cr2res_trace_get_order_idx_values(trace_wave,
934 &nb_order_idx_values);
935
936 /* QC - SLIT FWHM */
937 fwhm_array = cpl_array_new(nb_order_idx_values, CPL_TYPE_DOUBLE);
938 for (i=0 ; i<nb_order_idx_values ; i++) {
939 order_idx = order_idx_values[i] ;
940 order_idxp = cr2res_io_convert_order_idx_to_idxp(order_idx) ;
941 qc_fwhm = cr2res_qc_obs_slit_psf(slit_func, order_idxp,
942 extract_oversample);
943
944 key_name = cpl_sprintf(CR2RES_HEADER_QC_SLITFWHM_ORDER, order_idxp) ;
945 cpl_propertylist_append_double(plist, key_name, qc_fwhm) ;
946 cpl_free(key_name) ;
947 cpl_array_set(fwhm_array, i, qc_fwhm) ;
948 }
949 cpl_free(order_idx_values) ;
950 qc_fwhm = cpl_array_get_median(fwhm_array);
951 cpl_propertylist_append_double(plist, CR2RES_HEADER_QC_SLITFWHM_MED,
952 qc_fwhm) ;
953 if (qc_fwhm < 3.5) {
954 cpl_msg_warning(__func__, "Median FWHM of the PSF along the slit "
955 "is %gpix, i.e. below the slit width. This means the slit "
956 "is likely not evenly filled with light "
957 "in the spectral direction. This can result in a "
958 "wavelength offset between different positions along the slit,"
959 " and with respect to calibrations."
960 , qc_fwhm);
961 }
962
963 cpl_array_delete(fwhm_array) ;
964
965 /* QC - Real Orders */
966 if (order_zp > 0) {
967 /* Get the order numbers from the TW rows */
968 order_idx_values = cr2res_trace_get_order_idx_values(trace_wave,
969 &nb_order_idx_values);
970
971 /* Compute the Real Order numbers and store them in QCs */
972 for (i = 0; i < nb_order_idx_values; i++) {
973 int order_real;
974 order_idx = order_idx_values[i] ;
975 order_idxp = cr2res_io_convert_order_idx_to_idxp(order_idx) ;
976 order_real = cr2res_order_idx_to_real(order_idx, order_zp) ;
977 key_name = cpl_sprintf(CR2RES_HEADER_QC_REAL_ORDER, order_idxp) ;
978 cpl_propertylist_append_int(plist, key_name, order_real) ;
979 cpl_free(key_name) ;
980 }
981 cpl_free(order_idx_values) ;
982 }
983 cpl_table_delete(trace_wave) ;
984
985 /* Return */
986 *combined = collapsed ;
987 *extract = extracted ;
988 *slitfunc = slit_func ;
989 *model = model_master ;
990 *ext_plist = plist ;
991
992 return 0 ;
993}
994
995/*----------------------------------------------------------------------------*/
1001/*----------------------------------------------------------------------------*/
1002static int cr2res_obs_staring_check_inputs_validity(
1003 const cpl_frameset * rawframes)
1004{
1005 /* Check Inputs */
1006 if (rawframes == NULL) return -1 ;
1007 return 1 ;
1008}
1009
1010/*----------------------------------------------------------------------------*/
1019/*----------------------------------------------------------------------------*/
1020static cpl_frameset * cr2res_obs_staring_find_RAW(
1021 const cpl_frameset * in)
1022{
1023 cpl_frameset * out ;
1024
1025 /* Check entries */
1026 if (in == NULL) return NULL ;
1027
1028 out = cr2res_extract_frameset(in, CR2RES_OBS_STARING_OTHER_RAW) ;
1029 if (out == NULL) {
1030 out = cr2res_extract_frameset(in, CR2RES_OBS_STARING_JITTER_RAW) ;
1031 }
1032 if (out == NULL) {
1033 out = cr2res_extract_frameset(in, CR2RES_OBS_STARING_WAVE_SKY_RAW) ;
1034 }
1035 return out ;
1036}
1037
hdrl_imagelist * cr2res_calib_imagelist(const hdrl_imagelist *in, int chip, int clean_bad, int subtract_nolight_rows, int subtract_interorder_column, int cosmics_corr, const cpl_frame *flat, const cpl_frame *dark, const cpl_frame *bpm, const cpl_frame *detlin, const cpl_vector *dits, const cpl_vector *ndits)
The images calibration routine for a given chip on a list.
Definition: cr2res_calib.c:71
cpl_error_code cr2res_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: cr2res_dfs.c:53
int cr2res_extract_traces(const hdrl_image *img, const cpl_table *traces, const cpl_table *slit_func_in, const cpl_table *blaze_table_in, float blaze_norm, int reduce_order, int reduce_trace, cr2res_extr_method extr_method, int extr_height, int swath_width, int oversample, double pclip, double smooth_slit, double smooth_spec, int niter, double kappa, double error_factor, int display, int disp_order_idx, int disp_trace, cpl_table **extracted, cpl_table **slit_func, hdrl_image **model_master)
Extracts all the passed traces at once.
int cr2res_idp_save(const char *filename, cpl_frameset *allframes, cpl_frameset *rawframes, const cpl_parameterlist *parlist, cpl_table **tables, cpl_propertylist *main_qc_plist, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save an IDP file.
Definition: cr2res_idp.c:98
cpl_table * cr2res_io_load_EXTRACT_1D(const char *filename, int detector)
Load a table from a EXTRACT_1D.
Definition: cr2res_io.c:1296
const cpl_frame * cr2res_io_find_BPM(const cpl_frameset *in)
Get the first CR2RES_BPM_DRSTYPE frame from a frameset.
Definition: cr2res_io.c:369
int cr2res_io_save_SLIT_MODEL(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a SLIT_MODEL.
Definition: cr2res_io.c:1823
const cpl_frame * cr2res_io_find_TRACE_WAVE(const cpl_frameset *in)
Get the first CR2RES_TW_DRSTYPE frame from a frameset.
Definition: cr2res_io.c:231
int cr2res_io_convert_order_idx_to_idxp(int order_idx)
Convert the order_idx to the order_idxp.
Definition: cr2res_io.c:583
cpl_vector * cr2res_io_read_dits(const cpl_frameset *in)
Get the DITS from a frame set.
Definition: cr2res_io.c:432
int cr2res_io_save_EXTRACT_1D(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table **tables, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a 1D extracted spectrum.
Definition: cr2res_io.c:1732
hdrl_imagelist * cr2res_io_load_image_list_from_set(const cpl_frameset *in, int detector)
Load an hdrl image list from an images frameset.
Definition: cr2res_io.c:808
cpl_table * cr2res_io_get_eop_table()
Get the eop_table.
Definition: cr2res_io.c:120
int cr2res_io_get_ext_idx(const char *filename, int detector, int data)
Get the wished extension number for a detector.
Definition: cr2res_io.c:644
int cr2res_io_save_SLIT_FUNC(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_table **slit_func, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a SLIT_FUNC.
Definition: cr2res_io.c:1792
int cr2res_io_save_COMBINED(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **data, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a COMBINED.
Definition: cr2res_io.c:1854
cpl_table * cr2res_io_load_TRACE_WAVE(const char *filename, int detector)
Load a table from a TRACE_WAVE.
Definition: cr2res_io.c:1109
cpl_vector * cr2res_io_read_ndits(const cpl_frameset *in)
Get the NDITs from a frame set.
Definition: cr2res_io.c:462
int cr2res_qc_numsat(const cpl_frameset *frameset)
Calculate the number of saturated pixels.
Definition: cr2res_qc.c:1290
double cr2res_qc_obs_nodding_signal(const cpl_table *extracted)
Computes the integrated flux over part of the spectrum.
Definition: cr2res_qc.c:845
double * cr2res_qc_snr(const cpl_table *tw, const cpl_table *extracted, int **out_order_idx_values, int *out_nb_order_idx_values)
Computes the SNR of several spectra.
Definition: cr2res_qc.c:1010
double cr2res_qc_obs_slit_psf(const cpl_table *slitfu, int order_idxp, int oversample)
Computes the FWHM of the PSF along the slit for a given order.
Definition: cr2res_qc.c:1208
cpl_table * cr2res_trace_new_slit_fraction(const cpl_table *traces, const cpl_array *new_slit_fraction)
Recompute the traces at a newly specified slit fraction.
int * cr2res_trace_get_order_idx_values(const cpl_table *trace, int *nb_order_idx_values)
Count and return the different order_idx values from a TW table.
Definition: cr2res_trace.c:431
int cr2res_order_idx_to_real(int order_idx, int order_zp)
Convert the order_idx into order_real.
Definition: cr2res_utils.c:89
double cr2res_utils_get_center_mjd(const cpl_frameset *frameset)
Calculate the middle of the exposures in the frameset.
cpl_frameset * cr2res_extract_frameset(const cpl_frameset *in, const char *tag)
Extract the frames with the given tag from a frameset.
const char * cr2res_get_license(void)
Get the pipeline copyright and license.
cpl_error_code hdrl_barycorr_compute(double ra, double dec, const cpl_table *eop_table, double mjdobs, double time_to_mid_exposure, double longitude, double latitude, double elevation, double pressure, double temperature, double humidity, double wavelength, double *barycorr)
Derives the barycentric correction using the erfa function eraApco13(). The latter For a terrestrial ...
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
Definition: hdrl_image.c:379
cpl_error_code hdrl_imagelist_collapse_mean(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Mean collapsing of image list.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.