30 #include "muse_scipost_subtract_sky_z.h" 47 cpl_errorstate prestate = cpl_errorstate_get();
54 if (lsfCubes == NULL) {
57 if (lsfParams == NULL) {
59 cpl_msg_error(__func__,
"Could not load LSF");
60 cpl_table_delete(continuum);
61 cpl_table_delete(lines);
62 return CPL_ERROR_NULL_INPUT;
65 cpl_errorstate_set(prestate);
69 cpl_msg_warning(__func__,
"Could not load sky lines");
74 cpl_error_code rc = CPL_ERROR_NONE;
75 cpl_size iframe, nframes = cpl_frameset_get_size(inframes);
76 for (iframe = 0; iframe < nframes; iframe++) {
77 cpl_frame *frame = cpl_frameset_get_position(inframes, iframe);
78 const char *fn = cpl_frame_get_filename(frame);
83 if (pixtable == NULL) {
84 cpl_msg_error(__func__,
"NULL pixel table for %s", fn);
85 rc = CPL_ERROR_NULL_INPUT;
91 cpl_propertylist_erase_regexp(pixtable->
header,
"ESO QC ", 0);
93 cpl_msg_error(__func__,
"Pixel table %s not flux calibrated",
94 cpl_frame_get_filename(frame));
96 rc = CPL_ERROR_ILLEGAL_INPUT;
101 cpl_msg_error(__func__,
"Pixel table %s already sky subtracted",
102 cpl_frame_get_filename(frame));
104 rc = CPL_ERROR_ILLEGAL_INPUT;
109 double fluxs = cpl_propertylist_get_double(pixtable->
header,
110 MUSE_HDR_FLAT_FLUX_SKY);
111 double fluxl = cpl_propertylist_get_double(pixtable->
header,
112 MUSE_HDR_FLAT_FLUX_LAMP);
113 cpl_errorstate_set(prestate);
115 if (aParams->
orig != NULL) {
116 cpl_table_duplicate_column(pixtable->
table, aParams->
orig,
122 if (aParams->
flux_sky > 0. && fluxs > 0.) {
124 cpl_msg_debug(__func__,
"Scaling by SKY %e/%e = %f",
126 }
else if (aParams->
flux_lamp > 0. && fluxl > 0.) {
128 cpl_msg_debug(__func__,
"Scaling by LAMP %e/%e = %f",
134 if (continuum != NULL) {
137 if (rc != CPL_ERROR_NONE) {
138 cpl_msg_error(__func__,
"while muse_sky_subtract_continuum(%s)",
139 cpl_frame_get_filename(frame));
144 if (lsfCubes != NULL) {
146 #ifdef USE_LSF_PARAMS 147 }
else if (lsfParams != NULL) {
151 if (rc != CPL_ERROR_NONE) {
152 cpl_msg_error(__func__,
"while muse_sky_subtract_lines(%s)",
153 cpl_frame_get_filename(frame));
164 MUSE_HDR_PT_SKYSUB_COMMENT);
167 MUSE_TAG_PIXTABLE_REDUCED,
171 cpl_frameset_delete(inframes);
172 cpl_table_delete(continuum);
173 cpl_table_delete(lines);
176 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...
cpl_table * muse_sky_lines_load(muse_processing *)
Load the sky data files.
Data cube/stacked image list containing the LSF for one IFU.
cpl_table * table
The pixel table.
#define MUSE_PIXTABLE_DATA
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.
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 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.
muse_lsf_cube ** muse_lsf_cube_load_all(muse_processing *aProcessing)
Load all LSF cubes for all IFUs into an array.
cpl_error_code muse_sky_subtract_continuum(muse_pixtable *, cpl_table *)
Subtract sky continuum from pixel table.
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.
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...
void muse_lsf_cube_delete_all(muse_lsf_cube **aLsfCube)
Delete all LSF cubes.
cpl_error_code muse_sky_subtract_lines(muse_pixtable *, cpl_table *, muse_lsf_cube **)
Subtract sky lines from a pixtable.
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.
muse_lsf_params ** muse_processing_lsf_params_load(muse_processing *aProcessing, int aIFU)
Load slice LSF parameters.
Structure definition of detector (slice) parameters.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
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)