31#include "moo_single.h"
32#include "moo_badpix.h"
34#include "moo_fibres_table.h"
73 moo_det *res = cpl_calloc(1,
sizeof(moo_det));
93 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
94 const char *filename = cpl_frame_get_filename(frame);
96 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL);
100 res->primary_header = cpl_propertylist_load(filename, 0);
101 res->filename = cpl_strdup(filename);
103 cpl_errorstate prev_state = cpl_errorstate_get();
113 if (!cpl_errorstate_is_equal(prev_state)) {
114 cpl_msg_info(
"MOO_PREPARE",
"DET: can't load %s : code %d", filename,
115 cpl_error_get_code());
116 cpl_errorstate_set(prev_state);
137 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
140 for (i = 0; i < 2; i++) {
145 return CPL_ERROR_NONE;
168 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
169 cpl_ensure_code(num >= 0, CPL_ERROR_ILLEGAL_INPUT);
170 cpl_ensure_code(num <= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE);
171 cpl_ensure_code(level >= 0, CPL_ERROR_ILLEGAL_INPUT);
173 if (self->ri[num] != NULL) {
176 return CPL_ERROR_NONE;
199 moo_single *res = NULL;
201 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
202 cpl_ensure(num >= 1 && num <= 2, CPL_ERROR_ILLEGAL_INPUT, NULL);
233 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
234 cpl_ensure_code(num >= 1, CPL_ERROR_ILLEGAL_INPUT);
235 cpl_ensure_code(num <= 2, CPL_ERROR_ACCESS_OUT_OF_RANGE);
237 cpl_error_code status = CPL_ERROR_NONE;
240 if (single != NULL) {
267 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
268 cpl_ensure_code(num >= 0, CPL_ERROR_ILLEGAL_INPUT);
269 cpl_ensure_code(num <= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE);
270 cpl_ensure_code(level >= 0, CPL_ERROR_ILLEGAL_INPUT);
272 if (self->yj[num] != NULL) {
275 return CPL_ERROR_NONE;
300 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
301 cpl_ensure_code(num >= 0, CPL_ERROR_ILLEGAL_INPUT);
302 cpl_ensure_code(num <= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE);
303 cpl_ensure_code(level >= 0, CPL_ERROR_ILLEGAL_INPUT);
305 if (self->h[num] != NULL) {
308 return CPL_ERROR_NONE;
312moo_det_set_single(moo_det *self,
317 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
318 cpl_ensure_code(num >= 1 && num <= 2, CPL_ERROR_ILLEGAL_INPUT);
320 cpl_error_code status = CPL_ERROR_NONE;
325 self->ri[num - 1] = single;
329 self->yj[num - 1] = single;
333 self->h[num - 1] = single;
336 status = CPL_ERROR_ILLEGAL_INPUT;
337 cpl_error_set(__func__, status);
361 moo_single *result = NULL;
363 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
364 cpl_ensure(num >= 1 && num <= 2, CPL_ERROR_ILLEGAL_INPUT, NULL);
368 result = self->ri[num - 1];
371 result = self->yj[num - 1];
374 result = self->h[num - 1];
402 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
403 cpl_ensure(num >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
404 cpl_ensure(num <= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
406 return self->ri[num];
426 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
428 if (self->fibre_table == NULL && self->filename != NULL) {
430 cpl_fits_find_extension(self->filename, MOO_FIBRES_TABLE_EXTNAME);
432 self->fibre_table = cpl_table_load(self->filename, qnum, 0);
435 return self->fibre_table;
455 if (self->primary_header == NULL && self->filename != NULL) {
456 self->primary_header = cpl_propertylist_load(self->filename, 0);
458 return self->primary_header;
476 if (self->filename != NULL) {
477 cpl_free(self->filename);
480 for (i = 0; i < 2; i++) {
485 if (self->primary_header != NULL) {
486 cpl_propertylist_delete(self->primary_header);
488 if (self->fibre_table != NULL) {
489 cpl_table_delete(self->fibre_table);
510 if (self->primary_header != NULL) {
511 cpl_propertylist_save(self->primary_header, filename,
515 cpl_propertylist *h = cpl_propertylist_new();
516 cpl_propertylist_save(h, filename, CPL_IO_CREATE);
517 cpl_propertylist_delete(h);
520 for (i = 1; i <= 2; i++) {
526 if (self->fibre_table != NULL) {
527 cpl_propertylist *h = cpl_propertylist_new();
528 cpl_propertylist_append_string(h, MOO_PFITS_EXTNAME,
529 MOO_FIBRES_TABLE_EXTNAME);
530 cpl_table_save(self->fibre_table, h, h, filename, CPL_IO_EXTEND);
531 cpl_propertylist_delete(h);
552 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
553 cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT);
555 fprintf(stream,
"---MOO_DET\n");
556 fprintf(stream,
"filename %s\n", self->filename);
558 for (i = 0; i < 2; i++) {
559 if (self->ri[i] != NULL) {
560 fprintf(stream,
"---RI_%d %p\n", i, self->ri[i]);
564 if (self->yj[i] != NULL) {
565 fprintf(stream,
"---YJ_%d %p\n", i, self->yj[i]);
569 if (self->h[i] != NULL) {
570 fprintf(stream,
"---H_%d %p\n", i, self->h[i]);
575 return CPL_ERROR_NONE;
581 cpl_ensure(self != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
582 cpl_ensure(num >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
583 cpl_ensure(num <= 2, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
587 return moo_single_get_header(single);
606 cpl_ensure_code(self != NULL, CPL_ERROR_ILLEGAL_INPUT);
607 cpl_ensure_code(det != NULL, CPL_ERROR_ILLEGAL_INPUT);
610 for (i = 0; i < 2; i++) {
611 moo_single *ri = self->ri[i];
612 moo_single *detri = det->ri[i];
616 moo_single *yj = self->yj[i];
618 moo_single *detyj = det->yj[i];
621 moo_single *h = self->h[i];
623 moo_single *deth = det->h[i];
627 return CPL_ERROR_NONE;
645 cpl_ensure_code(self != NULL, CPL_ERROR_ILLEGAL_INPUT);
646 cpl_ensure_code(det != NULL, CPL_ERROR_ILLEGAL_INPUT);
649 for (i = 0; i < 2; i++) {
650 moo_single *ri = self->ri[i];
651 moo_single *detri = det->ri[i];
655 moo_single *yj = self->yj[i];
657 moo_single *detyj = det->yj[i];
660 moo_single *h = self->h[i];
662 moo_single *deth = det->h[i];
666 return CPL_ERROR_NONE;
684 cpl_ensure_code(self != NULL, CPL_ERROR_ILLEGAL_INPUT);
685 cpl_ensure_code(det != NULL, CPL_ERROR_ILLEGAL_INPUT);
688 for (i = 0; i < 2; i++) {
689 moo_single *ri = self->ri[i];
690 moo_single *detri = det->ri[i];
694 moo_single *yj = self->yj[i];
696 moo_single *detyj = det->yj[i];
699 moo_single *h = self->h[i];
701 moo_single *deth = det->h[i];
705 return CPL_ERROR_NONE;
723 cpl_ensure_code(self != NULL, CPL_ERROR_ILLEGAL_INPUT);
724 cpl_ensure_code(det != NULL, CPL_ERROR_ILLEGAL_INPUT);
727 for (i = 0; i < 2; i++) {
728 moo_single *ri = self->ri[i];
734 moo_single *yj = self->yj[i];
736 moo_single *detyj = det->yj[i];
743 moo_single *h = self->h[i];
745 moo_single *deth = det->h[i];
753 return CPL_ERROR_NONE;
771 cpl_ensure_code(self != NULL, CPL_ERROR_ILLEGAL_INPUT);
772 cpl_ensure_code(det != NULL, CPL_ERROR_ILLEGAL_INPUT);
775 for (i = 0; i < 2; i++) {
776 moo_single *ri = self->ri[i];
777 moo_single *detri = det->ri[i];
781 moo_single *yj = self->yj[i];
783 moo_single *detyj = det->yj[i];
786 moo_single *h = self->h[i];
788 moo_single *deth = det->h[i];
792 return CPL_ERROR_NONE;
810 cpl_ensure_code(self != NULL, CPL_ERROR_ILLEGAL_INPUT);
812 for (
int i = 0; i < 2; i++) {
813 moo_single *ri = self->ri[i];
815 double min_snr = min_snr_tab[i * 3];
819 moo_single *yj = self->yj[i];
821 double min_snr = min_snr_tab[i * 3 + 1];
825 moo_single *h = self->h[i];
827 double min_snr = min_snr_tab[i * 3 + 2];
832 return CPL_ERROR_NONE;
cpl_error_code moo_det_load_h(moo_det *self, int num, int level)
Load the H part in DET.
moo_single * moo_det_load_single(moo_det *self, moo_detector_type type, int num, int level)
Load the type part in DET and return it.
cpl_error_code moo_det_rescale_using_exptime(moo_det *self, moo_det *det)
Rescale using exptime factor.
cpl_error_code moo_det_filter_snr(moo_det *self, double *min_snr_tab)
Flag low snr pixels from DET structure.
cpl_error_code moo_det_load_ri(moo_det *self, int num, int level)
Load the RI part in DET.
cpl_error_code moo_det_load_yj(moo_det *self, int num, int level)
Load the YJ part in DET.
cpl_error_code moo_det_free_single(moo_det *self, moo_detector_type type, int num)
Free the given type part in DET.
moo_single * moo_det_get_ri(moo_det *self, int num)
Get the RI part in DET.
cpl_error_code moo_det_sum(moo_det *self, moo_det *det)
Sum DET structure.
cpl_propertylist * moo_det_get_primary_header(moo_det *self)
Get the PRIMARY HEADER in DET.
moo_det * moo_det_create(const cpl_frame *frame)
Create a new moo_det from the given DET frame.
moo_det * moo_det_new(void)
Create a new moo_det.
void moo_det_save(moo_det *self, const char *filename)
Save a moo_det to a FITS file.
cpl_error_code moo_det_dump(const moo_det *self, FILE *stream)
Dump structural information of DET.
cpl_table * moo_det_get_fibre_table(moo_det *self)
Get the FIBRE TABLE in DET.
cpl_error_code moo_det_load(moo_det *self, unsigned int level)
Load all parts in DET.
cpl_error_code moo_det_subtract(moo_det *self, moo_det *det)
Subtract DET structure.
void moo_det_delete(moo_det *self)
Delete a moo_det.
cpl_error_code moo_det_mean(moo_det *self, moo_det *det)
Sum DET structure.
moo_single * moo_det_get_single(moo_det *self, moo_detector_type type, int num)
Get the type part in DET and return it.
cpl_error_code moo_det_divide(moo_det *self, moo_det *det)
Divide DET structure.
enum _moo_detector_type_ moo_detector_type
The type code type.
cpl_error_code moo_single_load(moo_single *self, unsigned int level)
Load data in a single structure.
cpl_error_code moo_single_mean(moo_single *a, moo_single *b)
Mean of two single DET.
cpl_error_code moo_single_sub(moo_single *a, moo_single *b)
Subtract two single DET.
void moo_single_delete(moo_single *self)
Delete a moo_single.
moo_single * moo_single_create(const char *filename, moo_detector_type type, int ntas)
Create a new moo_single from the given filename.
cpl_error_code moo_single_dump(const moo_single *self, FILE *stream)
Dump structural information of a Single DET.
cpl_error_code moo_single_free(moo_single *self)
Free memory associate to this single DET.
cpl_error_code moo_single_sum(moo_single *a, moo_single *b)
Add two single DET.
cpl_error_code moo_single_divide(moo_single *a, moo_single *b)
Divide two single DET.
cpl_error_code moo_single_multiply_scalar(moo_single *a, double scalar)
Elementwise multiplication of a single with a scalar.
void moo_single_save(moo_single *self, const char *filename, moo_detector_type type, int ntas)
Save a moo_single to a FITS file.
cpl_error_code moo_single_filter_snr(moo_single *self, double min_snr)
Flag low snr pixels from single DET structure.
int moo_pfits_get_ndit(const cpl_propertylist *plist)
find out the ESO DET NDIT value
double moo_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
double moo_pfits_get_exptime(const cpl_propertylist *plist)
find out the EXPTIME value