34#include "moo_fibres_table.h"
70 moo_f2f *res = cpl_calloc(1,
sizeof(moo_f2f));
90 res->table = cpl_table_new(nbrows);
91 cpl_table_new_column(res->table, MOO_F2F_TRANS_RI, MOO_F2F_TRANS_RI_TYPE);
92 cpl_table_new_column(res->table, MOO_F2F_TRANS_YJ, MOO_F2F_TRANS_YJ_TYPE);
93 cpl_table_new_column(res->table, MOO_F2F_TRANS_H, MOO_F2F_TRANS_H_TYPE);
95 cpl_table_duplicate_column(res->table, MOO_F2F_INDEX, fibre_table,
96 MOO_FIBRES_TABLE_INDEX);
97 cpl_table_duplicate_column(res->table, MOO_FIBRES_TABLE_SPECTRO,
98 fibre_table, MOO_FIBRES_TABLE_SPECTRO);
99 cpl_table_duplicate_column(res->table, MOO_FIBRES_TABLE_INDEXEXT,
100 fibre_table, MOO_FIBRES_TABLE_INDEXEXT);
101 cpl_table_new_column(res->table, MOO_FIBRES_TABLE_INDEXRBN, CPL_TYPE_INT);
104 int moons1_nrow = cpl_table_get_nrow(moons1);
105 cpl_table_delete(moons1);
107 const int *indexext =
108 cpl_table_get_data_int_const(res->table, MOO_FIBRES_TABLE_INDEXEXT);
110 cpl_table_get_data_int_const(res->table, MOO_FIBRES_TABLE_SPECTRO);
112 cpl_table_get_data_int(res->table, MOO_FIBRES_TABLE_INDEXRBN);
113 for (
int i = 0; i < nbrows; i++) {
114 indexrbn[i] = indexext[i];
115 cpl_table_set_float(res->table, MOO_F2F_TRANS_RI, i, 0.);
116 cpl_table_set_float(res->table, MOO_F2F_TRANS_YJ, i, 0.);
117 cpl_table_set_float(res->table, MOO_F2F_TRANS_H, i, 0.);
119 if (MOO_FIBRES_TABLE_SPECTRO_2 == spectro[i] && indexrbn[i] != 0) {
120 indexrbn[i] += moons1_nrow;
123 res->primary_header = cpl_propertylist_new();
141 cpl_ensure(f2f_frame, CPL_ERROR_NULL_INPUT, NULL);
142 cpl_errorstate prev_state = cpl_errorstate_get();
144 const char *filename = cpl_frame_get_filename(f2f_frame);
146 res->filename = filename;
147 moo_try_check(res->table = cpl_table_load(filename, 1, 0),
" ");
148 moo_try_check(res->primary_header = cpl_propertylist_load(filename, 0),
152 if (!cpl_errorstate_is_equal(prev_state)) {
155 cpl_errorstate_set(prev_state);
171 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
173 cpl_propertylist *order = cpl_propertylist_new();
174 cpl_propertylist_append_bool(order, MOO_FIBRES_TABLE_INDEXRBN, CPL_FALSE);
175 cpl_table_sort(self->table, order);
176 cpl_propertylist_delete(order);
178 return CPL_ERROR_NONE;
192 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
194 cpl_propertylist *order = cpl_propertylist_new();
195 cpl_propertylist_append_bool(order, MOO_FIBRES_TABLE_SPECTRO, CPL_FALSE);
196 cpl_propertylist_append_bool(order, MOO_FIBRES_TABLE_INDEX, CPL_FALSE);
197 cpl_table_sort(self->table, order);
198 cpl_propertylist_delete(order);
200 return CPL_ERROR_NONE;
221 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
222 cpl_ensure_code(idxtab != NULL, CPL_ERROR_NULL_INPUT);
223 cpl_ensure_code(values != NULL, CPL_ERROR_NULL_INPUT);
225 cpl_error_code status = CPL_ERROR_NONE;
227 const char *colname = NULL;
230 colname = MOO_F2F_TRANS_RI;
233 colname = MOO_F2F_TRANS_YJ;
236 colname = MOO_F2F_TRANS_H;
240 int size = cpl_array_get_size(idxtab);
242 for (
int i = 0; i < size; i++) {
243 cpl_size idx = cpl_array_get_cplsize(idxtab, i, NULL);
244 float v = (float)cpl_vector_get(values, i);
245 cpl_table_set(self->table, colname, idx, v);
262 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
264 const char *colname = NULL;
267 colname = MOO_F2F_TRANS_RI;
270 colname = MOO_F2F_TRANS_YJ;
273 colname = MOO_F2F_TRANS_H;
291 cpl_vector *res = NULL;
293 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
294 cpl_ensure(idxtab != NULL, CPL_ERROR_NULL_INPUT, NULL);
296 int size = cpl_array_get_size(idxtab);
299 res = cpl_vector_new(size);
300 for (
int i = 0; i < size; i++) {
301 cpl_size idx = cpl_array_get_cplsize(idxtab, i, NULL);
302 double v = cpl_table_get(self->table, colname, idx, NULL);
303 cpl_vector_set(res, i, v);
323 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
325 const char *colname = NULL;
328 colname = MOO_F2F_TRANS_RI;
331 colname = MOO_F2F_TRANS_YJ;
334 colname = MOO_F2F_TRANS_H;
338 res = cpl_table_get_data_float(self->table, colname);
344moo_f2f_compute_qc(moo_f2f *self,
int *ref, cpl_array *bad)
346 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
347 cpl_ensure_code(ref != NULL, CPL_ERROR_NULL_INPUT);
349 cpl_table *selected = NULL;
351 for (
int i = 0; i < 2; i++) {
357 int size = cpl_array_get_size(bad);
359 for (
int i = 0; i < size; i++) {
360 int idx = cpl_array_get_cplsize(bad, i, NULL);
361 cpl_table_unselect_row(self->table, idx);
363 selected = cpl_table_extract_selected(self->table);
365 const char *transname[] = { MOO_F2F_TRANS_RI, MOO_F2F_TRANS_YJ,
368 for (
int i = 0; i < 3; i++) {
369 if (cpl_table_has_valid(selected, transname[i])) {
370 double min = cpl_table_get_column_min(selected, transname[i]);
371 double max = cpl_table_get_column_max(selected, transname[i]);
372 double med = cpl_table_get_column_median(selected, transname[i]);
380 cpl_table_delete(selected);
382 return cpl_error_get_code();
386moo_f2f_save(moo_f2f *self,
const char *filename)
388 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
389 cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT);
391 cpl_propertylist *extheader = cpl_propertylist_new();
392 cpl_propertylist_append_string(extheader, MOO_PFITS_EXTNAME,
394 self->filename = filename;
395 cpl_table_save(self->table, self->primary_header, extheader, filename,
397 cpl_propertylist_delete(extheader);
399 return cpl_error_get_code();
416 if (self->table != NULL) {
417 cpl_table_delete(self->table);
419 if (self->primary_header != NULL) {
420 cpl_propertylist_delete(self->primary_header);
enum _moo_detector_type_ moo_detector_type
The type code type.
float * moo_f2f_get_trans_column(moo_f2f *self, moo_detector_type type)
Get transmission column from table.
moo_f2f * moo_f2f_new(void)
Create a new moo_f2f.
const char * moo_f2f_get_trans_colname(moo_f2f *self, moo_detector_type type)
Get transmission column name from table.
cpl_error_code moo_f2f_order_by_indexrbn(moo_f2f *self)
Order F2F by INDEXRBN (ASC)
void moo_f2f_delete(moo_f2f *self)
Delete a moo_f2f.
cpl_vector * moo_f2f_get_trans(moo_f2f *self, moo_detector_type type, cpl_array *idxtab)
Get transmission values from table.
moo_f2f * moo_f2f_load(const cpl_frame *f2f_frame)
Load a F2F table from a fits file.
cpl_error_code moo_f2f_set_trans(moo_f2f *self, moo_detector_type type, cpl_array *idxtab, cpl_vector *values)
Set transmission values in table.
moo_f2f * moo_f2f_create(int nbrows, cpl_table *fibre_table)
Create a new moo_f2f and an empty structure in memory.
cpl_error_code moo_f2f_order_by_index(moo_f2f *self)
Order F2F by SPECTRO,INDEX (ASC)
cpl_table * moo_fibres_table_get_spectro_table(cpl_table *table, int num)
get the selection of a spectro in the fibre table
cpl_error_code moo_qc_set_fibtrans_ref(cpl_propertylist *plist, int ntas, int val)
Set the QC.SPECTRO.FIBTRANS.REF.value.
cpl_error_code moo_qc_set_fibtrans_med(cpl_propertylist *plist, moo_detector_type type, double val)
Set the QC.FIBTRANS.MED value.
cpl_error_code moo_qc_set_fibtrans_min(cpl_propertylist *plist, moo_detector_type type, double val)
Set the QC.FIBTRANS.MIN value.
cpl_error_code moo_qc_set_fibtrans_max(cpl_propertylist *plist, moo_detector_type type, double val)
Set the QC.FIBTRANS.MAX value.