36 #include "muse_scibasic_z.h"
63 cpl_table *aTrace, cpl_table *aWave, cpl_table *aGeo,
67 cpl_ensure(aImage && aTrace && aWave, CPL_ERROR_NULL_INPUT, -1);
69 char *intag = cpl_strdup(cpl_propertylist_get_string(aImage->
header,
71 if (intag && !strncmp(intag, MUSE_TAG_ILLUM, strlen(MUSE_TAG_ILLUM) + 1)) {
82 char *tag = cpl_sprintf(
"%s_RED", intag);
90 cpl_msg_error(__func__,
"Pixel table was not created for IFU %d: %s",
91 aParams->
nifu, cpl_error_get_message());
106 char *tag = cpl_sprintf(
"%s_RESAMPLED", intag);
108 cpl_propertylist_erase_regexp(image->
header, QC_SCIBASIC_PREFIX, 0);
117 const double llimN = 4750. - FLT_EPSILON, hlimN = 9350. + FLT_EPSILON,
118 llimE = 4600. - FLT_EPSILON, hlimE = 9350. + FLT_EPSILON;
121 cpl_msg_info(__func__,
"Nominal mode: cropping the pixel table of IFU %d"
122 " to %.1f...%.1f Angstrom", aParams->
nifu, llimN, hlimN);
125 cpl_msg_info(__func__,
"Extended mode: cropping the pixel table of IFU %d"
126 " to %.1f...%.1f Angstrom", aParams->
nifu, llimE, hlimE);
137 for (icor = 0; aTwilights && aTwilights[icor]; icor++) {
138 cpl_msg_info(__func__,
"Starting twilight correction %d in IFU %d",
139 icor + 1, aParams->
nifu);
144 char *outtag = cpl_sprintf(
"PIXTABLE_%s", intag);
168 cpl_msg_warning(__func__,
"Found REDUCED files on input, ignoring all "
173 "muse.muse_scibasic");
177 cpl_ensure(images, cpl_error_get_code(), -1);
179 cpl_table *tracetable =
muse_table_load(aProcessing, MUSE_TAG_TRACE_TABLE,
181 cpl_table *wavecaltable =
muse_table_load(aProcessing, MUSE_TAG_WAVECAL_TABLE,
183 cpl_table *geotable =
muse_table_load(aProcessing, MUSE_TAG_GEOMETRY_TABLE, 0);
184 if (!tracetable || !wavecaltable || !geotable) {
185 cpl_msg_error(__func__,
"Calibration could not be loaded for IFU %d:%s%s%s",
186 aParams->
nifu, !tracetable ?
" "MUSE_TAG_TRACE_TABLE :
"",
187 !wavecaltable ?
" "MUSE_TAG_WAVECAL_TABLE :
"",
188 !geotable ?
" "MUSE_TAG_GEOMETRY_TABLE :
"");
191 cpl_table_delete(tracetable);
192 cpl_table_delete(wavecaltable);
193 cpl_table_delete(geotable);
199 MUSE_TAG_TWILIGHT_CUBE, 0, 0);
200 int i, ntwilight = cpl_frameset_get_size(fset);
202 for (i = 0; i < ntwilight; i++) {
203 cpl_frame *ftwilight = cpl_frameset_get_position(fset, i);
204 const char *fn = cpl_frame_get_filename(ftwilight);
207 cpl_msg_warning(__func__,
"Could not load %s from \"%s\"",
208 MUSE_TAG_TWILIGHT_CUBE, fn);
214 cpl_frameset_delete(fset);
218 cpl_array_delete(lines);
221 "muse.muse_scibasic");
222 if (cpars->combine == MUSE_COMBINE_NONE) {
224 cpl_table *tattached = NULL;
226 for (k = 0; k < nimages; k++) {
227 cpl_boolean isillum = CPL_FALSE;
229 const char *tag = cpl_propertylist_get_string(image->
header,
231 if (tag && !strncmp(tag, MUSE_TAG_ILLUM, strlen(MUSE_TAG_ILLUM) + 1)) {
234 if (cpl_propertylist_has(image->
header,
"ESO TPL ID")) {
235 const char *tplid = cpl_propertylist_get_string(image->
header,
237 *fn = cpl_propertylist_get_string(image->
header,
239 *tplatt =
"MUSE_wfm_cal_specflatatt",
240 *tplill =
"MUSE_wfm_cal_illum";
241 if (strncmp(tplid, tplatt, strlen(tplatt) + 1) &&
242 strncmp(tplid, tplill, strlen(tplill) + 1)) {
243 cpl_msg_warning(__func__,
"%s input (\"%s\") was taken with neither"
244 " %s nor %s template, but %s!", MUSE_TAG_ILLUM, fn,
245 tplatt, tplill, tplid);
247 cpl_msg_debug(__func__,
"%s input (\"%s\") was taken with template "
248 "%s", MUSE_TAG_ILLUM, fn, tplid);
255 cpl_msg_warning(__func__,
"Image %u of %u of IFU %hhu is illum flat, "
256 "but not the first; not using it!", k + 1, nimages, ifu);
259 cpl_msg_debug(__func__,
"Image %u of %u of IFU %hhu is illum flat.",
260 k + 1, nimages, ifu);
266 cpl_msg_debug(__func__,
"Image %u of %u of IFU %hhu is science image.",
267 k + 1, nimages, ifu);
270 for (k = 0; k < nimages && !rc; k++) {
273 rc = muse_scibasic_per_exposure(aProcessing, aParams, tracetable,
274 wavecaltable, geotable, image, skylines,
275 tattached, twilights);
277 cpl_table_delete(tattached);
279 int ntags = cpl_array_get_size(aProcessing->
intags);
281 cpl_msg_warning(__func__,
"Combining images of %d different tags, but "
282 "will use %s for output!", ntags,
283 cpl_array_get_string(aProcessing->
intags, 0));
285 cpl_msg_debug(__func__,
"Combining images with %d tag", ntags);
289 cpl_propertylist_update_string(image->
header, MUSE_HDR_TMP_INTAG,
290 cpl_array_get_string(aProcessing->
intags, 0));
291 rc = muse_scibasic_per_exposure(aProcessing, aParams, tracetable,
292 wavecaltable, geotable, image, skylines,
296 cpl_array_delete(skylines);
301 cpl_table_delete(tracetable);
302 cpl_table_delete(wavecaltable);
303 cpl_table_delete(geotable);
304 for (i = 0; twilights[i]; i++) {
muse_imagelist * muse_basicproc_load(muse_processing *aProcessing, unsigned char aIFU, muse_basicproc_params *aBPars)
Load the raw input files from disk and do basic processing.
Structure definition of a MUSE datacube.
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.
unsigned char muse_utils_get_ifu(const cpl_propertylist *aHeaders)
Find out the IFU/channel from which this header originated.
muse_datacube * muse_datacube_load(const char *aFilename)
Load header, DATA and optionally STAT and DQ extensions as well as the reconstructed images of a MUSE...
cpl_array * muse_cplarray_string_to_double(const cpl_array *aArray)
Convert a string array into an array of type double.
void muse_datacube_delete(muse_datacube *aCube)
Deallocate memory associated to a muse_datacube object.
void muse_imagelist_delete(muse_imagelist *aList)
Free the memory of the MUSE image list.
muse_imagelist * muse_basicproc_load_reduced(muse_processing *aProcessing, unsigned char aIFU)
Load reduced input files from disk.
muse_basicproc_params * muse_basicproc_params_new(cpl_parameterlist *aParameters, const char *aPrefix)
Create a new structure of basic processing parameters.
double dlambda
Wavelength step (in Angstrom per pixel) to use for resampling.
muse_image * muse_combine_images(muse_combinepar *aCPars, muse_imagelist *aImages)
Combine several images into one.
Structure definition of MUSE three extension FITS file.
void muse_basicproc_params_delete(muse_basicproc_params *aBPars)
Free a structure of basic processing parameters.
cpl_propertylist * header
the FITS header
cpl_boolean muse_processing_check_intags(muse_processing *aProcessing, const char *aTag, int aNChars)
Check that a tag is part of the input tags of a processing structure.
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
void muse_combinepar_delete(muse_combinepar *aCPars)
Clear the combination parameters.
cpl_error_code muse_pixtable_restrict_wavelength(muse_pixtable *aPixtable, double aLow, double aHigh)
Restrict a pixel table to a certain wavelength range.
int saveimage
Save the pre-processed CCD-based image of each input exposure before it is transformed into a pixel t...
cpl_array * muse_cplarray_new_from_delimited_string(const char *aString, const char *aDelim)
Convert a delimited string into an array of strings.
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.
cpl_error_code muse_basicproc_apply_twilight(muse_pixtable *aPT, muse_datacube *aTwilight)
Apply an attached flat-field to a pixel table.
int resample
Resample the input science data into 2D spectral images using tracing and wavelength calibration solu...
muse_combinepar * muse_combinepar_new(cpl_parameterlist *aParameters, const char *aPrefix)
Create a new set of combination parameters.
int nifu
IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in ...
double skyhalfwidth
Half-width of the extraction box (in Angstrom) around each sky emission line.
void muse_processing_append_used(muse_processing *aProcessing, cpl_frame *aFrame, cpl_frame_group aGroup, int aDuplicate)
Add a frame to the set of used frames.
int crop
Automatically crop the output pixel tables in wavelength depending on the expected useful wavelength ...
muse_pixtable * muse_pixtable_create(muse_image *aImage, cpl_table *aTrace, cpl_table *aWave, cpl_table *aGeoTable)
Create the pixel table for one CCD.
cpl_error_code muse_basicproc_shift_pixtable(muse_pixtable *aPt, cpl_array *aLines, double aHalfWidth, double aBinWidth)
Compute wavelength corrections for science data based on reference sky lines.
int muse_processing_save_image(muse_processing *aProcessing, int aIFU, muse_image *aImage, const char *aTag)
Save a computed MUSE image to disk.
Structure to hold the parameters of the muse_scibasic recipe.
double skybinsize
Size of the bins (in Angstrom per pixel) for the intermediate spectrum to do the Gaussian fit to each...
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.
const char * skylines
List of wavelengths of sky emission lines (in Angstrom) to use as reference for wavelength offset cor...
cpl_error_code muse_basicproc_apply_illum(muse_pixtable *aPT, cpl_table *aAttached)
Apply an illum/attached flat-field to a pixel table.
cpl_frameset * muse_frameset_find(const cpl_frameset *aFrames, const char *aTag, unsigned char aIFU, cpl_boolean aInvert)
return frameset containing data from an IFU/channel with a certain tag
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
cpl_table * muse_basicproc_prepare_illum(muse_pixtable *aPT)
Apply an illum/attached flat-field to a pixel table.
muse_ins_mode muse_pfits_get_mode(const cpl_propertylist *aHeaders)
find out the observation mode
cpl_parameterlist * parameters
cpl_propertylist * header
The FITS header.
cpl_error_code muse_basicproc_qc_saturated(muse_image *aImage, const char *aPrefix)
Add QC parameter about saturated pixels to a muse_image.