MOONS Pipeline Reference Manual 0.13.2
moons_standard.c
1/*
2 * This file is part of the MOONS Pipeline
3 * Copyright (C) 2002-2016 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include "moo_utils.h"
29#include "moo_pfits.h"
30#include "moo_dfs.h"
31#include "moo_params.h"
32#include "moo_drl.h"
33#include "moo_products.h"
34#include "moo_correct_tell.h"
35#include "moo_molecfit.h"
36#include "moo_molectable.h"
37#include <cpl.h>
38#include <string.h>
39
40/*-----------------------------------------------------------------------------
41 Plugin registration
42 -----------------------------------------------------------------------------*/
43
44int cpl_plugin_get_info(cpl_pluginlist *list);
45
46/*-----------------------------------------------------------------------------
47 Private function prototypes
48 -----------------------------------------------------------------------------*/
49
50static int _moons_standard_create(cpl_plugin *plugin);
51static int _moons_standard_exec(cpl_plugin *plugin);
52static int _moons_standard_destroy(cpl_plugin *plugin);
53static int
54_moons_standard(cpl_frameset *frameset, const cpl_parameterlist *parlist);
55
56/*-----------------------------------------------------------------------------
57 Static variables
58 -----------------------------------------------------------------------------*/
59
60static const char *const _moons_standard_description =
61 "Produces the instrumental response for relative flux calibration, and "
62 "the telluric absorption spectrum.\n"
63 "INPUT FRAMES\n"
64 " * flux or telluric standard star n>=3 file(s) (RAW) with tag STD_FLUX "
65 "or STD_TELL : "
66 "standard star file\n"
67 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag BP_MAP_RP "
68 ": "
69 "cosmetic bad pixel map\n"
70 " * [OPTIONAL] NonLinearityBadPixMask 1 file (QUA) with tag BP_MAP_NL "
71 ": "
72 "cosmetic bad pixel map coming from linearity recipe\n"
73 " * MasterBias 1 file (DET) with tag "
74 "MASTER_BIAS : "
75 "master bias file\n"
76 " * MasterDarkNir 1 file (DET) with tag "
77 "MASTER_DARK_NIR : "
78 "master dark nir file\n"
79 " * [OPTIONAL]MasterDarkVis 1 file (DET) with tag "
80 "MASTER_DARK_VIS : "
81 "master dark vis file\n"
82 " * [OPTIONAL] CoeffsCube 1 file (3D) with tag "
83 "LINEARITY_COEFF_CUBE : "
84 "coefficients to correct pixels detector linearity\n"
85 " * [OPTIONAL] P2pMap 1 file (DET) with tag P2P_MAP : "
86 "pixel to pixel map\n"
87 " * LocTab 1 file (LOC) with tag FF_TRACE : "
88 "the localisation table\n"
89 " * Ffext 1 file (EXT) with tag "
90 "FF_EXTSPECTRA : "
91 "the extracted flat field\n"
92 " * F2f 1 file (F2F) with tag F2F_TABLE "
93 ": "
94 "the fibre-to-fibre relative response\n"
95 " * SFormat 1 file (FMT) with tag "
96 "SPECTRAL_FORMAT : "
97 "the spectral format table\n"
98 " * [OPTIONAL] MasterFlat 1 file (PSF) with tag "
99 "MASTER_FLAT : "
100 "the master flat used for optimal extraction\n"
101 " * WaveMap 1 file (WMAP) with tag WAVE_MAP "
102 ": "
103 "the wavelength map\n"
104 " * fluxStdCat 1 file (FLX) with tag "
105 "FLUX_STD_CAT : "
106 "the standard star flux table\n"
107 " * atmosExt 1 file (ATMO) with tag ATMOS_EXT "
108 ": "
109 "the atmospheric extinction table\n"
110 " * SkyLines 1 file (CAT) with tag "
111 "SKY_LINE_LIST : "
112 "the sky lines list table\n"
113 " * [STDTELL only] file (MOLECULES) with tag MOLECULES 1 file : "
114 "molecules list file\n"
115 "PRODUCTS\n"
116 " * STD_EXTSPECTRA_i_[insmode].fits (EXT) with tag STD_EXTSPECTRA : "
117 "Science product individual extracted frames\n"
118 " * STD_RBNSPECTRA_i_[insmode].fits (RBN) with tag STD_RBNSPECTRA : "
119 "Science product individual calibrated frames\n"
120 " * STD_SKSSPECTRA_[insmode]_i.fits (SCI) with tag STD_SKSSPECTRA : "
121 "Science product individual sky subtracted frames\n"
122 " * STD_SKSSPECTRA_[insmode].fits (SCI) with tag STD_SKSSPECTRA : "
123 "Science product flux calibrated frame\n"
124 " * RESPONSE_[insmode].fits (RESP) with tag RESPONSE : "
125 "Instrumental response product\n"
126 " * TELLURIC_[insmode].fits (TELLURIC) with tag TELLURIC : "
127 "Telluric product\n"
128 " * GDAS User GDAS profile"
129 " * GDAS_BEFORE If ESO DB GDAS is used, file before the MJD-OBS"
130 " * GDAS_AFTER If ESO DB GDAS is used, file after the MJD-OBS"
131 "\n";
132
133/*-----------------------------------------------------------------------------
134 Function code
135 -----------------------------------------------------------------------------*/
136
137/*----------------------------------------------------------------------------*/
147/*----------------------------------------------------------------------------*/
148
149int
150cpl_plugin_get_info(cpl_pluginlist *list)
151{
152 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
153 cpl_plugin *plugin = &recipe->interface;
154
155 if (cpl_plugin_init(plugin, CPL_PLUGIN_API, MOONS_BINARY_VERSION,
156 CPL_PLUGIN_TYPE_RECIPE, "moons_standard",
157 "Produces the instrumental response for relative flux "
158 "calibration, and the telluric absorption spectrum.",
159 _moons_standard_description, "Regis Haigron",
160 PACKAGE_BUGREPORT, moo_get_license(),
161 _moons_standard_create, _moons_standard_exec,
162 _moons_standard_destroy)) {
163 cpl_msg_error(cpl_func, "Plugin initialization failed");
164 (void)cpl_error_set_where(cpl_func);
165 return 1;
166 }
167
168 if (cpl_pluginlist_append(list, plugin)) {
169 cpl_msg_error(cpl_func, "Error adding plugin to list");
170 (void)cpl_error_set_where(cpl_func);
171 return 1;
172 }
173
174 return 0;
175}
176
177
178/*----------------------------------------------------------------------------*/
186/*----------------------------------------------------------------------------*/
187
188static int
189_moons_standard_create(cpl_plugin *plugin)
190{
191 cpl_recipe *recipe;
192
193 /* Do not create the recipe if an error code is already set */
194 if (cpl_error_get_code() != CPL_ERROR_NONE) {
195 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
196 cpl_func, __LINE__, cpl_error_get_where());
197 return (int)cpl_error_get_code();
198 }
199
200 if (plugin == NULL) {
201 cpl_msg_error(cpl_func, "Null plugin");
202 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
203 }
204
205 /* Verify plugin type */
206 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
207 cpl_msg_error(cpl_func, "Plugin is not a recipe");
208 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
209 }
210
211 /* Get the recipe */
212 recipe = (cpl_recipe *)plugin;
213
214 /* Create the parameters list in the cpl_recipe object */
215 recipe->parameters = cpl_parameterlist_new();
216 if (recipe->parameters == NULL) {
217 cpl_msg_error(cpl_func, "Parameter list allocation failed");
218 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
219 }
220
221 moo_params *params = moo_params_new("moons", "moons_standard");
222
223 /* Fill the parameters list */
224 moo_params_add_keep_temp(params, recipe->parameters);
225 moo_params_add_prepare(params, recipe->parameters);
226 moo_params_add_correct_bias(params, recipe->parameters,
227 MOO_CORRECT_BIAS_METHOD_MASTER);
228 moo_params_add_crh(params, recipe->parameters, MOO_CRH_METHOD_MEDIAN);
229 moo_params_add_extract(params, recipe->parameters);
230 moo_params_add_rebin(params, recipe->parameters);
231 moo_params_add_target_table(params, recipe->parameters, CPL_TRUE);
232 moo_params_add_sub_sky_stare(params, recipe->parameters);
233 moo_params_add_compute_resp(params, recipe->parameters);
234 moo_params_add_coadd(params, recipe->parameters);
235 moo_params_add_molecfit_model(params, recipe->parameters);
236 moo_params_delete(params);
237
238 return 0;
239}
240
241
242/*----------------------------------------------------------------------------*/
248/*----------------------------------------------------------------------------*/
249
250static int
251_moons_standard_exec(cpl_plugin *plugin)
252{
253 cpl_recipe *recipe;
254 int recipe_status;
255 cpl_errorstate initial_errorstate = cpl_errorstate_get();
256
257 /* Return immediately if an error code is already set */
258 if (cpl_error_get_code() != CPL_ERROR_NONE) {
259 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
260 cpl_func, __LINE__, cpl_error_get_where());
261 return (int)cpl_error_get_code();
262 }
263
264 if (plugin == NULL) {
265 cpl_msg_error(cpl_func, "Null plugin");
266 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
267 }
268
269 /* Verify plugin type */
270 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
271 cpl_msg_error(cpl_func, "Plugin is not a recipe");
272 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
273 }
274
275 /* Get the recipe */
276 recipe = (cpl_recipe *)plugin;
277
278 /* Verify parameter and frame lists */
279 if (recipe->parameters == NULL) {
280 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
281 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
282 }
283 if (recipe->frames == NULL) {
284 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
285 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
286 }
287
288 /* Invoke the recipe */
289 recipe_status = _moons_standard(recipe->frames, recipe->parameters);
290
291 /* Ensure DFS-compliance of the products */
292 if (cpl_dfs_update_product_header(recipe->frames)) {
293 if (!recipe_status)
294 recipe_status = (int)cpl_error_get_code();
295 }
296
297 if (!cpl_errorstate_is_equal(initial_errorstate)) {
298 /* Dump the error history since recipe execution start.
299 At this point the recipe cannot recover from the error */
300 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
301 }
302
303 return recipe_status;
304}
305
306
307/*----------------------------------------------------------------------------*/
313/*----------------------------------------------------------------------------*/
314
315static int
316_moons_standard_destroy(cpl_plugin *plugin)
317{
318 cpl_recipe *recipe;
319
320 if (plugin == NULL) {
321 cpl_msg_error(cpl_func, "Null plugin");
322 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
323 }
324
325 /* Verify plugin type */
326 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
327 cpl_msg_error(cpl_func, "Plugin is not a recipe");
328 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
329 }
330
331 /* Get the recipe */
332 recipe = (cpl_recipe *)plugin;
333
334 cpl_parameterlist_delete(recipe->parameters);
335
336 return 0;
337}
338
339static cpl_error_code
340_moons_standard_check_sof(cpl_frameset *frameset,
341 cpl_frameset *std_frameset,
342 const char **bpmap_rp_name,
343 const char **bpmap_nl_name,
344 const cpl_frame **masterbias,
345 const cpl_frame **masterdark_vis,
346 const cpl_frame **masterdark_nir,
347 const cpl_frame **coeffs_cube,
348 const cpl_frame **p2pmap,
349 const cpl_frame **fftrace,
350 const cpl_frame **master_flat,
351 const cpl_frame **sformat,
352 const cpl_frame **wmap,
353 const cpl_frame **skylines,
354 const cpl_frame **flat,
355 const cpl_frame **tell,
356 const cpl_frame **f2f,
357 const cpl_frame **flx,
358 const cpl_frame **atmo,
359 const cpl_frame **molecules_frame,
360 const cpl_frame **winc_frame,
361 const moo_extract_params *ext_params,
362 int *mode)
363{
364 cpl_ensure_code(moo_dfs_set_groups(frameset) == CPL_ERROR_NONE,
365 cpl_error_get_code());
366 cpl_ensure_code(mode != NULL, CPL_ERROR_NULL_INPUT);
367
368 int nb_std_flux = 0;
369 int nb_std_tell = 0;
370
371 int i;
372 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
373 cpl_frame *current_frame = cpl_frameset_get_position(frameset, i);
374 if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_STD_FLUX)) {
375 cpl_frameset_insert(std_frameset,
376 cpl_frame_duplicate(current_frame));
377 nb_std_flux++;
378 *mode = 0;
379 }
380 else if (!strcmp(cpl_frame_get_tag(current_frame),
381 MOONS_TAG_STD_TELL)) {
382 cpl_frameset_insert(std_frameset,
383 cpl_frame_duplicate(current_frame));
384 nb_std_tell++;
385 *mode = 1;
386 }
387 else if (!strcmp(cpl_frame_get_tag(current_frame),
388 MOONS_TAG_BP_MAP_RP)) {
389 *bpmap_rp_name = cpl_frame_get_filename(current_frame);
390 }
391 else if (!strcmp(cpl_frame_get_tag(current_frame),
392 MOONS_TAG_BP_MAP_NL)) {
393 *bpmap_nl_name = cpl_frame_get_filename(current_frame);
394 }
395 else if (!strcmp(cpl_frame_get_tag(current_frame),
396 MOONS_TAG_MASTER_BIAS)) {
397 *masterbias = current_frame;
398 }
399 else if (!strcmp(cpl_frame_get_tag(current_frame),
400 MOONS_TAG_MASTER_DARK_VIS)) {
401 *masterdark_vis = current_frame;
402 }
403 else if (!strcmp(cpl_frame_get_tag(current_frame),
404 MOONS_TAG_MASTER_DARK_NIR)) {
405 *masterdark_nir = current_frame;
406 }
407 else if (!strcmp(cpl_frame_get_tag(current_frame),
408 MOONS_TAG_LINEARITY_COEFF_CUBE)) {
409 *coeffs_cube = current_frame;
410 }
411 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_P2P_MAP)) {
412 *p2pmap = current_frame;
413 }
414 else if (!strcmp(cpl_frame_get_tag(current_frame),
415 MOONS_TAG_FF_TRACE)) {
416 *fftrace = current_frame;
417 }
418 else if (!strcmp(cpl_frame_get_tag(current_frame),
419 MOONS_TAG_MASTER_FLAT)) {
420 *master_flat = current_frame;
421 }
422 else if (!strcmp(cpl_frame_get_tag(current_frame),
423 MOONS_TAG_SPECTRAL_FORMAT)) {
424 *sformat = current_frame;
425 }
426 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_WAVEMAP)) {
427 *wmap = current_frame;
428 }
429 else if (!strcmp(cpl_frame_get_tag(current_frame),
430 MOONS_TAG_SKY_LINE_LIST)) {
431 *skylines = current_frame;
432 }
433 else if (!strcmp(cpl_frame_get_tag(current_frame),
434 MOONS_TAG_FF_EXTSPECTRA)) {
435 *flat = current_frame;
436 }
437 else if (!strcmp(cpl_frame_get_tag(current_frame),
438 MOONS_TAG_F2F_TABLE)) {
439 *f2f = current_frame;
440 }
441 else if (!strcmp(cpl_frame_get_tag(current_frame),
442 MOONS_TAG_FLUX_STD_CATALOG)) {
443 *flx = current_frame;
444 }
445 else if (!strcmp(cpl_frame_get_tag(current_frame),
446 MOONS_TAG_ATMOS_EXT)) {
447 *atmo = current_frame;
448 }
449 else if (!strcmp(cpl_frame_get_tag(current_frame),
450 MOONS_TAG_TELLURIC_CORR)) {
451 *tell = current_frame;
452 }
453 else if (!strcmp(cpl_frame_get_tag(current_frame),
454 MOONS_TAG_MOLECFIT_MOLECULES)) {
455 *molecules_frame = current_frame;
456 }
457 else if (!strcmp(cpl_frame_get_tag(current_frame),
458 MOONS_TAG_MOLECFIT_WINCLUDE)) {
459 *winc_frame = current_frame;
460 }
461 }
462
463
464 if (cpl_frameset_get_size(std_frameset) == 0) {
465 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
466 "SOF does not have any file tagged "
467 "with %s or %s",
468 MOONS_TAG_STD_FLUX,
469 MOONS_TAG_STD_TELL);
470 }
471 if (nb_std_flux > 0 && nb_std_tell > 0) {
472 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
473 "SOF have mixed STD input files"
474 "%d with %s and %d with %s",
475 nb_std_flux, MOONS_TAG_STD_FLUX,
476 nb_std_tell, MOONS_TAG_STD_TELL);
477 }
478 if (*fftrace == NULL) {
479 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
480 "SOF does not have any file tagged "
481 "with %s",
482 MOONS_TAG_FF_TRACE);
483 }
484
485 if (*f2f == NULL) {
486 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
487 "SOF does not have any file tagged "
488 "with %s",
489 MOONS_TAG_F2F_TABLE);
490 }
491
492 if (*master_flat == NULL &&
493 strcmp(ext_params->method, MOO_EXTRACT_METHOD_OPTIMAL) == 0) {
494 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
495 "SOF does not have any file tagged "
496 "with %s",
497 MOONS_TAG_MASTER_FLAT);
498 }
499
500 if (*sformat == NULL) {
501 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
502 "SOF does not have any file tagged "
503 "with %s",
504 MOONS_TAG_SPECTRAL_FORMAT);
505 }
506
507 if (*wmap == NULL) {
508 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
509 "SOF does not have any file tagged "
510 "with %s",
511 MOONS_TAG_WAVEMAP);
512 }
513
514 if (*skylines == NULL) {
515 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
516 "SOF does not have any file tagged "
517 "with %s",
518 MOONS_TAG_SKY_LINE_LIST);
519 }
520
521 if (*flat == NULL) {
522 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
523 "SOF does not have any file tagged "
524 "with %s",
525 MOONS_TAG_FF_EXTSPECTRA);
526 }
527
528 if (nb_std_flux > 0 && *flx == NULL) {
529 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
530 "SOF does not have any file tagged "
531 "with %s",
532 MOONS_TAG_FLUX_STD_CATALOG);
533 }
534 if (nb_std_flux > 0 && *atmo == NULL) {
535 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
536 "SOF does not have any file tagged "
537 "with %s",
538 MOONS_TAG_ATMOS_EXT);
539 }
540 if (nb_std_tell > 0) {
541 *tell = NULL;
542 if (*molecules_frame == NULL) {
543 return (
544 int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
545 "SOF does not have any file tagged "
546 "with %s",
547 MOONS_TAG_MOLECFIT_MOLECULES);
548 }
549
550 if (*winc_frame == NULL) {
551 return (
552 int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
553 "SOF does not have any file tagged "
554 "with %s",
555 MOONS_TAG_MOLECFIT_WINCLUDE);
556 }
557 }
558 return CPL_ERROR_NONE;
559}
560
561
562static cpl_error_code
563_moons_p2pmap(moo_det *arc, const cpl_frame *p2pmap)
564{
565 cpl_error_code status = CPL_ERROR_NONE;
566 moo_det *p2p = NULL;
567
568 if (p2pmap != NULL) {
569 moo_try_check(p2p = moo_det_create(p2pmap), " ");
570 moo_try_check(moo_apply_p2p(arc, p2p), " ");
571 }
572moo_try_cleanup:
573 moo_det_delete(p2p);
574 return status;
575}
576
577static cpl_error_code
578_moons_apply_flat(moo_ext *ext,
579 const cpl_frame *flat_frame,
580 const cpl_frame *f2f_frame)
581{
582 cpl_error_code status = CPL_ERROR_NONE;
583 moo_ext *flat = NULL;
584 moo_f2f *f2f = NULL;
585
586 moo_try_check(flat = moo_ext_create(flat_frame), " ");
587 if (f2f_frame != NULL) {
588 f2f = moo_f2f_load(f2f_frame);
589 }
590 moo_try_check(moo_apply_flat(ext, flat, f2f), " ");
591
592moo_try_cleanup:
593 moo_ext_delete(flat);
594 moo_f2f_delete(f2f);
595 return status;
596}
597
598static moo_sci *
599_moons_sub_sky_stare(moo_rbn *rbn,
600 moo_target_table *target_table,
601 const cpl_frame *f2f_frame,
602 moo_sub_sky_stare_params *sky_params,
603 const char *sci_filename)
604{
605 moo_sci *result = NULL;
606 moo_f2f *f2f = NULL;
607
608 if (f2f_frame != NULL) {
609 f2f = moo_f2f_load(f2f_frame);
610 }
611 moo_try_check(result =
612 moo_sub_sky_stare(rbn, target_table, rbn, f2f, NULL, NULL,
613 NULL, sky_params, sci_filename,
614 MOO_SCI1D_NOT_PAIRED),
615 " ");
616
617moo_try_cleanup:
618 moo_f2f_delete(f2f);
619 return result;
620}
621
622static cpl_frame *
623_moons_standard_frame(int inum,
624 const cpl_frame *frame,
625 const cpl_frame *refframe,
626 const cpl_frame *p2pmap,
627 const cpl_frame *fftrace,
628 const cpl_frame *master_flat,
629 moo_spectral_format *sformat,
630 moo_map *wmap,
631 moo_sky_lines_list *skylines,
632 const cpl_frame *flat_frame,
633 const cpl_frame *f2f_frame,
634 const cpl_frame *tell_frame,
635 moo_extract_params *extract_params,
636 moo_rebin_params *rbn_params,
637 moo_target_table_params *target_table_params,
638 moo_sub_sky_stare_params *sky_params,
639 moo_mode_type mode,
640 moo_products *products,
641 int rmode,
642 int offset)
643{
644 const char *stdp2p_tags[] = { MOONS_TAG_STDFLUX_APPLYP2P,
645 MOONS_TAG_STDTELL_APPLYP2P };
646
647 const char *stdext_tags[] = { MOONS_TAG_STDFLUX_EXTSPECTRA,
648 MOONS_TAG_STDTELL_EXTSPECTRA };
649
650 const char *stdffext_tags[] = { MOONS_TAG_STDFLUX_FFEXTSPECTRA,
651 MOONS_TAG_STDTELL_FFEXTSPECTRA };
652
653 const char *stdrbn_tags[] = { MOONS_TAG_STDFLUX_RBNSPECTRA,
654 MOONS_TAG_STDTELL_RBNSPECTRA };
655 const char *stdttable_tags[] = { MOONS_TAG_STDFLUX_TARGET_TABLE,
656 MOONS_TAG_STDTELL_TARGET_TABLE };
657
658 const char *stdsks_tags[] = { MOONS_TAG_STDFLUX_SKSSPECTRA,
659 MOONS_TAG_STDTELL_SKSSPECTRA };
660
661 cpl_frame *sci_frame = NULL;
662 moo_det *det = NULL;
663 moo_loc *loc = NULL;
664 moo_psf *psf = NULL;
665 moo_ext *ext = NULL;
666 moo_rbn *rbn = NULL;
667 moo_telluric *telluric = NULL;
668 moo_sci *sci = NULL;
669
670 char *det_filename = NULL;
671 char *ext_filename = NULL;
672 char *ffext_filename = NULL;
673 char *rbn_filename = NULL;
674 char *tellcorr_filename = NULL;
675 char *ttable_filename = NULL;
676 char *sci_filename = NULL;
677
678 moo_target_table *target_table = NULL;
679 cpl_errorstate prestate = cpl_errorstate_get();
680
681 moo_try_check(det = moo_det_create(frame), " ");
682 moo_try_check(_moons_p2pmap(det, p2pmap), " ");
683
684 det_filename = cpl_sprintf("%s_OFFSET%d_%s_%d.fits", stdp2p_tags[rmode],
685 offset, moo_mode_get_name(mode), inum);
686 moo_try_check(moo_products_add(products, det, CPL_FRAME_LEVEL_INTERMEDIATE,
687 stdp2p_tags[rmode], det_filename, refframe),
688 " ");
689 moo_try_check(loc = moo_loc_load(fftrace), " ");
690 if (master_flat != NULL) {
691 psf = moo_psf_load(master_flat);
692 }
693 ext_filename = cpl_sprintf("%s_OFFSET%d_%s_%d.fits", stdext_tags[rmode],
694 offset, moo_mode_get_name(mode), inum);
695 moo_try_check(ext =
696 moo_extract(det, loc, psf, extract_params, ext_filename),
697 " ");
698 moo_try_check(moo_products_add_ext(products, ext,
699 CPL_FRAME_LEVEL_INTERMEDIATE,
700 stdext_tags[rmode], ext_filename,
701 refframe),
702 " ");
703
704 moo_try_check(_moons_apply_flat(ext, flat_frame, f2f_frame), " ");
705 ffext_filename = cpl_sprintf("%s_OFFSET%d_%s_%d.fits", stdffext_tags[rmode],
706 offset, moo_mode_get_name(mode), inum);
707
708 moo_try_check(moo_ext_compute_snr(ext, wmap, sformat, skylines), " ");
709 moo_try_check(moo_products_add_ext(products, ext, CPL_FRAME_LEVEL_FINAL,
710 stdffext_tags[rmode], ffext_filename,
711 refframe),
712 " ");
713
714 rbn_filename = cpl_sprintf("%s_OFFSET%d_%s_%d.fits", stdrbn_tags[rmode],
715 offset, moo_mode_get_name(mode), inum);
716 moo_try_check(rbn = moo_rebin(ext, wmap, sformat, rbn_params, rbn_filename),
717 " ");
718
719 moo_try_check(moo_rbn_compute_snr(rbn, skylines), " ");
720
721 moo_try_check(moo_products_add_rbn(products, rbn, CPL_FRAME_LEVEL_FINAL,
722 stdrbn_tags[rmode], rbn_filename,
723 refframe),
724 " ");
725 if (tell_frame != NULL) {
726 moo_try_check(telluric = moo_telluric_load(tell_frame), " ");
727
728 tellcorr_filename = cpl_sprintf("%s_OFFSET%d_%s_%d.fits",
729 MOONS_TAG_STDFLUX_RBNTELLCORRSPECTRA,
730 offset, moo_mode_get_name(mode), inum);
731 moo_try_check(moo_correct_tell(rbn, telluric), " ");
732 moo_try_check(moo_products_add_rbn(products, rbn, CPL_FRAME_LEVEL_FINAL,
733 MOONS_TAG_STDFLUX_RBNTELLCORRSPECTRA,
734 tellcorr_filename, refframe),
735 " ");
736 }
737 else {
738 cpl_msg_info(__func__, "No telluric correction");
739 }
740
741 moo_try_check(target_table =
742 moo_create_target_table(rbn, NULL, MOO_MODE_STARE,
743 target_table_params),
744 " ");
745 ttable_filename =
746 cpl_sprintf("%s_OFFSET%d_%s_%d.fits", stdttable_tags[rmode], offset,
747 moo_mode_get_name(mode), inum);
748 moo_try_check(moo_products_add_target_table(products, target_table,
749 CPL_FRAME_LEVEL_INTERMEDIATE,
750 stdttable_tags[rmode],
751 ttable_filename, refframe),
752 " ");
753 sci_filename = cpl_sprintf("%s_OFFSET%d_%s_%d.fits", stdsks_tags[rmode],
754 offset, moo_mode_get_name(mode), inum);
755 moo_try_check(sci = _moons_sub_sky_stare(rbn, target_table, f2f_frame,
756 sky_params, sci_filename),
757 " ");
758 moo_try_check(moo_sci_compute_snr(sci, skylines), " ");
759
760 moo_try_check(sci_frame = cpl_frame_duplicate(
761 moo_products_add_sci(products, sci, CPL_FRAME_LEVEL_FINAL,
762 stdsks_tags[rmode], sci_filename,
763 refframe)),
764 " ");
765
766moo_try_cleanup:
767 // dump error from the state
768 if (!cpl_errorstate_is_equal(prestate)) {
769 cpl_frame_delete(sci_frame);
770 sci_frame = NULL;
771 }
772 cpl_free(det_filename);
773 cpl_free(ext_filename);
774 cpl_free(ffext_filename);
775 cpl_free(rbn_filename);
776 cpl_free(ttable_filename);
777 cpl_free(tellcorr_filename);
778 cpl_free(sci_filename);
779 moo_target_table_delete(target_table);
780 moo_sci_delete(sci);
781 moo_telluric_delete(telluric);
782 moo_rbn_delete(rbn);
783 moo_ext_delete(ext);
784 moo_loc_delete(loc);
785 moo_psf_delete(psf);
786 moo_det_delete(det);
787
788 return sci_frame;
789}
790
791
792static cpl_frame *
793_moons_prepare(int inum,
794 const cpl_frame *frame,
795 const char *bpmap_rp_name,
796 const char *bpmap_nl_name,
797 const cpl_frame *masterbias,
798 const cpl_frame *masterdark_vis,
799 const cpl_frame *masterdark_nir,
800 const cpl_frame *coeffs_cube,
801 moo_prepare_params *prepare_params,
802 moo_correct_bias_params *cbias_params,
803 moo_mode_type mode,
804 moo_products *products,
805 int rmode,
806 int offset)
807{
808 cpl_frame *result = NULL;
809 moo_det *det = NULL;
810
811 const char *det_tag[] = { MOONS_TAG_STDFLUX_CORRECTDARK,
812 MOONS_TAG_STDTELL_CORRECTDARK };
813 char *det_filename = NULL;
814
815 cpl_errorstate prestate = cpl_errorstate_get();
816
817 moo_try_check(det = moo_prepare(frame, bpmap_rp_name, bpmap_nl_name,
818 masterbias, coeffs_cube, prepare_params),
819 " ");
820
821 moo_try_check(moo_correct_bias(det, masterbias, cbias_params), " ");
822 moo_try_check(moo_correct_dark(det, NULL, masterdark_vis, masterdark_nir),
823 " ");
824
825 det_filename = cpl_sprintf("%s_OFFSET%d_%s_%d.fits", det_tag[rmode], offset,
826 moo_mode_get_name(mode), inum);
827 moo_try_check(result = cpl_frame_duplicate(
828 moo_products_add(products, det,
829 CPL_FRAME_LEVEL_INTERMEDIATE,
830 det_tag[rmode], det_filename, frame)),
831 " ");
832
833moo_try_cleanup:
834 if (!cpl_errorstate_is_equal(prestate)) {
835 cpl_frame_delete(result);
836 result = NULL;
837 }
838 moo_det_delete(det);
839 cpl_free(det_filename);
840 return result;
841}
842
843static cpl_frameset *
844_moons_prepare_set(const cpl_frameset *std_frameset,
845 const char *bpmap_rp_name,
846 const char *bpmap_nl_name,
847 const cpl_frame *masterbias,
848 const cpl_frame *masterdark_vis,
849 const cpl_frame *masterdark_nir,
850 const cpl_frame *coeffs_cube,
851 moo_prepare_params *prepare_params,
852 moo_correct_bias_params *cbias_params,
853 moo_mode_type mode,
854 moo_products *products,
855 int rmode,
856 int offset)
857{
858 cpl_frameset *detframes = NULL;
859 moo_det *det = NULL;
860
861 cpl_ensure(std_frameset, CPL_ERROR_NULL_INPUT, NULL);
862 cpl_ensure(products, CPL_ERROR_NULL_INPUT, NULL);
863
864 cpl_errorstate prestate = cpl_errorstate_get();
865
866 moo_try_check(detframes = cpl_frameset_new(), " ");
867
868 for (int i = 0; i < cpl_frameset_get_size(std_frameset); ++i) {
869 const cpl_frame *current_frame = NULL;
870 cpl_frame *frame = NULL;
871
872 moo_try_check(current_frame =
873 cpl_frameset_get_position_const(std_frameset, i),
874 " ");
875
876 moo_try_check(frame = _moons_prepare(i, current_frame, bpmap_rp_name,
877 bpmap_nl_name, masterbias,
878 masterdark_vis, masterdark_nir,
879 coeffs_cube, prepare_params,
880 cbias_params, mode, products,
881 rmode, offset),
882 " ");
883
884 moo_try_check(cpl_frameset_insert(detframes, frame), " ");
885 }
886moo_try_cleanup:
887 if (!cpl_errorstate_is_equal(prestate)) {
888 moo_det_delete(det);
889 cpl_frameset_delete(detframes);
890 detframes = NULL;
891 }
892 return detframes;
893}
894/*----------------------------------------------------------------------------*/
901/*----------------------------------------------------------------------------*/
902
903static int
904_moons_standard(cpl_frameset *frameset, const cpl_parameterlist *parlist)
905{
906 /* parameters */
907 moo_mode_type mode;
908 int offset;
909 moo_prepare_params *prepare_params = NULL;
910 moo_correct_bias_params *correct_bias_params = NULL;
911 moo_crh_params *crh_params = NULL;
912 moo_extract_params *extract_params = NULL;
913 moo_wavesol_params *wavesol_params = NULL;
914 moo_rebin_params *rbn_params = NULL;
915 moo_target_table_params *target_table_params = NULL;
916 moo_sub_sky_stare_params *sky_params = NULL;
917 moo_coadd_params *coadd_params = NULL;
918 moo_compute_resp_params *resp_params = NULL;
919 moo_spectral_format *sformat = NULL;
920 moo_map *wmap = NULL;
921 moo_sky_lines_list *skylines = NULL;
922 moo_flx *flx = NULL;
923 moo_atm *atm = NULL;
924 moo_detlist *det_list = NULL;
925 moo_det *std_med = NULL;
926 moo_scilist *sci_list = NULL;
927 moo_sci *sci_coadd = NULL;
928 moo_resp *resp = NULL;
929
930 /* SOF file */
931 cpl_frameset *std_frameset = cpl_frameset_new();
932 cpl_frameset *sci_set = cpl_frameset_new();
933
934 const char *bpmap_rp_name = NULL;
935 const char *bpmap_nl_name = NULL;
936 const cpl_frame *masterbias = NULL;
937 const cpl_frame *masterdark_vis = NULL;
938 const cpl_frame *masterdark_nir = NULL;
939 const cpl_frame *coeffs_cube = NULL;
940 const cpl_frame *p2pmap = NULL;
941 const cpl_frame *fftrace = NULL;
942 const cpl_frame *master_flat = NULL;
943 const cpl_frame *sformat_frame = NULL;
944 const cpl_frame *wmap_frame = NULL;
945 const cpl_frame *skylines_frame = NULL;
946 const cpl_frame *tell_frame = NULL;
947 const cpl_frame *flat_frame = NULL;
948 const cpl_frame *f2f_frame = NULL;
949 const cpl_frame *flx_frame = NULL;
950 const cpl_frame *atmo_frame = NULL;
951 cpl_frameset *stddet_frameset = NULL;
952 char *med_filename = NULL;
953 char *resp_filename = NULL;
954 char *calibflux_filename = NULL;
955 /* FLUX ==> 0, TELL ==> 1 */
956 int rmode;
957 const char *rmodenames[] = { "STDFLUX", "STDTELL" };
958
959 const char *modename = NULL;
960 const cpl_frame *molecule_frame = NULL;
961 const cpl_frame *winc_frame = NULL;
962 moo_molecfit_model_params *molecfit_model_params = NULL;
963
964 moo_molectable *atm_fitted = NULL;
965 moo_molectable *best_fitted_params = NULL;
966 moo_molectable *best_fitted_model = NULL;
967
968 char *best_fitted_params_name = NULL;
969 char *best_fitted_model_name = NULL;
970 char *atm_fitted_name = NULL;
971
972 moo_products *products =
973 moo_products_new(frameset, parlist, "moons_standard",
974 PACKAGE "/" PACKAGE_VERSION);
975
976
977 const moo_params *params = moo_products_get_params(products);
978 moo_try_check(prepare_params = moo_params_get_prepare(params, parlist),
979 " ");
980 moo_try_check(correct_bias_params =
981 moo_params_get_correct_bias(params, parlist),
982 " ");
983 moo_try_check(crh_params = moo_params_get_crh(params, parlist), " ");
984 moo_try_check(extract_params = moo_params_get_extract(params, parlist),
985 " ");
986 moo_try_check(rbn_params = moo_params_get_rebin(params, parlist), " ");
987 moo_try_check(target_table_params =
988 moo_params_get_target_table(params, parlist),
989 " ");
990 moo_try_check(sky_params = moo_params_get_sub_sky_stare(params, parlist),
991 " ");
992 moo_try_check(coadd_params = moo_params_get_coadd(params, parlist), " ");
993 moo_try_check(resp_params = moo_params_get_compute_resp(params, parlist),
994 " ");
995 moo_try_check(molecfit_model_params =
996 moo_params_get_molecfit_model(params, parlist),
997 " ");
998 moo_try_check(_moons_standard_check_sof(
999 frameset, std_frameset, &bpmap_rp_name, &bpmap_nl_name,
1000 &masterbias, &masterdark_vis, &masterdark_nir,
1001 &coeffs_cube, &p2pmap, &fftrace, &master_flat,
1002 &sformat_frame, &wmap_frame, &skylines_frame, &flat_frame,
1003 &tell_frame, &f2f_frame, &flx_frame, &atmo_frame,
1004 &molecule_frame, &winc_frame, extract_params, &rmode),
1005 " ");
1006
1007 const char *rmodename = rmodenames[rmode];
1008 int i;
1009
1010
1011 cpl_frame *frame = cpl_frameset_get_position(std_frameset, 0);
1012
1013 moo_try_check(mode = moo_mode_get(frame), " ");
1014 moo_try_check(offset = moo_offset_get(frame), " ");
1015
1016 cpl_msg_info("moons_standard",
1017 "Use standard in mode %s frame mode %s offset %d", rmodename,
1018 moo_mode_get_name(mode), offset);
1019
1020 moo_try_check(sformat = moo_spectral_format_load(sformat_frame, mode), " ");
1021 moo_try_check(wmap = moo_map_load(wmap_frame), " ");
1022 moo_try_check(skylines = moo_sky_lines_list_load(skylines_frame), " ");
1023
1024 moo_try_check(stddet_frameset =
1025 _moons_prepare_set(std_frameset, bpmap_rp_name,
1026 bpmap_nl_name, masterbias,
1027 masterdark_vis, masterdark_nir,
1028 coeffs_cube, prepare_params,
1029 correct_bias_params, mode, products,
1030 rmode, offset),
1031 " ");
1032
1033 if (rmode == 1) {
1034 moo_try_check(det_list = moo_detlist_create(stddet_frameset), " ");
1035 moo_try_check(std_med = moo_remove_CRH(det_list, NULL, crh_params),
1036 " ");
1037 med_filename =
1038 cpl_sprintf("%s_OFFSET%d_%s.fits", MOONS_TAG_STDTELL_REMOVECRH,
1039 offset, moo_mode_get_name(mode));
1040 cpl_frameset_delete(stddet_frameset);
1041 stddet_frameset = cpl_frameset_new();
1042 moo_try_check(cpl_frameset_insert(stddet_frameset,
1043 cpl_frame_duplicate(moo_products_add(
1044 products, std_med,
1045 CPL_FRAME_LEVEL_INTERMEDIATE,
1046 MOONS_TAG_STDTELL_REMOVECRH,
1047 med_filename, frame))),
1048 " ");
1049 }
1050 int size = cpl_frameset_get_size(stddet_frameset);
1051
1052 for (i = 0; i < size; ++i) {
1053 const cpl_frame *current_frame = NULL;
1054 const cpl_frame *ref_frame = NULL;
1055 cpl_frame *sci_frame = NULL;
1056 moo_try_check(current_frame =
1057 cpl_frameset_get_position_const(stddet_frameset, i),
1058 " ");
1059 moo_try_check(ref_frame =
1060 cpl_frameset_get_position_const(std_frameset, i),
1061 " ");
1062
1063 moo_try_check(sci_frame = _moons_standard_frame(
1064 i, current_frame, ref_frame, p2pmap, fftrace,
1065 master_flat, sformat, wmap, skylines, flat_frame,
1066 f2f_frame, tell_frame, extract_params, rbn_params,
1067 target_table_params, sky_params, mode, products,
1068 rmode, offset),
1069 " ");
1070 cpl_frameset_insert(sci_set, sci_frame);
1071 }
1072
1073 if (rmode == 0) {
1074 sci_list = moo_scilist_create_clean(sci_set);
1075
1076 moo_try_check(flx = moo_flx_load(flx_frame), " ");
1077 moo_try_check(atm = moo_atm_load(atmo_frame), " ");
1078
1079 moo_try_check(resp = moo_compute_resp(sci_list, atm, flx, resp_params),
1080 " ");
1081
1082 resp_filename = cpl_sprintf("%s_%s.fits", MOONS_TAG_RESPONSE,
1083 moo_mode_get_name(mode));
1084 moo_try_check(moo_products_add_resp(products, resp,
1085 CPL_FRAME_LEVEL_FINAL,
1086 MOONS_TAG_RESPONSE, resp_filename,
1087 frame),
1088 " ");
1089 }
1090 else {
1091 modename = moo_mode_get_name(mode);
1092 const cpl_frame *sci_frame = NULL;
1093 moo_try_check(sci_frame = cpl_frameset_get_position_const(sci_set, 0),
1094 " ");
1095 moo_try_check(best_fitted_params =
1096 moo_molecfit_model(sci_frame, modename,
1097 molecule_frame, winc_frame,
1098 &atm_fitted, &best_fitted_model,
1099 molecfit_model_params),
1100 " ");
1101 atm_fitted_name =
1102 cpl_sprintf("%s_%s.fits", MOONS_TAG_MOLECFIT_ATM_PARAMS,
1103 moo_mode_get_name(mode));
1104 best_fitted_params_name =
1105 cpl_sprintf("%s_%s.fits", MOONS_TAG_MOLECFIT_BEST_FIT_PARAMS,
1106 moo_mode_get_name(mode));
1107 best_fitted_model_name =
1108 cpl_sprintf("%s_%s.fits", MOONS_TAG_MOLECFIT_BEST_FIT_MODEL,
1109 moo_mode_get_name(mode));
1110
1111 moo_try_check(moo_products_add_molectable(
1112 products, best_fitted_params, CPL_FRAME_LEVEL_FINAL,
1113 MOONS_TAG_MOLECFIT_BEST_FIT_PARAMS,
1114 best_fitted_params_name, sci_frame),
1115 " ");
1116 moo_try_check(
1117 moo_products_add_molectable(products, best_fitted_model,
1118 CPL_FRAME_LEVEL_INTERMEDIATE,
1119 MOONS_TAG_MOLECFIT_BEST_FIT_MODEL,
1120 best_fitted_model_name, sci_frame),
1121 " ");
1122 moo_try_check(moo_products_add_molectable(products, atm_fitted,
1123 CPL_FRAME_LEVEL_FINAL,
1124 MOONS_TAG_MOLECFIT_ATM_PARAMS,
1125 atm_fitted_name, sci_frame),
1126 " ");
1127 }
1128
1129moo_try_cleanup:
1130 cpl_free(resp_filename);
1131 cpl_free(med_filename);
1132 cpl_free(calibflux_filename);
1133 moo_sci_delete(sci_coadd);
1134 moo_scilist_delete(sci_list);
1135 moo_sky_lines_list_delete(skylines);
1136 moo_map_delete(wmap);
1138 moo_flx_delete(flx);
1139 moo_atm_delete(atm);
1140 moo_resp_delete(resp);
1141 moo_det_delete(std_med);
1142 moo_detlist_delete(det_list);
1143 cpl_frameset_delete(std_frameset);
1144 cpl_frameset_delete(stddet_frameset);
1145 cpl_frameset_delete(sci_set);
1146 moo_extract_params_delete(extract_params);
1147 moo_wavesol_params_delete(wavesol_params);
1148 moo_target_table_params_delete(target_table_params);
1149 moo_rebin_params_delete(rbn_params);
1150 moo_sub_sky_stare_params_delete(sky_params);
1151 moo_coadd_params_delete(coadd_params);
1152 moo_compute_resp_params_delete(resp_params);
1153 moo_crh_params_delete(crh_params);
1154 moo_correct_bias_params_delete(correct_bias_params);
1155 moo_prepare_params_delete(prepare_params);
1156 cpl_free(best_fitted_params_name);
1157 cpl_free(best_fitted_model_name);
1158 cpl_free(atm_fitted_name);
1159 moo_molectable_delete(best_fitted_model);
1160 moo_molectable_delete(atm_fitted);
1161 moo_molectable_delete(best_fitted_params);
1162 moo_molecfit_model_params_delete(molecfit_model_params);
1163 moo_products_delete(products);
1164 return (int)cpl_error_get_code();
1165}
moo_atm * moo_atm_load(const cpl_frame *frame)
Load a ATM frame and create a moo_atm.
Definition: moo_atm.c:83
void moo_atm_delete(moo_atm *self)
Delete a moo_atm.
Definition: moo_atm.c:154
moo_det * moo_det_create(const cpl_frame *frame)
Create a new moo_det from the given DET frame.
Definition: moo_det.c:91
void moo_det_delete(moo_det *self)
Delete a moo_det.
Definition: moo_det.c:472
moo_mode_type moo_mode_get(const cpl_frame *frame)
Get the name of a mode from a frame.
Definition: moo_detector.c:224
int moo_offset_get(const cpl_frame *refframe)
Get the offset from a frame.
Definition: moo_detector.c:254
const char * moo_mode_get_name(moo_mode_type type)
Get the name of a mode.
Definition: moo_detector.c:204
moo_detlist * moo_detlist_create(cpl_frameset *frameset)
Create a new moo_detlist from the given DET frameset.
Definition: moo_detlist.c:71
void moo_detlist_delete(moo_detlist *self)
Free all memory used by a moo_detlist object including the DET.
Definition: moo_detlist.c:559
moo_ext * moo_ext_create(const cpl_frame *frame)
Create a new empty EXT filename.
Definition: moo_ext.c:86
void moo_ext_delete(moo_ext *self)
Delete a moo_ext.
Definition: moo_ext.c:370
cpl_error_code moo_ext_compute_snr(moo_ext *self, moo_map *wmap, moo_spectral_format *sformat, moo_sky_lines_list *skylines)
Compute SNR for all fibres EXT.
Definition: moo_ext.c:553
void moo_f2f_delete(moo_f2f *self)
Delete a moo_f2f.
Definition: moo_f2f.c:413
moo_f2f * moo_f2f_load(const cpl_frame *f2f_frame)
Load a F2F table from a fits file.
Definition: moo_f2f.c:139
moo_flx * moo_flx_load(const cpl_frame *frame)
Load a FLX frame and create a moo_flx.
Definition: moo_flx.c:84
void moo_flx_delete(moo_flx *self)
Delete a moo_flx.
Definition: moo_flx.c:196
moo_loc * moo_loc_load(const cpl_frame *locframe)
Load a LOC frame and create a moo_loc.
Definition: moo_loc.c:109
void moo_loc_delete(moo_loc *self)
Delete a moo_loc.
Definition: moo_loc.c:332
void moo_map_delete(moo_map *self)
Delete a moo_map.
Definition: moo_map.c:236
void moo_molectable_delete(moo_molectable *self)
Delete a moo_molectable.
moo_coadd_params * moo_params_get_coadd(const moo_params *self, const cpl_parameterlist *list)
Get coadd parameters from moons parameters list.
Definition: moo_params.c:3147
cpl_error_code moo_params_add_extract(moo_params *self, cpl_parameterlist *list)
Add default parameters for extraction.
Definition: moo_params.c:902
cpl_error_code moo_params_add_sub_sky_stare(moo_params *self, cpl_parameterlist *list)
Add default parameters for moo_sub_sky_stare.
Definition: moo_params.c:2179
moo_prepare_params * moo_params_get_prepare(const moo_params *self, const cpl_parameterlist *list)
Get remove prepare parameters from moons parameters list.
Definition: moo_params.c:1073
moo_sub_sky_stare_params * moo_params_get_sub_sky_stare(const moo_params *self, const cpl_parameterlist *list)
Get sub sky stare parameters from moons parameters list.
Definition: moo_params.c:2909
moo_compute_resp_params * moo_params_get_compute_resp(const moo_params *self, const cpl_parameterlist *list)
Get compute response parameters from moons parameters list.
Definition: moo_params.c:1968
cpl_error_code moo_params_add_target_table(moo_params *self, cpl_parameterlist *list, int value)
Add default parameters for moo_create_target_table.
Definition: moo_params.c:2616
moo_target_table_params * moo_params_get_target_table(const moo_params *self, const cpl_parameterlist *list)
Get target_table parameters from moons parameters list.
Definition: moo_params.c:3063
moo_correct_bias_params * moo_params_get_correct_bias(const moo_params *self, const cpl_parameterlist *list)
Get correct_bias parameters from moons parameters list.
Definition: moo_params.c:1167
void moo_molecfit_model_params_delete(moo_molecfit_model_params *self)
Delete a moo_molecfit_model_params.
Definition: moo_params.c:2278
cpl_error_code moo_params_add_crh(moo_params *self, cpl_parameterlist *list, const char *method)
Add default parameters for remove crh.
Definition: moo_params.c:694
moo_extract_params * moo_params_get_extract(const moo_params *self, const cpl_parameterlist *list)
Get extraction parameters from moons parameters list.
Definition: moo_params.c:1197
void moo_params_delete(moo_params *self)
Delete a moo_params.
Definition: moo_params.c:85
moo_crh_params * moo_params_get_crh(const moo_params *self, const cpl_parameterlist *list)
Get remove crh parameters from moons parameters list.
Definition: moo_params.c:1099
cpl_error_code moo_params_add_correct_bias(moo_params *self, cpl_parameterlist *list, const char *method)
Add default parameters for correct_bias.
Definition: moo_params.c:860
cpl_error_code moo_params_add_molecfit_model(moo_params *self, cpl_parameterlist *list)
Add default parameters for molecfit_model.
Definition: moo_params.c:2373
cpl_error_code moo_params_add_compute_resp(moo_params *self, cpl_parameterlist *list)
Add default parameters for compute_resp.
Definition: moo_params.c:1888
moo_molecfit_model_params * moo_params_get_molecfit_model(const moo_params *self, const cpl_parameterlist *list)
Get molecfit model parameters from moons parameters list.
Definition: moo_params.c:1554
cpl_error_code moo_params_add_keep_temp(moo_params *self, cpl_parameterlist *list)
Add default parameters for keep-temp.
Definition: moo_params.c:932
cpl_error_code moo_params_add_prepare(moo_params *self, cpl_parameterlist *list)
Add default parameters for prepare.
Definition: moo_params.c:667
moo_rebin_params * moo_params_get_rebin(const moo_params *self, const cpl_parameterlist *list)
Get rebin parameters from moons parameters list.
Definition: moo_params.c:2866
cpl_error_code moo_params_add_coadd(moo_params *self, cpl_parameterlist *list)
Add default parameters for moo_coadd.
Definition: moo_params.c:2687
moo_params * moo_params_new(const char *pid, const char *recipe_id)
Create a new moo_params.
Definition: moo_params.c:62
cpl_error_code moo_params_add_rebin(moo_params *self, cpl_parameterlist *list)
Add default parameters for moo_rebin.
Definition: moo_params.c:2152
void moo_psf_delete(moo_psf *self)
Delete a moo_psf.
Definition: moo_psf.c:264
moo_psf * moo_psf_load(const cpl_frame *psfframe)
Load a PSF frame and create a moo_psf.
Definition: moo_psf.c:109
void moo_rbn_delete(moo_rbn *self)
Delete a moo_rbn.
Definition: moo_rbn.c:120
cpl_error_code moo_rbn_compute_snr(moo_rbn *self, moo_sky_lines_list *skylines)
Compute SNR for targets in RBN.
Definition: moo_rbn.c:421
void moo_resp_delete(moo_resp *self)
Delete a moo_resp.
Definition: moo_resp.c:320
void moo_sci_delete(moo_sci *self)
Delete a moo_sci.
Definition: moo_sci.c:84
cpl_error_code moo_sci_compute_snr(moo_sci *self, moo_sky_lines_list *skylines)
Compute SNR for all targets in SCI.
Definition: moo_sci.c:415
void moo_scilist_delete(moo_scilist *self)
Free all memory used by a moo_scilist object including the SCI.
Definition: moo_scilist.c:176
moo_scilist * moo_scilist_create_clean(cpl_frameset *frameset)
Create a new moo_scilist from the given SCI frameset ignoring SCI with 0 targets.
Definition: moo_scilist.c:345
moo_sky_lines_list * moo_sky_lines_list_load(const cpl_frame *frame)
Load a SKY_LINES_LIST frame and create a moo_sky_lines_list.
void moo_sky_lines_list_delete(moo_sky_lines_list *self)
Delete a moo_sky_lines_list.
void moo_spectral_format_delete(moo_spectral_format *self)
Delete a moo_spectral_format.
moo_spectral_format * moo_spectral_format_load(const cpl_frame *frame, moo_mode_type m)
Load a SPECTRAL FORMAT frame and create a moo_spectral_format.
void moo_target_table_delete(moo_target_table *self)
Delete a moo_target_table.
moo_target_table * moo_create_target_table(moo_rbn *rbnA, moo_rbn *rbnB, moo_target_table_mode mode, moo_target_table_params *params)
Prepare target table for SCI frames using their attached fibre.
moo_telluric * moo_telluric_load(const cpl_frame *frame)
Load a TELLURIC frame and create a moo_telluric.
Definition: moo_telluric.c:405
void moo_telluric_delete(moo_telluric *self)
Delete a moo_telluric.
Definition: moo_telluric.c:334
cpl_error_code moo_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: moo_dfs.c:206
moo_det * moo_remove_CRH(moo_detlist *detlist, moo_masklist *cosmiclist, moo_crh_params *params)
Remove CRH in single frames or in a combination of multiple frames.
moo_ext * moo_extract(moo_det *det, moo_loc *loc, moo_psf *master_flat, moo_extract_params *params, const char *filename)
extract the 1D spectrum of fibres
Definition: moo_extract.c:523
cpl_error_code moo_correct_tell(moo_rbn *rbn, moo_telluric *tell)
Apply the telluric correction to 1D rebinned spectra.
moo_resp * moo_compute_resp(moo_scilist *scilist, moo_atm *atm, moo_flx *flx, moo_compute_resp_params *params)
Compute instrumental response.
cpl_error_code moo_apply_p2p(moo_det *flat, moo_det *p2pmap)
Divide DET by the pixel-to-pixel variation map.
moo_molectable * moo_molecfit_model(const cpl_frame *sci_frame, const char *modename, const cpl_frame *molecule_frame, const cpl_frame *winc_frame, moo_molectable **pmt_atm_fitted, moo_molectable **best_fitted_model, moo_molecfit_model_params *params)
Apply the relative flux calibration to 1D rebinned spectra.
moo_rbn * moo_rebin(moo_ext *ext, moo_map *wmap, moo_spectral_format *sformat, moo_rebin_params *params, const char *filename)
Rebin an EXT spectra in RBN format.
Definition: moo_rebin.c:783
moo_det * moo_prepare(const cpl_frame *rawframe, const char *const badpixmask_rp, const char *const badpixmask_nl, const cpl_frame *masterbias, const cpl_frame *cube_frame, moo_prepare_params *params)
This function transforms RAW frames in DET frames attaching the default bad pixel map and an error im...
Definition: moo_prepare.c:324
cpl_error_code moo_apply_flat(moo_ext *ext, moo_ext *flat, moo_f2f *f2f)
Divide spectra by 1D flat-field.
cpl_error_code moo_correct_bias(moo_det *det, const cpl_frame *masterbias_frame, moo_correct_bias_params *params)
Subtracts the Master Bias frame from a DET frame.
Definition: moo_drl.c:86
moo_sci * moo_sub_sky_stare(moo_rbn *obja_rbn, moo_target_table *target_table, moo_rbn *objb_rbn, moo_f2f *f2f, const cpl_frame *solflux_frame, const cpl_frame *airglow_group_frame, const cpl_frame *airglow_var_frame, moo_sub_sky_stare_params *params, const char *filename, int ispaired)
This function subtracts the sky in wavelength calibrated and extracted science frames obtain in Stare...
cpl_error_code moo_correct_dark(moo_det *det, moo_det *detoff, const cpl_frame *masterDarkVis, const cpl_frame *masterDarkNir)
Subtracts the master dark frame from a frame after scaling for exposure time (RI)....
Definition: moo_drl.c:250
moo_products * moo_products_new(cpl_frameset *framelist, const cpl_parameterlist *parlist, const char *recid, const char *pipeline_id)
create a moo_product object for a recipe
Definition: moo_products.c:53
cpl_frame * moo_products_add_sci(moo_products *self, moo_sci *sci, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a SCI object
Definition: moo_products.c:420
cpl_frame * moo_products_add_rbn(moo_products *self, moo_rbn *rbn, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a RBN object
Definition: moo_products.c:376
cpl_frame * moo_products_add_ext(moo_products *self, moo_ext *ext, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a EXT object
Definition: moo_products.c:333
cpl_frame * moo_products_add_molectable(moo_products *self, moo_molectable *mtable, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a MOLECTABLE object
Definition: moo_products.c:600
cpl_frame * moo_products_add_target_table(moo_products *self, moo_target_table *ttable, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a TARGET_TABLE object
Definition: moo_products.c:774
cpl_frame * moo_products_add_resp(moo_products *self, moo_resp *resp, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a RESP object
Definition: moo_products.c:464
cpl_frame * moo_products_add(moo_products *self, moo_det *det, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a DET object
Definition: moo_products.c:203
const moo_params * moo_products_get_params(const moo_products *self)
get the moo_params object
Definition: moo_products.c:87
const char * moo_get_license(void)
Get the pipeline copyright and license.
Definition: moo_utils.c:81
FLX format.
Definition: moo_flx.h:43
the different type of detectors