27 #include "muse_cplwrappers.h"
28 #include "muse_data_format_z.h"
66 cpl_array *lambda = NULL;
67 if (cpl_table_get_column_type(aPixtable->
table, MUSE_PIXTABLE_LAMBDA)
70 MUSE_PIXTABLE_LAMBDA);
72 cpl_table_cast_column(aPixtable->
table, MUSE_PIXTABLE_LAMBDA,
73 "lambda_double", CPL_TYPE_DOUBLE);
78 cpl_array *spectrum = NULL;
79 if ((aMaster->
lines != NULL) && (aLsf != NULL)) {
82 spectrum = cpl_array_new(cpl_array_get_size(lambda), CPL_TYPE_DOUBLE);
83 cpl_array_fill_window(spectrum, 0, cpl_array_get_size(spectrum), 0.0);
90 cpl_array_add(spectrum, continuum);
91 cpl_array_delete(continuum);
94 cpl_array_unwrap(lambda);
95 if (cpl_table_has_column(aPixtable->
table,
"lambda_double")) {
96 cpl_table_erase_column(aPixtable->
table,
"lambda_double");
118 cpl_propertylist *order = cpl_propertylist_new();
119 cpl_propertylist_append_bool(order, MUSE_PIXTABLE_LAMBDA, CPL_FALSE);
120 cpl_table_sort(aPixtable->
table, order);
121 cpl_propertylist_delete(order);
123 cpl_array *spectrum = muse_slice_get_skyspectrum(aPixtable, aMaster, aLsf);
127 cpl_array_subtract(data, spectrum);
130 for (ii = 0; ii < cpl_array_get_size(data); ii++) {
131 if (!cpl_array_is_valid(spectrum, ii)) {
132 cpl_table_set_invalid(aPixtable->
table, MUSE_PIXTABLE_DATA, ii);
135 cpl_array_unwrap(data);
136 cpl_array_delete(spectrum);
139 return CPL_ERROR_NONE;
162 cpl_ensure_code(aPixtable != NULL, CPL_ERROR_NULL_INPUT);
163 cpl_ensure_code(aPixtable->
table != NULL, CPL_ERROR_NULL_INPUT);
165 CPL_ERROR_DATA_NOT_FOUND);
166 cpl_ensure_code(aMaster != NULL, CPL_ERROR_NULL_INPUT);
168 return CPL_ERROR_NONE;
170 if (aMaster->
lines != NULL) {
171 cpl_ensure_code(aLsf != NULL, CPL_ERROR_NULL_INPUT);
176 double lmin = cpl_table_get_column_min(aMaster->
continuum,
"lambda"),
177 lmax = cpl_table_get_column_max(aMaster->
continuum,
"lambda");
178 cpl_msg_info(__func__,
"Cutting data to %.3f...%.3f Angstrom for sky "
179 "subtraction (range of continuum)", lmin, lmax);
186 cpl_msg_info(__func__,
"Starting sky subtraction of %"CPL_SIZE_FORMAT
" slices",
188 #pragma omp parallel for default(none) \
189 shared(aLsf, aMaster, n_slices, slice_pixtable)
190 for (i_slice = 0; i_slice < n_slices; i_slice++) {
192 = (uint32_t)cpl_table_get_int(slice_pixtable[i_slice]->table,
193 MUSE_PIXTABLE_ORIGIN, 0, NULL);
197 if ((slice_params == NULL) && (aMaster->
lines != NULL)){
198 cpl_msg_warning(__func__,
"No LSF params for slice #%i.%i."
199 " Ignoring lines in sky subtraction for this slice.",
204 cpl_msg_debug(__func__,
"Sky subtraction of %li pixels for slice #%i.%i",
205 (
long)nrows, ifu, slice);
206 cpl_errorstate prestate = cpl_errorstate_get();
208 if (!cpl_errorstate_is_equal(prestate)) {
209 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
210 cpl_errorstate_set(prestate);
220 MUSE_HDR_PT_SKYSUB_COMMENT);
222 return CPL_ERROR_NONE;
cpl_array * muse_cplarray_interpolate_table_linear(const cpl_array *aTargetAbscissa, const cpl_table *aSrcTable, const char *aSrcAbscissa, const char *aSrcOrdinate)
Linear interpolation of a 1d column.
void muse_pixtable_extracted_delete(muse_pixtable **aPixtables)
Delete a pixel table array.
unsigned short muse_pixtable_origin_get_slice(uint32_t aOrigin)
Get the slice number from the encoded 32bit origin number.
cpl_size muse_pixtable_extracted_get_size(muse_pixtable **aPixtables)
Get the size of an array of extracted pixel tables.
muse_pixtable ** muse_pixtable_extracted_get_slices(muse_pixtable *aPixtable)
Extract one pixel table per IFU and slice.
cpl_size muse_pixtable_get_nrow(const muse_pixtable *aPixtable)
get the number of rows within the pixel table
Structure to hold the MASTER SKY result.
muse_lsf_params * muse_lsf_params_get(muse_lsf_params **aParams, int aIFU, int aSlice)
Get the slice LSF parameters for one slice.
cpl_table * table
The pixel table.
cpl_error_code muse_cpltable_check(const cpl_table *aTable, const muse_cpltable_def *aDef)
Check whether the table contains the fields of the definition.
cpl_error_code muse_pixtable_restrict_wavelength(muse_pixtable *aPixtable, double aLow, double aHigh)
Restrict a pixel table to a certain wavelength range.
Structure definition of MUSE pixel table.
cpl_array * muse_cpltable_extract_column(cpl_table *aTable, const char *aColumn)
Create an array from a section of a column.
cpl_table * lines
Table of Atmospheric emission lines and their intensities.
#define MUSE_HDR_PT_SKYSUB
unsigned short muse_pixtable_origin_get_ifu(uint32_t aOrigin)
Get the IFU number from the encoded 32bit origin number.
const muse_cpltable_def muse_pixtable_def[]
MUSE pixel table definition.
cpl_array * muse_sky_apply_lsf(const cpl_array *, const cpl_table *, const muse_lsf_params *)
Apply the LSF parameters to a spectrum.
cpl_table * continuum
Continuum flux table
Structure definition of detector (slice) parameters.
cpl_error_code muse_sky_subtract_pixtable(muse_pixtable *aPixtable, muse_sky_master *aMaster, muse_lsf_params **aLsf)
Subtract the sky spectrum from the "data" column of a pixel table.
cpl_error_code muse_sky_subtract_slice(muse_pixtable *aPixtable, muse_sky_master *aMaster, muse_lsf_params *aLsf)
Subtract the sky spectrum from the "data" column of a pixel table for one slice.
cpl_propertylist * header
The FITS header.