30 #include "muse_scipost_subtract_sky_z.h"
51 cpl_msg_error(__func__,
"Could not load sky files");
52 return CPL_ERROR_NULL_INPUT;
58 cpl_error_code rc = CPL_ERROR_NONE;
59 cpl_size iframe, nframes = cpl_frameset_get_size(inframes);
60 for (iframe = 0; iframe < nframes; iframe++) {
61 cpl_frame *frame = cpl_frameset_get_position(inframes, iframe);
62 const char *fn = cpl_frame_get_filename(frame);
67 if (pixtable == NULL) {
68 cpl_msg_error(__func__,
"NULL pixel table for %s", fn);
69 rc = CPL_ERROR_NULL_INPUT;
75 cpl_propertylist_erase_regexp(pixtable->
header,
"ESO QC ", 0);
77 cpl_msg_error(__func__,
"Pixel table %s not flux calibrated, cannot "
78 "subtract sky!", cpl_frame_get_filename(frame));
80 rc = CPL_ERROR_ILLEGAL_INPUT;
85 cpl_msg_error(__func__,
"Pixel table %s already sky subtracted",
86 cpl_frame_get_filename(frame));
88 rc = CPL_ERROR_ILLEGAL_INPUT;
93 cpl_errorstate prestate = cpl_errorstate_get();
94 double fluxs = cpl_propertylist_get_double(pixtable->
header,
95 MUSE_HDR_FLAT_FLUX_SKY);
96 double fluxl = cpl_propertylist_get_double(pixtable->
header,
97 MUSE_HDR_FLAT_FLUX_LAMP);
98 cpl_errorstate_set(prestate);
100 if (aParams->
orig != NULL) {
101 cpl_table_duplicate_column(pixtable->
table, aParams->
orig,
102 pixtable->
table, MUSE_PIXTABLE_DATA);
107 if (aParams->
flux_sky > 0. && fluxs > 0.) {
109 cpl_msg_debug(__func__,
"Scaling by SKY %e/%e = %f",
111 }
else if (aParams->
flux_lamp > 0. && fluxl > 0.) {
113 cpl_msg_debug(__func__,
"Scaling by LAMP %e/%e = %f",
117 cpl_table_divide_scalar(pixtable->
table, MUSE_PIXTABLE_DATA, scale);
121 if (rc != CPL_ERROR_NONE) {
122 cpl_msg_error(__func__,
"while muse_sky_subtract_pixtable(%s)",
123 cpl_frame_get_filename(frame));
127 cpl_table_multiply_scalar(pixtable->
table, MUSE_PIXTABLE_DATA, scale);
133 MUSE_HDR_PT_SKYSUB_COMMENT);
136 MUSE_TAG_PIXTABLE_REDUCED,
140 cpl_frameset_delete(inframes);
143 return cpl_error_get_code();
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
const char * orig
If specified, write an additional column containing the original data to the pixel table...
Structure to hold the MASTER SKY result.
cpl_table * table
The pixel table.
cpl_boolean muse_pixtable_is_skysub(muse_pixtable *aPixtable)
Determine whether the pixel table is sky subtracted.
Structure definition of MUSE pixel table.
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
double flux_lamp
Reference flat field flux, obtained by lamp exposure. This parameter is needed to scale the data of e...
#define MUSE_HDR_PT_SKYSUB
cpl_boolean muse_pixtable_is_fluxcal(muse_pixtable *aPixtable)
Determine whether the pixel table is flux calibrated.
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.
Structure to hold the parameters of the muse_scipost_subtract_sky recipe.
void muse_sky_master_delete(muse_sky_master *)
Delete a MASTER SKY structure.
muse_pixtable * muse_pixtable_load_restricted_wavelength(const char *aFilename, double aLambdaMin, double aLambdaMax)
Load a pixel table from file and cut down the wavelength range.
double flux_sky
Reference flat field flux, obtained by sky exposure. This parameter is needed to scale the data of ea...
muse_sky_master * muse_sky_master_load(muse_processing *)
Load SKY_LINES, SKY_CONTINUUM, and LSF_PROFILE into a structure.
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.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
cpl_error_code muse_sky_subtract_pixtable(muse_pixtable *a, muse_sky_master *, muse_lsf_params **)
Subtract the sky spectrum from the "data" column of a pixel table.
muse_lsf_params ** lsf
LSF parameter for the resampled spectrum.
cpl_propertylist * header
The FITS header.
cpl_frameset * muse_frameset_find_tags(const cpl_frameset *aFrames, const cpl_array *aTags, unsigned char aIFU, cpl_boolean aInvert)
return frameset containing data from an IFU/channel with the given tag(s)