MOONS Pipeline Reference Manual 0.13.2
moo_fibres_table.c
1/*
2 * This file is part of the MOONS Pipeline
3 * Copyright (C) 2002-2016 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27#include <math.h>
28#include <cpl.h>
29#include <string.h>
30#include "moo_pfits.h"
31#include "moo_fits.h"
32#include "moo_utils.h"
33#include "moo_fibres_table.h"
34/*----------------------------------------------------------------------------*/
48/*----------------------------------------------------------------------------*/
49
52/*-----------------------------------------------------------------------------
53 Function codes
54 -----------------------------------------------------------------------------*/
55
56int
57moo_fibres_table_get_spectro(int num)
58{
59 if (num == 1) {
60 return MOO_FIBRES_TABLE_SPECTRO_1;
61 }
62 else {
63 return MOO_FIBRES_TABLE_SPECTRO_2;
64 }
65}
66/*----------------------------------------------------------------------------*/
74/*----------------------------------------------------------------------------*/
75
76cpl_array *
77moo_fibres_table_get_spectro_index(cpl_table *table, int num)
78{
79 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, NULL);
80
81 cpl_propertylist *slitorder = cpl_propertylist_new();
82 cpl_propertylist_append_bool(slitorder, MOO_FIBRES_TABLE_SPECTRO,
83 CPL_FALSE);
84 cpl_propertylist_append_bool(slitorder, MOO_FIBRES_TABLE_INDEX, CPL_FALSE);
85 cpl_table_sort(table, slitorder);
86 cpl_propertylist_delete(slitorder);
87
88 const int spectro_name = moo_fibres_table_get_spectro(num);
89 cpl_table_unselect_all(table);
90 cpl_table_or_selected_int(table, MOO_FIBRES_TABLE_SPECTRO, CPL_EQUAL_TO,
91 spectro_name);
92
93 cpl_array *res = cpl_table_where_selected(table);
94
95 return res;
96}
97
98/*----------------------------------------------------------------------------*/
106/*----------------------------------------------------------------------------*/
107
108cpl_array *
110{
111 cpl_array *res = NULL;
112 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, NULL);
113 cpl_errorstate prestate = cpl_errorstate_get();
114
115 const int spectro_name = moo_fibres_table_get_spectro(num);
116
117 cpl_propertylist *slitorder = NULL;
118
119 slitorder = cpl_propertylist_new();
120 cpl_propertylist_append_bool(slitorder, MOO_FIBRES_TABLE_SPECTRO,
121 CPL_FALSE);
122
123 moo_try_check(cpl_propertylist_append_bool(slitorder,
124 MOO_FIBRES_TABLE_INDEXEXT,
125 CPL_FALSE),
126 " ");
127 moo_try_check(cpl_table_sort(table, slitorder), " ");
128
129 moo_try_check(cpl_table_unselect_all(table), " ");
130 moo_try_check(cpl_table_or_selected_int(table, MOO_FIBRES_TABLE_SPECTRO,
131 CPL_EQUAL_TO, spectro_name),
132 " ");
133
134 moo_try_check(res = cpl_table_where_selected(table), " ");
135
136moo_try_cleanup:
137 if (!cpl_errorstate_is_equal(prestate)) {
138 cpl_array_delete(res);
139 res = NULL;
140 }
141 cpl_propertylist_delete(slitorder);
142 return res;
143}
144
145/*----------------------------------------------------------------------------*/
153/*----------------------------------------------------------------------------*/
154
155cpl_table *
156moo_fibres_table_get_spectro_table(cpl_table *table, int num)
157{
158 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, NULL);
159 const int spectro_name = moo_fibres_table_get_spectro(num);
160 cpl_table_unselect_all(table);
161 cpl_table_or_selected_int(table, MOO_FIBRES_TABLE_SPECTRO, CPL_EQUAL_TO,
162 spectro_name);
163 cpl_table *selected = cpl_table_extract_selected(table);
164
165 return selected;
166}
167
168/*----------------------------------------------------------------------------*/
176/*----------------------------------------------------------------------------*/
177int
178moo_fibres_table_get_spectro_nrow(cpl_table *table, int num)
179{
180 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, -1);
181 const int spectro_name = moo_fibres_table_get_spectro(num);
182 cpl_table_unselect_all(table);
183 return cpl_table_or_selected_int(table, MOO_FIBRES_TABLE_SPECTRO,
184 CPL_EQUAL_TO, spectro_name);
185}
186
187/*----------------------------------------------------------------------------*/
198/*----------------------------------------------------------------------------*/
199cpl_error_code
201{
202 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
203
204 cpl_error_code status = CPL_ERROR_NONE;
205
206 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_GOODPTSFRAC_RI,
207 CPL_TYPE_FLOAT);
208 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_GOODPTSFRAC_YJ,
209 CPL_TYPE_FLOAT);
210 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_GOODPTSFRAC_H,
211 CPL_TYPE_FLOAT);
212 int nrow = cpl_table_get_nrow(table);
213 for (int i = 0; i < nrow; i++) {
214 cpl_table_set_float(table, MOO_FIBRES_TABLE_GOODPTSFRAC_RI, i, 0.0);
215 cpl_table_set_float(table, MOO_FIBRES_TABLE_GOODPTSFRAC_YJ, i, 0.0);
216 cpl_table_set_float(table, MOO_FIBRES_TABLE_GOODPTSFRAC_H, i, 0.0);
217 }
218 return status;
219}
220
221/*----------------------------------------------------------------------------*/
232/*----------------------------------------------------------------------------*/
233cpl_error_code
235{
236 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
237
238 cpl_error_code status = CPL_ERROR_NONE;
239
240 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MEDSNR_RI_EXT,
241 CPL_TYPE_FLOAT);
242 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MEDSNR_YJ_EXT,
243 CPL_TYPE_FLOAT);
244 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MEDSNR_H_EXT,
245 CPL_TYPE_FLOAT);
246 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_DERSNR_RI_EXT,
247 CPL_TYPE_FLOAT);
248 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_DERSNR_YJ_EXT,
249 CPL_TYPE_FLOAT);
250 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_DERSNR_H_EXT,
251 CPL_TYPE_FLOAT);
252 status =
253 cpl_table_new_column(table, MOO_FIBRES_TABLE_INDEXEXT, CPL_TYPE_INT);
254 int nrow = cpl_table_get_nrow(table);
255 for (int i = 0; i < nrow; i++) {
256 cpl_table_set_int(table, MOO_FIBRES_TABLE_INDEXEXT, i, -1);
257 }
258 return status;
259}
260
261/*----------------------------------------------------------------------------*/
272/*----------------------------------------------------------------------------*/
273cpl_error_code
275{
276 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
277
278 cpl_error_code status = CPL_ERROR_NONE;
279
280 status =
281 cpl_table_new_column(table, MOO_FIBRES_TABLE_TRANS_RI, CPL_TYPE_FLOAT);
282 status =
283 cpl_table_new_column(table, MOO_FIBRES_TABLE_TRANS_YJ, CPL_TYPE_FLOAT);
284 status =
285 cpl_table_new_column(table, MOO_FIBRES_TABLE_TRANS_H, CPL_TYPE_FLOAT);
286
287 return status;
288}
289/*----------------------------------------------------------------------------*/
300/*----------------------------------------------------------------------------*/
301cpl_error_code
303{
304 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
305
306 cpl_error_code status = CPL_ERROR_NONE;
307
308 status =
309 cpl_table_new_column(table, MOO_FIBRES_TABLE_INDEXRBN, CPL_TYPE_INT);
310 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MEDSNR_RI_RBN,
311 CPL_TYPE_FLOAT);
312 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MEDSNR_YJ_RBN,
313 CPL_TYPE_FLOAT);
314 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MEDSNR_H_RBN,
315 CPL_TYPE_FLOAT);
316 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MONOTONOUS_RI,
317 CPL_TYPE_INT);
318 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MONOTONOUS_YJ,
319 CPL_TYPE_INT);
320 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MONOTONOUS_H,
321 CPL_TYPE_INT);
322 int nrow = cpl_table_get_nrow(table);
323
324 for (int i = 0; i < nrow; i++) {
325 cpl_table_set_int(table, MOO_FIBRES_TABLE_INDEXRBN, i, 0);
326 cpl_table_set_int(table, MOO_FIBRES_TABLE_MONOTONOUS_RI, i, 1);
327 cpl_table_set_int(table, MOO_FIBRES_TABLE_MONOTONOUS_YJ, i, 1);
328 cpl_table_set_int(table, MOO_FIBRES_TABLE_MONOTONOUS_H, i, 1);
329 }
330 return status;
331}
332
333/*----------------------------------------------------------------------------*/
344/*----------------------------------------------------------------------------*/
345cpl_error_code
347{
348 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
349
350 cpl_error_code status = CPL_ERROR_NONE;
351
352 status =
353 cpl_table_new_column(table, MOO_FIBRES_TABLE_TYPE_NOD, CPL_TYPE_STRING);
354 int nrow = cpl_table_get_nrow(table);
355
356 for (int i = 0; i < nrow; i++) {
357 cpl_table_set_string(table, MOO_FIBRES_TABLE_TYPE_NOD, i, "");
358 }
359 return status;
360}
361
362/*----------------------------------------------------------------------------*/
373/*----------------------------------------------------------------------------*/
374cpl_error_code
376{
377 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
378
379 cpl_error_code status = CPL_ERROR_NONE;
380
381 status = cpl_table_erase_column(table, MOO_FIBRES_TABLE_MEDSNR_RI_EXT);
382 status = cpl_table_erase_column(table, MOO_FIBRES_TABLE_MEDSNR_YJ_EXT);
383 status = cpl_table_erase_column(table, MOO_FIBRES_TABLE_MEDSNR_H_EXT);
384 return status;
385}
386
387/*----------------------------------------------------------------------------*/
400/*----------------------------------------------------------------------------*/
401cpl_error_code
403 cpl_table *guess,
404 const char *model)
405{
406 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
407 cpl_ensure_code(guess != NULL, CPL_ERROR_NULL_INPUT);
408 int nrow = cpl_table_get_nrow(table);
409 int guess_nrow = cpl_table_get_nrow(guess);
410 cpl_ensure_code(guess_nrow == nrow, CPL_ERROR_ILLEGAL_INPUT);
411 cpl_error_code status = CPL_ERROR_NONE;
412 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MATCHLINE_RI,
413 CPL_TYPE_INT);
414 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MODELLINE_RI,
415 CPL_TYPE_INT);
416 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_DETECTLINE_RI,
417 CPL_TYPE_INT);
418 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_FAILEDFIT_RI,
419 CPL_TYPE_INT);
420 status =
421 cpl_table_new_column(table, MOO_FIBRES_TABLE_FITLINE_RI, CPL_TYPE_INT);
422 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_REJECTLINE_RI,
423 CPL_TYPE_INT);
424 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_XDIFF_MEDIAN_RI,
425 CPL_TYPE_DOUBLE);
426
427 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MATCHLINE_YJ,
428 CPL_TYPE_INT);
429 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MODELLINE_YJ,
430 CPL_TYPE_INT);
431 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_DETECTLINE_YJ,
432 CPL_TYPE_INT);
433 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_FAILEDFIT_YJ,
434 CPL_TYPE_INT);
435 status =
436 cpl_table_new_column(table, MOO_FIBRES_TABLE_FITLINE_YJ, CPL_TYPE_INT);
437 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_REJECTLINE_YJ,
438 CPL_TYPE_INT);
439 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_XDIFF_MEDIAN_YJ,
440 CPL_TYPE_DOUBLE);
441
442 status =
443 cpl_table_new_column(table, MOO_FIBRES_TABLE_MATCHLINE_H, CPL_TYPE_INT);
444 status =
445 cpl_table_new_column(table, MOO_FIBRES_TABLE_MODELLINE_H, CPL_TYPE_INT);
446 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_DETECTLINE_H,
447 CPL_TYPE_INT);
448 status =
449 cpl_table_new_column(table, MOO_FIBRES_TABLE_FAILEDFIT_H, CPL_TYPE_INT);
450 status =
451 cpl_table_new_column(table, MOO_FIBRES_TABLE_FITLINE_H, CPL_TYPE_INT);
452 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_REJECTLINE_H,
453 CPL_TYPE_INT);
454 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_XDIFF_MEDIAN_H,
455 CPL_TYPE_DOUBLE);
456
457 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MONOTONOUS_RI,
458 CPL_TYPE_INT);
459 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MONOTONOUS_YJ,
460 CPL_TYPE_INT);
461 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MONOTONOUS_H,
462 CPL_TYPE_INT);
463 if (model != NULL) {
464 const char **names =
465 cpl_table_get_data_string_const(table, MOO_FIBRES_TABLE_FIBRE);
466 const char **guess_names =
467 cpl_table_get_data_string_const(guess, MOO_FIBRES_TABLE_FIBRE);
468
469 for (int i = 0; i < nrow; i++) {
470 const char *ext_name = names[i];
471 cpl_table_set_int(table, MOO_FIBRES_TABLE_MONOTONOUS_RI, i, -1);
472 cpl_table_set_int(table, MOO_FIBRES_TABLE_MONOTONOUS_YJ, i, -1);
473 cpl_table_set_int(table, MOO_FIBRES_TABLE_MONOTONOUS_H, i, -1);
474 for (int j = 0; j < guess_nrow; j++) {
475 const char *guess_name = guess_names[j];
476 if (strcmp(ext_name, guess_name) == 0) {
477 for (int k = 0; k < 3; k++) {
478 int nmatched = 0;
479 int nrej = 0;
480 moo_try_check(nmatched =
482 k, j),
483 " ");
484 moo_try_check(nrej =
486 k, j),
487 " ");
488 moo_fibres_table_set_matchline(table, k, i, nmatched);
490 nmatched - nrej);
491 }
492 break;
493 }
494 }
495 }
496 }
497moo_try_cleanup:
498 return status;
499}
500
501/*----------------------------------------------------------------------------*/
512/*----------------------------------------------------------------------------*/
513cpl_error_code
515{
516 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
517
518 cpl_error_code status = CPL_ERROR_NONE;
519
520 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_DETECTLINE_RI,
521 CPL_TYPE_INT);
522 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_FAILEDFIT_RI,
523 CPL_TYPE_INT);
524 status =
525 cpl_table_new_column(table, MOO_FIBRES_TABLE_FITLINE_RI, CPL_TYPE_INT);
526 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MATCHLINE_RI,
527 CPL_TYPE_INT);
528 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_REJECTLINE_RI,
529 CPL_TYPE_INT);
530
531 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_DETECTLINE_YJ,
532 CPL_TYPE_INT);
533 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_FAILEDFIT_YJ,
534 CPL_TYPE_INT);
535 status =
536 cpl_table_new_column(table, MOO_FIBRES_TABLE_FITLINE_YJ, CPL_TYPE_INT);
537 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MATCHLINE_YJ,
538 CPL_TYPE_INT);
539 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_REJECTLINE_YJ,
540 CPL_TYPE_INT);
541
542 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_DETECTLINE_H,
543 CPL_TYPE_INT);
544 status =
545 cpl_table_new_column(table, MOO_FIBRES_TABLE_FAILEDFIT_H, CPL_TYPE_INT);
546 status =
547 cpl_table_new_column(table, MOO_FIBRES_TABLE_FITLINE_H, CPL_TYPE_INT);
548 status =
549 cpl_table_new_column(table, MOO_FIBRES_TABLE_MATCHLINE_H, CPL_TYPE_INT);
550 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_REJECTLINE_H,
551 CPL_TYPE_INT);
552 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MONOTONOUS_RI,
553 CPL_TYPE_INT);
554 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MONOTONOUS_YJ,
555 CPL_TYPE_INT);
556 status = cpl_table_new_column(table, MOO_FIBRES_TABLE_MONOTONOUS_H,
557 CPL_TYPE_INT);
558
559 return status;
560}
561
562/*----------------------------------------------------------------------------*/
570/*----------------------------------------------------------------------------*/
571float *
573{
574 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, NULL);
575
576 const char *res[] = { MOO_FIBRES_TABLE_MEDSNR_RI_EXT,
577 MOO_FIBRES_TABLE_MEDSNR_YJ_EXT,
578 MOO_FIBRES_TABLE_MEDSNR_H_EXT };
579
580 return cpl_table_get_data_float(table, res[type]);
581}
582
583/*----------------------------------------------------------------------------*/
593/*----------------------------------------------------------------------------*/
594cpl_error_code
597 cpl_size row,
598 int value)
599{
600 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
601
602 const char *res[] = { MOO_FIBRES_TABLE_DETECTLINE_RI,
603 MOO_FIBRES_TABLE_DETECTLINE_YJ,
604 MOO_FIBRES_TABLE_DETECTLINE_H };
605
606 cpl_error_code status = CPL_ERROR_NONE;
607 int *data = cpl_table_get_data_int(table, res[type]);
608 data[row] = value;
609 return status;
610}
611
612/*----------------------------------------------------------------------------*/
622/*----------------------------------------------------------------------------*/
623cpl_error_code
626 cpl_size row,
627 int value)
628{
629 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
630
631 const char *res[] = { MOO_FIBRES_TABLE_FAILEDFIT_RI,
632 MOO_FIBRES_TABLE_FAILEDFIT_YJ,
633 MOO_FIBRES_TABLE_FAILEDFIT_H };
634 cpl_error_code status = CPL_ERROR_NONE;
635 int *data = cpl_table_get_data_int(table, res[type]);
636 data[row] = value;
637 return status;
638}
639
640/*----------------------------------------------------------------------------*/
650/*----------------------------------------------------------------------------*/
651cpl_error_code
654 cpl_size row,
655 int value)
656{
657 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
658
659 const char *res[] = { MOO_FIBRES_TABLE_FITLINE_RI,
660 MOO_FIBRES_TABLE_FITLINE_YJ,
661 MOO_FIBRES_TABLE_FITLINE_H };
662
663 cpl_error_code status = CPL_ERROR_NONE;
664 int *data = cpl_table_get_data_int(table, res[type]);
665 data[row] = value;
666 return status;
667}
668
669/*----------------------------------------------------------------------------*/
679/*----------------------------------------------------------------------------*/
680cpl_error_code
683 cpl_size row,
684 int value)
685{
686 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
687
688 const char *res[] = { MOO_FIBRES_TABLE_MATCHLINE_RI,
689 MOO_FIBRES_TABLE_MATCHLINE_YJ,
690 MOO_FIBRES_TABLE_MATCHLINE_H };
691 cpl_error_code status = CPL_ERROR_NONE;
692 status = cpl_table_set_int(table, res[type], row, value);
693 return status;
694}
695
696/*----------------------------------------------------------------------------*/
706/*----------------------------------------------------------------------------*/
707cpl_error_code
710 cpl_size row,
711 int value)
712{
713 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
714
715 const char *res[] = { MOO_FIBRES_TABLE_MODELLINE_RI,
716 MOO_FIBRES_TABLE_MODELLINE_YJ,
717 MOO_FIBRES_TABLE_MODELLINE_H };
718
719 return cpl_table_set_int(table, res[type], row, value);
720}
721
722/*----------------------------------------------------------------------------*/
732/*----------------------------------------------------------------------------*/
733cpl_error_code
736 cpl_size row,
737 int value)
738{
739 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
740
741 const char *res[] = { MOO_FIBRES_TABLE_REJECTLINE_RI,
742 MOO_FIBRES_TABLE_REJECTLINE_YJ,
743 MOO_FIBRES_TABLE_REJECTLINE_H };
744
745 cpl_error_code status = CPL_ERROR_NONE;
746 status = cpl_table_set_int(table, res[type], row, value);
747 return status;
748}
749
750/*----------------------------------------------------------------------------*/
760/*----------------------------------------------------------------------------*/
761cpl_error_code
764 cpl_size row,
765 double value)
766{
767 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
768
769 const char *res[] = { MOO_FIBRES_TABLE_XDIFF_MEDIAN_RI,
770 MOO_FIBRES_TABLE_XDIFF_MEDIAN_YJ,
771 MOO_FIBRES_TABLE_XDIFF_MEDIAN_H };
772
773 return cpl_table_set_double(table, res[type], row, value);
774}
775
776/*----------------------------------------------------------------------------*/
785/*----------------------------------------------------------------------------*/
786int
789 cpl_size row)
790{
791 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, 0);
792 int rej;
793
794 const char *res[] = { MOO_FIBRES_TABLE_MATCHLINE_RI,
795 MOO_FIBRES_TABLE_MATCHLINE_YJ,
796 MOO_FIBRES_TABLE_MATCHLINE_H };
797
798 return cpl_table_get_int(table, res[type], row, &rej);
799}
800
801/*----------------------------------------------------------------------------*/
810/*----------------------------------------------------------------------------*/
811int
814 cpl_size row)
815{
816 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, 0);
817 int rej;
818
819 const char *res[] = { MOO_FIBRES_TABLE_REJECTLINE_RI,
820 MOO_FIBRES_TABLE_REJECTLINE_YJ,
821 MOO_FIBRES_TABLE_REJECTLINE_H };
822
823 return cpl_table_get_int(table, res[type], row, &rej);
824}
825
826/*----------------------------------------------------------------------------*/
835/*----------------------------------------------------------------------------*/
836double
839 cpl_size row)
840{
841 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, 0);
842 int rej;
843
844 const char *res[] = { MOO_FIBRES_TABLE_XDIFF_MEDIAN_RI,
845 MOO_FIBRES_TABLE_XDIFF_MEDIAN_YJ,
846 MOO_FIBRES_TABLE_XDIFF_MEDIAN_H };
847
848 return cpl_table_get_double(table, res[type], row, &rej);
849}
850
851/*----------------------------------------------------------------------------*/
858/*----------------------------------------------------------------------------*/
859int
861{
862 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, 0);
863 return cpl_table_and_selected_int(table, MOO_FIBRES_TABLE_HEALTH,
864 CPL_NOT_EQUAL_TO,
865 MOO_FIBRES_TABLE_HEALTH_BROKEN);
866}
867
868/*----------------------------------------------------------------------------*/
875/*----------------------------------------------------------------------------*/
876cpl_table *
877moo_fibre_table_load(cpl_frame *frame)
878{
879 cpl_table *res = NULL;
880 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
881
882 const char *filename = cpl_frame_get_filename(frame);
883 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL);
884
885 cpl_size qnum = cpl_fits_find_extension(filename, MOO_FIBRES_TABLE_EXTNAME);
886 if (qnum > 0) {
887 res = cpl_table_load(filename, qnum, 0);
888 }
889 return res;
890}
891
892/*----------------------------------------------------------------------------*/
899/*----------------------------------------------------------------------------*/
900
901const char *
903{
904 const char *res = NULL;
905 cpl_ensure(table != NULL, CPL_ERROR_NULL_INPUT, NULL);
906
907 cpl_table_unselect_all(table);
908 cpl_table_or_selected_string(table, MOO_FIBRES_TABLE_TYPE, CPL_EQUAL_TO,
909 MOO_FIBRES_TABLE_TYPE_STD_FLUX);
910 cpl_table_or_selected_string(table, MOO_FIBRES_TABLE_TYPE, CPL_EQUAL_TO,
911 MOO_FIBRES_TABLE_TYPE_STD_TELL);
912
913 cpl_array *indexes = cpl_table_where_selected(table);
914
915 const char **names =
916 cpl_table_get_data_string_const(table, MOO_FIBRES_TABLE_TARGNAME);
917 int size = cpl_array_get_size(indexes);
918 if (size == 1) {
919 int idx = cpl_array_get_cplsize(indexes, 0, NULL);
920 res = names[idx];
921 }
922 else {
923 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
924 "Wrong number (%d) of STD found", size);
925 }
926 cpl_array_delete(indexes);
927 return res;
928}
929
930/*----------------------------------------------------------------------------*/
940/*----------------------------------------------------------------------------*/
941cpl_error_code
943 int indexrbn,
944 int *indexext,
945 int *num)
946{
947 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
948 cpl_ensure_code(indexext != NULL, CPL_ERROR_NULL_INPUT);
949 cpl_ensure_code(num != NULL, CPL_ERROR_NULL_INPUT);
950 cpl_table_select_all(table);
951 int size = cpl_table_and_selected_int(table, MOO_FIBRES_TABLE_INDEXRBN,
952 CPL_EQUAL_TO, indexrbn);
953
954 if (size == 1) {
955 cpl_array *sel = cpl_table_where_selected(table);
956 int idx = cpl_array_get_cplsize(sel, 0, NULL);
957 cpl_array_delete(sel);
958 *indexext =
959 cpl_table_get_int(table, MOO_FIBRES_TABLE_INDEXEXT, idx, NULL);
960 const int str =
961 cpl_table_get_int(table, MOO_FIBRES_TABLE_SPECTRO, idx, NULL);
962 if (str == MOO_FIBRES_TABLE_SPECTRO_1) {
963 *num = 1;
964 }
965 else {
966 *num = 2;
967 }
968 }
969 else {
970 *num = -1;
971 *indexext = -1;
972 }
973 return CPL_ERROR_NONE;
974}
975
976/*----------------------------------------------------------------------------*/
983/*----------------------------------------------------------------------------*/
984cpl_error_code
986{
987 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
988
989 cpl_propertylist *order = cpl_propertylist_new();
990 cpl_propertylist_append_bool(order, MOO_FIBRES_TABLE_INDEXRBN, CPL_FALSE);
991 cpl_table_sort(table, order);
992 cpl_propertylist_delete(order);
993
994 return CPL_ERROR_NONE;
995}
996
997/*----------------------------------------------------------------------------*/
1004/*----------------------------------------------------------------------------*/
1005cpl_error_code
1007{
1008 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
1009
1010 cpl_propertylist *order = cpl_propertylist_new();
1011 cpl_propertylist_append_bool(order, MOO_FIBRES_TABLE_SPECTRO, CPL_FALSE);
1012 cpl_propertylist_append_bool(order, MOO_FIBRES_TABLE_INDEX, CPL_FALSE);
1013 cpl_table_sort(table, order);
1014 cpl_propertylist_delete(order);
1015
1016 return CPL_ERROR_NONE;
1017}
1018
enum _moo_detector_type_ moo_detector_type
The type code type.
Definition: moo_detector.h:64
int moo_fibres_table_filter_health(cpl_table *table)
Filter bad health data in fibre table.
cpl_error_code moo_fibres_table_add_wavecalguess_cols(cpl_table *table)
add wavecal additional columns
cpl_table * moo_fibre_table_load(cpl_frame *frame)
Load a fibre table from a file.
cpl_error_code moo_fibres_table_by_index(cpl_table *table)
Order fibres table by INDEX (ASC)
cpl_error_code moo_fibres_table_add_wavecal_cols(cpl_table *table, cpl_table *guess, const char *model)
add wavecal additional columns
cpl_error_code moo_fibres_table_set_matchline(cpl_table *table, moo_detector_type type, cpl_size row, int value)
set the number of match lines for the given detector type
int moo_fibres_table_get_spectro_nrow(cpl_table *table, int num)
get the number of rows of a spectro in the fibre table
cpl_error_code moo_fibres_table_set_failedfit(cpl_table *table, moo_detector_type type, cpl_size row, int value)
set the number od failedfit lines for the given detector type
float * moo_fibres_table_get_median_snr(cpl_table *table, moo_detector_type type)
get the data of median_snr for the given detector type
cpl_array * moo_fibres_table_get_spectro_indexext(cpl_table *table, int num)
get the index of a spectro in the fibre table sort by spetcro,indexext
cpl_error_code moo_fibres_table_set_fitline(cpl_table *table, moo_detector_type type, cpl_size row, int value)
set the number of fit lines for the given detector type
cpl_error_code moo_fibres_table_set_modelline(cpl_table *table, moo_detector_type type, cpl_size row, int value)
set the number of model lines for the given detector type
cpl_table * moo_fibres_table_get_spectro_table(cpl_table *table, int num)
get the selection of a spectro in the fibre table
int moo_fibres_table_get_matchline(cpl_table *table, moo_detector_type type, cpl_size row)
Get the number of matched lines for the given detector type.
int moo_fibres_table_get_rejectline(cpl_table *table, moo_detector_type type, cpl_size row)
Get the number of rejected lines for the given detector type.
double moo_fibres_table_get_xdiff(cpl_table *table, moo_detector_type type, cpl_size row)
Get xdiff for the given detector type.
cpl_error_code moo_fibres_table_set_xdiff(cpl_table *table, moo_detector_type type, cpl_size row, double value)
set the xdiff for the given fibre and detector type
cpl_error_code moo_fibres_table_add_extract_cols(cpl_table *table)
add extract additional columns
const char * moo_fibres_table_get_std_name(cpl_table *table)
get the object name of the STD type in the fibre table
cpl_error_code moo_fibres_table_set_detectline(cpl_table *table, moo_detector_type type, cpl_size row, int value)
set the number od detectline for the given detector type
cpl_error_code moo_fibres_table_add_f2f_cols(cpl_table *table)
add f2f additional columns
cpl_array * moo_fibres_table_get_spectro_index(cpl_table *table, int num)
get the index of a spectro in the fibre table sort by index on the slit
cpl_error_code moo_fibres_table_by_indexrbn(cpl_table *table)
Order fibres table by INDEXRBN (ASC)
cpl_error_code moo_fibres_table_add_nod_cols(cpl_table *table)
add nod additional columns
cpl_error_code moo_fibres_table_rbn_to_ext(cpl_table *table, int indexrbn, int *indexext, int *num)
get from indexrbn the corresponding indexext and num
cpl_error_code moo_fibres_table_add_locguess_cols(cpl_table *table)
add localise guess additional columns
cpl_error_code moo_fibres_table_add_rebin_cols(cpl_table *table)
add rebin additional columns
cpl_error_code moo_fibres_table_set_rejectline(cpl_table *table, moo_detector_type type, cpl_size row, int value)
set the number of rejected lines for the given detector type
cpl_error_code moo_fibres_table_erase_extract_cols(cpl_table *table)
erase extract additional columns