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() :
"");
156 double crsigmac = 15.,
158 if (cpl_array_get_size(crarray) < 2) {
159 cpl_msg_warning(__func__,
"Less than two values given by crsigma " 160 "parameter, using defaults (%.3f.,%.3f)!", crsigmac,
163 crsigmac = cpl_array_get_string(crarray, 0)
164 ? atof(cpl_array_get_string(crarray, 0)) : 15.;
165 crsigmas = cpl_array_get_string(crarray, 1)
166 ? atof(cpl_array_get_string(crarray, 1)) : 0.;
168 cpl_array_delete(crarray);
170 muse_pixtable *pixtable = muse_create_sky_load_pixtable(aProcessing, aParams);
171 if (pixtable == NULL) {
172 cpl_msg_error(__func__,
"Could not load pixel table");
185 cpl_table_select_all(pixtable->
table);
191 if (whitelight == NULL) {
192 cpl_msg_error(__func__,
"Could not create whitelight image");
202 cpl_table_select_all(pixtable->
table);
204 cpl_table_not_selected(pixtable->
table);
205 cpl_table_erase_selected(pixtable->
table);
213 if (spectrum == NULL) {
222 double lambda_low = cpl_table_get_column_min(spectrum,
"lambda");
223 double lambda_high = cpl_table_get_column_max(spectrum,
"lambda");
235 cpl_errorstate prestate = cpl_errorstate_get();
246 if (lsfCube != NULL) {
251 cpl_msg_info(__func__,
"Creating master sky spectrum using fits to lines " 252 "(fluxes) and residual continuum");
256 if (!cpl_errorstate_is_equal(prestate)) {
257 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
258 cpl_errorstate_set(prestate);
261 if (continuum == NULL) {
267 cpl_image_delete(lsfImage);
268 #ifdef USE_LSF_PARAMS 270 cpl_errorstate_set(prestate);
272 if (lsfParams != NULL) {
276 if (!cpl_errorstate_is_equal(prestate)) {
277 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
278 cpl_errorstate_set(prestate);
281 if (continuum == NULL) {
284 cpl_table_erase_column(continuum,
"stat");
285 cpl_table_erase_column(continuum,
"dq");
286 cpl_table_name_column(continuum,
"data",
"flux");
291 cpl_msg_error(__func__,
"Could not load LSF. Continuum is not created.");
296 cpl_propertylist *header = cpl_propertylist_new();
299 cpl_propertylist_delete(header);
301 header = cpl_propertylist_new();
304 cpl_propertylist_delete(header);
307 cpl_table_delete(spectrum);
308 cpl_table_delete(lines);
309 cpl_table_delete(continuum);
311 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.
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_table * muse_sky_lines_load(muse_processing *)
Load the sky data files.
double csampling
Spectral sampling of the continuum spectrum [Angstrom].
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...
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.
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...
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.
cpl_error_code muse_sky_lines_set_range(cpl_table *, double, double)
Limit the lines in the table to a wavelength range.
cpl_error_code muse_pixtable_and_selected_mask(muse_pixtable *aPixtable, const muse_mask *aMask, const cpl_propertylist *aWCS, const cpl_table *aOffsets)
Select all pixels where the spatial positions are enabled in the given mask.
Structure to store a table together with a property list.
muse_image * muse_postproc_whitelight(muse_pixtable *aPixtable, double aCRSigma)
Create a white-light image of the field of view.
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.
muse_wcs * muse_lsf_cube_get_wcs_all(muse_lsf_cube **aLsfCubes)
Get the world coordinate representative of 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...
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...
muse_lsf_params ** muse_processing_lsf_params_load(muse_processing *aProcessing, int aIFU)
Load slice LSF parameters.
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.