35 #include "muse_wavecal_z.h"
56 cpl_ensure(aImages && aProcessing, CPL_ERROR_NULL_INPUT, NULL);
59 char *pname = cpl_sprintf(
"muse.%s.combine", aProcessing->
name);
60 cpl_parameter *param = cpl_parameterlist_find(aProcessing->
parameters, pname);
61 char *porig = cpl_strdup(cpl_parameter_get_string(param));
62 cpl_parameter_set_string(param,
"sum");
66 cpl_parameter_set_string(param, porig);
71 cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_OUTPUT,
72 "summing per-lamp images did not work");
80 cpl_errorstate state = cpl_errorstate_get();
82 while (cpl_errorstate_is_equal(state)) {
83 char *kwget = cpl_sprintf(QC_WAVECAL_PREFIXi
" "QC_BASIC_NSATURATED, i),
84 *kwout = cpl_sprintf(QC_WAVECAL_PREFIXli
" "QC_BASIC_NSATURATED, k+1, i);
88 if (cpl_errorstate_is_equal(state)) {
89 cpl_propertylist_update_int(image->
header, kwout, nsaturated);
97 cpl_errorstate_set(state);
124 if (aParams->
fitweighting == MUSE_WAVECAL_PARAM_FITWEIGHTING_CERR) {
126 }
else if (aParams->
fitweighting == MUSE_WAVECAL_PARAM_FITWEIGHTING_SCATTER) {
128 }
else if (aParams->
fitweighting == MUSE_WAVECAL_PARAM_FITWEIGHTING_CERRSCATTER) {
130 }
else if (aParams->
fitweighting != MUSE_WAVECAL_PARAM_FITWEIGHTING_UNIFORM) {
131 cpl_msg_error(__func__,
"unknown fitweighting method \"%s\"",
137 "muse.muse_wavecal");
138 cpl_frameset **labeledframes = NULL;
144 cpl_ensure(images, cpl_error_get_code(), -1);
150 for (k = 0; k < kimages; k++) {
152 if (!(kimages == 1 && needsum)) {
158 cpl_propertylist_erase_regexp(image->
header, MUSE_WCS_KEYS, 0);
160 MUSE_TAG_ARC_RED_LAMP);
164 cpl_frameset_delete(labeledframes[k]);
167 cpl_free(labeledframes);
171 masterimage = muse_wavecal_sum_and_save(images, aProcessing, aParams->
nifu);
175 cpl_table *linelist =
muse_table_load(aProcessing, MUSE_TAG_LINE_CATALOG, 0);
177 MUSE_TAG_LINE_CATALOG);
179 cpl_propertylist_delete(linehead);
181 cpl_table_delete(linelist);
187 cpl_table *tracetable =
muse_table_load(aProcessing, MUSE_TAG_TRACE_TABLE,
194 cpl_table *wavecaltable = NULL;
195 cpl_propertylist *header = NULL;
211 header = cpl_propertylist_duplicate(masterimage->
header);
216 cpl_table_delete(tracetable);
217 cpl_table_delete(linelist);
218 cpl_propertylist_delete(header);
225 cpl_propertylist_erase_regexp(header,
226 "^SIMPLE$|^BITPIX$|^NAXIS|^EXTEND$|^XTENSION$|"
227 "^DATASUM$|^DATAMIN$|^DATAMAX$|^DATAMD5$|"
228 "^PCOUNT$|^GCOUNT$|^HDUVERS$|^BLANK$|"
229 "^BZERO$|^BSCALE$|^BUNIT$|^CHECKSUM$|^INHERIT$|"
230 "^PIPEFILE$|^ESO PRO ", 0);
235 cpl_propertylist_erase_regexp(header, QC_WAVECAL_PREFIX, 0);
240 cpl_propertylist_delete(header);
254 cpl_propertylist_erase_regexp(resampled->
header, QC_WAVECAL_PREFIX, 0);
256 resampled->
header, MUSE_TAG_ARC_RESAMP);
264 cpl_image *map =
muse_wave_map(image, wavecaltable, tracetable);
268 cpl_image_delete(map);
272 cpl_table_delete(wavecaltable);
275 cpl_table_delete(tracetable);
276 cpl_table_delete(linelist);
int muse_processing_save_cimage(muse_processing *aProcessing, int aIFU, cpl_image *aImage, cpl_propertylist *aHeader, const char *aTag)
Save a computed FITS image to disk.
cpl_table * muse_wave_calib_lampwise(muse_imagelist *aImages, cpl_table *aTrace, cpl_table *aLinelist, muse_wave_params *aParams)
Find wavelength calibration solution using a list of arc images with different lamps.
cpl_table * muse_wave_calib(muse_image *aImage, cpl_table *aTrace, cpl_table *aLinelist, muse_wave_params *aParams)
Find wavelength calibration solution on an arc frame.
muse_image * muse_resampling_image(muse_pixtable *aPixtable, muse_resampling_type aMethod, double aDX, double aDLambda)
Resample a pixel table onto a two-dimensional regular grid.
Structure definition for a collection of muse_images.
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
double fitsigma
Sigma level for iterative rejection of deviant datapoints during the final polynomial wavelength solu...
muse_wave_weighting_type fitweighting
void muse_wave_params_delete(muse_wave_params *aParams)
Deallocate memory associated to a wavelength parameters structure.
double linesigma
Sigma level for iterative rejection of deviant fits for each arc line within each slice...
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.
cpl_image * data
the data extension
double dres
The allowed range of resolutions for pattern matching (of detected arc lines to line list) in fractio...
void muse_imagelist_delete(muse_imagelist *aList)
Free the memory of the MUSE image list.
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.
Structure definition of MUSE three extension FITS file.
muse_wave_weighting_type
Type of weighting to use in the wavelength calibration fit.
void muse_basicproc_params_delete(muse_basicproc_params *aBPars)
Free a structure of basic processing parameters.
cpl_propertylist * header
the FITS header
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
cpl_frameset * usedframes
void muse_combinepar_delete(muse_combinepar *aCPars)
Clear the combination parameters.
Structure definition of MUSE pixel table.
muse_image * muse_imagelist_get(muse_imagelist *aList, unsigned int aIdx)
Get the muse_image of given list index.
int nifu
IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in ...
Structure containing wavelength calibration parameters.
muse_combinepar * muse_combinepar_new(cpl_parameterlist *aParameters, const char *aPrefix)
Create a new set of combination parameters.
int wavemap
Create a wavelength map of the input images.
int lampwise
Identify and measure the arc emission lines on images separately for each lamp setup.
int residuals
Create a table containing residuals of the fits to the data of all arc lines. This is useful to asses...
cpl_image * muse_wave_map(muse_image *aImage, const cpl_table *aWave, const cpl_table *aTrace)
Write out a wavelength map for visual checks.
int resample
Resample the input arc images onto 2D images for a visual check using tracing and wavelength calibrat...
muse_pixtable * muse_pixtable_create(muse_image *aImage, cpl_table *aTrace, cpl_table *aWave, cpl_table *aGeoTable)
Create the pixel table for one CCD.
int yorder
Order of the polynomial used to fit the dispersion relation.
int muse_processing_save_image(muse_processing *aProcessing, int aIFU, muse_image *aImage, const char *aTag)
Save a computed MUSE image to disk.
int fitweighting
Type of weighting to use in the final polynomial wavelength solution fit, using centroiding error est...
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.
Structure to hold the parameters of the muse_wavecal recipe.
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.
double tolerance
Tolerance for pattern matching (of detected arc lines to line list)
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
muse_wave_params * muse_wave_params_new(void)
Allocate a wavelength parameters structure and fill it with defaults.
const char * fitweighting_s
Type of weighting to use in the final polynomial wavelength solution fit, using centroiding error est...
double sigma
Sigma level used to detect arc emission lines above the median background level in the S/N image of t...
cpl_parameterlist * parameters
int xorder
Order of the polynomial for the horizontal curvature within each slice.
cpl_error_code muse_basicproc_qc_saturated(muse_image *aImage, const char *aPrefix)
Add QC parameter about saturated pixels to a muse_image.