FORS Pipeline Reference Manual  4.12.5
Macros | Functions
MOS data reduction library

Macros

#define SEGNO(a, b)   ((b) >= 0.0 ? fabs(a) : -fabs(a))
 
#define READY   1
 Montecarlo simulation to evaluate error on polynomial fit. More...
 
#define cleanup
 

Functions

static void mos_seed (void)
 
static double mos_randg (int seme)
 
static cpl_image * mos_image_vertical_median_filter (cpl_image *ima_in, int filtsizey, int refrow, int above, int below, int step)
 
static int peakPosition (const float *data, int size, float *position, int minPoints)
 
static double values_to_dx (double v1, double v2, double v3)
 
static float * min_filter (float *buffer, int length, int size)
 
static float * max_filter (float *buffer, int length, int size)
 
static float * smo_filter (float *buffer, int length, int size)
 
static cpl_polynomial * read_global_distortion (cpl_table *global, cpl_size row)
 
static cpl_table * write_global_distortion (cpl_table *global, int row, cpl_polynomial *poly)
 
static int robustLinearFit (cpl_bivector *list, double *a, double *b, double *abdev)
 
cpl_table * mos_hough_table (cpl_table *table, const char *x, const char *y)
 
static void mos_extraction (cpl_image *sciwin, cpl_image *skywin, cpl_image *extracted, cpl_image *sky, cpl_image *error, int nobjects, int extraction, double ron, double conad, int ncomb)
 
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_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_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...
 
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...
 
void mos_set_multiplex (int multiplex)
 
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, cpl_table *detected_lines)
 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_identify_slits_fast (cpl_table *slits, cpl_table *maskslits, cpl_table *global)
 
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, cpl_table *detected_lines)
 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_error_code mos_clean_bad_pixels (cpl_image *image, cpl_table *table, int spectral)
 
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)
 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, int *nslits_out_det)
 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...
 
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_table * mos_load_overscans_fors (const cpl_propertylist *header)
 
cpl_polynomial * mos_montecarlo_polyfit (cpl_table *points, cpl_table *evaluate, int samples, int order)
 
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, int *nslits_out_det)
 Create PMOS slit location table from FITS header of FORS1/2 MOS data. More...
 
int * fors_get_nobjs_perslit (cpl_table *slits)
 
double fors_get_object_position (cpl_table *slits, int slit, int object)
 
int mos_rebin_signal (cpl_image **image, int rebin)
 
int mos_rebin_error (cpl_image **image, int rebin)
 
int map_table (cpl_image *image, double start, double step, cpl_table *table, char *xname, char *yname)
 
static cpl_image * polysmooth (cpl_image *image, int order, int hw)
 
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...
 
static double ksigma_vector (cpl_vector *values, double klow, double khigh, int kiter, int *good)
 
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. More...
 
cpl_image * mos_propagate_photometry_error (cpl_image *spectra, cpl_image *errors, cpl_table *response, cpl_table *ext_table, double startwave, double dispersion, double gain, double exptime, double airmass)
 Propagate errors from response curve and extracted spectra. 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...
 
int fors_mos_is_lss_like (cpl_table *maskslits, int nslits_out_det)
 

Detailed Description

The module moses collects low/medium level functions related to MOS data reduction.

Macro Definition Documentation

#define READY   1

Montecarlo simulation to evaluate error on polynomial fit.

Parameters
pointsTable with (x,y) coordinates and uncertainties on y.
evaluateTable with x coordinates where to evaluate model variance.
samplesNumber of simulations.
orderDegree of the fitted polynomial.
Returns
Polynomial fit

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.

Definition at line 15677 of file moses.c.

#define cleanup
Value:
do { \
cpl_image_delete(spectrum); \
cpl_image_delete(flux); \
cpl_image_delete(efficiency); \
cpl_image_delete(smo_efficiency); \
cpl_image_delete(extinction); \
cpl_image_delete(response); \
cpl_image_delete(smo_response); \
cpl_image_delete(physical); \
} while (0)

Definition at line 17169 of file moses.c.

Function Documentation

cpl_table* mos_global_distortion ( cpl_table *  slits,
cpl_table *  maskslits,
cpl_table *  ids,
cpl_table *  crv,
double  reference 
)

Determine all global distortions models.

Parameters
slitsTable with slits positions on CCD
maskslitsTable with slits positions on mask
idsIDS coefficients table
crvSpectral curvature coefficients table
referenceReference wavelength
Returns
The global distortions table

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.

Definition at line 1179 of file moses.c.

Referenced by vimos_calib_impl().

cpl_table* mos_build_slit_location ( cpl_table *  global,
cpl_table *  maskslits,
int  ysize 
)

Build the slit location table from a global distortions table.

Parameters
globalGlobal distortions table
maskslitsTable with slits positions on mask
ysizeY size of the CCD
Returns
Slits location table

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

xtop = poly0(mxtop, mytop)
xbottom = poly0(mxbottom, mybottom)
ytop = poly7(mxtop, mytop)
+ poly8(mxtop, mytop) * xtop;
+ poly9(mxtop, mytop) * xtop^2
ybottom = poly7(mxbottom, mybottom)
+ poly8(mxbottom, mybottom) * xbottom;
+ poly9(mxbottom, mybottom) * xbottom^2

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.

Definition at line 1543 of file moses.c.

Referenced by vimos_calib_impl().

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.

Parameters
globalGlobal distortions table
maskslitsTable with slits positions on mask
slitsTable with slits positions on CCD
Returns
Curvature coefficients table

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

c0 = poly7(mx, my)
c1 = poly8(mx, my)
c2 = poly9(mx, my)

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.

Definition at line 1690 of file moses.c.

Referenced by vimos_calib_impl().

cpl_table* mos_build_disp_coeff ( cpl_table *  global,
cpl_table *  slits 
)

Build the IDS coefficients table from a global distortions table.

Parameters
globalGlobal distortions table
slitsTable with slits positions on CCD
Returns
IDS coefficients table

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

c0 = poly0(xmask, ymask)
c1 = poly1(x, y)
c2 = poly2(x, y)
c3 = poly3(x, y)
c4 = poly4(x, y)
c5 = poly5(x, y)

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").

Definition at line 1845 of file moses.c.

Referenced by vimos_calib_impl().

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.

Parameters
scienceImage containing the CCD scientific spectra
slitsTable with slits positions
polytracesCoefficients of spectral curvature polynomials
referenceReference wavelength
blueStart lambda to process
redEnd lambda to process
dispersionMean spectral dispersion
Returns
The sky subtracted scientific image

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.

Definition at line 1969 of file moses.c.

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.

Parameters
flatImage containing the original flat field spectra
spatialSpatial calibration image
slitsTable with slits positions
polytracesCoefficients of spectral curvature polynomials
referenceReference wavelength
blueStart lambda to process
redEnd lambda to process
dispersionMean spectral dispersion
sradiusRadius of smoothing box along the dispersion direction
polyorderOrder of fitting polynomial along the dispersion
Returns
The smoothed flat field exposure used for normalisation

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.

Definition at line 2290 of file moses.c.

References mos_spatial_calibration().

Referenced by vimos_calib_impl().

cpl_image* mos_normalise_longflat ( cpl_image *  flat,
int  sradius,
int  dradius,
int  polyorder 
)

Normalise a long slit flat field exposure.

Parameters
flatImage containing the original flat field spectra
sradiusRadius of smoothing box along the spatial direction
dradiusRadius of smoothing box along the dispersion direction
polyorderOrder of fitting polynomial along the spatial direction
Returns
The smoothed flat field exposure used for normalisation

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.

Definition at line 2741 of file moses.c.

cpl_error_code mos_interpolate_wavecalib_slit ( cpl_table *  idscoeff,
cpl_table *  slits,
int  order,
int  global 
)

Interpolate MOS wavelength calibration.

Parameters
idscoeffTable with IDS polynomials
slitsTable with slits positions
order0 = median, > 0 order of fitting polynomial.
Returns
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().

Definition at line 2932 of file moses.c.

References mos_interpolate_wavecalib().

cpl_error_code mos_interpolate_wavecalib ( cpl_table *  idscoeff,
cpl_image *  wavemap,
int  mode,
int  degree 
)

Interpolate LSS wavelength calibration.

Parameters
idscoeffTable with IDS polynomials
wavemapWavelength calibration image
mode0 = do nothing, 1 = fill gaps, 2 = global model
degree0 = median, > 0 order of fitting polynomial.
Returns
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().

Definition at line 3061 of file moses.c.

Referenced by mos_interpolate_wavecalib_slit(), mos_wavelength_calibration_final(), and vimos_calib_impl().

cpl_image* mos_remove_bias ( cpl_image *  image,
cpl_image *  bias,
cpl_table *  overscans 
)

Subtract the bias from a CCD exposure.

Parameters
imageImage containing the data to correct
biasMaster bias
overscansTable with the overscan information
Returns
A newly allocated bias subtracted image

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.

Definition at line 3422 of file moses.c.

Referenced by vimos_calib_impl().

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)

Parameters
spectrumA 1D emission line spectrum
backA pre-allocated buffer where the background will be written
lengthLength of spectrum
msizeSize of min-filter
fsizeSize of running-average-filter
Returns
CPL_ERROR_NONE in case of success
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.

Definition at line 3595 of file moses.c.

Referenced by mos_arc_background().

cpl_image* mos_arc_background ( cpl_image *  image,
int  msize,
int  fsize 
)

Background determination on emission line spectrum (arc)

Parameters
imageAn emission line spectrum exposure
msizeSize of min-filter
fsizeSize of running-average-filter
Returns
Background image.
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.

Definition at line 3697 of file moses.c.

References mos_arc_background_1D(), and mos_image_filter_median().

Referenced by mos_subtract_background().

int mos_lines_width ( const float *  spectrum,
int  length 
)

Estimate lines widths (in pixel) in arc lamp spectrum.

Parameters
spectrumA 1D emission line spectrum
lengthLength of spectrum
Returns
Mean lines width

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.

Definition at line 3770 of file moses.c.

Referenced by mos_spectral_resolution(), mos_wavelength_calibration_final(), and mos_wavelength_calibration_raw().

cpl_vector* mos_peak_candidates ( const float *  spectrum,
int  length,
float  level,
float  exp_width 
)

Find positions of peaks candidates.

Parameters
spectrumA 1D emission line spectrum
lengthLength of spectrum
levelSignificance level
exp_widthExpected lines FWHM (in pixels)
Returns
List of peaks candidates positions

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.

Definition at line 3873 of file moses.c.

Referenced by mos_trace_flat(), mos_wavelength_calibration_final(), and mos_wavelength_calibration_raw().

cpl_vector* mos_refine_peaks ( const float *  spectrum,
int  length,
cpl_vector *  peaks,
int  sradius 
)

Improve (when possible) accuracy of peaks candidates positions.

Parameters
spectrumA 1D emission line spectrum
lengthLength of spectrum
peaksList of peaks candidates
sradiusSearch radius for expected peaks
Returns
Vector with refined peak positions

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.

Definition at line 3976 of file moses.c.

Referenced by mos_wavelength_calibration_final(), and mos_wavelength_calibration_raw().

cpl_bivector* mos_identify_peaks ( cpl_vector *  peaks,
cpl_vector *  lines,
double  min_disp,
double  max_disp,
double  tolerance 
)

Identify peak candidates.

Parameters
peaksList of peaks candidates
linesList of wavelengths
min_dispMin expected spectral dispersion (Angstrom/pixel)
max_dispMax expected spectral dispersion (Angstrom/pixel)
toleranceTolerance for interval ratio comparison
Returns
List of pixel positions and wavelengths of all identified peaks

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.

Definition at line 4085 of file moses.c.

Referenced by mos_wavelength_calibration_final(), and mos_wavelength_calibration_raw().

double mos_eval_dds ( cpl_polynomial *  ids,
double  blue,
double  red,
double  refwave,
double  pixel 
)

Evaluate the wavelength of a pixel position.

Parameters
idsInverse dispersion relation (from wave to pixel)
blueStart wavelength of ids validity
redEnd wavelength of ids validity
refwaveReference wavelength
pixelPixel position
Returns
Wavelength of pixel

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.

Definition at line 4774 of file moses.c.

Referenced by mos_map_idscoeff(), mos_wavelength_calibration_final(), and mos_wavelength_calibration_raw().

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.

Parameters
pixwavList of pixel positions and associated wavelengths
orderOrder of the fitting polynomial
rejectMax residual tolerated for line rejection (in pixel)
minlinesMin number of lines to be used in the fit
nlinesOutput number of lines actually used in the fit
errOutput RMS of the fit residuals
Returns
Polynomial relation from wavelengths to pixels

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.

Definition at line 4829 of file moses.c.

Referenced by mos_poly_pix2wav(), mos_wavelength_calibration_final(), and mos_wavelength_calibration_raw().

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.

Parameters
pixwavList of pixel positions and associated wavelengths
orderOrder of the fitting polynomial
rejectMax residual tolerated for line rejection (in wave units)
minlinesMin number of lines to be used in the fit
nlinesOutput number of lines actually used in the fit
errOutput RMS of the fit residuals
Returns
Polynomial relation from wavelengths to pixels

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.

Definition at line 4989 of file moses.c.

References mos_poly_wav2pix().

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.

Parameters
spectrumA 1D emission line spectrum
lengthLength of spectrum
linesList of wavelengths
idsPolynomial conversion from wavelengths to pixel
refwaveZero wavelength used in ids determination
sradiusSearch radius for expected peaks
Returns
List of pixel positions and wavelengths of all identified 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.

Definition at line 5041 of file moses.c.

Referenced by mos_wavelength_calibration_final(), and mos_wavelength_calibration_raw().

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,
cpl_table *  detected_lines 
)

Derive wavelength calibration from a raw arc lamp or sky exposure.

Parameters
imageAn arc lamp or sky exposure
linesList of reference lines wavelengths
dispersionExpected value of the dispersion (wavelength units/pixel)
levelThreshold for peak detection
sradiusSearch radius for expected peaks (pixels)
orderDegree of fitting polynomial for wavelength calibration
rejectMax residual tolerated for line rejection (pixels)
refwaveReference wavelength
wavestartI/O wavelength of first pixel of resampled image
waveendI/O wavelength of last pixel of resampled image
nlinesReturned array of number of lines used for each fit
errorReturned array of mean accuracies obtained for each fit
idscoeffReturned table with IDS polynomials
calibrationReturned wavelength calibration image
residualsReturned residuals image
restableReturned residuals table
refmaskReturned monochromatic image at reference wavelength
detected_linesReturned info on lines detected and used for the fit
Returns
Input exposure resampled at constant wavelength step.

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.

If detected_lines table is an input, then a table with the position of the detected lines, its peak flux, wavelength identified and final xpos position in the wavelength calibrated image using the wavelength solution is returned. The table has to be allocated but empty.

Definition at line 5221 of file moses.c.

References mos_eval_dds(), mos_find_peaks(), mos_identify_peaks(), mos_lines_width(), mos_peak_candidates(), mos_poly_wav2pix(), and mos_refine_peaks().

Referenced by vimos_calib_impl().

cpl_table* mos_locate_spectra ( cpl_mask *  mask)

Find the location of detected spectra on the CCD.

Parameters
maskA reference mask at a given reference wavelength
Returns
Table with characteristics of the detected spectra

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

Parameters
maskA reference mask at a given reference wavelength
Returns
Table with characteristics of the detected spectra

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().

Definition at line 5922 of file moses.c.

Referenced by vimos_calib_impl().

cpl_error_code mos_validate_slits ( cpl_table *  slits)

Check validity of a slit location table.

Parameters
slitsSlit location table to validate
Returns
CPL_ERROR_NONE in case of success

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.

Definition at line 6010 of file moses.c.

Referenced by mos_identify_slits(), and mos_rotate_slits().

cpl_error_code mos_rotate_slits ( cpl_table *  slits,
int  rotation,
int  nx,
int  ny 
)

Rotate a slit location table.

Parameters
slitsSlit location table to rotate
rotationRotation angle in multiples of 90 degrees (counterclockwise)
nxX size of reference image
nyY size of reference image
Returns
CPL_ERROR_NONE in case of success

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.

Definition at line 6074 of file moses.c.

References mos_validate_slits().

Referenced by mos_trace_flat(), and vimos_calib_impl().

cpl_table* mos_identify_slits ( cpl_table *  slits,
cpl_table *  maskslits,
cpl_table *  global 
)

Identify slits listed in a slit location table.

Parameters
slitsSlit location on the camera focal plane (CCD pixels).
maskslitsSlit location on the telescope focal plane (mask).
globalGlobal distortion table.
Returns
New slit location 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.

Definition at line 6188 of file moses.c.

References mos_validate_slits().

Referenced by vimos_calib_impl().

cpl_table* mos_trace_flat ( cpl_image *  flat,
cpl_table *  slits,
double  reference,
double  blue,
double  red,
double  dispersion 
)

Trace flat field spectra.

Parameters
flatFlat field image
slitsSlits positions on the CCD
referenceReference wavelength
blueStart lambda for tracing
redEnd lambda for tracing
dispersionMean spectral dispersion
Returns
A table with the tracings for each spectrum

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.

Definition at line 7488 of file moses.c.

References mos_peak_candidates(), and mos_rotate_slits().

Referenced by vimos_calib_impl().

cpl_table* mos_poly_trace ( cpl_table *  slits,
cpl_table *  traces,
int  order 
)

Fit spectral traces.

Parameters
slitsSlits positions on the CCD
tracesSpectral traces
orderOrder of fitting polynomial
Returns
Table with tracing polynomials coefficients

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".

Definition at line 7922 of file moses.c.

Referenced by vimos_calib_impl().

cpl_error_code mos_global_trace ( cpl_table *  slits,
cpl_table *  polytraces,
int  mode 
)

Recompute tracing coefficients globally.

Parameters
slitsSlits positions on the CCD
polytracesCoefficients of spectral curvature polynomials
mode0 = do nothing, 1 = fill gaps, 2 = global model
Returns
CPL_ERROR_NONE on success

The 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.

Definition at line 8083 of file moses.c.

Referenced by vimos_calib_impl().

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.

Parameters
spectraCCD image of spectra
slitsSlits positions on the CCD
polytracesCoefficients of spectral curvature polynomials
referenceReference wavelength
blueStart lambda for spatial remapping
redEnd lambda for spatial remapping
dispersionMean spectral dispersion
fluxIf zero, flux conservation is not applied
calibrationReturned spatial calibration image
Returns
Image with the spatially resampled spectra

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.

Definition at line 8264 of file moses.c.

Referenced by mos_normalise_flat(), and vimos_calib_impl().

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,
cpl_table *  detected_lines 
)

Derive wavelength calibration from a rectified arc lamp or sky exposure.

Parameters
imageA rectified arc lamp or sky exposure
slitsSlits positions table
linesList of reference lines wavelengths
dispersionExpected value of the dispersion (wavelength units/pixel)
levelThreshold for peak detection
sradiusSearch radius for expected peaks (pixels)
orderDegree of fitting polynomial for wavelength calibration
rejectMax residual tolerated for line rejection (pixels)
refwaveReference wavelength
wavestartI/O wavelength of first pixel of resampled image
waveendI/O wavelength of last pixel of resampled image
nlinesReturned array of number of lines used for each fit
errorReturned array of mean accuracies obtained for each fit
idscoeffReturned table with IDS polynomials
calibrationReturned wavelength calibration image
residualsReturned residuals image
restableReturned residuals table
detected_linesReturned info on lines detected and used for the fit
Returns
Input image resampled at constant wavelength step.

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.

If detected_lines table is an input, then a table with the position of the detected lines, its peak flux, wavelength identified and final xpos position in the wavelength calibrated image using the wavelength solution is returned. The table has to be allocated but empty.

Definition at line 8669 of file moses.c.

References mos_eval_dds(), mos_find_peaks(), mos_identify_peaks(), mos_interpolate_wavecalib(), mos_lines_width(), mos_peak_candidates(), mos_poly_wav2pix(), and mos_refine_peaks().

Referenced by vimos_calib_impl().

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.

Parameters
imageImage with rectified scientific spectra
refwaveReference wavelength
firstLambdaWavelength of first pixel of resampled image
lastLambdaWavelength of last pixel of resampled image
dispersionResampling step (wavelength units/pixel)
idscoeffTable with IDS polynomials
fluxIf zero, flux conservation correction is not applied.
Returns
Input image resampled at constant wavelength step.

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.

Definition at line 9412 of file moses.c.

Referenced by vimos_calib_impl().

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.

Parameters
imageImage with rectified scientific spectra
slitsSlits positions table
refwaveReference wavelength
firstLambdaWavelength range start
lastLambdaWavelength range end
idscoeffTable with IDS polynomials
skylinesVector with wavelengths of reference skylines
highres1 = high resolution data, 0 = low resolution data
orderOrder of sky lines offsets fitting polynomial
calibrationRectified wavelength calibration image
sradiusSearch radius for sky lines
Returns
Table with measured sky lines offsets (in pixel)

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").

Definition at line 9693 of file moses.c.

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).

Parameters
imageImage with rectified scientific spectra
refwaveReference wavelength
firstLambdaWavelength range start
lastLambdaWavelength range end
idscoeffTable with IDS polynomials
skylinesVector with wavelengths of reference skylines
highres1 = High resolution, 0 = Low resolution
orderOrder of sky lines offsets fitting polynomial
calibrationRectified wavelength calibration image
sradiusSearch radius for sky lines
Returns
Table with measured sky lines offsets (in pixel)

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").

Definition at line 10246 of file moses.c.

double mos_distortions_rms ( cpl_image *  rectified,
cpl_vector *  lines,
double  wavestart,
double  dispersion,
int  radius,
int  highres 
)

Estimate the spectral distortion modeling goodness.

Parameters
rectifiedCalibrated calibration image
linesReference wavelengths (line catalog)
wavestartWavelength of bluest (left) pixel in input image
dispersionAngstrom per pixel of input image
radiusSearch radius (in pixels of input image)
highres1 = high resolution data, 0 = low resolution data
Returns
Mean RMS of residuals in pixels

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).

Definition at line 10754 of file moses.c.

Referenced by vimos_calib_impl().

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.

Parameters
idscoeffTable with IDS polynomials
referenceReference wavelength
blueStart lambda for spatial remapping
redEnd lambda for spatial remapping
dispersionMean spectral dispersion
trendTrend to remove from IDS polynomials
Returns
Pixel map

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.

Definition at line 10891 of file moses.c.

Referenced by vimos_calib_impl().

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.

Parameters
idscoeffTable with IDS polynomials
xsizeX size of used CCD
referenceReference wavelength
blueStart lambda for spatial remapping
redEnd lambda for spatial remapping
Returns
Wavelengths map

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.

Definition at line 10976 of file moses.c.

References mos_eval_dds().

Referenced by vimos_calib_impl().

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.

Parameters
spatialCCD image of spatial coordinates
calibrationSpatially rectified image of wavelengths
slitsSlits positions on the CCD
polytracesCoefficients of spectral curvature polynomials
referenceReference wavelength
blueStart lambda for spatial remapping
redEnd lambda for spatial remapping
dispersionMean spectral dispersion
Returns
Wavelengths mapping on CCD.

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.

Definition at line 11087 of file moses.c.

Referenced by vimos_calib_impl().

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.

Parameters
spectraCCD image containing the observed slit spectra
wavecalibCCD image of wavelengths
spatialCCD image of spatial coordinates
slitsSlits positions on the CCD
polytracesCoefficients of spectral curvature polynomials
referenceReference wavelength
blueStart lambda for remapping
redEnd lambda for remapping
dispersionMean spectral dispersion
fluxflux = 0 means no flux conservation correction applied
Returns
Extracted slit spectra

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).

Definition at line 11437 of file moses.c.

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.

Parameters
spectraCCD image of spectra
wavemapCCD image of wavelengths
dispersionMean spectral dispersion
factorSupersampling factor
minpointsMinimum points required per supersampled spectrum bin
skymapReturned CCD image of sky
Returns
Table with median sky spectrum

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.

Definition at line 11849 of file moses.c.

cpl_table* mos_sky_map ( cpl_image *  spectra,
cpl_image *  wavemap,
double  dispersion,
cpl_image *  skymap 
)

Create a CCD median sky map.

Parameters
spectraCCD image of spectra
wavemapCCD image of wavelengths
dispersionMean spectral dispersion
skymapReturned CCD image of sky
Returns
Table with median sky spectrum

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.

Definition at line 12182 of file moses.c.

cpl_image* mos_sky_local_old ( cpl_image *  spectra,
cpl_table *  slits 
)

Local determination of sky.

Parameters
spectraRectified image of scientific spectra
slitsSlits positions table
Returns
Image of (rectified) sky

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.

Definition at line 12424 of file moses.c.

cpl_image* mos_sky_local ( cpl_image *  spectra,
cpl_table *  slits,
int  order 
)

Local determination of sky.

Parameters
spectraRectified image of scientific spectra
slitsSlits positions table
orderOrder of the polynomial fitting the sky.
Returns
Image of (rectified) 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.

Definition at line 12526 of file moses.c.

References mos_detect_objects().

cpl_error_code mos_clean_cosmics ( cpl_image *  image,
float  gain,
float  threshold,
float  ratio 
)

Remove cosmic rays from sky-subtracted CCD spectral exposure.

Parameters
imageInput image to be cleaned (in ADU)
gainInverse gain factor (e-/ADU)
thresholdThreshold for cosmics detection, given in noise sigmas
ratioRatio for discrimination between objects and cosmics
Returns
CPL_ERROR_NONE in case of success

If 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.

Definition at line 12881 of file moses.c.

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.

Parameters
spectraCCD image of spectra
slitsSlits positions on the CCD
polytracesCoefficients of spectral curvature polynomials
referenceReference wavelength
blueStart lambda for spatial remapping
redEnd lambda for spatial remapping
dispersionMean spectral dispersion
Returns
Coordinate map

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.

Definition at line 13385 of file moses.c.

cpl_image* mos_detect_objects ( cpl_image *  image,
cpl_table *  slits,
int  margin,
int  maxradius,
int  conradius 
)

Detect objects in rectified scientific frame.

Parameters
imageRectified image of scientific spectra
slitsTable with slits positions
marginNumber of pixels to exclude at slits edges
maxradiusMaximum extraction radius
conradiusContamination radius
Returns
Slits mean flux spatial profile

This 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

S = C * (L / L_o)

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):

B_i = (P_i * L_j + P_j * L_i) / (L_i + L_j)

where P_i is the position of the i-th peak, L_i its peak value, and j = i + 1. The position of the upper 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 lower 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.

Definition at line 13651 of file moses.c.

Referenced by mos_sky_local().

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.

Parameters
scienceRectified and sky subtracted scientific spectra
skyRectified sky spectra
objectsSpectra and objects position table
extractionExtraction mode: 0 = aperture, 1 = optimal (Horne)
ronRead-out-noise in ADU
gainConversion from ADU to electrons (e-/ADU)
ncombinedNumber of combined scientific frames
Returns
Images with extracted science, sky, and error spectra

The 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.

Definition at line 14002 of file moses.c.

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.

Parameters
imageRectified and wavelength calibrated arc lamp image
lambdaWavelength to examine
startwaveShortest wavelength in image.
dispersionWavelength units per image pixel
saturationSaturation value
mfwhmReturned: median FWHM
rmsfwhmReturned: RMS of median FWHM
resolutionReturned: spectral resolution
rmsresReturned: RMS of spectral resolution
nlinesReturned: Number of examined line profiles
Returns
1 in case of success, 0 in case of failure

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!

Definition at line 14205 of file moses.c.

References mos_lines_width().

Referenced by mos_resolution_table().

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.

Parameters
imageRectified and wavelength calibrated arc lamp image
startwaveShortest wavelength in image.
dispersionWavelength units per image pixel
saturationSaturation value
linesLine catalog
Returns
Spectral resolution table

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.

Definition at line 14401 of file moses.c.

References mos_spectral_resolution().

Referenced by vimos_calib_impl().

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.

Parameters
imageCCD exposure
wavemapWavelengths map of CCD exposure
ystartStart Y-pixel coordinate on CCD
yendEnd Y-pixel coordinate on CCD
wstartStart wavelength
wendEnd wavelength
Returns
Integrated signal

This function sum the signal in the specified interval. ystart is inclusive and wend exclusive.

Definition at line 14473 of file moses.c.

cpl_table* mos_load_slits_fors_mxu ( cpl_propertylist *  header)

Create slit location table from FITS header of FORS2-MXU data.

Parameters
headerFITS header of FORS data containing slits information
Returns
A slit position table

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.

Definition at line 14561 of file moses.c.

cpl_table* mos_load_slits_fors_mos ( cpl_propertylist *  header,
int *  nslits_out_det 
)

Create slit location table from FITS header of FORS1/2 MOS data.

Parameters
headerFITS header of FORS data containing slits information
nslits_out_detNumber of slits which don't lie in the detector
Returns
A slit position table

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.

Definition at line 14801 of file moses.c.

Referenced by mos_load_slits_fors_pmos().

cpl_table* mos_load_slits_fors_lss ( cpl_propertylist *  header)

Create slit location table from FITS header of FORS1/2 LSS data.

Parameters
headerFITS header of FORS data containing slits information
Returns
A slit position table

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.

Definition at line 15003 of file moses.c.

double mos_get_gain_vimos ( cpl_propertylist *  header)

Return gain factor for a VIMOS exposure.

Parameters
headerFITS header of VIMOS data containing information
Returns
Gain factor (e-/ADU)

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.

Definition at line 15171 of file moses.c.

cpl_table* mos_load_slits_vimos ( cpl_propertylist *  header)

Create slit location table from FITS header of VIMOS data.

Parameters
headerFITS header of VIMOS data containing slits information
Returns
A slit position table

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.

Definition at line 15216 of file moses.c.

Referenced by vimos_calib_impl().

int mos_check_multiplex ( cpl_table *  slits)

Determining whether a VIMOS mask has spectral multplexing or not.

Parameters
slitsSlit positions produced by mos_load_slits_vimos()
Returns
Max observed spectral multiplexing.

Definition at line 15327 of file moses.c.

cpl_table* mos_load_overscans_vimos ( const cpl_propertylist *  header,
int  check_consistency 
)

Get the overscan positions from FITS header of VIMOS data.

Parameters
headerFITS header containing overscan information
check_consistencyIf 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)
Returns
A overscan position table

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).

Definition at line 15426 of file moses.c.

Referenced by vimos_calib_impl().

cpl_error_code mos_randomise_image ( cpl_image *  image,
double  ron,
double  gain,
double  bias 
)

Randomise image.

Parameters
imageImage to randomise (in place)
ronRead out noise (ADU)
gainGain (electrons/ADU)
biasBias level (ADU)
Returns
CPL_ERROR_NONE or corresponding cpl_error_code on error.

For each pixel the 1-sigma error is evaluated as the square root of the variance:

V = ron*ron + (S - bias) / gain

where S is the pixel value. The pixel value is randomised as

S = S + sqrt(V) * mos_randg(1)

Definition at line 15877 of file moses.c.

cpl_error_code mos_refmask_find_gaps ( cpl_mask *  refmask,
cpl_image *  master_flat,
double  level 
)

Reconstruct the gaps required for slit location.

Parameters
refmaskReference mask
master_flatMasterflat. The gaps are detected and inserted based upon the values found in this image.
Returns
CPL_ERROR_NONE of corresponding cpl_error_code on error.

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.

Definition at line 15921 of file moses.c.

Referenced by vimos_calib_impl().

cpl_error_code mos_saturation_process ( cpl_image *  image)

Process saturation.

Parameters
imageImage to process saturation
Returns
CPL_ERROR_NONE of corresponding cpl_error_code on error.

Definition at line 16013 of file moses.c.

Referenced by vimos_calib_impl().

cpl_error_code mos_subtract_background ( cpl_image *  image)

Subtract the background.

Parameters
imageImage to subtract the background
Returns
CPL_ERROR_NONE of corresponding cpl_error_code on error.

Definition at line 16079 of file moses.c.

References mos_arc_background().

Referenced by vimos_calib_impl().

cpl_error_code mos_object_intersect ( cpl_table **  slitss,
cpl_table *  origslits,
int  nscience,
float  tolerance 
)

Intersect a number of slit tables.

Parameters
slitssPointer to the list of slit tables
origslitsPointer to output intersected table
nscienceNumber of tables in the list
toleranceTolerance in object position (pixel)
Returns
CPL_ERROR_NONE of corresponding cpl_error_code on error.

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 at all angles so polarimetric computation is possible)

Definition at line 16109 of file moses.c.

References mos_get_maxobjs_per_slit(), and mos_get_nobjects().

int mos_get_maxobjs_per_slit ( cpl_table *  slits)

Get the maximum possible number of objects in a slit.

Parameters
slitsSlits table
Returns
maximum possible number of objects in a slit

Definition at line 16704 of file moses.c.

Referenced by mos_get_nobjects(), and mos_object_intersect().

int mos_get_nobjects ( cpl_table *  slits)

Get the total number of objects detected in a slits table.

Parameters
slitsSlits table
Returns
the number of objects in the table

Definition at line 16730 of file moses.c.

References mos_get_maxobjs_per_slit().

Referenced by mos_object_intersect().

int mos_check_slits ( cpl_table *  slits,
float  rescale 
)

Check that all slit have been detected, insert them if not.

Parameters
slitsSlits table
Returns
0 or -1 on error.

Definition at line 16761 of file moses.c.

cpl_table* mos_load_slits_fors_pmos ( cpl_propertylist *  header,
int *  nslits_out_det 
)

Create PMOS slit location table from FITS header of FORS1/2 MOS data.

Parameters
headerFITS header of FORS data containing slits information
Returns
A slit position table

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.

Definition at line 16864 of file moses.c.

References mos_load_slits_fors_mos().

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.

Parameters
spectraImage with extracted spectra
startwaveShortest wavelength in input image (Angstrom)
dispersionAngstrom per pixel of input image
gainGain factor (e-/ADU)
exptimeExposure time (seconds)
ext_tableAtmospheric extinction table
airmassAirmass of observation
flux_tableStandard star catalog flux
orderOrder of polynomial to model the instrument response
Returns
A slit position table

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.

Definition at line 17204 of file moses.c.

cpl_image* mos_ksigma_stack ( cpl_imagelist *  imlist,
double  klow,
double  khigh,
int  kiter,
cpl_image **  good 
)

Stack images using k-sigma clipping.

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

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

Definition at line 17681 of file moses.c.

Referenced by fors_image_collapse_ksigma_create().

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.

Parameters
spectraImage containing extracted spectra (slits or objects)
responseTable including the response curve
ext_tableAtmospheric extinction table
startwaveStart wavelength
dispersionAngstrom per pixel of input image
gainGain factor (e-/ADU)
exptimeExposure time (seconds)
airmassAirmass of observation
Returns
Photometrically calibrated image at airmass 0.

Definition at line 17756 of file moses.c.

Referenced by mos_propagate_photometry_error().

cpl_image* mos_propagate_photometry_error ( cpl_image *  spectra,
cpl_image *  errors,
cpl_table *  response,
cpl_table *  ext_table,
double  startwave,
double  dispersion,
double  gain,
double  exptime,
double  airmass 
)

Propagate errors from response curve and extracted spectra.

Parameters
errorsImage containing errors on extracted spectra (objects)
responseTable including the response curve errors
ext_tableAtmospheric extinction table
startwaveStart wavelength
dispersionAngstrom per pixel of input image
gainGain factor (e-/ADU)
exptimeExposure time (seconds)
airmassAirmass of observation
Returns
Error on photometrically calibrated spectrum at airmass 0.

Definition at line 17849 of file moses.c.

References mos_apply_photometry().

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.

Parameters
q_imageImage whose rows correspond to extracted spectra
q_errorImage with errors of q_image
u_imageImage whose rows correspond to extracted spectra
u_errorImage with errors of u_image
startwaveStart wavelength
dispersionAngstrom per pixel of input image
bandWidth of band where the signal is averaged (Angstrom)
pol_staTable with polarimetric standard stars parameters
raRight Ascension of center of field of view (degrees)
decDeclination of center of field of view (degrees)
filterReturned filter (UBVRI) to which the measurement refers
polarisationReturned polarisation flag (0 = star is not polarised)
p_offsetReturned relative variation of P in filter
p_errorReturned error on p_offset
a_offsetReturned variation of angle in filter (degrees)
a_errorReturned error on a_offset (degrees)
Returns
0 on success.

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.

Definition at line 18027 of file moses.c.

int mos_compute_offset ( cpl_table *  reference,
cpl_table *  objects,
double *  offset 
)

Estimate offset between two object tables.

Parameters
referenceReference object table.
objectsObject table from offset frame.
offsetReturned offset in CCD pixels.
Returns
CPL_ERROR_NONE in case of success.

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

CCD_offset = Map_offset * (t - b) / length

in the same convention used in function mos_spatial_calibration(). The returned offset is the median offset obtained from all slits.

Definition at line 18385 of file moses.c.

References fors_tools_get_kth_double().

cpl_error_code mos_image_shift ( cpl_image *  image,
double  dx,
double  dy 
)

Shift values in an image.

Parameters
imageInput image
dxShift in x
dyShift in y
Returns
CPL_ERROR_NONE on success.

Definition at line 18585 of file moses.c.

int mos_slit_closest_to_center ( cpl_table *  slits,
int  nx,
int  ny 
)

Return slit closest to CCD center.

Parameters
slitsSlit table
nxX size of CCD
nyY size of CCD
Returns
Table row with the slit closest to center.

Definition at line 18646 of file moses.c.

Referenced by mos_extract_flux(), mos_extract_flux_mapped(), and vimos_calib_impl().

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.

Parameters
imageImage containing raw spectra.
slitsTable with slits properties.
dxPixels to extract along the dispersion direction (radius).
gainIn electrons/ADU, used for error computation.
o_fluxReturned integrated flux, in ADU/mm^2
o_errReturned error on integrated flux.
Returns
Status

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.

Definition at line 18694 of file moses.c.

References mos_slit_closest_to_center().

Referenced by vimos_calib_impl().

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.

Parameters
imageImage containing remapped spectra.
slitsTable with slits properties.
lambdaWavelength to examine
startwaveShortest wavelength in image.
dispersionWavelength units per image pixel
dxPixels to extract along the dispersion direction (radius).
gainIn electrons/ADU, used for error computation.
o_fluxReturned integrated flux, in ADU/mm^2
o_errReturned error on integrated flux.
Returns
Status

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.

Definition at line 18811 of file moses.c.

References mos_slit_closest_to_center().

Referenced by vimos_calib_impl().

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.

Parameters
tableTable with as many rows as rectified images
slitsTable with slits properties.
slitRow in slits corresponding to slit to examine
labelName of column to examine
mvalueReturned median value
Returns
0 in case of success.

Definition at line 18921 of file moses.c.

Referenced by vimos_calib_impl().

cpl_image* mos_image_filter_median ( cpl_image *  image,
int  nx,
int  ny 
)

Convenience function for standard median filtering.

Parameters
imageImage to smooth
nxFilter size in x.
nyFilter size in y.
Returns
Filtered image

Definition at line 18949 of file moses.c.

Referenced by mos_arc_background().