32 #include "muse_lsf_z.h"
38 muse_lsf_save_lsf_params(cpl_propertylist *aHeader,
42 cpl_error_code r = CPL_ERROR_NONE;
43 if (aSlicePars != NULL) {
46 CPL_FRAME_TYPE_TABLE);
48 const char *filename = cpl_frame_get_filename(frame);
49 cpl_msg_info(__func__,
"Saving LSF profile as %s", filename);
50 char *channel = cpl_sprintf(
"CHAN%02d", aIFU);
51 cpl_propertylist_update_string(aHeader,
"EXTNAME", channel);
53 r = cpl_propertylist_save(aHeader, filename, CPL_IO_CREATE);
55 if (r == CPL_ERROR_NONE) {
56 cpl_frameset_insert(aProcessing->
outframes, frame);
58 cpl_frame_delete(frame);
66 muse_lsf_compute_slice_lsf(cpl_table *aLines,
muse_pixtable *aPixtable,
70 uint32_t origin = (uint32_t)cpl_table_get_int(aPixtable->
table,
71 MUSE_PIXTABLE_ORIGIN, 0, NULL);
76 cpl_msg_info(__func__,
"processing slice %hu.%hu with %"CPL_SIZE_FORMAT
" rows",
77 i_ifu, i_slice, nrows);
79 cpl_propertylist *order = cpl_propertylist_new();
80 cpl_propertylist_append_bool(order, MUSE_PIXTABLE_LAMBDA, CPL_FALSE);
81 cpl_table_sort(aPixtable->
table, order);
82 cpl_propertylist_delete(order);
84 cpl_array *lambda = NULL;
85 if (cpl_table_get_column_type(aPixtable->
table, MUSE_PIXTABLE_LAMBDA)
88 MUSE_PIXTABLE_LAMBDA);
90 cpl_table_cast_column(aPixtable->
table, MUSE_PIXTABLE_LAMBDA,
91 "lambda_double", CPL_TYPE_DOUBLE);
100 aFirstguess, aMaxIter,
102 lsf->slice = i_slice;
105 if (cpl_table_has_column(aPixtable->
table,
"lambda_double")) {
106 cpl_table_erase_column(aPixtable->
table,
"lambda_double");
109 cpl_array_unwrap(lambda);
110 cpl_array_unwrap(data);
111 cpl_array_unwrap(stat);
117 muse_lsf_compute_lsf(cpl_table *aLines,
muse_pixtable *aPixtable,
127 #pragma omp parallel for default(none) num_threads(2) \
128 shared(aFirstguess, aLines, aMaxIter, aSliceParams, lsfParams, \
129 n_slices, slice_pixtable)
130 for (i_slice = 0; i_slice < n_slices; i_slice++) {
131 uint32_t origin = (uint32_t)cpl_table_get_int(slice_pixtable[i_slice]->table,
132 MUSE_PIXTABLE_ORIGIN, 0, NULL);
137 cpl_errorstate prestate = cpl_errorstate_get();
138 lsfParams[i_slice] = muse_lsf_compute_slice_lsf(aLines,
139 slice_pixtable[i_slice],
140 firstguess_slice, aMaxIter,
142 if (!cpl_errorstate_is_equal(prestate)) {
143 cpl_msg_error(__func__,
"While processing slice %hu.%hu:", ifu, slice);
144 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
145 cpl_errorstate_set(prestate);
162 static cpl_error_code
163 muse_lsf_qc(cpl_propertylist *aHeader,
const muse_lsf_params **aSlicePars)
165 cpl_ensure_code(aHeader && aSlicePars, CPL_ERROR_NULL_INPUT);
167 #define LSF_QC_DLBDA 150.
172 lbda2 = kMuseNominalLambdaMax;
173 int nsteps = (lbda2 - lbda1) / LSF_QC_DLBDA;
176 unsigned short nslice = 1;
178 for (slice = aSlicePars; *slice; slice++, nslice++) {
179 cpl_array *afwhm = cpl_array_new(nsteps + 1, CPL_TYPE_DOUBLE);
182 for (lambda = lbda1; lambda <= lbda2; lambda += LSF_QC_DLBDA, idx++) {
184 1000., 0.01, 1000., NULL);
185 cpl_array_set(afwhm, idx, fwhm);
187 char keyword[KEYWORD_LENGTH];
188 snprintf(keyword, KEYWORD_LENGTH,
"ESO QC LSF IFU%hhu SLICE%hu FWHM MEAN",
190 cpl_propertylist_append_float(aHeader, keyword, cpl_array_get_mean(afwhm));
191 snprintf(keyword, KEYWORD_LENGTH,
"ESO QC LSF IFU%hhu SLICE%hu FWHM STDEV",
193 cpl_propertylist_append_float(aHeader, keyword, cpl_array_get_stdev(afwhm));
194 snprintf(keyword, KEYWORD_LENGTH,
"ESO QC LSF IFU%hhu SLICE%hu FWHM MIN",
196 cpl_propertylist_append_float(aHeader, keyword, cpl_array_get_min(afwhm));
197 snprintf(keyword, KEYWORD_LENGTH,
"ESO QC LSF IFU%hhu SLICE%hu FWHM MAX",
199 cpl_propertylist_append_float(aHeader, keyword, cpl_array_get_max(afwhm));
200 cpl_array_delete(afwhm);
202 return CPL_ERROR_NONE;
218 cpl_table *tracetable =
muse_table_load(aProcessing, MUSE_TAG_TRACE_TABLE,
220 cpl_table *wavecaltable =
muse_table_load(aProcessing, MUSE_TAG_WAVECAL_TABLE,
223 cpl_table *linelist =
muse_table_load(aProcessing, MUSE_TAG_LINE_CATALOG, 0);
225 MUSE_TAG_LINE_CATALOG);
227 cpl_propertylist_delete(linehead);
228 if (!tracetable || !wavecaltable || !linelist || rc) {
229 cpl_table_delete(tracetable);
230 cpl_table_delete(wavecaltable);
231 cpl_table_delete(linelist);
241 cpl_ensure(images, cpl_error_get_code(), -1);
244 char *pname = cpl_sprintf(
"muse.%s.combine", aProcessing->
name);
245 cpl_parameter *param = cpl_parameterlist_find(aProcessing->
parameters, pname);
246 char *porig = cpl_strdup(cpl_parameter_get_string(param));
247 cpl_parameter_set_string(param,
"sum");
251 cpl_parameter_set_string(param, porig);
261 cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_INPUT,
"pixel table "
265 cpl_table_delete(wavecaltable);
266 cpl_table_delete(tracetable);
267 cpl_table_delete(linelist);
273 cpl_table_duplicate_column(pixtable->
table,
"orig_data", pixtable->
table,
279 cpl_table_unselect_all(linelist);
280 cpl_table_or_selected_int(linelist, MUSE_LINE_CATALOG_QUALITY,
282 cpl_table_or_selected_float(linelist,
"flux", CPL_NOT_GREATER_THAN, 0.);
283 cpl_table_erase_selected(linelist);
285 cpl_propertylist *flux_sort = cpl_propertylist_new();
286 cpl_propertylist_append_bool(flux_sort,
"flux", CPL_TRUE);
287 cpl_table_sort(linelist, flux_sort);
288 cpl_propertylist_delete(flux_sort);
290 if (nrows < cpl_table_get_nrow(linelist)) {
291 cpl_table_erase_window(linelist, nrows, cpl_table_get_nrow(linelist));
309 muse_lsf_params **lsf = muse_lsf_compute_lsf(linelist, pixtable, firstguess,
310 40, slice_fit_params);
314 cpl_propertylist *header = cpl_propertylist_duplicate(pixtable->
header);
315 cpl_propertylist_erase_regexp(header, MUSE_HDR_PT_REGEXP
"|ESO QC|ESO DRS MUSE",
319 aProcessing, aParams->
nifu);
320 cpl_propertylist_delete(header);
332 cpl_table_delete(tracetable);
333 cpl_table_delete(wavecaltable);
334 cpl_table_delete(linelist);
Structure definition for a collection of muse_images.
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
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.
unsigned char muse_utils_get_ifu(const cpl_propertylist *aHeaders)
Find out the IFU/channel from which this header originated.
muse_imagelist * muse_basicproc_combine_images_lampwise(muse_processing *aProcessing, unsigned char aIFU, muse_basicproc_params *aBPars, cpl_frameset ***aLabeledFrames)
Combine several images into a lampwise image list.
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
cpl_error_code muse_lsf_params_save(const muse_lsf_params **aLsf, const char *aFile)
Save slice LSF parameters to the extension "slice" on disk.
muse_lsf_params * muse_lsf_params_fit(const cpl_array *aLambda, cpl_array *aData, const cpl_array *aStat, const cpl_table *aLines, muse_lsf_params *aFirstGuess, int aMaxIter, const muse_sky_fit_params *aFitParams)
Fit all entries of one slice.
muse_lsf_params * muse_lsf_params_get(muse_lsf_params **aParams, int aIFU, int aSlice)
Get the slice LSF parameters for one slice.
int nifu
IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in ...
void muse_imagelist_delete(muse_imagelist *aList)
Free the memory of the MUSE image list.
Structure to define which slice parameters are fit.
muse_basicproc_params * muse_basicproc_params_new(cpl_parameterlist *aParameters, const char *aPrefix)
Create a new structure of basic processing parameters.
muse_image * muse_combine_images(muse_combinepar *aCPars, muse_imagelist *aImages)
Combine several images into one.
void muse_sky_fit_params_delete(muse_sky_fit_params *)
Delete the fit parameter structure.
Structure definition of MUSE three extension FITS file.
cpl_table * table
The pixel table.
void muse_basicproc_params_delete(muse_basicproc_params *aBPars)
Free a structure of basic processing parameters.
int save_subtracted
Save the pixel table after the LSF subtraction.
void muse_combinepar_delete(muse_combinepar *aCPars)
Clear the combination parameters.
double muse_lsf_fwhm_lambda(const muse_lsf_params *aDP, double aLambda, double aFlux, double aSampling, unsigned int aLength, FILE *aOutstream)
Measure the FWHM of an LSF at a given wavelength.
Structure definition of MUSE pixel table.
cpl_frame * muse_processing_new_frame(muse_processing *aProcessing, int aIFU, cpl_propertylist *aHeader, const char *aTag, cpl_frame_type aType)
Create a new frame for a result file.
cpl_array * muse_cpltable_extract_column(cpl_table *aTable, const char *aColumn)
Create an array from a section of a column.
Structure to hold the parameters of the muse_lsf recipe.
int line_quality
Minimal quality flag in line catalog for selection.
muse_combinepar * muse_combinepar_new(cpl_parameterlist *aParameters, const char *aPrefix)
Create a new set of combination parameters.
muse_sky_fit_params * muse_sky_fit_params_new(cpl_boolean, cpl_boolean, cpl_size, cpl_size, cpl_size, cpl_size, cpl_size, cpl_size, cpl_size, cpl_size)
Create a new fit parameter structure.
muse_pixtable * muse_pixtable_create(muse_image *aImage, cpl_table *aTrace, cpl_table *aWave, cpl_table *aGeoTable)
Create the pixel table for one CCD.
unsigned short muse_pixtable_origin_get_ifu(uint32_t aOrigin)
Get the IFU number from the encoded 32bit origin number.
cpl_table * muse_table_load(muse_processing *aProcessing, const char *aTag, unsigned char aIFU)
load a table according to its tag and IFU/channel number
cpl_error_code muse_processing_save_table(muse_processing *aProcessing, int aIFU, void *aTable, cpl_propertylist *aHeader, const char *aTag, muse_table_type aType)
Save a computed table to disk.
Structure of basic processing parameters.
muse_lsf_params ** muse_processing_lsf_params_load(muse_processing *aProcessing, int aIFU)
Load slice LSF parameters.
cpl_propertylist * muse_propertylist_load(muse_processing *aProcessing, const char *aTag)
load a propertylist according to its tag
cpl_boolean muse_wave_lines_check(cpl_table *aTable, cpl_propertylist *aHeader)
Check that a LINE_CATALOG has the expected format.
Structure definition of detector (slice) parameters.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
muse_ins_mode muse_pfits_get_mode(const cpl_propertylist *aHeaders)
find out the observation mode
cpl_parameterlist * parameters
void muse_lsf_params_delete(muse_lsf_params **aParams)
Delete an allocated array of muse_lsf_params structure.
cpl_propertylist * header
The FITS header.