31#include "moo_params.h"
33#include "moo_products.h"
34#include "moo_correct_tell.h"
35#include "moo_molecfit.h"
36#include "moo_molectable.h"
44int cpl_plugin_get_info(cpl_pluginlist *list);
50static int _moons_standard_create(cpl_plugin *plugin);
51static int _moons_standard_exec(cpl_plugin *plugin);
52static int _moons_standard_destroy(cpl_plugin *plugin);
54_moons_standard(cpl_frameset *frameset,
const cpl_parameterlist *parlist);
60static const char *
const _moons_standard_description =
61 "Produces the instrumental response for relative flux calibration, and "
62 "the telluric absorption spectrum.\n"
64 " * flux or telluric standard star n>=3 file(s) (RAW) with tag STD_FLUX "
66 "standard star file\n"
67 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag BP_MAP_RP "
69 "cosmetic bad pixel map\n"
70 " * [OPTIONAL] NonLinearityBadPixMask 1 file (QUA) with tag BP_MAP_NL "
72 "cosmetic bad pixel map coming from linearity recipe\n"
73 " * MasterBias 1 file (DET) with tag "
76 " * MasterDarkNir 1 file (DET) with tag "
78 "master dark nir file\n"
79 " * [OPTIONAL]MasterDarkVis 1 file (DET) with tag "
81 "master dark vis file\n"
82 " * [OPTIONAL] CoeffsCube 1 file (3D) with tag "
83 "LINEARITY_COEFF_CUBE : "
84 "coefficients to correct pixels detector linearity\n"
85 " * [OPTIONAL] P2pMap 1 file (DET) with tag P2P_MAP : "
86 "pixel to pixel map\n"
87 " * LocTab 1 file (LOC) with tag FF_TRACE : "
88 "the localisation table\n"
89 " * Ffext 1 file (EXT) with tag "
91 "the extracted flat field\n"
92 " * F2f 1 file (F2F) with tag F2F_TABLE "
94 "the fibre-to-fibre relative response\n"
95 " * SFormat 1 file (FMT) with tag "
97 "the spectral format table\n"
98 " * [OPTIONAL] MasterFlat 1 file (PSF) with tag "
100 "the master flat used for optimal extraction\n"
101 " * WaveMap 1 file (WMAP) with tag WAVE_MAP "
103 "the wavelength map\n"
104 " * fluxStdCat 1 file (FLX) with tag "
106 "the standard star flux table\n"
107 " * atmosExt 1 file (ATMO) with tag ATMOS_EXT "
109 "the atmospheric extinction table\n"
110 " * SkyLines 1 file (CAT) with tag "
112 "the sky lines list table\n"
113 " * [STDTELL only] file (MOLECULES) with tag MOLECULES 1 file : "
114 "molecules list file\n"
116 " * STD_EXTSPECTRA_i_[insmode].fits (EXT) with tag STD_EXTSPECTRA : "
117 "Science product individual extracted frames\n"
118 " * STD_RBNSPECTRA_i_[insmode].fits (RBN) with tag STD_RBNSPECTRA : "
119 "Science product individual calibrated frames\n"
120 " * STD_SKSSPECTRA_[insmode]_i.fits (SCI) with tag STD_SKSSPECTRA : "
121 "Science product individual sky subtracted frames\n"
122 " * STD_SKSSPECTRA_[insmode].fits (SCI) with tag STD_SKSSPECTRA : "
123 "Science product flux calibrated frame\n"
124 " * RESPONSE_[insmode].fits (RESP) with tag RESPONSE : "
125 "Instrumental response product\n"
126 " * TELLURIC_[insmode].fits (TELLURIC) with tag TELLURIC : "
128 " * GDAS User GDAS profile"
129 " * GDAS_BEFORE If ESO DB GDAS is used, file before the MJD-OBS"
130 " * GDAS_AFTER If ESO DB GDAS is used, file after the MJD-OBS"
150cpl_plugin_get_info(cpl_pluginlist *list)
152 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
153 cpl_plugin *plugin = &recipe->interface;
155 if (cpl_plugin_init(plugin, CPL_PLUGIN_API, MOONS_BINARY_VERSION,
156 CPL_PLUGIN_TYPE_RECIPE,
"moons_standard",
157 "Produces the instrumental response for relative flux "
158 "calibration, and the telluric absorption spectrum.",
159 _moons_standard_description,
"Regis Haigron",
161 _moons_standard_create, _moons_standard_exec,
162 _moons_standard_destroy)) {
163 cpl_msg_error(cpl_func,
"Plugin initialization failed");
164 (void)cpl_error_set_where(cpl_func);
168 if (cpl_pluginlist_append(list, plugin)) {
169 cpl_msg_error(cpl_func,
"Error adding plugin to list");
170 (void)cpl_error_set_where(cpl_func);
189_moons_standard_create(cpl_plugin *plugin)
194 if (cpl_error_get_code() != CPL_ERROR_NONE) {
195 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
196 cpl_func, __LINE__, cpl_error_get_where());
197 return (
int)cpl_error_get_code();
200 if (plugin == NULL) {
201 cpl_msg_error(cpl_func,
"Null plugin");
202 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
206 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
207 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
208 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
212 recipe = (cpl_recipe *)plugin;
215 recipe->parameters = cpl_parameterlist_new();
216 if (recipe->parameters == NULL) {
217 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
218 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
227 MOO_CORRECT_BIAS_METHOD_MASTER);
251_moons_standard_exec(cpl_plugin *plugin)
255 cpl_errorstate initial_errorstate = cpl_errorstate_get();
258 if (cpl_error_get_code() != CPL_ERROR_NONE) {
259 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
260 cpl_func, __LINE__, cpl_error_get_where());
261 return (
int)cpl_error_get_code();
264 if (plugin == NULL) {
265 cpl_msg_error(cpl_func,
"Null plugin");
266 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
270 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
271 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
272 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
276 recipe = (cpl_recipe *)plugin;
279 if (recipe->parameters == NULL) {
280 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
281 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
283 if (recipe->frames == NULL) {
284 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
285 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
289 recipe_status = _moons_standard(recipe->frames, recipe->parameters);
292 if (cpl_dfs_update_product_header(recipe->frames)) {
294 recipe_status = (int)cpl_error_get_code();
297 if (!cpl_errorstate_is_equal(initial_errorstate)) {
300 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
303 return recipe_status;
316_moons_standard_destroy(cpl_plugin *plugin)
320 if (plugin == NULL) {
321 cpl_msg_error(cpl_func,
"Null plugin");
322 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
326 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
327 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
328 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
332 recipe = (cpl_recipe *)plugin;
334 cpl_parameterlist_delete(recipe->parameters);
340_moons_standard_check_sof(cpl_frameset *frameset,
341 cpl_frameset *std_frameset,
342 const char **bpmap_rp_name,
343 const char **bpmap_nl_name,
344 const cpl_frame **masterbias,
345 const cpl_frame **masterdark_vis,
346 const cpl_frame **masterdark_nir,
347 const cpl_frame **coeffs_cube,
348 const cpl_frame **p2pmap,
349 const cpl_frame **fftrace,
350 const cpl_frame **master_flat,
351 const cpl_frame **sformat,
352 const cpl_frame **wmap,
353 const cpl_frame **skylines,
354 const cpl_frame **flat,
355 const cpl_frame **tell,
356 const cpl_frame **f2f,
357 const cpl_frame **flx,
358 const cpl_frame **atmo,
359 const cpl_frame **molecules_frame,
360 const cpl_frame **winc_frame,
361 const moo_extract_params *ext_params,
365 cpl_error_get_code());
366 cpl_ensure_code(mode != NULL, CPL_ERROR_NULL_INPUT);
372 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
373 cpl_frame *current_frame = cpl_frameset_get_position(frameset, i);
374 if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_STD_FLUX)) {
375 cpl_frameset_insert(std_frameset,
376 cpl_frame_duplicate(current_frame));
380 else if (!strcmp(cpl_frame_get_tag(current_frame),
381 MOONS_TAG_STD_TELL)) {
382 cpl_frameset_insert(std_frameset,
383 cpl_frame_duplicate(current_frame));
387 else if (!strcmp(cpl_frame_get_tag(current_frame),
388 MOONS_TAG_BP_MAP_RP)) {
389 *bpmap_rp_name = cpl_frame_get_filename(current_frame);
391 else if (!strcmp(cpl_frame_get_tag(current_frame),
392 MOONS_TAG_BP_MAP_NL)) {
393 *bpmap_nl_name = cpl_frame_get_filename(current_frame);
395 else if (!strcmp(cpl_frame_get_tag(current_frame),
396 MOONS_TAG_MASTER_BIAS)) {
397 *masterbias = current_frame;
399 else if (!strcmp(cpl_frame_get_tag(current_frame),
400 MOONS_TAG_MASTER_DARK_VIS)) {
401 *masterdark_vis = current_frame;
403 else if (!strcmp(cpl_frame_get_tag(current_frame),
404 MOONS_TAG_MASTER_DARK_NIR)) {
405 *masterdark_nir = current_frame;
407 else if (!strcmp(cpl_frame_get_tag(current_frame),
408 MOONS_TAG_LINEARITY_COEFF_CUBE)) {
409 *coeffs_cube = current_frame;
411 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_P2P_MAP)) {
412 *p2pmap = current_frame;
414 else if (!strcmp(cpl_frame_get_tag(current_frame),
415 MOONS_TAG_FF_TRACE)) {
416 *fftrace = current_frame;
418 else if (!strcmp(cpl_frame_get_tag(current_frame),
419 MOONS_TAG_MASTER_FLAT)) {
420 *master_flat = current_frame;
422 else if (!strcmp(cpl_frame_get_tag(current_frame),
423 MOONS_TAG_SPECTRAL_FORMAT)) {
424 *sformat = current_frame;
426 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_WAVEMAP)) {
427 *wmap = current_frame;
429 else if (!strcmp(cpl_frame_get_tag(current_frame),
430 MOONS_TAG_SKY_LINE_LIST)) {
431 *skylines = current_frame;
433 else if (!strcmp(cpl_frame_get_tag(current_frame),
434 MOONS_TAG_FF_EXTSPECTRA)) {
435 *flat = current_frame;
437 else if (!strcmp(cpl_frame_get_tag(current_frame),
438 MOONS_TAG_F2F_TABLE)) {
439 *f2f = current_frame;
441 else if (!strcmp(cpl_frame_get_tag(current_frame),
442 MOONS_TAG_FLUX_STD_CATALOG)) {
443 *flx = 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_TELLURIC_CORR)) {
451 *tell = current_frame;
453 else if (!strcmp(cpl_frame_get_tag(current_frame),
454 MOONS_TAG_MOLECFIT_MOLECULES)) {
455 *molecules_frame = current_frame;
457 else if (!strcmp(cpl_frame_get_tag(current_frame),
458 MOONS_TAG_MOLECFIT_WINCLUDE)) {
459 *winc_frame = current_frame;
464 if (cpl_frameset_get_size(std_frameset) == 0) {
465 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
466 "SOF does not have any file tagged "
471 if (nb_std_flux > 0 && nb_std_tell > 0) {
472 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
473 "SOF have mixed STD input files"
474 "%d with %s and %d with %s",
475 nb_std_flux, MOONS_TAG_STD_FLUX,
476 nb_std_tell, MOONS_TAG_STD_TELL);
478 if (*fftrace == NULL) {
479 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
480 "SOF does not have any file tagged "
486 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
487 "SOF does not have any file tagged "
489 MOONS_TAG_F2F_TABLE);
492 if (*master_flat == NULL &&
493 strcmp(ext_params->method, MOO_EXTRACT_METHOD_OPTIMAL) == 0) {
494 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
495 "SOF does not have any file tagged "
497 MOONS_TAG_MASTER_FLAT);
500 if (*sformat == NULL) {
501 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
502 "SOF does not have any file tagged "
504 MOONS_TAG_SPECTRAL_FORMAT);
508 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
509 "SOF does not have any file tagged "
514 if (*skylines == NULL) {
515 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
516 "SOF does not have any file tagged "
518 MOONS_TAG_SKY_LINE_LIST);
522 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
523 "SOF does not have any file tagged "
525 MOONS_TAG_FF_EXTSPECTRA);
528 if (nb_std_flux > 0 && *flx == NULL) {
529 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
530 "SOF does not have any file tagged "
532 MOONS_TAG_FLUX_STD_CATALOG);
534 if (nb_std_flux > 0 && *atmo == NULL) {
535 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
536 "SOF does not have any file tagged "
538 MOONS_TAG_ATMOS_EXT);
540 if (nb_std_tell > 0) {
542 if (*molecules_frame == NULL) {
544 int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
545 "SOF does not have any file tagged "
547 MOONS_TAG_MOLECFIT_MOLECULES);
550 if (*winc_frame == NULL) {
552 int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
553 "SOF does not have any file tagged "
555 MOONS_TAG_MOLECFIT_WINCLUDE);
558 return CPL_ERROR_NONE;
563_moons_p2pmap(moo_det *arc,
const cpl_frame *p2pmap)
565 cpl_error_code status = CPL_ERROR_NONE;
568 if (p2pmap != NULL) {
578_moons_apply_flat(moo_ext *ext,
579 const cpl_frame *flat_frame,
580 const cpl_frame *f2f_frame)
582 cpl_error_code status = CPL_ERROR_NONE;
583 moo_ext *flat = NULL;
587 if (f2f_frame != NULL) {
599_moons_sub_sky_stare(moo_rbn *rbn,
601 const cpl_frame *f2f_frame,
602 moo_sub_sky_stare_params *sky_params,
603 const char *sci_filename)
605 moo_sci *result = NULL;
608 if (f2f_frame != NULL) {
611 moo_try_check(result =
613 NULL, sky_params, sci_filename,
614 MOO_SCI1D_NOT_PAIRED),
623_moons_standard_frame(
int inum,
624 const cpl_frame *frame,
625 const cpl_frame *refframe,
626 const cpl_frame *p2pmap,
627 const cpl_frame *fftrace,
628 const cpl_frame *master_flat,
629 moo_spectral_format *sformat,
631 moo_sky_lines_list *skylines,
632 const cpl_frame *flat_frame,
633 const cpl_frame *f2f_frame,
634 const cpl_frame *tell_frame,
635 moo_extract_params *extract_params,
636 moo_rebin_params *rbn_params,
637 moo_target_table_params *target_table_params,
638 moo_sub_sky_stare_params *sky_params,
640 moo_products *products,
644 const char *stdp2p_tags[] = { MOONS_TAG_STDFLUX_APPLYP2P,
645 MOONS_TAG_STDTELL_APPLYP2P };
647 const char *stdext_tags[] = { MOONS_TAG_STDFLUX_EXTSPECTRA,
648 MOONS_TAG_STDTELL_EXTSPECTRA };
650 const char *stdffext_tags[] = { MOONS_TAG_STDFLUX_FFEXTSPECTRA,
651 MOONS_TAG_STDTELL_FFEXTSPECTRA };
653 const char *stdrbn_tags[] = { MOONS_TAG_STDFLUX_RBNSPECTRA,
654 MOONS_TAG_STDTELL_RBNSPECTRA };
655 const char *stdttable_tags[] = { MOONS_TAG_STDFLUX_TARGET_TABLE,
656 MOONS_TAG_STDTELL_TARGET_TABLE };
658 const char *stdsks_tags[] = { MOONS_TAG_STDFLUX_SKSSPECTRA,
659 MOONS_TAG_STDTELL_SKSSPECTRA };
661 cpl_frame *sci_frame = NULL;
667 moo_telluric *telluric = NULL;
670 char *det_filename = NULL;
671 char *ext_filename = NULL;
672 char *ffext_filename = NULL;
673 char *rbn_filename = NULL;
674 char *tellcorr_filename = NULL;
675 char *ttable_filename = NULL;
676 char *sci_filename = NULL;
679 cpl_errorstate prestate = cpl_errorstate_get();
682 moo_try_check(_moons_p2pmap(det, p2pmap),
" ");
684 det_filename = cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits", stdp2p_tags[rmode],
687 stdp2p_tags[rmode], det_filename, refframe),
690 if (master_flat != NULL) {
693 ext_filename = cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits", stdext_tags[rmode],
696 moo_extract(det, loc, psf, extract_params, ext_filename),
699 CPL_FRAME_LEVEL_INTERMEDIATE,
700 stdext_tags[rmode], ext_filename,
704 moo_try_check(_moons_apply_flat(ext, flat_frame, f2f_frame),
" ");
705 ffext_filename = cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits", stdffext_tags[rmode],
710 stdffext_tags[rmode], ffext_filename,
714 rbn_filename = cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits", stdrbn_tags[rmode],
716 moo_try_check(rbn =
moo_rebin(ext, wmap, sformat, rbn_params, rbn_filename),
722 stdrbn_tags[rmode], rbn_filename,
725 if (tell_frame != NULL) {
728 tellcorr_filename = cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits",
729 MOONS_TAG_STDFLUX_RBNTELLCORRSPECTRA,
733 MOONS_TAG_STDFLUX_RBNTELLCORRSPECTRA,
734 tellcorr_filename, refframe),
738 cpl_msg_info(__func__,
"No telluric correction");
741 moo_try_check(target_table =
743 target_table_params),
746 cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits", stdttable_tags[rmode], offset,
749 CPL_FRAME_LEVEL_INTERMEDIATE,
750 stdttable_tags[rmode],
751 ttable_filename, refframe),
753 sci_filename = cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits", stdsks_tags[rmode],
755 moo_try_check(sci = _moons_sub_sky_stare(rbn, target_table, f2f_frame,
756 sky_params, sci_filename),
760 moo_try_check(sci_frame = cpl_frame_duplicate(
762 stdsks_tags[rmode], sci_filename,
768 if (!cpl_errorstate_is_equal(prestate)) {
769 cpl_frame_delete(sci_frame);
772 cpl_free(det_filename);
773 cpl_free(ext_filename);
774 cpl_free(ffext_filename);
775 cpl_free(rbn_filename);
776 cpl_free(ttable_filename);
777 cpl_free(tellcorr_filename);
778 cpl_free(sci_filename);
793_moons_prepare(
int inum,
794 const cpl_frame *frame,
795 const char *bpmap_rp_name,
796 const char *bpmap_nl_name,
797 const cpl_frame *masterbias,
798 const cpl_frame *masterdark_vis,
799 const cpl_frame *masterdark_nir,
800 const cpl_frame *coeffs_cube,
801 moo_prepare_params *prepare_params,
802 moo_correct_bias_params *cbias_params,
804 moo_products *products,
808 cpl_frame *result = NULL;
811 const char *det_tag[] = { MOONS_TAG_STDFLUX_CORRECTDARK,
812 MOONS_TAG_STDTELL_CORRECTDARK };
813 char *det_filename = NULL;
815 cpl_errorstate prestate = cpl_errorstate_get();
817 moo_try_check(det =
moo_prepare(frame, bpmap_rp_name, bpmap_nl_name,
818 masterbias, coeffs_cube, prepare_params),
825 det_filename = cpl_sprintf(
"%s_OFFSET%d_%s_%d.fits", det_tag[rmode], offset,
827 moo_try_check(result = cpl_frame_duplicate(
829 CPL_FRAME_LEVEL_INTERMEDIATE,
830 det_tag[rmode], det_filename, frame)),
834 if (!cpl_errorstate_is_equal(prestate)) {
835 cpl_frame_delete(result);
839 cpl_free(det_filename);
844_moons_prepare_set(
const cpl_frameset *std_frameset,
845 const char *bpmap_rp_name,
846 const char *bpmap_nl_name,
847 const cpl_frame *masterbias,
848 const cpl_frame *masterdark_vis,
849 const cpl_frame *masterdark_nir,
850 const cpl_frame *coeffs_cube,
851 moo_prepare_params *prepare_params,
852 moo_correct_bias_params *cbias_params,
854 moo_products *products,
858 cpl_frameset *detframes = NULL;
861 cpl_ensure(std_frameset, CPL_ERROR_NULL_INPUT, NULL);
862 cpl_ensure(products, CPL_ERROR_NULL_INPUT, NULL);
864 cpl_errorstate prestate = cpl_errorstate_get();
866 moo_try_check(detframes = cpl_frameset_new(),
" ");
868 for (
int i = 0; i < cpl_frameset_get_size(std_frameset); ++i) {
869 const cpl_frame *current_frame = NULL;
870 cpl_frame *frame = NULL;
872 moo_try_check(current_frame =
873 cpl_frameset_get_position_const(std_frameset, i),
876 moo_try_check(frame = _moons_prepare(i, current_frame, bpmap_rp_name,
877 bpmap_nl_name, masterbias,
878 masterdark_vis, masterdark_nir,
879 coeffs_cube, prepare_params,
880 cbias_params, mode, products,
884 moo_try_check(cpl_frameset_insert(detframes, frame),
" ");
887 if (!cpl_errorstate_is_equal(prestate)) {
889 cpl_frameset_delete(detframes);
904_moons_standard(cpl_frameset *frameset,
const cpl_parameterlist *parlist)
909 moo_prepare_params *prepare_params = NULL;
910 moo_correct_bias_params *correct_bias_params = NULL;
911 moo_crh_params *crh_params = NULL;
912 moo_extract_params *extract_params = NULL;
913 moo_wavesol_params *wavesol_params = NULL;
914 moo_rebin_params *rbn_params = NULL;
915 moo_target_table_params *target_table_params = NULL;
916 moo_sub_sky_stare_params *sky_params = NULL;
917 moo_coadd_params *coadd_params = NULL;
918 moo_compute_resp_params *resp_params = NULL;
919 moo_spectral_format *sformat = NULL;
920 moo_map *wmap = NULL;
921 moo_sky_lines_list *skylines = NULL;
924 moo_detlist *det_list = NULL;
925 moo_det *std_med = NULL;
926 moo_scilist *sci_list = NULL;
927 moo_sci *sci_coadd = NULL;
928 moo_resp *resp = NULL;
931 cpl_frameset *std_frameset = cpl_frameset_new();
932 cpl_frameset *sci_set = cpl_frameset_new();
934 const char *bpmap_rp_name = NULL;
935 const char *bpmap_nl_name = NULL;
936 const cpl_frame *masterbias = NULL;
937 const cpl_frame *masterdark_vis = NULL;
938 const cpl_frame *masterdark_nir = NULL;
939 const cpl_frame *coeffs_cube = NULL;
940 const cpl_frame *p2pmap = NULL;
941 const cpl_frame *fftrace = NULL;
942 const cpl_frame *master_flat = NULL;
943 const cpl_frame *sformat_frame = NULL;
944 const cpl_frame *wmap_frame = NULL;
945 const cpl_frame *skylines_frame = NULL;
946 const cpl_frame *tell_frame = NULL;
947 const cpl_frame *flat_frame = NULL;
948 const cpl_frame *f2f_frame = NULL;
949 const cpl_frame *flx_frame = NULL;
950 const cpl_frame *atmo_frame = NULL;
951 cpl_frameset *stddet_frameset = NULL;
952 char *med_filename = NULL;
953 char *resp_filename = NULL;
954 char *calibflux_filename = NULL;
957 const char *rmodenames[] = {
"STDFLUX",
"STDTELL" };
959 const char *modename = NULL;
960 const cpl_frame *molecule_frame = NULL;
961 const cpl_frame *winc_frame = NULL;
962 moo_molecfit_model_params *molecfit_model_params = NULL;
964 moo_molectable *atm_fitted = NULL;
965 moo_molectable *best_fitted_params = NULL;
966 moo_molectable *best_fitted_model = NULL;
968 char *best_fitted_params_name = NULL;
969 char *best_fitted_model_name = NULL;
970 char *atm_fitted_name = NULL;
972 moo_products *products =
974 PACKAGE
"/" PACKAGE_VERSION);
980 moo_try_check(correct_bias_params =
987 moo_try_check(target_table_params =
995 moo_try_check(molecfit_model_params =
998 moo_try_check(_moons_standard_check_sof(
999 frameset, std_frameset, &bpmap_rp_name, &bpmap_nl_name,
1000 &masterbias, &masterdark_vis, &masterdark_nir,
1001 &coeffs_cube, &p2pmap, &fftrace, &master_flat,
1002 &sformat_frame, &wmap_frame, &skylines_frame, &flat_frame,
1003 &tell_frame, &f2f_frame, &flx_frame, &atmo_frame,
1004 &molecule_frame, &winc_frame, extract_params, &rmode),
1007 const char *rmodename = rmodenames[rmode];
1011 cpl_frame *frame = cpl_frameset_get_position(std_frameset, 0);
1016 cpl_msg_info(
"moons_standard",
1017 "Use standard in mode %s frame mode %s offset %d", rmodename,
1021 moo_try_check(wmap = moo_map_load(wmap_frame),
" ");
1024 moo_try_check(stddet_frameset =
1025 _moons_prepare_set(std_frameset, bpmap_rp_name,
1026 bpmap_nl_name, masterbias,
1027 masterdark_vis, masterdark_nir,
1028 coeffs_cube, prepare_params,
1029 correct_bias_params, mode, products,
1035 moo_try_check(std_med =
moo_remove_CRH(det_list, NULL, crh_params),
1038 cpl_sprintf(
"%s_OFFSET%d_%s.fits", MOONS_TAG_STDTELL_REMOVECRH,
1040 cpl_frameset_delete(stddet_frameset);
1041 stddet_frameset = cpl_frameset_new();
1042 moo_try_check(cpl_frameset_insert(stddet_frameset,
1045 CPL_FRAME_LEVEL_INTERMEDIATE,
1046 MOONS_TAG_STDTELL_REMOVECRH,
1047 med_filename, frame))),
1050 int size = cpl_frameset_get_size(stddet_frameset);
1052 for (i = 0; i < size; ++i) {
1053 const cpl_frame *current_frame = NULL;
1054 const cpl_frame *ref_frame = NULL;
1055 cpl_frame *sci_frame = NULL;
1056 moo_try_check(current_frame =
1057 cpl_frameset_get_position_const(stddet_frameset, i),
1059 moo_try_check(ref_frame =
1060 cpl_frameset_get_position_const(std_frameset, i),
1063 moo_try_check(sci_frame = _moons_standard_frame(
1064 i, current_frame, ref_frame, p2pmap, fftrace,
1065 master_flat, sformat, wmap, skylines, flat_frame,
1066 f2f_frame, tell_frame, extract_params, rbn_params,
1067 target_table_params, sky_params, mode, products,
1070 cpl_frameset_insert(sci_set, sci_frame);
1082 resp_filename = cpl_sprintf(
"%s_%s.fits", MOONS_TAG_RESPONSE,
1085 CPL_FRAME_LEVEL_FINAL,
1086 MOONS_TAG_RESPONSE, resp_filename,
1092 const cpl_frame *sci_frame = NULL;
1093 moo_try_check(sci_frame = cpl_frameset_get_position_const(sci_set, 0),
1095 moo_try_check(best_fitted_params =
1097 molecule_frame, winc_frame,
1098 &atm_fitted, &best_fitted_model,
1099 molecfit_model_params),
1102 cpl_sprintf(
"%s_%s.fits", MOONS_TAG_MOLECFIT_ATM_PARAMS,
1104 best_fitted_params_name =
1105 cpl_sprintf(
"%s_%s.fits", MOONS_TAG_MOLECFIT_BEST_FIT_PARAMS,
1107 best_fitted_model_name =
1108 cpl_sprintf(
"%s_%s.fits", MOONS_TAG_MOLECFIT_BEST_FIT_MODEL,
1112 products, best_fitted_params, CPL_FRAME_LEVEL_FINAL,
1113 MOONS_TAG_MOLECFIT_BEST_FIT_PARAMS,
1114 best_fitted_params_name, sci_frame),
1118 CPL_FRAME_LEVEL_INTERMEDIATE,
1119 MOONS_TAG_MOLECFIT_BEST_FIT_MODEL,
1120 best_fitted_model_name, sci_frame),
1123 CPL_FRAME_LEVEL_FINAL,
1124 MOONS_TAG_MOLECFIT_ATM_PARAMS,
1125 atm_fitted_name, sci_frame),
1130 cpl_free(resp_filename);
1131 cpl_free(med_filename);
1132 cpl_free(calibflux_filename);
1143 cpl_frameset_delete(std_frameset);
1144 cpl_frameset_delete(stddet_frameset);
1145 cpl_frameset_delete(sci_set);
1146 moo_extract_params_delete(extract_params);
1147 moo_wavesol_params_delete(wavesol_params);
1148 moo_target_table_params_delete(target_table_params);
1149 moo_rebin_params_delete(rbn_params);
1150 moo_sub_sky_stare_params_delete(sky_params);
1151 moo_coadd_params_delete(coadd_params);
1152 moo_compute_resp_params_delete(resp_params);
1153 moo_crh_params_delete(crh_params);
1154 moo_correct_bias_params_delete(correct_bias_params);
1155 moo_prepare_params_delete(prepare_params);
1156 cpl_free(best_fitted_params_name);
1157 cpl_free(best_fitted_model_name);
1158 cpl_free(atm_fitted_name);
1163 moo_products_delete(products);
1164 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.
void moo_det_delete(moo_det *self)
Delete a moo_det.
moo_mode_type moo_mode_get(const cpl_frame *frame)
Get the name of a mode from a frame.
int moo_offset_get(const cpl_frame *refframe)
Get the offset from a frame.
const char * moo_mode_get_name(moo_mode_type type)
Get the name of a mode.
moo_detlist * moo_detlist_create(cpl_frameset *frameset)
Create a new moo_detlist from the given DET frameset.
void moo_detlist_delete(moo_detlist *self)
Free all memory used by a moo_detlist object including the DET.
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.
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_flx * moo_flx_load(const cpl_frame *frame)
Load a FLX frame and create a moo_flx.
void moo_flx_delete(moo_flx *self)
Delete a moo_flx.
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_delete(moo_map *self)
Delete a moo_map.
void moo_molectable_delete(moo_molectable *self)
Delete a moo_molectable.
moo_coadd_params * moo_params_get_coadd(const moo_params *self, const cpl_parameterlist *list)
Get coadd parameters from moons parameters list.
cpl_error_code moo_params_add_extract(moo_params *self, cpl_parameterlist *list)
Add default parameters for extraction.
cpl_error_code moo_params_add_sub_sky_stare(moo_params *self, cpl_parameterlist *list)
Add default parameters for moo_sub_sky_stare.
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_compute_resp_params * moo_params_get_compute_resp(const moo_params *self, const cpl_parameterlist *list)
Get compute response 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.
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.
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.
void moo_molecfit_model_params_delete(moo_molecfit_model_params *self)
Delete a moo_molecfit_model_params.
cpl_error_code moo_params_add_crh(moo_params *self, cpl_parameterlist *list, const char *method)
Add default parameters for remove crh.
moo_extract_params * moo_params_get_extract(const moo_params *self, const cpl_parameterlist *list)
Get extraction parameters from moons parameters list.
void moo_params_delete(moo_params *self)
Delete a moo_params.
moo_crh_params * moo_params_get_crh(const moo_params *self, const cpl_parameterlist *list)
Get remove crh parameters from moons parameters list.
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_molecfit_model(moo_params *self, cpl_parameterlist *list)
Add default parameters for molecfit_model.
cpl_error_code moo_params_add_compute_resp(moo_params *self, cpl_parameterlist *list)
Add default parameters for compute_resp.
moo_molecfit_model_params * moo_params_get_molecfit_model(const moo_params *self, const cpl_parameterlist *list)
Get molecfit model parameters from moons parameters list.
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.
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.
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_clean(cpl_frameset *frameset)
Create a new moo_scilist from the given SCI frameset ignoring SCI with 0 targets.
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.
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_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
cpl_error_code moo_correct_tell(moo_rbn *rbn, moo_telluric *tell)
Apply the telluric correction to 1D rebinned spectra.
moo_resp * moo_compute_resp(moo_scilist *scilist, moo_atm *atm, moo_flx *flx, moo_compute_resp_params *params)
Compute instrumental response.
cpl_error_code moo_apply_p2p(moo_det *flat, moo_det *p2pmap)
Divide DET by the pixel-to-pixel variation map.
moo_molectable * moo_molecfit_model(const cpl_frame *sci_frame, const char *modename, const cpl_frame *molecule_frame, const cpl_frame *winc_frame, moo_molectable **pmt_atm_fitted, moo_molectable **best_fitted_model, moo_molecfit_model_params *params)
Apply the relative flux calibration to 1D rebinned spectra.
moo_rbn * moo_rebin(moo_ext *ext, moo_map *wmap, moo_spectral_format *sformat, moo_rebin_params *params, const char *filename)
Rebin an EXT spectra in RBN format.
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...
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_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)....
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_molectable(moo_products *self, moo_molectable *mtable, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a MOLECTABLE object
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_resp(moo_products *self, moo_resp *resp, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a RESP object
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