35#include "moo_badpix.h"
36#include "moo_combine_sky.h"
64_moo_qual_fromlist(cpl_imagelist *list)
66 cpl_ensure(list, CPL_ERROR_NULL_INPUT, NULL);
68 int size = cpl_imagelist_get_size(list);
69 cpl_ensure(size > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
71 const cpl_image *qimg = cpl_imagelist_get_const(list, 0);
76 int nx = cpl_image_get_size_x(qimg);
77 int ny = cpl_image_get_size_y(qimg);
78 const int *qdata = cpl_image_get_data_int_const(qimg);
80 for (k = 1; k < size; k++) {
81 cpl_image *qimg2 = cpl_imagelist_get(list, k);
82 int *qdata2 = cpl_image_get_data_int(qimg2);
83 for (
int i = 0; i < nx * ny; i++) {
84 if (qdata[i] != qdata2[i]) {
85 cpl_msg_error(__func__,
86 "QUAL of first frame and %d are not equal",
92 return cpl_image_duplicate(qimg);
95static moo_rbn_single *
96_moo_collapse_median(hdrl_imagelist *list,
97 cpl_imagelist *quallist,
100 moo_rbn_single *single = NULL;
102 cpl_ensure(list != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
104 int size = hdrl_imagelist_get_size(list);
107 hdrl_image *res = NULL;
108 cpl_image *contrib = NULL;
109 hdrl_imagelist_collapse_median(list, &res, &contrib);
111 for (j = 0; j < size; j++) {
112 hdrl_imagelist_unset(list, 0);
115 cpl_image *qual = _moo_qual_fromlist(quallist);
121 for (j = 0; j < size; j++) {
122 cpl_imagelist_unset(quallist, 0);
125 cpl_image_delete(contrib);
132_moo_copy_header_kw(cpl_propertylist *res_header,
133 const cpl_propertylist *orig_header)
135 cpl_ensure_code(res_header != NULL, CPL_ERROR_NULL_INPUT);
136 cpl_ensure_code(orig_header != NULL, CPL_ERROR_NULL_INPUT);
138 cpl_propertylist_copy_property_regexp(res_header, orig_header,
"ESO DET *",
140 cpl_propertylist_copy_property_regexp(res_header, orig_header,
"HDU*", 0);
141 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_BUNIT);
142 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_ERRDATA);
143 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_QUALDATA);
144 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CRPIX1);
145 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CRPIX2);
146 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CRVAL1);
147 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CRVAL2);
148 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CTYPE1);
149 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CTYPE2);
150 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CD1_1);
151 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CD1_2);
152 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CUNIT1);
153 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CD2_1);
154 cpl_propertylist_copy_property(res_header, orig_header, MOO_PFITS_CD2_2);
156 return cpl_error_get_code();
160_moo_combine_sky_single(moo_rbnlist *rbnlist,
163 unsigned int badpix_level,
166 cpl_error_code status = CPL_ERROR_NONE;
167 moo_rbn_single *single = NULL;
168 moo_rbn_single *orig_single = NULL;
175 single = _moo_collapse_median(list, qlist, type);
177 if (single != NULL) {
178 cpl_propertylist *header = NULL;
180 moo_try_check(_moo_copy_header_kw(single->header, header),
" ");
184 cpl_imagelist_unwrap(qlist);
185 hdrl_imagelist_unwrap(list);
211 cpl_ensure(rbnlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
212 cpl_ensure(rbnlist->size > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
214 cpl_errorstate prestate = cpl_errorstate_get();
216 cpl_msg_info(__func__,
"Combine sky of %d frames", (
int)rbnlist->size);
222 res->primary_header = cpl_propertylist_duplicate(orig_rbn->primary_header);
224 cpl_errorstate prev_state = cpl_errorstate_get();
227 if (!cpl_errorstate_is_equal(prev_state)) {
228 cpl_msg_info(__func__,
"DET input files do not have a fibre table.");
229 cpl_errorstate_set(prev_state);
232 for (
int i = 0; i < 3; i++) {
233 moo_try_check(_moo_combine_sky_single(rbnlist, orig_rbn, i,
239 if (!cpl_errorstate_is_equal(prestate)) {
240 cpl_msg_error(__func__,
"Error in remove CRH");
241 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
enum _moo_detector_type_ moo_detector_type
The type code type.
cpl_error_code moo_rbnlist_free_single(const moo_rbnlist *self, moo_detector_type type)
Free the type part for all DET in the detlist.
cpl_propertylist * moo_rbn_single_get_header(moo_rbn_single *self)
Get header of rbn single.
moo_rbn_single * moo_rbn_single_new(moo_detector_type type)
Create a new moo_rbn_single.
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.
moo_rbn_single * moo_rbn_get_single(moo_rbn *self, moo_detector_type type)
Get a RBN single from 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_rbnlist_load_single(const moo_rbnlist *self, moo_detector_type type, int level)
Load the type part for all RBN in the rbnlist.
hdrl_imagelist * moo_rbnlist_get_image(const moo_rbnlist *self, moo_detector_type type)
Get the all the images of the type part in the rbnlist.
cpl_imagelist * moo_rbnlist_get_single_qual(const moo_rbnlist *self, moo_detector_type type)
Get the type QUAL part for all RBN in the rbnlist.
moo_rbn * moo_rbnlist_get(moo_rbnlist *self, int i)
Get the RBN at the position i in the list.
moo_rbn * moo_combine_sky(moo_rbnlist *rbnlist)
Combine RBN sky frames.
cpl_error_code moo_qc_set_ncom(cpl_propertylist *plist, int val)
Set the QC.NCOM value.