31#include "moo_badpix.h"
33#include "moo_fibres_table.h"
69 moo_rbn *res = cpl_calloc(1,
sizeof(moo_rbn));
87 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
89 cpl_errorstate prev_state = cpl_errorstate_get();
91 const char *filename = cpl_frame_get_filename(frame);
93 res->filename = filename;
94 res->primary_header = cpl_propertylist_load(filename, 0);
100 if (!cpl_errorstate_is_equal(prev_state)) {
101 cpl_msg_info(
"moo_rbn",
"Error in rbn create ecode=%d filename=%s",
102 cpl_error_get_code(), filename);
103 cpl_errorstate_set(prev_state);
123 if (self->primary_header != NULL) {
124 cpl_propertylist_delete(self->primary_header);
127 if (self->ri != NULL) {
130 if (self->yj != NULL) {
133 if (self->h != NULL) {
137 if (self->fibre_table != NULL) {
138 cpl_table_delete(self->fibre_table);
162 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
164 cpl_error_code status = CPL_ERROR_NONE;
167 if (single != NULL) {
186 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
188 cpl_error_code status = CPL_ERROR_NONE;
189 cpl_errorstate prev_state = cpl_errorstate_get();
191 if (single != NULL) {
192 switch (single->type) {
204 if (!cpl_errorstate_is_equal(prev_state)) {
205 cpl_msg_error(
"moo_rbn",
"Error for adding rbn to %s (%d)",
206 self->filename, cpl_error_get_code());
207 status = cpl_error_get_code();
208 cpl_errorstate_set(prev_state);
228 moo_rbn_single *single)
230 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
231 cpl_ensure_code(self->filename != NULL, CPL_ERROR_NULL_INPUT);
232 cpl_error_code status = CPL_ERROR_NONE;
233 cpl_errorstate prev_state = cpl_errorstate_get();
238 if (!cpl_errorstate_is_equal(prev_state)) {
239 cpl_msg_error(
"moo_rbn",
"Error for adding single to %s (%s)",
241 cpl_error_get_message_default(cpl_error_get_code()));
242 status = cpl_error_get_code();
262 cpl_propertylist_save(self->primary_header, filename, CPL_IO_CREATE);
267 if (self->fibre_table != NULL) {
268 cpl_propertylist *h = cpl_propertylist_new();
269 cpl_propertylist_append_string(h, MOO_PFITS_EXTNAME,
270 MOO_FIBRES_TABLE_EXTNAME);
271 cpl_table_save(self->fibre_table, h, h, filename, CPL_IO_EXTEND);
272 cpl_propertylist_delete(h);
290 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
291 cpl_ensure_code(self->filename != NULL, CPL_ERROR_NULL_INPUT);
292 cpl_ensure_code(fibre_table != NULL, CPL_ERROR_NULL_INPUT);
294 cpl_error_code status = CPL_ERROR_NONE;
295 cpl_errorstate prev_state = cpl_errorstate_get();
296 self->fibre_table = fibre_table;
298 cpl_propertylist *h = cpl_propertylist_new();
299 cpl_propertylist_append_string(h, MOO_PFITS_EXTNAME,
300 MOO_FIBRES_TABLE_EXTNAME);
301 cpl_table_save(self->fibre_table, h, h, self->filename, CPL_IO_EXTEND);
302 cpl_propertylist_delete(h);
304 if (!cpl_errorstate_is_equal(prev_state)) {
305 cpl_msg_error(__func__,
"Error for adding fibre table to %s (%d)",
306 self->filename, cpl_error_get_code());
307 status = cpl_error_get_code();
308 cpl_errorstate_set(prev_state);
327 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
362 moo_rbn_single *res = NULL;
364 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
399 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
401 if (self->fibre_table == NULL && self->filename != NULL) {
403 cpl_fits_find_extension(self->filename, MOO_FIBRES_TABLE_EXTNAME);
405 self->fibre_table = cpl_table_load(self->filename, qnum, 0);
408 return self->fibre_table;
423 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
424 cpl_ensure_code(skylines != NULL, CPL_ERROR_NULL_INPUT);
427 const char *snrs[] = { MOO_FIBRES_TABLE_MEDSNR_RI_RBN,
428 MOO_FIBRES_TABLE_MEDSNR_YJ_RBN,
429 MOO_FIBRES_TABLE_MEDSNR_H_RBN };
431 int nrow = cpl_table_get_nrow(fibre_table);
433 for (
int t = 0; t < nrow; t++) {
435 cpl_table_get_int(fibre_table, MOO_FIBRES_TABLE_INDEXRBN, t, NULL);
437 cpl_table_get_int(fibre_table, MOO_FIBRES_TABLE_HEALTH, t, NULL);
439 for (
int i = 0; i < 3; i++) {
440 moo_rbn_single *single =
442 if (single != NULL) {
447 cpl_table_set_float(fibre_table, snrs[i], t, snr);
452 return CPL_ERROR_NONE;
471 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
472 cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT);
474 fprintf(stream,
"---MOO_RBN\n");
475 fprintf(stream,
"filename %s\n", self->filename);
477 if (self->ri != NULL) {
478 fprintf(stream,
"---RI %p\n", self->ri);
482 if (self->yj != NULL) {
483 fprintf(stream,
"---YJ %p\n", self->yj);
487 if (self->h != NULL) {
488 fprintf(stream,
"---H %p\n", self->h);
492 if (self->fibre_table != NULL) {
493 fprintf(stream,
"---FT %p\n", self->fibre_table);
496 return CPL_ERROR_NONE;
514 if (self->primary_header == NULL && self->filename != NULL) {
515 self->primary_header = cpl_propertylist_load(self->filename, 0);
517 return self->primary_header;
enum _moo_detector_type_ moo_detector_type
The type code type.
moo_rbn_single * moo_rbn_single_create(const char *filename, moo_detector_type type)
Create a new moo_rbn_single with the given filename and type.
void moo_rbn_single_save(const moo_rbn_single *self, const char *filename, moo_detector_type type)
Save a moo_rbn_single to a FITS file.
void moo_rbn_single_delete(moo_rbn_single *self)
Delete a moo_rbn_single.
cpl_error_code moo_rbn_single_dump(const moo_rbn_single *self, FILE *stream)
Dump structural information of a Single DET.
cpl_error_code moo_rbn_single_load(moo_rbn_single *self, unsigned int level)
load the data of a moo_rbn_single
double moo_rbn_single_compute_snr(moo_rbn_single *self, int rbn_idx, moo_sky_lines_list *skylines)
Compute SNR for a given target.
cpl_error_code moo_rbn_single_free(moo_rbn_single *self)
Free memory associate to this single RBN.
moo_rbn_single * moo_rbn_load_single(moo_rbn *self, moo_detector_type type, unsigned int level)
Load the type part in RBN and return it.
cpl_error_code moo_rbn_set_single(moo_rbn *self, moo_rbn_single *single)
assign moo_rbn_single structure in moo_rbn structure
void moo_rbn_delete(moo_rbn *self)
Delete a moo_rbn.
void moo_rbn_save(moo_rbn *self, const char *filename)
Save a moo_rbn to a FITS file.
cpl_propertylist * moo_rbn_get_primary_header(moo_rbn *self)
Get the PRIMARY HEADER in RBN.
moo_rbn_single * moo_rbn_get_single(moo_rbn *self, moo_detector_type type)
Get a RBN single from RBN.
cpl_error_code moo_rbn_dump(const moo_rbn *self, FILE *stream)
Dump structural information of RBN.
moo_rbn * moo_rbn_create(const cpl_frame *frame)
Create a new empty RBN filename.
cpl_error_code moo_rbn_add_single(moo_rbn *self, moo_detector_type type, moo_rbn_single *single)
Add RBN_SINGLE extension to RBN filename and update moo_rbn structure.
cpl_error_code moo_rbn_add_fibre_table(moo_rbn *self, cpl_table *fibre_table)
Add fibre table to RBN filename and update moo_rbn structure.
cpl_error_code moo_rbn_compute_snr(moo_rbn *self, moo_sky_lines_list *skylines)
Compute SNR for targets in RBN.
cpl_table * moo_rbn_get_fibre_table(moo_rbn *self)
Get the FIBRE TABLE in RBN.
moo_rbn * moo_rbn_new(void)
Create a new moo_rbn.
cpl_error_code moo_rbn_free_single(moo_rbn *self, moo_detector_type type)
Free the given type part in RBN.