34 #include "muse_sky_lsf_z.h"
44 "PIXTABLE_ARC", 0, CPL_FALSE);
45 if (frames == NULL || cpl_frameset_get_size(frames) <= 0) {
46 cpl_frameset_delete(frames);
49 cpl_frame *frame = cpl_frameset_get_position(frames, 0);
50 const char *fn = cpl_frame_get_filename(frame);
51 double lambdamin = aParams->
lambdamin - kMuseSpectralSamplingA,
52 lambdamax = aParams->
lambdamax + kMuseSpectralSamplingA;
56 cpl_msg_info(__func__,
"using pixel table \"%s\"", fn);
58 cpl_frameset_delete(frames);
59 if (pixtable != NULL) {
60 cpl_table_and_selected_int(pixtable->
table, MUSE_PIXTABLE_DQ,
61 CPL_NOT_EQUAL_TO, EURO3D_GOODPIXEL);
62 cpl_table_erase_selected(pixtable->
table);
64 cpl_propertylist_erase_regexp(pixtable->
header,
"ESO QC ", 0);
73 "SKY_LINES", 0, CPL_FALSE);
74 if (frames == NULL || cpl_frameset_get_size(frames) <= 0) {
75 cpl_frameset_delete(frames);
78 cpl_frame *frame = cpl_frameset_get_position(frames, 0);
79 cpl_table *lines = cpl_table_load(cpl_frame_get_filename(frame), 1, 1);
80 cpl_msg_info(__func__,
"using line table %s", cpl_frame_get_filename(frame));
82 cpl_frameset_delete(frames);
87 muse_sky_lsf_save_params(cpl_propertylist *aHeader,
91 if (aSlicePars != NULL) {
94 "LSF_TABLE", CPL_FRAME_TYPE_TABLE);
96 const char *filename = cpl_frame_get_filename(frame);
98 r = cpl_propertylist_save(aHeader, filename, CPL_IO_CREATE);
100 if (r == CPL_ERROR_NONE) {
103 cpl_frame_delete(frame);
111 muse_sky_lsf_compute_slice_params(cpl_table *aLines,
118 uint32_t origin = (uint32_t)cpl_table_get_int(aPixtable->
table,
119 MUSE_PIXTABLE_ORIGIN, 0, NULL);
124 cpl_msg_info(__func__,
"processing slice %i.%i with %"CPL_SIZE_FORMAT
" rows",
125 i_ifu, i_slice, nrows);
127 cpl_propertylist *order = cpl_propertylist_new();
128 cpl_propertylist_append_bool(order, MUSE_PIXTABLE_LAMBDA, CPL_FALSE);
129 cpl_table_sort(aPixtable->
table, order);
130 cpl_propertylist_delete(order);
132 cpl_array *lambda = NULL;
133 if (cpl_table_get_column_type(aPixtable->
table, MUSE_PIXTABLE_LAMBDA)
134 == CPL_TYPE_DOUBLE) {
136 MUSE_PIXTABLE_LAMBDA);
138 cpl_table_cast_column(aPixtable->
table, MUSE_PIXTABLE_LAMBDA,
139 "lambda_double", CPL_TYPE_DOUBLE);
149 max_iterations, slice_fit_params);
150 lsfParam->slice = i_slice;
151 lsfParam->ifu = i_ifu;
153 if (cpl_table_has_column(aPixtable->
table,
"lambda_double")) {
154 cpl_table_erase_column(aPixtable->
table,
"lambda_double");
157 cpl_array_unwrap(lambda);
158 cpl_array_unwrap(data);
159 cpl_array_unwrap(stat);
165 muse_sky_lsf_compute_slices(cpl_table *aLines,
178 #pragma omp parallel for default(none) \
179 shared(aLines, n_slices, i_slice, lsfParams, \
180 slice_pixtable, aFirstguess, max_iterations, slice_fit_params)
182 for (i_slice = 0; i_slice < n_slices; i_slice++) {
184 = (uint32_t)cpl_table_get_int(slice_pixtable[i_slice]->table,
185 MUSE_PIXTABLE_ORIGIN, 0, NULL);
191 cpl_errorstate prestate = cpl_errorstate_get();
193 = muse_sky_lsf_compute_slice_params(aLines, slice_pixtable[i_slice],
194 firstguess_slice, max_iterations,
196 if (!cpl_errorstate_is_equal(prestate)) {
197 cpl_msg_error(__func__,
"While processing slice %i.%i:", ifu, slice);
198 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
199 cpl_errorstate_set(prestate);
219 cpl_msg_debug(__func__,
"recipe=\"%s\", tag=\"%s\"", aProcessing->
recipeName,
222 cpl_errorstate prestate = cpl_errorstate_get();
224 muse_pixtable *pixtable = muse_sky_lsf_load_pixtable(aProcessing, aParams);
225 if (pixtable == NULL) {
229 if (aParams->
orig != NULL) {
230 cpl_table_duplicate_column(pixtable->
table, aParams->
orig,
231 pixtable->
table,
"data");
233 cpl_table *lines = muse_sky_lsf_load_lines(aProcessing);
254 muse_lsf_params **lsf = muse_sky_lsf_compute_slices(lines, pixtable, firstguess,
260 cpl_propertylist *qc_header = cpl_propertylist_new();
261 muse_sky_lsf_save_params(qc_header, (
const muse_lsf_params **)lsf, aProcessing);
266 MUSE_TAG_PIXTABLE_REDUCED,
272 cpl_propertylist_delete(qc_header);
275 return (cpl_errorstate_is_equal(prestate))?0:-1;
int slice_fit_lsf_width
Polynomial order for the LSF width fit parameter. Use -1 to not fit the LSF width.
int store_subtracted
Output the pixel table after the LSF subtraction.
int slice_fit_slit_width
Use the slit width as fit parameter.
void muse_pixtable_extracted_delete(muse_pixtable **aPixtables)
Delete a pixel table array.
const char * orig
If specified, write an additional column containing the original data to the pixel table...
unsigned short muse_pixtable_origin_get_slice(uint32_t aOrigin)
Get the slice number from the encoded 32bit origin number.
cpl_size muse_pixtable_extracted_get_size(muse_pixtable **aPixtables)
Get the size of an array of extracted pixel tables.
cpl_size muse_pixtable_get_nrow(muse_pixtable *aPixtable)
get the number of rows within the pixel table
muse_pixtable ** muse_pixtable_extracted_get_slices(muse_pixtable *aPixtable)
Extract one pixel table per IFU and slice.
int max_iterations
Maximum number of minimization steps for the slice parameter fit. If set to zero, the slice parameter...
cpl_error_code muse_lsf_params_save(const muse_lsf_params **aLsf, const char *aFile)
Save slice LSF parameters to the extension "slice" on disk.
muse_lsf_params * muse_lsf_params_fit(const cpl_array *aLambda, cpl_array *aData, const cpl_array *aStat, const cpl_table *aLines, muse_lsf_params *aFirstGuess, int aMaxIter, const muse_sky_fit_params *aFitParams)
Fit all entries of one slice.
muse_lsf_params * muse_lsf_params_get(muse_lsf_params **aParams, int aIFU, int aSlice)
Get the slice LSF parameters for one slice.
int slice_fit_h4
Polynomial order for the H4 fit parameter. Use -1 to not fit H4.
Structure to define which slice parameters are fit.
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
void muse_sky_fit_params_delete(muse_sky_fit_params *)
Delete the fit parameter structure.
cpl_table * table
The pixel table.
int slice_fit_h5
Polynomial order for the H5 fit parameter. Use -1 to not fit H5.
int slice_fit_h3
Polynomial order for the H3 fit parameter. Use -1 to not fit H3.
Structure definition of MUSE pixel table.
cpl_frame * muse_processing_new_frame(muse_processing *aProcessing, int aIFU, cpl_propertylist *aHeader, const char *aTag, cpl_frame_type aType)
Create a new frame for a result file.
cpl_array * muse_cpltable_extract_column(cpl_table *aTable, const char *aColumn)
Create an array from a section of a column.
int slice_fit_refraction
Use the refraction index as slice dependent fit parameter.
cpl_frameset * outputFrames
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.
muse_sky_fit_params * muse_sky_fit_params_new(cpl_boolean, cpl_boolean, cpl_size, cpl_size, cpl_size, cpl_size, cpl_size, cpl_size, cpl_size, cpl_size)
Create a new fit parameter 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.
int slice_fit_offset
Use wavelength offset as slice dependent fit parameter.
unsigned short muse_pixtable_origin_get_ifu(uint32_t aOrigin)
Get the IFU number from the encoded 32bit origin number.
Structure to hold the parameters of the muse_sky_lsf recipe.
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.
int slice_fit_bin_width
Use the bin width as fit parameter.
int slice_fit_h6
Polynomial order for the H6 fit parameter. Use -1 to not fit H6.
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
muse_lsf_params ** muse_processing_lsf_params_load(muse_processing *aProcessing, int aIFU)
Load slice LSF parameters.
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
cpl_frameset * inputFrames
Structure definition of detector (slice) parameters.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
void muse_lsf_params_delete(muse_lsf_params **aParams)
Delete an allocated array of muse_lsf_params structure.
cpl_propertylist * header
The FITS header.