MOONS Pipeline Reference Manual 0.13.2
moons_science_starenod2.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_badpix.h"
34#include "moo_extlist.h"
35#include "moo_correct_tell.h"
36#include "moo_subtract_nod.h"
37#include "moo_combine_pair.h"
38#include "moo_combine_sky.h"
39#include "moo_products.h"
40#include <cpl.h>
41
42#include <string.h>
43
44/*-----------------------------------------------------------------------------
45 Plugin registration
46 -----------------------------------------------------------------------------*/
47
48int cpl_plugin_get_info(cpl_pluginlist *list);
49
50/*-----------------------------------------------------------------------------
51 Private function prototypes
52 -----------------------------------------------------------------------------*/
53
54static int _moons_science_starenod2_create(cpl_plugin *plugin);
55static int _moons_science_starenod2_exec(cpl_plugin *plugin);
56static int _moons_science_starenod2_destroy(cpl_plugin *plugin);
57static int _moons_science_starenod2(cpl_frameset *frameset,
58 const cpl_parameterlist *parlist);
59
60/*-----------------------------------------------------------------------------
61 Static variables
62 -----------------------------------------------------------------------------*/
63static const char *const _moons_science_starenod2_description =
64 "From an observation sequence in StareNod mode, this recipe removes the"
65 " instrumental signature and provides calibrated science products. During "
66 "the"
67 " sequence, the telescope nods from one position on targets (labeled as T "
68 "in "
69 "Fig. 5-12) to a blank sky position (S). In the sequence, different slit "
70 "offset"
71 " positions can be used: as represented in Fig. 5-12, the combination is "
72 "done "
73 "with 1D wavelength calibrated sky subtracted spectra. Using different "
74 "slit "
75 "offset positions implies that different sets of calibration (FF, wave "
76 "maps) "
77 "are given as inputs.\n"
78 "INPUT FRAMES\n"
79 " * science exposure frames n>=1 file(s) (RAW) with tag "
80 "OBJECT_STARENOD : "
81 "science frame in stare+nod mode file\n"
82 " * sky exposure frames n file(s) (RAW) with tag "
83 "SKY_STARENOD : "
84 "Sky Frames illuminated by blank sky only, obtained in the Stare+Nod"
85 " observation mode. The amount of exposure time (or DIT × NDIT for NIR), "
86 "as "
87 "well as the number of exposures, can be less than for the corresponding "
88 "OBJECT_STARENOD frames.\n"
89 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag "
90 "BP_MAP_RP : "
91 "cosmetic bad pixel map\n"
92 " * [OPTIONAL] NonLinearityBadPixMask 1 file (QUA) with tag "
93 "BP_MAP_NL : "
94 "cosmetic bad pixel map coming from linearity recipe\n"
95 " * MasterBias 1 file (DET) with tag "
96 "MASTER_BIAS : "
97 "master bias file\n"
98 " * MasterDarkNir 1 file (DET) with tag "
99 "MASTER_DARK_NIR : "
100 "master dark nir for object\n"
101 " * [OPTIONAL] MasterDarkNir 1 file (DET) with tag "
102 "MASTER_DARK_NIR : "
103 "master dark nir file for sky (if exposure time is different from object)\n"
104 " * [OPTIONAL] MasterDarkVis 1 file (DET) with tag "
105 "MASTER_DARK_VIS : "
106 "master dark vis file\n"
107 " * [OPTIONAL] CoeffsCube 1 or 2 file(s) one by offset (3D) with tag "
108 "LINEARITY_COEFF_CUBE : "
109 "coefficients to correct pixels detector linearity\n"
110 " * [OPTIONAL] P2pMap 1 file (DET) with tag "
111 "P2P_MAP : "
112 "pixel to pixel map\n"
113 " * Fftrace 1 or 2 file(s) one by offset (LOC) with tag "
114 "FF_TRACE :"
115 "the localisation table\n"
116 " * [OPTIONAL] MasterFlat 1 or 2 file(s) one by offset (PSF) with tag "
117 "MASTER_FLAT : "
118 "the master flat used for optimal extraction\n"
119 " * Ffext 1 or 2 file(s) one by offset (EXT) with tag "
120 "FF_EXTSPECTRA : "
121 "the extracted flat field\n"
122 " * F2f [OPTIONAL] 1 or 2 file(s) one by offset (F2F) with tag "
123 "F2F_TABLE :"
124 "the fibre-to-fibre relative response\n"
125 " * SFormat 1 file (FMT) with tag "
126 "SPECTRAL_FORMAT : "
127 "the spectral format table\n"
128 " * WaveMap 1 or 2 file(s) one by offset (WMAP) with tag "
129 "WAVE_MAP : "
130 "the wavelength map\n"
131 " * SkyLines 1 file (CAT) with tag "
132 "SKY_LINE_LIST : "
133 "the sky lines list table\n"
134 " * [OPTIONAL] response 1 file (RESPONSE) with "
135 "tag RESPONSE : "
136 "the response spectra in the extracted pixel space\n"
137 " * [OPTIONAL] TellCorr 1 file (TELLURIC_CORR) "
138 "with tag TELLURIC_CORR : "
139 "the telluric correction spectra\n"
140 " * [OPTIONAL] atmosExt 1 file (ATMO) with tag "
141 "ATMOS_EXT : "
142 "the atmospheric extinction table\n"
143 "PRODUCTS\n"
144 " * STARENOD_RBNSPECTRA_OFFSET[offset]_[insmode]_i.fits (RBN) with tag "
145 "STARENOD_RBNSPECTRA : "
146 "Science product individual calibrated frames\n"
147 " * STARENOD_RBNFLXSPECTRA_OFFSET[offset]_[insmode]_i.fits (RBN) with tag "
148 "STARENOD_RBNFLXSPECTRA : "
149 "Science product individual flux calibrated frames\n"
150 " * STARENOD_SKSSPECTRA_OFFSET[offset]_[insmode]_i.fits (SCI) with tag "
151 "STARENOD_SKSSPECTRA : "
152 "Science product individual sky subtracted frames\n"
153 " * STARENOD_SKSSPECTRA_[insmode].fits (SCI) with tag "
154 "STARENOD_SKSSPECTRA : "
155 "Science product coadd calibrated frame\n"
156 "\n";
157
158/*-----------------------------------------------------------------------------
159 Function code
160 -----------------------------------------------------------------------------*/
161
162/*----------------------------------------------------------------------------*/
172/*----------------------------------------------------------------------------*/
173
174int
175cpl_plugin_get_info(cpl_pluginlist *list)
176{
177 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
178 cpl_plugin *plugin = &recipe->interface;
179 if (cpl_plugin_init(plugin, CPL_PLUGIN_API, MOONS_BINARY_VERSION,
180 CPL_PLUGIN_TYPE_RECIPE, "moons_science_starenod2",
181 "Reduces science exposure in stare and stare+nod modes",
182 _moons_science_starenod2_description, "Regis Haigron",
183 PACKAGE_BUGREPORT, moo_get_license(),
184 _moons_science_starenod2_create,
185 _moons_science_starenod2_exec,
186 _moons_science_starenod2_destroy)) {
187 cpl_msg_error(cpl_func, "Plugin initialization failed");
188 (void)cpl_error_set_where(cpl_func);
189 return 1;
190 }
191 if (cpl_pluginlist_append(list, plugin)) {
192 cpl_msg_error(cpl_func, "Error adding plugin to list");
193 (void)cpl_error_set_where(cpl_func);
194 return 1;
195 }
196 return 0;
197}
198
199/*----------------------------------------------------------------------------*/
207/*----------------------------------------------------------------------------*/
208
209static int
210_moons_science_starenod2_create(cpl_plugin *plugin)
211{
212 cpl_recipe *recipe;
213 /* Do not create the recipe if an error code is already set */
214 if (cpl_error_get_code() != CPL_ERROR_NONE) {
215 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
216 cpl_func, __LINE__, cpl_error_get_where());
217 return (int)cpl_error_get_code();
218 }
219 if (plugin == NULL) {
220 cpl_msg_error(cpl_func, "Null plugin");
221 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
222 }
223 /* Verify plugin type */
224 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
225 cpl_msg_error(cpl_func, "Plugin is not a recipe");
226 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
227 }
228 /* Get the recipe */
229 recipe = (cpl_recipe *)plugin;
230 /* Create the parameters list in the cpl_recipe object */
231 recipe->parameters = cpl_parameterlist_new();
232 if (recipe->parameters == NULL) {
233 cpl_msg_error(cpl_func, "Parameter list allocation failed");
234 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
235 }
236 moo_params *params = moo_params_new("moons", "moons_science_starenod2");
237 /* Fill the parameters list */
238 moo_params_add_keep_temp(params, recipe->parameters);
239
240 moo_params_add_prepare(params, recipe->parameters);
241 moo_params_add_correct_bias(params, recipe->parameters,
242 MOO_CORRECT_BIAS_METHOD_MASTER);
243 moo_params_add_extract(params, recipe->parameters);
244 moo_params_add_science_wavesol(params, recipe->parameters);
245 moo_params_add_rebin(params, recipe->parameters);
246 moo_params_add_target_table(params, recipe->parameters, CPL_FALSE);
247 moo_params_add_sub_sky_stare(params, recipe->parameters);
248 moo_params_add_coadd(params, recipe->parameters);
249 moo_params_add_create_s1d(params, recipe->parameters);
250 moo_params_delete(params);
251 return 0;
252}
253
254/*----------------------------------------------------------------------------*/
260/*----------------------------------------------------------------------------*/
261
262static int
263_moons_science_starenod2_exec(cpl_plugin *plugin)
264{
265 cpl_recipe *recipe;
266 int recipe_status;
267 cpl_errorstate initial_errorstate = cpl_errorstate_get();
268 /* Return immediately if an error code is already set */
269 if (cpl_error_get_code() != CPL_ERROR_NONE) {
270 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
271 cpl_func, __LINE__, cpl_error_get_where());
272 return (int)cpl_error_get_code();
273 }
274 if (plugin == NULL) {
275 cpl_msg_error(cpl_func, "Null plugin");
276 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
277 }
278 /* Verify plugin type */
279 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
280 cpl_msg_error(cpl_func, "Plugin is not a recipe");
281 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
282 }
283 /* Get the recipe */
284 recipe = (cpl_recipe *)plugin;
285 /* Verify parameter and frame lists */
286 if (recipe->parameters == NULL) {
287 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
288 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
289 }
290 if (recipe->frames == NULL) {
291 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
292 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
293 }
294 /* Invoke the recipe */
295 recipe_status =
296 _moons_science_starenod2(recipe->frames, recipe->parameters);
297 /* Ensure DFS-compliance of the products */
298 if (cpl_dfs_update_product_header(recipe->frames)) {
299 if (!recipe_status)
300 recipe_status = (int)cpl_error_get_code();
301 }
302 if (!cpl_errorstate_is_equal(initial_errorstate)) {
303 /* Dump the error history since recipe execution start.
304 At this point the recipe cannot recover from the error */
305 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
306 }
307 return recipe_status;
308}
309
310/*----------------------------------------------------------------------------*/
316/*----------------------------------------------------------------------------*/
317
318static int
319_moons_science_starenod2_destroy(cpl_plugin *plugin)
320{
321 cpl_recipe *recipe;
322 if (plugin == NULL) {
323 cpl_msg_error(cpl_func, "Null plugin");
324 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
325 }
326 /* Verify plugin type */
327 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
328 cpl_msg_error(cpl_func, "Plugin is not a recipe");
329 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
330 }
331 /* Get the recipe */
332 recipe = (cpl_recipe *)plugin;
333 cpl_parameterlist_delete(recipe->parameters);
334 return 0;
335}
336
337static cpl_error_code
338_moons_science_starenod2_check_sof(
339 cpl_frameset *frameset,
340 cpl_frameset *offset_frameset,
341 const char **bpmap_rp_name,
342 const char **bpmap_nl_name,
343 const cpl_frame **masterbias,
344 const cpl_frame **masterdark_vis,
345 cpl_frameset *masterdark_nir,
346 const cpl_frame **p2pmap,
347 const cpl_frame **sformat,
348 const cpl_frame **sky_lines,
349 const cpl_frame **atmo,
350 const cpl_frame **resp,
351 const cpl_frame **tell,
352 const cpl_frame **airglow_group,
353 const cpl_frame **airglow_var,
354 const cpl_frame **solflux,
355 const moo_sub_sky_stare_params *subsky_params)
356{
357 cpl_ensure_code(moo_dfs_set_groups(frameset) == CPL_ERROR_NONE,
358 cpl_error_get_code());
359 int i;
360 int nb_sky = 0;
361 int nb_stare = 0;
362 int nb_starenod = 0;
363
364 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
365 cpl_frame *current_frame = cpl_frameset_get_position(frameset, i);
366 if (!strcmp(cpl_frame_get_tag(current_frame),
367 MOONS_TAG_OBJECT_STARENOD)) {
368 cpl_frameset_insert(offset_frameset,
369 cpl_frame_duplicate(current_frame));
370 nb_starenod++;
371 }
372 else if (!strcmp(cpl_frame_get_tag(current_frame),
373 MOONS_TAG_OBJECT_STARE)) {
374 cpl_frameset_insert(offset_frameset,
375 cpl_frame_duplicate(current_frame));
376 nb_stare++;
377 }
378 else if (!strcmp(cpl_frame_get_tag(current_frame),
379 MOONS_TAG_SKY_STARENOD)) {
380 cpl_frameset_insert(offset_frameset,
381 cpl_frame_duplicate(current_frame));
382 nb_sky++;
383 }
384 else if (!strcmp(cpl_frame_get_tag(current_frame),
385 MOONS_TAG_BP_MAP_RP)) {
386 *bpmap_rp_name = cpl_frame_get_filename(current_frame);
387 }
388 else if (!strcmp(cpl_frame_get_tag(current_frame),
389 MOONS_TAG_BP_MAP_NL)) {
390 *bpmap_nl_name = cpl_frame_get_filename(current_frame);
391 }
392 else if (!strcmp(cpl_frame_get_tag(current_frame),
393 MOONS_TAG_MASTER_BIAS)) {
394 *masterbias = current_frame;
395 }
396 else if (!strcmp(cpl_frame_get_tag(current_frame),
397 MOONS_TAG_MASTER_DARK_VIS)) {
398 *masterdark_vis = current_frame;
399 }
400 else if (!strcmp(cpl_frame_get_tag(current_frame),
401 MOONS_TAG_MASTER_DARK_NIR)) {
402 cpl_frameset_insert(masterdark_nir,
403 cpl_frame_duplicate(current_frame));
404 }
405 else if (!strcmp(cpl_frame_get_tag(current_frame),
406 MOONS_TAG_MASTER_FLAT)) {
407 cpl_frameset_insert(offset_frameset,
408 cpl_frame_duplicate(current_frame));
409 }
410 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_P2P_MAP)) {
411 *p2pmap = current_frame;
412 }
413 else if (!strcmp(cpl_frame_get_tag(current_frame),
414 MOONS_TAG_FF_TRACE)) {
415 cpl_frameset_insert(offset_frameset,
416 cpl_frame_duplicate(current_frame));
417 }
418 else if (!strcmp(cpl_frame_get_tag(current_frame),
419 MOONS_TAG_LINEARITY_COEFF_CUBE)) {
420 cpl_frameset_insert(offset_frameset,
421 cpl_frame_duplicate(current_frame));
422 }
423 else if (!strcmp(cpl_frame_get_tag(current_frame),
424 MOONS_TAG_SPECTRAL_FORMAT)) {
425 *sformat = current_frame;
426 }
427 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_WAVEMAP)) {
428 cpl_frameset_insert(offset_frameset,
429 cpl_frame_duplicate(current_frame));
430 }
431 else if (!strcmp(cpl_frame_get_tag(current_frame),
432 MOONS_TAG_SKY_LINE_LIST)) {
433 *sky_lines = current_frame;
434 }
435 else if (!strcmp(cpl_frame_get_tag(current_frame),
436 MOONS_TAG_FF_EXTSPECTRA)) {
437 cpl_frameset_insert(offset_frameset,
438 cpl_frame_duplicate(current_frame));
439 }
440 else if (!strcmp(cpl_frame_get_tag(current_frame),
441 MOONS_TAG_F2F_TABLE)) {
442 cpl_frameset_insert(offset_frameset,
443 cpl_frame_duplicate(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_RESPONSE)) {
451 *resp = current_frame;
452 }
453 else if (!strcmp(cpl_frame_get_tag(current_frame),
454 MOONS_TAG_TELLURIC_CORR)) {
455 *tell = current_frame;
456 }
457 else if (!strcmp(cpl_frame_get_tag(current_frame),
458 MOONS_TAG_AIRGLOW_GROUP)) {
459 *airglow_group = current_frame;
460 }
461 else if (!strcmp(cpl_frame_get_tag(current_frame),
462 MOONS_TAG_AIRGLOW_VAR)) {
463 *airglow_var = current_frame;
464 }
465 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_SOLFLUX)) {
466 *solflux = current_frame;
467 }
468 }
469 if (nb_stare > 0 && nb_starenod > 0) {
470 return (int)cpl_error_set_message(
471 cpl_func, CPL_ERROR_DATA_NOT_FOUND,
472 "SOF have mixed file tags STARE and STARENOD");
473 }
474 if (nb_stare > 0 && nb_sky > 0) {
475 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
476 "remove SKY from sof");
477 }
478 if (nb_starenod > 0 && nb_sky <= 0) {
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_SKY_STARENOD);
483 }
484 if (*sformat == NULL) {
485 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
486 "SOF does not have any file tagged "
487 "with %s",
488 MOONS_TAG_SPECTRAL_FORMAT);
489 }
490 if (*sky_lines == NULL) {
491 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
492 "SOF does not have any file tagged "
493 "with %s",
494 MOONS_TAG_SKY_LINE_LIST);
495 }
496 if (*airglow_group == NULL &&
497 strcmp(subsky_params->method, MOO_SUB_SKY_STARE_METHOD_SKYCORR) == 0) {
498 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
499 "SOF does not have any file tagged "
500 "with %s",
501 MOONS_TAG_AIRGLOW_GROUP);
502 }
503 if (*airglow_var == NULL &&
504 strcmp(subsky_params->method, MOO_SUB_SKY_STARE_METHOD_SKYCORR) == 0) {
505 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
506 "SOF does not have any file tagged "
507 "with %s",
508 MOONS_TAG_AIRGLOW_VAR);
509 }
510 if (*solflux == NULL &&
511 strcmp(subsky_params->method, MOO_SUB_SKY_STARE_METHOD_SKYCORR) == 0) {
512 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
513 "SOF does not have any file tagged "
514 "with %s",
515 MOONS_TAG_SOLFLUX);
516 }
517 return CPL_ERROR_NONE;
518}
519
520static cpl_error_code
521_moons_science_starenod2_check_sof_byoffset(
522 cpl_frameset *frameset,
523 cpl_frameset *object_frameset,
524 cpl_frameset *sky_frameset,
525 const cpl_frame **master_flat,
526 const cpl_frame **fftrace,
527 const cpl_frame **coeffs_cube,
528 const cpl_frame **wmap,
529 const cpl_frame **flat,
530 const cpl_frame **f2f,
531 moo_extract_params *ext_params,
532 moo_sub_sky_stare_params *sky_params,
534{
535 cpl_ensure_code(moo_dfs_set_groups(frameset) == CPL_ERROR_NONE,
536 cpl_error_get_code());
537 int nb_object = 0;
538 int nb_stare = 0;
539 int nb_sky = 0;
540 int i;
541 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
542 cpl_frame *current_frame = cpl_frameset_get_position(frameset, i);
543 if (!strcmp(cpl_frame_get_tag(current_frame),
544 MOONS_TAG_OBJECT_STARENOD)) {
545 cpl_frameset_insert(object_frameset,
546 cpl_frame_duplicate(current_frame));
547 nb_object++;
548 }
549 else if (!strcmp(cpl_frame_get_tag(current_frame),
550 MOONS_TAG_OBJECT_STARE)) {
551 cpl_frameset_insert(object_frameset,
552 cpl_frame_duplicate(current_frame));
553 nb_stare++;
554 nb_object++;
555 }
556 else if (!strcmp(cpl_frame_get_tag(current_frame),
557 MOONS_TAG_SKY_STARENOD)) {
558 cpl_frameset_insert(sky_frameset,
559 cpl_frame_duplicate(current_frame));
560 nb_sky++;
561 }
562 else if (!strcmp(cpl_frame_get_tag(current_frame),
563 MOONS_TAG_MASTER_FLAT)) {
564 *master_flat = current_frame;
565 }
566 else if (!strcmp(cpl_frame_get_tag(current_frame),
567 MOONS_TAG_FF_TRACE)) {
568 *fftrace = current_frame;
569 }
570 else if (!strcmp(cpl_frame_get_tag(current_frame),
571 MOONS_TAG_LINEARITY_COEFF_CUBE)) {
572 *coeffs_cube = current_frame;
573 }
574 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_WAVEMAP)) {
575 *wmap = current_frame;
576 }
577 else if (!strcmp(cpl_frame_get_tag(current_frame),
578 MOONS_TAG_FF_EXTSPECTRA)) {
579 *flat = current_frame;
580 }
581 else if (!strcmp(cpl_frame_get_tag(current_frame),
582 MOONS_TAG_F2F_TABLE)) {
583 *f2f = current_frame;
584 }
585 }
586
587 if (nb_object <= 0) {
588 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
589 "SOF does not have any file tagged "
590 "with %s",
591 MOONS_TAG_OBJECT_STARENOD);
592 }
593
594 if (nb_stare > 0) {
595 *mode = MOO_MODE_STARE;
596 cpl_msg_info("test", "Recipe running in STARE mode");
597 }
598 else {
599 *mode = MOO_MODE_STARENOD;
600 cpl_msg_info("test", "Recipe running in STARENOD mode");
601 }
602
603 if (*mode == MOO_MODE_STARENOD) {
604 if (nb_sky == 0) {
605 return (int)cpl_error_set_message(
606 cpl_func, CPL_ERROR_DATA_NOT_FOUND,
607 "SOF (filter by offset) does not have any file tagged "
608 "with %s",
609 MOONS_TAG_SKY_STARENOD);
610 }
611 if (strcmp(sky_params->method, MOO_SUB_SKY_STARE_METHOD_NONE) == 0) {
612 return (int)cpl_error_set_message(
613 cpl_func, CPL_ERROR_DATA_NOT_FOUND,
614 "sky subtraction NONE method not allowed in STARENOD");
615 }
616 }
617
618 if (*fftrace == NULL) {
619 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
620 "SOF does not have any file tagged "
621 "with %s",
622 MOONS_TAG_FF_TRACE);
623 }
624 if (*wmap == NULL) {
625 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
626 "SOF does not have any file tagged "
627 "with %s",
628 MOONS_TAG_WAVEMAP);
629 }
630 if (*flat == NULL) {
631 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
632 "SOF does not have any file tagged "
633 "with %s",
634 MOONS_TAG_FF_EXTSPECTRA);
635 }
636 if (*master_flat == NULL &&
637 strcmp(ext_params->method, MOO_EXTRACT_METHOD_OPTIMAL) == 0) {
638 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
639 "SOF does not have any file tagged "
640 "with %s",
641 MOONS_TAG_MASTER_FLAT);
642 }
643
644 return CPL_ERROR_NONE;
645}
646
647static cpl_error_code
648_moons_p2pmap(moo_det *arc, const cpl_frame *p2pmap)
649{
650 cpl_error_code status = CPL_ERROR_NONE;
651 moo_det *p2p = NULL;
652 if (p2pmap != NULL) {
653 moo_try_check(p2p = moo_det_create(p2pmap), " ");
654 moo_try_check(moo_apply_p2p(arc, p2p), " ");
655 }
656moo_try_cleanup:
657 moo_det_delete(p2p);
658 return status;
659}
660
661static cpl_error_code
662_moons_apply_flat(moo_ext *ext,
663 const cpl_frame *flat_frame,
664 const cpl_frame *f2f_frame)
665{
666 cpl_error_code status = CPL_ERROR_NONE;
667 moo_ext *flat = NULL;
668 moo_f2f *f2f = NULL;
669 moo_try_check(flat = moo_ext_create(flat_frame), " ");
670 if (f2f_frame != NULL) {
671 f2f = moo_f2f_load(f2f_frame);
672 }
673 moo_try_check(moo_apply_flat(ext, flat, f2f), " ");
674moo_try_cleanup:
675 moo_ext_delete(flat);
676 moo_f2f_delete(f2f);
677 return status;
678}
679
680static cpl_frame *
681_moons_starenod_rebin(int inum,
682 const char *mode,
683 int offset,
684 moo_ext *ext,
685 const cpl_frame *ref_frame,
686 moo_spectral_format *sformat,
687 moo_sky_lines_list *sky_lines,
688 moo_map *wmap,
689 const cpl_frame *atmo_frame,
690 const cpl_frame *resp_frame,
691 const cpl_frame *tell_frame,
692 moo_rebin_params *rbn_params,
693 moo_products *products,
694 const char *prefix)
695{
696 cpl_frame *rbn_frame = NULL;
697 moo_atm *atm = NULL;
698 moo_resp *resp = NULL;
699 moo_telluric *telluric = NULL;
700 moo_rbn *rbn = NULL;
701
702 char *rbn_filename = NULL;
703 char *calibflux_filename = NULL;
704 char *tellcorr_filename = NULL;
705
706 cpl_ensure(ext != NULL, CPL_ERROR_NULL_INPUT, NULL);
707 cpl_ensure(ref_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
708
709 rbn_filename = cpl_sprintf("%s_RBNSPECTRA_OFFSET%d_%s_%d.fits", prefix,
710 offset, mode, inum);
711 moo_try_check(rbn = moo_rebin(ext, wmap, sformat, rbn_params, rbn_filename),
712 " ");
713 moo_try_check(moo_rbn_compute_snr(rbn, sky_lines), " ");
714 moo_try_check(
715 rbn_frame = moo_products_add_rbn(products, rbn, CPL_FRAME_LEVEL_FINAL,
716 MOONS_TAG_SCIENCE_STARENOD_RBNSPECTRA,
717 rbn_filename, ref_frame),
718 " ");
719
720 if (atmo_frame != NULL && resp_frame != NULL) {
721 moo_try_check(atm = moo_atm_load(atmo_frame), " ");
722 moo_try_check(resp = moo_resp_load(resp_frame), " ");
723
724 calibflux_filename = cpl_sprintf("%s_RBNFLXSPECTRA_OFFSET%d_%s_%d.fits",
725 prefix, offset, mode, inum);
726 moo_try_check(moo_calib_flux(rbn, atm, resp), " ");
727 moo_try_check(rbn_frame = moo_products_add_rbn(
728 products, rbn, CPL_FRAME_LEVEL_FINAL,
729 MOONS_TAG_SCIENCE_STARENOD_RBNFLXSPECTRA,
730 calibflux_filename, ref_frame),
731 " ");
732 }
733 else {
734 cpl_msg_info(__func__, "No flux calibration");
735 }
736
737 if (tell_frame != NULL) {
738 moo_try_check(telluric = moo_telluric_load(tell_frame), " ");
739
740 tellcorr_filename =
741 cpl_sprintf("%s_RBNTELLCORRSPECTRA_OFFSET%d_%s_%d.fits", prefix,
742 offset, mode, inum);
743 moo_try_check(moo_correct_tell(rbn, telluric), " ");
744 moo_try_check(rbn_frame = moo_products_add_rbn(
745 products, rbn, CPL_FRAME_LEVEL_FINAL,
746 MOONS_TAG_SCIENCE_STARENOD_RBNTELLCORRSPECTRA,
747 tellcorr_filename, ref_frame),
748 " ");
749 }
750 else {
751 cpl_msg_info(__func__, "No telluric correction");
752 }
753
754moo_try_cleanup:
755 cpl_free(tellcorr_filename);
756 cpl_free(calibflux_filename);
757 cpl_free(rbn_filename);
758 moo_atm_delete(atm);
759 moo_resp_delete(resp);
760 moo_telluric_delete(telluric);
761 moo_rbn_delete(rbn);
762 return rbn_frame;
763}
764
765static moo_sci *
766_moons_sub_sky_stare(moo_rbn *rbn,
767 moo_target_table *target_table,
768 const cpl_frame *f2f_frame,
769 const cpl_frame *solflux_frame,
770 const cpl_frame *airglow_group_frame,
771 const cpl_frame *airglow_var_frame,
772 moo_sub_sky_stare_params *sky_params,
773 const char *sci_filename)
774{
775 moo_sci *result = NULL;
776 moo_f2f *f2f = NULL;
777
778 if (f2f_frame != NULL) {
779 f2f = moo_f2f_load(f2f_frame);
780 }
781 moo_try_check(result =
782 moo_sub_sky_stare(rbn, target_table, rbn, f2f,
783 solflux_frame, airglow_group_frame,
784 airglow_var_frame, sky_params,
785 sci_filename, MOO_SCI1D_NOT_PAIRED),
786 " ");
787
788moo_try_cleanup:
789 moo_f2f_delete(f2f);
790 return result;
791}
792
793static cpl_frame *
794_moons_stare_sci(int inum,
795 const char *mode,
796 int offset,
797 const cpl_frame *ref_frame,
798 const cpl_frame *rbn_frame,
799 moo_sky_lines_list *sky_lines,
800 const cpl_frame *f2f_frame,
801 const cpl_frame *airglow_group_frame,
802 const cpl_frame *airglow_var_frame,
803 const cpl_frame *solflux_frame,
804 moo_target_table_params *target_table_params,
805 moo_sub_sky_stare_params *sky_params,
806 moo_products *products,
807 const char *prefix)
808{
809 cpl_frame *sci_frame = NULL;
810 moo_rbn *rbn = NULL;
811 moo_target_table *target_table = NULL;
812 moo_sci *sci = NULL;
813
814 char *ttable_filename = NULL;
815 char *sci_filename = NULL;
816
817 cpl_ensure(rbn_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
818 cpl_ensure(ref_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
819 rbn = moo_rbn_create(rbn_frame);
820
821 moo_try_check(target_table =
822 moo_create_target_table(rbn, NULL, MOO_MODE_STARE,
823 target_table_params),
824 " ");
825 ttable_filename = cpl_sprintf("%s_TARGET_TABLE_OFFSET%d_%s_%d.fits", prefix,
826 offset, mode, inum);
827 moo_try_check(moo_products_add_target_table(
828 products, target_table, CPL_FRAME_LEVEL_INTERMEDIATE,
829 MOONS_TAG_SCIENCE_STARENOD_TARGET_TABLE, ttable_filename,
830 ref_frame),
831 " ");
832
833 sci_filename =
834 cpl_sprintf("%s_SCI_OFFSET%d_%s_%d.fits", prefix, offset, mode, inum);
835
836 moo_try_check(sci = _moons_sub_sky_stare(rbn, target_table, f2f_frame,
837 solflux_frame, airglow_group_frame,
838 airglow_var_frame, sky_params,
839 sci_filename),
840 " ");
841 moo_try_check(moo_sci_compute_snr(sci, sky_lines), " ");
842
843 moo_try_check(
844 sci_frame = moo_products_add_sci(products, sci, CPL_FRAME_LEVEL_FINAL,
845 MOONS_TAG_SCIENCE_STARENOD_SKSSPECTRA,
846 sci_filename, ref_frame),
847 " ");
848
849moo_try_cleanup:
850 cpl_free(ttable_filename);
851 cpl_free(sci_filename);
852 moo_target_table_delete(target_table);
853 moo_sci_delete(sci);
854 moo_rbn_delete(rbn);
855 return sci_frame;
856}
857
858static cpl_frame *
859_moons_starenod_sci1d(int inum,
860 const char *mode,
861 int offset,
862 const cpl_frame *obj_frame,
863 const cpl_frame *obj_rbn_frame,
864 const cpl_frame *sky_rbn_frame,
865 moo_sky_lines_list *sky_lines,
866 const cpl_frame *f2f_frame,
867 const cpl_frame *airglow_group_frame,
868 const cpl_frame *airglow_var_frame,
869 const cpl_frame *solflux_frame,
870 moo_target_table *target_table,
871 moo_sub_sky_stare_params *sky_params,
872 moo_products *products,
873 const char *prefix)
874{
875 cpl_frame *result = NULL;
876 moo_rbn *sky_rbn = NULL;
877 moo_rbn *obj_rbn = NULL;
878 moo_sci *sci1d = NULL;
879 moo_f2f *f2f = NULL;
880
881 char *sci1d_filename = NULL;
882
883 cpl_ensure(obj_rbn_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
884 cpl_ensure(sky_rbn_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
885
886 cpl_errorstate prestate = cpl_errorstate_get();
887
888 moo_try_check(obj_rbn = moo_rbn_create(obj_rbn_frame), " ");
889 moo_try_check(sky_rbn = moo_rbn_create(sky_rbn_frame), " ");
890
891 sci1d_filename =
892 cpl_sprintf("%s_SCI1D_OFFSET%d_%s_%d.fits", prefix, offset, mode, inum);
893
894 if (f2f_frame != NULL) {
895 f2f = moo_f2f_load(f2f_frame);
896 }
897 moo_try_check(sci1d =
898 moo_sub_sky_stare(obj_rbn, target_table, sky_rbn, f2f,
899 solflux_frame, airglow_group_frame,
900 airglow_var_frame, sky_params,
901 sci1d_filename, MOO_SCI1D_NOT_PAIRED),
902 " ");
903
904 moo_try_check(moo_sci_compute_snr(sci1d, sky_lines), " ");
905
906 moo_try_check(
907 result = moo_products_add_sci(products, sci1d, CPL_FRAME_LEVEL_FINAL,
908 MOONS_TAG_SCIENCE_STARENOD_SKSSPECTRA,
909 sci1d_filename, obj_frame),
910 " ");
911
912moo_try_cleanup:
913 if (!cpl_errorstate_is_equal(prestate)) {
914 cpl_frame_delete(result);
915 result = NULL;
916 }
917 cpl_free(sci1d_filename);
918 moo_sci_delete(sci1d);
919 moo_rbn_delete(sky_rbn);
920 moo_rbn_delete(obj_rbn);
921 moo_f2f_delete(f2f);
922 return result;
923}
924
925static cpl_frame *
926_moons_starenod_sci2d(const char *mode,
927 int offset,
928 const cpl_frame *ref_frame,
929 const cpl_frame *nod_rbn_frame,
930 cpl_frameset *sky_rbn_frameset,
931 moo_sky_lines_list *sky_lines,
932 moo_target_table *target_table,
933 moo_products *products,
934 const char *prefix)
935{
936 cpl_frame *result = NULL;
937 moo_rbn *nod_rbn = NULL;
938 moo_rbn *sky_rbn = NULL;
939 moo_rbnlist *sky_rbnlist = NULL;
940 moo_sci *sci2d = NULL;
941 char *sci2d_filename = NULL;
942
943 cpl_ensure(nod_rbn_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
944 cpl_ensure(sky_rbn_frameset != NULL, CPL_ERROR_NULL_INPUT, NULL);
945
946 cpl_errorstate prestate = cpl_errorstate_get();
947
948 moo_try_check(nod_rbn = moo_rbn_create(nod_rbn_frame), " ");
949 moo_try_check(sky_rbnlist = moo_rbnlist_create(sky_rbn_frameset), " ");
950 moo_try_check(sky_rbn = moo_combine_sky(sky_rbnlist), " ");
951
952 sci2d_filename =
953 cpl_sprintf("%s_SCI2D_OFFSET%d_%s.fits", prefix, offset, mode);
954
955 moo_try_check(sci2d =
956 moo_create_sci2d(nod_rbn, sky_rbn, NULL, target_table,
957 MOO_SCI2D_NOT_PAIRED, sci2d_filename),
958 " ");
959
960 moo_try_check(moo_sci_compute_snr(sci2d, sky_lines), " ");
961
962 moo_try_check(
963 result = moo_products_add_sci(products, sci2d, CPL_FRAME_LEVEL_FINAL,
964 MOONS_TAG_SCIENCE_STARENOD_SKSSPECTRA,
965 sci2d_filename, ref_frame),
966 " ");
967
968moo_try_cleanup:
969 if (!cpl_errorstate_is_equal(prestate)) {
970 cpl_frame_delete(result);
971 result = NULL;
972 }
973 cpl_free(sci2d_filename);
974 moo_sci_delete(sci2d);
975 moo_rbn_delete(nod_rbn);
976 moo_rbn_delete(sky_rbn);
977 moo_rbnlist_delete(sky_rbnlist);
978 return result;
979}
980
981static const cpl_frame *
982find_masterdark_nir(moo_det *det, cpl_frameset *set)
983{
984 const cpl_frame *result = NULL;
985 double dit = 0.0;
986 int ndit = 0;
987 double exptime = 0.0;
988 int num;
989 int type;
990 int find = 0;
991 moo_det *current_det = NULL;
992
993 cpl_ensure(det != NULL, CPL_ERROR_NULL_INPUT, NULL);
994
995 for (num = 1; num <= 2; num++) {
996 for (type = 1; type <= 2; type++) {
997 moo_single *single = moo_det_get_single(det, type, num);
998 if (single != NULL) {
999 moo_try_check(ndit = moo_pfits_get_ndit(single->header), " ");
1000 moo_try_check(dit = moo_pfits_get_dit(single->header), " ");
1001 exptime = dit * ndit;
1002 find = 1;
1003 break;
1004 }
1005 }
1006 if (find) {
1007 break;
1008 }
1009 }
1010
1011 if (find && set != NULL) {
1012 int size = cpl_frameset_get_size(set);
1013 for (int i = 0; i < size; i++) {
1014 const cpl_frame *current = cpl_frameset_get_position_const(set, i);
1015 current_det = moo_det_create(current);
1016 moo_single *current_single =
1017 moo_det_get_single(current_det, type, num);
1018 moo_try_check(ndit = moo_pfits_get_ndit(current_single->header),
1019 " ");
1020 moo_try_check(dit = moo_pfits_get_dit(current_single->header), " ");
1021 double current_exptime = dit * ndit;
1022 if (fabs(exptime - current_exptime) <= 1E-9) {
1023 result = current;
1024 break;
1025 }
1026 moo_det_delete(current_det);
1027 current_det = NULL;
1028 }
1029 }
1030 if (result != NULL) {
1031 cpl_msg_info(__func__, "Find MASTER_DARK_NIR for exptime %f : %s",
1032 exptime, cpl_frame_get_filename(result));
1033 }
1034 else {
1035 cpl_msg_warning(__func__, "MASTER_DARK_NIR not found for exptime %f",
1036 exptime);
1037 }
1038moo_try_cleanup:
1039 moo_det_delete(current_det);
1040 return result;
1041}
1042
1043static cpl_frame *
1044_moons_starenod_subtractnod(int inum,
1045 const char *mode,
1046 int offset,
1047 const cpl_frame *obj_frame,
1048 const cpl_frame *obj_det_frame,
1049 const cpl_frame *sky_det_frame,
1050 moo_products *products)
1051{
1052 cpl_frame *result = NULL;
1053 char *nod_det_filename = NULL;
1054 moo_det *nod_det = NULL;
1055 unsigned int badpix_level = MOO_BADPIX_GOOD;
1056
1057 moo_det *obj_det = moo_det_create(obj_det_frame);
1058 moo_det *sky_det = moo_det_create(sky_det_frame);
1059 moo_try_check(moo_det_load(obj_det, badpix_level), " ");
1060 moo_try_check(moo_det_load(sky_det, badpix_level), " ");
1061
1062 nod_det_filename =
1063 cpl_sprintf("%s_OFFSET%d_%s_%d.fits", MOONS_TAG_STARENOD_SUBTRACTNOD,
1064 offset, mode, inum);
1065
1066 moo_try_check(nod_det =
1067 moo_subtract_nod(obj_det, sky_det, nod_det_filename),
1068 " ");
1069 moo_try_check(result = moo_products_add(products, nod_det,
1070 CPL_FRAME_LEVEL_INTERMEDIATE,
1071 MOONS_TAG_STARENOD_SUBTRACTNOD,
1072 nod_det_filename, obj_frame),
1073 " ");
1074
1075moo_try_cleanup:
1076 cpl_free(nod_det_filename);
1077 moo_det_delete(obj_det);
1078 moo_det_delete(sky_det);
1079 moo_det_delete(nod_det);
1080
1081 return result;
1082}
1083
1084static cpl_frame *
1085_moons_starenod_prepare(int inum,
1086 const char *mode,
1087 int offset,
1088 const cpl_frame *frame,
1089 const char *bpmap_rp_name,
1090 const char *bpmap_nl_name,
1091 const cpl_frame *masterbias,
1092 const cpl_frame *masterdark_vis,
1093 cpl_frameset *masterdark_nir_frameset,
1094 const cpl_frame *p2pmap,
1095 const cpl_frame *coeffs_cube,
1096 moo_prepare_params *prepare_params,
1097 moo_correct_bias_params *cbias_params,
1098 moo_products *products,
1099 int objtype)
1100{
1101 cpl_frame *result = NULL;
1102 const cpl_frame *masterdark_nir = NULL;
1103 moo_det *det = NULL;
1104 char *det_filename = NULL;
1105 char *det_p2p_filename = NULL;
1106 const char *det_tags[] = { MOONS_TAG_STARENOD_OBJ_CORRECTDARK,
1107 MOONS_TAG_STARENOD_SKY_CORRECTDARK };
1108 const char *detp2p_tags[] = { MOONS_TAG_STARENOD_OBJ_APPLYP2P,
1109 MOONS_TAG_STARENOD_SKY_APPLYP2P };
1110
1111 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
1112
1113 moo_try_check(det = moo_prepare(frame, bpmap_rp_name, bpmap_nl_name,
1114 masterbias, coeffs_cube, prepare_params),
1115 " ");
1116 moo_try_check(moo_correct_bias(det, masterbias, cbias_params), " ");
1117
1118 masterdark_nir = find_masterdark_nir(det, masterdark_nir_frameset);
1119
1120 moo_try_check(moo_correct_dark(det, NULL, masterdark_vis, masterdark_nir),
1121 " ");
1122 det_filename = cpl_sprintf("%s_OFFSET%d_%s_%d.fits", det_tags[objtype],
1123 offset, mode, inum);
1124 moo_try_check(moo_products_add(products, det, CPL_FRAME_LEVEL_INTERMEDIATE,
1125 det_tags[objtype], det_filename, frame),
1126 " ");
1127 moo_try_check(_moons_p2pmap(det, p2pmap), " ");
1128 det_p2p_filename = cpl_sprintf("%s_OFFSET%d_%s_%d.fits",
1129 detp2p_tags[objtype], offset, mode, inum);
1130 moo_try_check(result = moo_products_add(products, det,
1131 CPL_FRAME_LEVEL_INTERMEDIATE,
1132 detp2p_tags[objtype],
1133 det_p2p_filename, frame),
1134 " ");
1135
1136moo_try_cleanup:
1137 cpl_free(det_filename);
1138 cpl_free(det_p2p_filename);
1139 moo_det_delete(det);
1140 return result;
1141}
1142
1143static cpl_frame *
1144_moons_starenod_extract(int inum,
1145 const char *mode,
1146 int offset,
1147 const cpl_frame *ref_frame,
1148 const cpl_frame *det_frame,
1149 moo_loc *loc,
1150 moo_map *wmap,
1151 moo_spectral_format *sformat,
1152 moo_sky_lines_list *skylines,
1153 const cpl_frame *masterflat_frame,
1154 const cpl_frame *flat_frame,
1155 const cpl_frame *f2f_frame,
1156 moo_extract_params *extract_params,
1157 moo_products *products,
1158 const char *prefix)
1159{
1160 cpl_frame *ext_frame = NULL;
1161 moo_det *det = NULL;
1162 moo_psf *psf = NULL;
1163 moo_ext *ext = NULL;
1164
1165 char *ext_filename = NULL;
1166 char *extff_filename = NULL;
1167
1168 cpl_ensure(det_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
1169 det = moo_det_create(det_frame);
1170 ext_filename = cpl_sprintf("%s_EXTSPECTRA_OFFSET%d_%s_%d.fits", prefix,
1171 offset, mode, inum);
1172 if (masterflat_frame != NULL) {
1173 psf = moo_psf_load(masterflat_frame);
1174 }
1175
1176 moo_try_check(ext =
1177 moo_extract(det, loc, psf, extract_params, ext_filename),
1178 " ");
1179 moo_try_check(ext_frame = moo_products_add_ext(
1180 products, ext, CPL_FRAME_LEVEL_INTERMEDIATE,
1181 MOONS_TAG_SCIENCE_STARENOD_EXTSPECTRA, ext_filename,
1182 ref_frame),
1183 " ");
1184
1185 moo_try_check(_moons_apply_flat(ext, flat_frame, f2f_frame), " ");
1186 moo_try_check(moo_ext_compute_snr(ext, wmap, sformat, skylines), " ");
1187 extff_filename = cpl_sprintf("%s_EXTFFSPECTRA_OFFSET%d_%s_%d.fits", prefix,
1188 offset, mode, inum);
1189
1190 moo_try_check(ext_frame = moo_products_add_ext(
1191 products, ext, CPL_FRAME_LEVEL_INTERMEDIATE,
1192 MOONS_TAG_SCIENCE_STARENOD_EXTSPECTRA, extff_filename,
1193 ref_frame),
1194 " ");
1195
1196moo_try_cleanup:
1197 cpl_free(ext_filename);
1198 cpl_free(extff_filename);
1199 moo_det_delete(det);
1200 moo_ext_delete(ext);
1201 moo_psf_delete(psf);
1202 return ext_frame;
1203}
1204
1205static int
1206_moons_sort_mjdobs(const cpl_frame *a, const cpl_frame *b)
1207{
1208 int res = 0;
1209
1210 const char *filenameA = cpl_frame_get_filename(a);
1211 const char *filenameB = cpl_frame_get_filename(b);
1212
1213 cpl_propertylist *lista = cpl_propertylist_load(filenameA, 0);
1214 cpl_propertylist *listb = cpl_propertylist_load(filenameB, 0);
1215
1216 if (cpl_propertylist_has(lista, MOO_PFITS_MJDOBS) &&
1217 cpl_propertylist_has(listb, MOO_PFITS_MJDOBS)) {
1218 double mjdA = moo_pfits_get_mjdobs(lista);
1219 double mjdB = moo_pfits_get_mjdobs(listb);
1220 if (mjdA < mjdB) {
1221 res = -1;
1222 }
1223 else if (mjdA > mjdB) {
1224 res = 1;
1225 }
1226 else {
1227 res = 0;
1228 }
1229 }
1230 cpl_propertylist_delete(listb);
1231 cpl_propertylist_delete(lista);
1232 return res;
1233}
1234
1235static int
1236_moons_compare_offset(const cpl_frame *a, const cpl_frame *b)
1237{
1238 int res = 0;
1239 const char *filenameA = cpl_frame_get_filename(a);
1240 cpl_propertylist *lista = cpl_propertylist_load(filenameA, 0);
1241
1242 double oA = moo_pfits_get_slit_offset(lista);
1243 const char *filenameB = cpl_frame_get_filename(b);
1244 cpl_propertylist *listb = cpl_propertylist_load(filenameB, 0);
1245
1246 double oB = moo_pfits_get_slit_offset(listb);
1247 if (fabs(oA - oB) < 1E-12) {
1248 res = 1;
1249 }
1250
1251 cpl_propertylist_delete(lista);
1252 cpl_propertylist_delete(listb);
1253 return res;
1254}
1255
1256static int
1257_starenod_getsky_index(const cpl_frame *obj_frame,
1258 const cpl_frameset *sky_frameset)
1259{
1260 int result = 0;
1261
1262 cpl_ensure(obj_frame != NULL, CPL_ERROR_NULL_INPUT, 0);
1263 cpl_ensure(sky_frameset != NULL, CPL_ERROR_NULL_INPUT, 0);
1264
1265 const char *obj_filename = cpl_frame_get_filename(obj_frame);
1266 cpl_propertylist *obj_list = cpl_propertylist_load(obj_filename, 0);
1267 double obj_mjd = moo_pfits_get_mjdobs(obj_list);
1268 double odiff = -1;
1269 int size = cpl_frameset_get_size(sky_frameset);
1270 for (int i = 0; i < size; i++) {
1271 const cpl_frame *sky_frame =
1272 cpl_frameset_get_position_const(sky_frameset, i);
1273 const char *sky_filename = cpl_frame_get_filename(sky_frame);
1274 cpl_propertylist *sky_list = cpl_propertylist_load(sky_filename, 0);
1275 double sky_mjd = moo_pfits_get_mjdobs(sky_list);
1276 double diff = fabs(sky_mjd - obj_mjd);
1277 if (odiff < 0) {
1278 odiff = diff;
1279 }
1280 else if (odiff > diff) {
1281 odiff = diff;
1282 result = i;
1283 }
1284 cpl_propertylist_delete(sky_list);
1285 }
1286 cpl_propertylist_delete(obj_list);
1287 return result;
1288}
1289
1290static cpl_frame *
1291_starenod_nod_rebin(cpl_frameset *det_frameset,
1292 const char *mode,
1293 int offset,
1294 const cpl_frame *ref_frame,
1295 moo_loc *loc,
1296 moo_map *wmap,
1297 moo_spectral_format *sformat,
1298 moo_sky_lines_list *skylines,
1299 const cpl_frame *masterflat_frame,
1300 const cpl_frame *flat_frame,
1301 const cpl_frame *f2f_frame,
1302 const cpl_frame *atmo_frame,
1303 const cpl_frame *resp_frame,
1304 const cpl_frame *tell_frame,
1305 moo_extract_params *extract_params,
1306 moo_rebin_params *rbn_params,
1307 moo_products *products,
1308 const char *prefix)
1309{
1310 cpl_frame *result = NULL;
1311 moo_detlist *detlist = NULL;
1312 moo_det *combined = NULL;
1313
1314 moo_psf *psf = NULL;
1315 moo_ext *ext = NULL;
1316 moo_crh_params *crh_params = NULL;
1317 moo_atm *atm = NULL;
1318 moo_resp *resp = NULL;
1319 moo_telluric *telluric = NULL;
1320 moo_rbn *rbn = NULL;
1321
1322 char *comb_filename = NULL;
1323 char *ext_filename = NULL;
1324 char *extff_filename = NULL;
1325
1326 char *rbn_filename = NULL;
1327 char *calibflux_filename = NULL;
1328 char *tellcorr_filename = NULL;
1329
1330 cpl_ensure(det_frameset != NULL, CPL_ERROR_NULL_INPUT, NULL);
1331
1332 cpl_errorstate prestate = cpl_errorstate_get();
1333 crh_params = moo_crh_params_new();
1334 crh_params->method = MOO_CRH_METHOD_MEDIAN;
1335 moo_try_check(detlist = moo_detlist_create(det_frameset), " ");
1336 moo_try_check(combined = moo_remove_CRH(detlist, NULL, crh_params), " ");
1337 comb_filename =
1338 cpl_sprintf("%s_COMB2D_OFFSET%d_%s.fits", prefix, offset, mode);
1339
1340 moo_try_check(moo_products_add(products, combined,
1341 CPL_FRAME_LEVEL_INTERMEDIATE,
1342 MOONS_TAG_STARENOD_REMOVECRH, comb_filename,
1343 ref_frame),
1344 " ");
1345
1346 ext_filename =
1347 cpl_sprintf("%s_EXTSPECTRA_OFFSET%d_%s.fits", prefix, offset, mode);
1348 if (masterflat_frame != NULL) {
1349 psf = moo_psf_load(masterflat_frame);
1350 }
1351
1352 moo_try_check(ext = moo_extract(combined, loc, psf, extract_params,
1353 ext_filename),
1354 " ");
1355 moo_try_check(moo_products_add_ext(products, ext,
1356 CPL_FRAME_LEVEL_INTERMEDIATE,
1357 MOONS_TAG_SCIENCE_STARENOD_EXTSPECTRA,
1358 ext_filename, ref_frame),
1359 " ");
1360
1361 moo_try_check(_moons_apply_flat(ext, flat_frame, f2f_frame), " ");
1362 moo_try_check(moo_ext_compute_snr(ext, wmap, sformat, skylines), " ");
1363 extff_filename =
1364 cpl_sprintf("%s_EXTFFSPECTRA_OFFSET%d_%s.fits", prefix, offset, mode);
1365
1366 moo_try_check(moo_products_add_ext(products, ext,
1367 CPL_FRAME_LEVEL_INTERMEDIATE,
1368 MOONS_TAG_SCIENCE_STARENOD_EXTSPECTRA,
1369 extff_filename, ref_frame),
1370 " ");
1371
1372 rbn_filename =
1373 cpl_sprintf("%s_RBNSPECTRA_OFFSET%d_%s.fits", prefix, offset, mode);
1374 moo_try_check(rbn = moo_rebin(ext, wmap, sformat, rbn_params, rbn_filename),
1375 " ");
1376 moo_try_check(moo_rbn_compute_snr(rbn, skylines), " ");
1377 moo_try_check(
1378 result = moo_products_add_rbn(products, rbn, CPL_FRAME_LEVEL_FINAL,
1379 MOONS_TAG_SCIENCE_STARENOD_RBNSPECTRA,
1380 rbn_filename, ref_frame),
1381 " ");
1382
1383 if (atmo_frame != NULL && resp_frame != NULL) {
1384 moo_try_check(atm = moo_atm_load(atmo_frame), " ");
1385 moo_try_check(resp = moo_resp_load(resp_frame), " ");
1386
1387 calibflux_filename = cpl_sprintf("%s_RBNFLXSPECTRA_OFFSET%d_%s.fits",
1388 prefix, offset, mode);
1389 moo_try_check(moo_calib_flux(rbn, atm, resp), " ");
1390 moo_try_check(result = moo_products_add_rbn(
1391 products, rbn, CPL_FRAME_LEVEL_FINAL,
1392 MOONS_TAG_SCIENCE_STARENOD_RBNFLXSPECTRA,
1393 calibflux_filename, ref_frame),
1394 " ");
1395 }
1396 else {
1397 cpl_msg_info(__func__, "No flux calibration");
1398 }
1399
1400 if (tell_frame != NULL) {
1401 moo_try_check(telluric = moo_telluric_load(tell_frame), " ");
1402
1403 tellcorr_filename =
1404 cpl_sprintf("%s_RBNTELLCORRSPECTRA_OFFSET%d_%s.fits", prefix,
1405 offset, mode);
1406 moo_try_check(moo_correct_tell(rbn, telluric), " ");
1407 moo_try_check(result = moo_products_add_rbn(
1408 products, rbn, CPL_FRAME_LEVEL_FINAL,
1409 MOONS_TAG_SCIENCE_STARENOD_RBNTELLCORRSPECTRA,
1410 tellcorr_filename, ref_frame),
1411 " ");
1412 }
1413 else {
1414 cpl_msg_info(__func__, "No telluric correction");
1415 }
1416 result = cpl_frame_duplicate(result);
1417
1418moo_try_cleanup:
1419 if (!cpl_errorstate_is_equal(prestate)) {
1420 cpl_frame_delete(result);
1421 result = NULL;
1422 }
1423 moo_detlist_delete(detlist);
1424 moo_crh_params_delete(crh_params);
1425 moo_det_delete(combined);
1426 cpl_free(comb_filename);
1427
1428 moo_ext_delete(ext);
1429 moo_psf_delete(psf);
1430 cpl_free(ext_filename);
1431 cpl_free(extff_filename);
1432 cpl_free(rbn_filename);
1433 moo_rbn_delete(rbn);
1434
1435 cpl_free(tellcorr_filename);
1436 cpl_free(calibflux_filename);
1437
1438 moo_atm_delete(atm);
1439 moo_resp_delete(resp);
1440 moo_telluric_delete(telluric);
1441
1442 return result;
1443}
1444
1445static int
1446_moons_science_starenod2_byoffset(cpl_frameset *frameset,
1447 cpl_frameset *sci1d_frameset,
1448 cpl_frameset *sci2d_frameset,
1449 cpl_frameset *ref_frameset,
1450 const char *bpmap_rp_name,
1451 const char *bpmap_nl_name,
1452 const cpl_frame *masterbias,
1453 const cpl_frame *masterdark_vis,
1454 cpl_frameset *masterdark_nir,
1455 const cpl_frame *p2pmap,
1456 const cpl_frame *sformat_frame,
1457 moo_sky_lines_list *sky_lines,
1458 const cpl_frame *airglow_group_frame,
1459 const cpl_frame *solflux_frame,
1460 const cpl_frame *airglow_var_frame,
1461 const cpl_frame *atmo_frame,
1462 const cpl_frame *resp_frame,
1463 const cpl_frame *tell_frame,
1464 moo_prepare_params *prepare_params,
1465 moo_correct_bias_params *correct_bias_params,
1466 moo_extract_params *extract_params,
1467 moo_wavesol_params *wavesol_params,
1468 moo_rebin_params *rbn_params,
1469 moo_target_table_params *target_table_params,
1470 moo_sub_sky_stare_params *sky_params,
1471 moo_products *products)
1472{
1473 /* parameters */
1474 int *skyindex = NULL;
1475 moo_loc *loc = NULL;
1476 moo_spectral_format *sformat = NULL;
1477 moo_map *wmap = NULL;
1478 moo_map *wmap_tuned = NULL;
1479 moo_extlist *obj_extlist = NULL;
1480 moo_extlist *sky_extlist = NULL;
1481 moo_extlist *wavemap_extlist = NULL;
1482 moo_ext *sum_ext = NULL;
1483 cpl_frameset *obj_frameset = NULL;
1484 cpl_frameset *sky_frameset = NULL;
1485 cpl_frameset *sky_det_frameset = NULL;
1486 cpl_frameset *obj_det_frameset = NULL;
1487 cpl_frameset *nod_det_frameset = NULL;
1488
1489 cpl_frameset *sky_ext_frameset = NULL;
1490 cpl_frameset *obj_ext_frameset = NULL;
1491
1492 cpl_frameset *obj_rbn_frameset = NULL;
1493 cpl_frameset *sky_rbn_frameset = NULL;
1494 cpl_frame *nod_rbn_frame = NULL;
1495
1496 const cpl_frame *master_flat = NULL;
1497 const cpl_frame *fftrace = NULL;
1498 const cpl_frame *coeffs_cube = NULL;
1499 const cpl_frame *wmap_frame = NULL;
1500 const cpl_frame *flat_frame = NULL;
1501 const cpl_frame *f2f_frame = NULL;
1502 char *sum_ext_filename = NULL;
1503 const char *ref_filename = NULL;
1504 cpl_propertylist *ref_header = NULL;
1505 moo_mode_type mode;
1506 const char *mode_name = NULL;
1507 int offset;
1508 int wavemap_extlist_size = 0;
1509
1510 char *wmap_tuned_filename = NULL;
1511 moo_target_table_mode target_mode = MOO_MODE_STARENOD;
1512 moo_target_table *target_table = NULL;
1513 char *ttable_filename = NULL;
1514
1515 cpl_errorstate prestate = cpl_errorstate_get();
1516 sky_frameset = cpl_frameset_new();
1517 obj_frameset = cpl_frameset_new();
1518
1519 sky_det_frameset = cpl_frameset_new();
1520 obj_det_frameset = cpl_frameset_new();
1521 nod_det_frameset = cpl_frameset_new();
1522
1523 sky_ext_frameset = cpl_frameset_new();
1524 obj_ext_frameset = cpl_frameset_new();
1525
1526 obj_rbn_frameset = cpl_frameset_new();
1527 sky_rbn_frameset = cpl_frameset_new();
1528
1529 moo_try_check(_moons_science_starenod2_check_sof_byoffset(
1530 frameset, obj_frameset, sky_frameset, &master_flat,
1531 &fftrace, &coeffs_cube, &wmap_frame, &flat_frame,
1532 &f2f_frame, extract_params, sky_params, &target_mode),
1533 " ");
1534 cpl_frameset_join(ref_frameset, obj_frameset);
1535
1536 int nb_sky = cpl_frameset_get_size(sky_frameset);
1537 int nb_obj = cpl_frameset_get_size(obj_frameset);
1538
1539 cpl_frame *frame = cpl_frameset_get_position(obj_frameset, 0);
1540 ref_filename = cpl_frame_get_filename(frame);
1541 moo_try_check(mode = moo_mode_get(frame), " ");
1542 mode_name = moo_mode_get_name(mode);
1543 moo_try_check(ref_header = cpl_propertylist_load(ref_filename, 0), " ");
1544 moo_try_check(offset = moo_pfits_get_slit_offset(ref_header), " ");
1545 cpl_propertylist_delete(ref_header);
1546 ref_header = NULL;
1547 cpl_msg_info(__func__, "Do offset %d Use mode %s", offset, mode_name);
1548
1549 for (int i = 0; i < nb_sky; i++) {
1550 cpl_msg_info(__func__, "---Prepare sky: %d/%d", i + 1, nb_sky);
1551 cpl_frame *sky_frame = NULL;
1552 moo_try_check(sky_frame = cpl_frameset_get_position(sky_frameset, i),
1553 " ");
1554 cpl_frame *result =
1555 _moons_starenod_prepare(i, mode_name, offset, sky_frame,
1556 bpmap_rp_name, bpmap_nl_name, masterbias,
1557 masterdark_vis, masterdark_nir, p2pmap,
1558 coeffs_cube, prepare_params,
1559 correct_bias_params, products, 1);
1560 cpl_frameset_insert(sky_det_frameset, cpl_frame_duplicate(result));
1561 }
1562
1563 for (int i = 0; i < nb_obj; i++) {
1564 cpl_msg_info(__func__, "---Prepare objects: %d/%d", i + 1, nb_obj);
1565 cpl_frame *obj_frame = NULL;
1566 moo_try_check(obj_frame = cpl_frameset_get_position(obj_frameset, i),
1567 " ");
1568 cpl_frame *result =
1569 _moons_starenod_prepare(i, mode_name, offset, obj_frame,
1570 bpmap_rp_name, bpmap_nl_name, masterbias,
1571 masterdark_vis, masterdark_nir, p2pmap,
1572 coeffs_cube, prepare_params,
1573 correct_bias_params, products, 0);
1574 cpl_frameset_insert(obj_det_frameset, cpl_frame_duplicate(result));
1575 }
1576
1577 if (nb_sky > 0) {
1578 skyindex = cpl_calloc(nb_obj, sizeof(int));
1579 for (int i = 0; i < nb_obj; i++) {
1580 cpl_frame *obj_frame = NULL;
1581 cpl_frame *obj_det_frame = NULL;
1582 cpl_frame *sky_det_frame = NULL;
1583 moo_try_check(obj_frame =
1584 cpl_frameset_get_position(obj_frameset, i),
1585 " ");
1586 skyindex[i] = _starenod_getsky_index(obj_frame, sky_frameset);
1587 moo_try_check(obj_det_frame =
1588 cpl_frameset_get_position(obj_det_frameset, i),
1589 " ");
1590 moo_try_check(sky_det_frame =
1591 cpl_frameset_get_position(sky_det_frameset,
1592 skyindex[i]),
1593 " ");
1594 cpl_msg_info(__func__,
1595 "---Prepare nod %d/%d using object:%s sky: %s", i + 1,
1596 nb_obj, cpl_frame_get_filename(obj_det_frame),
1597 cpl_frame_get_filename(sky_det_frame));
1598 cpl_frame *result =
1599 _moons_starenod_subtractnod(i, mode_name, offset, obj_frame,
1600 obj_det_frame, sky_det_frame,
1601 products);
1602 cpl_frameset_insert(nod_det_frameset, cpl_frame_duplicate(result));
1603 }
1604 }
1605 int nb_nod = cpl_frameset_get_size(nod_det_frameset);
1606 moo_try_check(wmap = moo_map_load(wmap_frame), " ");
1607 moo_try_check(loc = moo_loc_load(fftrace), " ");
1608 moo_try_check(sformat = moo_spectral_format_load(sformat_frame, mode), " ");
1609
1610 for (int i = 0; i < nb_sky; i++) {
1611 cpl_frame *sky_frame = NULL;
1612 cpl_frame *sky_det_frame = NULL;
1613 cpl_msg_info(__func__, "---Extract sky: %d/%d", i + 1, nb_sky);
1614 moo_try_check(sky_frame = cpl_frameset_get_position(sky_frameset, i),
1615 " ");
1616 moo_try_check(sky_det_frame =
1617 cpl_frameset_get_position(sky_det_frameset, i),
1618 " ");
1619 cpl_frame *result =
1620 _moons_starenod_extract(i, mode_name, offset, sky_frame,
1621 sky_det_frame, loc, wmap, sformat,
1622 sky_lines, master_flat, flat_frame,
1623 f2f_frame, extract_params, products,
1624 "STARENOD_SKY");
1625 cpl_frameset_insert(sky_ext_frameset, cpl_frame_duplicate(result));
1626 }
1627
1628 for (int i = 0; i < nb_obj; i++) {
1629 cpl_frame *obj_frame = NULL;
1630 cpl_frame *obj_det_frame = NULL;
1631 cpl_msg_info(__func__, "---Extract objects: %d/%d", i + 1, nb_obj);
1632 moo_try_check(obj_frame = cpl_frameset_get_position(obj_frameset, i),
1633 " ");
1634 moo_try_check(obj_det_frame =
1635 cpl_frameset_get_position(obj_det_frameset, i),
1636 " ");
1637 cpl_frame *result =
1638 _moons_starenod_extract(i, mode_name, offset, obj_frame,
1639 obj_det_frame, loc, wmap, sformat,
1640 sky_lines, master_flat, flat_frame,
1641 f2f_frame, extract_params, products,
1642 "STARENOD_OBJ");
1643 cpl_frameset_insert(obj_ext_frameset, cpl_frame_duplicate(result));
1644 }
1645
1646 obj_extlist = moo_extlist_create(obj_ext_frameset);
1647 sky_extlist = moo_extlist_create(sky_ext_frameset);
1648 wavemap_extlist = moo_extlist_new();
1649
1650 for (int i = 0; i < nb_obj; i++) {
1651 moo_ext *ext = moo_extlist_get(obj_extlist, i);
1652 moo_extlist_set(wavemap_extlist, ext, wavemap_extlist_size);
1653 wavemap_extlist_size++;
1654 }
1655 for (int i = 0; i < nb_sky; i++) {
1656 moo_ext *ext = moo_extlist_get(sky_extlist, i);
1657 moo_extlist_set(wavemap_extlist, ext, wavemap_extlist_size);
1658 wavemap_extlist_size++;
1659 }
1660
1661 sum_ext_filename =
1662 cpl_sprintf("STARENOD_EXT_SUM_OFFSET%d_%s.fits", offset, mode_name);
1663 sum_ext = moo_extlist_sum(wavemap_extlist, sum_ext_filename);
1664 cpl_frame *ref_frame = cpl_frameset_get_position(obj_frameset, 0);
1665 moo_try_check(moo_products_add_ext(products, sum_ext,
1666 CPL_FRAME_LEVEL_TEMPORARY,
1667 MOONS_TAG_SCIENCE_STARENOD_EXTSPECTRA,
1668 sum_ext_filename, ref_frame),
1669 " ");
1670 moo_map *used_wmap = NULL;
1671 const char *wavesol_control = wavesol_params->control;
1672 if ((strcmp(wavesol_control, MOO_WAVESOL_CONTROL_CHECK) == 0) ||
1673 (strcmp(wavesol_control, MOO_WAVESOL_CONTROL_UPDATE) == 0)) {
1674 const char *sky_lines_name = sky_lines->filename;
1675 moo_try_check(wmap_tuned = moo_wavesol(sum_ext, sky_lines_name, sformat,
1676 loc, wmap, wavesol_params),
1677 " ");
1678 if (strcmp(wavesol_control, MOO_WAVESOL_CONTROL_UPDATE) == 0) {
1679 used_wmap = wmap_tuned;
1680 wmap_tuned_filename =
1681 cpl_sprintf("STARENOD_WMAP_TUNED_OFFSET%d_%s.fits", offset,
1682 mode_name);
1683 moo_map_save(wmap_tuned, wmap_tuned_filename);
1684 }
1685 }
1686 else {
1687 used_wmap = wmap;
1688 }
1689
1690 for (int i = 0; i < nb_obj; i++) {
1691 cpl_frame *obj_frame = NULL;
1692 moo_ext *obj_ext = moo_extlist_get(obj_extlist, i);
1693 cpl_msg_info(__func__, "---Rebin objects: %d/%d", i + 1, nb_obj);
1694 moo_try_check(obj_frame = cpl_frameset_get_position(obj_frameset, i),
1695 " ");
1696 cpl_frame *result =
1697 _moons_starenod_rebin(i, mode_name, offset, obj_ext, obj_frame,
1698 sformat, sky_lines, used_wmap, atmo_frame,
1699 resp_frame, tell_frame, rbn_params, products,
1700 "STARENOD_OBJ");
1701 cpl_frameset_insert(obj_rbn_frameset, cpl_frame_duplicate(result));
1702 }
1703
1704 for (int i = 0; i < nb_sky; i++) {
1705 cpl_frame *sky_frame = NULL;
1706 moo_ext *sky_ext = moo_extlist_get(sky_extlist, i);
1707 cpl_msg_info(__func__, "---Rebin sky: %d/%d", i + 1, nb_sky);
1708 moo_try_check(sky_frame = cpl_frameset_get_position(sky_frameset, i),
1709 " ");
1710 cpl_frame *result =
1711 _moons_starenod_rebin(i, mode_name, offset, sky_ext, sky_frame,
1712 sformat, sky_lines, used_wmap, atmo_frame,
1713 resp_frame, tell_frame, rbn_params, products,
1714 "STARENOD_SKY");
1715 cpl_frameset_insert(sky_rbn_frameset, cpl_frame_duplicate(result));
1716 }
1717
1718 if (nb_nod > 0) {
1719 moo_try_check(nod_rbn_frame =
1720 _starenod_nod_rebin(nod_det_frameset, mode_name,
1721 offset, frame, loc, used_wmap,
1722 sformat, sky_lines, master_flat,
1723 flat_frame, f2f_frame, atmo_frame,
1724 resp_frame, tell_frame,
1725 extract_params, rbn_params,
1726 products, "STARENOD_NOD"),
1727 " ");
1728 }
1729
1730 if (nb_sky == 0) {
1731 for (int i = 0; i < nb_obj; i++) {
1732 cpl_frame *obj_frame = NULL;
1733 cpl_frame *obj_rbn_frame = NULL;
1734 cpl_msg_info(__func__, "---Create sci: %d/%d", i + 1, nb_obj);
1735 moo_try_check(obj_frame =
1736 cpl_frameset_get_position(obj_frameset, i),
1737 " ");
1738 moo_try_check(obj_rbn_frame =
1739 cpl_frameset_get_position(obj_rbn_frameset, i),
1740 " ");
1741 cpl_frame *result =
1742 _moons_stare_sci(i, mode_name, offset, obj_frame, obj_rbn_frame,
1743 sky_lines, f2f_frame, airglow_group_frame,
1744 airglow_var_frame, solflux_frame,
1745 target_table_params, sky_params, products,
1746 "STARENOD_OBJ");
1747 cpl_frameset_insert(sci1d_frameset, cpl_frame_duplicate(result));
1748 }
1749 }
1750 else {
1751 cpl_frame *obj_rbn_frame = NULL;
1752 cpl_frame *sky_rbn_frame = NULL;
1753 cpl_frame *sci_frame = NULL;
1754
1755 moo_try_check(obj_rbn_frame =
1756 cpl_frameset_get_position(obj_rbn_frameset, 0),
1757 " ");
1758 moo_try_check(sky_rbn_frame =
1759 cpl_frameset_get_position(sky_rbn_frameset,
1760 skyindex[0]),
1761 " ");
1762 moo_rbn *sky_rbn = NULL;
1763 moo_rbn *obj_rbn = NULL;
1764
1765 moo_try_check(obj_rbn = moo_rbn_create(obj_rbn_frame), " ");
1766 moo_try_check(sky_rbn = moo_rbn_create(sky_rbn_frame), " ");
1767
1768 moo_try_check(target_table =
1769 moo_create_target_table(obj_rbn, sky_rbn,
1770 MOO_MODE_STARENOD,
1771 target_table_params),
1772 " ");
1773 moo_rbn_delete(sky_rbn);
1774 moo_rbn_delete(obj_rbn);
1775 ttable_filename = cpl_sprintf("STARENOD_TARGET_TABLE_OFFSET%d_%s.fits",
1776 offset, mode_name);
1777
1778 moo_try_check(moo_products_add_target_table(
1779 products, target_table, CPL_FRAME_LEVEL_INTERMEDIATE,
1780 MOONS_TAG_SCIENCE_STARENOD_TARGET_TABLE,
1781 ttable_filename, frame),
1782 " ");
1783
1784 moo_try_check(sci_frame =
1785 _moons_starenod_sci2d(mode_name, offset, ref_frame,
1786 nod_rbn_frame, sky_rbn_frameset,
1787 sky_lines, target_table,
1788 products, "STARENOD_NOD"),
1789 " ");
1790 cpl_frameset_insert(sci2d_frameset, cpl_frame_duplicate(sci_frame));
1791
1792 for (int i = 0; i < nb_nod; i++) {
1793 cpl_frame *obj_frame = NULL;
1794
1795 moo_try_check(obj_frame =
1796 cpl_frameset_get_position(obj_frameset, i),
1797 " ");
1798 moo_try_check(obj_rbn_frame =
1799 cpl_frameset_get_position(obj_rbn_frameset, i),
1800 " ");
1801 moo_try_check(sky_rbn_frame =
1802 cpl_frameset_get_position(sky_rbn_frameset,
1803 skyindex[i]),
1804 " ");
1805 cpl_msg_info(
1806 __func__,
1807 "---Create sci1d: %d/%d using nod %s object:%s sky: %s", i + 1,
1808 nb_nod, cpl_frame_get_filename(nod_rbn_frame),
1809 cpl_frame_get_filename(obj_rbn_frame),
1810 cpl_frame_get_filename(sky_rbn_frame));
1811
1812 moo_try_check(sci_frame = _moons_starenod_sci1d(
1813 i, mode_name, offset, obj_frame, obj_rbn_frame,
1814 sky_rbn_frame, sky_lines, f2f_frame,
1815 airglow_group_frame, airglow_var_frame,
1816 solflux_frame, target_table, sky_params, products,
1817 "STARENOD_NOD"),
1818 " ");
1819 cpl_frameset_insert(sci1d_frameset, cpl_frame_duplicate(sci_frame));
1820 }
1821 }
1822
1823moo_try_cleanup:
1824 if (!cpl_errorstate_is_equal(prestate)) {
1825 cpl_propertylist_delete(ref_header);
1826 }
1827 moo_extlist_delete(obj_extlist);
1828 moo_extlist_delete(sky_extlist);
1829 if (wavemap_extlist != NULL) {
1830 for (int i = 0; i < wavemap_extlist_size; i++) {
1831 moo_extlist_unset(wavemap_extlist, 0);
1832 }
1833 }
1834 moo_extlist_delete(wavemap_extlist);
1835 moo_ext_delete(sum_ext);
1836 moo_loc_delete(loc);
1837 moo_map_delete(wmap);
1838 moo_map_delete(wmap_tuned);
1839 cpl_free(sum_ext_filename);
1840 cpl_free(wmap_tuned_filename);
1842
1843 cpl_free(ttable_filename);
1844 moo_target_table_delete(target_table);
1845
1846 cpl_frameset_delete(obj_rbn_frameset);
1847 cpl_frameset_delete(sky_rbn_frameset);
1848 cpl_frame_delete(nod_rbn_frame);
1849
1850 cpl_frameset_delete(sky_det_frameset);
1851 cpl_frameset_delete(obj_det_frameset);
1852 cpl_frameset_delete(nod_det_frameset);
1853
1854 cpl_frameset_delete(sky_ext_frameset);
1855 cpl_frameset_delete(obj_ext_frameset);
1856
1857 cpl_frameset_delete(obj_frameset);
1858 cpl_frameset_delete(sky_frameset);
1859
1860 cpl_free(skyindex);
1861
1862 return (int)cpl_error_get_code();
1863}
1864
1865static int
1866_moons_science_starenod2(cpl_frameset *frameset,
1867 const cpl_parameterlist *parlist)
1868{
1869 /* parameters */
1870 moo_prepare_params *prepare_params = NULL;
1871 moo_correct_bias_params *correct_bias_params = NULL;
1872 moo_extract_params *extract_params = NULL;
1873 moo_wavesol_params *wavesol_params = NULL;
1874 moo_rebin_params *rbn_params = NULL;
1875 moo_target_table_params *target_table_params = NULL;
1876 moo_sub_sky_stare_params *sky_params = NULL;
1877 moo_coadd_params *coadd_params = NULL;
1878 moo_create_s1d_params *s1d_params = NULL;
1879 moo_scilist *sci1d_list = NULL;
1880 moo_sci *sci1d_coadd = NULL;
1881 moo_scilist *sci2d_list = NULL;
1882 moo_sci *sci2d_coadd = NULL;
1883 moo_sci *sci_coadd = NULL;
1884 moo_scilist *sci_list = NULL;
1885 cpl_frameset *offset_frameset = NULL;
1886 cpl_frameset *set = NULL;
1887 cpl_frameset *sci1d_set = NULL;
1888 cpl_frameset *sci2d_set = NULL;
1889 cpl_frameset *sci_set = NULL;
1890 cpl_frameset *ref_frameset = NULL;
1891
1892 const char *bpmap_rp_name = NULL;
1893 const char *bpmap_nl_name = NULL;
1894 const cpl_frame *masterbias = NULL;
1895 const cpl_frame *masterdark_vis = NULL;
1896 cpl_frameset *masterdark_nir = NULL;
1897 const cpl_frame *p2pmap = NULL;
1898 const cpl_frame *sformat_frame = NULL;
1899 const cpl_frame *sky_lines_frame = NULL;
1900 const cpl_frame *atmo_frame = NULL;
1901 const cpl_frame *resp_frame = NULL;
1902 const cpl_frame *tell_frame = NULL;
1903 const cpl_frame *airglow_group_frame = NULL;
1904 const cpl_frame *solflux_frame = NULL;
1905 const cpl_frame *airglow_var_frame = NULL;
1906 const cpl_frame *ref_frame = NULL;
1907 cpl_size nsel = 0;
1908 cpl_size *selection = NULL;
1909 moo_sky_lines_list *skylines = NULL;
1910 char *coadd1d_filename = NULL;
1911 char *coadd2d_filename = NULL;
1912 char *coadd_filename = NULL;
1913
1914 cpl_errorstate prestate = cpl_errorstate_get();
1915
1916 moo_products *products =
1917 moo_products_new(frameset, parlist, "moons_science_starenod2",
1918 PACKAGE "/" PACKAGE_VERSION);
1919
1920 const moo_params *params = moo_products_get_params(products);
1921 moo_try_check(prepare_params = moo_params_get_prepare(params, parlist),
1922 " ");
1923 moo_try_check(correct_bias_params =
1924 moo_params_get_correct_bias(params, parlist),
1925 " ");
1926 moo_try_check(extract_params = moo_params_get_extract(params, parlist),
1927 " ");
1928 moo_try_check(rbn_params = moo_params_get_rebin(params, parlist), " ");
1929 moo_try_check(target_table_params =
1930 moo_params_get_target_table(params, parlist),
1931 " ");
1932
1933 moo_try_check(sky_params = moo_params_get_sub_sky_stare(params, parlist),
1934 " ");
1935 moo_try_check(coadd_params = moo_params_get_coadd(params, parlist), " ");
1936 moo_try_check(wavesol_params =
1937 moo_params_get_science_wavesol(params, parlist),
1938 " ");
1939 moo_try_check(s1d_params = moo_params_get_create_s1d(params, parlist), " ");
1940
1941 /* SOF file */
1942 offset_frameset = cpl_frameset_new();
1943 sci_set = cpl_frameset_new();
1944 sci1d_set = cpl_frameset_new();
1945 sci2d_set = cpl_frameset_new();
1946 ref_frameset = cpl_frameset_new();
1947 masterdark_nir = cpl_frameset_new();
1948
1949 moo_try_check(_moons_science_starenod2_check_sof(
1950 frameset, offset_frameset, &bpmap_rp_name, &bpmap_nl_name,
1951 &masterbias, &masterdark_vis, masterdark_nir, &p2pmap,
1952 &sformat_frame, &sky_lines_frame, &atmo_frame,
1953 &resp_frame, &tell_frame, &airglow_group_frame,
1954 &airglow_var_frame, &solflux_frame, sky_params),
1955 " ");
1956
1957 cpl_frameset_sort(offset_frameset, _moons_sort_mjdobs);
1958
1959 moo_try_check(selection =
1960 cpl_frameset_labelise(offset_frameset,
1961 &_moons_compare_offset, &nsel),
1962 " ");
1963
1964 moo_try_check(skylines = moo_sky_lines_list_load(sky_lines_frame), " ");
1965
1966 for (int i = 0; i < nsel; i++) {
1967 moo_try_check(set = cpl_frameset_extract(offset_frameset, selection, i),
1968 " ");
1969
1970 moo_try_check(_moons_science_starenod2_byoffset(
1971 set, sci1d_set, sci2d_set, ref_frameset,
1972 bpmap_rp_name, bpmap_nl_name, masterbias,
1973 masterdark_vis, masterdark_nir, p2pmap, sformat_frame,
1974 skylines, airglow_group_frame, solflux_frame,
1975 airglow_var_frame, atmo_frame, resp_frame, tell_frame,
1976 prepare_params, correct_bias_params, extract_params,
1977 wavesol_params, rbn_params, target_table_params,
1978 sky_params, products),
1979 " ");
1980 cpl_frameset_delete(set);
1981 set = NULL;
1982 }
1983
1984 moo_try_check(ref_frame = cpl_frameset_get_position_const(ref_frameset, 0),
1985 " ");
1986 moo_mode_type mode = moo_mode_get(ref_frame);
1987
1988 int sci1d_size = cpl_frameset_get_size(sci1d_set);
1989 if (sci1d_size > 0) {
1990 cpl_frame *result = NULL;
1991 sci1d_list = moo_scilist_create(sci1d_set);
1992 cpl_msg_info(__func__, "Create SCI1D products");
1993 coadd1d_filename =
1994 cpl_sprintf("STARENOD2_SCI1D_%s_%s.fits",
1995 MOONS_TAG_STARENOD_SKSSPECTRA, moo_mode_get_name(mode));
1996 sci1d_coadd = moo_coadd(sci1d_list, coadd_params, coadd1d_filename);
1997 moo_try_check(moo_sci_compute_snr(sci1d_coadd, skylines), " ");
1998 moo_try_check(result =
1999 moo_products_add_sci(products, sci1d_coadd,
2000 CPL_FRAME_LEVEL_INTERMEDIATE,
2001 MOONS_TAG_STARENOD_SKSSPECTRA,
2002 coadd1d_filename, ref_frame),
2003 " ");
2004 cpl_frameset_insert(sci_set, cpl_frame_duplicate(result));
2005 }
2006 int sci2d_size = cpl_frameset_get_size(sci2d_set);
2007 if (sci2d_size > 0) {
2008 cpl_frame *result = NULL;
2009 sci2d_list = moo_scilist_create(sci2d_set);
2010 cpl_msg_info(__func__, "Create SCI2D products");
2011 coadd2d_filename =
2012 cpl_sprintf("STARENOD2_SCI2D_%s_%s.fits",
2013 MOONS_TAG_STARENOD_SKSSPECTRA, moo_mode_get_name(mode));
2014
2015 sci2d_coadd = moo_coadd(sci2d_list, coadd_params, coadd2d_filename);
2016
2017 moo_try_check(moo_sci_compute_snr(sci2d_coadd, skylines), " ");
2018
2019 moo_try_check(result =
2020 moo_products_add_sci(products, sci2d_coadd,
2021 CPL_FRAME_LEVEL_INTERMEDIATE,
2022 MOONS_TAG_STARENOD_SKSSPECTRA,
2023 coadd2d_filename, ref_frame),
2024 " ");
2025 cpl_frameset_insert(sci_set, cpl_frame_duplicate(result));
2026 }
2027
2028 if (cpl_frameset_get_size(sci_set) > 0) {
2029 sci_list = moo_scilist_create(sci_set);
2030 cpl_msg_info(__func__, "Create final product");
2031 coadd_filename =
2032 cpl_sprintf("%s_%s.fits", MOONS_TAG_STARENOD2_COMBINED_SPECTRA,
2033 moo_mode_get_name(mode));
2034 sci_coadd = moo_coadd(sci_list, coadd_params, coadd_filename);
2035
2036 moo_try_check(moo_sci_compute_snr(sci_coadd, skylines), " ");
2037
2038 cpl_frame *sci_final = NULL;
2039 moo_try_check(sci_final = moo_products_add_sci(
2040 products, sci_coadd, CPL_FRAME_LEVEL_FINAL,
2041 MOONS_TAG_STARENOD2_COMBINED_SPECTRA, coadd_filename,
2042 ref_frame),
2043 " ");
2044 moo_create_s1d(sci_final, s1d_params,
2045 MOONS_TAG_SCIENCE_STARENOD2_1DSPECTRUM, products);
2046 }
2047
2048moo_try_cleanup:
2049 if (!cpl_errorstate_is_equal(prestate)) {
2050 cpl_frameset_delete(set);
2051 }
2052 cpl_free(coadd1d_filename);
2053 cpl_free(coadd2d_filename);
2054 cpl_free(coadd_filename);
2055 cpl_free(selection);
2056 moo_sci_delete(sci1d_coadd);
2057 moo_scilist_delete(sci_list);
2058 moo_scilist_delete(sci1d_list);
2059 moo_sci_delete(sci2d_coadd);
2060 moo_sci_delete(sci_coadd);
2061 moo_scilist_delete(sci2d_list);
2062 moo_sky_lines_list_delete(skylines);
2063
2064 cpl_frameset_delete(sci_set);
2065 cpl_frameset_delete(sci1d_set);
2066 cpl_frameset_delete(sci2d_set);
2067 cpl_frameset_delete(ref_frameset);
2068 cpl_frameset_delete(offset_frameset);
2069 cpl_frameset_delete(masterdark_nir);
2070
2071 moo_extract_params_delete(extract_params);
2072 moo_wavesol_params_delete(wavesol_params);
2073 moo_rebin_params_delete(rbn_params);
2074 moo_target_table_params_delete(target_table_params);
2075
2076 moo_sub_sky_stare_params_delete(sky_params);
2077 moo_coadd_params_delete(coadd_params);
2078 moo_correct_bias_params_delete(correct_bias_params);
2079 moo_create_s1d_params_delete(s1d_params);
2080 moo_prepare_params_delete(prepare_params);
2081 moo_products_delete(products);
2082 return (int)cpl_error_get_code();
2083}
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
#define MOO_BADPIX_GOOD
Definition: moo_badpix.h:36
moo_det * moo_det_create(const cpl_frame *frame)
Create a new moo_det from the given DET frame.
Definition: moo_det.c:91
cpl_error_code moo_det_load(moo_det *self, unsigned int level)
Load all parts in DET.
Definition: moo_det.c:135
void moo_det_delete(moo_det *self)
Delete a moo_det.
Definition: moo_det.c:472
moo_single * moo_det_get_single(moo_det *self, moo_detector_type type, int num)
Get the type part in DET and return it.
Definition: moo_det.c:359
moo_mode_type moo_mode_get(const cpl_frame *frame)
Get the name of a mode from a frame.
Definition: moo_detector.c:224
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
moo_ext * moo_extlist_get(moo_extlist *self, int i)
Get the DET at the position i in the list.
Definition: moo_extlist.c:197
cpl_error_code moo_extlist_set(moo_extlist *self, moo_ext *ext, cpl_size pos)
Insert a DET into an moo_extlist.
Definition: moo_extlist.c:376
moo_ext * moo_extlist_unset(moo_extlist *self, cpl_size pos)
Remove a DET from a DET list.
Definition: moo_extlist.c:467
moo_ext * moo_extlist_sum(moo_extlist *self, const char *filename)
Sum EXT element from the list and save result in filename.
Definition: moo_extlist.c:581
void moo_extlist_delete(moo_extlist *self)
Free all memory used by a moo_extlist object including the DET.
Definition: moo_extlist.c:561
moo_extlist * moo_extlist_create(cpl_frameset *frameset)
Create a new moo_extlist from the given DET frameset.
Definition: moo_extlist.c:72
moo_extlist * moo_extlist_new(void)
Create a new moo_extlist.
Definition: moo_extlist.c:57
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_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_save(moo_map *self, const char *filename)
Save a moo_map to a FITS file.
Definition: moo_map.c:275
void moo_map_delete(moo_map *self)
Delete a moo_map.
Definition: moo_map.c:236
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_create_s1d(moo_params *self, cpl_parameterlist *list)
Add default parameters for create_s1d.
Definition: moo_params.c:2437
void moo_create_s1d_params_delete(moo_create_s1d_params *self)
Delete a moo_create_s1d_params.
Definition: moo_params.c:2353
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_create_s1d_params * moo_params_get_create_s1d(const moo_params *self, const cpl_parameterlist *list)
Get create s1d parameters from moons parameters list.
Definition: moo_params.c:1614
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
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
cpl_error_code moo_params_add_science_wavesol(moo_params *self, cpl_parameterlist *list)
Add default science parameters for moo_wavesol.
Definition: moo_params.c:2091
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
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
moo_wavesol_params * moo_params_get_science_wavesol(const moo_params *self, const cpl_parameterlist *list)
Get science_wavesol parameters from moons parameters list.
Definition: moo_params.c:2790
void moo_params_delete(moo_params *self)
Delete a moo_params.
Definition: moo_params.c:85
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_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
moo_rbn * moo_rbn_create(const cpl_frame *frame)
Create a new empty RBN filename.
Definition: moo_rbn.c:85
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_rbnlist_delete(moo_rbnlist *self)
Free all memory used by a moo_rbnlist object including the RBN.
Definition: moo_rbnlist.c:529
moo_rbnlist * moo_rbnlist_create(const cpl_frameset *frameset)
Create a new moo_rbnlist from the given RBN frameset.
Definition: moo_rbnlist.c:71
void moo_resp_delete(moo_resp *self)
Delete a moo_resp.
Definition: moo_resp.c:320
moo_resp * moo_resp_load(const cpl_frame *frame)
Load a RESP frame and create a moo_resp.
Definition: moo_resp.c:401
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(cpl_frameset *frameset)
Create a new moo_scilist from the given SCI frameset.
Definition: moo_scilist.c:321
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.
enum _moo_target_table_mode_ moo_target_table_mode
The type code type.
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
moo_rbn * moo_combine_sky(moo_rbnlist *rbnlist)
Combine RBN sky frames.
cpl_error_code moo_correct_tell(moo_rbn *rbn, moo_telluric *tell)
Apply the telluric correction to 1D rebinned spectra.
moo_sci * moo_coadd(moo_scilist *scilist, moo_coadd_params *params, const char *filename)
Co-add reduced science frames in SCI format.
Definition: moo_coadd.c:134
moo_map * moo_wavesol(moo_ext *arc_ext, const char *lineCatname, moo_spectral_format *sformat, moo_loc *loc, moo_map *wmap, moo_wavesol_params *params)
Computes the wavelength solution from 1D extracted arc spectra.
Definition: moo_wavesol.c:2728
cpl_error_code moo_apply_p2p(moo_det *flat, moo_det *p2pmap)
Divide DET by the pixel-to-pixel variation map.
cpl_error_code moo_create_s1d(cpl_frame *sci_frame, moo_create_s1d_params *params, const char *tag, moo_products *products)
Apply the telluric correction to SCI.
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_calib_flux(moo_rbn *rbn, moo_atm *atm, moo_resp *resp)
Apply the relative flux calibration to 1D rebinned spectra.
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_det * moo_subtract_nod(moo_det *object, moo_det *sky, const char *filename)
Sky from object subtraction.
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
int moo_pfits_get_ndit(const cpl_propertylist *plist)
find out the ESO DET NDIT value
Definition: moo_pfits.c:382
double moo_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
Definition: moo_pfits.c:362
double moo_pfits_get_mjdobs(const cpl_propertylist *plist)
find out the MJD-OBS
Definition: moo_pfits.c:328
int moo_pfits_get_slit_offset(const cpl_propertylist *plist)
find out the INS SLIT OFFSET value
Definition: moo_pfits.c:1110
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_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(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
the different type of detectors