32 #include "muse_scipost_z.h" 52 muse_scipost_offsets_scale(
muse_pixtable *aPT,
const cpl_table *aOffsets,
55 if (!aPT || !aOffsets) {
61 cpl_msg_info(__func__,
"Applying offsets to %s...", aPurpose);
62 cpl_msg_indent_more();
67 char keyword[KEYWORD_LENGTH], comment[KEYWORD_LENGTH];
69 if (isfinite(offsets[0]) && isfinite(offsets[1])) {
72 cpl_msg_debug(__func__,
"Applying coordinate offsets to exposure: %e/%e" 73 " deg", offsets[0], offsets[1]);
75 cpl_errorstate state = cpl_errorstate_get();
76 cpl_propertylist_update_double(aPT->
header,
"RA", ra);
77 if (!cpl_errorstate_is_equal(state)) {
78 cpl_errorstate_set(state);
79 cpl_propertylist_update_float(aPT->
header,
"RA", ra);
81 cpl_propertylist_set_comment(aPT->
header,
"RA",
"offset applied!");
82 state = cpl_errorstate_get();
83 cpl_propertylist_update_double(aPT->
header,
"DEC", dec);
84 if (!cpl_errorstate_is_equal(state)) {
85 cpl_errorstate_set(state);
86 cpl_propertylist_update_float(aPT->
header,
"DEC", dec);
88 cpl_propertylist_set_comment(aPT->
header,
"DEC",
"offset applied!");
90 snprintf(keyword, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DRA, 1);
91 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DRA_C, offsets[0] * 3600.);
92 cpl_propertylist_append_double(aPT->
header, keyword, offsets[0]);
93 cpl_propertylist_set_comment(aPT->
header, keyword, comment);
94 snprintf(keyword, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DDEC, 1);
95 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DDEC_C, offsets[1] * 3600.);
96 cpl_propertylist_append_double(aPT->
header, keyword, offsets[1]);
97 cpl_propertylist_set_comment(aPT->
header, keyword, comment);
99 if (isnormal(offsets[2])) {
101 cpl_msg_debug(__func__,
"Scaling flux of exposure by %g.", offsets[2]);
104 snprintf(keyword, KEYWORD_LENGTH, MUSE_HDR_FLUX_SCALEi, 1);
105 cpl_propertylist_append_double(aPT->
header, keyword, offsets[2]);
106 cpl_propertylist_set_comment(aPT->
header, keyword, MUSE_HDR_FLUX_SCALEi_C);
109 snprintf(keyword, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DATEOBS, 1);
110 snprintf(comment, KEYWORD_LENGTH, MUSE_HDR_OFFSETi_DATEOBS_C, 1);
111 cpl_propertylist_append_string(aPT->
header, keyword,
113 cpl_propertylist_set_comment(aPT->
header, keyword, comment);
116 cpl_msg_indent_less();
140 const char *savevalid =
"cube,skymodel,individual,positioned,combined,stacked";
149 prop->
darcheck = MUSE_POSTPROC_DARCHECK_NONE;
150 if (aParams->
darcheck == MUSE_SCIPOST_PARAM_DARCHECK_CHECK) {
151 prop->
darcheck = MUSE_POSTPROC_DARCHECK_CHECK;
152 }
else if (aParams->
darcheck == MUSE_SCIPOST_PARAM_DARCHECK_CORRECT) {
153 prop->
darcheck = MUSE_POSTPROC_DARCHECK_CORRECT;
158 MUSE_TAG_STD_RESPONSE, 0);
160 MUSE_TAG_STD_TELLURIC, 0);
162 MUSE_TAG_EXTINCT_TABLE, 0);
168 cpl_msg_warning(__func__,
"Using default MUSE WFM astrometry, output " 169 "world coordinates will be inaccurate!");
178 { MUSE_SCIPOST_PARAM_SKYMETHOD_NONE, MUSE_POSTPROC_SKYMETHOD_NONE },
179 { MUSE_SCIPOST_PARAM_SKYMETHOD_SUBTRACT_MODEL, MUSE_POSTPROC_SKYMETHOD_NONE },
180 { MUSE_SCIPOST_PARAM_SKYMETHOD_MODEL, MUSE_POSTPROC_SKYMETHOD_MODEL },
181 { MUSE_SCIPOST_PARAM_SKYMETHOD_SIMPLE, MUSE_POSTPROC_SKYMETHOD_SIMPLE },
182 { MUSE_SCIPOST_PARAM_SKYMETHOD_INVALID_VALUE, MUSE_POSTPROC_SKYMETHOD_MODEL },
184 prop->
skymethod = MUSE_POSTPROC_SKYMETHOD_MODEL;
187 skymethod[i_method].par != MUSE_SCIPOST_PARAM_SKYMETHOD_INVALID_VALUE;
189 if (skymethod[i_method].par == aParams->
skymethod) {
190 prop->
skymethod = skymethod[i_method].postproc;
200 if (cpl_array_get_size(crarray) < 2) {
203 cpl_msg_warning(__func__,
"Less than two values given by sky_crsigma " 204 "parameter, using defaults (%.3f.,%.3f)!",
208 ? atof(cpl_array_get_string(crarray, 0)) : 15.;
210 ? atof(cpl_array_get_string(crarray, 1)) : 0.;
212 cpl_array_delete(crarray);
214 #ifdef USE_LSF_PARAMS 215 cpl_errorstate prestate = cpl_errorstate_get();
217 if (aParams->
skymethod == MUSE_SCIPOST_PARAM_SKYMETHOD_SUBTRACT_MODEL) {
221 #ifdef USE_LSF_PARAMS 225 cpl_errorstate_set(prestate);
231 }
else if (aParams->
skymethod == MUSE_SCIPOST_PARAM_SKYMETHOD_MODEL) {
234 #ifdef USE_LSF_PARAMS 237 cpl_errorstate_set(prestate);
240 cpl_msg_error(__func__,
"Missing required LSF frames for sky model");
241 #ifdef USE_LSF_PARAMS 247 cpl_msg_error(__func__,
"Missing required sky lines frame for sky model");
250 #ifdef USE_LSF_PARAMS
260 }
else if (aParams->
skymethod == MUSE_SCIPOST_PARAM_SKYMETHOD_SIMPLE) {
268 cpl_msg_error(__func__,
"no science exposures found in input");
272 int nexposures = cpl_table_get_nrow(prop->
exposures);
277 cpl_msg_warning(__func__,
"Input %s has unexpected format, proceeding " 278 "without offset and flux scales!", MUSE_TAG_OFFSET_LIST);
279 cpl_table_delete(offsets);
287 for (i = 0; i < nexposures; i++) {
292 for (i2 = 0; i2 <= i; i2++) {
297 cpl_table_delete(offsets);
301 if (strstr(aParams->
save,
"skymodel")) {
306 cpl_propertylist *header = cpl_propertylist_duplicate(pixtables[i]->header);
307 cpl_propertylist_erase_regexp(header, MUSE_HDR_PT_REGEXP, 0);
310 cpl_propertylist_delete(header);
313 cpl_propertylist *header = cpl_propertylist_duplicate(pixtables[i]->header);
314 cpl_propertylist_erase_regexp(header, MUSE_HDR_PT_REGEXP, 0);
317 cpl_propertylist_delete(header);
320 cpl_propertylist *header = cpl_propertylist_duplicate(pixtables[i]->header);
321 cpl_propertylist_erase_regexp(header, MUSE_HDR_PT_REGEXP, 0);
324 cpl_propertylist_delete(header);
329 cpl_table_delete(skyout->
lines);
333 if (strstr(aParams->
save,
"individual")) {
335 MUSE_TAG_PIXTABLE_REDUCED,
338 if (strstr(aParams->
save,
"positioned")) {
344 muse_scipost_offsets_scale(pt, offsets,
345 "positioned pixel table for saving");
349 MUSE_TAG_PIXTABLE_POSITIONED,
358 if (nexposures > 1) {
361 if (rc != CPL_ERROR_NONE) {
362 cpl_msg_error(__func__,
"weighting the pixel tables didn't work: %s",
363 cpl_error_get_message());
364 for (i = 0; i < nexposures; i++) {
368 cpl_table_delete(offsets);
374 cpl_msg_error(__func__,
"combining the pixel tables didn't work: %s",
375 cpl_error_get_message());
376 for (i = 0; i < nexposures; i++) {
380 cpl_table_delete(offsets);
384 bigpixtable = pixtables[0];
386 cpl_msg_indent_more();
387 muse_scipost_offsets_scale(bigpixtable, offsets,
388 "single pixel table for resampling");
389 cpl_msg_indent_less();
395 cpl_table_delete(offsets);
397 cpl_error_code rc = CPL_ERROR_NONE;
398 if (strstr(aParams->
save,
"cube")) {
402 rp->
dx = aParams->
dx;
403 rp->dy = aParams->
dy;
404 rp->dlambda = aParams->
dlambda;
407 rp->
ld = aParams->
ld;
408 rp->
rc = aParams->
rc;
412 cpl_propertylist_delete(outwcs);
415 format, rp, aParams->
filter);
418 if (strstr(aParams->
save,
"combined")) {
420 MUSE_TAG_PIXTABLE_COMBINED,
423 if (strstr(aParams->
save,
"stacked")) {
424 cpl_msg_debug(__func__,
"additional output as column-stacked image");
435 return rc == CPL_ERROR_NONE ? 0 : -1;
muse_rvcorrect_type rvtype
muse_image * muse_resampling_image(muse_pixtable *aPixtable, muse_resampling_type aMethod, double aDX, double aDLambda)
Resample a pixel table onto a two-dimensional regular grid.
cpl_propertylist * muse_postproc_cube_load_output_wcs(muse_processing *aProcessing)
Find a file with a usable output WCS in the input frameset.
muse_postproc_properties * muse_postproc_properties_new(muse_postproc_type aType)
Create a post-processing properties object.
muse_postproc_skymethod
Method of sky subtraction to apply.
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
double lambdamin
Cut off the data below this wavelength after loading the pixel table(s).
muse_pixtable * muse_pixtable_duplicate(muse_pixtable *aPixtable)
Make a copy of the pixtanle.
int muse_processing_save_mask(muse_processing *aProcessing, int aIFU, muse_mask *aMask, const char *aTag)
Save a computed MUSE mask to disk.
double muse_pfits_get_ra(const cpl_propertylist *aHeaders)
find out the right ascension
cpl_error_code muse_resampling_params_set_wcs(muse_resampling_params *aParams, const cpl_propertylist *aWCS)
Set an output WCS (and wavelength scale) in the resampling parameters.
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.
muse_xcombine_types muse_postproc_get_weight_type(const char *aWeightString)
Select correct weighting type for weight string.
double skymodel_ignore
Fraction of the image to be ignored. If an input sky mask is provided, the fraction is applied to the...
cpl_table * muse_sky_lines_load(muse_processing *)
Load the sky data files.
muse_resampling_crstats_type muse_postproc_get_cr_type(const char *aCRTypeString)
Select correct cosmic ray rejection type for crtype string.
int ld
Number of adjacent pixels to take into account during resampling in all three directions (loop distan...
const char * muse_pfits_get_dateobs(const cpl_propertylist *aHeaders)
find out the date of observations
const char * rvcorr_s
Correct the radial velocity of the telescope with reference to either the barycenter of the Solar Sys...
muse_rvcorrect_type muse_rvcorrect_select_type(const char *aTypeString)
Select type of radial velocity correction to be done from type string.
void muse_sky_qc_lines(cpl_propertylist *, cpl_table *, const char *)
Fill a header with the QC parameters for the sky lines.
void * muse_postproc_process_exposure(muse_postproc_properties *aProp, unsigned int aIndex, muse_postproc_sky_outputs *aSkyOut)
Merge and process pixel tables from one exposure.
Structure definition of MUSE three extension FITS file.
const char * pixfrac
Pixel down-scaling factor for the "drizzle" resampling method. Up to three, comma-separated, floating-point values can be given. If only one value is given, it applies to all dimensions, two values are interpreted as spatial and spectral direction, respectively, while three are taken as horizontal, vertical, and spectral.
cpl_error_code muse_postproc_cube_resample_and_collapse(muse_processing *aProcessing, muse_pixtable *aPixtable, muse_cube_type aFormat, muse_resampling_params *aParams, const char *aFilter)
High level function to resample to a datacube and collapse that to an image of the field of view and ...
cpl_error_code muse_xcombine_weights(muse_pixtable **aPixtables, muse_xcombine_types aWeighting)
compute the weights for combination of two or more exposures
muse_postproc_skymethod skymethod
muse_lsf_params ** lsf_params
cpl_error_code muse_cpltable_check(const cpl_table *aTable, const muse_cpltable_def *aDef)
Check whether the table contains the fields of the definition.
const char * sky_crsigma
Sigma level clipping for cube-based and spectrum-based CR rejection when creating the sky spectrum...
const char * filter
The filter name(s) to be used for the output field-of-view image. Each name has to correspond to an E...
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.
const char * weight_s
Type of weighting scheme to use when combining multiple exposures. "exptime" just uses the exposure t...
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.
muse_cube_type muse_postproc_get_cube_format(const char *aFormatString)
Select correct cube format for format string.
double * muse_xcombine_find_offsets(const cpl_table *aOffsets, const char *aDateObs)
Get offsets and scale from table row with matching DATE-OBS entry.
double dy
Vertical step size for resampling (in arcsec or pixel). The following defaults are taken when this va...
cpl_boolean muse_postproc_check_save_param(const char *aSave, const char *aValid)
Check the –save parameter contents against allowed options.
muse_resampling_params * muse_resampling_params_new(muse_resampling_type aMethod)
Create the resampling parameters structure.
double lambdaref
Reference wavelength used for correction of differential atmospheric refraction. The R-band (peak wav...
double rc
Critical radius for the "renka" resampling method.
muse_lsf_cube ** muse_lsf_cube_load_all(muse_processing *aProcessing)
Load all LSF cubes for all IFUs into an array.
muse_pixtable * muse_xcombine_tables(muse_pixtable **aPixtables, const cpl_table *aOffsets)
combine the pixel tables of several exposures into one
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.
Structure definition of the post-processing properties.
double skymodel_fraction
Fraction of the image (without the ignored part) to be considered as sky. If an input sky mask is pro...
void muse_postproc_properties_delete(muse_postproc_properties *aProp)
Free memory taken by a post-processing properties object and all its components.
const char * crtype_s
Type of statistics used for detection of cosmic rays during final resampling. "iraf" uses the varianc...
int darcheck
Carry out a check of the theoretical DAR correction using source centroiding. If "correct" it will al...
double skymodel_sampling
Spectral sampling of the sky spectrum [Angstrom].
double muse_pfits_get_dec(const cpl_propertylist *aHeaders)
find out the declination
int astrometry
If false, skip any astrometric calibration, even if one was passed in the input set of files...
muse_mask * muse_processing_load_mask(muse_processing *aProcessing, const char *aTag)
Load a mask file and its FITS header.
double skymodel_csampling
Spectral sampling of the continuum spectrum [Angstrom].
muse_lsf_cube ** lsf_cube
cpl_error_code muse_resampling_params_set_pixfrac(muse_resampling_params *aParams, const char *aString)
Set resampling pixfrac given a string that can contain up to three floating-point values...
const char * format_s
Type of output file format, "Cube" is a standard FITS cube with NAXIS=3 and multiple extensions (for ...
double lambdamax
Cut off the data above this wavelength after loading the pixel table(s).
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_resampling_type muse_postproc_get_resampling_type(const char *aResampleString)
Select correct resampling type for resample string.
double dx
Horizontal step size for resampling (in arcsec or pixel). The following defaults are taken when this ...
int skymethod
The method used to subtract the sky background (spectrum). Option "model" should work in all kinds of...
Structure to hold the parameters of the muse_scipost recipe.
double crsigma
Sigma rejection factor to use for cosmic ray rejection during final resampling. A zero or negative va...
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_resampling_type
Resampling types.
Structure definition of the post-processing output sky data.
void muse_resampling_params_delete(muse_resampling_params *aParams)
Delete a resampling parameters structure.
muse_lsf_params ** muse_processing_lsf_params_load(muse_processing *aProcessing, int aIFU)
Load slice LSF parameters.
cpl_error_code muse_wcs_position_celestial(muse_pixtable *aPixtable, double aRA, double aDEC)
Convert native to celestial spherical coordinates in a pixel table.
muse_sky_params skymodel_params
cpl_table * muse_processing_sort_exposures(muse_processing *aProcessing)
Sort input frames (containing lists of pixel table filenames) into different exposures.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
cpl_propertylist * muse_processing_load_header(muse_processing *aProcessing, const char *aTag)
load a header according to its tag
cpl_table * sky_continuum
muse_postproc_darcheck darcheck
muse_xcombine_types
Xposure combination types.
double dlambda
Wavelength step size (in Angstrom). Natural instrument sampling is used, if this is 0...
const char * resample_s
The resampling technique to use for the final output cube. (as string)
cpl_propertylist * header
The FITS header.
const char * save
Select output product(s) to save. Can contain one or more of "cube", "skymodel", "individual", "positioned", "combined", and "stacked". If several options are given, they have to be comma-separated. ("cube": output cube and associated images, if this is not given, no final resampling is done at all – "skymodel": up to four additional output products about the effectively used sky that was subtracted with the "model" method – "individual": fully reduced pixel table for each individual exposure – "positioned": fully reduced and positioned pixel table for each individual exposure, the difference to "individual" is that here, the output pixel tables have coordinates in RA and DEC; this is only useful, if both the relative exposure weighting and the final resampling are to be done externally – "combined": fully reduced and combined pixel table for the full set of exposures, the difference to "positioned" is that all pixel tables are combined into one, with an added weight column; this is useful, if only the final resampling step is to be done separately – "stacked": an additional output file in form of a 2D column-stacked image, i.e. x direction is pseudo-spatial, y direction is wavelength.)
cpl_error_code muse_pixtable_flux_multiply(muse_pixtable *aPixtable, double aScale)
Scale the flux of a pixel table with correct treatment of variance.
cpl_propertylist * muse_wcs_create_default(void)
Create FITS headers containing a default (relative) WCS.
cpl_error_code muse_sky_save_continuum(muse_processing *, const cpl_table *, cpl_propertylist *)
Save sky continuum table to file.