33 #include "muse_create_sky_z.h" 47 cpl_msg_error(__func__,
"no science exposures found in input");
50 int nexposures = cpl_table_get_nrow(exposures);
51 if (nexposures != 1) {
52 cpl_msg_error(__func__,
"More than one exposure (%i) in sky creation",
58 for (i = 0; i < nexposures; i++) {
59 cpl_table *thisexp = cpl_table_extract(exposures, i, 1);
63 cpl_table_delete(thisexp);
70 cpl_propertylist_erase_regexp(p->
header,
"ESO QC ", 0);
71 if (pixtable == NULL) {
75 cpl_table_get_nrow(pixtable->
table));
79 cpl_table_delete(exposures);
82 cpl_msg_error(__func__,
"Pixel table already sky subtracted");
88 MUSE_TAG_STD_RESPONSE, 0),
90 MUSE_TAG_STD_TELLURIC, 0);
92 MUSE_TAG_EXTINCT_TABLE, 0);
94 if ((pixtable != NULL) && (response != NULL)) {
96 cpl_msg_error(__func__,
97 "Pixel table already flux calibrated. Dont specify %s, %s, %s",
98 MUSE_TAG_STD_RESPONSE, MUSE_TAG_EXTINCT_TABLE,
99 MUSE_TAG_STD_TELLURIC);
108 if (rc != CPL_ERROR_NONE) {
109 cpl_msg_error(__func__,
"while muse_flux_calibrate");
118 cpl_table_delete(extinction);
121 cpl_msg_error(__func__,
"Pixel table not flux calibrated");
126 if (pixtable != NULL) {
128 CPL_NOT_EQUAL_TO, EURO3D_GOODPIXEL);
129 cpl_table_erase_selected(pixtable->
table);
133 cpl_msg_debug(__func__,
"WFM detected: starting DAR correction");
135 cpl_msg_debug(__func__,
"DAR correction returned rc=%d: %s", rc,
136 rc != CPL_ERROR_NONE ? cpl_error_get_message() :
"");
155 muse_create_sky_whitelight_image(
muse_pixtable *aPixtable,
double aCRSigma)
157 cpl_boolean usegrid = getenv(
"MUSE_COLLAPSE_PIXTABLE")
158 && atoi(getenv(
"MUSE_COLLAPSE_PIXTABLE")) > 0;
168 usegrid ? &grid : NULL);
170 cpl_msg_error(__func__,
"Could not create cube for whitelight image");
180 cube, fwhite, params);
204 double crsigmac = 15.,
206 if (cpl_array_get_size(crarray) < 2) {
207 cpl_msg_warning(__func__,
"Less than two values given by crsigma " 208 "parameter, using defaults (%.3f.,%.3f)!", crsigmac,
211 crsigmac = cpl_array_get_string(crarray, 0)
212 ? atof(cpl_array_get_string(crarray, 0)) : 15.;
213 crsigmas = cpl_array_get_string(crarray, 1)
214 ? atof(cpl_array_get_string(crarray, 1)) : 0.;
216 cpl_array_delete(crarray);
218 muse_pixtable *pixtable = muse_create_sky_load_pixtable(aProcessing, aParams);
219 if (pixtable == NULL) {
220 cpl_msg_error(__func__,
"Could not load pixel table");
233 cpl_table_select_all(pixtable->
table);
238 muse_image *whitelight = muse_create_sky_whitelight_image(pixtable, crsigmac);
239 if (whitelight == NULL) {
240 cpl_msg_error(__func__,
"Could not create whitelight image");
250 cpl_table_select_all(pixtable->
table);
252 cpl_table_not_selected(pixtable->
table);
253 cpl_table_erase_selected(pixtable->
table);
261 if (spectrum == NULL) {
270 double lambda_low = cpl_table_get_column_min(spectrum,
"lambda");
271 double lambda_high = cpl_table_get_column_max(spectrum,
"lambda");
283 cpl_errorstate prestate = cpl_errorstate_get();
294 if (lsfCube != NULL) {
296 muse_wcs *lsfWCS = muse_lsf_cube_get_wcs_all(lsfCube);
299 cpl_msg_info(__func__,
"Creating master sky spectrum using fits to lines " 300 "(fluxes) and residual continuum");
304 if (!cpl_errorstate_is_equal(prestate)) {
305 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
306 cpl_errorstate_set(prestate);
309 if (continuum == NULL) {
315 cpl_image_delete(lsfImage);
316 #ifdef USE_LSF_PARAMS 318 cpl_errorstate_set(prestate);
320 if (lsfParams != NULL) {
324 if (!cpl_errorstate_is_equal(prestate)) {
325 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
326 cpl_errorstate_set(prestate);
329 if (continuum == NULL) {
332 cpl_table_erase_column(continuum,
"stat");
333 cpl_table_erase_column(continuum,
"dq");
334 cpl_table_name_column(continuum,
"data",
"flux");
339 cpl_msg_error(__func__,
"Could not load LSF. Continuum is not created.");
344 cpl_propertylist *header = cpl_propertylist_new();
347 cpl_propertylist_delete(header);
349 header = cpl_propertylist_new();
352 cpl_propertylist_delete(header);
355 cpl_table_delete(spectrum);
356 cpl_table_delete(lines);
357 cpl_table_delete(continuum);
359 return cpl_errorstate_is_equal(prestate) ? 0 : -1;
cpl_error_code muse_sky_lines_fit(cpl_table *, cpl_table *, cpl_image *, muse_wcs *)
Fit all entries of the pixel table to the master sky.
cpl_table * muse_sky_continuum_create(cpl_table *, cpl_table *, cpl_image *, muse_wcs *, double)
Create a continuum spectrum.
muse_image * muse_resampling_collapse_pixgrid(muse_pixtable *aPixtable, muse_pixgrid *aGrid, muse_datacube *aCube, const muse_table *aFilter, muse_resampling_params *aParams)
Integrate a pixel table / pixel grid along the wavelength direction.
Structure definition of a MUSE datacube.
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
int muse_processing_save_mask(muse_processing *aProcessing, int aIFU, muse_mask *aMask, const char *aTag)
Save a computed MUSE mask to disk.
A structure containing a spatial two-axis WCS.
cpl_table * muse_resampling_spectrum_iterate(muse_pixtable *aPixtable, double aBinwidth, float aLo, float aHi, unsigned char aIter)
Iteratively resample selected pixels of a pixel table into spectrum.
cpl_error_code muse_sky_lines_save(muse_processing *, const cpl_table *, cpl_propertylist *)
Save sky lines table to file.
void muse_mask_delete(muse_mask *aMask)
Deallocate memory associated to a muse_mask object.
cpl_error_code muse_dar_correct(muse_pixtable *aPixtable, double aLambdaRef)
Correct the pixel coordinates of all pixels of a given pixel table for differential atmospheric refra...
cpl_error_code muse_postproc_revert_ffspec_maybe(muse_pixtable *aPt, const muse_table *aResponse)
Revert correction of on-sky data with the flat-field spectrum.
cpl_image * muse_lsf_average_cube_all(muse_lsf_cube **aLsfCube, muse_pixtable *aPixtable)
Create an average image from all LSF cubes.
cpl_error_code muse_pixtable_and_selected_mask(muse_pixtable *aPixtable, muse_mask *aMask)
Select all pixels where the (x,y) positions are enabled in the given mask.
cpl_table * muse_sky_lines_load(muse_processing *)
Load the sky data files.
double csampling
Spectral sampling of the continuum spectrum [Angstrom].
muse_datacube * muse_resampling_cube(muse_pixtable *aPixtable, muse_resampling_params *aParams, muse_pixgrid **aGrid)
Resample a pixel table onto a regular grid structure representing a FITS NAXIS=3 datacube.
void muse_datacube_delete(muse_datacube *aCube)
Deallocate memory associated to a muse_datacube object.
Data cube/stacked image list containing the LSF for one IFU.
void muse_sky_qc_lines(cpl_propertylist *, cpl_table *, const char *)
Fill a header with the QC parameters for the sky lines.
Structure definition of MUSE three extension FITS file.
cpl_error_code muse_flux_calibrate(muse_pixtable *aPixtable, const muse_table *aResponse, const cpl_table *aExtinction, const muse_table *aTelluric)
Convert the input pixel table from counts to fluxes.
cpl_table * table
The pixel table.
void muse_lsf_params_delete_all(muse_lsf_params **aParams)
Delete an allocated array of muse_lsf_params structure.
const char * crsigma
Sigma level clipping for cube-based and spectrum-based CR rejection. This has to be a string of two c...
muse_resampling_crstats_type crtype
void muse_sky_qc_continuum(cpl_propertylist *, cpl_table *, const char *)
Fill a header with the QC parameters for the sky continuum.
cpl_boolean muse_pixtable_is_skysub(muse_pixtable *aPixtable)
Determine whether the pixel table is sky subtracted.
void muse_pixgrid_delete(muse_pixgrid *aGrid)
Delete a pixel grid and remove its memory.
cpl_table * muse_sky_continuum_load(muse_processing *)
Load the sky continuum.
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.
cpl_error_code muse_sky_subtract_lines_old(muse_pixtable *aPixtable, cpl_table *aLines, muse_lsf_params **aLsfParams)
Subtract sky lines from a pixtable.
double ignore
Fraction of the image to be ignored. If an input sky mask is provided, the fraction is applied to the...
muse_resampling_params * muse_resampling_params_new(muse_resampling_type aMethod)
Create the resampling parameters structure.
cpl_boolean muse_pixtable_is_fluxcal(muse_pixtable *aPixtable)
Determine whether the pixel table is flux calibrated.
muse_lsf_cube ** muse_lsf_cube_load_all(muse_processing *aProcessing)
Load all LSF cubes for all IFUs into an array.
muse_table * muse_processing_load_table(muse_processing *aProcessing, const char *aTag, unsigned char aIFU)
Load a MUSE table according to its tag and IFU/channel number.
muse_table * muse_table_load_filter(muse_processing *aProcessing, const char *aFilterName)
Load a table for a given filter name.
cpl_error_code muse_sky_lines_set_range(cpl_table *, double, double)
Limit the lines in the table to a wavelength range.
Structure to store a table together with a property list.
muse_mask * muse_processing_load_mask(muse_processing *aProcessing, const char *aTag)
Load a mask file and its FITS header.
void muse_table_delete(muse_table *aTable)
Deallocate memory associated to a muse_table object.
int muse_processing_save_image(muse_processing *aProcessing, int aIFU, muse_image *aImage, const char *aTag)
Save a computed MUSE image to disk.
cpl_table * muse_processing_load_ctable(muse_processing *aProcessing, const char *aTag, unsigned char aIFU)
Load a CPL table according to its tag and IFU/channel number.
muse_pixtable * muse_pixtable_load_merge_channels(cpl_table *aExposureList, double aLambdaMin, double aLambdaMax)
Load and merge the pixel tables of the 24 MUSE sub-fields.
Handling of "mask" files.
void muse_lsf_cube_delete_all(muse_lsf_cube **aLsfCube)
Delete all LSF cubes.
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
muse_mask * muse_sky_create_skymask(muse_image *, double, double, const char *)
Select spaxels to be considered as sky.
double sampling
Spectral sampling of the sky spectrum [Angstrom].
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.
double fraction
Fraction of the image (without the ignored part) to be considered as sky. If an input sky mask is pro...
muse_resampling_type
Resampling types.
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
cpl_error_code muse_lsf_fold_rectangle(cpl_image *aLsfImage, const muse_wcs *aWCS, double aBinWidth)
Filter an LSF image with a rectangle to model spectrum binning.
double lambdaref
Reference wavelength used for correction of differential atmospheric refraction. The R-band (peak wav...
void muse_resampling_params_delete(muse_resampling_params *aParams)
Delete a resampling parameters structure.
muse_resampling_type method
muse_lsf_params ** muse_processing_lsf_params_load(muse_processing *aProcessing, int aIFU)
Load slice LSF parameters.
muse_image * muse_datacube_collapse(muse_datacube *aCube, const muse_table *aFilter)
Integrate a FITS NAXIS=3 datacube along the wavelength direction.
cpl_table * muse_resampling_spectrum(muse_pixtable *aPixtable, double aBinwidth)
Resample the selected pixels of a pixel table into a spectrum.
cpl_error_code muse_sky_lines_fit_old(cpl_table *aSpectrum, cpl_table *aLines)
Fit all entries of the pixel table to the master sky.
cpl_table * muse_processing_sort_exposures(muse_processing *aProcessing)
Sort input frames (containing lists of pixel table filenames) into different exposures.
Structure definition of detector (slice) parameters.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
Structure to hold the parameters of the muse_create_sky recipe.
muse_ins_mode muse_pfits_get_mode(const cpl_propertylist *aHeaders)
find out the observation mode
cpl_propertylist * header
The FITS header.
cpl_error_code muse_sky_save_continuum(muse_processing *, const cpl_table *, cpl_propertylist *)
Save sky continuum table to file.