VIMOS DRS Reference Manual
2.9.13
|
Macros | |
#define | READY 1 |
Montecarlo simulation to evaluate error on polynomial fit. More... | |
Functions | |
cpl_table * | mos_global_distortion (cpl_table *slits, cpl_table *maskslits, cpl_table *ids, cpl_table *crv, double reference) |
Determine all global distortions models. More... | |
cpl_table * | mos_average_global_distortion (cpl_table **global, int nglobal, double scale, double tolerance) |
Average global distortion tables. More... | |
cpl_table * | mos_build_slit_location (cpl_table *global, cpl_table *maskslits, int ysize) |
Build the slit location table from a global distortions table. More... | |
cpl_table * | mos_build_curv_coeff (cpl_table *global, cpl_table *maskslits, cpl_table *slits) |
Build the curvature coefficients table from a global distortions table. More... | |
cpl_table * | mos_build_disp_coeff (cpl_table *global, cpl_table *slits) |
Build the IDS coefficients table from a global distortions table. More... | |
cpl_image * | mos_subtract_sky (cpl_image *science, cpl_table *slits, cpl_table *polytraces, double reference, double blue, double red, double dispersion) |
Subtract the sky from the scientific CCD exposure. More... | |
cpl_error_code | mos_slit_wavemap (cpl_image *wavemap, int slit, cpl_table *slits, cpl_table *polytraces, double reference, double blue, double red, double dispersion) |
Select wavelengths from a single spectrum. More... | |
cpl_image * | mos_normalise_flat (cpl_image *flat, cpl_image *spatial, cpl_table *slits, cpl_table *polytraces, double reference, double blue, double red, double dispersion, int sradius, int polyorder) |
Normalise a flat field exposure. More... | |
cpl_image * | mos_normalise_longflat (cpl_image *flat, int sradius, int dradius, int polyorder) |
Normalise a long slit flat field exposure. More... | |
cpl_error_code | mos_interpolate_wavecalib_slit (cpl_table *idscoeff, cpl_table *slits, int order, int global) |
Interpolate MOS wavelength calibration. More... | |
cpl_error_code | mos_interpolate_wavecalib (cpl_table *idscoeff, cpl_image *wavemap, int mode, int degree) |
Interpolate LSS wavelength calibration. More... | |
int | mos_clean_outliers (cpl_table *table, const char *name) |
Eliminate obvious outliers from table column values. More... | |
cpl_image * | mos_remove_bias (cpl_image *image, cpl_image *bias, cpl_table *overscans) |
Subtract the bias from a CCD exposure. More... | |
cpl_error_code | mos_arc_background_1D (float *spectrum, float *back, int length, int msize, int fsize) |
Background determination on 1D emission line spectrum (arc) More... | |
cpl_image * | mos_arc_background (cpl_image *image, int msize, int fsize) |
Background determination on emission line spectrum (arc) More... | |
int | mos_lines_width (const float *spectrum, int length) |
Estimate lines widths (in pixel) in arc lamp spectrum. More... | |
cpl_vector * | mos_peak_candidates (const float *spectrum, int length, float level, float exp_width) |
Find positions of peaks candidates. More... | |
cpl_vector * | mos_refine_peaks (const float *spectrum, int length, cpl_vector *peaks, int sradius) |
Improve (when possible) accuracy of peaks candidates positions. More... | |
cpl_bivector * | mos_identify_peaks (cpl_vector *peaks, cpl_vector *lines, double min_disp, double max_disp, double tolerance) |
Identify peak candidates. More... | |
double | mos_eval_dds (cpl_polynomial *ids, double blue, double red, double refwave, double pixel) |
Evaluate the wavelength of a pixel position. More... | |
cpl_polynomial * | mos_poly_wav2pix (cpl_bivector *pixwav, int order, double reject, int minlines, int *nlines, double *err) |
Fit polynomial relation from wavelengths to pixels. More... | |
cpl_polynomial * | mos_poly_pix2wav (cpl_bivector *pixwav, int order, double reject, int minlines, int *nlines, double *err) |
Fit polynomial relation from pixels to wavelengths. More... | |
cpl_bivector * | mos_find_peaks (const float *spectrum, int length, cpl_vector *lines, cpl_polynomial *ids, double refwave, int sradius) |
Find the reference lines peaks using a polynomial first-guess. More... | |
cpl_image * | mos_wavelength_calibration_raw (const cpl_image *image, cpl_vector *lines, double dispersion, float level, int sradius, int order, double reject, double refwave, double *wavestart, double *waveend, int *nlines, double *error, cpl_table *idscoeff, cpl_image *calibration, cpl_image *residuals, cpl_table *restable, cpl_mask *refmask) |
Derive wavelength calibration from a raw arc lamp or sky exposure. More... | |
cpl_table * | mos_locate_spectra (cpl_mask *mask) |
Find the location of detected spectra on the CCD. More... | |
cpl_error_code | mos_validate_slits (cpl_table *slits) |
Check validity of a slit location table. More... | |
cpl_error_code | mos_rotate_slits (cpl_table *slits, int rotation, int nx, int ny) |
Rotate a slit location table. More... | |
cpl_table * | mos_identify_slits (cpl_table *slits, cpl_table *maskslits, cpl_table *global) |
Identify slits listed in a slit location table. More... | |
cpl_table * | mos_trace_flat (cpl_image *flat, cpl_table *slits, double reference, double blue, double red, double dispersion) |
Trace flat field spectra. More... | |
cpl_table * | mos_poly_trace (cpl_table *slits, cpl_table *traces, int order) |
Fit spectral traces. More... | |
cpl_error_code | mos_global_trace (cpl_table *slits, cpl_table *polytraces, int mode) |
Recompute tracing coefficients globally. More... | |
cpl_image * | mos_spatial_calibration (cpl_image *spectra, cpl_table *slits, cpl_table *polytraces, double reference, double blue, double red, double dispersion, int flux, cpl_image *calibration) |
Spatial remapping of CCD spectra eliminating the spectral curvature. More... | |
cpl_image * | mos_wavelength_calibration_final (cpl_image *image, cpl_table *slits, cpl_vector *lines, double dispersion, float level, int sradius, int order, double reject, double refwave, double *wavestart, double *waveend, int *nlines, double *error, cpl_table *idscoeff, cpl_image *calibration, cpl_image *residuals, cpl_table *restable) |
Derive wavelength calibration from a rectified arc lamp or sky exposure. More... | |
cpl_image * | mos_wavelength_calibration (cpl_image *image, double refwave, double firstLambda, double lastLambda, double dispersion, cpl_table *idscoeff, int flux) |
Remap at constant wavelength step an image of rectified scientific spectra. More... | |
cpl_table * | mos_wavelength_align (cpl_image *image, cpl_table *slits, double refwave, double firstLambda, double lastLambda, cpl_table *idscoeff, cpl_vector *skylines, int highres, int order, cpl_image *calibration, int sradius) |
Modify the input wavelength solution to match reference sky lines. More... | |
cpl_table * | mos_wavelength_align_lss (cpl_image *image, double refwave, double firstLambda, double lastLambda, cpl_table *idscoeff, cpl_vector *skylines, int highres, int order, cpl_image *calibration, int sradius) |
Modify the input wavelength solution to match reference sky lines (LSS). More... | |
double | mos_distortions_rms (cpl_image *rectified, cpl_vector *lines, double wavestart, double dispersion, int radius, int highres) |
Estimate the spectral distortion modeling goodness. More... | |
cpl_image * | mos_map_pixel (cpl_table *idscoeff, double reference, double blue, double red, double dispersion, int trend) |
Create a pixel map from an IDS coefficients table. More... | |
cpl_image * | mos_map_idscoeff (cpl_table *idscoeff, int xsize, double reference, double blue, double red) |
Create a wavelengths map from an IDS coefficients table. More... | |
cpl_image * | mos_map_wavelengths (cpl_image *spatial, cpl_image *calibration, cpl_table *slits, cpl_table *polytraces, double reference, double blue, double red, double dispersion) |
Remapping of spatially rectified wavelengths to original CCD pixels. More... | |
cpl_image * | mos_map_spectrum (cpl_image *spectra, cpl_image *wavecalib, cpl_image *spatial, cpl_table *slits, cpl_table *polytraces, double reference, double blue, double red, double dispersion, int flux) |
Remapping of slit spectra into a grid of lambda-space coordinates. More... | |
cpl_table * | mos_sky_map_super (cpl_image *spectra, cpl_image *wavemap, double dispersion, double factor, int minpoints, cpl_image *skymap) |
Create a CCD median sky map. More... | |
cpl_table * | mos_sky_map (cpl_image *spectra, cpl_image *wavemap, double dispersion, cpl_image *skymap) |
Create a CCD median sky map. More... | |
cpl_image * | mos_sky_local_old (cpl_image *spectra, cpl_table *slits) |
Local determination of sky. More... | |
cpl_image * | mos_sky_local (cpl_image *spectra, cpl_table *slits, int order) |
Local determination of sky. More... | |
cpl_error_code | mos_clean_cosmics (cpl_image *image, float gain, float threshold, float ratio) |
Remove cosmic rays from sky-subtracted CCD spectral exposure. More... | |
cpl_image * | mos_spatial_map (cpl_image *spectra, cpl_table *slits, cpl_table *polytraces, double reference, double blue, double red, double dispersion) |
Create coordinate map from spectral curvature table. More... | |
cpl_image * | mos_detect_objects (cpl_image *image, cpl_table *slits, int margin, int maxradius, int conradius, double noise) |
Detect objects in rectified scientific frame. More... | |
cpl_image ** | mos_extract_objects (cpl_image *science, cpl_image *sky, cpl_table *objects, int extraction, double ron, double gain, int ncombined) |
Extract detected objects from rectified scientific frame. More... | |
int | mos_spectral_resolution (cpl_image *image, double lambda, double startwave, double dispersion, int saturation, double *mfwhm, double *rmsfwhm, double *resolution, double *rmsres, int *nlines) |
Compute mean spectral resolution at a given arc lamp line. More... | |
cpl_table * | mos_resolution_table (cpl_image *image, double startwave, double dispersion, int saturation, cpl_vector *lines) |
Compute mean spectral resolution at a given arc lamp line. More... | |
double | mos_integrate_signal (cpl_image *image, cpl_image *wavemap, int ystart, int yend, double wstart, double wend) |
Integrate signal from wavelength and spatial interval. More... | |
cpl_table * | mos_load_slits_fors_mxu (cpl_propertylist *header) |
Create slit location table from FITS header of FORS2-MXU data. More... | |
cpl_table * | mos_load_slits_fors_mos (cpl_propertylist *header) |
Create slit location table from FITS header of FORS1/2 MOS data. More... | |
cpl_table * | mos_load_slits_fors_lss (cpl_propertylist *header) |
Create slit location table from FITS header of FORS1/2 LSS data. More... | |
double | mos_get_gain_vimos (cpl_propertylist *header) |
Return gain factor for a VIMOS exposure. More... | |
cpl_table * | mos_load_slits_vimos (cpl_propertylist *header) |
Create slit location table from FITS header of VIMOS data. More... | |
int | mos_check_multiplex (cpl_table *slits) |
Determining whether a VIMOS mask has spectral multplexing or not. More... | |
int | mos_check_multiplex_old (cpl_table *slits) |
Determining whether a VIMOS mask has spectral multplexing or not. More... | |
int | mos_assign_multiplex_group (cpl_table *slits) |
Assign to each slit a group index, where a group has no multiplexing. More... | |
cpl_table * | mos_load_overscans_vimos (const cpl_propertylist *header, int check_consistency) |
Get the overscan positions from FITS header of VIMOS data. More... | |
cpl_error_code | mos_randomise_image (cpl_image *image, double ron, double gain, double bias) |
Randomise image. More... | |
cpl_error_code | mos_refmask_find_gaps (cpl_mask *refmask, cpl_image *master_flat, double level) |
Reconstruct the gaps required for slit location. More... | |
cpl_error_code | mos_saturation_process (cpl_image *image) |
Process saturation. More... | |
cpl_error_code | mos_subtract_background (cpl_image *image) |
Subtract the background. More... | |
cpl_error_code | mos_object_intersect (cpl_table **slitss, cpl_table *origslits, int nscience, float tolerance) |
Intersect a number of slit tables. More... | |
int | mos_get_maxobjs_per_slit (cpl_table *slits) |
Get the maximum possible number of objects in a slit. More... | |
int | mos_get_nobjects (cpl_table *slits) |
Get the total number of objects detected in a slits table. More... | |
int | mos_check_slits (cpl_table *slits, float rescale) |
Check that all slit have been detected, insert them if not. More... | |
cpl_table * | mos_load_slits_fors_pmos (cpl_propertylist *header) |
Create PMOS slit location table from FITS header of FORS1/2 MOS data. More... | |
cpl_table * | mos_photometric_calibration (cpl_image *spectra, double startwave, double dispersion, double gain, double exptime, cpl_table *ext_table, double airmass, cpl_table *flux_table, int order) |
Produce instrument response curve, with some ancillary information. More... | |
cpl_image * | mos_ksigma_stack (cpl_imagelist *imlist, double klow, double khigh, int kiter, cpl_image **good) |
Stack images using k-sigma clipping. More... | |
cpl_image * | mos_apply_photometry (cpl_image *spectra, cpl_table *response, cpl_table *ext_table, double startwave, double dispersion, double gain, double exptime, double airmass) |
Apply response curve to extracted spectra (or their errors). More... | |
int | mos_check_polarisation (cpl_image *q_image, cpl_image *q_error, cpl_image *u_image, cpl_image *u_error, double startwave, double dispersion, double band, cpl_table *pol_sta, double ra, double dec, char *filter, int *polarisation, double *p_offset, double *p_error, double *a_offset, double *a_error) |
Estimate linear polarisation parameters on spectral interval. More... | |
int | mos_compute_offset (cpl_table *reference, cpl_table *objects, double *offset) |
Estimate offset between two object tables. More... | |
cpl_error_code | mos_image_shift (cpl_image *image, double dx, double dy) |
Shift values in an image. More... | |
int | mos_slit_closest_to_center (cpl_table *slits, int nx, int ny) |
Return slit closest to CCD center. More... | |
cpl_error_code | mos_extract_flux (cpl_image *image, cpl_table *slits, double xwidth, double ywidth, int dx, double gain, double *o_flux, double *o_err) |
Measure flux from spectral interval on CCD. More... | |
cpl_error_code | mos_extract_flux_mapped (cpl_image *image, cpl_table *slits, double xwidth, double ywidth, double lambda, double startwave, double dispersion, int dx, double gain, double *o_flux, double *o_err) |
Measure flux from spectral interval on remapped frame. More... | |
int | mos_median_in_slit (cpl_table *table, cpl_table *slits, int slit, char *label, double *mvalue) |
Compute median from a table column section corresponding to a slit. More... | |
cpl_image * | mos_image_filter_median (cpl_image *image, int nx, int ny) |
Convenience function for standard median filtering. More... | |
The module moses collects low/medium level functions related to MOS data reduction.
#define READY 1 |
Montecarlo simulation to evaluate error on polynomial fit.
points | Table with (x,y) coordinates and uncertainties on y. |
evaluate | Table with x coordinates where to evaluate model variance. |
samples | Number of simulations. |
order | Degree of the fitted polynomial. |
This function evaluates the effects of variations of coordinates on a fitted polynomial model. The points table must contain two columns labeled x and y, and optionally a third column labeled y_err. x is assumed errorless, and y_err must be given at 1-sigma error. All columns must be of type CPL_TYPE_DOUBLE. A first (reference) polynomial fit p(x) is made. If the column y_err was not given, one is created and filled with the RMS of the fit residuals. The fit is then repeated samples times, varying at each time the set y coordinates according to a gaussian random distribution. The varied y coordinates to fit are taken as
y = p(x) + y_err * mos_randg(1)
where p(x) is the fit on the original points, and x are taken from the points table together with the corresponding y_err. The evaluate table should contain a column labeled x, and is returned with a new column labeled sigma, listing the sigma of the model variation at each of the indicated x coordinates.
cpl_image* mos_apply_photometry | ( | cpl_image * | spectra, |
cpl_table * | response, | ||
cpl_table * | ext_table, | ||
double | startwave, | ||
double | dispersion, | ||
double | gain, | ||
double | exptime, | ||
double | airmass | ||
) |
Apply response curve to extracted spectra (or their errors).
spectra | Image containing extracted spectra (slits or objects) |
response | Table including the response curve |
ext_table | Atmospheric extinction table |
startwave | Start wavelength |
dispersion | Angstrom per pixel of input image |
gain | Gain factor (e-/ADU) |
exptime | Exposure time (seconds) |
airmass | Airmass of observation |
Clearly if this function is applied to extracted spectra, it should be applied to their errors too.
cpl_image* mos_arc_background | ( | cpl_image * | image, |
int | msize, | ||
int | fsize | ||
) |
Background determination on emission line spectrum (arc)
image | An emission line spectrum exposure |
msize | Size of min-filter |
fsize | Size of running-average-filter |
CPL_ERROR_NULL_INPUT | The input image is a NULL pointer. |
CPL_ERROR_ILLEGAL_INPUT | Either msize is less than 3, or fsize is less than msize, or fsize is greater than half the input image size in the X direction. |
The input image is assumed to be of type float
and to contain MOS arc lamp line spectra dispersed (roughly) along the X direction. The background is estimated independently for each image row. The algorithm is based on the assumption that there is at least one background value at any position of the 1D-min-filter box running along the image row. A min-filter is passed along the row, and the result is smoothed by averaging on a running box of size fsize. The min-filter is run between the positions msize / 2 and length - msize / 2, and the min value found at such positions is then repeated up to the spectrum ends. Similarly, the running average is limited to the interval from fsize / 2 and length - fsize / 2, leaving the most external values untouched. After this, a max filter and a smoothing using boxes with double the specified sizes are run, as a way to eliminate the contamination from occasional cold pixels. Finally, the min filter and the smoothing are applied again to obviate the slight background over-estimation introduced by the max filter.
It is required that msize is greater than 1, and fsize greater than, or equal to, msize. Likewise, the image size along the X direction must be greater than fsize / 2. If such conditions are not met, or if the input image is a NULL
pointer, this function will set an error code and return a NULL
pointer. If either msize or fsize are even numbers, they are made odd by adding 1. Suggested values for msize and fsize are 15 pixels for typical arc lamp spectra.
cpl_error_code mos_arc_background_1D | ( | float * | spectrum, |
float * | back, | ||
int | length, | ||
int | msize, | ||
int | fsize | ||
) |
Background determination on 1D emission line spectrum (arc)
spectrum | A 1D emission line spectrum |
back | A pre-allocated buffer where the background will be written |
length | Length of spectrum |
msize | Size of min-filter |
fsize | Size of running-average-filter |
CPL_ERROR_NULL_INPUT | The input spectrum is a NULL pointer. |
CPL_ERROR_ILLEGAL_INPUT | Either msize is less than 3, or fsize is less than msize, or fsize is greater than length/2. |
This function fills the array back with the estimated values of the background along the input spectrum. The algorithm is based on the assumption that there is at least one background value at any position of the min-filter box running along the spectrum. A min-filter is passed on the spectrum, and the result is smoothed by averaging on a running box of size fsize. The min-filter is run between the positions msize / 2 and length - msize / 2, and the min value found at such positions is then repeated up to the spectrum ends. Similarly, the running average is limited to the interval from fsize / 2 and length - fsize / 2, leaving the most external values untouched. After this, a max filter and a smoothing using boxes with double the specified sizes are run, as a way to eliminate the contamination from occasional cold pixels. Finally, the min filter and the smoothing are applied again to obviate the slight background over-estimation introduced by the max filter.
It is required that the back array is at least long as the array spectrum. Moreover msize must be greater than 1, and fsize greater than, or equal to, msize. Likewise, length must be greater than twice fsize. If such conditions are not met, or if the input arrays are NULL
pointers, this function will set an error code, and leave the back array untouched. If either msize or fsize are even numbers, they are made odd by adding 1. Suggested values for msize and fsize are 15 pixels for typical arc lamp spectra.
int mos_assign_multiplex_group | ( | cpl_table * | slits | ) |
Assign to each slit a group index, where a group has no multiplexing.
slits | Slit positions produced by mos_load_slits_vimos() |
cpl_table* mos_average_global_distortion | ( | cpl_table ** | global, |
int | nglobal, | ||
double | scale, | ||
double | tolerance | ||
) |
Average global distortion tables.
global | Array of global distortion tables to average. |
nglobal | Number of global distortion tables to average. |
scale | Expected scale. |
tolerance | Tolerance around expected scale. |
The scale is the value of the first element of column a10 of a global distortion table. If scale and tolerance are positive, only the tables with a scale within tolerance are averaged.
cpl_table* mos_build_curv_coeff | ( | cpl_table * | global, |
cpl_table * | maskslits, | ||
cpl_table * | slits | ||
) |
Build the curvature coefficients table from a global distortions table.
global | Global distortions table |
maskslits | Table with slits positions on mask |
slits | Table with slits positions on CCD |
The output curvature coefficients table has the same structure of the output of the function mos_poly_trace()
. The column "slit_id" is obtained from the "slit_id" column of the input maskslits table. The coefficients columns are obtained as
where polyX is the polynomial obtained from row X of the input global distortions table, and (mx, my) are the coordinates of the slits ends listed in the input maskslits table. The slits that are completely outside the CCD are excluded from the table.
cpl_table* mos_build_disp_coeff | ( | cpl_table * | global, |
cpl_table * | slits | ||
) |
Build the IDS coefficients table from a global distortions table.
global | Global distortions table |
slits | Table with slits positions on CCD |
The input slits table should be already processed by the function mos_spatial_calibration()
, i.e., it should already have the columns "position" and "length". The output IDS coefficients table will have the same structure of the one created by mos_wavelength_calibration_final()
, but without the "error" and "nlines" columns. This output table will have as many rows as the sum of the "length" values in the input slits table, corresponding to the number of spatial pseudo-pixels of a corresponding rectified data image. If a given slit extends between CCD coordinates ytop and ybottom (as listed in the input slits table), the corresponding number of spatial pseudo-pixels is conventionally set to length = ceil(ytop-ybottom)+1 (corresponding to the content of the "length" column, as computed by the mos_spatial_calibration()
function). The spatial pseudo-pixels p are counted from top to bottom, starting from 0, and their corresponding y coordinate on the CCD is therefore given by y = ytop - p*(ytop-ybottom)/length . The corresponding x coordinate is computed in the same way, as x = xtop - p*(xtop-xbottom)/length . The coefficients columns are obtained as
where polyX is the polynomial obtained from row X of the input global distortions table, and the (xmask, ymask) are the slit coordinate on the mask. The value of poly0(xmask, ymask) is already contained in the input slits table (columns "xtop" and "xbottom").
cpl_table* mos_build_slit_location | ( | cpl_table * | global, |
cpl_table * | maskslits, | ||
int | ysize | ||
) |
Build the slit location table from a global distortions table.
global | Global distortions table |
maskslits | Table with slits positions on mask |
ysize | Y size of the CCD |
The output slits location table has the same structure of the output of the function mos_identify_slits()
, i.e. the "position" and "length" columns are still missing (such columns would be added by the mos_spatial_calibration()
function). The column "slit_id" is obtained from the "slit_id" column of the input maskslits table, while the "xtop", "ytop", "xbottom", "ybottom" columns are obtained as
where polyX is the polynomial obtained from row X of the input global distortions table, and mxtop, mytop, mxbottom, mybottom are the coordinates of the slits ends listed in the input maskslits table. The resulting slits location table is finally sorted according to the descending value of "ytop", ordering the slits from top to bottom of the image starting from the first table row. The slits that are completely outside the CCD are excluded from the table. The argument ysize is used for this purpose.
int mos_check_multiplex | ( | cpl_table * | slits | ) |
Determining whether a VIMOS mask has spectral multplexing or not.
slits | Slit positions produced by mos_load_slits_vimos() |
int mos_check_multiplex_old | ( | cpl_table * | slits | ) |
Determining whether a VIMOS mask has spectral multplexing or not.
slits | Slit positions produced by mos_load_slits_vimos() |
int mos_check_polarisation | ( | cpl_image * | q_image, |
cpl_image * | q_error, | ||
cpl_image * | u_image, | ||
cpl_image * | u_error, | ||
double | startwave, | ||
double | dispersion, | ||
double | band, | ||
cpl_table * | pol_sta, | ||
double | ra, | ||
double | dec, | ||
char * | filter, | ||
int * | polarisation, | ||
double * | p_offset, | ||
double * | p_error, | ||
double * | a_offset, | ||
double * | a_error | ||
) |
Estimate linear polarisation parameters on spectral interval.
q_image | Image whose rows correspond to extracted spectra |
q_error | Image with errors of q_image |
u_image | Image whose rows correspond to extracted spectra |
u_error | Image with errors of u_image |
startwave | Start wavelength |
dispersion | Angstrom per pixel of input image |
band | Width of band where the signal is averaged (Angstrom) |
pol_sta | Table with polarimetric standard stars parameters |
ra | Right Ascension of center of field of view (degrees) |
dec | Declination of center of field of view (degrees) |
filter | Returned filter (UBVRI) to which the measurement refers |
polarisation | Returned polarisation flag (0 = star is not polarised) |
p_offset | Returned relative variation of P in filter |
p_error | Returned error on p_offset |
a_offset | Returned variation of angle in filter (degrees) |
a_error | Returned error on a_offset (degrees) |
This function is used to estimate the deviation of the linear polarization of observed polarimetric standard stars from expected (catalog) values.
The parameter p_offset is defined as observed minus expected polarisation, divided by expected polarisation. Only in case the expected polarisation is zero, p_offset is simply defined as the observed polarisation.
The parameter p_error is obtained by propagating the measurement and the catalog errors.
The parameter a_offset is defined as observed minus expected polarisation angle. In case the expected polarisation is zero, a_offset is simply set to zero.
The parameter a_error is obtained by propagating the measurement and the catalog errors. In case the expected polarisation is zero, a_error is simply set to zero.
The applied algorithm is the following:
Each row of the input images corresponds to a different object. The row corresponding to the standard star is selected as the one where the S/N ratio is the greatest (this check is performed conventionally on q_error, which is minimal for high S/N objects). The selected row is extracted from all input images.
From the table pol_sta the standard star closest to the specified ra and dec coordinates is found, and if this is closer than half a degree from the input ra and dec is selected. From the available expected values at the different spectral bands (U, B, V, etc.) the one which is closest to the center of the valid spectral interval for the standard star observation is selected (the valid spectral interval is defined here as the region where the error is greater than zero). The following wavelengths are associated to each band:
U -> 3650 Angstrom B -> 4450 Angstrom V -> 5510 Angstrom R -> 6580 Angstrom I -> 8060 Angstrom
If the interval band centered at the wavelength closest to center of the valid spectral range is not entirely contained in the valid spectral range, this function fails and 1 is returned. Otherwise, within the defined band, the median values of Q and U, together with their median errors, are determined. From those the values for the output parameters are computed in the usual way.
int mos_check_slits | ( | cpl_table * | slits, |
float | rescale | ||
) |
Check that all slit have been detected, insert them if not.
slits | Slits table |
cpl_error_code mos_clean_cosmics | ( | cpl_image * | image, |
float | gain, | ||
float | threshold, | ||
float | ratio | ||
) |
Remove cosmic rays from sky-subtracted CCD spectral exposure.
image | Input image to be cleaned (in ADU) |
gain | Inverse gain factor (e-/ADU) |
threshold | Threshold for cosmics detection, given in noise sigmas |
ratio | Ratio for discrimination between objects and cosmics |
CPL_ERROR_NONE
in case of successIf treshold is negative, it is assigned the value 4.0. If ratio is negative, it is assigned the value 2.0. The algorithm used is the same of the MIDAS command FILTER/COSMIC. This function should be used to process not-rectified spectral exposures from where the sky spectrum was already subtracted. Cosmics are not cleaned if either x or y size of the image is not greater than 3: in this case the function returns without setting an error.
int mos_clean_outliers | ( | cpl_table * | table, |
const char * | name | ||
) |
Eliminate obvious outliers from table column values.
table | Input table |
name | Column name |
The method is base on finite differences. First, the median finite difference M is found. Then the median of the absolute second order differences S is also found, and taken as a typical deviation of the first order differences. Then values having both forward and backward differences more than 2S are invalidated.
int mos_compute_offset | ( | cpl_table * | reference, |
cpl_table * | objects, | ||
double * | offset | ||
) |
Estimate offset between two object tables.
reference | Reference object table. |
objects | Object table from offset frame. |
offset | Returned offset in CCD pixels. |
Given two object tables, derived from two scientific exposures obtained with the same mask, this function determines the offset between the two tables.
The procedure is the following: For each slit (corresponding to one row of the object tables), two integer arrays of length "length" (read from the object table) are allocated. The position of objects in that slit, as given in both the reference and the offset object tables, are flagged with 1, all the rest is left to zero. The two arrays are correlated, finding a preliminary (integer) offset in pixel. This preliminary offset is just used to match corresponding objects. At a second step, the median offset between matching objects is computed. This offset is converted to CCD pixels according to the
in the same convention used in function mos_spatial_calibration()
. The returned offset is the median offset obtained from all slits.
cpl_image* mos_detect_objects | ( | cpl_image * | image, |
cpl_table * | slits, | ||
int | margin, | ||
int | maxradius, | ||
int | conradius, | ||
double | noise | ||
) |
Detect objects in rectified scientific frame.
image | Rectified image of scientific spectra |
slits | Table with slits positions |
margin | Number of pixels to exclude at slits edges |
maxradius | Maximum extraction radius |
conradius | Contamination radius |
Slits
mean flux spatial profileThis function upgrades the input slits position table with the positions of the objects detected within each slit, and their corresponding extraction intervals. The object positions are listed in columns labeled "object_1", "object_2", etc., while the start and end positions of the extraction interval are marked with "start_1", "start_2", ... and "end_1", "end_2", etc., where the pixel coordinate is counted starting from the bottom position of the slit. Objects are not searched in slits having less than 10 valid pixels.
The algorithm applied is based on the relative peak intensity of each detected object. First of all, a peak is identified by a positive value that is preceded and followed by two lower positive values that decrease with distance. Also the first and the last (valid) spatial pixel of a slit is considered a peak, if followed or preceded by decreasing pixels, to keep it into account in the computation of the contaminations, but it is never extracted in the end. Each peak is compared with all the other peaks to determine if this peak is contaminated by any of the others. Indicating with L_o the peak value of the examined peak and with L the peak value of another peak, the quantity
is computed, where C is the indicated contamination radius, conradius, that represents the minimum distance at which two point-like object of equal luminosity can stay without contaminating each others (a typical value for this parameter may be 16 pixels). If the distance between the two peaks is less than S, the examined peak is flagged as contaminated, and is excluded from the final list of detected objects. This empirical formula has the effect of assigning a larger contamination radius to relatively brighter objects with respect to dimmer ones. With the final list of object positions the extraction intervals are determined in the following way: for each pair of consecutive peaks, an intermediate positions is determined with the inverse baricenter formula (defining the point of minimal reciprocal contamination):
where P_i is the position of the i-th peak, L_i its peak value, and j = i + 1. The position of the lower limit of the first object is set at the top border of the slit, excluding the number of pixels indicated by the margin argument. Analogously, the position of the upper limit of the last object is set at the bottom border of the slit, excluding the same number of pixels. Finally, the extraction borders exceeding maxradius are corrected accordingly.
double mos_distortions_rms | ( | cpl_image * | rectified, |
cpl_vector * | lines, | ||
double | wavestart, | ||
double | dispersion, | ||
int | radius, | ||
int | highres | ||
) |
Estimate the spectral distortion modeling goodness.
rectified | Calibrated calibration image |
lines | Reference wavelengths (line catalog) |
wavestart | Wavelength of bluest (left) pixel in input image |
dispersion | Angstrom per pixel of input image |
radius | Search radius (in pixels of input image) |
highres | 1 = high resolution data, 0 = low resolution data |
The input rectified image is the product of either the functions mos_wavelength_calibration_raw()
and mos_wavelength_calibration_final()
The RMS of the residuals between the expected positions of the arc lamp lines and the actual position of a detected peak is computed. The peak is searched within the search radius specified by the last argument, which typically would depend on the expected lines FWHM. This function prints also the computed RMS for each wavelength listed in the line catalog to screen. If the lines vector is not provided, an internal list of sky lines wavelengths is used instead. Only in this case the argument highres is checked in order to select a sky lines list for high or low resolution data (by high resolution data we mean here R > 700).
double mos_eval_dds | ( | cpl_polynomial * | ids, |
double | blue, | ||
double | red, | ||
double | refwave, | ||
double | pixel | ||
) |
Evaluate the wavelength of a pixel position.
ids | Inverse dispersion relation (from wave to pixel) |
blue | Start wavelength of ids validity |
red | End wavelength of ids validity |
refwave | Reference wavelength |
pixel | Pixel position |
The accuracy of the returned wavelength is guaranteed to be better than 0.02 pixels (converted from wavelength units to pixel). If pixel is outside the ids validity range, the wavelength 0.0 is returned.
cpl_error_code mos_extract_flux | ( | cpl_image * | image, |
cpl_table * | slits, | ||
double | xwidth, | ||
double | ywidth, | ||
int | dx, | ||
double | gain, | ||
double * | o_flux, | ||
double * | o_err | ||
) |
Measure flux from spectral interval on CCD.
image | Image containing raw spectra. |
slits | Table with slits properties. |
dx | Pixels to extract along the dispersion direction (radius). |
gain | In electrons/ADU, used for error computation. |
o_flux | Returned integrated flux, in ADU/mm^2 |
o_err | Returned error on integrated flux. |
This one should integrate counts on a rectangle around a given wavelength on a spectrum corresponding to a given slit. Then the counts are normalized to the corresponding physical area on the slit.
cpl_error_code mos_extract_flux_mapped | ( | cpl_image * | image, |
cpl_table * | slits, | ||
double | xwidth, | ||
double | ywidth, | ||
double | lambda, | ||
double | startwave, | ||
double | dispersion, | ||
int | dx, | ||
double | gain, | ||
double * | o_flux, | ||
double * | o_err | ||
) |
Measure flux from spectral interval on remapped frame.
image | Image containing remapped spectra. |
slits | Table with slits properties. |
lambda | Wavelength to examine |
startwave | Shortest wavelength in image. |
dispersion | Wavelength units per image pixel |
dx | Pixels to extract along the dispersion direction (radius). |
gain | In electrons/ADU, used for error computation. |
o_flux | Returned integrated flux, in ADU/mm^2 |
o_err | Returned error on integrated flux. |
This one should integrate counts on a rectangle around a given wavelength on a spectrum corresponding to the slit closest to the CCD center. Then the counts are normalized to the corresponding physical area on the slit.
cpl_image** mos_extract_objects | ( | cpl_image * | science, |
cpl_image * | sky, | ||
cpl_table * | objects, | ||
int | extraction, | ||
double | ron, | ||
double | gain, | ||
int | ncombined | ||
) |
Extract detected objects from rectified scientific frame.
science | Rectified and sky subtracted scientific spectra |
sky | Rectified sky spectra |
objects | Spectra and objects position table |
extraction | Extraction mode: 0 = aperture, 1 = optimal (Horne) |
ron | Read-out-noise in ADU |
gain | Conversion from ADU to electrons (e-/ADU) |
ncombined | Number of combined scientific frames |
Images
with extracted science, sky, and error spectraThe objects spatial extraction intervals are those listed in the input objects table produced by the function mos_detect_objects()
. The arguments ron, gain, and ncombined are used only in case the extraction mode is set to 1 (optimal extraction). The optimal extraction is based on Horne, K., (1986), PASP, 98, 609. If the science and science_sky frames are the result of the combination of different frames, the value of ron will be divided by the square root of ncombined.
cpl_bivector* mos_find_peaks | ( | const float * | spectrum, |
int | length, | ||
cpl_vector * | lines, | ||
cpl_polynomial * | ids, | ||
double | refwave, | ||
int | sradius | ||
) |
Find the reference lines peaks using a polynomial first-guess.
spectrum | A 1D emission line spectrum |
length | Length of spectrum |
lines | List of wavelengths |
ids | Polynomial conversion from wavelengths to pixel |
refwave | Zero wavelength used in ids determination |
sradius | Search radius for expected peaks |
The input polynomial ids is applied to the input wavelengths to find the expected position of the corresponding peak along the input spectrum. The expected peak is searched within a window of radius sradius. A list is returned, with the positions of the detected peaks with their associated wavelengths. The sradius must be at least 1 pixel, and the input spectrum must be at least twice + 1 sradius. In case of error, a NULL
pointer is returned.
double mos_get_gain_vimos | ( | cpl_propertylist * | header | ) |
Return gain factor for a VIMOS exposure.
header | FITS header of VIMOS data containing information |
This function is meant to read the gain factor from VIMOS data FITS headers. In the specific case of VIMOS the keyword used is ESO DET OUT1 CONAD. If no keyword is found a negative gain factor is returned.
int mos_get_maxobjs_per_slit | ( | cpl_table * | slits | ) |
Get the maximum possible number of objects in a slit.
slits | Slits table |
int mos_get_nobjects | ( | cpl_table * | slits | ) |
Get the total number of objects detected in a slits table.
slits | Slits table |
cpl_table* mos_global_distortion | ( | cpl_table * | slits, |
cpl_table * | maskslits, | ||
cpl_table * | ids, | ||
cpl_table * | crv, | ||
double | reference | ||
) |
Determine all global distortions models.
slits | Table with slits positions on CCD |
maskslits | Table with slits positions on mask |
ids | IDS coefficients table |
crv | Spectral curvature coefficients table |
reference | Reference wavelength |
The ids table refers to the spatially rectified spectra, and therefore it has as many rows as the rectified image. The x coordinate of this image corresponds to the x coordinate on the CCD. From the "position" and "length" columns of the slits table it is possible to select from the ids table the rows belonging to the same slit. For each slit the median value of each coefficient is computed, and associated to the CCD coordinates of the slit of the slits table having the same "slit_id". Each coefficient can then be modeled as a function of the CCD coordinates by fitting a second order bivariate polynomial. The only exception to this scheme is with the modeling of the IDS constant term (the zeropoint of the wavelength calibration), that is expressed as a function of the mask coordinates listed in the maskslits table.
The crv table lists the values of the curvature polynomial for each end of the detected slits. Such values are associated to the mask coordinates listed in the maskslits table having the same "slit_id". Each coefficient can then be modeled as a function of the mask coordinates by fitting a second order bivariate polynomial.
All the coefficients of the obtained bivariate polynomial are written to the newly created global distortions table. Conventionally this table consists of 6 columns and 10 rows. Each row corresponds to the modeling of one coefficient of the original polynomial coefficients belonging to the local solutions. The first 6 table rows are a description of the IDS coefficients, up to the fifth polynomial degree; these rows are followed by a row where just the first element is assigned the value of the reference wavelength for the given IDS model. The remaining 3 rows are a description of the spectral curvature, up to the second polynomial degree.
At least 12 valid slits must be listed in the slits tables.
cpl_error_code mos_global_trace | ( | cpl_table * | slits, |
cpl_table * | polytraces, | ||
int | mode | ||
) |
Recompute tracing coefficients globally.
slits | Slits positions on the CCD |
polytraces | Coefficients of spectral curvature polynomials |
mode | 0 = do nothing, 1 = fill gaps, 2 = global model |
CPL_ERROR_NONE
on successThe polytraces table should be the product of the function mos_trace_flat()
, and the slits table should be the same used and processed there. The trend of the tracing coefficients as a function of the first (offset) coefficient c0 is modelled by a linear fit. If mode is 2, all the coefficients are recomputed according to this model. If mode is 1, just missing solutions are found by interpolation. If some tracings are missing from the polytraces table, the value of the coefficient c0 is drawn from the y coordinate of the corresponding slit edge in the slits table, and the rest of the coefficients are derived from it.
cpl_bivector* mos_identify_peaks | ( | cpl_vector * | peaks, |
cpl_vector * | lines, | ||
double | min_disp, | ||
double | max_disp, | ||
double | tolerance | ||
) |
Identify peak candidates.
peaks | List of peaks candidates |
lines | List of wavelengths |
min_disp | Min expected spectral dispersion (Angstrom/pixel) |
max_disp | Max expected spectral dispersion (Angstrom/pixel) |
tolerance | Tolerance for interval ratio comparison |
The list of input peaks candidates (obtained with the functions mos_peak_candidates()
, and possibly mos_refine_peaks()
) is compared with a list of expected emission lines wavelengths. The algorithm is based on pattern recognition, where the pattern is contained in the vector lines, and is searched in the list peak.
In order to work, this method just requires a rough expectation value of the spectral dispersion (in Angstrom/pixel), and a line catalog. The line catalog lines should just include lines that are expected somewhere in the CCD exposure of the calibration lamp (note, however, that a catalog including extra lines at its blue and/or red ends is still allowed).
Typically, the arc lamp lines candidates peak will include light contaminations, hot pixels, and other unwanted signal, but only in extreme cases this prevents the pattern-recognition algorithm from identifying all the spectral lines. The pattern is detected even in the case peak contained more arc lamp lines than actually listed in the input line catalog.
This method is based on the assumption that the relation between wavelengths and CCD positions is with good approximation locally linear (this is always true, for any existing spectrograph).
The ratio between consecutive intervals pairs in wavelength and in pixel is invariant to linear transformations, and therefore this quantity can be used in the recognition of local portions of the searched pattern. All the examined sub-patterns will overlap, leading to the final identification of the whole pattern, notwithstanding the overall non-linearity of the relation between pixels and wavelengths.
Ambiguous cases, caused by exceptional regularities in the pattern, or by a number of undetected (but expected) peaks that disrupt the pattern on the data, are solved by linear interpolation and extrapolation of the safe identifications.
More details about the applied algorithm can be found in the comments to the function code.
cpl_table* mos_identify_slits | ( | cpl_table * | slits, |
cpl_table * | maskslits, | ||
cpl_table * | global | ||
) |
Identify slits listed in a slit location table.
slits | Slit location on the camera focal plane (CCD pixels). |
maskslits | Slit location on the telescope focal plane (mask). |
global | Global distortion table. |
This function is meant to assign to the slits positions listed in the input slits table the slit identifiers contained in the input maskslits table. At least 3 slits should be listed in both tables. The input slits table is the one obtained with the function mos_locate_spectra()
, with no rotation applied. This table is expected to contain the double precision columns labeled xtop, ytop, xbottom, and ybottom, containing the start and end image coordinates of the slits on the CCD obtained at reference wavelength. The table maskslits is expected to contain the same columns, but with the start and end coordinates of the slits on the telescope focal plane. The coordinate system should have approximately the same orientation of the input slits table, i.e., with horizontal dispersion direction and red wavelengths dispersed toward the right side. In addition to the standard columns listed above, the input maskslits table should also have a slit identifying integer column, labeled "slit_id", containing the unique slit identifiers that will be assigned to the identified slits in the input slits table. The construction of this table is instrument dependent, and should be provided at instrument recipe level.
The output slit location table will contain the same columns as the input tables, with the CCD positions of all the slits listed in the maskslits table: such positions are not necessarily all contained in the CCD. The new positions are obtained by mean of a low degree bivariate polynomial model converting from mask positions to CCD positions. This model is derived from a subset of safely identified slits positions. The preliminary identification is performed by matching similar triangles constructed both on the mask and on the CCD of the slits taken three-by-three. Recomputing all positions will remove false detections, join slits containing gaps, and separate slits that were accidentally joined together.
The slit identification may fail in case of masks containing a regular spacing of slits: such masks would invariably lead to ambiguous pattern matching, that would not be processed. This would not prevent that data reduction in itself: simply, the reduced spectra would miss their identification. Note that this is not a real problem, since ambiguous masks are typically masks used for calibration, and not for scientific observations.
In case a global distortion table is specified in input, the coefficients of the bivariate polynomials describing the relation between mask and CCD coordinates (at reference wavelength) are written to rows 0 and 7.
cpl_image* mos_image_filter_median | ( | cpl_image * | image, |
int | nx, | ||
int | ny | ||
) |
Convenience function for standard median filtering.
image | Image to smooth |
nx | Filter size in x. |
ny | Filter size in y. |
cpl_error_code mos_image_shift | ( | cpl_image * | image, |
double | dx, | ||
double | dy | ||
) |
Shift values in an image.
image | Input image |
dx | Shift in x |
dy | Shift in y |
CPL_ERROR_NONE
on success. double mos_integrate_signal | ( | cpl_image * | image, |
cpl_image * | wavemap, | ||
int | ystart, | ||
int | yend, | ||
double | wstart, | ||
double | wend | ||
) |
Integrate signal from wavelength and spatial interval.
image | CCD exposure |
wavemap | Wavelengths map of CCD exposure |
ystart | Start Y-pixel coordinate on CCD |
yend | End Y-pixel coordinate on CCD |
wstart | Start wavelength |
wend | End wavelength |
This function sum the signal in the specified interval. ystart is inclusive and wend exclusive.
cpl_error_code mos_interpolate_wavecalib | ( | cpl_table * | idscoeff, |
cpl_image * | wavemap, | ||
int | mode, | ||
int | degree | ||
) |
Interpolate LSS wavelength calibration.
idscoeff | Table with IDS polynomials |
wavemap | Wavelength calibration image |
mode | 0 = do nothing, 1 = fill gaps, 2 = global model |
degree | 0 = median, > 0 order of fitting polynomial. |
CPL_ERROR_NONE
on success.This function is used on LSS data, to interpolate the wavelength calibration obtained with the function mos_wavelength_calibration_raw()
also in those image rows where the calibration failed. The input idscoeff table and wavemap image are reprocessed and modified in-place according to what indicated by the mode argument. The idscoeff table coefficients and the wavelengths in wavemap are modeled by low degree polynomials: if mode is 1, the model values are used to fill the gaps in the input solutions, otherwise all the inputs are replaced with the fitted model values. If the wavemap is not given, just the idscoeff table will be interpolated: the corresponding wavelength map could still be calculated using the function mos_map_idscoeff()
.
cpl_error_code mos_interpolate_wavecalib_slit | ( | cpl_table * | idscoeff, |
cpl_table * | slits, | ||
int | order, | ||
int | global | ||
) |
Interpolate MOS wavelength calibration.
idscoeff | Table with IDS polynomials |
slits | Table with slits positions |
order | 0 = median, > 0 order of fitting polynomial. |
CPL_ERROR_NONE
on success.This function is used on MOS data, to interpolate the wavelength calibration obtained with the function mos_wavelength_calibration_final()
also in those image rows where the calibration failed. The input idscoeff table is reprocessed and modified in-place according to what indicated by the mode argument. The idscoeff table coefficients are modeled by low degree polynomials: if mode is 1, the model values are used to fill the gaps in the input solutions, otherwise all the inputs are replaced with the fitted model values. The corresponding wavelength map could be calculated using the function mos_map_idscoeff()
.
cpl_image* mos_ksigma_stack | ( | cpl_imagelist * | imlist, |
double | klow, | ||
double | khigh, | ||
int | kiter, | ||
cpl_image ** | good | ||
) |
Stack images using k-sigma clipping.
imlist | List of images to stack |
klow | Number of sigmas for rejection of lowest values |
khigh | Number of sigmas for rejection of highest values |
kiter | Max number of iterations |
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.
int mos_lines_width | ( | const float * | spectrum, |
int | length | ||
) |
Estimate lines widths (in pixel) in arc lamp spectrum.
spectrum | A 1D emission line spectrum |
length | Length of spectrum |
This function only works with emission lines spectra. The derivative of the input spectrum is calculated. The result is processed once by setting all its negative values to zero, and once by setting all its positive values to zero and then making positive its negative values. The two profiles are cross-correlated, finding in this way the mean width of all the emission lines. Note that the returned width is the width of the lines measured at the point of max steepness of the signal (i.e., not necessarily the FWHM). In case of pure noise a width 1 is returned. The maximum returned width is 20.
cpl_table* mos_load_overscans_vimos | ( | const cpl_propertylist * | header, |
int | check_consistency | ||
) |
Get the overscan positions from FITS header of VIMOS data.
header | FITS header containing overscan information |
check_consistency | If true (non-zero), this function fails if the sum of prescan, overscan and detector size is different from the actual FITS image size. (this does not hold true for old FORS data) |
This function is meant to convert the information contained in VIMOS data FITS header into an overscan position table. This table will contain the integer columns labeled xlow, ylow, xhig, and yhig, containing the pixel coordinates of opposite corners of the overscan regions, and at its first row the corners coordinates of the valid region (i.e., the CCD proper) within the image. This is a standard table valid for all instruments that should be used by the function mos_remove_bias()
. In the specific case of VIMOS the keywords used are NAXIS1, NAXIS2, ESO DET OUT1 PRSCX, ESO DET OUT1 OVSCX, ESO DET OUT1 PRSCY, and ESO DET OUT1 OVSCY. The input header should come from a raw, unprocessed image (typically the image from which a master bias was not yet subtracted).
cpl_table* mos_load_slits_fors_lss | ( | cpl_propertylist * | header | ) |
Create slit location table from FITS header of FORS1/2 LSS data.
header | FITS header of FORS data containing slits information |
This function is meant to convert the information contained in FORS1 and FORS2 LSS data FITS header into a slit position table. This table will contain the double precision columns labeled xtop, ytop, xbottom, and ybottom, containing the start and end coordinates of the slits on the telescope focal plane (mask). The coordinates are expected to have a horizontal dispersion direction and red wavelengths on the right side. A flip to the Y coordinate is applied to match the increasing Y CCD pixel coordinate. A slit identifying integer column, labeled "slit_id", containing unique slit identifiers, will also be added. This identifier will be set to 1 for lSlit0_3arcsec, 2 for lSlit0_4arcsec, up to 9 for lSlit2_5arcsec. In case of FORS2 data only the part of the slit pertaining to the used chip is loaded.
cpl_table* mos_load_slits_fors_mos | ( | cpl_propertylist * | header | ) |
Create slit location table from FITS header of FORS1/2 MOS data.
header | FITS header of FORS data containing slits information |
This function is meant to convert the information contained in FORS1 and FORS2 MOS data FITS header into a slit position table. This table will contain the double precision columns labeled xtop, ytop, xbottom, and ybottom, containing the start and end coordinates of the slits on the telescope focal plane (mask). The coordinates are expected to have a horizontal dispersion direction and red wavelengths on the right side. A flip to the Y coordinate is applied to match the increasing Y CCD pixel coordinate. A slit identifying integer column, labeled "slit_id", containing unique slit identifiers, will also be added. In case of FORS2 data only the slits pertaining to the used chip are loaded.
cpl_table* mos_load_slits_fors_mxu | ( | cpl_propertylist * | header | ) |
Create slit location table from FITS header of FORS2-MXU data.
header | FITS header of FORS data containing slits information |
This function is meant to convert the information contained in FORS2 MXU data FITS header into a slit position table. This table will contain the double precision columns labeled xtop, ytop, xbottom, and ybottom, containing the start and end coordinates of the slits on the telescope focal plane (mask). The coordinates are expected to have a horizontal dispersion direction and red wavelengths on the right side. A flip to the Y coordinate is applied to match the increasing Y CCD pixel coordinate. A slit identifying integer column, labeled "slit_id", containing unique slit identifiers, will also be added. In case of FORS2 data only the slits pertaining to the used chip are loaded.
cpl_table* mos_load_slits_fors_pmos | ( | cpl_propertylist * | header | ) |
Create PMOS slit location table from FITS header of FORS1/2 MOS data.
header | FITS header of FORS data containing slits information |
This function is meant to convert the information contained in FORS1 and FORS2 MOS data FITS header into a slit position table. This table will contain the double precision columns labeled xtop, ytop, xbottom, and ybottom, containing the start and end coordinates of the slits on the telescope focal plane (mask). The coordinates are expected to have a horizontal dispersion direction and red wavelengths on the right side. A flip to the Y coordinate is applied to match the increasing Y CCD pixel coordinate. A slit identifying integer column, labeled "slit_id", containing unique slit identifiers, will also be added. In case of FORS2 data only the slits pertaining to the used chip are loaded.
cpl_table* mos_load_slits_vimos | ( | cpl_propertylist * | header | ) |
Create slit location table from FITS header of VIMOS data.
header | FITS header of VIMOS data containing slits information |
This function is meant to convert the information contained in VIMOS data FITS header into a slit position table. This table will contain the double precision columns labeled xtop, ytop, xbottom, and ybottom, containing the start and end coordinates of the slits on the telescope focal plane (mask). The coordinates will be rotated to have a horizontal dispersion direction and red wavelengths on the right side. A slit identifying integer column, labeled "slit_id", containing unique slit identifiers, will also be added.
cpl_table* mos_locate_spectra | ( | cpl_mask * | mask | ) |
Find the location of detected spectra on the CCD.
mask | A reference mask at a given reference wavelength |
The input mask is the one obtained with the function mos_wavelength_calibration_raw()
. The output table contains the start and end image coordinates of the slit on the input mask at reference wavelength. The slits are ordered from top to bottom of the image starting from the first table row.
Note that possible gaps within the images of the slits will result in splitting the same slit into two or more sub-slits. This kind of problem is solved within the slit identification task, performed by the function mos_identify_slits()
.
Find the location of detected spectra on the CCD
mask | A reference mask at a given reference wavelength |
The input mask is the one obtained with the function mos_wavelength_calibration_raw()
. The output table contains the start and end image coordinates of the slit on the input mask at reference wavelength. The slits are ordered from top to bottom of the image starting from the first table row.
Note that possible gaps within the images of the slits will result in splitting the same slit into two or more sub-slits. This kind of problem is solved within the slit identification task, performed by the function mos_identify_slits()
.
cpl_image* mos_map_idscoeff | ( | cpl_table * | idscoeff, |
int | xsize, | ||
double | reference, | ||
double | blue, | ||
double | red | ||
) |
Create a wavelengths map from an IDS coefficients table.
idscoeff | Table with IDS polynomials |
xsize | X size of used CCD |
reference | Reference wavelength |
blue | Start lambda for spatial remapping |
red | End lambda for spatial remapping |
The output wavelength map will have the Y size equal to the number of rows in the idscoeff table. The input xsize will typically be the X size of the used detector. In general this should be identical to the X size of the arc lamp image from where the idscoeff table was derived. The wavelengths map is created by applying the inverses of the IDS polynomials to all the pixel positions of each output image row.
cpl_image* mos_map_pixel | ( | cpl_table * | idscoeff, |
double | reference, | ||
double | blue, | ||
double | red, | ||
double | dispersion, | ||
int | trend | ||
) |
Create a pixel map from an IDS coefficients table.
idscoeff | Table with IDS polynomials |
reference | Reference wavelength |
blue | Start lambda for spatial remapping |
red | End lambda for spatial remapping |
dispersion | Mean spectral dispersion |
trend | Trend to remove from IDS polynomials |
The output pixel map will have the Y size equal to the number of rows in the idscoeff table. The X size is computed as (red - blue) / dispersion. With trend the number of polynomial coefficients to ignore in the computation can be specified.
cpl_image* mos_map_spectrum | ( | cpl_image * | spectra, |
cpl_image * | wavecalib, | ||
cpl_image * | spatial, | ||
cpl_table * | slits, | ||
cpl_table * | polytraces, | ||
double | reference, | ||
double | blue, | ||
double | red, | ||
double | dispersion, | ||
int | flux | ||
) |
Remapping of slit spectra into a grid of lambda-space coordinates.
spectra | CCD image containing the observed slit spectra |
wavecalib | CCD image of wavelengths |
spatial | CCD image of spatial coordinates |
slits | Slits positions on the CCD |
polytraces | Coefficients of spectral curvature polynomials |
reference | Reference wavelength |
blue | Start lambda for remapping |
red | End lambda for remapping |
dispersion | Mean spectral dispersion |
flux | flux = 0 means no flux conservation correction applied |
DO NOT USE THIS FUNCTION, IT GIVES BAD RESULTS (and it should be eventually removed).
The input wavecalib image is the one returned by the function mos_map_wavelengths()
or, if this is not available, the approximate one returned by the function mos_wavelength_calibration_raw(). The input spatial image is the one produced by the function mos_spatial_calibration()
(argument: calibration). Both images are expected to be oriented with horizontal dispersion direction and red wavelengths on the right side, and they should have the same sizes of the input spectra image. The slits table should be the same processed by the function mos_spatial_calibration()
. The polytraces table is the output of the function mos_poly_trace()
. If flux is different from 0, the factors to be applied for flux conservation are calculated and applied to the remapped image. The other arguments should be in principle the same specified for the function mos_spatial_calibration()
, even if it would be conceivable (and perhaps even reasonable) to specify shorter spectral ranges, and/or a smaller value of the dispersion (A/pixel) for supersampling the signal.
The target grid in lambda and pseudo spatial coordinates is defined on the basis of the indicated spectral range and dispersion, while the number of spatial pixels assigned to each slits are compatible with the positions listed in the slits table (column "position") following the convention used in the rest of the spectral reduction, in particular the functions mos_spatial_calibration() and mos_map_wavelengths()
.
Indicating with (x,y) a pixel position on the CCD, and with (L,S) a pixel position on one extracted slit, the mapping from (x,y) to (L,S) is done in the following way (for each slit): for each (x,y) read the corresponding value of lambda and space from the input images wavecalib and spatial; find the pixel (L,S) on the output (remapped) slit that has the highest lambda and space that are less than the lambda and space obtained above; read the values of the following CCD pixels from the input spectrum: (x,y), (x-1,y), (x+N,y+1), (x+N-1,y+1), where N is an offset pointing to the pixel on the row y+1 having the closest wavelength to the wavelength of pixel (x,y). This is a way to avoid possible discontinuities in the wavelength calibration along the cross-dispersion direction (due to slit irregularities, also commonly indicated with the expression "slit geometry"). Typically, it will always be N = 0.
The pixel value to assign to the pixel (L,S) is computed by linear interpolation to its corresponding (x',y') position of the 4 pixel values (horizontal interpolation followed by vertical interpolation of the interpolated values). The corresponding flux-conservation factor, if requested, is computed as (dL/dx)*(dS/dy). The interpolated value is multiplied by this factor before being written to the pixel (L,S).
DO NOT USE THIS FUNCTION, IT GIVES BAD RESULTS (and it should be eventually removed).
cpl_image* mos_map_wavelengths | ( | cpl_image * | spatial, |
cpl_image * | calibration, | ||
cpl_table * | slits, | ||
cpl_table * | polytraces, | ||
double | reference, | ||
double | blue, | ||
double | red, | ||
double | dispersion | ||
) |
Remapping of spatially rectified wavelengths to original CCD pixels.
spatial | CCD image of spatial coordinates |
calibration | Spatially rectified image of wavelengths |
slits | Slits positions on the CCD |
polytraces | Coefficients of spectral curvature polynomials |
reference | Reference wavelength |
blue | Start lambda for spatial remapping |
red | End lambda for spatial remapping |
dispersion | Mean spectral dispersion |
The input spatial image is the one produced by the function mos_spatial_calibration()
(argument: calibration). It is expected to be oriented with horizontal dispersion direction and red wavelengths on the right side, and it should have the same x-length of the input calibration image. The calibration image is the one produced by the function mos_wavelength_calibration_final()
(argument: calibration). The slits table should be the same processed by the function mos_spatial_calibration()
. The polytraces table is the output of the function mos_poly_trace()
. The other arguments should be in principle the same specified for the function mos_spatial_calibration()
.
For each slit, each (x,y) coordinate on the spatial image is characterised by a spatial coordinate p. The wavelength at that spatial coordinate is derived by linear interpolation of the two wavelengths with the same coordinate x that are closer to p on the calibration image.
int mos_median_in_slit | ( | cpl_table * | table, |
cpl_table * | slits, | ||
int | slit, | ||
char * | label, | ||
double * | mvalue | ||
) |
Compute median from a table column section corresponding to a slit.
table | Table with as many rows as rectified images |
slits | Table with slits properties. |
slit | Row in slits corresponding to slit to examine |
label | Name of column to examine |
mvalue | Returned median value |
cpl_image* mos_normalise_flat | ( | cpl_image * | flat, |
cpl_image * | spatial, | ||
cpl_table * | slits, | ||
cpl_table * | polytraces, | ||
double | reference, | ||
double | blue, | ||
double | red, | ||
double | dispersion, | ||
int | sradius, | ||
int | polyorder | ||
) |
Normalise a flat field exposure.
flat | Image containing the original flat field spectra |
spatial | Spatial calibration image |
slits | Table with slits positions |
polytraces | Coefficients of spectral curvature polynomials |
reference | Reference wavelength |
blue | Start lambda to process |
red | End lambda to process |
dispersion | Mean spectral dispersion |
sradius | Radius of smoothing box along the dispersion direction |
polyorder | Order of fitting polynomial along the dispersion |
The input flat frame should be already bias subtracted, and should be oriented so that the dispersion direction is horizontal with blue on the left and red on the right. The flat field spectra are spatially rectified, heavily smoothed, and then mapped back on the CCD. The original flat image is divided IN PLACE by its smoothed counterpart, which is also returned. If the polynomial polyorder is set to a negative number the smoothing consists of a linear fit along the spatial direction (excluding 3+3 pixels at the spectral edges), and by a median filtering along the dispersion direction using a window with the specified sradius; alternatively, if polyorder is not negative, the smoothing will consist of a polynomial fitting of the illumination profile along the dispersion direction, performed independently for each row of the spatially remapped spectra.
cpl_image* mos_normalise_longflat | ( | cpl_image * | flat, |
int | sradius, | ||
int | dradius, | ||
int | polyorder | ||
) |
Normalise a long slit flat field exposure.
flat | Image containing the original flat field spectra |
sradius | Radius of smoothing box along the spatial direction |
dradius | Radius of smoothing box along the dispersion direction |
polyorder | Order of fitting polynomial along the spatial direction |
The input flat frame should be already bias subtracted, and should be oriented so that the dispersion direction is horizontal with blue on the left and red on the right. The original flat image is divided IN PLACE by its smoothed counterpart, which is also returned. If the polynomial polyorder is set to a negative number the smoothing consists of a median filtering box of specified sizes. Alternatively, if polyorder is not negative, the smoothing will consist of a polynomial fitting of the illumination profile along the spatial direction (and not along the dispersion direction, as for the case of shorter slits), performed independently for each column of the spectrum.
cpl_error_code mos_object_intersect | ( | cpl_table ** | slitss, |
cpl_table * | origslits, | ||
int | nscience, | ||
float | tolerance | ||
) |
Intersect a number of slit tables.
slitss | Pointer to the list of slit tables |
origslits | Pointer to output intersected table |
nscience | Number of tables in the list |
tolerance | Tolerance in object position (pixel) |
The intersected table will only contain polarimetric objects which have been detected in all tables in both beams in the input table list (that is, are present, for all angles so polarimetric computation is possible)
cpl_vector* mos_peak_candidates | ( | const float * | spectrum, |
int | length, | ||
float | level, | ||
float | exp_width | ||
) |
Find positions of peaks candidates.
spectrum | A 1D emission line spectrum |
length | Length of spectrum |
level | Significance level |
exp_width | Expected lines FWHM (in pixels) |
A peak candidate corresponds to any pixel value above level that is preceded and followed by a pixel with lower values. The peak candidate position is determined by parabolic interpolation of the three pixel values. A NULL
pointer is returned in case no peak candidate is found. No error code is set in this case.
If very very broad and flat-topped peaks are expected, i.e., if the expected lines FWHM is more than 5 pixels, the spectrum is slightly smoothed before peaks are searched. If the expected lines FWHM is more than 20 pixels, the spectrum is preliminary sampled at a step of half exp_width. These operations are applied to ensure that the top of an emission line profile is never flat.
cpl_table* mos_photometric_calibration | ( | cpl_image * | spectra, |
double | startwave, | ||
double | dispersion, | ||
double | gain, | ||
double | exptime, | ||
cpl_table * | ext_table, | ||
double | airmass, | ||
cpl_table * | flux_table, | ||
int | order | ||
) |
Produce instrument response curve, with some ancillary information.
spectra | Image with extracted spectra |
startwave | Shortest wavelength in input image (Angstrom) |
dispersion | Angstrom per pixel of input image |
gain | Gain factor (e-/ADU) |
exptime | Exposure time (seconds) |
ext_table | Atmospheric extinction table |
airmass | Airmass of observation |
flux_table | Standard star catalog flux |
order | Order of polynomial to model the instrument response |
This function is meant to convert the information contained in
The brightest extracted spectrum in spectra is assumed to be the standard star spectrum. The order of the polynomial fitting the instrument must be at least 2.
cpl_polynomial* mos_poly_pix2wav | ( | cpl_bivector * | pixwav, |
int | order, | ||
double | reject, | ||
int | minlines, | ||
int * | nlines, | ||
double * | err | ||
) |
Fit polynomial relation from pixels to wavelengths.
pixwav | List of pixel positions and associated wavelengths |
order | Order of the fitting polynomial |
reject | Max residual tolerated for line rejection (in wave units) |
minlines | Min number of lines to be used in the fit |
nlines | Output number of lines actually used in the fit |
err | Output RMS of the fit residuals |
The list of identified peaks and their wavelengths (obtained with the function mos_identify_peaks()
) must contain at least minlines entries. A fit is tried, and all the peaks farther than the reject threshold from the model are rejected. This process is iterated until either the number of surviving lines is less than minlines or there are no more outliers (whichever comes first). Only in the latter case a fit is returned. If the reject threshold is negative, no outliers rejection is applied, and the first fit is accepted. In case of error, a NULL
pointer is returned, and nlines and err are set to zero.
cpl_table* mos_poly_trace | ( | cpl_table * | slits, |
cpl_table * | traces, | ||
int | order | ||
) |
Fit spectral traces.
slits | Slits positions on the CCD |
traces | Spectral traces |
order | Order of fitting polynomial |
The traces table should be the product of the function mos_trace_flat()
, and the slits table should be the same used and processed there. The order of the fitting polynomial should not be greater than 5. If the fit of a trace is successful, a column containing the residuals of the fit is added to the traces table. If the fitted data are contained in a column named "xyz" (in the convention used by the function mos_trace_flat()
), the column containing the residuals will be named "xyz_res".
cpl_polynomial* mos_poly_wav2pix | ( | cpl_bivector * | pixwav, |
int | order, | ||
double | reject, | ||
int | minlines, | ||
int * | nlines, | ||
double * | err | ||
) |
Fit polynomial relation from wavelengths to pixels.
pixwav | List of pixel positions and associated wavelengths |
order | Order of the fitting polynomial |
reject | Max residual tolerated for line rejection (in pixel) |
minlines | Min number of lines to be used in the fit |
nlines | Output number of lines actually used in the fit |
err | Output RMS of the fit residuals |
The list of identified peaks and their wavelengths (obtained either with the function mos_identify_peaks()
or the function mos_find_peaks()
) must contain at least minlines entries. A fit is tried, and all the peaks farther than the reject threshold from the model are rejected. This process is iterated until either the number of surviving lines is less than minlines or there are no more outliers (whichever comes first). Only in the latter case a fit is returned. If the reject threshold is negative, no outliers rejection is applied, and the first fit is accepted. In case of error, a NULL
pointer is returned, and nlines and err are set to zero.
cpl_error_code mos_randomise_image | ( | cpl_image * | image, |
double | ron, | ||
double | gain, | ||
double | bias | ||
) |
Randomise image.
image | Image to randomise (in place) |
ron | Read out noise (ADU) |
gain | Gain (electrons/ADU) |
bias | Bias level (ADU) |
For each pixel the 1-sigma error is evaluated as the square root of the variance:
where S is the pixel value. The pixel value is randomised as
cpl_vector* mos_refine_peaks | ( | const float * | spectrum, |
int | length, | ||
cpl_vector * | peaks, | ||
int | sradius | ||
) |
Improve (when possible) accuracy of peaks candidates positions.
spectrum | A 1D emission line spectrum |
length | Length of spectrum |
peaks | List of peaks candidates |
sradius | Search radius for expected peaks |
The list of input peaks candidates (obtained with the function mos_peak_candidates()
) is made more accurate, whenever possible, by applying a line baricenter determination method. In case the baricentric method fails, the corresponding peak position is not rejected, but just kept unchanged. The final peaks candidates list is finally cleaned from peak positions that are closer than 0.5 pixel (to avoid duplications). The input vector is destroyed, and a newly allocated vector is returned.
cpl_error_code mos_refmask_find_gaps | ( | cpl_mask * | refmask, |
cpl_image * | master_flat, | ||
double | level | ||
) |
Reconstruct the gaps required for slit location.
refmask | Reference mask |
master_flat | Masterflat. The gaps are detected and inserted based upon the values found in this image. |
Deviation larger than 1 sigma from median are killed from map. If level is greater than zero, deviations less than level from median are killed.
cpl_image* mos_remove_bias | ( | cpl_image * | image, |
cpl_image * | bias, | ||
cpl_table * | overscans | ||
) |
Subtract the bias from a CCD exposure.
image | Image containing the data to correct |
bias | Master bias |
overscans | Table with the overscan information |
If the master bias has the same sizes of the input image it is simply subtracted from the image. If it has different sizes, they should be compatible with the description in the overscans table produced by one of the functions mos_load_overscans_<instrument>(). In this case the mean level of the master bias is compared with the mean level of the overscan regions of the input image. The master bias and the difference of mean levels are then subtracted from the valid region of the input image. The output image will always have the overscan regions trimmed, having in this way the same sizes of the input master bias. If the bias frame is not specified, only the mean level of the overscan regions is subtracted from the input image. Only in case no overscan regions are present, nothing is done.
cpl_table* mos_resolution_table | ( | cpl_image * | image, |
double | startwave, | ||
double | dispersion, | ||
int | saturation, | ||
cpl_vector * | lines | ||
) |
Compute mean spectral resolution at a given arc lamp line.
image | Rectified and wavelength calibrated arc lamp image |
startwave | Shortest wavelength in image. |
dispersion | Wavelength units per image pixel |
saturation | Saturation value |
lines | Line catalog |
This function loops on the function mos_spectral_resolution()
for each line of the input line catalog, and creates a spectral resolution table. This table has a column "wavelength" listing the line catalog wavelengths, a column "resolution" containing the corresponding mean spectral resolutions, a column "rms" with the population standard deviation of the measured resolutions, and a column "nlines" reporting the number of measurement for each wavelength.
cpl_error_code mos_rotate_slits | ( | cpl_table * | slits, |
int | rotation, | ||
int | nx, | ||
int | ny | ||
) |
Rotate a slit location table.
slits | Slit location table to rotate |
rotation | Rotation angle in multiples of 90 degrees (counterclockwise) |
nx | X size of reference image |
ny | Y size of reference image |
This function is meant to align the input slits table to the mask coordinates convention used for a given instrument. The input slits table is the one obtained with the function mos_locate_spectra()
, or by this self. This table is expected to contain double precision columns labeled xtop, ytop, xbottom, and ybottom, containing the start and end image coordinates of the slits on the mask obtained at reference wavelength. The transformation will affect these columns, other columns are ignored. The reference wavelength image was expected to be oriented with horizontal dispersion direction and red wavelengths on the right side, but the slits columns are not renamed after a rotation to reflect the change of convention. If the sizes of the reference mask, nx and ny, are greater than 0, the new coordinates will be related to the image rotated in the same way, otherwise a simple geometrical rotation is applied. The sizes nx and ny must refer to the reference image after it is rotated in the same way.
cpl_error_code mos_saturation_process | ( | cpl_image * | image | ) |
Process saturation.
image | Image to process saturation |
cpl_image* mos_sky_local | ( | cpl_image * | spectra, |
cpl_table * | slits, | ||
int | order | ||
) |
Local determination of sky.
spectra | Rectified image of scientific spectra |
slits | Slits positions table |
order | Order of the polynomial fitting the sky. |
The median level at each wavelength is determined and subtracted from the data. The position and extension of the objects is detected and the rest of the pixels are flagged as sky, and used for the final determination of the sky level at each wavelength. If the order of the sky-fitting polynomial is zero the median sky level is determined, otherwise a fit with outliers rejection is applied. The sky map generated in this way is returned.
cpl_image* mos_sky_local_old | ( | cpl_image * | spectra, |
cpl_table * | slits | ||
) |
Local determination of sky.
spectra | Rectified image of scientific spectra |
slits | Slits positions table |
Each slit spectrum contained in the input image, spectra, is assumed to contain at least 50% of its pixels on the sky. The median level at each wavelength is determined, and the sky map generated in this way is returned.
cpl_table* mos_sky_map | ( | cpl_image * | spectra, |
cpl_image * | wavemap, | ||
double | dispersion, | ||
cpl_image * | skymap | ||
) |
Create a CCD median sky map.
spectra | CCD image of spectra |
wavemap | CCD image of wavelengths |
dispersion | Mean spectral dispersion |
skymap | Returned CCD image of sky |
The spectra contained in the input image, spectra, taken all together are assumed to contain at least 50% of their pixels on the sky. Moreover, all slits are assumed to have the same width. The CCD image of wavelengths, wavemap, is the one produced by the function mos_wavelength_calibration_final()
, possibly modified by the function mos_wavelength_align()
used to align the wavelength solution to available sky lines. The computed sky spectrum will consist of pixels of size dispersion: typically the passed dispersion should be slightly smaller than the dispersion of the original spectra. How much smaller will affect the level of supersampling of the computed sky spectrum: a too small value will increase the noise of the output sky spectrum, leading to no advantage in the determination of the sky map to be subtracted from the scientific data. Each pixel of the resulting sky spectrum is computed as the median of all the pixel values of all the CCD spectra in the wavelength interval corresponding to that pixel. The skymap image should be preallocated: each one of its pixels, corresponding to a wavelength read from wavemap, will be assigned a value obtained by linear interpolation of the two pixels of the supersampled spectrum that are closest to its wavelength.
cpl_table* mos_sky_map_super | ( | cpl_image * | spectra, |
cpl_image * | wavemap, | ||
double | dispersion, | ||
double | factor, | ||
int | minpoints, | ||
cpl_image * | skymap | ||
) |
Create a CCD median sky map.
spectra | CCD image of spectra |
wavemap | CCD image of wavelengths |
dispersion | Mean spectral dispersion |
factor | Supersampling factor |
minpoints | Minimum points required per supersampled spectrum bin |
skymap | Returned CCD image of sky |
The spectra contained in the input image, spectra, taken all together are assumed to contain at least 50% of their pixels on the sky. Moreover, all slits are assumed to have the same width. The CCD image of wavelengths, wavemap, is the one produced by the function mos_wavelength_calibration_final()
, possibly modified by the function mos_wavelength_align()
used to align the wavelength solution to available sky lines. The sky spectrum is computed as the median level of all the pixel values of all the CCD spectra in the wavelength interval corresponding to that bin, on bins containing at least minpoints; otherwise it is computed by linear interpolation from the nearest valid bins. To each bin is assigned in the first case the median of the contributing wavelengths, and in the second case its central wavelength. The skymap image should be preallocated: each one of its pixels, corresponding to a wavelength read from wavemap, will be assigned a value obtained by linear interpolation of the two pixels of the supersampled spectrum that are closest to its wavelength.
int mos_slit_closest_to_center | ( | cpl_table * | slits, |
int | nx, | ||
int | ny | ||
) |
Return slit closest to CCD center.
slits | Slit table |
nx | X size of CCD |
ny | Y size of CCD |
cpl_error_code mos_slit_wavemap | ( | cpl_image * | wavemap, |
int | slit, | ||
cpl_table * | slits, | ||
cpl_table * | polytraces, | ||
double | reference, | ||
double | blue, | ||
double | red, | ||
double | dispersion | ||
) |
Select wavelengths from a single spectrum.
wavemap | Wavelength map |
slit | Slit number |
slits | Table with slits positions |
polytraces | Coefficients of spectral curvature polynomials |
reference | Reference wavelength |
blue | Start lambda to process |
red | End lambda to process |
dispersion | Mean spectral dispersion |
CPL_ERROR_NONE
on success.The input wavelength map is filled with zeroes, but for the specified slit.
cpl_image* mos_spatial_calibration | ( | cpl_image * | spectra, |
cpl_table * | slits, | ||
cpl_table * | polytraces, | ||
double | reference, | ||
double | blue, | ||
double | red, | ||
double | dispersion, | ||
int | flux, | ||
cpl_image * | calibration | ||
) |
Spatial remapping of CCD spectra eliminating the spectral curvature.
spectra | CCD image of spectra |
slits | Slits positions on the CCD |
polytraces | Coefficients of spectral curvature polynomials |
reference | Reference wavelength |
blue | Start lambda for spatial remapping |
red | End lambda for spatial remapping |
dispersion | Mean spectral dispersion |
flux | If zero, flux conservation is not applied |
calibration | Returned spatial calibration image |
The input spectra image is expected to be oriented with horizontal dispersion direction and red wavelengths on the right side, and it should be of type CPL_TYPE_FLOAT
. The slits table should be the output of either the function mos_identify_slits()
(if available) or the function mos_locate_spectra()
. The polytraces table is the output of the function mos_poly_trace()
.
The spectra are spatially remapped (with a slight oversampling) starting from the pixel containing the reference wavelength (as reported for each entry of the slits table). The number of pixels to the left and to the right of the reference pixel is trivially derived from the specified spectral range blue to red and dispersion.
At each x pixel position the interval between the top and the bottom edges of each spectrum is linearly remapped into N = ceil(t-b)+1 spatial pseudo-pixels, where t and b are its edges positions at the CCD reference pixel (i.e., if the slit spectrum is widening or narrowing along the wavelength range, it is mapped always to the same number of pseudo-pixels). The returned image will have the same x size of the input spectra image, and a y size equal to the sum of the N spatial sizes of the resampled spectra.
Optionally, an image of the spatially calibrated input exposure, calibration, can be returned. This image must be pre-allocated, and should have the same size of the input spectra image. If a NULL
pointer is passed, it is not computed. The calibration image will consist of pixels having the value of their spatial coordinate along the slit they belong to, or the value zero if the pixels do not belong to any spectrum.
In case flux is set to a value different from zero, the remapping is performed applying a correction for flux conservation.
Here is how the spatial resampling is applied: the value of a spatial pseudo-pixel p (counted from 0, corresponding to the top spectral trace at a given x position on the CCD of a given spectrum), is computed by linear interpolation between the two values of the consecutive CCD pixels closest to the position y = t - p*(t-b)/N, with the same meaning for N, b, and t, described above, and with 0 <= p <= N.
On the calibration image the original y pixel positions (at a given x) are assigned the value of their distance from the top spectral trace, computed as p = N*(t-y)/(t-b), where p is now a float, and y an integer varying from ceil(t) to floor(b).
The input slits table is added two new columns, labeled "position" and "length", reporting the number of the first (bottom) row belonging to the corresponding slit spectrum, and its extension in pseudo-pixels on the returned spatially rectified image.
cpl_image* mos_spatial_map | ( | cpl_image * | spectra, |
cpl_table * | slits, | ||
cpl_table * | polytraces, | ||
double | reference, | ||
double | blue, | ||
double | red, | ||
double | dispersion | ||
) |
Create coordinate map from spectral curvature table.
spectra | CCD image of spectra |
slits | Slits positions on the CCD |
polytraces | Coefficients of spectral curvature polynomials |
reference | Reference wavelength |
blue | Start lambda for spatial remapping |
red | End lambda for spatial remapping |
dispersion | Mean spectral dispersion |
The input spectra image is expected to be oriented with horizontal dispersion direction and red wavelengths on the right side, and it should be of type CPL_TYPE_FLOAT
. The slits table should be the output of either the function mos_identify_slits()
(if available) or the function mos_locate_spectra()
. The polytraces table is the output of the function mos_poly_trace()
.
The returned image image has the same size of the input spectra image, and it will consist of pixels having the value of their spatial coordinate along the slit they belong to, or the value zero if the pixels do not belong to any spectrum. The original y pixel positions (at a given x) are assigned the value of their distance from the top spectral trace measured in CCD pixels.
int mos_spectral_resolution | ( | cpl_image * | image, |
double | lambda, | ||
double | startwave, | ||
double | dispersion, | ||
int | saturation, | ||
double * | mfwhm, | ||
double * | rmsfwhm, | ||
double * | resolution, | ||
double * | rmsres, | ||
int * | nlines | ||
) |
Compute mean spectral resolution at a given arc lamp line.
image | Rectified and wavelength calibrated arc lamp image |
lambda | Wavelength to examine |
startwave | Shortest wavelength in image. |
dispersion | Wavelength units per image pixel |
saturation | Saturation value |
mfwhm | Returned: median FWHM |
rmsfwhm | Returned: RMS of median FWHM |
resolution | Returned: spectral resolution |
rmsres | Returned: RMS of spectral resolution |
nlines | Returned: Number of examined line profiles |
Given a wavelength, determine spectral resolution from a given arc lamp line. A high S/N is assumed (virtually no noise). Working with 2D extracted images!
cpl_error_code mos_subtract_background | ( | cpl_image * | image | ) |
Subtract the background.
image | Image to subtract the background |
cpl_image* mos_subtract_sky | ( | cpl_image * | science, |
cpl_table * | slits, | ||
cpl_table * | polytraces, | ||
double | reference, | ||
double | blue, | ||
double | red, | ||
double | dispersion | ||
) |
Subtract the sky from the scientific CCD exposure.
science | Image containing the CCD scientific spectra |
slits | Table with slits positions |
polytraces | Coefficients of spectral curvature polynomials |
reference | Reference wavelength |
blue | Start lambda to process |
red | End lambda to process |
dispersion | Mean spectral dispersion |
The input science frame should be already bias subtracted, and should be oriented so that the dispersion direction is horizontal with blue on the left and red on the right. The sky level is determined by robust linear fitting of flux along the spatial direction. The input science image is sky subtracted IN PLACE using the obtained sky map, that is also returned.
cpl_table* mos_trace_flat | ( | cpl_image * | flat, |
cpl_table * | slits, | ||
double | reference, | ||
double | blue, | ||
double | red, | ||
double | dispersion | ||
) |
Trace flat field spectra.
flat | Flat field image |
slits | Slits positions on the CCD |
reference | Reference wavelength |
blue | Start lambda for tracing |
red | End lambda for tracing |
dispersion | Mean spectral dispersion |
The input flat field image is expected to be oriented with horizontal dispersion direction and red wavelengths on the right side, and it should be of type CPL_TYPE_FLOAT
. The slits table should be the output of either the function mos_identify_slits()
(if available) or the function mos_locate_spectra()
.
The flat image is shifted one pixel down and is subtracted from the original image. The result is a vertical gradient map. Next, the negative values are forced positive, to obtain an absolute gradient map. The map is passed with a horizontal median filter, and after that the gradient peaks are traced starting from the slits positions listed in the input slits table. The number of pixels to the left and to the right of the reference pixel is trivially derived from the specified spectral range blue to red and dispersion.
The output table contains the traced spectral edges positions in CCD (Y) coordinates for each spectrum. The columns are named after the "slit_id" listed in the input slits table, and are preceded by a "t" for upper edges, and by a "b" for bottom edges: for instance, the trace corresponding to the upper edge of a spectrum with id = 123 will be found in a column named "t123". If the "slit_id" column is missing in the input table, one will be created with conventional (unique) numbers. One more column will be created, named "x", listing the corresponding CCD (X) coordinates of the trace.
cpl_error_code mos_validate_slits | ( | cpl_table * | slits | ) |
Check validity of a slit location table.
slits | Slit location table to validate |
The input slits table is the one obtained with the functions mos_locate_spectra()
and mos_rotate_slits
. This table is expected to contain double precision columns labeled xtop, ytop, xbottom, and ybottom, and this is the check that is performed here.
cpl_table* mos_wavelength_align | ( | cpl_image * | image, |
cpl_table * | slits, | ||
double | refwave, | ||
double | firstLambda, | ||
double | lastLambda, | ||
cpl_table * | idscoeff, | ||
cpl_vector * | skylines, | ||
int | highres, | ||
int | order, | ||
cpl_image * | calibration, | ||
int | sradius | ||
) |
Modify the input wavelength solution to match reference sky lines.
image | Image with rectified scientific spectra |
slits | Slits positions table |
refwave | Reference wavelength |
firstLambda | Wavelength range start |
lastLambda | Wavelength range end |
idscoeff | Table with IDS polynomials |
skylines | Vector with wavelengths of reference skylines |
highres | 1 = high resolution data, 0 = low resolution data |
order | Order of sky lines offsets fitting polynomial |
calibration | Rectified wavelength calibration image |
sradius | Search radius for sky lines |
The input image is the image of the scientific spectra with the spectral curvature removed, as produced by the function mos_spatial_calibration()
. The input slits table should be the same used and processed by the same function, containing a column named "position" listing the position of the individual spectra in the rectified image. The table idscoeff contains the polynomial fits coefficients obtained for each input image row, as produced by the function mos_wavelength_calibration_final()
. The vector skylines should list a number of reference sky-lines wavelengths. The calibrating polynomials will be used to get the expected positions of the reference skylines for each slit, for measuring their offset from this position as a function of wavelength. If the skylines vector is not provided, an internal list of sky lines is used instead. Only in this case the argument highres is checked in order to select a sky lines list for high or low resolution data (by high resolution data we mean here R > 700). In all cases, only the sky lines within the specified range firstLambda lastLambda will be used. If the rectified wavelengths calibration image produced by the function mos_wavelength_calibration_final()
is provided, the mapped wavelengths will be upgraded to reflect the alignment of the old solution to the position of the detected sky lines. Subsequently, such map may be transferred to the CCD image using the function mos_map_wavelengths()
.
More in detail: for each slit, a "sky" spectrum is derived by computing the median slit spectrum, reducing in this way possible contamination by bright scientific object(s) contained in the slit. All the IDS polynomials modelling the slit are used to determine the sky lines offsets: with N slit rows, N independent offsets for each reference sky line are found; a new table is created, with columns containing the median offsets obtained for each reference sky line and for each slit. The columns are named after the "slit_id" listed in the input slits table, preceded by "offset". For instance, the median offsets for all sky lines observed on a slit with id = 123 will be written to a column named "offset123". A column "wave" listing the reference wavelengths used will be also included to the table.
For each slit, the median offsets are fitted by a polynomial relation that is then summed to all the IDS polynomials pertaining to that slit, modifying in this way the input idscoeff table. It is of course advisable not to go beyond a fitting polynomial of 0th or 1st order, unless many and well distributed reference sky lines are available within the specified range. Note that this way of proceeding is applied to avoid destroying the information about irregularities in the slit ("slit geometry").
cpl_table* mos_wavelength_align_lss | ( | cpl_image * | image, |
double | refwave, | ||
double | firstLambda, | ||
double | lastLambda, | ||
cpl_table * | idscoeff, | ||
cpl_vector * | skylines, | ||
int | highres, | ||
int | order, | ||
cpl_image * | calibration, | ||
int | sradius | ||
) |
Modify the input wavelength solution to match reference sky lines (LSS).
image | Image with rectified scientific spectra |
refwave | Reference wavelength |
firstLambda | Wavelength range start |
lastLambda | Wavelength range end |
idscoeff | Table with IDS polynomials |
skylines | Vector with wavelengths of reference skylines |
highres | 1 = High resolution, 0 = Low resolution |
order | Order of sky lines offsets fitting polynomial |
calibration | Rectified wavelength calibration image |
sradius | Search radius for sky lines |
The input image is the image of the scientific spectra with the spectral curvature removed, as produced by the function mos_spatial_calibration()
. The table idscoeff contains the polynomial fits coefficients obtained for each input image row, as produced by the function mos_wavelength_calibration_final()
. The vector skylines should list a number of reference sky-lines wavelengths. The calibrating polynomials will be used to get the expected positions of the reference skylines for each slit, for measuring their offset from this position as a function of wavelength. If the skylines vector is not provided, an internal list of sky lines is used instead. Only in this case the argument highres is checked in order to select a sky lines list for high or low resolution data (by high resolution data we mean here R > 700). In all cases, only the sky lines within the specified range firstLambda lastLambda will be used. If the rectified wavelengths calibration image produced by the function mos_wavelength_calibration_final()
is provided, the mapped wavelengths will be upgraded to reflect the alignment of the old solution to the position of the detected sky lines. Subsequently, such map may be transferred to the CCD image using the function mos_map_wavelengths()
.
More in detail: a "sky" spectrum is derived by computing the median spectrum, reducing in this way possible contamination by bright scientific object(s) contained in the image. All the IDS polynomials modelling the image are used to determine the sky lines offsets: with N image rows, N independent offsets for each reference sky line are found; a new table is created, with a column containing the median offsets obtained for each reference sky line and for each image row. This column is named "offset". A column "wave" listing the reference wavelengths used will be also included to the table.
For each image row, the measured offsets are fitted by a polynomial relation of given order. The coefficients of all the obtained polynomial relations are then modeled as a function of the image row, and their modeled values are then summed to all the IDS polynomials modifying in this way the input idscoeff table. It is of course advisable not to go beyond a fitting polynomial of 0th or 1st order, unless many and well distributed reference sky lines are available within the specified range. Note that this way of proceeding is applied to avoid destroying the information about irregularities in the slit ("slit geometry").
cpl_image* mos_wavelength_calibration | ( | cpl_image * | image, |
double | refwave, | ||
double | firstLambda, | ||
double | lastLambda, | ||
double | dispersion, | ||
cpl_table * | idscoeff, | ||
int | flux | ||
) |
Remap at constant wavelength step an image of rectified scientific spectra.
image | Image with rectified scientific spectra |
refwave | Reference wavelength |
firstLambda | Wavelength of first pixel of resampled image |
lastLambda | Wavelength of last pixel of resampled image |
dispersion | Resampling step (wavelength units/pixel) |
idscoeff | Table with IDS polynomials |
flux | If zero, flux conservation correction is not applied. |
The input image is the image of the scientific spectra with the spectral curvature removed, as produced by the function mos_spatial_calibration()
. The table idscoeff contains the polynomial fits coefficients obtained for each input image row, as produced by the function mos_wavelength_calibration_final()
, and possibly modified by the function mos_wavelength_align()
, used to align the wavelength solution to available sky lines. The input image is resampled at a constant wavelength step, dispersion, and is returned by this function. In case of error a NULL
pointer is returned.
cpl_image* mos_wavelength_calibration_final | ( | cpl_image * | image, |
cpl_table * | slits, | ||
cpl_vector * | lines, | ||
double | dispersion, | ||
float | level, | ||
int | sradius, | ||
int | order, | ||
double | reject, | ||
double | refwave, | ||
double * | wavestart, | ||
double * | waveend, | ||
int * | nlines, | ||
double * | error, | ||
cpl_table * | idscoeff, | ||
cpl_image * | calibration, | ||
cpl_image * | residuals, | ||
cpl_table * | restable | ||
) |
Derive wavelength calibration from a rectified arc lamp or sky exposure.
image | A rectified arc lamp or sky exposure |
slits | Slits positions table |
lines | List of reference lines wavelengths |
dispersion | Expected value of the dispersion (wavelength units/pixel) |
level | Threshold for peak detection |
sradius | Search radius for expected peaks (pixels) |
order | Degree of fitting polynomial for wavelength calibration |
reject | Max residual tolerated for line rejection (pixels) |
refwave | Reference wavelength |
wavestart | I/O wavelength of first pixel of resampled image |
waveend | I/O wavelength of last pixel of resampled image |
nlines | Returned array of number of lines used for each fit |
error | Returned array of mean accuracies obtained for each fit |
idscoeff | Returned table with IDS polynomials |
calibration | Returned wavelength calibration image |
residuals | Returned residuals image |
restable | Returned residuals table |
This function applies the same algorithm for line identification that is applied by the function mos_wavelength_calibration_raw()
. The fundamental difference is that the algorithm is here applied to an image containing just spectra where the spectral curvature was eliminated, as produced by the function mos_spatial_calibration()
. The input slits table should be the same used and processed by the function mos_spatial_calibration()
, containing a column named "position" listing the position of the individual spectra in the rectified image.
The rows of the input image are independently calibrated one by one. The spectral continuum is assumed to have been already removed (and it should be so, if the function mos_wavelength_calibration_raw()
was earlier called).
Optionally, in case sradius is positive, the polynomial solutions obtained for all rows of each individual slit are averaged into a single solution, that is used as a first-guess that is passed to the function mos_find_peaks()
. This function will search again along each row belonging to that slit the reference lines candidates around their expected positions, within the specified search radius; the polynomial fitting is then repeated using the new found positions. This option can be useful for recovering very faint (i.e., below level) reference lines, or reference lines that were lost by mos_identify_peaks()
because of a partially wrong input lines list. The first-guess polynomial solution is derived from the initial polynomial solutions by determining their median coefficients.
An array nlines, containing the number of lines used for each fit, and an array error, containing the mean error of the polynomial models (in pixels), are returned. A fit failure is indicated with the corresponding element of nlines set to zero. The mean error of the polynomial model is evaluated by dividing the RMS of the fit residuals by the square root of the number of fitted points divided the degrees of freedom of the model:
mean error = RMS / sqrt(N / (@em order + 1))
The arrays nlines and error must be pre-allocated, and should all have as many elements as the number of rows in the input image. If NULL
pointers are passed, they are not computed.
In the table idscoeff will be written the polynomial fits coefficients obtained for each input image row: this table must therefore be preallocated, before calling this function, with the same number of rows as the input image. No columns should be defined in this table: they will be created automatically by this function, and will be labeled c0, c1, c2, ... up to the specified order of the fitting polynomial.
As a by-product of the wavelength calibration, the input image is resampled at a constant wavelength step, dispersion, and is returned by this function. In case of error a NULL
pointer is returned. If the input arguments wavestart and waveend are greater than 1.0, they are taken as the spectral interval where the spectra are resampled; alternatively, the wavelength range covered by the resampled image is equal to the wavelength range of the input reference lines catalog, extended by 10 percent on the blue and the red sides: such used spectral interval is then returned via the same variables, wavestart and waveend. Note that limiting the spectral range doesn't prevents this function to perform a wavelength calibration based on all the reference wavelengths listed in the input line catalog, including those outside the specified range (if they are found somewhere on the detector).
Optionally, an image of the wavelength calibrated input exposure, calibration, might be filled with the value of the wavelength for each pixel. This image may be significantly more accurate than the calibration image obtained with the preliminary wavelength calibration, returned by the function mos_wavelength_calibration_raw()
. For this reason it would also be appropriate to map it back to the original CCD coordinate system, using the function mos_map_wavelengths()
. The image calibration should be pre-allocated in order to have it computed, and it should have the same size of the input image that was used for the calibration. Furthermore, an image of the fit residuals, residuals, can be returned. This image must also be be pre-allocated for having it computed, and should as well have the same size of the input rectified image. If NULL
pointers are passed, the calibration and residuals images are not computed.
cpl_image* mos_wavelength_calibration_raw | ( | const cpl_image * | image, |
cpl_vector * | lines, | ||
double | dispersion, | ||
float | level, | ||
int | sradius, | ||
int | order, | ||
double | reject, | ||
double | refwave, | ||
double * | wavestart, | ||
double * | waveend, | ||
int * | nlines, | ||
double * | error, | ||
cpl_table * | idscoeff, | ||
cpl_image * | calibration, | ||
cpl_image * | residuals, | ||
cpl_table * | restable, | ||
cpl_mask * | refmask | ||
) |
Derive wavelength calibration from a raw arc lamp or sky exposure.
image | An arc lamp or sky exposure |
lines | List of reference lines wavelengths |
dispersion | Expected value of the dispersion (wavelength units/pixel) |
level | Threshold for peak detection |
sradius | Search radius for expected peaks (pixels) |
order | Degree of fitting polynomial for wavelength calibration |
reject | Max residual tolerated for line rejection (pixels) |
refwave | Reference wavelength |
wavestart | I/O wavelength of first pixel of resampled image |
waveend | I/O wavelength of last pixel of resampled image |
nlines | Returned array of number of lines used for each fit |
error | Returned array of mean accuracies obtained for each fit |
idscoeff | Returned table with IDS polynomials |
calibration | Returned wavelength calibration image |
residuals | Returned residuals image |
restable | Returned residuals table |
refmask | Returned monochromatic image at reference wavelength |
The input image must contain spectra with the dispersion direction approximately horizontal, with blue on the left and red on the right.
The rows of the input image are independently calibrated one by one. First, the function mos_arc_background()
is used to subtract the continuum from the input spectrum. Second, the two functions mos_peak_candidates()
and mos_refine_peaks()
are used to create a list of positions of reference lines candidates along each image row. Only peaks above level are selected. Third, the function mos_identify_peaks()
is applied to select from the found peaks the ones corresponding to reference lines, associating them to the appropriate wavelengths from the line catalog lines. The ensuing polynomial fit is adaptive: it is performed using the specified polynomial order in case the resulting list of positions in pixels and wavelengths contains at least twice the degrees of freedom of the polynomial (i.e., order + 1). If this is not the case, the order of the fitting polynomial is adapted to the number of actual entries. The number of points to fit, however, should never be less than 4. The fit is performed both from wavelength to pixel and from pixel to wavelength, using the functions mos_poly_wav2pix()
and mos_poly_pix2wav()
. If a reject threshold greater than zero is specified, outlaying entries are removed iteratively from the list. If the reject threshold is negative, no outliers rejection is applied, and the first fit is accepted.
Optionally, in case sradius is positive, the obtained polynomial solution is passed to the function mos_find_peaks()
, that searches again along each image row the reference lines candidates around their expected positions, within the specified search radius; The polynomial fitting is then repeated with the new found positions. This option can be useful for recovering very faint (i.e., below level) reference lines, or reference lines that were lost by mos_identify_peaks()
because of a partially wrong input lines list.
An array nlines, containing the number of lines used for each fit, and an array error, containing the mean error of the polynomial models (in pixels), are returned. A fit failure is indicated with the corresponding element of nlines set to zero. The mean error of the polynomial model is evaluated by dividing the RMS of the fit residuals by the square root of the number of fitted points divided the degrees of freedom of the model:
mean error = RMS / sqrt(N / (@em order + 1))
The arrays nlines and error must be pre-allocated, and should all have as many elements as the number of rows in the input image. If NULL
pointers are passed, they are not computed. In the same way a preallocated idscoeff table may or may not be passed to this function, and it will be filled with the dispersion relation coefficients only in the former case. This table should be preallocated with the same number of rows as the input image. No columns should be defined in this table: they will be created automatically by this function, and will be labeled c0, c1, c2, ... up to the specified order of the fitting polynomial.
As a by-product of the wavelength calibration, the input image is resampled at a constant wavelength step, dispersion, and is returned by this function. In case of error a NULL
pointer is returned. If the input arguments wavestart and waveend are greater than 1.0, they are taken as the spectral interval where the spectra are resampled; alternatively, the wavelength range covered by the resampled image is equal to the wavelength range of the input reference lines catalog, extended by 10 percent on the blue and the red sides: such used spectral interval is then returned via the same variables, wavestart and waveend. Note that limiting the spectral range doesn't prevents this function to perform a wavelength calibration based on all the reference wavelengths listed in the input line catalog, including those outside the specified range (if they are found somewhere on the detector).
Optionally, an image of the wavelength calibrated input exposure, calibration, an image of the fit residuals, residuals, and a monochromatic mask image, refmask, that is obtained at a given wavelength refwave, can be returned. These images must be pre-allocated, and should all have the same size of the input image. If NULL
pointers are passed, they are not computed. The calibration image consists of pixels having the value of their wavelength, or the value zero if this is not available. The residuals image has, at the positions of the reference lines, the value of the corresponding distance from the polynomial model. The refmask image is used to flag the pixels containing the specified reference wavelength. All the other pixels are set to zero. This mask is the monochromatic image on the CCD of the slits located on the telescope focal plane, and can be used in the determination of an optical distortion model. In order to clean this image from occasional bad fits contributions and fill possible small gaps in the wavelength calibration, a morphological closing (dilation + erosion), followed by a morphological opening (erosion + dilation), is applied.