30#include "moo_extlist.h"
31#include "moo_params.h"
33#include "moo_products.h"
43int cpl_plugin_get_info(cpl_pluginlist *list);
49static int _moons_quicklook_create(cpl_plugin *plugin);
50static int _moons_quicklook_exec(cpl_plugin *plugin);
51static int _moons_quicklook_destroy(cpl_plugin *plugin);
53_moons_quicklook(cpl_frameset *frameset,
const cpl_parameterlist *parlist);
59static const char *
const _moons_quicklook_description =
60 "quickly produce reduced spectra for a subset of the observed objects and "
61 "assess the quality of the data\n"
63 " * science exposure frame 1 file (RAW) with tag OBJECT_STARE "
65 "science frame in stare mode file\n"
66 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag BP_MAP_RP : "
67 "cosmetic bad pixel map\n"
68 " * [OPTIONAL] NonLinearityBadPixMask 1 file (QUA) with tag BP_MAP_NL : "
69 "cosmetic bad pixel map coming from linearity recipe\n"
70 " * MasterBias 1 file (DET) with tag MASTER_BIAS : "
72 " * MasterDarkNir 1 file (DET) with tag "
74 "master dark nir file\n"
75 " * [OPTIONAL]MasterDarkVis 1 file (DET) with tag "
77 "master dark vis file\n"
78 " * [OPTIONAL] CoeffsCube 1 file (3D) with tag "
79 "LINEARITY_COEFF_CUBE : "
80 "coefficients to correct pixels detector linearity\n"
81 " * [OPTIONAL] P2pMap 1 file (DET) with tag P2P_MAP : "
82 "pixel to pixel map\n"
83 " * LocTab 1 file (LOC) with tag FF_TRACE : "
84 "the localisation table\n"
85 " * Ffext 1 file (EXT) with tag FF_EXTSPECTRA "
87 "the extracted flat field\n"
88 " * F2f 1 file (F2F) with tag F2F_TABLE : "
89 "the fibre-to-fibre relative response\n"
90 " * SFormat 1 file (FMT) with tag "
92 "the spectral format table\n"
93 " * WaveMap 1 file (WMAP) with tag WAVE_MAP : "
94 "the wavelength map\n"
95 " * SkyLines 1 file (CAT) with tag SKY_LINE_LIST "
97 "the sky lines list table\n"
99 " * QUICKLOOK_SCI.fits (SCI) with tag SCIENCE_QUICKLOOK_SKSSPECTRA : "
100 "Science product coadd calibrated frame\n"
120cpl_plugin_get_info(cpl_pluginlist *list)
122 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
123 cpl_plugin *plugin = &recipe->interface;
125 if (cpl_plugin_init(plugin, CPL_PLUGIN_API, MOONS_BINARY_VERSION,
126 CPL_PLUGIN_TYPE_RECIPE,
"moons_quicklook",
127 "quickly produce reduced spectra for a subset of the "
128 "observed objects and assess the quality of the data",
129 _moons_quicklook_description,
"Regis Haigron",
131 _moons_quicklook_create, _moons_quicklook_exec,
132 _moons_quicklook_destroy)) {
133 cpl_msg_error(cpl_func,
"Plugin initialization failed");
134 (void)cpl_error_set_where(cpl_func);
138 if (cpl_pluginlist_append(list, plugin)) {
139 cpl_msg_error(cpl_func,
"Error adding plugin to list");
140 (void)cpl_error_set_where(cpl_func);
158_moons_quicklook_create(cpl_plugin *plugin)
163 if (cpl_error_get_code() != CPL_ERROR_NONE) {
164 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
165 cpl_func, __LINE__, cpl_error_get_where());
166 return (
int)cpl_error_get_code();
169 if (plugin == NULL) {
170 cpl_msg_error(cpl_func,
"Null plugin");
171 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
175 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
176 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
177 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
181 recipe = (cpl_recipe *)plugin;
184 recipe->parameters = cpl_parameterlist_new();
185 if (recipe->parameters == NULL) {
186 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
187 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
197 MOO_CORRECT_BIAS_METHOD_MASTER);
214_moons_quicklook_exec(cpl_plugin *plugin)
218 cpl_errorstate initial_errorstate = cpl_errorstate_get();
221 if (cpl_error_get_code() != CPL_ERROR_NONE) {
222 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
223 cpl_func, __LINE__, cpl_error_get_where());
224 return (
int)cpl_error_get_code();
227 if (plugin == NULL) {
228 cpl_msg_error(cpl_func,
"Null plugin");
229 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
233 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
234 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
235 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
239 recipe = (cpl_recipe *)plugin;
242 if (recipe->parameters == NULL) {
243 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
244 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
246 if (recipe->frames == NULL) {
247 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
248 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
252 recipe_status = _moons_quicklook(recipe->frames, recipe->parameters);
255 if (cpl_dfs_update_product_header(recipe->frames)) {
257 recipe_status = (int)cpl_error_get_code();
260 if (!cpl_errorstate_is_equal(initial_errorstate)) {
263 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
266 return recipe_status;
278_moons_quicklook_destroy(cpl_plugin *plugin)
282 if (plugin == NULL) {
283 cpl_msg_error(cpl_func,
"Null plugin");
284 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
288 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
289 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
290 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
294 recipe = (cpl_recipe *)plugin;
296 cpl_parameterlist_delete(recipe->parameters);
302_moons_select_quicklook_targets(moo_det *det,
304 const cpl_frame *f2f_frame,
305 moo_sub_sky_stare_params *params,
306 cpl_array *index_list)
309 cpl_array *sel = NULL;
310 cpl_array *sky_sel = NULL;
311 cpl_array *obj_sel = NULL;
312 cpl_table **sky_stare_tables = NULL;
315 cpl_ensure(det != NULL, CPL_ERROR_NULL_INPUT, 0);
316 cpl_ensure(loc != NULL, CPL_ERROR_NULL_INPUT, 0);
317 cpl_ensure(f2f_frame != NULL, CPL_ERROR_NULL_INPUT, 0);
318 cpl_ensure(params != NULL, CPL_ERROR_NULL_INPUT, 0);
324 moo_try_assure(det_fibre_table != NULL, CPL_ERROR_ILLEGAL_INPUT,
" ");
325 moo_try_assure(loc_fibre_table != NULL, CPL_ERROR_ILLEGAL_INPUT,
" ");
332 cpl_table_new_column(det_fibre_table, MOO_TARGET_TABLE_INDEXRBN,
334 int tsize = cpl_table_get_nrow(det_fibre_table);
336 cpl_table_get_data_int(loc_fibre_table, MOO_FIBRES_TABLE_INDEXEXT);
337 for (
int i = 1; i <= tsize; i++) {
338 int indexext = indexextt[i];
340 cpl_table_set_int(det_fibre_table, MOO_TARGET_TABLE_INDEXRBN, i - 1,
344 int index_size = cpl_array_get_size(index_list);
346 if (index_size > 0) {
347 cpl_table_unselect_all(det_fibre_table);
349 cpl_table_or_selected_string(det_fibre_table, MOO_FIBRES_TABLE_TYPE,
351 MOO_FIBRES_TABLE_TYPE_CHECKOBJ);
352 sel = cpl_table_where_selected(det_fibre_table);
353 for (
int i = 0; i < size; i++) {
354 int fidx = cpl_array_get_cplsize(sel, i, NULL);
355 cpl_table_set_string(det_fibre_table, MOO_FIBRES_TABLE_TYPE, fidx,
358 cpl_array_delete(sel);
361 for (
int i = 0; i < index_size; i++) {
362 const char *fibname = cpl_array_get_string(index_list, i);
363 cpl_table_unselect_all(det_fibre_table);
364 size = cpl_table_or_selected_string(det_fibre_table,
365 MOO_FIBRES_TABLE_FIBRE,
366 CPL_EQUAL_TO, fibname);
367 sel = cpl_table_where_selected(det_fibre_table);
368 int fidx = cpl_array_get_cplsize(sel, 0, NULL);
369 cpl_table_set_string(det_fibre_table, MOO_FIBRES_TABLE_TYPE, fidx,
370 MOO_FIBRES_TABLE_TYPE_CHECKOBJ);
371 cpl_array_delete(sel);
376 cpl_table_unselect_all(loc_fibre_table);
378 cpl_table_or_selected_int(loc_fibre_table, MOO_FIBRES_TABLE_HEALTH,
380 sel = cpl_table_where_selected(loc_fibre_table);
382 for (
int i = 0; i < size; i++) {
383 int fidx = cpl_array_get_cplsize(sel, i, NULL);
384 cpl_table_set_int(det_fibre_table, MOO_FIBRES_TABLE_HEALTH, fidx, 0);
386 cpl_array_delete(sel);
389 cpl_table_select_all(det_fibre_table);
390 cpl_table_and_selected_int(det_fibre_table, MOO_FIBRES_TABLE_INDEXRBN,
391 CPL_NOT_EQUAL_TO, 0);
392 cpl_table_and_selected_int(det_fibre_table, MOO_FIBRES_TABLE_HEALTH,
393 CPL_NOT_EQUAL_TO, 0);
395 cpl_table_and_selected_string(det_fibre_table, MOO_FIBRES_TABLE_TYPE,
397 MOO_FIBRES_TABLE_TYPE_CHECKOBJ);
399 if (nb_targets > 0) {
400 size = cpl_table_or_selected_string(det_fibre_table,
401 MOO_FIBRES_TABLE_TYPE, CPL_EQUAL_TO,
402 MOO_FIBRES_TABLE_TYPE_SKY);
403 cpl_table_and_selected_int(det_fibre_table, MOO_FIBRES_TABLE_INDEXRBN,
404 CPL_NOT_EQUAL_TO, 0);
406 size = cpl_table_not_selected(det_fibre_table);
407 sel = cpl_table_where_selected(det_fibre_table);
409 for (
int i = 0; i < size; i++) {
410 int fidx = cpl_array_get_cplsize(sel, i, NULL);
411 int h = cpl_table_get_int(det_fibre_table, MOO_FIBRES_TABLE_HEALTH,
414 cpl_table_set_int(det_fibre_table, MOO_FIBRES_TABLE_HEALTH,
418 cpl_table_select_all(det_fibre_table);
420 cpl_table_and_selected_string(det_fibre_table,
421 MOO_FIBRES_TABLE_TYPE, CPL_EQUAL_TO,
422 MOO_FIBRES_TABLE_TYPE_SKY);
424 cpl_table_and_selected_int(det_fibre_table, MOO_FIBRES_TABLE_HEALTH,
426 sky_size = cpl_table_and_selected_int(det_fibre_table,
427 MOO_FIBRES_TABLE_INDEXRBN,
428 CPL_NOT_EQUAL_TO, 0);
430 sky_sel = cpl_table_where_selected(det_fibre_table);
432 cpl_table_select_all(det_fibre_table);
433 cpl_table_and_selected_string(det_fibre_table, MOO_FIBRES_TABLE_TYPE,
435 MOO_FIBRES_TABLE_TYPE_CHECKOBJ);
437 cpl_table_and_selected_int(det_fibre_table, MOO_FIBRES_TABLE_HEALTH,
438 CPL_NOT_EQUAL_TO, 0);
439 size = cpl_table_and_selected_int(det_fibre_table,
440 MOO_FIBRES_TABLE_INDEXRBN,
441 CPL_NOT_EQUAL_TO, 0);
443 obj_sel = cpl_table_where_selected(det_fibre_table);
447 sky_stare_tables = cpl_calloc(3,
sizeof(cpl_table *));
448 for (
int t = 0; t < 3; t++) {
449 cpl_table *sky_stare_table = cpl_table_new(0);
450 cpl_table_new_column(sky_stare_table, MOO_SKY_STARE_INDEXTARG,
452 cpl_table_new_column(sky_stare_table, MOO_SKY_STARE_TARGNAME,
454 cpl_table_new_column(sky_stare_table, MOO_SKY_STARE_INDEXRBN,
456 cpl_table_new_column(sky_stare_table, MOO_SKY_STARE_SKYINDEXRBN,
458 cpl_table_new_column(sky_stare_table, MOO_SKY_STARE_SKYDSLIT,
460 cpl_table_new_column(sky_stare_table, MOO_SKY_STARE_SKYTRANS,
462 cpl_table_new_column(sky_stare_table, MOO_SKY_STARE_RADIUS,
464 cpl_table_new_column(sky_stare_table, MOO_SKY_STARE_SKYDIST,
466 for (
int i = 0; i < size; i++) {
468 int fidx = cpl_array_get_cplsize(obj_sel, i, NULL);
470 cpl_table_get_string(det_fibre_table,
471 MOO_FIBRES_TABLE_TARGNAME, fidx);
473 cpl_table_get_int(det_fibre_table,
474 MOO_TARGET_TABLE_INDEXRBN, fidx, NULL);
475 double obj_targalpha =
476 cpl_table_get_double(det_fibre_table,
477 MOO_FIBRES_TABLE_TARGALPHA, fidx,
479 double obj_targdelta =
480 cpl_table_get_double(det_fibre_table,
481 MOO_FIBRES_TABLE_TARGDELTA, fidx,
484 cpl_array *sky_indexes =
486 obj_targdelta, det_fibre_table,
487 MOO_TARGET_TABLE_INDEXRBN, sky_stare_table,
488 type, params->maxdistslit, params->min_trans,
489 params->min_sky, params->radius_sky,
490 params->step_r, fidx, f2f, sky_sel);
493 cpl_array_delete(sky_indexes);
495 sky_stare_tables[t] = sky_stare_table;
498 for (
int i = 0; i < sky_size; i++) {
499 int fidx = cpl_array_get_cplsize(sky_sel, i, NULL);
500 cpl_table_set_int(det_fibre_table, MOO_FIBRES_TABLE_HEALTH, fidx,
504 for (
int i = 0; i < 3; i++) {
505 cpl_table *sky_stare_table = sky_stare_tables[i];
506 int nrow = cpl_table_get_nrow(sky_stare_table);
508 for (
int r = 0; r < nrow; r++) {
510 cpl_table_get_int(sky_stare_table,
511 MOO_SKY_STARE_SKYINDEXRBN, r, NULL);
512 cpl_table_select_all(det_fibre_table);
513 cpl_table_and_selected_int(det_fibre_table,
514 MOO_FIBRES_TABLE_INDEXRBN,
515 CPL_EQUAL_TO, indexrbn);
516 cpl_array *detsel = cpl_table_where_selected(det_fibre_table);
517 int fidx = cpl_array_get_cplsize(detsel, 0, NULL);
518 cpl_table_set_int(det_fibre_table, MOO_FIBRES_TABLE_HEALTH,
520 cpl_array_delete(detsel);
522 cpl_table_delete(sky_stare_table);
525 cpl_table_select_all(det_fibre_table);
527 cpl_table_and_selected_int(det_fibre_table, MOO_FIBRES_TABLE_HEALTH,
529 cpl_array_delete(sel);
530 sel = cpl_table_where_selected(det_fibre_table);
531 for (
int i = 0; i < size; i++) {
532 int fidx = cpl_array_get_cplsize(sel, i, NULL);
533 cpl_table_set_int(loc_fibre_table, MOO_FIBRES_TABLE_HEALTH, fidx,
537 cpl_table_erase_column(det_fibre_table, MOO_TARGET_TABLE_INDEXRBN);
540 cpl_free(sky_stare_tables);
541 cpl_array_delete(sky_sel);
542 cpl_array_delete(obj_sel);
543 cpl_array_delete(sel);
549_moons_quicklook_check_sof(cpl_frameset *frameset,
551 const char **bpmap_rp_name,
552 const char **bpmap_nl_name,
553 const cpl_frame **masterbias,
554 const cpl_frame **masterdark_vis,
555 const cpl_frame **masterdark_nir,
556 const cpl_frame **fftrace,
557 const cpl_frame **coeffs_cube,
558 const cpl_frame **wmap,
559 const cpl_frame **skylines,
560 const cpl_frame **flat,
561 const cpl_frame **f2f,
562 const cpl_frame **p2pmap,
563 const cpl_frame **sformat,
564 const cpl_frame **atmo,
565 const cpl_frame **resp)
568 cpl_error_get_code());
572 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
573 cpl_frame *current_frame = cpl_frameset_get_position(frameset, i);
574 if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_OBJECT_STARE)) {
575 *frame = current_frame;
578 else if (!strcmp(cpl_frame_get_tag(current_frame),
579 MOONS_TAG_OBJECT_STARENOD)) {
580 *frame = current_frame;
583 else if (!strcmp(cpl_frame_get_tag(current_frame),
584 MOONS_TAG_OBJECT_XSWITCH)) {
585 *frame = current_frame;
588 else if (!strcmp(cpl_frame_get_tag(current_frame),
589 MOONS_TAG_BP_MAP_RP)) {
590 *bpmap_rp_name = cpl_frame_get_filename(current_frame);
592 else if (!strcmp(cpl_frame_get_tag(current_frame),
593 MOONS_TAG_BP_MAP_NL)) {
594 *bpmap_nl_name = cpl_frame_get_filename(current_frame);
596 else if (!strcmp(cpl_frame_get_tag(current_frame),
597 MOONS_TAG_MASTER_BIAS)) {
598 *masterbias = current_frame;
600 else if (!strcmp(cpl_frame_get_tag(current_frame),
601 MOONS_TAG_MASTER_DARK_VIS)) {
602 *masterdark_vis = current_frame;
604 else if (!strcmp(cpl_frame_get_tag(current_frame),
605 MOONS_TAG_MASTER_DARK_NIR)) {
606 *masterdark_nir = current_frame;
608 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_P2P_MAP)) {
609 *p2pmap = current_frame;
611 else if (!strcmp(cpl_frame_get_tag(current_frame),
612 MOONS_TAG_SPECTRAL_FORMAT)) {
613 *sformat = current_frame;
615 else if (!strcmp(cpl_frame_get_tag(current_frame),
616 MOONS_TAG_ATMOS_EXT)) {
617 *atmo = current_frame;
619 else if (!strcmp(cpl_frame_get_tag(current_frame),
620 MOONS_TAG_RESPONSE)) {
621 *resp = current_frame;
623 else if (!strcmp(cpl_frame_get_tag(current_frame),
624 MOONS_TAG_FF_TRACE)) {
625 *fftrace = current_frame;
627 else if (!strcmp(cpl_frame_get_tag(current_frame),
628 MOONS_TAG_LINEARITY_COEFF_CUBE)) {
629 *coeffs_cube = current_frame;
631 else if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_WAVEMAP)) {
632 *wmap = current_frame;
634 else if (!strcmp(cpl_frame_get_tag(current_frame),
635 MOONS_TAG_SKY_LINE_LIST)) {
636 *skylines = current_frame;
638 else if (!strcmp(cpl_frame_get_tag(current_frame),
639 MOONS_TAG_FF_EXTSPECTRA)) {
640 *flat = current_frame;
642 else if (!strcmp(cpl_frame_get_tag(current_frame),
643 MOONS_TAG_F2F_TABLE)) {
644 *f2f = current_frame;
648 if (*sformat == NULL) {
649 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
650 "SOF does not have any file tagged "
652 MOONS_TAG_SPECTRAL_FORMAT);
655 if (nb_object != 1) {
656 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
657 "SOF does exactly one file tagged "
658 "with %s or %s or %s",
659 MOONS_TAG_OBJECT_STARE,
660 MOONS_TAG_OBJECT_STARENOD,
661 MOONS_TAG_OBJECT_XSWITCH);
664 if (*fftrace == NULL) {
665 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
666 "SOF does not have any file tagged "
672 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
673 "SOF does not have any file tagged "
678 if (*skylines == NULL) {
679 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
680 "SOF does not have any file tagged "
682 MOONS_TAG_SKY_LINE_LIST);
685 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
686 "SOF does not have any file tagged "
688 MOONS_TAG_FF_EXTSPECTRA);
690 return CPL_ERROR_NONE;
694_moons_p2pmap(moo_det *arc,
const cpl_frame *p2pmap)
696 cpl_error_code status = CPL_ERROR_NONE;
699 if (p2pmap != NULL) {
700 cpl_msg_info(
"test",
"apply_p2P");
710_moons_apply_flat(moo_ext *ext,
711 const cpl_frame *flat_frame,
712 const cpl_frame *f2f_frame)
714 cpl_error_code status = CPL_ERROR_NONE;
715 moo_ext *flat = NULL;
719 if (f2f_frame != NULL) {
731_moons_sub_sky_stare(moo_rbn *rbn,
733 const cpl_frame *f2f_frame,
734 const cpl_frame *solflux_frame,
735 const cpl_frame *airglow_group_frame,
736 const cpl_frame *airglow_var_frame,
737 moo_sub_sky_stare_params *sky_params,
738 const char *sci_filename)
740 moo_sci *result = NULL;
743 if (f2f_frame != NULL) {
746 moo_try_check(result =
748 solflux_frame, airglow_group_frame,
749 airglow_var_frame, sky_params,
750 sci_filename, MOO_SCI1D_NOT_PAIRED),
759_moons_quicklook_notarget_sci(moo_det *det,
const char *filename)
764 res->filename = filename;
765 res->primary_header = cpl_propertylist_duplicate(det->primary_header);
768 res->target_table = ttable;
782_moons_quicklook(cpl_frameset *frameset,
const cpl_parameterlist *parlist)
785 moo_prepare_params *prepare_params = NULL;
786 moo_correct_bias_params *correct_bias_params = NULL;
787 moo_extract_params *extract_params = NULL;
788 moo_rebin_params *rbn_params = NULL;
789 moo_target_table_params *target_table_params = NULL;
790 moo_sub_sky_stare_params *sky_params = NULL;
791 cpl_array *index_list = NULL;
793 moo_spectral_format *sformat = NULL;
794 moo_map *wmap = NULL;
795 moo_sky_lines_list *skylines = NULL;
803 moo_resp *resp = NULL;
805 cpl_frame *frame = NULL;
807 const char *bpmap_rp_name = NULL;
808 const char *bpmap_nl_name = NULL;
809 const cpl_frame *masterbias = NULL;
810 const cpl_frame *masterdark_vis = NULL;
811 const cpl_frame *masterdark_nir = NULL;
812 const cpl_frame *p2pmap = NULL;
813 const cpl_frame *sformat_frame = NULL;
814 const cpl_frame *atmo_frame = NULL;
815 const cpl_frame *resp_frame = NULL;
816 const cpl_frame *fftrace = NULL;
817 const cpl_frame *coeffs_cube = NULL;
818 const cpl_frame *wmap_frame = NULL;
819 const cpl_frame *skylines_frame = NULL;
820 const cpl_frame *flat_frame = NULL;
821 const cpl_frame *f2f_frame = NULL;
822 const char *ref_filename = NULL;
823 cpl_propertylist *ref_header = NULL;
826 const char *mode_name = NULL;
829 char *extname = NULL;
830 char *rbnname = NULL;
831 char *sciname = NULL;
833 cpl_errorstate prestate = cpl_errorstate_get();
835 moo_products *products =
837 PACKAGE
"/" PACKAGE_VERSION);
842 moo_try_check(correct_bias_params =
845 extract_params = moo_extract_params_new();
846 extract_params->method = MOO_EXTRACT_METHOD_SUM;
848 target_table_params = moo_target_table_params_new();
849 target_table_params->nosky = CPL_TRUE;
850 moo_try_check(sky_params =
853 moo_try_check(index_list =
856 moo_try_check(_moons_quicklook_check_sof(frameset, &frame, &bpmap_rp_name,
857 &bpmap_nl_name, &masterbias,
858 &masterdark_vis, &masterdark_nir,
859 &fftrace, &coeffs_cube,
860 &wmap_frame, &skylines_frame,
861 &flat_frame, &f2f_frame, &p2pmap,
862 &sformat_frame, &atmo_frame,
866 ref_filename = cpl_frame_get_filename(frame);
869 moo_try_check(ref_header = cpl_propertylist_load(ref_filename, 0),
" ");
871 cpl_propertylist_delete(ref_header);
873 cpl_msg_info(__func__,
"Do offset %d Use mode %s", offset, mode_name);
876 moo_try_check(wmap = moo_map_load(wmap_frame),
" ");
879 moo_try_check(det =
moo_prepare(frame, bpmap_rp_name, bpmap_nl_name,
880 masterbias, NULL, prepare_params),
883 MOONS_TAG_QUICKLOOK_PREPARE, NULL, frame),
886 moo_try_check(nb_targets =
887 _moons_select_quicklook_targets(det, loc, f2f_frame,
888 sky_params, index_list),
891 if (nb_targets == 0) {
892 cpl_msg_info(
"test",
"No target");
893 sci = _moons_quicklook_notarget_sci(det,
"QLOOK_SCI.fits");
902 CPL_FRAME_LEVEL_INTERMEDIATE,
903 MOONS_TAG_QUICKLOOK_CORRECTDARK, NULL,
907 moo_try_check(_moons_p2pmap(det, p2pmap),
" ");
910 CPL_FRAME_LEVEL_INTERMEDIATE,
911 MOONS_TAG_QUICKLOOK_APPLYP2P, NULL,
915 cpl_sprintf(
"%s.fits", MOONS_TAG_SCIENCE_QUICKLOOK_EXTSPECTRA);
917 moo_extract(det, loc, NULL, extract_params, extname),
920 products, ext, CPL_FRAME_LEVEL_INTERMEDIATE,
921 MOONS_TAG_SCIENCE_QUICKLOOK_EXTSPECTRA, NULL, frame),
924 moo_try_check(_moons_apply_flat(ext, flat_frame, f2f_frame),
" ");
929 MOONS_TAG_SCIENCE_QUICKLOOK_FFEXTSPECTRA, NULL,
933 cpl_sprintf(
"%s.fits", MOONS_TAG_SCIENCE_QUICKLOOK_RBNSPECTRA);
934 moo_try_check(rbn =
moo_rebin(ext, wmap, sformat, rbn_params, rbnname),
938 products, rbn, CPL_FRAME_LEVEL_INTERMEDIATE,
939 MOONS_TAG_SCIENCE_QUICKLOOK_RBNSPECTRA, NULL, frame),
942 moo_try_check(target_table =
944 target_table_params),
948 products, target_table, CPL_FRAME_LEVEL_INTERMEDIATE,
949 MOONS_TAG_SCIENCE_QUICKLOOK_TARGET_TABLE, NULL,
954 cpl_sprintf(
"%s.fits", MOONS_TAG_SCIENCE_QUICKLOOK_SKSSPECTRA);
955 moo_try_check(sci = _moons_sub_sky_stare(rbn, target_table, f2f_frame,
956 NULL, NULL, NULL, sky_params,
962 MOONS_TAG_SCIENCE_QUICKLOOK_SKSSPECTRA,
966 if (!cpl_errorstate_is_equal(prestate)) {
967 cpl_propertylist_delete(ref_header);
982 moo_target_table_params_delete(target_table_params);
983 moo_rebin_params_delete(rbn_params);
984 moo_sub_sky_stare_params_delete(sky_params);
985 moo_extract_params_delete(extract_params);
986 moo_correct_bias_params_delete(correct_bias_params);
987 moo_prepare_params_delete(prepare_params);
988 cpl_array_delete(index_list);
989 moo_products_delete(products);
993 return (
int)cpl_error_get_code();
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_table * moo_det_get_fibre_table(moo_det *self)
Get the FIBRE TABLE in DET.
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.
enum _moo_detector_type_ moo_detector_type
The type code type.
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.
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.
cpl_error_code moo_f2f_order_by_index(moo_f2f *self)
Order F2F by SPECTRO,INDEX (ASC)
cpl_error_code moo_fibres_table_by_index(cpl_table *table)
Order fibres table by INDEX (ASC)
moo_loc * moo_loc_load(const cpl_frame *locframe)
Load a LOC frame and create a moo_loc.
cpl_table * moo_loc_get_fibre_table(moo_loc *self)
Get the FIBRE TABLE in LOC.
void moo_loc_delete(moo_loc *self)
Delete a moo_loc.
void moo_map_delete(moo_map *self)
Delete a moo_map.
cpl_array * moo_params_get_quicklook_fibre_list(const moo_params *self, const cpl_parameterlist *list)
Get quicklook_fibre_list parameter 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.
cpl_error_code moo_params_add_sub_sky_stare_simple(moo_params *self, cpl_parameterlist *list)
Add default parameters for moo_sub_sky_stare.
moo_sub_sky_stare_params * moo_params_get_sub_sky_stare_simple(const moo_params *self, const cpl_parameterlist *list)
Get sub sky stare simple parameters from moons parameters list.
cpl_error_code moo_params_add_quicklook_fibre_list(moo_params *self, cpl_parameterlist *list)
Add default parameters for quicklook.
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_params_delete(moo_params *self)
Delete a moo_params.
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.
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_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.
moo_sci * moo_sci_new(void)
Create a new moo_sci.
void moo_sci_save(moo_sci *self, const char *filename)
Save a moo_sci to a FITS file.
cpl_error_code moo_sci_compute_snr(moo_sci *self, moo_sky_lines_list *skylines)
Compute SNR for all targets in SCI.
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.
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_array * moo_select_sky(const char *targname, int indextarg, int obj_index, double obj_targalpha, double obj_targdelta, cpl_table *target_table, const char *index_colname, cpl_table *sky_stare_table, moo_detector_type type, int maxdistslit, double mintrans, int min_sky, double radius, double step_r, int target_table_idx, moo_f2f *f2f, cpl_array *allsky_indexes)
This function selects sky fibres around a target object.
cpl_error_code moo_apply_p2p(moo_det *flat, moo_det *p2pmap)
Divide DET by the pixel-to-pixel variation map.
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)....
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