32#include "moo_badpix.h"
33#include "moo_target_table.h"
68 moo_sci *res = cpl_calloc(1,
sizeof(moo_sci));
87 if (self->primary_header != NULL) {
88 cpl_propertylist_delete(self->primary_header);
91 if (self->ri != NULL) {
94 if (self->yj != NULL) {
97 if (self->h != NULL) {
101 if (self->target_table != NULL) {
109moo_sci_load(moo_sci *self,
unsigned int level)
111 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
113 for (
int i = 0; i < 3; i++) {
118 return CPL_ERROR_NONE;
134 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
135 cpl_ensure_code(self->filename != NULL, CPL_ERROR_NULL_INPUT);
136 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
138 cpl_error_code status = CPL_ERROR_NONE;
139 cpl_errorstate prev_state = cpl_errorstate_get();
140 self->target_table = table;
142 cpl_propertylist *h = cpl_propertylist_new();
147 cpl_propertylist_append_string(h, MOO_PFITS_EXTNAME,
148 MOO_TARGET_TABLE_EXTNAME);
149 cpl_table_save(self->target_table->table, h, h, self->filename,
152 cpl_propertylist_delete(h);
154 if (!cpl_errorstate_is_equal(prev_state)) {
155 cpl_msg_error(__func__,
"Error for adding target table to %s (%d)",
156 self->filename, cpl_error_get_code());
157 status = cpl_error_get_code();
158 cpl_errorstate_set(prev_state);
176 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
178 cpl_error_code status = CPL_ERROR_NONE;
179 cpl_errorstate prev_state = cpl_errorstate_get();
181 if (single != NULL) {
182 switch (single->type) {
194 if (!cpl_errorstate_is_equal(prev_state)) {
195 cpl_msg_error(
"moo_sci",
"Error for adding SCI_SINGLE to file %s (%d)",
196 self->filename, cpl_error_get_code());
197 status = cpl_error_get_code();
198 cpl_errorstate_set(prev_state);
218 moo_sci_single *single)
220 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
221 cpl_ensure_code(self->filename != NULL, CPL_ERROR_NULL_INPUT);
222 cpl_error_code status = CPL_ERROR_NONE;
223 cpl_errorstate prev_state = cpl_errorstate_get();
228 if (!cpl_errorstate_is_equal(prev_state)) {
229 cpl_msg_error(
"moo_sci",
"Error for adding single to %s (%s)",
231 cpl_error_get_message_default(cpl_error_get_code()));
232 status = cpl_error_get_code();
251 const char *filename = NULL;
252 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
254 cpl_errorstate prev_state = cpl_errorstate_get();
257 filename = cpl_frame_get_filename(frame);
258 sci->filename = filename;
259 sci->primary_header = cpl_propertylist_load(filename, 0);
263 if (!cpl_errorstate_is_equal(prev_state)) {
264 cpl_msg_info(
"moo_sci",
"sci create using filename %s : %d", filename,
265 cpl_error_get_code());
266 cpl_errorstate_set(prev_state);
286 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
287 if (self->target_table == NULL && self->filename != NULL) {
289 cpl_fits_find_extension(self->filename, MOO_TARGET_TABLE_EXTNAME);
293 cpl_errorstate prev_state = cpl_errorstate_get();
294 self->target_table->table = cpl_table_load(self->filename, qnum, 0);
296 if (!cpl_errorstate_is_equal(prev_state) &&
297 CPL_ERROR_DATA_NOT_FOUND == cpl_error_get_code()) {
298 cpl_errorstate_set(prev_state);
300 self->target_table->primary_header =
301 cpl_propertylist_load(self->filename, qnum);
304 return self->target_table;
325 moo_sci_single *res = NULL;
327 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
353 moo_sci_single *result = NULL;
355 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
388 cpl_propertylist_save(self->primary_header, filename, CPL_IO_CREATE);
393 if (self->target_table != NULL) {
394 cpl_propertylist *h = cpl_propertylist_new();
395 cpl_propertylist_append_string(h, MOO_PFITS_EXTNAME,
396 MOO_TARGET_TABLE_EXTNAME);
398 cpl_table_save(self->target_table->table, h, h, filename,
400 cpl_propertylist_delete(h);
417 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
418 cpl_ensure_code(skylines != NULL, CPL_ERROR_NULL_INPUT);
420 unsigned int badpix_level =
423 const char *snrs[] = { MOO_TARGET_TABLE_MEDSNRRI_SCI,
424 MOO_TARGET_TABLE_MEDSNRYJ_SCI,
425 MOO_TARGET_TABLE_MEDSNRH_SCI };
429 cpl_table *table = target_table->table;
430 int nrow = cpl_table_get_nrow(table);
431 for (
int t = 0; t < nrow; t++) {
433 cpl_table_get_int(table, MOO_TARGET_TABLE_INDEXTARG, t, NULL);
434 for (
int i = 0; i < 3; i++) {
436 if (single != NULL) {
439 cpl_table_set_double(table, snrs[i], t, snr);
444 return CPL_ERROR_NONE;
#define MOO_BADPIX_OUTSIDE_DATA_RANGE
#define MOO_BADPIX_CALIB_DEFECT
enum _moo_detector_type_ moo_detector_type
The type code type.
void moo_sci_single_save(moo_sci_single *self, const char *filename, moo_detector_type type)
Save a moo_sci_single to a FITS file.
void moo_sci_single_delete(moo_sci_single *self)
Delete a moo_sci_single.
cpl_error_code moo_sci_single_load(moo_sci_single *self, unsigned int level)
Load a moo_sci_single from the filename.
double moo_sci_single_compute_snr(moo_sci_single *self, int targ_idx, moo_sky_lines_list *skylines)
Compute SNR for a given target.
moo_sci_single * moo_sci_single_create(const char *filename, moo_detector_type type)
Create a new moo_sci_single with the given filename and type.
cpl_error_code moo_sci_set_single(moo_sci *self, moo_sci_single *single)
assign moo_sci_single structure in moo_sci structure
cpl_error_code moo_sci_add_target_table(moo_sci *self, moo_target_table *table)
Add target table to SCI file and update moo_sci structure.
moo_sci_single * moo_sci_load_single(moo_sci *self, moo_detector_type type, int level)
Load the type part in SCI and return it.
void moo_sci_delete(moo_sci *self)
Delete a moo_sci.
moo_sci * moo_sci_new(void)
Create a new moo_sci.
moo_sci * moo_sci_create(const cpl_frame *frame)
Create a new empty SCI filename.
cpl_error_code moo_sci_add_single(moo_sci *self, moo_detector_type type, moo_sci_single *single)
Add SCI_SINGLE extension to SCI file and update moo_sci structure.
moo_sci_single * moo_sci_get_single(moo_sci *self, moo_detector_type type)
Get the type part in SCI and return it.
void moo_sci_save(moo_sci *self, const char *filename)
Save a moo_sci to a FITS file.
moo_target_table * moo_sci_get_target_table(moo_sci *self)
Get the target table of SCI file.
cpl_error_code moo_sci_compute_snr(moo_sci *self, moo_sky_lines_list *skylines)
Compute SNR for all targets in SCI.
void moo_target_table_delete(moo_target_table *self)
Delete a moo_target_table.
moo_target_table * moo_target_table_new(void)
Create a new moo_target_table.
the different type of detectors