31#include "moo_params.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_products.h"
47int cpl_plugin_get_info(cpl_pluginlist *list);
53static int _moons_science_starenod_create(cpl_plugin *plugin);
54static int _moons_science_starenod_exec(cpl_plugin *plugin);
55static int _moons_science_starenod_destroy(cpl_plugin *plugin);
56static int _moons_science_starenod(cpl_frameset *frameset,
57 const cpl_parameterlist *parlist);
62static const char *
const _moons_science_starenod_description =
63 "From an observation sequence in StareNod mode, this recipe removes the"
64 " instrumental signature and provides calibrated science products. During "
66 " sequence, the telescope nods from one position on targets (labeled as T "
68 "Fig. 5-12) to a blank sky position (S). In the sequence, different slit "
70 " positions can be used: as represented in Fig. 5-12, the combination is "
72 "with 1D wavelength calibrated sky subtracted spectra. Using different "
74 "offset positions implies that different sets of calibration (FF, wave "
76 "are given as inputs.\n"
78 " * science exposure frames n>=1 file(s) (RAW) with tag "
80 "science frame in stare+nod mode file\n"
81 " * sky exposure frames n file(s) (RAW) with tag "
83 "Sky Frames illuminated by blank sky only, obtained in the Stare+Nod"
84 " observation mode. The amount of exposure time (or DIT × NDIT for NIR), "
86 "well as the number of exposures, can be less than for the corresponding "
87 "OBJECT_STARENOD frames.\n"
88 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag "
90 "cosmetic bad pixel map\n"
91 " * [OPTIONAL] NonLinearityBadPixMask 1 file (QUA) with tag "
93 "cosmetic bad pixel map coming from linearity recipe\n"
94 " * MasterBias 1 file (DET) with tag "
97 " * MasterDarkNir 1 file (DET) with tag "
99 "master dark nir for object\n"
100 " * [OPTIONAL] MasterDarkNir 1 file (DET) with tag "
102 "master dark nir file for sky (if exposure time is different from object)\n"
103 " * [OPTIONAL] MasterDarkVis 1 file (DET) with tag "
105 "master dark vis file\n"
106 " * [OPTIONAL] CoeffsCube 1 or 2 file(s) one by offset (3D) with tag "
107 "LINEARITY_COEFF_CUBE : "
108 "coefficients to correct pixels detector linearity\n"
109 " * [OPTIONAL] P2pMap 1 file (DET) with tag "
111 "pixel to pixel map\n"
112 " * Fftrace 1 or 2 file(s) one by offset (LOC) with tag "
114 "the localisation table\n"
115 " * [OPTIONAL] MasterFlat 1 or 2 file(s) one by offset (PSF) with tag "
117 "the master flat used for optimal extraction\n"
118 " * Ffext 1 or 2 file(s) one by offset (EXT) with tag "
120 "the extracted flat field\n"
121 " * F2f [OPTIONAL] 1 or 2 file(s) one by offset (F2F) with tag "
123 "the fibre-to-fibre relative response\n"
124 " * SFormat 1 file (FMT) with tag "
126 "the spectral format table\n"
127 " * WaveMap 1 or 2 file(s) one by offset (WMAP) with tag "
129 "the wavelength map\n"
130 " * SkyLines 1 file (CAT) with tag "
132 "the sky lines list table\n"
133 " * [OPTIONAL] response 1 file (RESPONSE) with "
135 "the response spectra in the extracted pixel space\n"
136 " * [OPTIONAL] TellCorr 1 file (TELLURIC_CORR) "
137 "with tag TELLURIC_CORR : "
138 "the telluric correction spectra\n"
139 " * [OPTIONAL] atmosExt 1 file (ATMO) with tag "
141 "the atmospheric extinction table\n"
143 " * STARENOD_RBNSPECTRA_OFFSET[offset]_[insmode]_i.fits (RBN) with tag "
144 "STARENOD_RBNSPECTRA : "
145 "Science product individual calibrated frames\n"
146 " * STARENOD_RBNFLXSPECTRA_OFFSET[offset]_[insmode]_i.fits (RBN) with tag "
147 "STARENOD_RBNFLXSPECTRA : "
148 "Science product individual flux calibrated frames\n"
149 " * STARENOD_SKSSPECTRA_OFFSET[offset]_[insmode]_i.fits (SCI) with tag "
150 "STARENOD_SKSSPECTRA : "
151 "Science product individual sky subtracted frames\n"
152 " * STARENOD_SKSSPECTRA_[insmode].fits (SCI) with tag "
153 "STARENOD_SKSSPECTRA : "
154 "Science product coadd calibrated frame\n"
174cpl_plugin_get_info(cpl_pluginlist *list)
176 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
177 cpl_plugin *plugin = &recipe->interface;
178 if (cpl_plugin_init(plugin, CPL_PLUGIN_API, MOONS_BINARY_VERSION,
179 CPL_PLUGIN_TYPE_RECIPE,
"moons_science_starenod",
180 "Reduces science exposure in stare and stare+nod modes",
181 _moons_science_starenod_description,
"Regis Haigron",
183 _moons_science_starenod_create,
184 _moons_science_starenod_exec,
185 _moons_science_starenod_destroy)) {
186 cpl_msg_error(cpl_func,
"Plugin initialization failed");
187 (void)cpl_error_set_where(cpl_func);
190 if (cpl_pluginlist_append(list, plugin)) {
191 cpl_msg_error(cpl_func,
"Error adding plugin to list");
192 (void)cpl_error_set_where(cpl_func);
210_moons_science_starenod_create(cpl_plugin *plugin)
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();
219 if (plugin == NULL) {
220 cpl_msg_error(cpl_func,
"Null plugin");
221 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
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);
229 recipe = (cpl_recipe *)plugin;
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);
236 moo_params *params =
moo_params_new(
"moons",
"moons_science_starenod");
241 MOO_CORRECT_BIAS_METHOD_MASTER);
264_moons_science_starenod_exec(cpl_plugin *plugin)
268 cpl_errorstate initial_errorstate = cpl_errorstate_get();
270 if (cpl_error_get_code() != CPL_ERROR_NONE) {
271 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
272 cpl_func, __LINE__, cpl_error_get_where());
273 return (
int)cpl_error_get_code();
275 if (plugin == NULL) {
276 cpl_msg_error(cpl_func,
"Null plugin");
277 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
280 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
281 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
282 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
285 recipe = (cpl_recipe *)plugin;
287 if (recipe->parameters == NULL) {
288 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
289 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
291 if (recipe->frames == NULL) {
292 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
293 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
296 recipe_status = _moons_science_starenod(recipe->frames, recipe->parameters);
298 if (cpl_dfs_update_product_header(recipe->frames)) {
300 recipe_status = (int)cpl_error_get_code();
302 if (!cpl_errorstate_is_equal(initial_errorstate)) {
305 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
307 return recipe_status;
320_moons_science_starenod_destroy(cpl_plugin *plugin)
323 if (plugin == NULL) {
324 cpl_msg_error(cpl_func,
"Null plugin");
325 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
328 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
329 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
330 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
333 recipe = (cpl_recipe *)plugin;
334 cpl_parameterlist_delete(recipe->parameters);
339_moons_science_starenod_check_sof(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)
358 cpl_error_get_code());
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));
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));
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));
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);
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);
392 else if (!strcmp(cpl_frame_get_tag(current_frame),
393 MOONS_TAG_MASTER_BIAS)) {
394 *masterbias = current_frame;
396 else if (!strcmp(cpl_frame_get_tag(current_frame),
397 MOONS_TAG_MASTER_DARK_VIS)) {
398 *masterdark_vis = current_frame;
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));
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));
410 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_P2P_MAP)) {
411 *p2pmap = current_frame;
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));
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));
423 else if (!strcmp(cpl_frame_get_tag(current_frame),
424 MOONS_TAG_SPECTRAL_FORMAT)) {
425 *sformat = current_frame;
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));
431 else if (!strcmp(cpl_frame_get_tag(current_frame),
432 MOONS_TAG_SKY_LINE_LIST)) {
433 *sky_lines = current_frame;
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));
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));
445 else if (!strcmp(cpl_frame_get_tag(current_frame),
446 MOONS_TAG_ATMOS_EXT)) {
447 *atmo = current_frame;
449 else if (!strcmp(cpl_frame_get_tag(current_frame),
450 MOONS_TAG_RESPONSE)) {
451 *resp = current_frame;
453 else if (!strcmp(cpl_frame_get_tag(current_frame),
454 MOONS_TAG_TELLURIC_CORR)) {
455 *tell = current_frame;
457 else if (!strcmp(cpl_frame_get_tag(current_frame),
458 MOONS_TAG_AIRGLOW_GROUP)) {
459 *airglow_group = current_frame;
461 else if (!strcmp(cpl_frame_get_tag(current_frame),
462 MOONS_TAG_AIRGLOW_VAR)) {
463 *airglow_var = current_frame;
465 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_SOLFLUX)) {
466 *solflux = current_frame;
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");
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");
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 "
482 MOONS_TAG_SKY_STARENOD);
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 "
488 MOONS_TAG_SPECTRAL_FORMAT);
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 "
494 MOONS_TAG_SKY_LINE_LIST);
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 "
501 MOONS_TAG_AIRGLOW_GROUP);
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 "
508 MOONS_TAG_AIRGLOW_VAR);
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 "
517 return CPL_ERROR_NONE;
521_moons_science_starenod_check_sof_byoffset(cpl_frameset *frameset,
522 cpl_frameset *object_frameset,
523 cpl_frameset *sky_frameset,
524 const cpl_frame **master_flat,
525 const cpl_frame **fftrace,
526 const cpl_frame **coeffs_cube,
527 const cpl_frame **wmap,
528 const cpl_frame **flat,
529 const cpl_frame **f2f,
530 moo_extract_params *ext_params,
531 moo_sub_sky_stare_params *sky_params,
535 cpl_error_get_code());
540 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
541 cpl_frame *current_frame = cpl_frameset_get_position(frameset, i);
542 if (!strcmp(cpl_frame_get_tag(current_frame),
543 MOONS_TAG_OBJECT_STARENOD)) {
544 cpl_frameset_insert(object_frameset,
545 cpl_frame_duplicate(current_frame));
548 else if (!strcmp(cpl_frame_get_tag(current_frame),
549 MOONS_TAG_OBJECT_STARE)) {
550 cpl_frameset_insert(object_frameset,
551 cpl_frame_duplicate(current_frame));
555 else if (!strcmp(cpl_frame_get_tag(current_frame),
556 MOONS_TAG_SKY_STARENOD)) {
557 cpl_frameset_insert(sky_frameset,
558 cpl_frame_duplicate(current_frame));
561 else if (!strcmp(cpl_frame_get_tag(current_frame),
562 MOONS_TAG_MASTER_FLAT)) {
563 *master_flat = current_frame;
565 else if (!strcmp(cpl_frame_get_tag(current_frame),
566 MOONS_TAG_FF_TRACE)) {
567 *fftrace = current_frame;
569 else if (!strcmp(cpl_frame_get_tag(current_frame),
570 MOONS_TAG_LINEARITY_COEFF_CUBE)) {
571 *coeffs_cube = current_frame;
573 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_WAVEMAP)) {
574 *wmap = current_frame;
576 else if (!strcmp(cpl_frame_get_tag(current_frame),
577 MOONS_TAG_FF_EXTSPECTRA)) {
578 *flat = current_frame;
580 else if (!strcmp(cpl_frame_get_tag(current_frame),
581 MOONS_TAG_F2F_TABLE)) {
582 *f2f = current_frame;
586 if (nb_object <= 0) {
587 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
588 "SOF does not have any file tagged "
590 MOONS_TAG_OBJECT_STARENOD);
594 *mode = MOO_MODE_STARE;
595 cpl_msg_info(
"test",
"Recipe running in STARE mode");
598 *mode = MOO_MODE_STARENOD;
599 cpl_msg_info(
"test",
"Recipe running in STARENOD mode");
602 if (*mode == MOO_MODE_STARENOD) {
604 return (
int)cpl_error_set_message(
605 cpl_func, CPL_ERROR_DATA_NOT_FOUND,
606 "SOF (filter by offset) does not have any file tagged "
608 MOONS_TAG_SKY_STARENOD);
610 if (strcmp(sky_params->method, MOO_SUB_SKY_STARE_METHOD_NONE) == 0) {
611 return (
int)cpl_error_set_message(
612 cpl_func, CPL_ERROR_DATA_NOT_FOUND,
613 "sky subtraction NONE method not allowed in STARENOD");
617 if (*fftrace == NULL) {
618 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
619 "SOF does not have any file tagged "
624 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
625 "SOF does not have any file tagged "
630 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
631 "SOF does not have any file tagged "
633 MOONS_TAG_FF_EXTSPECTRA);
635 if (*master_flat == NULL &&
636 strcmp(ext_params->method, MOO_EXTRACT_METHOD_OPTIMAL) == 0) {
637 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
638 "SOF does not have any file tagged "
640 MOONS_TAG_MASTER_FLAT);
643 return CPL_ERROR_NONE;
648_moons_p2pmap(moo_det *arc,
const cpl_frame *p2pmap)
650 cpl_error_code status = CPL_ERROR_NONE;
652 if (p2pmap != NULL) {
662_moons_apply_flat(moo_ext *ext,
663 const cpl_frame *flat_frame,
664 const cpl_frame *f2f_frame)
666 cpl_error_code status = CPL_ERROR_NONE;
667 moo_ext *flat = NULL;
670 if (f2f_frame != NULL) {
681_moons_combine_pair(moo_rbn *rbn,
685 const cpl_frame *f2f_frame,
686 const cpl_frame *solflux_frame,
687 const cpl_frame *airglow_group_frame,
688 const cpl_frame *airglow_var_frame,
689 moo_combine_pair_params *combine_pair_params,
690 moo_sub_sky_stare_params *sky_params,
691 const char *sci_filename,
692 moo_products *products,
693 const cpl_frame *ref_frame)
695 moo_sci *result = NULL;
697 if (f2f_frame != NULL) {
700 moo_try_check(result =
702 solflux_frame, airglow_group_frame,
703 airglow_var_frame, combine_pair_params,
704 sky_params, sci_filename, products,
714_moons_starenod_rebin(
int inum,
718 const cpl_frame *ref_frame,
719 moo_spectral_format *sformat,
720 moo_sky_lines_list *sky_lines,
722 const cpl_frame *atmo_frame,
723 const cpl_frame *resp_frame,
724 const cpl_frame *tell_frame,
725 moo_rebin_params *rbn_params,
726 moo_products *products,
729 cpl_frame *rbn_frame = NULL;
731 moo_resp *resp = NULL;
732 moo_telluric *telluric = NULL;
735 char *rbn_filename = NULL;
736 char *calibflux_filename = NULL;
737 char *tellcorr_filename = NULL;
739 cpl_ensure(ext != NULL, CPL_ERROR_NULL_INPUT, NULL);
740 cpl_ensure(ref_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
742 rbn_filename = cpl_sprintf(
"%s_RBNSPECTRA_OFFSET%d_%s_%d.fits", prefix,
744 moo_try_check(rbn =
moo_rebin(ext, wmap, sformat, rbn_params, rbn_filename),
751 MOONS_TAG_SCIENCE_STARENOD_RBNSPECTRA,
752 rbn_filename, ref_frame),
755 if (atmo_frame != NULL && resp_frame != NULL) {
759 calibflux_filename = cpl_sprintf(
"%s_RBNFLXSPECTRA_OFFSET%d_%s_%d.fits",
760 prefix, offset, mode, inum);
763 products, rbn, CPL_FRAME_LEVEL_FINAL,
764 MOONS_TAG_SCIENCE_STARENOD_RBNFLXSPECTRA,
765 calibflux_filename, ref_frame),
769 cpl_msg_info(__func__,
"No flux calibration");
772 if (tell_frame != NULL) {
776 cpl_sprintf(
"%s_RBNTELLCORRSPECTRA_OFFSET%d_%s_%d.fits", prefix,
780 products, rbn, CPL_FRAME_LEVEL_FINAL,
781 MOONS_TAG_SCIENCE_STARENOD_RBNTELLCORRSPECTRA,
782 tellcorr_filename, ref_frame),
786 cpl_msg_info(__func__,
"No telluric correction");
790 cpl_free(tellcorr_filename);
791 cpl_free(calibflux_filename);
792 cpl_free(rbn_filename);
801_moons_sub_sky_stare(moo_rbn *rbn,
803 const cpl_frame *f2f_frame,
804 const cpl_frame *solflux_frame,
805 const cpl_frame *airglow_group_frame,
806 const cpl_frame *airglow_var_frame,
807 moo_sub_sky_stare_params *sky_params,
808 const char *sci_filename)
810 moo_sci *result = NULL;
813 if (f2f_frame != NULL) {
816 moo_try_check(result =
818 solflux_frame, airglow_group_frame,
819 airglow_var_frame, sky_params,
820 sci_filename, MOO_SCI1D_NOT_PAIRED),
829_moons_stare_sci(
int inum,
832 const cpl_frame *ref_frame,
833 const cpl_frame *rbn_frame,
834 moo_sky_lines_list *sky_lines,
835 const cpl_frame *f2f_frame,
836 const cpl_frame *airglow_group_frame,
837 const cpl_frame *airglow_var_frame,
838 const cpl_frame *solflux_frame,
839 moo_target_table_params *target_table_params,
840 moo_sub_sky_stare_params *sky_params,
841 moo_products *products,
844 cpl_frame *sci_frame = NULL;
849 char *ttable_filename = NULL;
850 char *sci_filename = NULL;
852 cpl_ensure(rbn_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
853 cpl_ensure(ref_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
856 moo_try_check(target_table =
858 target_table_params),
860 ttable_filename = cpl_sprintf(
"%s_TARGET_TABLE_OFFSET%d_%s_%d.fits", prefix,
863 products, target_table, CPL_FRAME_LEVEL_INTERMEDIATE,
864 MOONS_TAG_SCIENCE_STARENOD_TARGET_TABLE, ttable_filename,
869 cpl_sprintf(
"%s_SCI_OFFSET%d_%s_%d.fits", prefix, offset, mode, inum);
871 moo_try_check(sci = _moons_sub_sky_stare(rbn, target_table, f2f_frame,
872 solflux_frame, airglow_group_frame,
873 airglow_var_frame, sky_params,
880 MOONS_TAG_SCIENCE_STARENOD_SKSSPECTRA,
881 sci_filename, ref_frame),
885 cpl_free(ttable_filename);
886 cpl_free(sci_filename);
894_moons_starenod_sci(
int inum,
897 const cpl_frame *obj_frame,
898 const cpl_frame *obj_rbn_frame,
899 const cpl_frame *sky_rbn_frame,
900 const cpl_frame *nod_rbn_frame,
901 moo_sky_lines_list *sky_lines,
902 const cpl_frame *f2f_frame,
903 const cpl_frame *airglow_group_frame,
904 const cpl_frame *airglow_var_frame,
905 const cpl_frame *solflux_frame,
906 moo_target_table_params *target_table_params,
907 moo_combine_pair_params *combine_pair_params,
908 moo_sub_sky_stare_params *sky_params,
909 moo_products *products,
912 cpl_frame *sci_frame = NULL;
913 moo_rbn *nod_rbn = NULL;
914 moo_rbn *sky_rbn = NULL;
915 moo_rbn *obj_rbn = NULL;
919 char *ttable_filename = NULL;
920 char *sci_filename = NULL;
922 cpl_ensure(nod_rbn_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
923 cpl_ensure(obj_rbn_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
924 cpl_ensure(sky_rbn_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
932 target_table_params),
934 ttable_filename = cpl_sprintf(
"%s_TARGET_TABLE_OFFSET%d_%s_%d.fits", prefix,
937 products, target_table, CPL_FRAME_LEVEL_INTERMEDIATE,
938 MOONS_TAG_SCIENCE_STARENOD_TARGET_TABLE, ttable_filename,
943 cpl_sprintf(
"%s_SCI_OFFSET%d_%s_%d.fits", prefix, offset, mode, inum);
944 moo_try_check(sci = _moons_combine_pair(nod_rbn, sky_rbn, obj_rbn,
945 target_table, f2f_frame,
946 solflux_frame, airglow_group_frame,
948 combine_pair_params, sky_params,
949 sci_filename, products, obj_frame),
956 MOONS_TAG_SCIENCE_STARENOD_SKSSPECTRA,
957 sci_filename, obj_frame),
961 cpl_free(ttable_filename);
962 cpl_free(sci_filename);
972static const cpl_frame *
973find_masterdark_nir(moo_det *det, cpl_frameset *set)
975 const cpl_frame *result = NULL;
978 double exptime = 0.0;
982 moo_det *current_det = NULL;
984 cpl_ensure(det != NULL, CPL_ERROR_NULL_INPUT, NULL);
986 for (num = 1; num <= 2; num++) {
987 for (type = 1; type <= 2; type++) {
989 if (single != NULL) {
992 exptime = dit * ndit;
1002 if (find && set != NULL) {
1003 int size = cpl_frameset_get_size(set);
1004 for (
int i = 0; i < size; i++) {
1005 const cpl_frame *current = cpl_frameset_get_position_const(set, i);
1007 moo_single *current_single =
1012 double current_exptime = dit * ndit;
1013 if (fabs(exptime - current_exptime) <= 1E-9) {
1027_moons_starenod_subtractnod(
int inum,
1030 const cpl_frame *obj_frame,
1031 const cpl_frame *obj_det_frame,
1032 const cpl_frame *sky_det_frame,
1033 moo_products *products)
1035 cpl_frame *result = NULL;
1036 char *nod_det_filename = NULL;
1037 moo_det *nod_det = NULL;
1042 moo_try_check(
moo_det_load(obj_det, badpix_level),
" ");
1043 moo_try_check(
moo_det_load(sky_det, badpix_level),
" ");
1046 cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits", MOONS_TAG_STARENOD_SUBTRACTNOD,
1047 offset, mode, inum);
1049 moo_try_check(nod_det =
1053 CPL_FRAME_LEVEL_INTERMEDIATE,
1054 MOONS_TAG_STARENOD_SUBTRACTNOD,
1055 nod_det_filename, obj_frame),
1059 cpl_free(nod_det_filename);
1068_moons_starenod_prepare(
int inum,
1071 const cpl_frame *frame,
1072 const char *bpmap_rp_name,
1073 const char *bpmap_nl_name,
1074 const cpl_frame *masterbias,
1075 const cpl_frame *masterdark_vis,
1076 cpl_frameset *masterdark_nir_frameset,
1077 const cpl_frame *p2pmap,
1078 const cpl_frame *coeffs_cube,
1079 moo_prepare_params *prepare_params,
1080 moo_correct_bias_params *cbias_params,
1081 moo_products *products,
1084 cpl_frame *result = NULL;
1085 const cpl_frame *masterdark_nir = NULL;
1086 moo_det *det = NULL;
1087 char *det_filename = NULL;
1088 char *det_p2p_filename = NULL;
1089 const char *det_tags[] = { MOONS_TAG_STARENOD_OBJ_CORRECTDARK,
1090 MOONS_TAG_STARENOD_SKY_CORRECTDARK };
1091 const char *detp2p_tags[] = { MOONS_TAG_STARENOD_OBJ_APPLYP2P,
1092 MOONS_TAG_STARENOD_SKY_APPLYP2P };
1095 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
1097 moo_try_check(det =
moo_prepare(frame, bpmap_rp_name, bpmap_nl_name,
1098 masterbias, coeffs_cube, prepare_params),
1102 masterdark_nir = find_masterdark_nir(det, masterdark_nir_frameset);
1106 det_filename = cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits", det_tags[objtype],
1107 offset, mode, inum);
1108 moo_try_check(
moo_products_add(products, det, CPL_FRAME_LEVEL_INTERMEDIATE,
1109 det_tags[objtype], det_filename, frame),
1111 moo_try_check(_moons_p2pmap(det, p2pmap),
" ");
1112 det_p2p_filename = cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits",
1113 detp2p_tags[objtype], offset, mode, inum);
1115 CPL_FRAME_LEVEL_INTERMEDIATE,
1116 detp2p_tags[objtype],
1117 det_p2p_filename, frame),
1121 cpl_free(det_filename);
1122 cpl_free(det_p2p_filename);
1128_moons_starenod_extract(
int inum,
1131 const cpl_frame *ref_frame,
1132 const cpl_frame *det_frame,
1135 moo_spectral_format *sformat,
1136 moo_sky_lines_list *skylines,
1137 const cpl_frame *masterflat_frame,
1138 const cpl_frame *flat_frame,
1139 const cpl_frame *f2f_frame,
1140 moo_extract_params *extract_params,
1141 moo_products *products,
1144 cpl_frame *ext_frame = NULL;
1145 moo_det *det = NULL;
1146 moo_psf *psf = NULL;
1147 moo_ext *ext = NULL;
1149 char *ext_filename = NULL;
1150 char *extff_filename = NULL;
1152 cpl_ensure(det_frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
1154 ext_filename = cpl_sprintf(
"%s_EXTSPECTRA_OFFSET%d_%s_%d.fits", prefix,
1155 offset, mode, inum);
1156 if (masterflat_frame != NULL) {
1160 moo_extract(det, loc, psf, extract_params, ext_filename),
1163 products, ext, CPL_FRAME_LEVEL_INTERMEDIATE,
1164 MOONS_TAG_SCIENCE_STARENOD_EXTSPECTRA, ext_filename,
1167 moo_try_check(_moons_apply_flat(ext, flat_frame, f2f_frame),
" ");
1170 extff_filename = cpl_sprintf(
"%s_EXTFFSPECTRA_OFFSET%d_%s_%d.fits", prefix,
1171 offset, mode, inum);
1174 products, ext, CPL_FRAME_LEVEL_INTERMEDIATE,
1175 MOONS_TAG_SCIENCE_STARENOD_EXTSPECTRA, extff_filename,
1180 cpl_free(ext_filename);
1181 cpl_free(extff_filename);
1189_moons_sort_mjdobs(
const cpl_frame *a,
const cpl_frame *b)
1193 const char *filenameA = cpl_frame_get_filename(a);
1194 const char *filenameB = cpl_frame_get_filename(b);
1196 cpl_propertylist *lista = cpl_propertylist_load(filenameA, 0);
1197 cpl_propertylist *listb = cpl_propertylist_load(filenameB, 0);
1199 if (cpl_propertylist_has(lista, MOO_PFITS_MJDOBS) &&
1200 cpl_propertylist_has(listb, MOO_PFITS_MJDOBS)) {
1206 else if (mjdA > mjdB) {
1213 cpl_propertylist_delete(listb);
1214 cpl_propertylist_delete(lista);
1219_moons_compare_offset(
const cpl_frame *a,
const cpl_frame *b)
1223 cpl_propertylist *lista = NULL;
1224 cpl_propertylist *listb = NULL;
1225 const char *filenameA = cpl_frame_get_filename(a);
1226 lista = cpl_propertylist_load(filenameA, 0);
1230 const char *filenameB = cpl_frame_get_filename(b);
1231 listb = cpl_propertylist_load(filenameB, 0);
1235 if (fabs(oA - oB) < 1E-12) {
1239 cpl_propertylist_delete(lista);
1240 cpl_propertylist_delete(listb);
1245_starenod_getsky_index(
const cpl_frame *obj_frame,
1246 const cpl_frameset *sky_frameset)
1250 cpl_ensure(obj_frame != NULL, CPL_ERROR_NULL_INPUT, 0);
1251 cpl_ensure(sky_frameset != NULL, CPL_ERROR_NULL_INPUT, 0);
1253 const char *obj_filename = cpl_frame_get_filename(obj_frame);
1254 cpl_propertylist *obj_list = cpl_propertylist_load(obj_filename, 0);
1257 int size = cpl_frameset_get_size(sky_frameset);
1258 for (
int i = 0; i < size; i++) {
1259 const cpl_frame *sky_frame =
1260 cpl_frameset_get_position_const(sky_frameset, i);
1261 const char *sky_filename = cpl_frame_get_filename(sky_frame);
1262 cpl_propertylist *sky_list = cpl_propertylist_load(sky_filename, 0);
1264 double diff = fabs(sky_mjd - obj_mjd);
1268 else if (odiff > diff) {
1272 cpl_propertylist_delete(sky_list);
1274 cpl_propertylist_delete(obj_list);
1279_moons_science_starenod_byoffset(cpl_frameset *frameset,
1280 cpl_frameset *sci_frameset,
1281 cpl_frameset *ref_frameset,
1282 const char *bpmap_rp_name,
1283 const char *bpmap_nl_name,
1284 const cpl_frame *masterbias,
1285 const cpl_frame *masterdark_vis,
1286 cpl_frameset *masterdark_nir,
1287 const cpl_frame *p2pmap,
1288 const cpl_frame *sformat_frame,
1289 moo_sky_lines_list *sky_lines,
1290 const cpl_frame *airglow_group_frame,
1291 const cpl_frame *solflux_frame,
1292 const cpl_frame *airglow_var_frame,
1293 const cpl_frame *atmo_frame,
1294 const cpl_frame *resp_frame,
1295 const cpl_frame *tell_frame,
1296 moo_prepare_params *prepare_params,
1297 moo_correct_bias_params *correct_bias_params,
1298 moo_extract_params *extract_params,
1299 moo_wavesol_params *wavesol_params,
1300 moo_rebin_params *rbn_params,
1301 moo_target_table_params *target_table_params,
1302 moo_combine_pair_params *combine_pair_params,
1303 moo_sub_sky_stare_params *sky_params,
1304 moo_products *products)
1307 int *skyindex = NULL;
1308 moo_loc *loc = NULL;
1309 moo_spectral_format *sformat = NULL;
1310 moo_map *wmap = NULL;
1311 moo_map *wmap_tuned = NULL;
1312 moo_extlist *obj_extlist = NULL;
1313 moo_extlist *sky_extlist = NULL;
1314 moo_extlist *nod_extlist = NULL;
1315 moo_extlist *wavemap_extlist = NULL;
1316 moo_ext *sum_ext = NULL;
1317 cpl_frameset *obj_frameset = NULL;
1318 cpl_frameset *sky_frameset = NULL;
1319 cpl_frameset *sky_det_frameset = NULL;
1320 cpl_frameset *obj_det_frameset = NULL;
1321 cpl_frameset *nod_det_frameset = NULL;
1323 cpl_frameset *nod_ext_frameset = NULL;
1324 cpl_frameset *sky_ext_frameset = NULL;
1325 cpl_frameset *obj_ext_frameset = NULL;
1327 cpl_frameset *obj_rbn_frameset = NULL;
1328 cpl_frameset *sky_rbn_frameset = NULL;
1329 cpl_frameset *nod_rbn_frameset = NULL;
1331 const cpl_frame *master_flat = NULL;
1332 const cpl_frame *fftrace = NULL;
1333 const cpl_frame *coeffs_cube = NULL;
1334 const cpl_frame *wmap_frame = NULL;
1335 const cpl_frame *flat_frame = NULL;
1336 const cpl_frame *f2f_frame = NULL;
1337 char *sum_ext_filename = NULL;
1338 const char *ref_filename = NULL;
1339 cpl_propertylist *ref_header = NULL;
1341 const char *mode_name = NULL;
1343 int wavemap_extlist_size = 0;
1345 char *wmap_tuned_filename = NULL;
1348 cpl_errorstate prestate = cpl_errorstate_get();
1349 obj_frameset = cpl_frameset_new();
1350 sky_frameset = cpl_frameset_new();
1352 sky_det_frameset = cpl_frameset_new();
1353 obj_det_frameset = cpl_frameset_new();
1354 nod_det_frameset = cpl_frameset_new();
1356 nod_ext_frameset = cpl_frameset_new();
1357 sky_ext_frameset = cpl_frameset_new();
1358 obj_ext_frameset = cpl_frameset_new();
1360 obj_rbn_frameset = cpl_frameset_new();
1361 sky_rbn_frameset = cpl_frameset_new();
1362 nod_rbn_frameset = cpl_frameset_new();
1364 moo_try_check(_moons_science_starenod_check_sof_byoffset(
1365 frameset, obj_frameset, sky_frameset, &master_flat,
1366 &fftrace, &coeffs_cube, &wmap_frame, &flat_frame,
1367 &f2f_frame, extract_params, sky_params, &target_mode),
1369 cpl_frameset_join(ref_frameset, obj_frameset);
1370 int nb_sky = cpl_frameset_get_size(sky_frameset);
1371 int nb_obj = cpl_frameset_get_size(obj_frameset);
1373 cpl_frame *frame = cpl_frameset_get_position(obj_frameset, 0);
1374 ref_filename = cpl_frame_get_filename(frame);
1377 moo_try_check(ref_header = cpl_propertylist_load(ref_filename, 0),
" ");
1379 cpl_propertylist_delete(ref_header);
1381 cpl_msg_info(__func__,
"Do offset %d Use mode %s", offset, mode_name);
1383 for (
int i = 0; i < nb_sky; i++) {
1384 cpl_msg_info(__func__,
"---Prepare sky: %d/%d", i + 1, nb_sky);
1385 cpl_frame *sky_frame = NULL;
1386 moo_try_check(sky_frame = cpl_frameset_get_position(sky_frameset, i),
1389 _moons_starenod_prepare(i, mode_name, offset, sky_frame,
1390 bpmap_rp_name, bpmap_nl_name, masterbias,
1391 masterdark_vis, masterdark_nir, p2pmap,
1392 coeffs_cube, prepare_params,
1393 correct_bias_params, products, 1);
1394 cpl_frameset_insert(sky_det_frameset, cpl_frame_duplicate(result));
1397 for (
int i = 0; i < nb_obj; i++) {
1398 cpl_msg_info(__func__,
"---Prepare objects: %d/%d", i + 1, nb_obj);
1399 cpl_frame *obj_frame = NULL;
1400 moo_try_check(obj_frame = cpl_frameset_get_position(obj_frameset, i),
1403 _moons_starenod_prepare(i, mode_name, offset, obj_frame,
1404 bpmap_rp_name, bpmap_nl_name, masterbias,
1405 masterdark_vis, masterdark_nir, p2pmap,
1406 coeffs_cube, prepare_params,
1407 correct_bias_params, products, 0);
1408 cpl_frameset_insert(obj_det_frameset, cpl_frame_duplicate(result));
1412 skyindex = cpl_calloc(nb_obj,
sizeof(
int));
1413 for (
int i = 0; i < nb_obj; i++) {
1414 cpl_frame *obj_frame = NULL;
1415 cpl_frame *obj_det_frame = NULL;
1416 cpl_frame *sky_det_frame = NULL;
1417 moo_try_check(obj_frame =
1418 cpl_frameset_get_position(obj_frameset, i),
1420 skyindex[i] = _starenod_getsky_index(obj_frame, sky_frameset);
1421 moo_try_check(obj_det_frame =
1422 cpl_frameset_get_position(obj_det_frameset, i),
1424 moo_try_check(sky_det_frame =
1425 cpl_frameset_get_position(sky_det_frameset,
1428 cpl_msg_info(__func__,
1429 "---Prepare nod %d/%d using object:%s sky: %s", i + 1,
1430 nb_obj, cpl_frame_get_filename(obj_det_frame),
1431 cpl_frame_get_filename(sky_det_frame));
1433 _moons_starenod_subtractnod(i, mode_name, offset, obj_frame,
1434 obj_det_frame, sky_det_frame,
1436 cpl_frameset_insert(nod_det_frameset, cpl_frame_duplicate(result));
1439 int nb_nod = cpl_frameset_get_size(nod_det_frameset);
1440 moo_try_check(wmap = moo_map_load(wmap_frame),
" ");
1444 for (
int i = 0; i < nb_sky; i++) {
1445 cpl_frame *sky_frame = NULL;
1446 cpl_frame *sky_det_frame = NULL;
1447 cpl_msg_info(__func__,
"---Extract sky: %d/%d", i + 1, nb_sky);
1448 moo_try_check(sky_frame = cpl_frameset_get_position(sky_frameset, i),
1450 moo_try_check(sky_det_frame =
1451 cpl_frameset_get_position(sky_det_frameset, i),
1454 _moons_starenod_extract(i, mode_name, offset, sky_frame,
1455 sky_det_frame, loc, wmap, sformat,
1456 sky_lines, master_flat, flat_frame,
1457 f2f_frame, extract_params, products,
1459 cpl_frameset_insert(sky_ext_frameset, cpl_frame_duplicate(result));
1462 for (
int i = 0; i < nb_obj; i++) {
1463 cpl_frame *obj_frame = NULL;
1464 cpl_frame *obj_det_frame = NULL;
1465 cpl_msg_info(__func__,
"---Extract objects: %d/%d", i + 1, nb_obj);
1466 moo_try_check(obj_frame = cpl_frameset_get_position(obj_frameset, i),
1468 moo_try_check(obj_det_frame =
1469 cpl_frameset_get_position(obj_det_frameset, i),
1472 _moons_starenod_extract(i, mode_name, offset, obj_frame,
1473 obj_det_frame, loc, wmap, sformat,
1474 sky_lines, master_flat, flat_frame,
1475 f2f_frame, extract_params, products,
1477 cpl_frameset_insert(obj_ext_frameset, cpl_frame_duplicate(result));
1480 for (
int i = 0; i < nb_nod; i++) {
1481 cpl_frame *obj_frame = NULL;
1482 cpl_frame *nod_det_frame = NULL;
1483 cpl_msg_info(__func__,
"---Extract nod: %d/%d", i + 1, nb_nod);
1484 moo_try_check(obj_frame = cpl_frameset_get_position(obj_frameset, i),
1486 moo_try_check(nod_det_frame =
1487 cpl_frameset_get_position(nod_det_frameset, i),
1490 _moons_starenod_extract(i, mode_name, offset, obj_frame,
1491 nod_det_frame, loc, wmap, sformat,
1492 sky_lines, master_flat, flat_frame,
1493 f2f_frame, extract_params, products,
1495 cpl_frameset_insert(nod_ext_frameset, cpl_frame_duplicate(result));
1503 for (
int i = 0; i < nb_obj; i++) {
1506 wavemap_extlist_size++;
1508 for (
int i = 0; i < nb_sky; i++) {
1511 wavemap_extlist_size++;
1515 cpl_sprintf(
"STARENOD_EXT_SUM_OFFSET%d_%s.fits", offset, mode_name);
1517 cpl_frame *ref_frame = cpl_frameset_get_position(obj_frameset, 0);
1519 CPL_FRAME_LEVEL_TEMPORARY,
1520 MOONS_TAG_SCIENCE_STARENOD_EXTSPECTRA,
1521 sum_ext_filename, ref_frame),
1523 moo_map *used_wmap = NULL;
1524 const char *wavesol_control = wavesol_params->control;
1525 if ((strcmp(wavesol_control, MOO_WAVESOL_CONTROL_CHECK) == 0) ||
1526 (strcmp(wavesol_control, MOO_WAVESOL_CONTROL_UPDATE) == 0)) {
1527 const char *sky_lines_name = sky_lines->filename;
1528 moo_try_check(wmap_tuned =
moo_wavesol(sum_ext, sky_lines_name, sformat,
1529 loc, wmap, wavesol_params),
1531 if (strcmp(wavesol_control, MOO_WAVESOL_CONTROL_UPDATE) == 0) {
1532 used_wmap = wmap_tuned;
1533 wmap_tuned_filename =
1534 cpl_sprintf(
"STARENOD_WMAP_TUNED_OFFSET%d_%s.fits", offset,
1543 for (
int i = 0; i < nb_obj; i++) {
1544 cpl_frame *obj_frame = NULL;
1546 cpl_msg_info(__func__,
"---Rebin objects: %d/%d", i + 1, nb_obj);
1548 moo_try_check(obj_frame = cpl_frameset_get_position(obj_frameset, i),
1551 _moons_starenod_rebin(i, mode_name, offset, obj_ext, obj_frame,
1552 sformat, sky_lines, used_wmap, atmo_frame,
1553 resp_frame, tell_frame, rbn_params, products,
1556 cpl_frameset_insert(obj_rbn_frameset, cpl_frame_duplicate(result));
1559 for (
int i = 0; i < nb_sky; i++) {
1560 cpl_frame *sky_frame = NULL;
1562 cpl_msg_info(__func__,
"---Rebin sky: %d/%d", i + 1, nb_sky);
1563 moo_try_check(sky_frame = cpl_frameset_get_position(sky_frameset, i),
1566 _moons_starenod_rebin(i, mode_name, offset, sky_ext, sky_frame,
1567 sformat, sky_lines, used_wmap, atmo_frame,
1568 resp_frame, tell_frame, rbn_params, products,
1570 cpl_frameset_insert(sky_rbn_frameset, cpl_frame_duplicate(result));
1573 for (
int i = 0; i < nb_nod; i++) {
1574 cpl_frame *nod_frame = NULL;
1576 cpl_msg_info(__func__,
"---Rebin nod: %d/%d", i + 1, nb_nod);
1577 moo_try_check(nod_frame = cpl_frameset_get_position(obj_frameset, i),
1580 _moons_starenod_rebin(i, mode_name, offset, nod_ext, nod_frame,
1581 sformat, sky_lines, used_wmap, atmo_frame,
1582 resp_frame, tell_frame, rbn_params, products,
1584 cpl_frameset_insert(nod_rbn_frameset, cpl_frame_duplicate(result));
1588 for (
int i = 0; i < nb_obj; i++) {
1589 cpl_frame *obj_frame = NULL;
1590 cpl_frame *obj_rbn_frame = NULL;
1591 cpl_msg_info(__func__,
"---Create sci: %d/%d", i + 1, nb_obj);
1592 moo_try_check(obj_frame =
1593 cpl_frameset_get_position(obj_frameset, i),
1595 moo_try_check(obj_rbn_frame =
1596 cpl_frameset_get_position(obj_rbn_frameset, i),
1599 _moons_stare_sci(i, mode_name, offset, obj_frame, obj_rbn_frame,
1600 sky_lines, f2f_frame, airglow_group_frame,
1601 airglow_var_frame, solflux_frame,
1602 target_table_params, sky_params, products,
1604 cpl_frameset_insert(sci_frameset, cpl_frame_duplicate(result));
1608 for (
int i = 0; i < nb_nod; i++) {
1609 cpl_frame *obj_frame = NULL;
1610 cpl_frame *obj_rbn_frame = NULL;
1611 cpl_frame *sky_rbn_frame = NULL;
1612 cpl_frame *nod_rbn_frame = NULL;
1613 cpl_frame *sci_frame = NULL;
1614 moo_try_check(obj_frame =
1615 cpl_frameset_get_position(obj_frameset, i),
1617 moo_try_check(obj_rbn_frame =
1618 cpl_frameset_get_position(obj_rbn_frameset, i),
1620 moo_try_check(sky_rbn_frame =
1621 cpl_frameset_get_position(sky_rbn_frameset,
1624 moo_try_check(nod_rbn_frame =
1625 cpl_frameset_get_position(nod_rbn_frameset, i),
1627 cpl_msg_info(__func__,
1628 "---Create sci: %d/%d using nod %s object:%s sky: %s",
1629 i + 1, nb_nod, cpl_frame_get_filename(nod_rbn_frame),
1630 cpl_frame_get_filename(obj_rbn_frame),
1631 cpl_frame_get_filename(sky_rbn_frame));
1633 moo_try_check(sci_frame = _moons_starenod_sci(
1634 i, mode_name, offset, obj_frame, obj_rbn_frame,
1635 sky_rbn_frame, nod_rbn_frame, sky_lines,
1636 f2f_frame, airglow_group_frame, airglow_var_frame,
1637 solflux_frame, target_table_params,
1638 combine_pair_params, sky_params, products,
1641 cpl_frameset_insert(sci_frameset, cpl_frame_duplicate(sci_frame));
1646 if (!cpl_errorstate_is_equal(prestate)) {
1647 cpl_propertylist_delete(ref_header);
1652 if (wavemap_extlist != NULL) {
1653 for (
int i = 0; i < wavemap_extlist_size; i++) {
1662 cpl_free(sum_ext_filename);
1663 cpl_free(wmap_tuned_filename);
1666 cpl_frameset_delete(obj_rbn_frameset);
1667 cpl_frameset_delete(sky_rbn_frameset);
1668 cpl_frameset_delete(nod_rbn_frameset);
1670 cpl_frameset_delete(sky_det_frameset);
1671 cpl_frameset_delete(obj_det_frameset);
1672 cpl_frameset_delete(nod_det_frameset);
1674 cpl_frameset_delete(obj_frameset);
1675 cpl_frameset_delete(sky_frameset);
1676 cpl_frameset_delete(nod_ext_frameset);
1677 cpl_frameset_delete(sky_ext_frameset);
1678 cpl_frameset_delete(obj_ext_frameset);
1682 return (
int)cpl_error_get_code();
1686_moons_science_starenod(cpl_frameset *frameset,
1687 const cpl_parameterlist *parlist)
1690 moo_prepare_params *prepare_params = NULL;
1691 moo_correct_bias_params *correct_bias_params = NULL;
1692 moo_extract_params *extract_params = NULL;
1693 moo_wavesol_params *wavesol_params = NULL;
1694 moo_rebin_params *rbn_params = NULL;
1695 moo_target_table_params *target_table_params = NULL;
1696 moo_combine_pair_params *combine_pair_params = NULL;
1697 moo_sub_sky_stare_params *sky_params = NULL;
1698 moo_coadd_params *coadd_params = NULL;
1699 moo_create_s1d_params *s1d_params = NULL;
1701 moo_scilist *sci_list = NULL;
1702 moo_sci *sci_coadd = NULL;
1704 cpl_frameset *offset_frameset = NULL;
1705 cpl_frameset *set = NULL;
1706 cpl_frameset *sci_set = NULL;
1707 cpl_frameset *ref_frameset = NULL;
1709 const char *bpmap_rp_name = NULL;
1710 const char *bpmap_nl_name = NULL;
1711 const cpl_frame *masterbias = NULL;
1712 const cpl_frame *masterdark_vis = NULL;
1713 cpl_frameset *masterdark_nir = NULL;
1714 const cpl_frame *p2pmap = NULL;
1715 const cpl_frame *sformat_frame = NULL;
1716 const cpl_frame *sky_lines_frame = NULL;
1717 const cpl_frame *atmo_frame = NULL;
1718 const cpl_frame *resp_frame = NULL;
1719 const cpl_frame *tell_frame = NULL;
1720 const cpl_frame *airglow_group_frame = NULL;
1721 const cpl_frame *solflux_frame = NULL;
1722 const cpl_frame *airglow_var_frame = NULL;
1723 const cpl_frame *ref_frame = NULL;
1725 cpl_size *selection = NULL;
1726 moo_sky_lines_list *skylines = NULL;
1727 char *coadd_filename = NULL;
1728 char *calibflux_filename = NULL;
1730 cpl_errorstate prestate = cpl_errorstate_get();
1732 moo_products *products =
1734 PACKAGE
"/" PACKAGE_VERSION);
1739 moo_try_check(correct_bias_params =
1745 moo_try_check(target_table_params =
1748 moo_try_check(combine_pair_params =
1754 moo_try_check(wavesol_params =
1760 offset_frameset = cpl_frameset_new();
1761 sci_set = cpl_frameset_new();
1762 ref_frameset = cpl_frameset_new();
1763 masterdark_nir = cpl_frameset_new();
1765 moo_try_check(_moons_science_starenod_check_sof(
1766 frameset, offset_frameset, &bpmap_rp_name, &bpmap_nl_name,
1767 &masterbias, &masterdark_vis, masterdark_nir, &p2pmap,
1768 &sformat_frame, &sky_lines_frame, &atmo_frame,
1769 &resp_frame, &tell_frame, &airglow_group_frame,
1770 &airglow_var_frame, &solflux_frame, sky_params),
1773 cpl_frameset_sort(offset_frameset, _moons_sort_mjdobs);
1775 moo_try_check(selection =
1776 cpl_frameset_labelise(offset_frameset,
1777 &_moons_compare_offset, &nsel),
1782 for (
int i = 0; i < nsel; i++) {
1783 moo_try_check(set = cpl_frameset_extract(offset_frameset, selection, i),
1785 moo_try_check(_moons_science_starenod_byoffset(
1786 set, sci_set, ref_frameset, bpmap_rp_name,
1787 bpmap_nl_name, masterbias, masterdark_vis,
1788 masterdark_nir, p2pmap, sformat_frame, skylines,
1789 airglow_group_frame, solflux_frame, airglow_var_frame,
1790 atmo_frame, resp_frame, tell_frame, prepare_params,
1791 correct_bias_params, extract_params, wavesol_params,
1792 rbn_params, target_table_params, combine_pair_params,
1793 sky_params, products),
1796 cpl_frameset_delete(set);
1800 moo_try_check(ref_frame = cpl_frameset_get_position_const(ref_frameset, 0),
1806 cpl_sprintf(
"%s_%s.fits", MOONS_TAG_STARENOD_COMBINED_SPECTRA,
1809 sci_coadd =
moo_coadd(sci_list, coadd_params, coadd_filename);
1812 cpl_frame *sci_final = NULL;
1813 moo_try_check(sci_final =
1815 CPL_FRAME_LEVEL_FINAL,
1816 MOONS_TAG_STARENOD_COMBINED_SPECTRA,
1817 coadd_filename, ref_frame),
1819 moo_create_s1d(sci_final, s1d_params, MOONS_TAG_SCIENCE_STARENOD_1DSPECTRUM,
1823 if (!cpl_errorstate_is_equal(prestate)) {
1824 cpl_frameset_delete(set);
1826 cpl_free(coadd_filename);
1827 cpl_free(calibflux_filename);
1828 cpl_free(selection);
1833 cpl_frameset_delete(sci_set);
1834 cpl_frameset_delete(ref_frameset);
1835 cpl_frameset_delete(offset_frameset);
1836 cpl_frameset_delete(masterdark_nir);
1838 moo_extract_params_delete(extract_params);
1839 moo_wavesol_params_delete(wavesol_params);
1840 moo_rebin_params_delete(rbn_params);
1841 moo_target_table_params_delete(target_table_params);
1843 moo_combine_pair_params_delete(combine_pair_params);
1844 moo_sub_sky_stare_params_delete(sky_params);
1845 moo_coadd_params_delete(coadd_params);
1846 moo_correct_bias_params_delete(correct_bias_params);
1848 moo_prepare_params_delete(prepare_params);
1850 moo_products_delete(products);
1851 return (
int)cpl_error_get_code();
moo_atm * moo_atm_load(const cpl_frame *frame)
Load a ATM frame and create a moo_atm.
void moo_atm_delete(moo_atm *self)
Delete a moo_atm.
moo_det * moo_det_create(const cpl_frame *frame)
Create a new moo_det from the given DET frame.
cpl_error_code moo_det_load(moo_det *self, unsigned int level)
Load all parts in DET.
void moo_det_delete(moo_det *self)
Delete a moo_det.
moo_single * moo_det_get_single(moo_det *self, moo_detector_type type, int num)
Get the type part in DET and return it.
moo_mode_type moo_mode_get(const cpl_frame *frame)
Get the name of a mode from a frame.
const char * moo_mode_get_name(moo_mode_type type)
Get the name of a mode.
moo_ext * moo_ext_create(const cpl_frame *frame)
Create a new empty EXT filename.
void moo_ext_delete(moo_ext *self)
Delete a moo_ext.
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.
moo_ext * moo_extlist_get(moo_extlist *self, int i)
Get the DET at the position i in the list.
cpl_error_code moo_extlist_set(moo_extlist *self, moo_ext *ext, cpl_size pos)
Insert a DET into an moo_extlist.
moo_ext * moo_extlist_unset(moo_extlist *self, cpl_size pos)
Remove a DET from a DET list.
moo_ext * moo_extlist_sum(moo_extlist *self, const char *filename)
Sum EXT element from the list and save result in filename.
void moo_extlist_delete(moo_extlist *self)
Free all memory used by a moo_extlist object including the DET.
moo_extlist * moo_extlist_create(cpl_frameset *frameset)
Create a new moo_extlist from the given DET frameset.
moo_extlist * moo_extlist_new(void)
Create a new moo_extlist.
void moo_f2f_delete(moo_f2f *self)
Delete a moo_f2f.
moo_f2f * moo_f2f_load(const cpl_frame *f2f_frame)
Load a F2F table from a fits file.
moo_loc * moo_loc_load(const cpl_frame *locframe)
Load a LOC frame and create a moo_loc.
void moo_loc_delete(moo_loc *self)
Delete a moo_loc.
void moo_map_save(moo_map *self, const char *filename)
Save a moo_map to a FITS file.
void moo_map_delete(moo_map *self)
Delete a moo_map.
moo_coadd_params * moo_params_get_coadd(const moo_params *self, const cpl_parameterlist *list)
Get coadd parameters from moons parameters list.
cpl_error_code moo_params_add_create_s1d(moo_params *self, cpl_parameterlist *list)
Add default parameters for create_s1d.
void moo_create_s1d_params_delete(moo_create_s1d_params *self)
Delete a moo_create_s1d_params.
cpl_error_code moo_params_add_extract(moo_params *self, cpl_parameterlist *list)
Add default parameters for extraction.
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.
moo_prepare_params * moo_params_get_prepare(const moo_params *self, const cpl_parameterlist *list)
Get remove prepare parameters from moons parameters list.
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.
moo_combine_pair_params * moo_params_get_combine_pair(const moo_params *self, const cpl_parameterlist *list)
Get combine_pair parameters from moons parameters list.
cpl_error_code moo_params_add_target_table(moo_params *self, cpl_parameterlist *list, int value)
Add default parameters for moo_create_target_table.
cpl_error_code moo_params_add_combine_pair(moo_params *self, cpl_parameterlist *list, int value)
Add default parameters for moo_combine_pair.
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.
cpl_error_code moo_params_add_science_wavesol(moo_params *self, cpl_parameterlist *list)
Add default science parameters for moo_wavesol.
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.
moo_extract_params * moo_params_get_extract(const moo_params *self, const cpl_parameterlist *list)
Get extraction parameters from moons parameters list.
moo_wavesol_params * moo_params_get_science_wavesol(const moo_params *self, const cpl_parameterlist *list)
Get science_wavesol parameters from moons parameters list.
void moo_params_delete(moo_params *self)
Delete a moo_params.
cpl_error_code moo_params_add_sub_sky_stare_wnone(moo_params *self, cpl_parameterlist *list)
Add default parameters for moo_sub_sky_stare.
cpl_error_code moo_params_add_correct_bias(moo_params *self, cpl_parameterlist *list, const char *method)
Add default parameters for correct_bias.
cpl_error_code moo_params_add_keep_temp(moo_params *self, cpl_parameterlist *list)
Add default parameters for keep-temp.
cpl_error_code moo_params_add_prepare(moo_params *self, cpl_parameterlist *list)
Add default parameters for prepare.
moo_rebin_params * moo_params_get_rebin(const moo_params *self, const cpl_parameterlist *list)
Get rebin parameters from moons parameters list.
cpl_error_code moo_params_add_coadd(moo_params *self, cpl_parameterlist *list)
Add default parameters for moo_coadd.
moo_params * moo_params_new(const char *pid, const char *recipe_id)
Create a new moo_params.
cpl_error_code moo_params_add_rebin(moo_params *self, cpl_parameterlist *list)
Add default parameters for moo_rebin.
void moo_psf_delete(moo_psf *self)
Delete a moo_psf.
moo_psf * moo_psf_load(const cpl_frame *psfframe)
Load a PSF frame and create a moo_psf.
void moo_rbn_delete(moo_rbn *self)
Delete a moo_rbn.
moo_rbn * moo_rbn_create(const cpl_frame *frame)
Create a new empty RBN filename.
cpl_error_code moo_rbn_compute_snr(moo_rbn *self, moo_sky_lines_list *skylines)
Compute SNR for targets in RBN.
void moo_resp_delete(moo_resp *self)
Delete a moo_resp.
moo_resp * moo_resp_load(const cpl_frame *frame)
Load a RESP frame and create a moo_resp.
void moo_sci_delete(moo_sci *self)
Delete a moo_sci.
cpl_error_code moo_sci_compute_snr(moo_sci *self, moo_sky_lines_list *skylines)
Compute SNR for all targets in SCI.
void moo_scilist_delete(moo_scilist *self)
Free all memory used by a moo_scilist object including the SCI.
moo_scilist * moo_scilist_create(cpl_frameset *frameset)
Create a new moo_scilist from the given SCI frameset.
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_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.
void moo_telluric_delete(moo_telluric *self)
Delete a moo_telluric.
cpl_error_code moo_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
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
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.
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.
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.
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...
moo_sci * moo_combine_pair(moo_rbn *nod_rbn, moo_rbn *sky_rbn, moo_rbn *obj_rbn, moo_target_table *target_table, moo_f2f *f2f, const cpl_frame *solflux_frame, const cpl_frame *airglow_group_frame, const cpl_frame *airglow_var_frame, moo_combine_pair_params *combine_pair_params, moo_sub_sky_stare_params *sky_params, const char *filename, moo_products *products, const cpl_frame *ref_frame)
Combine the extracted spectra from a same objec.
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.
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)....
int moo_pfits_get_ndit(const cpl_propertylist *plist)
find out the ESO DET NDIT value
double moo_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
double moo_pfits_get_mjdobs(const cpl_propertylist *plist)
find out the MJD-OBS
int moo_pfits_get_slit_offset(const cpl_propertylist *plist)
find out the INS SLIT OFFSET value
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
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
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
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
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
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
const moo_params * moo_products_get_params(const moo_products *self)
get the moo_params object
const char * moo_get_license(void)
Get the pipeline copyright and license.
the different type of detectors