27 #include "muse_cplwrappers.h" 28 #include "muse_data_format_z.h" 65 const cpl_image *aLsfImage,
68 cpl_size n_lines = cpl_table_get_nrow(aLines);
70 double l_min = aLsfWCS->crval1 + aLsfWCS->cd11 * (1 - aLsfWCS->crpix1),
71 l_max = aLsfWCS->crval1
72 + aLsfWCS->cd11 * (cpl_image_get_size_x(aLsfImage) - aLsfWCS->crpix1);
73 cpl_array *spectrum = cpl_array_new(cpl_array_get_size(aLambda),
75 cpl_array_fill_window(spectrum, 0, cpl_array_get_size(aLambda), 0.0);
76 for (i_line = 0; i_line < n_lines; i_line++) {
77 double l_lambda = cpl_table_get(aLines,
"lambda", i_line, NULL);
78 double l_flux = cpl_table_get(aLines,
"flux", i_line, NULL);
84 cpl_array *l0 = cpl_array_extract(aLambda, imin, imax-imin+1);
85 cpl_array_subtract_scalar(l0, l_lambda);
87 cpl_array_multiply_scalar(l0, l_flux);
101 static cpl_error_code
102 muse_sky_subtract_lines_slice(
muse_pixtable *aPixtable, cpl_table *aLines,
103 cpl_image *aLsfImage,
muse_wcs *aLsfWCS)
105 cpl_propertylist *order = cpl_propertylist_new();
107 cpl_table_sort(aPixtable->
table, order);
108 cpl_propertylist_delete(order);
113 cpl_array *lambda = NULL;
115 == CPL_TYPE_DOUBLE) {
120 "lambda_double", CPL_TYPE_DOUBLE);
124 if ((aLines != NULL) && (aLsfImage != NULL) && (aLsfWCS != NULL)) {
127 cpl_array_subtract(data, spectrum);
128 cpl_array_delete(spectrum);
131 cpl_array_unwrap(data);
132 cpl_array_unwrap(lambda);
133 if (cpl_table_has_column(aPixtable->
table,
"lambda_double")) {
134 cpl_table_erase_column(aPixtable->
table,
"lambda_double");
137 return CPL_ERROR_NONE;
153 cpl_ensure_code(aPixtable != NULL, CPL_ERROR_NULL_INPUT);
154 cpl_ensure_code(aPixtable->
table != NULL, CPL_ERROR_NULL_INPUT);
156 CPL_ERROR_DATA_NOT_FOUND);
157 cpl_ensure_code(aLines != NULL, CPL_ERROR_NULL_INPUT);
158 cpl_ensure_code(aLsfCube != NULL, CPL_ERROR_NULL_INPUT);
164 cpl_error_code rc[n_slices];
165 cpl_msg_info(__func__,
"Starting sky subtraction of %"CPL_SIZE_FORMAT
166 " slices", n_slices);
167 cpl_boolean debug = getenv(
"MUSE_DEBUG_SKY")
168 && atoi(getenv(
"MUSE_DEBUG_SKY")) > 0;
169 #pragma omp parallel for default(none) \ 170 shared(aLsfCube, aLines, debug, n_slices, slice_pixtable, rc) 171 for (i_slice = 0; i_slice < n_slices; i_slice++) {
174 (uint32_t) cpl_table_get_int(slice_pt->
table,
178 if ((aLsfCube[ifu-1] == NULL) && (aLines != NULL)) {
179 cpl_msg_warning(__func__,
180 "No LSF params for slice #%i.%i." 181 " Ignoring lines in sky subtraction for this slice.",
183 rc[i_slice] = CPL_ERROR_NONE;
189 cpl_msg_debug(__func__,
"Sky subtraction of %"CPL_SIZE_FORMAT
" pixels for" 190 " slice #%i.%i (%i)", nrows, ifu, slice, (
int)i_slice+1);
192 cpl_image *lsfImage = cpl_imagelist_get(aLsfCube[ifu-1]->img, slice-1);
193 rc[i_slice] = muse_sky_subtract_lines_slice(slice_pt,
195 aLsfCube[ifu-1]->wcs);
199 for (i_slice = 0; i_slice < n_slices; i_slice++) {
200 if (rc[i_slice] != CPL_ERROR_NONE) {
204 return CPL_ERROR_NONE;
218 cpl_ensure_code(aPixtable != NULL, CPL_ERROR_NULL_INPUT);
219 cpl_ensure_code(aPixtable->
table != NULL, CPL_ERROR_NULL_INPUT);
221 == CPL_ERROR_NONE, CPL_ERROR_DATA_NOT_FOUND);
222 cpl_ensure_code(aSpectrum != NULL, CPL_ERROR_NULL_INPUT);
223 cpl_ensure_code(cpl_table_has_column(aSpectrum,
"lambda") &&
224 cpl_table_has_column(aSpectrum,
"flux"),
225 CPL_ERROR_DATA_NOT_FOUND);
228 double lmin = cpl_table_get_column_min(aSpectrum,
"lambda");
229 double lmax = cpl_table_get_column_max(aSpectrum,
"lambda");
230 cpl_msg_info(__func__,
"Cutting data to %.3f...%.3f Angstrom for sky " 231 "subtraction (range of continuum)", lmin, lmax);
237 MUSE_PIXTABLE_OPERATION_SUBTRACT);
238 cpl_array_unwrap(lambda);
239 cpl_array_unwrap(flux);
241 return CPL_ERROR_NONE;
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.
A structure containing a spatial two-axis WCS.
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
Data cube/stacked image list containing the LSF for one IFU.
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.
#define MUSE_PIXTABLE_DATA
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_error_code muse_sky_subtract_continuum(muse_pixtable *aPixtable, cpl_table *aSpectrum)
Subtract sky continuum from pixel table.
cpl_error_code muse_lsf_apply(const cpl_image *aLsfImage, const muse_wcs *aWCS, cpl_array *aVal, double aLambda)
Apply the LSF to a number of data points of one slice.
cpl_error_code muse_cplarray_add_window(cpl_array *aDest, cpl_size aStart, const cpl_array *aArray)
Add the value of an array to a window of a table column.
#define MUSE_PIXTABLE_ORIGIN
cpl_array * muse_sky_lines_spectrum(const cpl_array *aLambda, cpl_table *aLines, const cpl_image *aLsfImage, const muse_wcs *aLsfWCS)
Create spectrum for a single slice.
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.
#define MUSE_PIXTABLE_LAMBDA
cpl_error_code muse_sky_subtract_lines(muse_pixtable *aPixtable, cpl_table *aLines, muse_lsf_cube **aLsfCube)
Subtract sky lines from a pixtable.
cpl_error_code muse_pixtable_spectrum_apply(muse_pixtable *aPixtable, const cpl_array *aLambdas, const cpl_array *aFlux, muse_pixtable_operation aOperation)
Apply a spectrum given by two arrays with an operation to a pixel table.
cpl_size muse_cplarray_find_sorted(const cpl_array *aArray, double aValue)
Find a row in an array.