74 cpl_error_code status = CPL_ERROR_NONE;
75 cpl_table *groups, *linetab;
80 groups = cpl_table_new(0);
81 if ((status =
sc_lines(groups, parlist)) != CPL_ERROR_NONE) {
82 cpl_table_delete(groups);
91 linetab = cpl_table_new(0);
94 cpl_table_delete(linetab);
95 status = cpl_error_get_code();
96 if (status != CPL_ERROR_NONE) {
97 sprintf(errtxt,
"%s: error while separating lines and continuum of "
98 "science spectrum", SC_ERROR_EIS_TXT);
99 cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_EIS,
"%s", errtxt);
105 linetab = cpl_table_new(0);
108 cpl_table_delete(linetab); linetab = NULL;
109 if (status != CPL_ERROR_NONE) {
110 sprintf(errtxt,
"%s: error while separating lines and continuum of "
111 "sky spectrum", SC_ERROR_EIS_TXT);
112 cpl_error_set_message(cpl_func, (cpl_error_code)SC_ERROR_EIS,
"%s", errtxt);
113 cpl_table_delete(groups);
119 status =
sc_skycorr_fit(scispec, skyspec, groups, parlist, product_depth);
120 if (status != CPL_ERROR_NONE) {
121 cpl_table_delete(groups);
126 cpl_table_delete(groups);
135 cpl_parameterlist *parlist,
136 const cpl_table *groups)
179 cpl_error_code status = CPL_ERROR_NONE;
183 int it = 0, i = 0, n = 10, nrow = 0, j = 0, niso = 0, search = 0;
184 double fwhm0 = 0., fwhm = 1000., eps = 1e-2, tmp = 0., rms = 0.;
185 double fluxlim = 0., minfluxlim = 0.005, maxfluxlim = 0.1;
192 p = cpl_parameterlist_find(parlist,
"fwhm");
193 fwhm0 = cpl_parameter_get_double(p);
196 p = cpl_parameterlist_find(parlist,
"iteration");
197 it = cpl_parameter_get_int(p);
201if (cpl_error_get_code() != CPL_ERROR_NONE) {
202 return cpl_error_get_code();
205 p = cpl_parameterlist_find(parlist,
"ltol");
206 eps = cpl_parameter_get_double(p);
209 for (tmp = fwhm, i = 0; i < n; i++, tmp = fwhm) {
212 if (status != CPL_ERROR_NONE) {
218 if (status != CPL_ERROR_NONE) {
223 nrow = cpl_table_get_nrow(linetab);
224 for (j = 0, niso = 0; j < nrow; j++) {
225 if (cpl_table_get_int(linetab,
"isol_flag", j, NULL) != 0) {
235 cpl_msg_warning(cpl_func,
"No isolated lines found -> "
236 "Take initial FWHM");
241 status =
sc_fwhmest(&fwhm, &rms, spec, linetab, parlist);
242 if (status != CPL_ERROR_NONE) {
247 p = cpl_parameterlist_find(parlist,
"fwhm");
248 cpl_parameter_set_double(p, fwhm);
251 if (fabs((fwhm - tmp) / tmp) < eps) {
257 mask = cpl_array_new(0, CPL_TYPE_INT);
259 if (status != CPL_ERROR_NONE) {
264 p = cpl_parameterlist_find(parlist,
"fluxlim");
265 fluxlim = cpl_parameter_get_double(p);
269 fluxlim = minfluxlim;
277 if (status != CPL_ERROR_NONE) {
278 cpl_array_delete(mask);
285 if (status != CPL_ERROR_NONE) {
286 cpl_array_delete(mask);
292 }
while (
sc_contsub_check(spec) != 0 && fluxlim <= maxfluxlim && search == 1);
294 status = cpl_error_get_code();
295 if (status != CPL_ERROR_NONE) {
307 if (status != CPL_ERROR_NONE) {
312 cpl_array_delete(mask); mask = NULL;
323 if (status != CPL_ERROR_NONE) {
331 cpl_table *groups, cpl_parameterlist *parlist,
356 cpl_error_code status = CPL_ERROR_NONE;
363 cpl_table_new_column(skyspec,
"mlambda", CPL_TYPE_DOUBLE);
364 cpl_table_new_column(skyspec,
"mlflux", CPL_TYPE_DOUBLE);
365 if (cpl_table_has_column(skyspec,
"dflux") == 1) {
366 cpl_table_new_column(skyspec,
"mdflux", CPL_TYPE_DOUBLE);
368 cpl_table_new_column(skyspec,
"mweight", CPL_TYPE_DOUBLE);
369 cpl_table_new_column(skyspec,
"mpix", CPL_TYPE_INT);
370 cpl_table_new_column(skyspec,
"dpix", CPL_TYPE_DOUBLE);
371 cpl_table_new_column(skyspec,
"frat", CPL_TYPE_DOUBLE);
374 cpl_table_new_column(scispec,
"mcflux", CPL_TYPE_DOUBLE);
375 cpl_table_new_column(scispec,
"mlflux", CPL_TYPE_DOUBLE);
376 cpl_table_new_column(scispec,
"mflux", CPL_TYPE_DOUBLE);
377 if (cpl_table_has_column(skyspec,
"dflux") == 1) {
378 cpl_table_new_column(scispec,
"mdflux", CPL_TYPE_DOUBLE);
380 if (cpl_table_has_column(skyspec,
"mask") == 1) {
381 cpl_table_new_column(scispec,
"mmask", CPL_TYPE_INT);
383 cpl_table_new_column(scispec,
"mweight", CPL_TYPE_DOUBLE);
384 cpl_table_new_column(scispec,
"sigclip", CPL_TYPE_INT);
385 cpl_table_new_column(scispec,
"cweight", CPL_TYPE_DOUBLE);
386 cpl_table_new_column(scispec,
"dev", CPL_TYPE_DOUBLE);
389 nsci = cpl_table_get_nrow(scispec);
390 cpl_table_fill_column_window(scispec,
"sigclip", 0, nsci, 1);
393 fitpar = cpl_table_new(0);
397 if ((status =
sc_weights(skyspec, fitpar, groups, parlist)) !=
399 cpl_table_delete(fitpar);
407 status =
sc_mpfit(&result, scispec, skyspec, fitpar, parlist);
425 if ((product_depth == 3) && (result.status != 1)) {
426 cpl_msg_debug(cpl_func,
">>>>> skycorr fit result: %d", result.status);
443 cpl_table_delete(fitpar);
472 cpl_error_code status = CPL_ERROR_NONE;
474 int *mmask = NULL, *mask = NULL, *scmask = NULL;
475 double *mweight = NULL, *dflux = NULL, *mdflux = NULL, *scdflux = NULL;
478 nrow = cpl_table_get_nrow(scispec);
481 cpl_table_fill_column_window(scispec,
"mflux", 0, nrow, 0.);
482 cpl_table_add_columns(scispec,
"mflux",
"mcflux");
483 cpl_table_add_columns(scispec,
"mflux",
"mlflux");
486 if (cpl_table_has_column(scispec,
"mask") == 1) {
487 cpl_table_fill_column_window(scispec,
"mmask", 0, nrow, 0);
488 mweight = cpl_table_get_data_double(scispec,
"mweight");
489 mmask = cpl_table_get_data_int(scispec,
"mmask");
490 for (i = 0; i < nrow; i++) {
491 if (mweight[i] == 0.) {
501 cpl_table_duplicate_column(scispec,
"scflux", scispec,
"flux");
505 if (cpl_table_has_column(scispec,
"dflux") == 1) {
506 cpl_table_duplicate_column(scispec,
"scdflux", scispec,
"dflux");
511 if (cpl_table_has_column(scispec,
"mask") == 1) {
512 cpl_table_duplicate_column(scispec,
"scmask", scispec,
"mask");
516 if ((status = cpl_error_get_code()) != CPL_ERROR_NONE) {
521 cpl_table_subtract_columns(scispec,
"scflux",
"mflux");
525 if (cpl_table_has_column(scispec,
"dflux") == 1) {
526 dflux = cpl_table_get_data_double(scispec,
"dflux");
527 mdflux = cpl_table_get_data_double(scispec,
"mdflux");
528 scdflux = cpl_table_get_data_double(scispec,
"scdflux");
529 for (i = 0; i < nrow; i++) {
530 scdflux[i] = sqrt(dflux[i] * dflux[i] + mdflux[i] * mdflux[i]);
535 if (cpl_table_has_column(scispec,
"mask") == 1) {
536 mask = cpl_table_get_data_int(scispec,
"mask");
537 mmask = cpl_table_get_data_int(scispec,
"mmask");
538 scmask = cpl_table_get_data_int(scispec,
"scmask");
539 for (i = 0; i < nrow; i++) {
540 if (mask[i] == 1 && mmask[i] == 1) {
548 return cpl_error_get_code();
cpl_error_code sc_basic_col2arr(cpl_array *arr, const cpl_table *tab, const char *colname)
cpl_error_code sc_basic_arr2col(cpl_table *tab, const char *colname, const cpl_array *arr)
int sc_contsub_check(cpl_table *spec)
cpl_error_code sc_contsub_skipthermir(cpl_table *spec)
cpl_error_code sc_contsub_identcont(cpl_table *spec, const cpl_table *groups, const cpl_table *linetab, const double fluxlim, const cpl_parameterlist *parlist)
cpl_error_code sc_contsub(cpl_table *spec)
cpl_error_code sc_fwhmest(double *fwhm, double *rms, cpl_table *spec, cpl_table *lines, const cpl_parameterlist *parlist)
cpl_error_code sc_lines(cpl_table *groups, cpl_parameterlist *parlist)
cpl_error_code sc_mpfit(mp_result *result, cpl_table *scispec, cpl_table *skyspec, cpl_table *fitpar, const cpl_parameterlist *parlist)
cpl_error_code sc_mpfit_freememresult(mp_result *result)
cpl_error_code sc_skycorr(cpl_parameterlist *parlist, cpl_table *scispec, cpl_table *skyspec, int product_depth)
cpl_error_code sc_skycorr_subcont(cpl_table *spec, cpl_table *linetab, cpl_parameterlist *parlist, const cpl_table *groups)
cpl_error_code sc_skycorr_fit(cpl_table *scispec, cpl_table *skyspec, cpl_table *groups, cpl_parameterlist *parlist, int product_depth)
cpl_error_code sc_skycorr_subsky(cpl_table *scispec)
void sc_specdiss_init_linetab(cpl_table *linetab)
cpl_error_code sc_specdiss_find_emissionlines(cpl_table *input_spectrum, cpl_table *linetab, cpl_parameterlist *parlist, const cpl_table *groups)
cpl_error_code sc_weights(cpl_table *skyspec, cpl_table *fitpar, cpl_table *groups, cpl_parameterlist *parlist)