MUSE Pipeline Reference Manual  2.1.1
Data Structures | Enumerations | Functions
Post-processing functions

Data Structures

struct  muse_postproc_properties
 Structure definition of the post-processing properties. More...
 
struct  muse_postproc_sky_outputs
 Structure definition of the post-processing output sky data. More...
 

Enumerations

Functions

muse_postproc_propertiesmuse_postproc_properties_new (muse_postproc_type aType)
 Create a post-processing properties object. More...
 
void muse_postproc_properties_delete (muse_postproc_properties *aProp)
 Free memory taken by a post-processing properties object and all its components. More...
 
cpl_boolean muse_postproc_check_save_param (const char *aSave, const char *aValid)
 Check the –save parameter contents against allowed options. More...
 
muse_resampling_type muse_postproc_get_resampling_type (const char *aResampleString)
 Select correct resampling type for resample string. More...
 
muse_resampling_crstats_type muse_postproc_get_cr_type (const char *aCRTypeString)
 Select correct cosmic ray rejection type for crtype string. More...
 
muse_cube_type muse_postproc_get_cube_format (const char *aFormatString)
 Select correct cube format for format string. More...
 
muse_xcombine_types muse_postproc_get_weight_type (const char *aWeightString)
 Select correct weighting type for weight string. More...
 
cpl_table * muse_postproc_load_nearest (const cpl_propertylist *aHeader, const cpl_frame *aFrame, float aWarnLimit, float aErrLimit, double *aRA, double *aDEC)
 Load the calibration from a multi-table FITS file that is nearest on the sky. More...
 
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. More...
 
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. More...
 
cpl_propertylist * muse_postproc_cube_load_output_wcs (muse_processing *aProcessing)
 Find a file with a usable output WCS in the input frameset. More...
 
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 save both objects. More...
 
cpl_error_code muse_postproc_qc_fwhm (muse_processing *aProcessing, muse_datacube *aCube)
 Compute QC1 parameters for datacubes and save them in the FITS header. More...
 

Detailed Description

This module contains functions that are common to some post-processing recipes.

Function Documentation

cpl_boolean muse_postproc_check_save_param ( const char *  aSave,
const char *  aValid 
)

Check the –save parameter contents against allowed options.

Parameters
aSave–save parameter string constant
aValidcomma-delimited string of all valid options
Returns
CPL_TRUE if everything is ok, CPL_FALSE something went wrong.

Definition at line 135 of file muse_postproc.c.

References muse_cplarray_new_from_delimited_string().

cpl_propertylist* muse_postproc_cube_load_output_wcs ( muse_processing aProcessing)

Find a file with a usable output WCS in the input frameset.

Parameters
aProcessingthe processing structure
Returns
A cpl_propertylist with the WCS or NULL on failure

The file to search should be tagged as MUSE_TAG_OUTPUT_WCS in the input aProcessing->inFrames. This function then takes the header of the first extension that has NAXIS=2 or 3 (or WCSAXES=2 or 3) and supported CTYPEi entries for all relevant axes (supported are RA—TAN for axis1, DEC–TAN for axis 2, and AWAV and AWAV-LOG for axis 3). If aProcessing->inFrames contains multiple files with the required tag, only the first one is taken into account.

Exceptions
set CPL_ERROR_NULL_INPUT, return NULLaProcessing is NULL
set CPL_ERROR_NONE, return NULLno file tagged MUSE_TAG_OUTPUT_WCS was found

Definition at line 874 of file muse_postproc.c.

References muse_processing::inframes, muse_frameset_find(), and muse_processing_append_used().

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 save both objects.

Parameters
aProcessingthe processing structure
aPixtablethe MUSE pixel table to resample
aFormatthe output format of the datacube
aParamsthe structure of resampling parameters
aFilterthe string with comma-separated filter names to load
Returns
CPL_ERROR_NONE on success or a cpl_error_code on failure
Exceptions
return CPL_ERROR_NULL_INPUTaProcessing, aPixtable, or aParams are NULL
return CPL_ERROR_ILLEGAL_INPUTaFormat contains an invalid format ID
propagate error code of muse_resampling_<format>resampling to cube fails
propagate error code of muse_processing_save_cube()saving cube fails

Definition at line 964 of file muse_postproc.c.

References muse_image::header, muse_cplarray_new_from_delimited_string(), MUSE_CUBE_TYPE_EURO3D, MUSE_CUBE_TYPE_EURO3D_X, MUSE_CUBE_TYPE_FITS, MUSE_CUBE_TYPE_FITS_X, MUSE_CUBE_TYPE_SDP, muse_datacube_collapse(), muse_datacube_convert_dq(), muse_datacube_delete(), muse_euro3dcube_collapse(), muse_euro3dcube_delete(), muse_image_delete(), muse_image_dq_to_nan(), muse_imagelist_get_size(), muse_imagelist_new(), muse_imagelist_set(), MUSE_PHYS_AIR_STANDARD, muse_phys_air_to_vacuum(), muse_pixgrid_delete(), muse_postproc_qc_fwhm(), muse_processing_save_cube(), muse_processing_save_image(), muse_resampling_collapse_pixgrid(), muse_resampling_cube(), MUSE_RESAMPLING_DISP_WAVE, MUSE_RESAMPLING_DISP_WAVE_LOG, muse_resampling_euro3d(), muse_table_delete(), muse_table_load_filter(), muse_utils_copy_modified_header(), and muse_resampling_params::tlambda.

muse_resampling_crstats_type muse_postproc_get_cr_type ( const char *  aCRTypeString)

Select correct cosmic ray rejection type for crtype string.

Parameters
aCRTypeStringthe format string from the recipe parameters
Returns
The respective cosmic ray rejection type as muse_resampling_crstats_type or MUSE_RESAMPLING_CRSTATS_MEDIAN on error.

The framework in principle ensures that no unsupported/unknown crtypes arrive here but nevertheless fall back to MUSE_RESAMPLING_CRSTATS_MEDIAN as the default in case something really weird happens.

Exceptions
set CPL_ERROR_NULL_INPUT, return MUSE_RESAMPLING_CRSTATS_MEDIANaCRTypeString is NULL

Definition at line 228 of file muse_postproc.c.

References MUSE_RESAMPLING_CRSTATS_IRAF, MUSE_RESAMPLING_CRSTATS_MEAN, and MUSE_RESAMPLING_CRSTATS_MEDIAN.

muse_cube_type muse_postproc_get_cube_format ( const char *  aFormatString)

Select correct cube format for format string.

Parameters
aFormatStringthe format string from the recipe parameters
Returns
The respective cube format as muse_cube_type or MUSE_CUBE_TYPE_FITS on error.

The framework in principle ensures that no unsupported/unknown formats arrive here but nevertheless fall back to MUSE_CUBE_TYPE_FITS as the default in case something really weird happens.

Exceptions
set CPL_ERROR_NULL_INPUT, return MUSE_CUBE_TYPE_FITSaFormatString is NULL

Definition at line 259 of file muse_postproc.c.

References MUSE_CUBE_TYPE_EURO3D, MUSE_CUBE_TYPE_EURO3D_X, MUSE_CUBE_TYPE_FITS, MUSE_CUBE_TYPE_FITS_X, and MUSE_CUBE_TYPE_SDP.

muse_resampling_type muse_postproc_get_resampling_type ( const char *  aResampleString)

Select correct resampling type for resample string.

Parameters
aResampleStringthe format string from the recipe parameters
Returns
The respective resampling type as muse_resampling_type or MUSE_RESAMPLE_WEIGHTED_DRIZZLE on error.

The framework in principle ensures that no unsupported/unknown resampling types arrive here but nevertheless fall back to MUSE_RESAMPLE_WEIGHTED_DRIZZLE as the default in case something really weird happens.

Exceptions
set CPL_ERROR_NULL_INPUT, return MUSE_RESAMPLE_WEIGHTED_DRIZZLEaResampleString is NULL

Definition at line 187 of file muse_postproc.c.

References MUSE_RESAMPLE_NEAREST, MUSE_RESAMPLE_WEIGHTED_DRIZZLE, MUSE_RESAMPLE_WEIGHTED_LANCZOS, MUSE_RESAMPLE_WEIGHTED_LINEAR, MUSE_RESAMPLE_WEIGHTED_QUADRATIC, and MUSE_RESAMPLE_WEIGHTED_RENKA.

muse_xcombine_types muse_postproc_get_weight_type ( const char *  aWeightString)

Select correct weighting type for weight string.

Parameters
aWeightStringthe weight string from the recipe parameters
Returns
The respective weighting type as muse_xcombine_types or MUSE_XCOMBINE_EXPTIME on error.

The framework in principle ensures that no unsupported/unknown weight types arrive here but nevertheless fall back to MUSE_XCOMBINE_EXPTIME as the default in case something really weird happens.

Exceptions
set CPL_ERROR_NULL_INPUT, return MUSE_XCOMBINE_EXPTIMEaWeightString is NULL

Definition at line 296 of file muse_postproc.c.

References MUSE_XCOMBINE_EXPTIME, MUSE_XCOMBINE_FWHM, and MUSE_XCOMBINE_NONE.

cpl_table* muse_postproc_load_nearest ( const cpl_propertylist *  aHeader,
const cpl_frame *  aFrame,
float  aWarnLimit,
float  aErrLimit,
double *  aRA,
double *  aDEC 
)

Load the calibration from a multi-table FITS file that is nearest on the sky.

Parameters
aHeaderthe FITS header with the reference position (RA, DEC)
aFramethe frame containing the multi-table file information
aWarnLimitminimum distance in arcsec before warning is given
aErrLimitminimum distance in arcsec before failing
aRARA of reference source to return (can be NULL)
aDECDEC of reference source to return (can be NULL)
Returns
a table selected to be nearest on the sky or NULL on error

This loops through all FITS extensions present in the file in aFrame and computes the distance on the sky relative to the position taken from aHeader. The table from the extension with the nearest distance is then loaded.

A warning is output if the distance is larger than half the MUSE field size, i.e. more than aWarnLimit arcsec.

Exceptions
set CPL_ERROR_NULL_INPUT, return NULLaHeader and/or aFrame are NULL
set CPL_ERROR_DATA_NOT_FOUND, return NULLaHeader does not contain RA and/or DEC
set CPL_ERROR_INCOMPATIBLE_INPUT, return NULLposition in aHeader is more than aErrLimit away from all reference sources

Definition at line 338 of file muse_postproc.c.

References muse_astro_angular_distance(), muse_pfits_get_dec(), and muse_pfits_get_ra().

Referenced by muse_postproc_process_exposure().

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.

Parameters
aPropthe post-processing properties object
aIndexindex of the exposure (starting with 0)
aSkyOutsky output structure
Returns
a valid pointer representing the object expected by the calling recipe or NULL on error

Depending on processing type requested in the properties object, either apply all calibrations (and return a pixel table), or derive the flux response (and return a response table plus a telluric correction table), or derive an astrometric calibration (and return it).

On output, the components of the aSkyOut structure may have been filled (depending on the inputs and parameters given in aProp). Then, they need to be deallocated with the respective functions.

Pseudo code:
pixeltable = muse_pixtable_load_merge_channels()
if not standard:
  muse_flux_calibrate()
muse_sky_subtract_pixtable(pixeltable)
if WFM:
  muse_dar_correct()
  muse_dar_check()
if standard:
  muse_flux_integrate_std()
  muse_flux_response_compute()
  muse_flux_get_response_table()
  muse_flux_get_telluric_table()
  return
if astrometry:
  muse_wcs_locate_sources()
  muse_wcs_solve()
  return
muse_wcs_project_tan()
Exceptions
set CPL_ERROR_NULL_INPUT, return NULLaProp or aProp->exposures are NULL
set CPL_ERROR_ILLEGAL_INPUT, return NULLaIndex is larger than the last index in the aProp->exposures table

Definition at line 500 of file muse_postproc.c.

References muse_postproc_properties::centroid, muse_postproc_sky_outputs::continuum, muse_postproc_properties::crpix2, muse_resampling_params::crsigma, muse_resampling_params::crtype, muse_postproc_properties::darcheck, muse_image::data, muse_flux_object::decref, muse_postproc_properties::detsigma, muse_postproc_properties::exposures, muse_postproc_properties::extinction, muse_postproc_properties::faccuracy, muse_pixtable::header, muse_flux_object::intimage, muse_postproc_properties::lambdamax, muse_postproc_properties::lambdamin, muse_postproc_properties::lambdaref, muse_postproc_sky_outputs::lines, muse_postproc_properties::lsf_cube, muse_postproc_properties::lsf_params, muse_postproc_sky_outputs::mask, muse_astro_airmass(), muse_cplerrorstate_dump_some(), muse_cpltable_extract_column(), muse_dar_check(), muse_dar_correct(), muse_datacube_collapse(), muse_datacube_delete(), muse_flux_calibrate(), muse_flux_compute_qc(), muse_flux_get_response_table(), muse_flux_get_telluric_table(), muse_flux_integrate_std(), muse_flux_object_new(), muse_flux_reference_table_check(), muse_flux_response_compute(), muse_image_delete(), muse_lsf_average_cube_all(), muse_lsf_fold_rectangle(), muse_mask_delete(), muse_pfits_get_dec(), muse_pfits_get_mode(), muse_pfits_get_ra(), muse_pixtable_and_selected_mask(), muse_pixtable_delete(), muse_pixtable_duplicate(), muse_pixtable_load_merge_channels(), muse_postproc_load_nearest(), muse_postproc_revert_ffspec_maybe(), MUSE_RESAMPLE_WEIGHTED_DRIZZLE, MUSE_RESAMPLING_CRSTATS_MEDIAN, muse_resampling_cube(), muse_resampling_params_delete(), muse_resampling_params_new(), muse_resampling_spectrum(), muse_resampling_spectrum_iterate(), muse_rvcorrect(), muse_sky_continuum_create(), muse_sky_create_skymask(), muse_sky_lines_fit(), muse_sky_lines_fit_old(), muse_sky_lines_set_range(), muse_sky_subtract_continuum(), muse_sky_subtract_lines(), muse_sky_subtract_lines_old(), muse_table_delete(), muse_table_load_filter(), muse_wcs_locate_sources(), muse_wcs_object_new(), muse_wcs_optimize_solution(), muse_wcs_project_tan(), muse_wcs_solve(), muse_postproc_properties::niter, muse_postproc_properties::profile, muse_postproc_properties::radius, muse_flux_object::raref, muse_postproc_properties::refframe, muse_postproc_properties::rejsigma, muse_postproc_properties::response, muse_postproc_properties::rvtype, muse_postproc_properties::select, muse_postproc_properties::sky_continuum, muse_postproc_properties::sky_lines, muse_postproc_properties::sky_mask, muse_postproc_properties::skymethod, muse_postproc_properties::skymodel_params, muse_postproc_properties::smooth, muse_postproc_sky_outputs::spectrum, muse_pixtable::table, muse_postproc_properties::tellregions, muse_postproc_properties::telluric, muse_postproc_properties::type, and muse_postproc_properties::wcs.

void muse_postproc_properties_delete ( muse_postproc_properties aProp)
muse_postproc_properties* muse_postproc_properties_new ( muse_postproc_type  aType)

Create a post-processing properties object.

Parameters
aTypethe type of processing to set
Returns
the post-processing properties object or NULL on error

In the returned structure, all pointer objects are NULL. The sky subtraction method is set to MUSE_POSTPROC_SKYMETHOD_NONE.

Exceptions
set CPL_ERROR_ILLEGAL_INPUT, return NULLunsupported aType is given

Definition at line 77 of file muse_postproc.c.

References muse_postproc_properties::type.

cpl_error_code muse_postproc_qc_fwhm ( muse_processing aProcessing,
muse_datacube aCube 
)

Compute QC1 parameters for datacubes and save them in the FITS header.

Parameters
aProcessingthe processing structure
aCubethe datacube
Returns
CPL_ERROR_NONE on success or a cpl_error_code on failure

The prefix of the generated QC1 FITS keywords is set depending on the recipe name in the aProcessing structure.

Note
Part of this is copied in the image_fwhm tool.
Algorithm:
This function detects objects in the central wavelength plane of the input datacube, derives the FWHM for each source in x- and y-direction, and converts the FWHM from pixel scale to arcsec units which are saved in the header of the input cube.
Exceptions
return CPL_ERROR_NULL_INPUTaProcessing or aCube are NULL
return CPL_ERROR_DATA_NOT_FOUNDno sources were detected
output info message, return CPL_ERROR_NONEunknown recipe called this function

Definition at line 1132 of file muse_postproc.c.

References muse_datacube::data, muse_datacube::header, muse_pfits_get_cd(), muse_pfits_get_crpix(), muse_pfits_get_crval(), muse_pfits_get_ctype(), muse_pfits_get_mode(), and muse_processing::name.

Referenced by muse_postproc_cube_resample_and_collapse().

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.

Parameters
aPtpixel table with the on-sky data
aResponsethe response table with header
Returns
CPL_ERROR_NONE if nothing needs to be done or on success, another CPL error code on failure.

This function is a dirty trick to improve backward compatibility: if an old (pre v2.0, without flat-field spectrum correction) STD_RESPONSE was passed to the one of the post-processing recipes, then make the (merged) pixel table compatible to that response, by reverting application of the flat-field spectrum. In effect, this function divides the pixel table again by the averaged flat-field spectrum.

Definition at line 416 of file muse_postproc.c.

References muse_pixtable::ffspec, muse_table::header, muse_pixtable::header, muse_cpltable_extract_column(), MUSE_HDR_PT_FFCORR, MUSE_PIXTABLE_FFDATA, MUSE_PIXTABLE_FFLAMBDA, and muse_pixtable_spectrum_apply().

Referenced by muse_postproc_process_exposure().