27 #include "muse_cplwrappers.h"
28 #include "muse_data_format_z.h"
64 cpl_array *lambda = NULL;
65 if (cpl_table_get_column_type(aPixtable->
table, MUSE_PIXTABLE_LAMBDA)
68 MUSE_PIXTABLE_LAMBDA);
70 cpl_table_cast_column(aPixtable->
table, MUSE_PIXTABLE_LAMBDA,
71 "lambda_double", CPL_TYPE_DOUBLE);
76 cpl_array *spectrum = NULL;
77 if ((aMaster->
lines != NULL) && (aLsf != NULL)) {
80 spectrum = cpl_array_new(cpl_array_get_size(lambda), CPL_TYPE_DOUBLE);
81 cpl_array_fill_window(spectrum, 0, cpl_array_get_size(spectrum), 0.0);
88 cpl_array_add(spectrum, continuum);
89 cpl_array_delete(continuum);
92 cpl_array_unwrap(lambda);
93 if (cpl_table_has_column(aPixtable->
table,
"lambda_double")) {
94 cpl_table_erase_column(aPixtable->
table,
"lambda_double");
115 cpl_propertylist *order = cpl_propertylist_new();
116 cpl_propertylist_append_bool(order, MUSE_PIXTABLE_LAMBDA, CPL_FALSE);
117 cpl_table_sort(aPixtable->
table, order);
118 cpl_propertylist_delete(order);
124 cpl_array_subtract(data, spectrum);
127 for (ii = 0; ii < cpl_array_get_size(data); ii++) {
128 if (!cpl_array_is_valid(spectrum, ii)) {
129 cpl_table_set_invalid(aPixtable->
table, MUSE_PIXTABLE_DATA, ii);
132 cpl_array_unwrap(data);
133 cpl_array_delete(spectrum);
136 return CPL_ERROR_NONE;
159 cpl_ensure_code(aPixtable != NULL, CPL_ERROR_NULL_INPUT);
160 cpl_ensure_code(aPixtable->
table != NULL, CPL_ERROR_NULL_INPUT);
162 CPL_ERROR_DATA_NOT_FOUND);
163 cpl_ensure_code(aMaster != NULL, CPL_ERROR_NULL_INPUT);
165 return CPL_ERROR_NONE;
167 if (aMaster->
lines != NULL) {
168 cpl_ensure_code(aLsf != NULL, CPL_ERROR_NULL_INPUT);
173 double lmin = cpl_table_get_column_min(aMaster->
continuum,
"lambda"),
174 lmax = cpl_table_get_column_max(aMaster->
continuum,
"lambda");
175 cpl_msg_info(__func__,
"Cutting data to %.3f...%.3f Angstrom for sky "
176 "subtraction (range of continuum)", lmin, lmax);
183 cpl_msg_info(__func__,
"Starting sky subtraction of %"CPL_SIZE_FORMAT
" slices",
185 #pragma omp parallel for default(none) \
186 shared(aLsf, aMaster, n_slices, slice_pixtable)
187 for (i_slice = 0; i_slice < n_slices; i_slice++) {
189 = (uint32_t)cpl_table_get_int(slice_pixtable[i_slice]->table,
190 MUSE_PIXTABLE_ORIGIN, 0, NULL);
194 if ((slice_params == NULL) && (aMaster->
lines != NULL)){
195 cpl_msg_warning(__func__,
"No LSF params for slice #%i.%i."
196 " Ignoring lines in sky subtraction for this slice.",
201 cpl_msg_debug(__func__,
"Sky subtraction of %li pixels for slice #%i.%i",
202 (
long)nrows, ifu, slice);
203 cpl_errorstate prestate = cpl_errorstate_get();
205 if (!cpl_errorstate_is_equal(prestate)) {
206 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
207 cpl_errorstate_set(prestate);
217 MUSE_HDR_PT_SKYSUB_COMMENT);
219 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.
cpl_size muse_pixtable_get_nrow(muse_pixtable *aPixtable)
get the number of rows within the pixel table
muse_pixtable ** muse_pixtable_extracted_get_slices(muse_pixtable *aPixtable)
Extract one pixel table per IFU and slice.
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
static cpl_array * muse_slice_get_skyspectrum(muse_pixtable *aPixtable, muse_sky_master *aMaster, muse_lsf_params *aLsf)
Create a sky spectrum from a parametrization.
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.