33#include "moo_params.h"
35#include "moo_ext_single.h"
36#include "moo_badpix.h"
37#include "moo_fibres_table.h"
38#include "moo_apply_flat.h"
69_moo_apply_trans_single(moo_ext_single *ext,
72 cpl_table *fibre_table,
73 const char *transcolname)
75 cpl_ensure_code(ext != NULL, CPL_ERROR_NULL_INPUT);
76 cpl_ensure_code(trans != NULL, CPL_ERROR_NULL_INPUT);
78 cpl_errorstate prestate = cpl_errorstate_get();
81 cpl_image *data = hdrl_image_get_image(ext_himage);
82 cpl_image *err = hdrl_image_get_error(ext_himage);
83 int ny = hdrl_image_get_size_y(ext_himage);
84 int nx = hdrl_image_get_size_x(ext_himage);
86 for (
int j = 0; j < ny; j++) {
87 double tv = cpl_vector_get(trans, j);
88 int idx = cpl_array_get_cplsize(idxtab, j, NULL);
89 cpl_table_set_float(fibre_table, transcolname, idx, tv);
90 for (
int i = 1; i <= nx; i++) {
92 double v = cpl_image_get(data, i, j + 1, &rej1);
93 double ev = cpl_image_get(err, i, j + 1, &rej2);
95 cpl_image_set(data, i, j + 1, v / tv);
96 cpl_image_set(err, i, j + 1, ev / tv);
100 if (!cpl_errorstate_is_equal(prestate)) {
101 cpl_msg_error(__func__,
"Error in apply_flat");
102 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
104 cpl_errorstate_set(prestate);
107 return CPL_ERROR_NONE;
126_moo_apply_flat_single(moo_ext_single *ext, moo_ext_single *flat)
128 cpl_ensure_code(ext != NULL, CPL_ERROR_NULL_INPUT);
129 cpl_ensure_code(flat != NULL, CPL_ERROR_NULL_INPUT);
131 cpl_errorstate prestate = cpl_errorstate_get();
136 cpl_mask *mask1 = hdrl_image_get_mask(ext_himage);
137 cpl_mask *mask2 = hdrl_image_get_mask(flat_himage);
139 cpl_mask *orig = cpl_mask_duplicate(mask1);
140 cpl_mask_or(orig, mask2);
142 hdrl_image_div_image(ext_himage, flat_himage);
145 cpl_mask_and(orig, mask1);
151 cpl_mask_delete(orig);
153 if (!cpl_errorstate_is_equal(prestate)) {
154 cpl_msg_error(__func__,
"Error in apply_flat");
155 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
157 cpl_errorstate_set(prestate);
159 return CPL_ERROR_NONE;
184 cpl_ensure_code(ext != NULL, CPL_ERROR_NULL_INPUT);
185 cpl_ensure_code(flat != NULL, CPL_ERROR_NULL_INPUT);
187 cpl_errorstate prestate = cpl_errorstate_get();
189 cpl_msg_info(__func__,
"Apply flat-field");
191 unsigned int badpix_level =
194 const char *transcol[] = { MOO_FIBRES_TABLE_TRANS_RI,
195 MOO_FIBRES_TABLE_TRANS_YJ,
196 MOO_FIBRES_TABLE_TRANS_H };
197 cpl_msg_indent_more();
202 cpl_ensure_code(fibres_table != NULL, CPL_ERROR_ILLEGAL_INPUT);
205 for (
int i = 1; i <= 2; i++) {
207 for (
int j = 0; j < 3; j++) {
208 moo_ext_single *ext_single =
210 moo_ext_single *flat_single =
212 const char *transcolname = transcol[j];
213 if (ext_single != NULL && flat_single != NULL) {
214 cpl_msg_info(__func__,
"Apply flat-field for extension %s",
216 _moo_apply_flat_single(ext_single, flat_single);
220 if (ext_single != NULL) {
221 cpl_msg_info(__func__,
222 "Apply F2F transmission for extension %s",
225 _moo_apply_trans_single(ext_single, trans, idxtab,
226 fibres_table, transcolname);
229 int size = cpl_array_get_size(idxtab);
230 for (
int k = 0; k < size; k++) {
231 double tv = cpl_vector_get(trans, k);
232 int idx = cpl_array_get_cplsize(idxtab, k, NULL);
233 cpl_table_set_float(fibres_table, transcolname, idx,
237 cpl_vector_delete(trans);
240 cpl_array_delete(idxtab);
242 cpl_msg_indent_less();
246 if (!cpl_errorstate_is_equal(prestate)) {
247 cpl_msg_error(__func__,
"Error in apply_flat");
248 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
250 cpl_errorstate_set(prestate);
252 return CPL_ERROR_NONE;
cpl_error_code moo_mask_to_badpix(cpl_image *badpix, cpl_mask *mask, unsigned int level)
Add the mask of the badpix level to the badpix map.
#define MOO_BADPIX_LOW_QE
#define MOO_BADPIX_OUTSIDE_DATA_RANGE
cpl_error_code moo_badpix_merge(cpl_image *badpix1, cpl_image *badpix2)
Merge to bad pixel map.
#define MOO_BADPIX_CALIB_DEFECT
const char * moo_detector_get_extname(moo_detector_type type, int ntas)
Get the extension name of a detector.
hdrl_image * moo_ext_single_get_image(moo_ext_single *self)
Get image of EXT_SINGLE.
moo_ext_single * moo_ext_load_single(moo_ext *self, moo_detector_type type, int num, unsigned int level)
Load the type part in EXT and return it.
cpl_table * moo_ext_get_fibre_table(moo_ext *self)
Get the FIBRE TABLE in EXT.
cpl_vector * moo_f2f_get_trans(moo_f2f *self, moo_detector_type type, cpl_array *idxtab)
Get transmission values from table.
cpl_error_code moo_f2f_order_by_index(moo_f2f *self)
Order F2F by SPECTRO,INDEX (ASC)
cpl_error_code moo_fibres_table_add_f2f_cols(cpl_table *table)
add f2f additional columns
cpl_array * moo_fibres_table_get_spectro_index(cpl_table *table, int num)
get the index of a spectro in the fibre table sort by index on the slit
cpl_error_code moo_apply_flat(moo_ext *ext, moo_ext *flat, moo_f2f *f2f)
Divide spectra by 1D flat-field.