MOONS Pipeline Reference Manual 0.13.1
moons_mflat.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_flat_shift_compute.h"
35#include "moo_compute_slitoffset.h"
36#include <cpl.h>
37#include <math.h>
38#include <string.h>
39/*-----------------------------------------------------------------------------
40 Plugin registration
41 -----------------------------------------------------------------------------*/
42
43int cpl_plugin_get_info(cpl_pluginlist *list);
44
45/*-----------------------------------------------------------------------------
46 Private function prototypes
47 -----------------------------------------------------------------------------*/
48
49static int _moons_mflat_create(cpl_plugin *plugin);
50static int _moons_mflat_exec(cpl_plugin *plugin);
51static int _moons_mflat_destroy(cpl_plugin *plugin);
52static int
53_moons_mflat(cpl_frameset *frameset, const cpl_parameterlist *parlist);
54
55/*-----------------------------------------------------------------------------
56 Static variables
57 -----------------------------------------------------------------------------*/
58
59static const char *const _moons_mflat_description[2] = {
60 "This recipe aims at creating the products necessary to locate and extract "
61 "1D"
62 " spectra and correct from flat-field signatures. It can be used in three"
63 " different flows\n\n"
64 "Workflow 1: Localises the spectra from scratch and creates the guess"
65 " localisation traces and widths\n"
66 "INPUT FRAMES\n"
67 " * RawList n1>=3 files (RAW) with tag FLAT : "
68 "flat files\n"
69 " * RawOffList n2==n1 files (RAW) with tag FLAT_OFF : "
70 "flat off files\n"
71 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag BP_MAP_RP : "
72 "cosmetic bad pixel map\n"
73 " * MasterBias 1 file (DET) with tag MASTER_BIAS : "
74 "master bias file\n"
75 " * [OPTIONAL] MasterDarkVis 1 file (DET) with tag "
76 "MASTER_DARK_VIS : "
77 "master dark vis file\n"
78 " * [OPTIONAL] MasterDarkNir 1 file (DET) with tag "
79 "MASTER_DARK_NIR : "
80 "master dark nir file\n"
81 "PRODUCTS\n"
82 " * FF_TRACE_GUESS_OFFSET[offset]_[insmode].fits (LOC) with tag "
83 "FF_TRACE_GUESS : "
84 "the localisation trace stores the Y centroid values of the spectra traces"
85 " and the width of the spectra in Y direction at each centroid position "
86 "\n\n"
87 "Workflow 2: Localises the spectra and creates the localisation traces"
88 " and widths. Creates the master and extracted flat-fields, and "
89 "the fibre-to-fibre relative response. Updates the bad-pixel mask.\n"
90 "INPUT FRAMES\n"
91 " * RawList n1>=3 files (RAW) with tag FLAT : "
92 "flat files\n"
93 " * RawOffList n2==n1 files (RAW) with tag FLAT_OFF : "
94 "flat off files\n"
95 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag BP_MAP_RP : "
96 "cosmetic bad pixel map\n"
97 " * [OPTIONAL] NonLinearityBadPixMask 1 file (QUA) with tag BP_MAP_NL : "
98 "non linearity bad pixel map coming from linearity recipe\n"
99 " * MasterBias 1 file (DET) with tag MASTER_BIAS : "
100 "master bias file\n"
101 " * [OPTIONAL] MasterDarkVis 1 file (DET) with tag "
102 "MASTER_DARK_VIS : "
103 "master dark vis file\n"
104 " * [OPTIONAL] MasterDarkNir 1 file (DET) with tag "
105 "MASTER_DARK_NIR : "
106 "master dark nir file\n"
107 " * [OPTIONAL] LinCoeffsCube 1 file (3D) with tag "
108 "LINEARITY_COEFF_CUBE : "
109 "linearity coefficients coming from linearity recipe\n"
110 " * [OPTIONAL] P2pMap 1 file (DET) with tag P2P_MAP : "
111 "the pixel to pixel variation map \n"
112 " * FfTraceGuess 1 file (LOC) with tag "
113 "FF_TRACE_GUESS : "
114 "localisation trace produced in workflow 1\n"
115 "PRODUCTS\n"
116 " * FF_TRACE_OFFSET[offset]_[insmode].fits (LOC) with tag FF_TRACE : "
117 "the localisation trace stores the Y centroid values of the spectra traces"
118 " and the width of the spectra in Y direction at each centroid position\n"
119 " * FF_EXTSPECTRA_OFFSET[offset]_[insmode].fits (EXT) with tag "
120 "FF_FF_EXTSPECTRA : "
121 "extracted flat-fields\n"
122 " * F2F_OFFSET[offset]_[insmode].fits (F2F) with tag F2F_TABLE "
123 ": "
124 "the fibre-to-fibre relative response\n"
125 "[if --extract-method==OPTIMAL]\n"
126 " * MASTER_FLAT_OFFSET[offset]_[insmode].fits (PSF) with tag "
127 "MASTER_FLAT : "
128 "the master normalized flat product for given position\n"
129 "[endif]\n\n",
130 "Workflow 3: Localises the spectra and creates the localisation traces"
131 " and widths. Creates the master and extracted flat-fields,"
132 " the pixel-to-pixel variation map and the fibre-to-fibre relative "
133 "response."
134 " Updates the bad-pixel mask\n"
135 "INPUT FRAMES\n"
136 " * RawList n1>=3 files (RAW) with tag FLAT : "
137 "flat files at offset 0\n"
138 " * RawList n2>=3 files (RAW) with tag FLAT : "
139 "flat files at offset 1\n"
140 " * RawOffList n2+n1 files (RAW) with tag FLAT_OFF : "
141 "flat off files\n"
142 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag BP_MAP_RP : "
143 "cosmetic bad pixel map\n"
144 " * [OPTIONAL] NonLinearityBadPixMask 1 file (QUA) with tag BP_MAP_NL : "
145 "non linearity bad pixel map coming from linearity recipe\n"
146 " * MasterBias 1 file (DET) with tag MASTER_BIAS : "
147 "master bias file\n"
148 " * [OPTIONAL] MasterDarkVis 1 file (DET) with tag "
149 "MASTER_DARK_VIS : "
150 "master dark vis file\n"
151 " * [OPTIONAL] MasterDarkNir 1 file (DET) with tag "
152 "MASTER_DARK_NIR : "
153 "master dark nir file\n"
154 " * [OPTIONAL] LinCoeffsCube1 1 file (3D) with tag "
155 "LINEARITY_COEFF_CUBE : "
156 "linearity coefficients coming from linearity recipe at offset 0\n"
157 " * [OPTIONAL] LinCoeffsCube2 1 file (3D) with tag "
158 "LINEARITY_COEFF_CUBE : "
159 "linearity coefficients coming from linearity recipe at offset 1\n"
160 " * FfTraceGuess1 1 file (LOC) with tag "
161 "FF_TRACE_GUESS : "
162 "localisation trace produced in workflow 1 at offset 0\n"
163 " * FfTraceGuess2 1 file (LOC) with tag "
164 "FF_TRACE_GUESS : "
165 "localisation trace produced in workflow 1 at offset 1\n"
166 "PRODUCTS\n"
167 " * P2P_[insmode].fits (DET) with tag P2P_MAP : "
168 "the pixel to pixel variation map \n\n"
169 "Workflow 4: Compute shift in fibre-to-fibre relative response."
170 "INPUT FRAMES\n"
171 " * FlatAttached (RAW) with tag FLAT_ATTACHED "
172 ": "
173 "flat file\n"
174 " * RawOff (RAW) with tag FLAT_OFF : "
175 "flat off files\n"
176 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag BP_MAP_RP : "
177 "cosmetic bad pixel map\n"
178 " * [OPTIONAL] NonLinearityBadPixMask 1 file (QUA) with tag BP_MAP_NL : "
179 "non linearity bad pixel map coming from linearity recipe\n"
180 " * MasterBias 1 file (DET) with tag MASTER_BIAS : "
181 "master bias file\n"
182 " * [OPTIONAL] MasterDarkVis 1 file (DET) with tag "
183 "MASTER_DARK_VIS : "
184 "master dark vis file\n"
185 " * [OPTIONAL] MasterDarkNir 1 file (DET) with tag "
186 "MASTER_DARK_NIR : "
187 "master dark nir file\n"
188 " * [OPTIONAL] LinCoeffsCube 1 file (3D) with tag "
189 "LINEARITY_COEFF_CUBE : "
190 "linearity coefficients coming from linearity recipe\n"
191 " * FfTrace 1 file (LOC): "
192 "localisation trace produced in workflow 2\n"
193 "PRODUCTS\n"
194 " * F2F_OFFSET[offset]_[insmode].fits (F2F) with tag F2F_TABLE "
195 ": "
196 "the fibre-to-fibre relative response\n"
197};
198
199/*-----------------------------------------------------------------------------
200 Function code
201 -----------------------------------------------------------------------------*/
202
203/*----------------------------------------------------------------------------*/
213/*----------------------------------------------------------------------------*/
214
215int
216cpl_plugin_get_info(cpl_pluginlist *list)
217{
218 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
219 cpl_plugin *plugin = &recipe->interface;
220
221 cpl_size sz[2] = { strlen(_moons_mflat_description[0]),
222 strlen(_moons_mflat_description[1]) };
223 char *description = cpl_calloc(sizeof(char), sz[0] + sz[1] + 1);
224
225 cpl_size idx;
226 cpl_size offset = 0;
227 for (idx = 0; idx < 2; ++idx) {
228 strncpy(&description[offset], _moons_mflat_description[idx], sz[idx]);
229 offset += sz[idx];
230 }
231
232 if (cpl_plugin_init(plugin, CPL_PLUGIN_API, MOONS_BINARY_VERSION,
233 CPL_PLUGIN_TYPE_RECIPE, "moons_mflat",
234 "Create a master flat product", description,
235 "Regis Haigron", PACKAGE_BUGREPORT, moo_get_license(),
236 _moons_mflat_create, _moons_mflat_exec,
237 _moons_mflat_destroy)) {
238 cpl_free(description);
239 cpl_msg_error(cpl_func, "Plugin initialization failed");
240 (void)cpl_error_set_where(cpl_func);
241 return 1;
242 }
243 cpl_free(description);
244
245 if (cpl_pluginlist_append(list, plugin)) {
246 cpl_msg_error(cpl_func, "Error adding plugin to list");
247 (void)cpl_error_set_where(cpl_func);
248 return 1;
249 }
250
251 return 0;
252}
253
254
255/*----------------------------------------------------------------------------*/
263/*----------------------------------------------------------------------------*/
264
265static int
266_moons_mflat_create(cpl_plugin *plugin)
267{
268 cpl_recipe *recipe;
269
270 /* Do not create the recipe if an error code is already set */
271 if (cpl_error_get_code() != CPL_ERROR_NONE) {
272 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
273 cpl_func, __LINE__, cpl_error_get_where());
274 return (int)cpl_error_get_code();
275 }
276
277 if (plugin == NULL) {
278 cpl_msg_error(cpl_func, "Null plugin");
279 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
280 }
281
282 /* Verify plugin type */
283 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
284 cpl_msg_error(cpl_func, "Plugin is not a recipe");
285 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
286 }
287
288 /* Get the recipe */
289 recipe = (cpl_recipe *)plugin;
290
291 /* Create the parameters list in the cpl_recipe object */
292 recipe->parameters = cpl_parameterlist_new();
293 if (recipe->parameters == NULL) {
294 cpl_msg_error(cpl_func, "Parameter list allocation failed");
295 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
296 }
297
298 moo_params *params = moo_params_new("moons", "moons_mflat");
299
300 /* Fill the parameters list */
301 moo_params_add_keep_temp(params, recipe->parameters);
302 moo_params_add_prepare(params, recipe->parameters);
303 moo_params_add_correct_bias(params, recipe->parameters,
304 MOO_CORRECT_BIAS_METHOD_MASTER);
305 moo_params_add_crh(params, recipe->parameters, MOO_CRH_METHOD_SIGCLIP);
306 moo_params_add_localise(params, recipe->parameters);
307 moo_params_add_compute_slitoffset(params, recipe->parameters);
308 moo_params_add_extract(params, recipe->parameters);
309 moo_params_add_model_flat(params, recipe->parameters);
310 moo_params_add_compute_fibtrans(params, recipe->parameters);
311 moo_params_delete(params);
312
313 return 0;
314}
315
316
317/*----------------------------------------------------------------------------*/
323/*----------------------------------------------------------------------------*/
324
325static int
326_moons_mflat_exec(cpl_plugin *plugin)
327{
328 cpl_recipe *recipe;
329 int recipe_status;
330 cpl_errorstate initial_errorstate = cpl_errorstate_get();
331
332 /* Return immediately if an error code is already set */
333 if (cpl_error_get_code() != CPL_ERROR_NONE) {
334 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
335 cpl_func, __LINE__, cpl_error_get_where());
336 return (int)cpl_error_get_code();
337 }
338
339 if (plugin == NULL) {
340 cpl_msg_error(cpl_func, "Null plugin");
341 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
342 }
343
344 /* Verify plugin type */
345 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
346 cpl_msg_error(cpl_func, "Plugin is not a recipe");
347 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
348 }
349
350 /* Get the recipe */
351 recipe = (cpl_recipe *)plugin;
352
353 /* Verify parameter and frame lists */
354 if (recipe->parameters == NULL) {
355 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
356 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
357 }
358 if (recipe->frames == NULL) {
359 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
360 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
361 }
362
363 /* Invoke the recipe */
364 recipe_status = _moons_mflat(recipe->frames, recipe->parameters);
365
366 /* Ensure DFS-compliance of the products */
367 if (cpl_dfs_update_product_header(recipe->frames)) {
368 if (!recipe_status)
369 recipe_status = (int)cpl_error_get_code();
370 }
371
372 if (!cpl_errorstate_is_equal(initial_errorstate)) {
373 /* Dump the error history since recipe execution start.
374 At this point the recipe cannot recover from the error */
375 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
376 }
377
378 return recipe_status;
379}
380
381
382/*----------------------------------------------------------------------------*/
388/*----------------------------------------------------------------------------*/
389
390static int
391_moons_mflat_destroy(cpl_plugin *plugin)
392{
393 cpl_recipe *recipe;
394
395 if (plugin == NULL) {
396 cpl_msg_error(cpl_func, "Null plugin");
397 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
398 }
399
400 /* Verify plugin type */
401 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
402 cpl_msg_error(cpl_func, "Plugin is not a recipe");
403 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
404 }
405
406 /* Get the recipe */
407 recipe = (cpl_recipe *)plugin;
408
409 cpl_parameterlist_delete(recipe->parameters);
410
411 return 0;
412}
413
414/*----------------------------------------------------------------------------*/
432/*----------------------------------------------------------------------------*/
433static cpl_frame *
434_moons_prepare(moo_products *products,
435 const cpl_frame *frame,
436 const cpl_frame *frame_off,
437 const char *bpmap_rp_name,
438 const char *bpmap_nl_name,
439 const cpl_frame *masterbias,
440 const cpl_frame *masterdark_vis,
441 const cpl_frame *masterdark_nir,
442 const cpl_frame *coeffs_cube,
443 moo_prepare_params *prepare_params,
444 moo_correct_bias_params *params,
445 int i,
446 int offset,
447 moo_mode_type mode)
448{
449 cpl_frame *result = NULL;
450 cpl_frame *pframe = NULL;
451 char *detname1 = NULL;
452 char *detname2 = NULL;
453 char *detname3 = NULL;
454 moo_det *det = NULL;
455 moo_det *detoff = NULL;
456
457 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
458 cpl_ensure(frame_off != NULL, CPL_ERROR_NULL_INPUT, NULL);
459 cpl_errorstate prestate = cpl_errorstate_get();
460
461 moo_try_check(det = moo_prepare(frame, bpmap_rp_name, bpmap_nl_name,
462 masterbias, coeffs_cube, prepare_params),
463 " ");
464
465 moo_try_check(moo_correct_bias(det, masterbias, params), " ");
466
467 moo_try_check(detname1 = cpl_sprintf("%s_OFFSET%d_%s_%d.fits",
468 MOONS_TAG_FLAT_CORRECTBIAS, offset,
469 moo_mode_get_name(mode), i),
470 " ");
471 moo_try_check(moo_products_add(products, det, CPL_FRAME_LEVEL_INTERMEDIATE,
472 MOONS_TAG_FLAT_CORRECTBIAS, detname1, frame),
473 " ");
474
475 moo_try_check(detname2 = cpl_sprintf("%s_OFFSET%d_%s_%d.fits",
476 MOONS_TAG_FLATOFF_PREPARE, offset,
477 moo_mode_get_name(mode), i),
478 " ");
479
480 moo_try_check(detoff = moo_prepare(frame_off, bpmap_rp_name, bpmap_nl_name,
481 masterbias, coeffs_cube, prepare_params),
482 " ");
483
484 moo_try_check(pframe = moo_products_add(products, detoff,
485 CPL_FRAME_LEVEL_INTERMEDIATE,
486 MOONS_TAG_FLATOFF_PREPARE, detname2,
487 frame_off),
488 " ");
489
490 moo_try_check(moo_correct_dark(det, detoff, masterdark_vis, masterdark_nir),
491 " ");
492 moo_try_check(detname3 = cpl_sprintf("%s_OFFSET%d_%s_%d.fits",
493 MOONS_TAG_FLAT_CORRECTDARK, offset,
494 moo_mode_get_name(mode), i),
495 " ");
496 moo_try_check(pframe = moo_products_add(products, det,
497 CPL_FRAME_LEVEL_INTERMEDIATE,
498 MOONS_TAG_FLAT_CORRECTDARK,
499 detname3, frame),
500 " ");
501
502 moo_try_check(result = cpl_frame_duplicate(pframe), " ");
503
504moo_try_cleanup:
505 if (!cpl_errorstate_is_equal(prestate)) {
506 cpl_frame_delete(result);
507 result = NULL;
508 }
509 moo_det_delete(det);
510 moo_det_delete(detoff);
511 cpl_free(detname1);
512 cpl_free(detname2);
513 cpl_free(detname3);
514 return result;
515}
516
517/*----------------------------------------------------------------------------*/
533/*----------------------------------------------------------------------------*/
534static cpl_frameset *
535_moons_prepare_set(cpl_frameset *raw_frames,
536 cpl_frameset *rawoff_frames,
537 const char *bpmap_rp_name,
538 const char *bpmap_nl_name,
539 const cpl_frame *masterbias,
540 const cpl_frame *masterdark_vis,
541 const cpl_frame *masterdark_nir,
542 const cpl_frame *coeffs_cube,
543 moo_prepare_params *prepare_params,
544 moo_correct_bias_params *params,
545 moo_products *products,
546 int offset,
547 moo_mode_type mode)
548{
549 cpl_frameset *detframes = NULL;
550 moo_det *det = NULL;
551 moo_det *detoff = NULL;
552
553 cpl_ensure(raw_frames, CPL_ERROR_NULL_INPUT, NULL);
554 cpl_ensure(rawoff_frames, CPL_ERROR_NULL_INPUT, NULL);
555 cpl_ensure(products, CPL_ERROR_NULL_INPUT, NULL);
556
557 cpl_errorstate prestate = cpl_errorstate_get();
558
559 moo_try_check(detframes = cpl_frameset_new(), " ");
560
561 int i;
562
563 for (i = 0; i < cpl_frameset_get_size(raw_frames); ++i) {
564 const cpl_frame *current_frame = NULL;
565 const cpl_frame *raw_off = NULL;
566 cpl_frame *pframe = NULL;
567
568 moo_try_check(current_frame =
569 cpl_frameset_get_position_const(raw_frames, i),
570 " ");
571 moo_try_check(raw_off =
572 cpl_frameset_get_position_const(rawoff_frames, i),
573 " ");
574
575 moo_try_check(pframe = _moons_prepare(products, current_frame, raw_off,
576 bpmap_rp_name, bpmap_nl_name,
577 masterbias, masterdark_vis,
578 masterdark_nir, coeffs_cube,
579 prepare_params, params, i, mode,
580 offset),
581 " ");
582 moo_try_check(cpl_frameset_insert(detframes, pframe), " ");
583 }
584
585moo_try_cleanup:
586 if (!cpl_errorstate_is_equal(prestate)) {
587 moo_det_delete(det);
588 moo_det_delete(detoff);
589 cpl_frameset_delete(detframes);
590 detframes = NULL;
591 }
592 return detframes;
593}
594
595/*----------------------------------------------------------------------------*/
605/*----------------------------------------------------------------------------*/
606static cpl_error_code
607_moons_flat_check_header(const cpl_frame *raw, const cpl_frame *ff_trace)
608{
609 cpl_ensure_code(raw != NULL, CPL_ERROR_NULL_INPUT);
610 cpl_ensure_code(ff_trace != NULL, CPL_ERROR_NULL_INPUT);
611 cpl_error_code status = CPL_ERROR_NONE;
612 const char *filename = NULL;
613 const char *trace_filename = NULL;
614 cpl_propertylist *raw_pheader = NULL;
615 cpl_propertylist *trace_pheader = NULL;
616 int raw_offset, trace_offset;
617
618 cpl_errorstate prestate = cpl_errorstate_get();
619 moo_try_check(filename = cpl_frame_get_filename(raw), " ");
620 moo_try_check(trace_filename = cpl_frame_get_filename(ff_trace), " ");
621
622 moo_try_check(raw_pheader = cpl_propertylist_load(filename, 0), " ");
623 moo_try_check(trace_pheader = cpl_propertylist_load(trace_filename, 0),
624 " ");
625
626 moo_try_check(raw_offset = moo_pfits_get_slit_offset(raw_pheader), " ");
627 moo_try_check(trace_offset = moo_pfits_get_slit_offset(trace_pheader), " ");
628
629 if (raw_offset != trace_offset) {
630 cpl_msg_error("check_header",
631 "OFFSET keyword mismatch between FLAT file %s value %d "
632 "and FF_TRACE file %s value %d",
633 filename, raw_offset, trace_filename, trace_offset);
634 status = CPL_ERROR_ILLEGAL_INPUT;
635 cpl_error_set("check_header", status);
636 }
637
638moo_try_cleanup:
639 if (!cpl_errorstate_is_equal(prestate)) {
640 status = cpl_error_get_code();
641 }
642 cpl_propertylist_delete(raw_pheader);
643 cpl_propertylist_delete(trace_pheader);
644 return status;
645}
646
647/*----------------------------------------------------------------------------*/
664/*----------------------------------------------------------------------------*/
665static moo_loc *
666_moons_mflat_localise(cpl_frameset *raw_frames,
667 cpl_frameset *rawoff_frames,
668 const char *bpmap_rp_name,
669 const char *bpmap_nl_name,
670 const cpl_frame *masterbias,
671 const cpl_frame *masterdark_vis,
672 const cpl_frame *masterdark_nir,
673 const cpl_frame *coeffs_cube,
674 const cpl_frame *p2pmap,
675 const cpl_frame *ff_trace_guess,
676 moo_prepare_params *prepare_params,
677 moo_crh_params *crh_params,
678 moo_compute_slitoffset_params *compute_slitoffset_params,
679 moo_localise_params *localise_params,
680 moo_model_flat_params *modelflat_params,
681 moo_correct_bias_params *cbias_params,
682 int domodel,
683 const char *loctag,
684 moo_products *products,
685 moo_det **medflat,
686 moo_psf **psf,
687 const cpl_frame **ref_frame,
688 double *offset,
689 moo_mode_type *mode,
690 cpl_frame_level level)
691{
692 moo_loc *loc = NULL;
693 cpl_frameset *detframes = NULL;
694 moo_detlist *detList = NULL;
695 char *locname = NULL;
696 char *flatname = NULL;
697 char *flatp2p_name = NULL;
698 moo_det *p2p = NULL;
699
700 cpl_ensure(loctag != NULL, CPL_ERROR_NULL_INPUT, NULL);
701 cpl_ensure(raw_frames != NULL, CPL_ERROR_NULL_INPUT, NULL);
702 cpl_ensure(rawoff_frames != NULL, CPL_ERROR_NULL_INPUT, NULL);
703
704 cpl_errorstate prestate = cpl_errorstate_get();
705
706 int nraw, nraw_off;
707
708 moo_try_check(nraw = cpl_frameset_get_size(raw_frames), " ");
709 moo_try_check(nraw_off = cpl_frameset_get_size(rawoff_frames), " ");
710
711 if (nraw == 0) {
712 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
713 "SOF does not have any file tagged "
714 "with %s",
715 MOONS_TAG_FLAT);
716 return NULL;
717 }
718
719 if (nraw < 3) {
720 cpl_msg_warning(cpl_func,
721 "SOF does not have enough files (%d<3) tagged "
722 "with %s",
723 nraw, MOONS_TAG_FLAT);
724 }
725
726 if (nraw_off != nraw) {
727 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
728 "SOF does not have %d files tagged "
729 "with %s",
730 nraw, MOONS_TAG_FLAT_OFF);
731 return NULL;
732 }
733
734 if (masterbias == NULL) {
735 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
736 "SOF does not have any file tagged "
737 "with %s",
738 MOONS_TAG_MASTER_BIAS);
739 return NULL;
740 }
741
742 if (ff_trace_guess != NULL) {
743 moo_try_check(_moons_flat_check_header(
744 cpl_frameset_get_position_const(raw_frames, 0),
745 ff_trace_guess),
746 " Mismatch header");
747 }
748
749 moo_try_check(*ref_frame = cpl_frameset_get_position_const(raw_frames, 0),
750 " ");
751 moo_try_check(*mode = moo_mode_get(*ref_frame), " ");
752 moo_try_check(*offset = moo_offset_get(*ref_frame), " ");
753
754
755 moo_try_check(detframes = _moons_prepare_set(raw_frames, rawoff_frames,
756 bpmap_rp_name, bpmap_nl_name,
757 masterbias, masterdark_vis,
758 masterdark_nir, coeffs_cube,
759 prepare_params, cbias_params,
760 products, *mode, *offset),
761 " ");
762
763 moo_try_check(detList = moo_detlist_create(detframes), " ");
764 moo_try_check(*medflat = moo_remove_CRH(detList, NULL, crh_params), " ");
765 moo_try_check(flatname = cpl_sprintf("%s_OFFSET%d_%s.fits",
766 MOONS_TAG_FLAT_REMOVECRH, (int)*offset,
767 moo_mode_get_name(*mode)),
768 " ");
769
770 moo_try_check(moo_products_add(products, *medflat,
771 CPL_FRAME_LEVEL_INTERMEDIATE,
772 MOONS_TAG_FLAT_REMOVECRH, flatname,
773 *ref_frame),
774 " ");
775
776 if (p2pmap != NULL) {
777 moo_try_check(p2p = moo_det_create(p2pmap), " ");
778 moo_try_check(moo_apply_p2p(*medflat, p2p), " ");
779 flatp2p_name =
780 cpl_sprintf("%s_OFFSET%d_%s.fits", MOONS_TAG_FLAT_APPLYP2P,
781 (int)*offset, moo_mode_get_name(*mode));
782 moo_products_add(products, *medflat, CPL_FRAME_LEVEL_INTERMEDIATE,
783 MOONS_TAG_FLAT_APPLYP2P, flatp2p_name, *ref_frame);
784 moo_det_delete(p2p);
785 p2p = NULL;
786 }
787 if (ff_trace_guess != NULL) {
788 moo_loc *gloc = moo_loc_load(ff_trace_guess);
789 float *offsets =
790 moo_compute_slitoffset(*medflat, gloc, compute_slitoffset_params);
791 for (int i = 0; i < 6; i++) {
792 cpl_msg_info("test", "Offsets[%d]=%f", i, offsets[i]);
793 }
794 moo_loc_delete(gloc);
795 cpl_free(offsets);
796 }
797 moo_try_check(locname = cpl_sprintf("%s_OFFSET%d_%s.fits", loctag,
798 (int)*offset, moo_mode_get_name(*mode)),
799 " ");
800 moo_try_check(loc = moo_localise(*medflat, ff_trace_guess, localise_params,
801 locname),
802 " ");
803
804 moo_try_check(moo_products_add_loc(products, loc,
805 localise_params->keep_points, level,
806 loctag, locname, *ref_frame),
807 " ");
808
809 if (domodel) {
810 char *psfname =
811 cpl_sprintf("%s_OFFSET%d_%s.fits", MOONS_TAG_MASTER_FLAT,
812 (int)*offset, moo_mode_get_name(*mode));
813 *psf = moo_model_flat(*medflat, loc, modelflat_params, psfname);
814 moo_products_add_psf(products, *psf, level, MOONS_TAG_MASTER_FLAT,
815 psfname, *ref_frame);
816 cpl_free(psfname);
817 }
818
819moo_try_cleanup:
820 cpl_frameset_delete(detframes);
821 moo_detlist_delete(detList);
822 cpl_free(flatname);
823 cpl_free(flatp2p_name);
824 cpl_free(locname);
825 if (!cpl_errorstate_is_equal(prestate)) {
826 moo_loc_delete(loc);
827 loc = NULL;
828 moo_det_delete(p2p);
829 p2p = NULL;
830 }
831 return loc;
832}
833
834static cpl_error_code
835_moons_mflat_fibtrans(moo_det *medflat,
836 moo_loc *ff_trace,
837 moo_psf *psf,
838 moo_extract_params *extract_params,
839 moo_compute_fibtrans_params *fibtrans_params,
840 moo_products *products,
841 const cpl_frame *ref_frame,
842 double offset,
843 moo_mode_type mode)
844{
845 moo_f2f *f2f = NULL;
846 moo_ext *ext = NULL;
847 char *flatname = NULL;
848 char *extname = NULL;
849 char *ffname = NULL;
850 char *f2fname = NULL;
851
852 cpl_ensure_code(medflat != NULL, CPL_ERROR_NULL_INPUT);
853 cpl_msg_info("moons_mflat", "Work on offset %d mode %s", (int)offset,
854 moo_mode_get_name(mode));
855
856 extname = cpl_sprintf("%s_OFFSET%d_%s.fits", MOONS_TAG_FLAT_EXTSPECTRA,
857 (int)offset, moo_mode_get_name(mode));
858
859 moo_try_check(ext = moo_extract(medflat, ff_trace, psf, extract_params,
860 extname),
861 " ");
862 moo_products_add_ext(products, ext, CPL_FRAME_LEVEL_INTERMEDIATE,
863 MOONS_TAG_FLAT_EXTSPECTRA, extname, ref_frame);
864
865
866 ffname = cpl_sprintf("%s_OFFSET%d_%s.fits", MOONS_TAG_FF_EXTSPECTRA,
867 (int)offset, moo_mode_get_name(mode));
868 f2fname = cpl_sprintf("%s_OFFSET%d_%s.fits", MOONS_TAG_F2F_TABLE,
869 (int)offset, moo_mode_get_name(mode));
870
871 moo_try_check(f2f = moo_compute_fibtrans(ext, fibtrans_params, f2fname),
872 " ");
873 moo_products_add_ext(products, ext, CPL_FRAME_LEVEL_FINAL,
874 MOONS_TAG_FF_EXTSPECTRA, ffname, ref_frame);
875 moo_products_add_f2f(products, f2f, CPL_FRAME_LEVEL_FINAL,
876 MOONS_TAG_F2F_TABLE, f2fname, ref_frame);
877
878moo_try_cleanup:
879 cpl_free(flatname);
880 cpl_free(extname);
881 cpl_free(f2fname);
882 cpl_free(ffname);
883
884 moo_ext_delete(ext);
885 moo_f2f_delete(f2f);
886
887 return CPL_ERROR_NONE;
888}
889
890/*----------------------------------------------------------------------------*/
910/*----------------------------------------------------------------------------*/
911static int
912_moons_mflat_wf1(cpl_frameset **raw_byoffset_set,
913 cpl_frameset *rawoff_frames,
914 const char *bpmap_rp_name,
915 const char *bpmap_nl_name,
916 const cpl_frame *masterbias,
917 const cpl_frame *masterdark_vis,
918 const cpl_frame *masterdark_nir,
919 const cpl_frame *coeffs_cube,
920 moo_prepare_params *prepare_params,
921 moo_crh_params *crh_params,
922 moo_localise_params *localise_params,
923 moo_correct_bias_params *cbias_params,
924 moo_products *products)
925{
926 cpl_ensure_code(raw_byoffset_set != NULL, CPL_ERROR_NULL_INPUT);
927 cpl_ensure_code(raw_byoffset_set[0] != NULL, CPL_ERROR_NULL_INPUT);
928 cpl_ensure_code(raw_byoffset_set[1] != NULL, CPL_ERROR_NULL_INPUT);
929
930 int size1 = 0;
931 int size2 = 0;
932 cpl_frameset *raw_frames = NULL;
933 const cpl_frame *ref_frame = NULL;
934 moo_det *medflat = NULL;
935 moo_loc *guess_loc = NULL;
936 double offset;
937 moo_mode_type mode;
938 moo_try_check(size1 = cpl_frameset_get_size(raw_byoffset_set[0]), " ");
939 moo_try_check(size2 = cpl_frameset_get_size(raw_byoffset_set[1]), " ");
940
941
942 if (size1 > 0) {
943 if (size2 > 0) {
944 return (int)
945 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
946 "SOF have two different offset in input");
947 }
948 raw_frames = raw_byoffset_set[0];
949 }
950 else {
951 raw_frames = raw_byoffset_set[1];
952 }
953 moo_try_assure(cpl_frameset_get_size(raw_frames) > 0,
954 CPL_ERROR_ILLEGAL_INPUT, "No FLAT frames in input");
955 moo_try_check(guess_loc = _moons_mflat_localise(
956 raw_frames, rawoff_frames, bpmap_rp_name, bpmap_nl_name,
957 masterbias, masterdark_vis, masterdark_nir, coeffs_cube,
958 NULL, NULL, prepare_params, crh_params, NULL,
959 localise_params, NULL, cbias_params, 0,
960 MOONS_TAG_FF_TRACE_GUESS, products, &medflat, NULL,
961 &ref_frame, &offset, &mode, CPL_FRAME_LEVEL_FINAL),
962 " ");
963
964moo_try_cleanup:
965 moo_loc_delete(guess_loc);
966 moo_det_delete(medflat);
967 return CPL_ERROR_NONE;
968}
969/*----------------------------------------------------------------------------*/
990/*----------------------------------------------------------------------------*/
991static int
992_moons_mflat_wf4(const cpl_frame *flat_attached_frame,
993 const cpl_frame *flat_off_frame,
994 const char *bpmap_rp_name,
995 const char *bpmap_nl_name,
996 const cpl_frame *masterbias,
997 const cpl_frame *masterdark_vis,
998 const cpl_frame *masterdark_nir,
999 const cpl_frame *coeffs_cube,
1000 const cpl_frame *ff_trace_frame,
1001 const cpl_frame *p2pmap,
1002 const cpl_frame *master_flat,
1003 moo_prepare_params *prepare_params,
1004 moo_extract_params *extract_params,
1005 moo_compute_fibtrans_params *fibtrans_params,
1006 moo_correct_bias_params *cbias_params,
1007 moo_products *products)
1008{
1009 cpl_ensure_code(flat_attached_frame != NULL, CPL_ERROR_NULL_INPUT);
1010 cpl_ensure_code(flat_off_frame != NULL, CPL_ERROR_NULL_INPUT);
1011 cpl_ensure_code(ff_trace_frame != NULL, CPL_ERROR_NULL_INPUT);
1012
1013 moo_loc *ff_trace = NULL;
1014 int offset;
1015 moo_mode_type mode;
1016 char *detname1 = NULL;
1017 char *detname2 = NULL;
1018 char *detname3 = NULL;
1019 moo_det *det = NULL;
1020 moo_det *detoff = NULL;
1021 moo_f2f *f2f = NULL;
1022 moo_ext *ext = NULL;
1023 char *flatname = NULL;
1024 char *extname = NULL;
1025 char *f2fname = NULL;
1026 moo_det *p2p = NULL;
1027 moo_psf *psf = NULL;
1028
1029 cpl_errorstate prestate = cpl_errorstate_get();
1030
1031 if (masterbias == NULL) {
1032 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
1033 "SOF does not have any file tagged "
1034 "with %s",
1035 MOONS_TAG_MASTER_BIAS);
1036 return CPL_ERROR_NONE;
1037 }
1038
1039 if (ff_trace_frame != NULL) {
1040 moo_try_check(_moons_flat_check_header(flat_attached_frame,
1041 ff_trace_frame),
1042 " Mismatch header");
1043 }
1044
1045 moo_try_check(mode = moo_mode_get(flat_attached_frame), " ");
1046 moo_try_check(offset = moo_offset_get(flat_attached_frame), " ");
1047 moo_try_check(det = moo_prepare(flat_attached_frame, bpmap_rp_name,
1048 bpmap_nl_name, masterbias, coeffs_cube,
1049 prepare_params),
1050 " ");
1051
1052 moo_try_check(detoff =
1053 moo_prepare(flat_off_frame, bpmap_rp_name, bpmap_nl_name,
1054 masterbias, coeffs_cube, prepare_params),
1055 " ");
1056 moo_try_check(moo_correct_bias(det, masterbias, cbias_params), " ");
1057
1058 moo_try_check(detname1 = cpl_sprintf("%s_OFFSET%d_%s.fits",
1059 MOONS_TAG_FLAT_CORRECTBIAS, offset,
1060 moo_mode_get_name(mode)),
1061 " ");
1062 moo_try_check(moo_products_add(products, det, CPL_FRAME_LEVEL_INTERMEDIATE,
1063 MOONS_TAG_FLAT_CORRECTBIAS, detname1,
1064 flat_attached_frame),
1065 " ");
1066
1067 moo_try_check(detname2 = cpl_sprintf("%s_OFFSET%d_%s.fits",
1068 MOONS_TAG_FLATOFF_PREPARE, offset,
1069 moo_mode_get_name(mode)),
1070 " ");
1071
1072 moo_try_check(moo_products_add(products, detoff,
1073 CPL_FRAME_LEVEL_INTERMEDIATE,
1074 MOONS_TAG_FLATOFF_PREPARE, detname2,
1075 flat_off_frame),
1076 " ");
1077
1078 moo_try_check(moo_correct_dark(det, detoff, masterdark_vis, masterdark_nir),
1079 " ");
1080 moo_try_check(detname3 = cpl_sprintf("%s_OFFSET%d_%s.fits",
1081 MOONS_TAG_FLAT_CORRECTDARK, offset,
1082 moo_mode_get_name(mode)),
1083 " ");
1084 moo_try_check(moo_products_add(products, det, CPL_FRAME_LEVEL_INTERMEDIATE,
1085 MOONS_TAG_FLAT_CORRECTDARK, detname3,
1086 flat_attached_frame),
1087 " ");
1088
1089 if (p2pmap != NULL) {
1090 moo_try_check(p2p = moo_det_create(p2pmap), " ");
1091 moo_try_check(moo_apply_p2p(det, p2p), " ");
1092 flatname = cpl_sprintf("%s_OFFSET%d_%s.fits", MOONS_TAG_FLAT_APPLYP2P,
1093 offset, moo_mode_get_name(mode));
1094 moo_products_add(products, det, CPL_FRAME_LEVEL_INTERMEDIATE,
1095 MOONS_TAG_FLAT_APPLYP2P, flatname,
1096 flat_attached_frame);
1097
1098 moo_det_delete(p2p);
1099 p2p = NULL;
1100 }
1101
1102 extname =
1103 cpl_sprintf("EXT_OFFSET%d_%s.fits", offset, moo_mode_get_name(mode));
1104
1105 moo_try_check(ff_trace = moo_loc_load(ff_trace_frame), " ");
1106
1107 if (master_flat != NULL) {
1108 psf = moo_psf_load(master_flat);
1109 }
1110 moo_try_check(ext =
1111 moo_extract(det, ff_trace, psf, extract_params, extname),
1112 " ");
1113
1114 moo_products_add_ext(products, ext, CPL_FRAME_LEVEL_INTERMEDIATE, "EXT",
1115 extname, flat_attached_frame);
1116
1117
1118 f2fname =
1119 cpl_sprintf("F2F_OFFSET%d_%s.fits", offset, moo_mode_get_name(mode));
1120 f2f = moo_compute_fibtrans(ext, fibtrans_params, f2fname);
1121 moo_flat_shift_compute(det, ff_trace);
1122
1123 moo_products_add_f2f(products, f2f, CPL_FRAME_LEVEL_FINAL,
1124 MOONS_TAG_F2F_TABLE, f2fname, flat_attached_frame);
1125
1126moo_try_cleanup:
1127 cpl_free(flatname);
1128 cpl_free(extname);
1129 cpl_free(f2fname);
1130
1131 moo_ext_delete(ext);
1132 moo_f2f_delete(f2f);
1133 if (!cpl_errorstate_is_equal(prestate)) {
1134 moo_det_delete(p2p);
1135 }
1136 moo_det_delete(det);
1137 moo_det_delete(detoff);
1138 cpl_free(detname1);
1139 cpl_free(detname2);
1140 cpl_free(detname3);
1141 moo_loc_delete(ff_trace);
1142 moo_psf_delete(psf);
1143
1144 return CPL_ERROR_NONE;
1145}
1146
1147/*----------------------------------------------------------------------------*/
1171/*----------------------------------------------------------------------------*/
1172static int
1173_moons_mflat_wf2(cpl_frameset **raw_byoffset_set,
1174 cpl_frameset *rawoff_frames,
1175 const char *bpmap_rp_name,
1176 const char *bpmap_nl_name,
1177 const cpl_frame *masterbias,
1178 const cpl_frame *masterdark_vis,
1179 const cpl_frame *masterdark_nir,
1180 const cpl_frame *coeffs_cube,
1181 const cpl_frame *ff_trace_guess,
1182 const cpl_frame *p2pmap,
1183 moo_prepare_params *prepare_params,
1184 moo_crh_params *crh_params,
1185 moo_localise_params *localise_params,
1186 moo_compute_slitoffset_params *compute_slitoffset_params,
1187 moo_extract_params *extract_params,
1188 moo_model_flat_params *modelflat_params,
1189 moo_compute_fibtrans_params *fibtrans_params,
1190 moo_correct_bias_params *cbias_params,
1191 moo_products *products)
1192{
1193 cpl_ensure_code(raw_byoffset_set != NULL, CPL_ERROR_NULL_INPUT);
1194 cpl_ensure_code(raw_byoffset_set[0] != NULL, CPL_ERROR_NULL_INPUT);
1195 cpl_ensure_code(raw_byoffset_set[1] != NULL, CPL_ERROR_NULL_INPUT);
1196
1197 int domodel =
1198 (strcmp(extract_params->method, MOO_EXTRACT_METHOD_OPTIMAL) == 0);
1199
1200 const cpl_frame *ref_frame = NULL;
1201 cpl_frameset *raw_frames = NULL;
1202 moo_det *medflat = NULL;
1203 moo_loc *ff_trace = NULL;
1204 moo_psf *psf = NULL;
1205 double offset;
1206 moo_mode_type mode;
1207 int size1 = 0;
1208 int size2 = 0;
1209
1210 moo_try_check(size1 = cpl_frameset_get_size(raw_byoffset_set[0]), " ");
1211 moo_try_check(size2 = cpl_frameset_get_size(raw_byoffset_set[1]), " ");
1212
1213 if (size1 > 0) {
1214 if (size2 > 0) {
1215 return (int)cpl_error_set_message(
1216 cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1217 "SOF have two different offset in input ");
1218 }
1219 raw_frames = raw_byoffset_set[0];
1220 }
1221 else {
1222 raw_frames = raw_byoffset_set[1];
1223 }
1224
1225 moo_try_assure(cpl_frameset_get_size(raw_frames) > 0,
1226 CPL_ERROR_ILLEGAL_INPUT, "No FLAT frames in input");
1227
1228
1229 moo_try_check(ff_trace = _moons_mflat_localise(
1230 raw_frames, rawoff_frames, bpmap_rp_name, bpmap_nl_name,
1231 masterbias, masterdark_vis, masterdark_nir, coeffs_cube,
1232 p2pmap, ff_trace_guess, prepare_params, crh_params,
1233 compute_slitoffset_params, localise_params,
1234 modelflat_params, cbias_params, domodel,
1235 MOONS_TAG_FF_TRACE, products, &medflat, &psf, &ref_frame,
1236 &offset, &mode, CPL_FRAME_LEVEL_FINAL),
1237 " ");
1238
1239 moo_try_check(_moons_mflat_fibtrans(medflat, ff_trace, psf, extract_params,
1240 fibtrans_params, products, ref_frame,
1241 offset, mode),
1242 " ");
1243
1244moo_try_cleanup:
1245 moo_loc_delete(ff_trace);
1246 moo_det_delete(medflat);
1247 moo_psf_delete(psf);
1248
1249 return CPL_ERROR_NONE;
1250}
1251
1252static int
1253_moons_mflat_wf3(cpl_frameset **raw_byoffset_set,
1254 cpl_frameset *rawoff_frames,
1255 const char *bpmap_rp_name,
1256 const char *bpmap_nl_name,
1257 const cpl_frame *masterbias,
1258 const cpl_frame *masterdark_vis,
1259 const cpl_frame *masterdark_nir,
1260 cpl_frameset **cube_set,
1261 cpl_frameset **ff_trace_set,
1262 moo_prepare_params *prepare_params,
1263 moo_crh_params *crh_params,
1264 moo_compute_slitoffset_params *compute_slitoffset_params,
1265 moo_localise_params *localise_params,
1266 moo_model_flat_params *modelflat_params,
1267 moo_correct_bias_params *cbias_params,
1268 moo_products *products)
1269{
1270 moo_det *medflat1 = NULL;
1271 moo_loc *ff_trace1 = NULL;
1272 double offset1;
1273 moo_mode_type mode;
1274 moo_psf *psf1 = NULL;
1275 const cpl_frame *coeffs_cube1 = NULL;
1276 const cpl_frame *coeffs_cube2 = NULL;
1277 const cpl_frame *ref_frame2 = NULL;
1278
1279 moo_det *medflat2 = NULL;
1280 moo_loc *ff_trace2 = NULL;
1281 double offset2;
1282 moo_psf *psf2 = NULL;
1283 moo_det *p2p = NULL;
1284 char *p2pname = NULL;
1285
1286 int sff_trace1 = cpl_frameset_get_size(ff_trace_set[0]);
1287 int sff_trace2 = cpl_frameset_get_size(ff_trace_set[1]);
1288
1289 cpl_ensure_code(sff_trace1 == 1, CPL_ERROR_ILLEGAL_INPUT);
1290 cpl_ensure_code(sff_trace2 == 1, CPL_ERROR_ILLEGAL_INPUT);
1291
1292 const cpl_frame *ref_frame1 = NULL;
1293 cpl_frameset *raw_frames1 = raw_byoffset_set[0];
1294 const cpl_frame *ff_trace_guess1 =
1295 cpl_frameset_get_position_const(ff_trace_set[0], 0);
1296 cpl_frameset *raw_frames2 = raw_byoffset_set[1];
1297 int csize1 = cpl_frameset_get_size(cube_set[0]);
1298 int csize2 = cpl_frameset_get_size(cube_set[1]);
1299 if (csize1 > 0) {
1300 coeffs_cube1 = cpl_frameset_get_position_const(cube_set[0], 0);
1301 }
1302 if (csize2 > 0) {
1303 coeffs_cube2 = cpl_frameset_get_position_const(cube_set[1], 0);
1304 }
1305
1306 const cpl_frame *ff_trace_guess2 =
1307 cpl_frameset_get_position_const(ff_trace_set[1], 0);
1308 moo_try_check(ff_trace1 = _moons_mflat_localise(
1309 raw_frames1, rawoff_frames, bpmap_rp_name, bpmap_nl_name,
1310 masterbias, masterdark_vis, masterdark_nir, coeffs_cube1,
1311 NULL, ff_trace_guess1, prepare_params, crh_params,
1312 compute_slitoffset_params, localise_params,
1313 modelflat_params, cbias_params, 1, MOONS_TAG_FF_TRACE,
1314 products, &medflat1, &psf1, &ref_frame1, &offset1, &mode,
1315 CPL_FRAME_LEVEL_INTERMEDIATE),
1316 "Can't localise offset1");
1317
1318 moo_try_check(ff_trace2 = _moons_mflat_localise(
1319 raw_frames2, rawoff_frames, bpmap_rp_name, bpmap_nl_name,
1320 masterbias, masterdark_vis, masterdark_nir, coeffs_cube2,
1321 NULL, ff_trace_guess2, prepare_params, crh_params,
1322 compute_slitoffset_params, localise_params,
1323 modelflat_params, cbias_params, 1, MOONS_TAG_FF_TRACE,
1324 products, &medflat2, &psf2, &ref_frame2, &offset2, &mode,
1325 CPL_FRAME_LEVEL_INTERMEDIATE),
1326 "Can't localise offset 2");
1327
1328 moo_try_check(p2p = moo_compute_p2p(medflat1, ff_trace1, psf1, medflat2,
1329 ff_trace2, psf2),
1330 "can't compute P2P");
1331
1332 moo_try_check(p2pname = cpl_sprintf("%s_%s.fits", MOONS_TAG_P2P_MAP,
1333 moo_mode_get_name(mode)),
1334 " ");
1335
1336 moo_products_add(products, p2p, CPL_FRAME_LEVEL_FINAL, MOONS_TAG_P2P_MAP,
1337 p2pname, ref_frame1);
1338
1339moo_try_cleanup:
1340 moo_det_delete(medflat1);
1341 moo_loc_delete(ff_trace1);
1342 moo_det_delete(medflat2);
1343 moo_loc_delete(ff_trace2);
1344 moo_psf_delete(psf1);
1345 moo_psf_delete(psf2);
1346 moo_det_delete(p2p);
1347 cpl_free(p2pname);
1348
1349 return CPL_ERROR_NONE;
1350}
1351
1352/*----------------------------------------------------------------------------*/
1369/*----------------------------------------------------------------------------*/
1370static cpl_error_code
1371_moons_mflat_check_sof(cpl_frameset *frameset,
1372 cpl_frameset **ff_trace_guess_frames,
1373 cpl_frameset **raw_frames,
1374 const cpl_frame **flat_attached,
1375 const cpl_frame **ff_trace,
1376 const cpl_frame **master_flat,
1377 cpl_frameset **rawoff_frames,
1378 const char **bpmap_rp_name,
1379 const char **bpmap_nl_name,
1380 const cpl_frame **master_bias,
1381 const cpl_frame **master_dark_vis,
1382 const cpl_frame **master_dark_nir,
1383 cpl_frameset **coeffs_cube_frames,
1384 const cpl_frame **p2pmap)
1385{
1386 cpl_errorstate prestate = cpl_errorstate_get();
1387
1388 cpl_ensure_code(frameset != NULL, CPL_ERROR_NULL_INPUT);
1389 cpl_ensure_code(ff_trace_guess_frames != NULL, CPL_ERROR_NULL_INPUT);
1390 cpl_ensure_code(raw_frames != NULL, CPL_ERROR_NULL_INPUT);
1391 cpl_ensure_code(rawoff_frames != NULL, CPL_ERROR_NULL_INPUT);
1392 cpl_ensure_code(moo_dfs_set_groups(frameset) == CPL_ERROR_NONE,
1393 cpl_error_get_code());
1394
1395 moo_try_check(*ff_trace_guess_frames = cpl_frameset_new(), " ");
1396 moo_try_check(*coeffs_cube_frames = cpl_frameset_new(), " ");
1397 moo_try_check(*raw_frames = cpl_frameset_new(), " ");
1398 moo_try_check(*rawoff_frames = cpl_frameset_new(), " ");
1399
1400 int size = 0;
1401 moo_try_check(size = cpl_frameset_get_size(frameset), " ");
1402
1403 for (int i = 0; i < size; ++i) {
1404 const cpl_frame *current_frame = NULL;
1405
1406 moo_try_check(current_frame =
1407 cpl_frameset_get_position_const(frameset, i),
1408 " ");
1409
1410 if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_FLAT)) {
1411 moo_try_check(cpl_frameset_insert(*raw_frames, cpl_frame_duplicate(
1412 current_frame)),
1413 " ");
1414 }
1415 else if (!strcmp(cpl_frame_get_tag(current_frame),
1416 MOONS_TAG_FLAT_ATTACHED)) {
1417 *flat_attached = current_frame;
1418 }
1419 else if (!strcmp(cpl_frame_get_tag(current_frame),
1420 MOONS_TAG_FLAT_OFF)) {
1421 moo_try_check(cpl_frameset_insert(*rawoff_frames,
1422 cpl_frame_duplicate(
1423 current_frame)),
1424 " ");
1425 }
1426 else if (!strcmp(cpl_frame_get_tag(current_frame),
1427 MOONS_TAG_BP_MAP_RP)) {
1428 moo_try_check(*bpmap_rp_name =
1429 cpl_frame_get_filename(current_frame),
1430 " ");
1431 }
1432 else if (!strcmp(cpl_frame_get_tag(current_frame),
1433 MOONS_TAG_BP_MAP_NL)) {
1434 moo_try_check(*bpmap_nl_name =
1435 cpl_frame_get_filename(current_frame),
1436 " ");
1437 }
1438 else if (!strcmp(cpl_frame_get_tag(current_frame),
1439 MOONS_TAG_MASTER_BIAS)) {
1440 *master_bias = current_frame;
1441 }
1442 else if (!strcmp(cpl_frame_get_tag(current_frame),
1443 MOONS_TAG_MASTER_DARK_VIS)) {
1444 *master_dark_vis = current_frame;
1445 }
1446 else if (!strcmp(cpl_frame_get_tag(current_frame),
1447 MOONS_TAG_MASTER_DARK_NIR)) {
1448 *master_dark_nir = current_frame;
1449 }
1450 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_P2P_MAP)) {
1451 *p2pmap = current_frame;
1452 }
1453 else if (!strcmp(cpl_frame_get_tag(current_frame),
1454 MOONS_TAG_FF_TRACE_GUESS)) {
1455 moo_try_check(cpl_frameset_insert(*ff_trace_guess_frames,
1456 cpl_frame_duplicate(
1457 current_frame)),
1458 " ");
1459 }
1460 else if (!strcmp(cpl_frame_get_tag(current_frame),
1461 MOONS_TAG_FF_TRACE)) {
1462 *ff_trace = current_frame;
1463 }
1464 else if (!strcmp(cpl_frame_get_tag(current_frame),
1465 MOONS_TAG_MASTER_FLAT)) {
1466 *master_flat = current_frame;
1467 }
1468 else if (!strcmp(cpl_frame_get_tag(current_frame),
1469 MOONS_TAG_LINEARITY_COEFF_CUBE)) {
1470 moo_try_check(cpl_frameset_insert(*coeffs_cube_frames,
1471 cpl_frame_duplicate(
1472 current_frame)),
1473 " ");
1474 }
1475 }
1476
1477moo_try_cleanup:
1478 if (!cpl_errorstate_is_equal(prestate)) {
1479 cpl_frameset_delete(*ff_trace_guess_frames);
1480 cpl_frameset_delete(*raw_frames);
1481 cpl_frameset_delete(*rawoff_frames);
1482 *ff_trace_guess_frames = NULL;
1483 *raw_frames = NULL;
1484 *rawoff_frames = NULL;
1485 }
1486 return cpl_error_get_code();
1487}
1488/*----------------------------------------------------------------------------*/
1495/*----------------------------------------------------------------------------*/
1496static int
1497_moons_mflat(cpl_frameset *frameset, const cpl_parameterlist *parlist)
1498{
1499 /* parameters */
1500 moo_prepare_params *prepare_params = NULL;
1501 moo_correct_bias_params *correct_bias_params = NULL;
1502 moo_localise_params *localise_params = NULL;
1503 moo_crh_params *crh_params = NULL;
1504 moo_compute_slitoffset_params *compute_slitoffset_params = NULL;
1505 moo_extract_params *extract_params = NULL;
1506 moo_model_flat_params *model_flat_params = NULL;
1507 moo_compute_fibtrans_params *fibtrans_params = NULL;
1508
1509 /* input files */
1510 const char *bpmap_rp_name = NULL;
1511 const char *bpmap_nl_name = NULL;
1512 const cpl_frame *masterbias = NULL;
1513 const cpl_frame *masterdark_vis = NULL;
1514 const cpl_frame *masterdark_nir = NULL;
1515 const cpl_frame *p2pmap = NULL;
1516 cpl_frameset *coeffs_cube_frames = NULL;
1517 cpl_frameset *ff_trace_guess_frames = NULL;
1518 cpl_frameset *raw_frames = NULL;
1519 const cpl_frame *flat_attached = NULL;
1520 const cpl_frame *ff_trace = NULL;
1521 const cpl_frame *master_flat = NULL;
1522 cpl_frameset *rawoff_frames = NULL;
1523 cpl_frameset **raw_byoffset_set = NULL;
1524
1525 moo_products *products = moo_products_new(frameset, parlist, "moons_mflat",
1526 PACKAGE "/" PACKAGE_VERSION);
1527
1528 /* parameters */
1529 const moo_params *params = moo_products_get_params(products);
1530 moo_try_check(prepare_params = moo_params_get_prepare(params, parlist),
1531 " ");
1532
1533 moo_try_check(correct_bias_params =
1534 moo_params_get_correct_bias(params, parlist),
1535 " ");
1536 moo_try_check(localise_params = moo_params_get_localise(params, parlist),
1537 " ");
1538 moo_try_check(crh_params = moo_params_get_crh(params, parlist), " ");
1539
1540 moo_try_check(compute_slitoffset_params =
1541 moo_params_get_compute_slitoffset(params, parlist),
1542 " ");
1543
1544 moo_try_check(extract_params = moo_params_get_extract(params, parlist),
1545 " ");
1546
1547 moo_try_check(model_flat_params =
1548 moo_params_get_model_flat(params, parlist),
1549 " ");
1550
1551 moo_try_check(fibtrans_params =
1552 moo_params_get_compute_fibtrans(params, parlist),
1553 " ");
1554
1555 /* SOF file */
1556 moo_try_check(_moons_mflat_check_sof(frameset, &ff_trace_guess_frames,
1557 &raw_frames, &flat_attached, &ff_trace,
1558 &master_flat, &rawoff_frames,
1559 &bpmap_rp_name, &bpmap_nl_name,
1560 &masterbias, &masterdark_vis,
1561 &masterdark_nir, &coeffs_cube_frames,
1562 &p2pmap),
1563 " ");
1564
1565 int size = 0;
1566 int csize = 0;
1567
1568 moo_try_check(csize = cpl_frameset_get_size(coeffs_cube_frames), " ");
1569 moo_try_check(size = cpl_frameset_get_size(ff_trace_guess_frames), " ");
1570 moo_try_check(raw_byoffset_set = moo_dfs_split_by_offset(raw_frames), " ");
1571
1572 if (flat_attached != NULL) {
1573 cpl_msg_info("moons_mflat", "Workflow 4 : create a F2F_TABLE");
1574 const cpl_frame *coeffs_cube = NULL;
1575 const cpl_frame *flat_off = NULL;
1576 int off_size = 0;
1577 moo_try_check(off_size = cpl_frameset_get_size(rawoff_frames), " ");
1578 if (off_size > 0) {
1579 flat_off = cpl_frameset_get_position_const(rawoff_frames, 0);
1580 }
1581 if (csize > 0) {
1582 coeffs_cube =
1583 cpl_frameset_get_position_const(coeffs_cube_frames, 0);
1584 }
1585
1586 _moons_mflat_wf4(flat_attached, flat_off, bpmap_rp_name, bpmap_nl_name,
1587 masterbias, masterdark_vis, masterdark_nir,
1588 coeffs_cube, ff_trace, p2pmap, master_flat,
1589 prepare_params, extract_params, fibtrans_params,
1590 correct_bias_params, products);
1591 }
1592 else if (size == 0) {
1593 cpl_msg_info("moons_mflat", "Workflow 1 : create a FF_TRACE_GUESS");
1594 _moons_mflat_wf1(raw_byoffset_set, rawoff_frames, bpmap_rp_name,
1595 bpmap_nl_name, masterbias, masterdark_vis,
1596 masterdark_nir, NULL, prepare_params, crh_params,
1597 localise_params, correct_bias_params, products);
1598 }
1599 else if (size == 1) {
1600 const cpl_frame *coeffs_cube = NULL;
1601
1602 if (csize > 0) {
1603 coeffs_cube =
1604 cpl_frameset_get_position_const(coeffs_cube_frames, 0);
1605 }
1606 cpl_msg_info("moons_mflat", "Workflow 2 : one offset reduction");
1607 const cpl_frame *ff_trace_guess =
1608 cpl_frameset_get_position_const(ff_trace_guess_frames, 0);
1609 _moons_mflat_wf2(raw_byoffset_set, rawoff_frames, bpmap_rp_name,
1610 bpmap_nl_name, masterbias, masterdark_vis,
1611 masterdark_nir, coeffs_cube, ff_trace_guess, p2pmap,
1612 prepare_params, crh_params, localise_params,
1613 compute_slitoffset_params, extract_params,
1614 model_flat_params, fibtrans_params,
1615 correct_bias_params, products);
1616 }
1617 else {
1618 cpl_msg_info("moons_mflat", "Workflow 3 : two offsets reduction");
1619 cpl_frameset **fftrace_byoffset_set =
1620 moo_dfs_split_by_offset(ff_trace_guess_frames);
1621 cpl_frameset **cube_byoffset_set =
1622 moo_dfs_split_by_offset(coeffs_cube_frames);
1623
1624 _moons_mflat_wf3(raw_byoffset_set, rawoff_frames, bpmap_rp_name,
1625 bpmap_nl_name, masterbias, masterdark_vis,
1626 masterdark_nir, cube_byoffset_set,
1627 fftrace_byoffset_set, prepare_params, crh_params,
1628 compute_slitoffset_params, localise_params,
1629 model_flat_params, correct_bias_params, products);
1630 for (int i = 0; i < 2; i++) {
1631 cpl_frameset_delete(fftrace_byoffset_set[i]);
1632 }
1633 cpl_free(fftrace_byoffset_set);
1634
1635 for (int i = 0; i < 2; i++) {
1636 cpl_frameset_delete(cube_byoffset_set[i]);
1637 }
1638 cpl_free(cube_byoffset_set);
1639 }
1640
1641moo_try_cleanup:
1642 if (raw_byoffset_set != NULL) {
1643 for (int i = 0; i < 2; i++) {
1644 cpl_frameset_delete(raw_byoffset_set[i]);
1645 }
1646 cpl_free(raw_byoffset_set);
1647 }
1648 cpl_frameset_delete(raw_frames);
1649 cpl_frameset_delete(rawoff_frames);
1650 cpl_frameset_delete(coeffs_cube_frames);
1651 cpl_frameset_delete(ff_trace_guess_frames);
1652 moo_crh_params_delete(crh_params);
1653 moo_localise_params_delete(localise_params);
1654 moo_compute_slitoffset_params_delete(compute_slitoffset_params);
1655 moo_extract_params_delete(extract_params);
1656 moo_model_flat_params_delete(model_flat_params);
1657 moo_compute_fibtrans_params_delete(fibtrans_params);
1658 moo_prepare_params_delete(prepare_params);
1659 moo_correct_bias_params_delete(correct_bias_params);
1660 moo_products_delete(products);
1661
1662 return (int)cpl_error_get_code();
1663}
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
void moo_ext_delete(moo_ext *self)
Delete a moo_ext.
Definition: moo_ext.c:370
void moo_f2f_delete(moo_f2f *self)
Delete a moo_f2f.
Definition: moo_f2f.c:413
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
cpl_error_code moo_params_add_compute_fibtrans(moo_params *self, cpl_parameterlist *list)
Add default parameters for compute_fibtrans.
Definition: moo_params.c:1866
cpl_error_code moo_params_add_extract(moo_params *self, cpl_parameterlist *list)
Add default parameters for extraction.
Definition: moo_params.c:902
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_localise_params * moo_params_get_localise(const moo_params *self, const cpl_parameterlist *list)
Get localisation parameters from moons parameters list.
Definition: moo_params.c:1233
cpl_error_code moo_params_add_compute_slitoffset(moo_params *self, cpl_parameterlist *list)
Add default parameters for moo_sci_compute_slitoffset.
Definition: moo_params.c:2663
moo_compute_slitoffset_params * moo_params_get_compute_slitoffset(const moo_params *self, const cpl_parameterlist *list)
Get compute_slitoffset parameters from moons parameters list.
Definition: moo_params.c:3119
moo_model_flat_params * moo_params_get_model_flat(const moo_params *self, const cpl_parameterlist *list)
Get model flat parameters from moons parameters list.
Definition: moo_params.c:1640
moo_compute_fibtrans_params * moo_params_get_compute_fibtrans(const moo_params *self, const cpl_parameterlist *list)
Get compute fibtrans parameters from moons parameters list.
Definition: moo_params.c:1927
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
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_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_localise(moo_params *self, cpl_parameterlist *list)
Add default parameters for localisation.
Definition: moo_params.c:1410
cpl_error_code moo_params_add_prepare(moo_params *self, cpl_parameterlist *list)
Add default parameters for prepare.
Definition: moo_params.c:667
cpl_error_code moo_params_add_model_flat(moo_params *self, cpl_parameterlist *list)
Add default parameters for model flat.
Definition: moo_params.c:1524
moo_params * moo_params_new(const char *pid, const char *recipe_id)
Create a new moo_params.
Definition: moo_params.c:62
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
cpl_error_code moo_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: moo_dfs.c:104
cpl_frameset ** moo_dfs_split_by_offset(cpl_frameset *set)
Get the EXPTIME from the frameset.
Definition: moo_dfs.c:59
moo_det * moo_compute_p2p(moo_det *flat1, moo_loc *loc1, moo_psf *model_flat1, moo_det *flat2, moo_loc *loc2, moo_psf *model_flat2)
To compute pixel-to-pixel variation map.
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_psf * moo_model_flat(moo_det *det, moo_loc *loc, moo_model_flat_params *params, const char *filename)
To extract 2D FF and model it, resulting MASTER_FLAT.
float * moo_compute_slitoffset(moo_det *det, moo_loc *loc, moo_compute_slitoffset_params *params)
Compute slit offset in LOC.
cpl_error_code moo_apply_p2p(moo_det *flat, moo_det *p2pmap)
Divide DET by the pixel-to-pixel variation map.
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_flat_shift_compute(moo_det *det, moo_loc *ff_trace)
Compute the shift between FF_TRACE and FLAT.
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_f2f * moo_compute_fibtrans(moo_ext *ext, moo_compute_fibtrans_params *params, const char *filename)
Computes fibre-to-fibre relative transmission table.
moo_loc * moo_localise(moo_det *det, const cpl_frame *guess_loc, moo_localise_params *params, const char *locname)
To localise the centroid of fibre spectrum on frames.
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_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:51
cpl_frame * moo_products_add_loc(moo_products *self, moo_loc *loc, int keep_points, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
This function creates a product from a LOC structure.
Definition: moo_products.c:229
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:285
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:188
const moo_params * moo_products_get_params(const moo_products *self)
get the moo_params object
Definition: moo_products.c:85
const char * moo_get_license(void)
Get the pipeline copyright and license.
Definition: moo_utils.c:81