UVES Pipeline Reference Manual  5.4.0
Macros | Functions
Utility functions

Macros

#define REQ_CPL_MAJOR   3
 Check compile time and runtime library versions.
#define REQ_CPL_MINOR   1
#define REQ_CPL_MICRO   0
#define REQ_QF_MAJOR   6
#define REQ_QF_MINOR   2
#define REQ_QF_MICRO   0

Functions

static cpl_error_code uves_cosrout (cpl_image *ima, cpl_image **msk, const double ron, const double gain, const int ns, const double sky, const double rc, cpl_image **flt, cpl_image **out)
 Remove cosmic ray events on single ccd exposure and replace them by interpolation on neighbourhood pixels.
static cpl_error_code uves_find_next (cpl_image **msk, const int first_y, int *next_x, int *next_y)
static cpl_error_code uves_sort (const int kmax, float *inp, int *ord)
cpl_error_code uves_rcosmic (cpl_image *ima, cpl_image **flt, cpl_image **out, cpl_image **msk, const double sky, const double ron, const double gain, const int ns, const double rc)
 Remove cosmic ray events on single ccd exposure and replace them by interpolation on neighbourhood pixels.
static double uves_ksigma_vector (cpl_vector *values, double klow, double khigh, int kiter)
 Perform kappa-sigma clip.
cpl_image * uves_ksigma_stack (const cpl_imagelist *imlist, double klow, double khigh, int kiter)
 Stack images using k-sigma clipping.
cpl_image * uves_get_wave_map (cpl_image *ima_sci, const char *context, const cpl_parameterlist *parameters, const cpl_table *ordertable, const cpl_table *linetable, const polynomial *order_locations, const polynomial *dispersion_relation, const int first_abs_order, const int last_abs_order, const int slit_size)
 Generates wave map.
cpl_image * uves_flat_create_normalized_master2 (cpl_imagelist *flats, const cpl_table *ordertable, const polynomial *order_locations, const cpl_image *mflat)
 Stack images using k-sigma clipping.
cpl_image * uves_flat_create_normalized_master (cpl_imagelist *flats, const cpl_table *ordertable, const polynomial *order_locations, const cpl_vector *gain_vals, double *fnoise)
 Stack images using k-sigma clipping.
cpl_parameterlist * uves_parameterlist_duplicate (const cpl_parameterlist *pin)
 Extract frames with given tag from frameset.
const char * uves_string_toupper (char *s)
 Convert all lowercase characters in a string into uppercase characters.
const char * uves_string_tolower (char *s)
 Convert all uppercase characters in a string into lowercase characters.
cpl_frameset * uves_frameset_extract (const cpl_frameset *frames, const char *tag)
 Extract frames with given tag from frameset.
double uves_pow_int (double x, int y)
 Calculate x to the y'th.
cpl_error_code uves_get_version (int *major, int *minor, int *micro)
 Get UVES library version number.
int uves_get_version_binary (void)
 Get UVES library binary version number.
const char * uves_get_license (void)
 Get the pipeline copyright and license.
void uves_check_version (void)
cpl_error_code uves_end (const char *recipe_id, const cpl_frameset *frames)
 Recipe termination.
char * uves_initialize (cpl_frameset *frames, const cpl_parameterlist *parlist, const char *recipe_id, const char *short_descr)
 Recipe initialization.
cpl_image * uves_average_images (const cpl_image *image1, const cpl_image *noise1, const cpl_image *image2, const cpl_image *noise2, cpl_image **noise)
 Optimally average images.
uves_propertylistuves_initialize_image_header (const char *ctype1, const char *ctype2, const char *cunit1, const char *cunit2, const char *bunit, const double bscale, double crval1, double crval2, double crpix1, double crpix2, double cdelt1, double cdelt2)
 Initialize image header.
cpl_image * uves_define_noise (const cpl_image *image, const uves_propertylist *image_header, int ncom, enum uves_chip chip)
 Create noise image.
cpl_error_code uves_subtract_bias (cpl_image *image, const cpl_image *master_bias)
 Subtract bias.
cpl_error_code uves_subtract_dark (cpl_image *image, const uves_propertylist *image_header, const cpl_image *master_dark, const uves_propertylist *mdark_header)
 Subtract dark.
int uves_absolute_order (int first_abs_order, int last_abs_order, int relative_order)
 Get the absolute order number.
double uves_average_reject (cpl_table *t, const char *column, const char *residual2, double kappa)
 Get average with iterative rejection.
polynomialuves_polynomial_regression_1d (cpl_table *t, const char *X, const char *Y, const char *sigmaY, int degree, const char *polynomial_fit, const char *residual_square, double *mean_squared_error, double kappa)
 Fit a 1d polynomial to two table columns.
polynomialuves_polynomial_regression_2d (cpl_table *t, const char *X1, const char *X2, const char *Y, const char *sigmaY, int degree1, int degree2, const char *polynomial_fit, const char *residual_square, const char *variance_fit, double *mse, double *red_chisq, polynomial **variance, double kappa, double min_reject)
 Fit a 2d polynomial to three table columns.
polynomialuves_polynomial_regression_2d_autodegree (cpl_table *t, const char *X1, const char *X2, const char *Y, const char *sigmaY, const char *polynomial_fit, const char *residual_square, const char *variance_fit, double *mean_squared_error, double *red_chisq, polynomial **variance, double kappa, int maxdeg1, int maxdeg2, double min_rms, double min_reject, bool verbose, const double *min_val, const double *max_val, int npos, double positions[][2])
 Fit a 2d polynomial to three table columns.
const char * uves_remove_string_prefix (const char *s, const char *prefix)
 Remove named prefix from string.
double uves_gaussrand (void)
 Pseudo-random gaussian distributed number.
double uves_spline_hermite_table (double xp, const cpl_table *t, const char *column_x, const char *column_y, int *istart)
 Spline interpolation based on Hermite polynomials.
double uves_spline_hermite (double xp, const double *x, const double *y, int n, int *istart)
 Spline interpolation based on Hermite polynomials.
double uves_spline_cubic (double xp, double *x, float *y, float *y2, int n, int *kstart)
 Natural cubic-spline interpolation.
bool uves_table_is_sorted_double (const cpl_table *t, const char *column, const bool reverse)
 Determine if a table is sorted.
cpl_table * uves_ordertable_traces_new (void)
 Create the table that describes fibre traces.
cpl_error_code uves_ordertable_traces_add (cpl_table *traces, int fibre_ID, double fibre_offset, int fibre_mask)
 Add a trace.
cpl_error_code uves_tablename_remove_units (const char *tname)
 Remove column units from a table.
cpl_error_code uves_tablenames_unify_units (const char *tname2, const char *tname1)
 Unify column units in tables.
cpl_error_code uves_table_remove_units (cpl_table **table)
 Remove column units from a table.
cpl_error_code uves_table_unify_units (cpl_table **table2, cpl_table **table1)
 Unify column units of table2 to table1.
static void fmoffa_i (float x, const double a[], double *y, double dyda[])
 This subroutine gives the value of the Moffat (beta=4)+ linear functions at pixel of coordinates x estimated at one point.
static void fmoffa_c (float x, const double a[], double *y, double dyda[])
 Moffat profile.
int uves_moffat (const double x[], const double a[], double *result)
 Evaluate a Moffat.
int uves_moffat_derivative (const double x[], const double a[], double result[])
 Evaluate Moffat derivative.
int uves_gauss (const double x[], const double a[], double *result)
 Evaluate a gaussian.
int uves_gauss_derivative (const double x[], const double a[], double result[])
 Evaluate the derivatives of a gaussian.
int uves_gauss_linear (const double x[], const double a[], double *result)
 Evaluate a gaussian with linear background.
int uves_gauss_linear_derivative (const double x[], const double a[], double result[])
 Evaluate the derivatives of a gaussian with linear background.
cpl_image * uves_create_image (uves_iterate_position *pos, enum uves_chip chip, const cpl_image *spectrum, const cpl_image *sky, const cpl_image *cosmic_image, const uves_extract_profile *profile, cpl_image **image_noise, uves_propertylist **image_header)
 Reconstruct echelle image from spectrum.
void uves_frameset_dump (cpl_frameset *set)

uves_image_smooth_x

Smooth an image using a simple mean.

Parameters:
inpImage to shift.
Returns:
1 newly allocated image.
See also:
uves_spline_hermite

This function interpolate an image using hermite splines.

The returned image is a newly allocated object, it must be deallocated using uves_image_delete().

cpl_image * uves_image_smooth_x (cpl_image *inp, const int r)
cpl_image * uves_image_smooth_y (cpl_image *inp, const int r)

uves_image_smooth_mean_x

Smooth an image using a simple mean.

Parameters:
inpImage to shift.
Returns:
1 newly allocated image.
See also:
uves_spline_hermite

This function interpolate an image using hermite splines.

The returned image is a newly allocated object, it must be deallocated using uves_image_delete().

cpl_image * uves_image_smooth_mean_x (cpl_image *inp, const int r)

uves_image_smooth_median_x

Smooth an image using a simple mean.

Parameters:
inpImage to shift.
Returns:
1 newly allocated image.
See also:
uves_spline_hermite

This function interpolate an image using hermite splines.

The returned image is a newly allocated object, it must be deallocated using uves_image_delete().

cpl_image * uves_image_smooth_median_x (cpl_image *inp, const int r)

uves_image_smooth_fft

Smooth an image using a FFT.

Parameters:
inpImage to filter
fxImage to filter
Returns:
1 newly allocated image. This function applies a lowpass spatial filter of frequency fy along Y.

The returned image is a newly allocated object, it must be deallocated using uves_free_image().

static cpl_image * uves_gen_lowpass (const int xs, const int ys, const double sigma_x, const double sigma_y)
 Generate a low pass filter for FFT convolution .
cpl_image * uves_image_smooth_fft (cpl_image *inp, const int fx)
cpl_vector * uves_imagelist_get_clean_mean_levels (cpl_imagelist *iml, double kappa)
 Computes kappa-sigma clean mean (free bad pixels) for each input image of the input imagelist.
cpl_error_code uves_imagelist_subtract_values (cpl_imagelist **iml, cpl_vector *values)
 Subtract from input imagelist values specified in input vector.
cpl_image * uves_image_mflat_detect_blemishes (const cpl_image *flat, const uves_propertylist *head)
 Flag blemishes in a flat image.

Detailed Description

This module contains various functions that are shared between multiple recipes


Macro Definition Documentation

#define REQ_CPL_MAJOR   3

Check compile time and runtime library versions.

Returns:
CPL_ERROR_NONE iff OK

The function returns error if CPL and QFITS version are not up to date. Running with versions older than required will cause subtle bugs.

This function should be called from "make check" to verify an installation

Definition at line 1712 of file uves_utils.c.


Function Documentation

static cpl_error_code uves_cosrout ( cpl_image *  ima,
cpl_image **  msk,
const double  ron,
const double  gain,
const int  ns,
const double  sky,
const double  rc,
cpl_image **  flt,
cpl_image **  out 
)
static

Remove cosmic ray events on single ccd exposure and replace them by interpolation on neighbourhood pixels.

Author:
P.Magain, M.Remy, Institut d'Astrophysique de Liege Ported to UVES pipe from MIDAS rcosmic.for
Parameters:
imainput image
fltmedian filter of input image
outoutput image
bkgmean value of the background
ronReadout noise in ADU units.
gainInverse gain factor (e-/ADU)
nsthreshold for the detection of cosmic rays
nccritical ratio for discrimination of objects and cosmic rays
mskname of an optional frame containing the value 1 for cosmic rays and 0 for all other pixels
Note:
The detection threshold is in units of the theoretical noise sigma of each pixel; it's default value is 4. The default for `rc' is 2.
Returns:

Definition at line 846 of file uves_utils.c.

References check_nomsg, uves_msg_debug, and uves_msg_warning.

Referenced by uves_rcosmic().

static cpl_image * uves_gen_lowpass ( const int  xs,
const int  ys,
const double  sigma_x,
const double  sigma_y 
)
static

Generate a low pass filter for FFT convolution .

Parameters:
xsx size of the generated image.
ysy size of the generated image.
sigma_xSigma for the gaussian distribution.
sigma_ySigma for the gaussian distribution.
Returns:
1 newly allocated image.

This function generates an image of a 2d gaussian, modified in such a way that the different quadrants have a quadrants of the gaussian in the corner. This image is suitable for FFT convolution. Copied from eclipse, src/iproc/generate.c

The returned image must be deallocated.

Definition at line 5083 of file uves_utils.c.

References uves_msg_error.

cpl_error_code uves_rcosmic ( cpl_image *  ima,
cpl_image **  flt,
cpl_image **  out,
cpl_image **  msk,
const double  sky,
const double  ron,
const double  gain,
const int  ns,
const double  rc 
)

Remove cosmic ray events on single ccd exposure and replace them by interpolation on neighbourhood pixels.

Author:
P.Magain, M.Remy, Institut d'Astrophysique de Liege Ported to UVES pipe from MIDAS rcosmic.for
Parameters:
imainput image
fltmedian filter of input image
outoutput image
skymean value of the sky background
ronReadout noise in ADU units.
gainInverse gain factor (e-/ADU)
nsthreshold for the detection of cosmic rays
nccritical ratio for discrimination of objects and cosmic rays
mskname of an optional frame containing the value 1 for cosmic rays and 0 for all other pixels
Note:
The detection threshold is in units of the theoretical noise sigma of each pixel; it's default value is 4. The default for `rc' is 2.

a) The algorithm works as follows:

  1. The input image is filtered in the following way: FILTER/MEDIAN inframe middumma 1,1,0.0 NA For Long-Slit spectra of extended sources, the algorithm may be more efficient if the median filter works only along the slit.
  2. The input image is compared with the filtered image. All pixels with an intensity I greater than Im+ns*sigma are suspicious and may be cosmic rays (Im is the filtered intensity of a pixel and sigma is given by: sigma**2 = ron**2+I/gain).
  3. All suspicious pixels are grouped into sets of contiguous points. In each of these sets, the pixel with the maximum intensity Imax is selected. If (Imax-sky) is greater than rc*(Iaver-sky), Iaver being an average of the intensities of the first eight neighbours of that pixel, the whole set of points is considered as a cosmic ray event.
  4. The intensities of the pixels affected by cosmic rays are replaced by a median value calculated over the nearest neighbours of the group to which they belong. b) In many situations, rc is the most critical parameter and requires careful fine-tuning. If it is choosen too small, small sources such as stars may be affected. If rc is too large, the filter may not remove weak partical hits superimposed to reasonably well exposed extended sources.
Returns:
newly allocated parametrlist or NULL on error

Definition at line 162 of file uves_utils.c.

References check_nomsg, uves_cosrout(), and uves_filter_image_median().

Referenced by uves_utl_rcosmic().

static double uves_ksigma_vector ( cpl_vector *  values,
double  klow,
double  khigh,
int  kiter 
)
static

Perform kappa-sigma clip.

Author:
C. Izzo
Parameters:
valuesvalues to be checked
klowkappa to clip too low level values
khighkappa to clip too high values
kiternumber of iterations
Note:
In first iteration a median is the reference value for robustness
Returns:

Definition at line 277 of file uves_utils.c.

References check_nomsg.

Referenced by uves_ksigma_stack().

cpl_image* uves_ksigma_stack ( const cpl_imagelist *  imlist,
double  klow,
double  khigh,
int  kiter 
)

Stack images using k-sigma clipping.

Parameters:
imlistList of images to stack
klowNumber of sigmas for rejection of lowest values
khighNumber of sigmas for rejection of highest values
kiterMax number of iterations
Returns:
Stacked image.

At the first iteration the value of sigma is computed relatively to the median value of all pixels at a given image position. For the next iterations the sigma is computed in the standard way. If at some iteration all points would be rejected, the mean computed at the previous iteration is returned.

Definition at line 356 of file uves_utils.c.

References check_nomsg, passure, and uves_ksigma_vector().

cpl_image* uves_get_wave_map ( cpl_image *  ima_sci,
const char *  context,
const cpl_parameterlist *  parameters,
const cpl_table *  ordertable,
const cpl_table *  linetable,
const polynomial order_locations,
const polynomial dispersion_relation,
const int  first_abs_order,
const int  last_abs_order,
const int  slit_size 
)

Generates wave map.

Parameters:
ima_sci(to get dimensions)
contextrecipe context
parametersinput params
ordertableorder table
linetableline table
order_locationsorder traces polynomial description
dispersion_relationwavelength solution
first_abs_ordermin abs order
last_abs_ordermax abs order
slit_sizeslit size in pixels
flatsList of flats to stack
ordertableInput order table
order_locationspolynomial description of order locations
Returns:
wavemap image (that need to be deallocated from caller) Generates an image that at each point has an intensity equal to the corresponding pixels for each order for each x with y position on the order trace determines the wavelength corresponding to (x,y,m) and set it to the corresponding map(x,y,m) pixel. We assume that point at the same x,m have same waveleng for each y along the extraction slit. endfor endfor

Definition at line 452 of file uves_utils.c.

References check_nomsg, uves_absolute_order(), uves_msg, and uves_polynomial_evaluate_2d().

Referenced by extract_ff_rebin_merge().

cpl_image* uves_flat_create_normalized_master2 ( cpl_imagelist *  flats,
const cpl_table *  ordertable,
const polynomial order_locations,
const cpl_image *  mflat 
)

Stack images using k-sigma clipping.

Parameters:
flatsList of flats to stack
ordertableInput order table
order_locationspolynomial description of order locations
Returns:
Stacked image.

The input list of flats is analized to compute for each flat for each order The median flux on a number of windows of given X * Y size. The mean flux of the values computed on each order is computed. endfor Finally the mean flux of all means is computed. The flat is normalized by the computed mean endfor

Definition at line 551 of file uves_utils.c.

References check, check_nomsg, uves_msg, and uves_polynomial_evaluate_2d().

Referenced by uves_mflat_process_chip().

cpl_image* uves_flat_create_normalized_master ( cpl_imagelist *  flats,
const cpl_table *  ordertable,
const polynomial order_locations,
const cpl_vector *  gain_vals,
double *  fnoise 
)

Stack images using k-sigma clipping.

Parameters:
flatsList of flats to stack
ordertableInput order table
order_locationspolynomial description of order locations
Returns:
Stacked image.

The input list of flats is analized to compute for each flat for each order The median flux on a number of windows of given X * Y size. The mean flux of the values computed on each order is computed. endfor Finally the mean flux of all means is computed. The flat is normalized by the computed mean endfor

Definition at line 702 of file uves_utils.c.

References check, check_nomsg, passure, uves_msg, and uves_polynomial_evaluate_2d().

Referenced by uves_mflat_process_chip().

cpl_parameterlist* uves_parameterlist_duplicate ( const cpl_parameterlist *  pin)

Extract frames with given tag from frameset.

Parameters:
pininput parameterlist
Returns:
newly allocated parametrlist or NULL on error

Definition at line 1461 of file uves_utils.c.

const char* uves_string_toupper ( char *  s)

Convert all lowercase characters in a string into uppercase characters.

Parameters:
sThe string to convert.
Returns:
Returns a pointer to the converted string.

Walks through the given string and turns lowercase characters into uppercase characters using toupper().

See also:
uves_string_tolower()

Definition at line 1493 of file uves_utils.c.

Referenced by uves_mflat_process_chip(), uves_reduce_mflat(), uves_reduce_mflat_combine(), uves_reduce_scired(), and uves_utl_physmod().

const char* uves_string_tolower ( char *  s)

Convert all uppercase characters in a string into lowercase characters.

Parameters:
sThe string to convert.
Returns:
Returns a pointer to the converted string.

Walks through the given string and turns uppercase characters into lowercase characters using tolower().

See also:
uves_string_tolower()

Definition at line 1527 of file uves_utils.c.

cpl_frameset* uves_frameset_extract ( const cpl_frameset *  frames,
const char *  tag 
)

Extract frames with given tag from frameset.

Parameters:
framesframe set
tagto search for
Returns:
newly allocated, possibly empty, frameset, or NULL on error

Definition at line 1557 of file uves_utils.c.

Referenced by uves_msflats().

double uves_pow_int ( double  x,
int  y 
)

Calculate x to the y'th.

Parameters:
x
yThe exponent. May be positive or zero or negative.
Note:
This function is (very much, on some platforms) faster than pow() from math.h when y is an integer

Definition at line 1593 of file uves_utils.c.

Referenced by opt_measure_profile_order(), uves_polynomial_fit_1d(), and uves_polynomial_fit_2d().

cpl_error_code uves_get_version ( int *  major,
int *  minor,
int *  micro 
)

Get UVES library version number.

Parameters:
major(output) If non-null, the major version number
minor(output) If non-null, the minor version number
micro(output) If non-null, the micro version number
Returns:
CPL_ERROR_NONE iff okay

Definition at line 1641 of file uves_utils.c.

int uves_get_version_binary ( void  )

Get UVES library binary version number.

Returns:
Binary version number

Definition at line 1660 of file uves_utils.c.

const char* uves_get_license ( void  )

Get the pipeline copyright and license.

Returns:
The copyright and license string

The function returns a pointer to the statically allocated license string. This string should not be modified using the returned pointer.

Definition at line 1676 of file uves_utils.c.

Referenced by cpl_plugin_get_info().

cpl_error_code uves_end ( const char *  recipe_id,
const cpl_frameset *  frames 
)

Recipe termination.

Parameters:
recipe_idName of calling recipe
framesThe output frame set
Returns:
CPL_ERROR_NONE iff OK

This function is called at the end of a recipe. The output frame set is printed, and the number of warnings produced by the recipe (using uves_msg_warning()) is summarized. See also uves_initialize().

Definition at line 1840 of file uves_utils.c.

References assure_mem, check_nomsg, uves_msg_get_warnings(), and uves_msg_warning.

char* uves_initialize ( cpl_frameset *  frames,
const cpl_parameterlist *  parlist,
const char *  recipe_id,
const char *  short_descr 
)

Recipe initialization.

Parameters:
framesThe input frame set
parlistThe input parameter list
recipe_idName of the recipe, e.g. uves_mbias
short_descrA short description of what the recipe does
framesThe input frame set
Returns:
current time in ISO 8601 format

This function takes care of all the mandatory tasks that are common for every recipe before the beginning of the data reduction. This function

  • initializes error handling (by resetting the error state),
  • initializes messaging (thereby setting the severity level),
  • initializes plotting (by reading the plotting commands from the parameterlist and passing these to the plotting module),
  • makes sure that the CPL and qfits libraries are up to date, and prints a warning message if not,
  • defines the group of all input frames (see uves_dfs_set_groups()), and
  • prints the input frame set.

Definition at line 1909 of file uves_utils.c.

References check, uves_get_datetime_iso8601(), uves_msg, uves_msg_debug, uves_msg_low, uves_msg_set_level(), and uves_print_cpl_frameset().

Referenced by test_save_frame().

cpl_image* uves_average_images ( const cpl_image *  image1,
const cpl_image *  noise1,
const cpl_image *  image2,
const cpl_image *  noise2,
cpl_image **  noise 
)

Optimally average images.

Parameters:
image1First image
noise1Noise (one sigma) of first image
image2Second image
noise2Noise (one sigma) of second image
noise(Output) Combined noise image. This may not be NULL.
Returns:
The optimally combined image

For each pixel the resultant flux is computed as x = (x1 / sigma_1^2 + x2 / sigma_2^2) / ( 1 / sigma_1^2 + 1 / sigma_2^2)

and the combined noise is

1/sigma^2 = 1 / sigma_1^2 + 1 / sigma_2^2.

Bad pixels are properly propagated (i.e. a resulting pixel is marked bad if both inputs are bad ; if only one input is good, this input is used as the output and the 'bad' input is ignored).

Note:
If it turns out to be necessary, this function can be optimized by using 'image1_data[i]' rather than 'cpl_image_get(image1, x, y, &pis_rejected1)', i.e. avoid multiplication for each pixel

Definition at line 2045 of file uves_utils.c.

Referenced by subtract_sky_row().

uves_propertylist* uves_initialize_image_header ( const char *  ctype1,
const char *  ctype2,
const char *  cunit1,
const char *  cunit2,
const char *  bunit,
const double  bscale,
double  crval1,
double  crval2,
double  crpix1,
double  crpix2,
double  cdelt1,
double  cdelt2 
)

Initialize image header.

Parameters:
ctype1Value of CTYPE1 keyword
ctype2Value of CTYPE2 keyword
bunitValue of BUNIT keyword
crval1Value of CRVAL1 keyword
crval2Value of CRVAL2 keyword
crpix1Value of CRPIX1 keyword
crpix2Value of CRPIX2 keyword
cdelt1Value of CDELT1 keyword
cdelt2Value of CDELT2 keyword
Returns:
Header containing the specified FITS keywords

Definition at line 2173 of file uves_utils.c.

References check, uves_pfits_set_bscale(), uves_pfits_set_bunit(), uves_pfits_set_cdelt1(), uves_pfits_set_cdelt2(), uves_pfits_set_crpix1(), uves_pfits_set_crpix2(), uves_pfits_set_crval1(), uves_pfits_set_crval2(), uves_pfits_set_ctype1(), uves_pfits_set_ctype2(), uves_pfits_set_cunit1(), uves_pfits_set_cunit2(), and uves_propertylist_new().

Referenced by uves_extract(), uves_merge_orders(), uves_rebin(), and uves_scired_process_chip().

cpl_image* uves_define_noise ( const cpl_image *  image,
const uves_propertylist image_header,
int  ncom,
enum uves_chip  chip 
)

Create noise image.

Parameters:
imageInput image
image_headerInput image header
ncomNumber of combined frames
chipCCD chip
Returns:
The newly allocated noise image, or NULL on error.

The noise image is calculated as a combination of read-out noise, discretization noise and photonic noise.

The noise decreases accordingly if the number of combined frames, ncom, is more than one. Those frames are assumed to have been median stacked.

(See source code for the exact error propagation formulas).

Definition at line 2225 of file uves_utils.c.

References assure_mem, check, uves_msg_debug, uves_pfits_get_exptime(), uves_pfits_get_gain(), uves_pfits_get_ron_adu(), uves_propertylist_contains(), uves_propertylist_get_double(), and uves_tostring_cpl_type().

Referenced by revise_noise(), and uves_reduce().

cpl_error_code uves_subtract_bias ( cpl_image *  image,
const cpl_image *  master_bias 
)

Subtract bias.

Parameters:
imageThe image to be de-biased
master_biasThe bias image to subtract
Returns:
CPL_ERROR_NONE iff okay

Negative values are set to zero.

Definition at line 2391 of file uves_utils.c.

References check, and passure.

Referenced by uves_mflat_process_chip(), and uves_reduce().

cpl_error_code uves_subtract_dark ( cpl_image *  image,
const uves_propertylist image_header,
const cpl_image *  master_dark,
const uves_propertylist mdark_header 
)

Subtract dark.

Parameters:
imageThe image to be dark-subtracted
image_headerThe image header
master_darkThe dark image to subtract
mdark_headerThe master dark header
Returns:
CPL_ERROR_NONE iff okay

Before subtracting the dark frame, it is normalized to the same exposure time as the input image. Exposure times are read from the provided headers.

Definition at line 2435 of file uves_utils.c.

References check, passure, uves_msg, uves_msg_warning, and uves_pfits_get_exptime().

Referenced by uves_reduce().

int uves_absolute_order ( int  first_abs_order,
int  last_abs_order,
int  relative_order 
)

Get the absolute order number.

Parameters:
first_abs_orderAbsolute order number of row number 1 in the spectrum image
last_abs_orderAbsolute order number of the highest row in the spectrum image
relative_orderRelative order number (row number in spectrum image)
Returns:
The absolute order number

This function converts from row number in a spectrum image to absolute (physical) order number.

Definition at line 2488 of file uves_utils.c.

Referenced by uves_get_wave_map(), uves_rebin(), and uves_response_efficiency().

double uves_average_reject ( cpl_table *  t,
const char *  column,
const char *  residual2,
double  kappa 
)

Get average with iterative rejection.

Parameters:
ttable, rows with outliers are removed
columnwith data values
residual2name of temporary column used to store the squared residuals (this column must not already exist)
kapparejection parameter
Returns:
robust mean

Outliers are rejected using robust estimation. The final average value is computed using the arithmetic mean, which has lower error than the median.

Definition at line 2510 of file uves_utils.c.

References check_nomsg.

Referenced by uves_delete_bad_lines().

polynomial* uves_polynomial_regression_1d ( cpl_table *  t,
const char *  X,
const char *  Y,
const char *  sigmaY,
int  degree,
const char *  polynomial_fit,
const char *  residual_square,
double *  mean_squared_error,
double  kappa 
)

Fit a 1d polynomial to two table columns.

Parameters:
tTable
XName of table column containing independent variable
YName of table column containing dependent variable
sigmaYUncertainty of dependent variable. If NULL, constant uncertainties are assumed.
degreeDegree of polynomial fit
polynomial_fitName of column to add
residual_squareName of column to add
mean_squared_errorMean squared error of the residuals
kappaIf positive, the value of kappa used in a kappa sigma-clipping. Ignored if negative.
Returns:
Fitted polynomial

This function fits column Y as function of X. Both columns must have type CPL_TYPE_DOUBLE or CPL_TYPE_INT.

If non-NULL the columns specified by the parameters polynomial_fit and residual_square are added to the table (containing the fitted value and the squared residual for each point). If any of these columns already exist, an error is set.

If kappa is positive, a kappa-sigma clipping is performed (iteratively, until there are no points with residuals worse than kappa*sigma). The rejected points (rows) are physically removed from the table.

Note that rows with invalid values are not handled properly (the garbage values are used for the fitting). Therefore the input table should not have invalid rows.

Definition at line 2587 of file uves_utils.c.

References check, uves_msg_debug, uves_polynomial_delete(), uves_polynomial_evaluate_1d(), uves_polynomial_fit_1d(), and uves_tostring_cpl_type().

Referenced by fit_order_linear(), opt_measure_profile(), opt_measure_profile_order(), uves_get_blaze_ratio(), and uves_physmod_calmap().

polynomial* uves_polynomial_regression_2d ( cpl_table *  t,
const char *  X1,
const char *  X2,
const char *  Y,
const char *  sigmaY,
int  degree1,
int  degree2,
const char *  polynomial_fit,
const char *  residual_square,
const char *  variance_fit,
double *  mse,
double *  red_chisq,
polynomial **  variance,
double  kappa,
double  min_reject 
)

Fit a 2d polynomial to three table columns.

Parameters:
tThe table
X1Name of table column containing 1st independent variable
X2Name of table column containing 2nd independent variable
YName of table column containing dependent variable
sigmaYUncertainty of dependent variable. If NULL, constant uncertainties are assumed.
degree1Degree of polynomial fit (1st variable)
degree2Degree of polynomial fit (2nd variable)
polynomial_fitIf non-NULL, name of column to add. The fitted value.
residual_squareIf non-NULL, name of column to add. The squared residual of the fit.
variance_fitIf non-NULL, name of column to add. Variance of the fitted value.
mean_squared_error(out) Mean squared error of the residuals. May be NULL.
red_chisq(out) Reduced chi square of the fit. May be NULL.
variance(out) Variance of the fit-polynomial (which is in itself a polynomial; see also uves_polynomial_fit_2d() ). May be NULL.
kappaIf positive, the value of kappa used in a kappa sigma-clipping. Ignored if negative.
min_rejectMinimum number of outliers worth rejecting. Stop iterating (for efficiency) if less than this relative number of outliers (e.g. 0.001) are detected. Negative to disable
Returns:
Fitted polynomial

This function fits column Y (must be of type CPL_TYPE_DOUBLE) as function of X1 (CPL_TYPE_DOUBLE or CPL_TYPE_INT) and X2 (CPL_TYPE_DOUBLE or CPL_TYPE_INT). The column sigmaY contains the Y-uncertainties. If NULL, constant uncertainty equal to 1 is assumed.

If non-NULL the columns specified by the parameters polynomial_fit, residual_square and variance_fit are added to the table (containing the fitted value, the squared residual and the variance of the fitted value, for each point).

If non-NULL, the mean_squared_error and red_chisq (reduced chi square) are calculated.

If non-NULL the parameter variance will contain the polynomial that defines the variance of the fit (i.e. as function of x1 and x2 ).

To calculate variances or reduced chi square, the parameter sigmaY must be non-NULL.

If kappa is positive, a kappa-sigma clipping is performed (iteratively, until there are no points with residuals worse than kappa*sigma). The rejected points (rows) are physically removed from the table.

Also see uves_polynomial_regression_1d() .

Definition at line 2866 of file uves_utils.c.

References check, uves_msg_debug, uves_polynomial_delete(), uves_polynomial_evaluate_2d(), uves_polynomial_fit_2d(), and uves_tostring_cpl_type().

Referenced by calibrate_global(), create_line_table(), opt_measure_profile(), uves_locate_orders(), uves_physmod_calmap(), uves_physmod_msrawxy(), uves_physmod_regress_echelle(), and uves_polynomial_regression_2d_autodegree().

polynomial* uves_polynomial_regression_2d_autodegree ( cpl_table *  t,
const char *  X1,
const char *  X2,
const char *  Y,
const char *  sigmaY,
const char *  polynomial_fit,
const char *  residual_square,
const char *  variance_fit,
double *  mean_squared_error,
double *  red_chisq,
polynomial **  variance,
double  kappa,
int  maxdeg1,
int  maxdeg2,
double  min_rms,
double  min_reject,
bool  verbose,
const double *  min_val,
const double *  max_val,
int  npos,
double  positions[][2] 
)

Fit a 2d polynomial to three table columns.

Parameters:
tThe table
X1Name of table column containing 1st independent variable
X2Name of table column containing 2nd independent variable
YName of table column containing dependent variable
sigmaYUncertainty of dependent variable. If NULL, constant uncertainties are assumed.
polynomial_fitIf non-NULL, name of column to add. The fitted value.
residual_squareIf non-NULL, name of column to add. The squared residual of the fit.
variance_fitIf non-NULL, name of column to add. Variance of the fitted value.
mean_squared_error(out) Mean squared error of the residuals. May be NULL.
red_chisq(out) Reduced chi square of the fit. May be NULL.
variance(out) Variance of the fit-polynomial (which is in itself a polynomial; see also uves_polynomial_fit_2d() ). May be NULL.
kappaIf positive, the value of kappa used in a kappa sigma-clipping. Ignored if negative.
maxdeg1Maximum degree of 1st independent variable
maxdeg2Maximum degree of 2nd independent variable
min_rmsMinimum RMS to aim for. Stop iterating (for efficiency) if this precision is achieved. Set to negative to disable.
min_rejectMinimum number of outliers worth rejecting. Stop iterating (for efficiency) if less than this relative number of outliers (e.g. 0.001) are detected. Negative to disable
verboseprint messages at info level (true) or debug level (false)
min_valminimum allowed value. A fit producing a value lower than this number will be rejected. Set to NULL to disable
max_valmaximum allowed value
npossize of positions array
positionspositions where the fitted solution must be inside the limits given by min_val / max_val (for the solution to be accepted)
Returns:
Fitted polynomial

This function is like uves_polynomial_regression_2d() except it automatically selects the best polynomial degrees based on the RMS of the fit.

Note:
that when kappa-sigma clipping is involved, it becomes rather complicated to decide which are the optimal degrees, and for that reason this function is not expected to give good results for all possible kinds of input data.

Definition at line 3302 of file uves_utils.c.

References assure_mem, check, check_nomsg, uves_error_reset, uves_msg_debug, uves_msg_low, uves_polynomial_delete(), uves_polynomial_evaluate_2d(), and uves_polynomial_regression_2d().

Referenced by calibrate_global(), opt_measure_profile(), and repeat_orderdef().

const char* uves_remove_string_prefix ( const char *  s,
const char *  prefix 
)

Remove named prefix from string.

Parameters:
sstring
prefixthe prefix to remove
Returns:
s without prefix, or NULL on error. This points to a position in the string s, and therefore must not be deallocated.

The function fails if prefix is not a prefix of s.

Definition at line 3609 of file uves_utils.c.

Referenced by tflat_qclog(), uves_qclog_add_common_wave(), and uves_qclog_init().

double uves_gaussrand ( void  )

Pseudo-random gaussian distributed number.

Returns:
Pseudo-random gasssian value with mean zero, stdev 1, based on C's rand()

It is probably a good idea to call srand() before using this function, for reasons of reproducability.

Definition at line 3642 of file uves_utils.c.

double uves_spline_hermite_table ( double  xp,
const cpl_table *  t,
const char *  column_x,
const char *  column_y,
int *  istart 
)

Spline interpolation based on Hermite polynomials.

Parameters:
xpx-value to interpolate
tTable containing the columns to interpolate
column_xColumn of x-values
column_yColumn of y-values
istart(input/output) initial row (set to 0 to search all row)
Returns:
The interpolated value.

Definition at line 3680 of file uves_utils.c.

References check, and uves_spline_hermite().

Referenced by uves_calculate_response(), uves_normalize_spectrum(), and uves_scired_process_chip().

double uves_spline_hermite ( double  xp,
const double *  x,
const double *  y,
int  n,
int *  istart 
)

Spline interpolation based on Hermite polynomials.

Parameters:
xpx-value to interpolate
xx-values
yy-values
narray length
istart(input/output) initial row (set to 0 to search all row)
Returns:
The interpolated value.

The x column must be sorted (ascending or descending) and all x column values must be different.

Adopted from: Cristian Levin - ESO La Silla, 1-Apr-1991

Definition at line 3718 of file uves_utils.c.

Referenced by uves_spline_hermite_table().

double uves_spline_cubic ( double  xp,
double *  x,
float *  y,
float *  y2,
int  n,
int *  kstart 
)

Natural cubic-spline interpolation.

Parameters:
xpx-value to interpolate
xx-array [1..n], must be sorted ascending
yy-array [1..n]
y2y2-array [1..n] (2-nd derivatives)
narray size
kstartStart search index. Contains on output index of largest x less than xp.
Returns:
the interpolated value

Definition at line 3790 of file uves_utils.c.

References assure_nomsg.

bool uves_table_is_sorted_double ( const cpl_table *  t,
const char *  column,
const bool  reverse 
)

Determine if a table is sorted.

Parameters:
tTable
columnColumn name, type must be double
reverseFlag indicating to check for ascending (false) or descending (true) sort order
Returns:
Non-zero iff table is sorted according to the specified column

Definition at line 3844 of file uves_utils.c.

References passure.

cpl_table* uves_ordertable_traces_new ( void  )

Create the table that describes fibre traces.

Returns:
The table which must be deallocated with cpl_table_delete() .

Definition at line 3895 of file uves_utils.c.

References check.

cpl_error_code uves_ordertable_traces_add ( cpl_table *  traces,
int  fibre_ID,
double  fibre_offset,
int  fibre_mask 
)

Add a trace.

Parameters:
tracesThe table containing information on the position of fibre traces (FLAMES/UVES)
fibre_IDThe fibre ID number
fibre_offsetOffset of this fibre
fibre_mask0 if fibre is disabled, 1 if it is enabled
Returns:
CPL_ERROR_NONE iff okay

Definition at line 3922 of file uves_utils.c.

References check.

cpl_error_code uves_tablename_remove_units ( const char *  tname)

Remove column units from a table.

Parameters:
tnamefilename of the table containing units to be removed (FLAMES/UVES)
Returns:
CPL_ERROR_NONE iff okay

Definition at line 3951 of file uves_utils.c.

References check_nomsg, uves_propertylist_load(), and uves_table_remove_units().

cpl_error_code uves_tablenames_unify_units ( const char *  tname2,
const char *  tname1 
)

Unify column units in tables.

Parameters:
name2of the table with reference units
name1of the table with new units
Returns:
CPL_ERROR_NONE iff okay

Definition at line 3977 of file uves_utils.c.

References check_nomsg, uves_propertylist_load(), and uves_table_unify_units().

cpl_error_code uves_table_remove_units ( cpl_table **  table)

Remove column units from a table.

Parameters:
tabThe table containing units to be removed (FLAMES/UVES)
Returns:
CPL_ERROR_NONE iff okay

Definition at line 4009 of file uves_utils.c.

Referenced by uves_tablename_remove_units().

cpl_error_code uves_table_unify_units ( cpl_table **  table2,
cpl_table **  table1 
)

Unify column units of table2 to table1.

Parameters:
table2The table with reference units
table1The table with new units
Returns:
CPL_ERROR_NONE iff okay

Definition at line 4041 of file uves_utils.c.

Referenced by uves_tablenames_unify_units().

static void fmoffa_i ( float  x,
const double  a[],
double *  y,
double  dyda[] 
)
static

This subroutine gives the value of the Moffat (beta=4)+ linear functions at pixel of coordinates x estimated at one point.

Parameters:
xinput pixel coordinates
aprofile coefficients
yMoffat profile values
dydaerrors associated to y

Definition at line 4102 of file uves_utils.c.

Referenced by fmoffa_c().

static void fmoffa_c ( float  x,
const double  a[],
double *  y,
double  dyda[] 
)
static

Moffat profile.

Parameters:
xinput pixel coordinates
aprofile coefficients
yMoffat profile values
dydaerrors associated to y
Note:
    This subroutine  gives  the value  of  the  Moffat (beta =  4,
fixed)+ linear functions  at pixel of coordinates x integrated
over  this pixel; the integration  is done  using the npoint=3
Gauss-Legendre  integration formula. The weights and abscissae
are modified to take into account the range of integration (in
pratice, the values are divided by 2) .

Definition at line 4171 of file uves_utils.c.

References fmoffa_i().

Referenced by uves_moffat(), and uves_moffat_derivative().

int uves_moffat ( const double  x[],
const double  a[],
double *  result 
)

Evaluate a Moffat.

Parameters:
xThe evaluation point
aThe parameters defining the gaussian
resultThe function value
Returns:
0 iff okay.

Definition at line 4237 of file uves_utils.c.

References fmoffa_c().

Referenced by eval_gauss(), and uves_extract().

int uves_moffat_derivative ( const double  x[],
const double  a[],
double  result[] 
)

Evaluate Moffat derivative.

Parameters:
xThe evaluation point
aThe parameters defining the gaussian
resultThe function value
Returns:
0 iff okay.

Definition at line 4256 of file uves_utils.c.

References fmoffa_c().

Referenced by uves_extract().

int uves_gauss ( const double  x[],
const double  a[],
double *  result 
)

Evaluate a gaussian.

Parameters:
xThe evaluation point
aThe parameters defining the gaussian
resultThe function value
Returns:
0 iff okay.

This function computes

a3 + a2 / sqrt(2 pi a1^2) * exp( -(x0 - a0)^2/(2 a1^2)).

where a0, ..., a3 are the first four elements of a, and x0 is the first element of x .

The function never fails.

Definition at line 4288 of file uves_utils.c.

Referenced by find_centroid(), repeat_orderdef(), test_extract(), uves_extract(), uves_fit_gaussian_2d_image(), and xcenter().

int uves_gauss_derivative ( const double  x[],
const double  a[],
double  result[] 
)

Evaluate the derivatives of a gaussian.

Parameters:
xThe evaluation point
aThe parameters defining the gaussian
resultThe derivatives wrt to parameters
Returns:
0 iff okay.

This function computes the partial derivatives of f(x0,a) = a3 + a2 / sqrt(2 pi a1^2) * exp( -(x0 - a0)^2/(2 a1^2)) with respect to a0, ..., a3. On successful evaluation, the i'th element of the result vector contains df/da_i.

The function never returns failure.

Definition at line 4343 of file uves_utils.c.

Referenced by find_centroid(), repeat_orderdef(), test_extract(), uves_extract(), uves_fit_gaussian_2d_image(), and xcenter().

int uves_gauss_linear ( const double  x[],
const double  a[],
double *  result 
)

Evaluate a gaussian with linear background.

Parameters:
xThe evaluation point
aThe parameters defining the gaussian
resultThe function value
Returns:
0 iff okay.

This function computes

a3 + a4*(x0 - a0) + a2 / sqrt(2 pi a1^2) * exp( -(x0 - a0)^2/(2 a1^2)).

where a0, ..., a4 are the first five elements of a, and x0 is the first element of x .

The function never fails.

Definition at line 4408 of file uves_utils.c.

Referenced by xcenter().

int uves_gauss_linear_derivative ( const double  x[],
const double  a[],
double  result[] 
)

Evaluate the derivatives of a gaussian with linear background.

Parameters:
xThe evaluation point
aThe parameters defining the gaussian
resultThe derivatives wrt to parameters
Returns:
0 iff okay.

This function computes the partial derivatives of

f(x0,a) = a3 + a4*(x0 - a0) + a2 / sqrt(2 pi a1^2) * exp( -(x0 - a0)^2/(2 a1^2))

with respect to a0, ..., a4. On successful evaluation, the i'th element of the result vector contains df/da_i.

The function never returns failure.

Definition at line 4467 of file uves_utils.c.

Referenced by xcenter().

cpl_image* uves_create_image ( uves_iterate_position *  pos,
enum uves_chip  chip,
const cpl_image *  spectrum,
const cpl_image *  sky,
const cpl_image *  cosmic_image,
const uves_extract_profile *  profile,
cpl_image **  image_noise,
uves_propertylist **  image_header 
)

Reconstruct echelle image from spectrum.

Parameters:
posposition iterator
chipCCD chip (for header)
spectrumobject spectrum
skysky spectrum
cosmic_imageif non-NULL, image of cosmic rays. Values > 0 mark CR hits
image_noise(output) error bars
image_header(output) describing the output image
Returns:
simulated image

Definition at line 4531 of file uves_utils.c.

References assure_mem, uves_iterate_finished(), uves_iterate_increment(), uves_iterate_set_first(), and uves_propertylist_new().

Referenced by test_extract(), and uves_extract().

cpl_vector* uves_imagelist_get_clean_mean_levels ( cpl_imagelist *  iml,
double  kappa 
)

Computes kappa-sigma clean mean (free bad pixels) for each input image of the input imagelist.

Parameters:
imlinput imagelist
kappavalue for kappa-sigma clip
Returns:
vector with computed values for each image of the list

The returned vector must be deallocated.

Definition at line 5002 of file uves_utils.c.

References check_nomsg, and uves_msg.

cpl_error_code uves_imagelist_subtract_values ( cpl_imagelist **  iml,
cpl_vector *  values 
)

Subtract from input imagelist values specified in input vector.

Parameters:
imlinput imagelist
valuesvalue to be subtracted
Returns:
corrected imagelist

The returned vector must be deallocated.

Definition at line 5043 of file uves_utils.c.

References check_nomsg.

cpl_image* uves_image_mflat_detect_blemishes ( const cpl_image *  flat,
const uves_propertylist head 
)

Flag blemishes in a flat image.

Parameters:
flatinput image
headinput header
Returns:
output flag image or NULL

Definition at line 5173 of file uves_utils.c.

References check_nomsg, passure, uves_pfits_get_binx(), and uves_pfits_get_biny().

Referenced by extract_ff_rebin_merge().