31#include "moo_correct_tell.h"
32#include "moo_fibres_table.h"
35#include "moo_badpix.h"
38#include "mf_calctrans.h"
53_molecfit_data_create(
double crpix1,
62 cpl_table *result = NULL;
63 int nx = cpl_image_get_size_x(data);
64 int tell_nx = cpl_image_get_size_x(tell);
66 cpl_ensure(nx == tell_nx, CPL_ERROR_NULL_INPUT, NULL);
68 result = cpl_table_new(nx);
69 cpl_table_new_column(result, MOO_CORRECT_TELL_LAMBDA, CPL_TYPE_DOUBLE);
70 cpl_table_new_column(result, MOO_CORRECT_TELL_FLUX, CPL_TYPE_DOUBLE);
71 cpl_table_new_column(result, MOO_CORRECT_TELL_DFLUX, CPL_TYPE_DOUBLE);
72 cpl_table_new_column(result, MOO_CORRECT_TELL_MASK, CPL_TYPE_INT);
73 cpl_table_new_column(result, MOO_CORRECT_TELL_CFLUX, CPL_TYPE_DOUBLE);
74 cpl_table_new_column(result, MOO_CORRECT_TELL_CDFLUX, CPL_TYPE_DOUBLE);
75 cpl_table_new_column(result, MOO_CORRECT_TELL_QUAL, CPL_TYPE_INT);
76 cpl_table_new_column(result, MOO_CORRECT_TELL_MTRANS, CPL_TYPE_DOUBLE);
78 for (
int i = 0; i < nx; i++) {
81 double w = (ipix - crpix1) * cd1_1 + crval1;
82 double f = cpl_image_get(data, ipix,
id, &rej1);
84 double e = cpl_image_get(data_err, ipix,
id, &rej1);
85 double t = cpl_image_get(tell, ipix, idtell, &rej2);
86 cpl_table_set_double(result, MOO_CORRECT_TELL_LAMBDA, i, w);
87 cpl_table_set_double(result, MOO_CORRECT_TELL_FLUX, i, f);
88 cpl_table_set_double(result, MOO_CORRECT_TELL_DFLUX, i, e);
89 cpl_table_set_int(result, MOO_CORRECT_TELL_MASK, i, rej1);
90 cpl_table_set_double(result, MOO_CORRECT_TELL_CFLUX, i, f);
91 cpl_table_set_double(result, MOO_CORRECT_TELL_CDFLUX, i, e);
92 cpl_table_set_int(result, MOO_CORRECT_TELL_QUAL, i, rej1);
93 cpl_table_set_double(result, MOO_CORRECT_TELL_MTRANS, i, t);
100_moo_update_primary_header(cpl_propertylist *primary_header)
102 cpl_error_code status = CPL_ERROR_NONE;
126 cpl_ensure_code(rbn != NULL, CPL_ERROR_NULL_INPUT);
127 cpl_ensure_code(tell != NULL, CPL_ERROR_NULL_INPUT);
129 cpl_errorstate prestate = cpl_errorstate_get();
130 cpl_msg_info(__func__,
"Correct telluric");
135 _moo_update_primary_header(primary_header);
136 int nfibres = cpl_table_get_nrow(fibre_table);
138 cpl_table_get_data_int(fibre_table, MOO_FIBRES_TABLE_INDEXRBN);
139 const int *spectrot =
140 cpl_table_get_data_int_const(fibre_table, MOO_FIBRES_TABLE_SPECTRO);
142 const char *trans_colnames[] = { MOO_FIBRES_TABLE_TRANS_RI,
143 MOO_FIBRES_TABLE_TRANS_YJ,
144 MOO_FIBRES_TABLE_TRANS_H };
146 for (
int i = 0; i < 3; i++) {
149 if (rbn_single != NULL) {
150 const char *trans_colname = trans_colnames[i];
153 cpl_table_get_data_float(fibre_table, trans_colname);
155 int tnx = cpl_image_get_size_x(tell_img);
158 cpl_image *img = hdrl_image_get_image(himg);
159 cpl_image *err = hdrl_image_get_error(himg);
160 int nx = cpl_image_get_size_x(img);
166 moo_try_assure(tnx == nx, CPL_ERROR_ILLEGAL_INPUT,
167 "Telluric correction file must have the rebin "
170 for (
int f = 0; f < nfibres; f++) {
171 int idrbn = idrbnt[f];
172 double trans = transt[f];
173 int spectro = spectrot[f];
175 if (!isnan(trans) && trans > 0 && idrbn > 0) {
178 if (tell_index > 0) {
180 _molecfit_data_create(crpix1, crval1, cd1_1, img,
181 err, idrbn, tell_img,
184 mf_calctrans_correct_spectrum(
185 mdata, MF_PARAMETERS_TRANSMISSION_TRUE);
186#if MOO_DEBUG_CORRECT_TELL
188 char *name = cpl_sprintf(
"test_%d.fits", idrbn);
189 cpl_table_save(mdata, NULL, NULL, name,
195 for (
int x = 0; x < nx; x++) {
197 cpl_table_get_double(mdata,
198 MOO_CORRECT_TELL_CFLUX, x,
201 cpl_table_get_double(mdata,
202 MOO_CORRECT_TELL_CDFLUX, x,
204 cpl_image_set(img, x + 1, idrbn, flux_v);
205 cpl_image_set(err, x + 1, idrbn, err_v);
208 cpl_table_delete(mdata);
213 "No telluric reference for band %s indexrbn %d",
214 rbn_single->extname, idrbn);
222 if (!cpl_errorstate_is_equal(prestate)) {
223 cpl_msg_error(__func__,
"Error in correct telluric");
224 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
226 return CPL_ERROR_NONE;
248 cpl_ensure_code(sci != NULL, CPL_ERROR_NULL_INPUT);
249 cpl_ensure_code(tell != NULL, CPL_ERROR_NULL_INPUT);
251 cpl_errorstate prestate = cpl_errorstate_get();
252 cpl_msg_info(__func__,
"Correct telluric");
257 int nbtarget = cpl_table_get_nrow(target_table->table);
260 cpl_table_get_data_int(target_table->table, MOO_TARGET_TABLE_INDEXRBN);
262 cpl_table_get_data_int(target_table->table, MOO_TARGET_TABLE_INDEXTARG);
263 const int *spectrot =
264 cpl_table_get_data_int_const(target_table->table,
265 MOO_TARGET_TABLE_SPECTRO);
266 const char *trans_colnames[] = { MOO_TARGET_TABLE_TRANSRI,
267 MOO_TARGET_TABLE_TRANSYJ,
268 MOO_TARGET_TABLE_TRANSH };
270 for (
int i = 0; i < 3; i++) {
273 if (sci_single != NULL) {
274 const char *trans_colname = trans_colnames[i];
277 cpl_table_get_data_float(target_table->table, trans_colname);
286 cpl_image *img = hdrl_image_get_image(himg);
287 cpl_image *err = hdrl_image_get_error(himg);
288 int nx = cpl_image_get_size_x(img);
290 for (
int f = 0; f < nbtarget; f++) {
291 int idrbn = idrbnt[f];
292 int idtarg = idtargt[f];
293 double trans = transt[f];
294 int spectro = spectrot[f];
296 if (!isnan(trans) && trans > 0) {
299 if (tell_index > 0) {
301 _molecfit_data_create(crpix1, crval1, cd1_1, img,
302 err, idtarg, tell_img,
305 mf_calctrans_correct_spectrum(
306 mdata, MF_PARAMETERS_TRANSMISSION_TRUE);
307#if MOO_DEBUG_CORRECT_TELL
309 char *name = cpl_sprintf(
"test_%d.fits", idrbn);
310 cpl_table_save(mdata, NULL, NULL, name,
316 for (
int x = 0; x < nx; x++) {
318 cpl_table_get_double(mdata,
319 MOO_CORRECT_TELL_CFLUX, x,
322 cpl_table_get_double(mdata,
323 MOO_CORRECT_TELL_CDFLUX, x,
325 cpl_image_set(img, x + 1, idtarg, flux_v);
326 cpl_image_set(err, x + 1, idtarg, err_v);
329 cpl_table_delete(mdata);
332 cpl_msg_info(__func__,
333 "no telluric correction for %s idrbn %d",
341 if (!cpl_errorstate_is_equal(prestate)) {
342 cpl_msg_error(__func__,
"Error in correct telluric");
343 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
345 return CPL_ERROR_NONE;
#define MOO_BADPIX_OUTSIDE_DATA_RANGE
hdrl_image * moo_rbn_single_get_image(moo_rbn_single *self)
Get image of RBN_SINGLE.
cpl_propertylist * moo_rbn_single_get_header(moo_rbn_single *self)
Get header of rbn single.
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_propertylist * moo_rbn_get_primary_header(moo_rbn *self)
Get the PRIMARY HEADER in RBN.
cpl_table * moo_rbn_get_fibre_table(moo_rbn *self)
Get the FIBRE TABLE in RBN.
hdrl_image * moo_sci_single_get_image(moo_sci_single *self)
Get image of SCI_SINGLE.
cpl_propertylist * moo_sci_single_get_header(moo_sci_single *self)
Get header of sci single.
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.
moo_target_table * moo_sci_get_target_table(moo_sci *self)
Get the target table of SCI file.
int moo_telluric_get_index(moo_telluric *self, int idrbn, int fspectro, const char *fband)
Get the index of the telluric for a given indexrbn.
const char * moo_telluric_get_band(moo_detector_type type)
Get the band of the telluric
cpl_image * moo_telluric_get_image(moo_telluric *self, moo_detector_type type)
Get a telluric image from TELLURIC.
cpl_error_code moo_correct_tell(moo_rbn *rbn, moo_telluric *tell)
Apply the telluric correction to 1D rebinned spectra.
cpl_error_code moo_correct_tell_science(moo_sci *sci, moo_telluric *tell)
Apply the telluric correction to SCI.
double moo_pfits_get_cd1_1(const cpl_propertylist *plist)
find out the CD1_1 value
double moo_pfits_get_crval1(const cpl_propertylist *plist)
find out the CRVAL1 value
double moo_pfits_get_crpix1(const cpl_propertylist *plist)
find out the CRPIX1 value
cpl_error_code moo_qc_set_is_tellcor(cpl_propertylist *plist, cpl_boolean val)
Set the QC.IS.TELLCOR value.
the different type of detectors