Defines | |
#define | SEGNO(a, b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) |
#define | READY 1 |
Montecarlo simulation to evaluate error on polynomial fit. | |
#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, int 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. | |
cpl_table * | mos_build_slit_location (cpl_table *global, cpl_table *maskslits, int ysize) |
Build the slit location table from a global distortions table. | |
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. | |
cpl_table * | mos_build_disp_coeff (cpl_table *global, cpl_table *slits) |
Build the IDS coefficients table from a global distortions table. | |
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. | |
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. | |
cpl_image * | mos_normalise_longflat (cpl_image *flat, int sradius, int dradius, int polyorder) |
Normalise a long slit flat field exposure. | |
cpl_error_code | mos_interpolate_wavecalib_slit (cpl_table *idscoeff, cpl_table *slits, int order, int global) |
Interpolate MOS wavelength calibration. | |
cpl_error_code | mos_interpolate_wavecalib (cpl_table *idscoeff, cpl_image *wavemap, int mode, int degree) |
Interpolate LSS wavelength calibration. | |
cpl_image * | mos_remove_bias (cpl_image *image, cpl_image *bias, cpl_table *overscans) |
Subtract the bias from a CCD exposure. | |
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). | |
cpl_image * | mos_arc_background (cpl_image *image, int msize, int fsize) |
Background determination on emission line spectrum (arc). | |
int | mos_lines_width (const float *spectrum, int length) |
Estimate lines widths (in pixel) in arc lamp spectrum. | |
cpl_vector * | mos_peak_candidates (const float *spectrum, int length, float level, float exp_width) |
Find positions of peaks candidates. | |
cpl_vector * | mos_refine_peaks (const float *spectrum, int length, cpl_vector *peaks, int sradius) |
Improve (when possible) accuracy of peaks candidates positions. | |
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. | |
double | mos_eval_dds (cpl_polynomial *ids, double blue, double red, double refwave, double pixel) |
Evaluate the wavelength of a pixel position. | |
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. | |
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. | |
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. | |
cpl_image * | mos_wavelength_calibration_raw (const cpl_image *image, cpl_vector *lines, double dispersion, float level, int sradius, int order, double reject, double refwave, double *wavestart, double *waveend, int *nlines, double *error, cpl_table *idscoeff, cpl_image *calibration, cpl_image *residuals, cpl_table *restable, cpl_mask *refmask) |
Derive wavelength calibration from a raw arc lamp or sky exposure. | |
cpl_table * | mos_locate_spectra (cpl_mask *mask) |
Find the location of detected spectra on the CCD Find the location of detected spectra on the CCD. | |
cpl_error_code | mos_validate_slits (cpl_table *slits) |
Check validity of a slit location table. | |
cpl_error_code | mos_rotate_slits (cpl_table *slits, int rotation, int nx, int ny) |
Rotate a slit location table. | |
cpl_table * | mos_identify_slits (cpl_table *slits, cpl_table *maskslits, cpl_table *global) |
Identify slits listed in a slit location table. | |
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. | |
cpl_table * | mos_poly_trace (cpl_table *slits, cpl_table *traces, int order) |
Fit spectral traces. | |
cpl_error_code | mos_global_trace (cpl_table *slits, cpl_table *polytraces, int mode) |
Recompute tracing coefficients globally. | |
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. | |
cpl_image * | mos_wavelength_calibration_final (cpl_image *image, cpl_table *slits, cpl_vector *lines, double dispersion, float level, int sradius, int order, double reject, double refwave, double *wavestart, double *waveend, int *nlines, double *error, cpl_table *idscoeff, cpl_image *calibration, cpl_image *residuals, cpl_table *restable) |
Derive wavelength calibration from a rectified arc lamp or sky exposure. | |
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. | |
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. | |
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). | |
double | mos_distortions_rms (cpl_image *rectified, cpl_vector *lines, double wavestart, double dispersion, int radius, int highres) |
Estimate the spectral distortion modeling goodness. | |
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. | |
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. | |
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. | |
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. | |
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. | |
cpl_table * | mos_sky_map (cpl_image *spectra, cpl_image *wavemap, double dispersion, cpl_image *skymap) |
Create a CCD median sky map. | |
cpl_image * | mos_sky_local_old (cpl_image *spectra, cpl_table *slits) |
Local determination of sky. | |
cpl_image * | mos_sky_local (cpl_image *spectra, cpl_table *slits, int order) |
Local determination of sky. | |
cpl_error_code | mos_clean_cosmics (cpl_image *image, float gain, float threshold, float ratio) |
Remove cosmic rays from sky-subtracted CCD spectral exposure. | |
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. | |
cpl_image * | mos_detect_objects (cpl_image *image, cpl_table *slits, int margin, int maxradius, int conradius) |
Detect objects in rectified scientific frame. | |
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. | |
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. | |
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. | |
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. | |
cpl_table * | mos_load_slits_fors_mxu (cpl_propertylist *header) |
Create slit location table from FITS header of FORS2-MXU data. | |
cpl_table * | mos_load_slits_fors_mos (cpl_propertylist *header) |
Create slit location table from FITS header of FORS1/2 MOS data. | |
cpl_table * | mos_load_slits_fors_lss (cpl_propertylist *header) |
Create slit location table from FITS header of FORS1/2 LSS data. | |
double | mos_get_gain_vimos (cpl_propertylist *header) |
Return gain factor for a VIMOS exposure. | |
cpl_table * | mos_load_slits_vimos (cpl_propertylist *header) |
Create slit location table from FITS header of VIMOS data. | |
int | mos_check_multiplex (cpl_table *slits) |
Determining whether a VIMOS mask has spectral multplexing or not. | |
cpl_table * | mos_load_overscans_vimos (const cpl_propertylist *header, int check_consistency) |
Get the overscan positions from FITS header of VIMOS data. | |
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. | |
cpl_error_code | mos_refmask_find_gaps (cpl_mask *refmask, cpl_image *master_flat, double level) |
Reconstruct the gaps required for slit location. | |
cpl_error_code | mos_saturation_process (cpl_image *image) |
Process saturation. | |
cpl_error_code | mos_subtract_background (cpl_image *image) |
Subtract the background. | |
cpl_error_code | mos_object_intersect (cpl_table **slitss, cpl_table *origslits, int nscience, float tolerance) |
Intersect a number of slit tables. | |
int | mos_get_maxobjs_per_slit (cpl_table *slits) |
Get the maximum possible number of objects in a slit. | |
int | mos_get_nobjects (cpl_table *slits) |
Get the total number of objects detected in a slits table. | |
int | mos_check_slits (cpl_table *slits, float rescale) |
Check that all slit have been detected, insert them if not. | |
cpl_table * | mos_load_slits_fors_pmos (cpl_propertylist *header) |
Create PMOS slit location table from FITS header of FORS1/2 MOS data. | |
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. | |
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. | |
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. | |
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. | |
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. | |
int | mos_compute_offset (cpl_table *reference, cpl_table *objects, double *offset) |
Estimate offset between two object tables. | |
cpl_error_code | mos_image_shift (cpl_image *image, double dx, double dy) |
Shift values in an image. | |
int | mos_slit_closest_to_center (cpl_table *slits, int nx, int ny) |
Return slit closest to CCD center. | |
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. | |
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. | |
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. | |
cpl_image * | mos_image_filter_median (cpl_image *image, int nx, int ny) |
Convenience function for standard median filtering. |
#define READY 1 |
Montecarlo simulation to evaluate error on polynomial fit.
points | Table with (x,y) coordinates and uncertainties on y. | |
evaluate | Table with x coordinates where to evaluate model variance. | |
samples | Number of simulations. | |
order | Degree of the fitted polynomial. |
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.
#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)
cpl_table* mos_global_distortion | ( | cpl_table * | slits, | |
cpl_table * | maskslits, | |||
cpl_table * | ids, | |||
cpl_table * | crv, | |||
double | reference | |||
) |
Determine all global distortions models.
slits | Table with slits positions on CCD | |
maskslits | Table with slits positions on mask | |
ids | IDS coefficients table | |
crv | Spectral curvature coefficients table | |
reference | Reference wavelength |
The 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 1175 of file moses.c.
References write_global_distortion().
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.
global | Global distortions table | |
maskslits | Table with slits positions on mask | |
ysize | Y size of the CCD |
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
Definition at line 1539 of file moses.c.
References read_global_distortion().
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.
global | Global distortions table | |
maskslits | Table with slits positions on mask | |
slits | Table with slits positions on CCD |
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)
Definition at line 1685 of file moses.c.
References read_global_distortion().
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.
global | Global distortions table | |
slits | Table with slits positions on CCD |
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)
Definition at line 1840 of file moses.c.
References read_global_distortion().
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.
science | Image containing the CCD scientific spectra | |
slits | Table with slits positions | |
polytraces | Coefficients of spectral curvature polynomials | |
reference | Reference wavelength | |
blue | Start lambda to process | |
red | End lambda to process | |
dispersion | Mean spectral dispersion |
Definition at line 1964 of file moses.c.
References robustLinearFit().
Referenced by vimos_science_impl().
cpl_image* mos_normalise_flat | ( | cpl_image * | flat, | |
cpl_image * | spatial, | |||
cpl_table * | slits, | |||
cpl_table * | polytraces, | |||
double | reference, | |||
double | blue, | |||
double | red, | |||
double | dispersion, | |||
int | sradius, | |||
int | polyorder | |||
) |
Normalise a flat field exposure.
flat | Image containing the original flat field spectra | |
spatial | Spatial calibration image | |
slits | Table with slits positions | |
polytraces | Coefficients of spectral curvature polynomials | |
reference | Reference wavelength | |
blue | Start lambda to process | |
red | End lambda to process | |
dispersion | Mean spectral dispersion | |
sradius | Radius of smoothing box along the dispersion direction | |
polyorder | Order of fitting polynomial along the dispersion |
Definition at line 2284 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.
flat | Image containing the original flat field spectra | |
sradius | Radius of smoothing box along the spatial direction | |
dradius | Radius of smoothing box along the dispersion direction | |
polyorder | Order of fitting polynomial along the spatial direction |
cpl_error_code mos_interpolate_wavecalib_slit | ( | cpl_table * | idscoeff, | |
cpl_table * | slits, | |||
int | order, | |||
int | global | |||
) |
Interpolate MOS wavelength calibration.
idscoeff | Table with IDS polynomials | |
slits | Table with slits positions | |
order | 0 = median, > 0 order of fitting polynomial. |
CPL_ERROR_NONE
on success.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 2925 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.
idscoeff | Table with IDS polynomials | |
wavemap | Wavelength calibration image | |
mode | 0 = do nothing, 1 = fill gaps, 2 = global model | |
degree | 0 = median, > 0 order of fitting polynomial. |
CPL_ERROR_NONE
on success.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 3054 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.
image | Image containing the data to correct | |
bias | Master bias | |
overscans | Table with the overscan information |
Definition at line 3411 of file moses.c.
Referenced by vimos_calib_impl(), and vimos_science_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).
spectrum | A 1D emission line spectrum | |
back | A pre-allocated buffer where the background will be written | |
length | Length of spectrum | |
msize | Size of min-filter | |
fsize | Size of running-average-filter |
CPL_ERROR_NULL_INPUT | The input spectrum is a NULL pointer. |
CPL_ERROR_ILLEGAL_INPUT | Either msize is less than 3, or fsize is less than msize, or fsize is greater than length/2. |
This function fills the array back with the estimated values of the background along the input spectrum. The algorithm is based on the assumption that there is at least one background value at any position of the min-filter box running along the spectrum. A min-filter is passed on the spectrum, and the result is smoothed by averaging on a running box of size fsize. The min-filter is run between the positions msize / 2 and length - msize / 2, and the min value found at such positions is then repeated up to the spectrum ends. Similarly, the running average is limited to the interval from fsize / 2 and length - fsize / 2, leaving the most external values untouched. After this, a max filter and a smoothing using boxes with double the specified sizes are run, as a way to eliminate the contamination from occasional cold pixels. Finally, the min filter and the smoothing are applied again to obviate the slight background over-estimation introduced by the max filter.
It is required that the back array is at least long as the array spectrum. Moreover msize must be greater than 1, and fsize greater than, or equal to, msize. Likewise, length must be greater than twice fsize. If such conditions are not met, or if the input arrays are NULL
pointers, this function will set an error code, and leave the back array untouched. If either msize or fsize are even numbers, they are made odd by adding 1. Suggested values for msize and fsize are 15 pixels for typical arc lamp spectra.
Definition at line 3583 of file moses.c.
References max_filter(), min_filter(), and smo_filter().
Referenced by mos_arc_background().
cpl_image* mos_arc_background | ( | cpl_image * | image, | |
int | msize, | |||
int | fsize | |||
) |
Background determination on emission line spectrum (arc).
image | An emission line spectrum exposure | |
msize | Size of min-filter | |
fsize | Size of running-average-filter |
CPL_ERROR_NULL_INPUT | The input image is a NULL pointer. |
CPL_ERROR_ILLEGAL_INPUT | Either msize is less than 3, or fsize is less than msize, or fsize is greater than half the input image size in the X direction. |
The input image is assumed to be of type float
and to contain MOS arc lamp line spectra dispersed (roughly) along the X direction. The background is estimated independently for each image row. The algorithm is based on the assumption that there is at least one background value at any position of the 1D-min-filter box running along the image row. A min-filter is passed along the row, and the result is smoothed by averaging on a running box of size fsize. The min-filter is run between the positions msize / 2 and length - msize / 2, and the min value found at such positions is then repeated up to the spectrum ends. Similarly, the running average is limited to the interval from fsize / 2 and length - fsize / 2, leaving the most external values untouched. After this, a max filter and a smoothing using boxes with double the specified sizes are run, as a way to eliminate the contamination from occasional cold pixels. Finally, the min filter and the smoothing are applied again to obviate the slight background over-estimation introduced by the max filter.
It is required that msize is greater than 1, and fsize greater than, or equal to, msize. Likewise, the image size along the X direction must be greater than fsize / 2. If such conditions are not met, or if the input image is a NULL
pointer, this function will set an error code and return a NULL
pointer. If either msize or fsize are even numbers, they are made odd by adding 1. Suggested values for msize and fsize are 15 pixels for typical arc lamp spectra.
Definition at line 3685 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.
spectrum | A 1D emission line spectrum | |
length | Length of spectrum |
Definition at line 3758 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.
spectrum | A 1D emission line spectrum | |
length | Length of spectrum | |
level | Significance level | |
exp_width | Expected lines FWHM (in pixels) |
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 3861 of file moses.c.
References values_to_dx().
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.
spectrum | A 1D emission line spectrum | |
length | Length of spectrum | |
peaks | List of peaks candidates | |
sradius | Search radius for expected peaks |
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 3964 of file moses.c.
References peakPosition().
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.
peaks | List of peaks candidates | |
lines | List of wavelengths | |
min_disp | Min expected spectral dispersion (Angstrom/pixel) | |
max_disp | Max expected spectral dispersion (Angstrom/pixel) | |
tolerance | Tolerance for interval ratio comparison |
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 4073 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.
ids | Inverse dispersion relation (from wave to pixel) | |
blue | Start wavelength of ids validity | |
red | End wavelength of ids validity | |
refwave | Reference wavelength | |
pixel | Pixel position |
Definition at line 4762 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.
pixwav | List of pixel positions and associated wavelengths | |
order | Order of the fitting polynomial | |
reject | Max residual tolerated for line rejection (in pixel) | |
minlines | Min number of lines to be used in the fit | |
nlines | Output number of lines actually used in the fit | |
err | Output RMS of the fit residuals |
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 4817 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.
pixwav | List of pixel positions and associated wavelengths | |
order | Order of the fitting polynomial | |
reject | Max residual tolerated for line rejection (in wave units) | |
minlines | Min number of lines to be used in the fit | |
nlines | Output number of lines actually used in the fit | |
err | Output RMS of the fit residuals |
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 4977 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.
spectrum | A 1D emission line spectrum | |
length | Length of spectrum | |
lines | List of wavelengths | |
ids | Polynomial conversion from wavelengths to pixel | |
refwave | Zero wavelength used in ids determination | |
sradius | Search radius for expected peaks |
NULL
pointer is returned.
Definition at line 5029 of file moses.c.
References peakPosition().
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 | |||
) |
Derive wavelength calibration from a raw arc lamp or sky exposure.
image | An arc lamp or sky exposure | |
lines | List of reference lines wavelengths | |
dispersion | Expected value of the dispersion (wavelength units/pixel) | |
level | Threshold for peak detection | |
sradius | Search radius for expected peaks (pixels) | |
order | Degree of fitting polynomial for wavelength calibration | |
reject | Max residual tolerated for line rejection (pixels) | |
refwave | Reference wavelength | |
wavestart | I/O wavelength of first pixel of resampled image | |
waveend | I/O wavelength of last pixel of resampled image | |
nlines | Returned array of number of lines used for each fit | |
error | Returned array of mean accuracies obtained for each fit | |
idscoeff | Returned table with IDS polynomials | |
calibration | Returned wavelength calibration image | |
residuals | Returned residuals image | |
restable | Returned residuals table | |
refmask | Returned monochromatic image at reference wavelength |
The 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 / (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.
Definition at line 5203 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 Find the location of detected spectra on the CCD.
mask | A reference mask at a given reference wavelength |
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 5807 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.
slits | Slit location table to validate |
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 5895 of file moses.c.
Referenced by mos_identify_slits(), mos_identify_slits_fast(), and mos_rotate_slits().
cpl_error_code mos_rotate_slits | ( | cpl_table * | slits, | |
int | rotation, | |||
int | nx, | |||
int | ny | |||
) |
Rotate a slit location table.
slits | Slit location table to rotate | |
rotation | Rotation angle in multiples of 90 degrees (counterclockwise) | |
nx | X size of reference image | |
ny | Y size of reference image |
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 5959 of file moses.c.
References mos_validate_slits().
Referenced by mos_trace_flat(), vimos_calib_impl(), and vimos_science_impl().
cpl_table* mos_identify_slits | ( | cpl_table * | slits, | |
cpl_table * | maskslits, | |||
cpl_table * | global | |||
) |
Identify slits listed in a slit location table.
slits | Slit location on the camera focal plane (CCD pixels). | |
maskslits | Slit location on the telescope focal plane (mask). | |
global | Global distortion table. |
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 6073 of file moses.c.
References mos_identify_slits_fast(), mos_validate_slits(), and write_global_distortion().
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.
flat | Flat field image | |
slits | Slits positions on the CCD | |
reference | Reference wavelength | |
blue | Start lambda for tracing | |
red | End lambda for tracing | |
dispersion | Mean spectral dispersion |
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 7360 of file moses.c.
References mos_image_vertical_median_filter(), 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.
slits | Slits positions on the CCD | |
traces | Spectral traces | |
order | Order of fitting polynomial |
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 7794 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.
slits | Slits positions on the CCD | |
polytraces | Coefficients of spectral curvature polynomials | |
mode | 0 = do nothing, 1 = fill gaps, 2 = global model |
CPL_ERROR_NONE
on successmos_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 7954 of file moses.c.
References robustLinearFit().
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.
spectra | CCD image of spectra | |
slits | Slits positions on the CCD | |
polytraces | Coefficients of spectral curvature polynomials | |
reference | Reference wavelength | |
blue | Start lambda for spatial remapping | |
red | End lambda for spatial remapping | |
dispersion | Mean spectral dispersion | |
flux | If zero, flux conservation is not applied | |
calibration | Returned spatial calibration image |
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 8135 of file moses.c.
Referenced by mos_normalise_flat(), vimos_calib_impl(), and vimos_science_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 | |||
) |
Derive wavelength calibration from a rectified arc lamp or sky exposure.
image | A rectified arc lamp or sky exposure | |
slits | Slits positions table | |
lines | List of reference lines wavelengths | |
dispersion | Expected value of the dispersion (wavelength units/pixel) | |
level | Threshold for peak detection | |
sradius | Search radius for expected peaks (pixels) | |
order | Degree of fitting polynomial for wavelength calibration | |
reject | Max residual tolerated for line rejection (pixels) | |
refwave | Reference wavelength | |
wavestart | I/O wavelength of first pixel of resampled image | |
waveend | I/O wavelength of last pixel of resampled image | |
nlines | Returned array of number of lines used for each fit | |
error | Returned array of mean accuracies obtained for each fit | |
idscoeff | Returned table with IDS polynomials | |
calibration | Returned wavelength calibration image | |
residuals | Returned residuals image | |
restable | Returned residuals table |
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 / (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.
Definition at line 8533 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.
image | Image with rectified scientific spectra | |
refwave | Reference wavelength | |
firstLambda | Wavelength of first pixel of resampled image | |
lastLambda | Wavelength of last pixel of resampled image | |
dispersion | Resampling step (wavelength units/pixel) | |
idscoeff | Table with IDS polynomials | |
flux | If zero, flux conservation correction is not applied. |
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 9174 of file moses.c.
Referenced by vimos_calib_impl(), and vimos_science_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.
image | Image with rectified scientific spectra | |
slits | Slits positions table | |
refwave | Reference wavelength | |
firstLambda | Wavelength range start | |
lastLambda | Wavelength range end | |
idscoeff | Table with IDS polynomials | |
skylines | Vector with wavelengths of reference skylines | |
highres | 1 = high resolution data, 0 = low resolution data | |
order | Order of sky lines offsets fitting polynomial | |
calibration | Rectified wavelength calibration image | |
sradius | Search radius for sky lines |
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 9454 of file moses.c.
References peakPosition(), and robustLinearFit().
Referenced by vimos_science_impl().
cpl_table* mos_wavelength_align_lss | ( | cpl_image * | image, | |
double | refwave, | |||
double | firstLambda, | |||
double | lastLambda, | |||
cpl_table * | idscoeff, | |||
cpl_vector * | skylines, | |||
int | highres, | |||
int | order, | |||
cpl_image * | calibration, | |||
int | sradius | |||
) |
Modify the input wavelength solution to match reference sky lines (LSS).
image | Image with rectified scientific spectra | |
refwave | Reference wavelength | |
firstLambda | Wavelength range start | |
lastLambda | Wavelength range end | |
idscoeff | Table with IDS polynomials | |
skylines | Vector with wavelengths of reference skylines | |
highres | 1 = High resolution, 0 = Low resolution | |
order | Order of sky lines offsets fitting polynomial | |
calibration | Rectified wavelength calibration image | |
sradius | Search radius for sky lines |
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 10006 of file moses.c.
References peakPosition(), and robustLinearFit().
Referenced by vimos_science_impl().
double mos_distortions_rms | ( | cpl_image * | rectified, | |
cpl_vector * | lines, | |||
double | wavestart, | |||
double | dispersion, | |||
int | radius, | |||
int | highres | |||
) |
Estimate the spectral distortion modeling goodness.
rectified | Calibrated calibration image | |
lines | Reference wavelengths (line catalog) | |
wavestart | Wavelength of bluest (left) pixel in input image | |
dispersion | Angstrom per pixel of input image | |
radius | Search radius (in pixels of input image) | |
highres | 1 = high resolution data, 0 = low resolution data |
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 10513 of file moses.c.
References peakPosition().
Referenced by vimos_calib_impl(), and vimos_science_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.
idscoeff | Table with IDS polynomials | |
reference | Reference wavelength | |
blue | Start lambda for spatial remapping | |
red | End lambda for spatial remapping | |
dispersion | Mean spectral dispersion | |
trend | Trend to remove from IDS polynomials |
Definition at line 10650 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.
idscoeff | Table with IDS polynomials | |
xsize | X size of used CCD | |
reference | Reference wavelength | |
blue | Start lambda for spatial remapping | |
red | End lambda for spatial remapping |
Definition at line 10734 of file moses.c.
References mos_eval_dds().
Referenced by vimos_calib_impl(), and vimos_science_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.
spatial | CCD image of spatial coordinates | |
calibration | Spatially rectified image of wavelengths | |
slits | Slits positions on the CCD | |
polytraces | Coefficients of spectral curvature polynomials | |
reference | Reference wavelength | |
blue | Start lambda for spatial remapping | |
red | End lambda for spatial remapping | |
dispersion | Mean spectral dispersion |
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 10844 of file moses.c.
Referenced by vimos_calib_impl(), and vimos_science_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.
spectra | CCD image containing the observed slit spectra | |
wavecalib | CCD image of wavelengths | |
spatial | CCD image of spatial coordinates | |
slits | Slits positions on the CCD | |
polytraces | Coefficients of spectral curvature polynomials | |
reference | Reference wavelength | |
blue | Start lambda for remapping | |
red | End lambda for remapping | |
dispersion | Mean spectral dispersion | |
flux | flux = 0 means no flux conservation correction applied |
The input wavecalib image is the one returned by the function mos_map_wavelengths()
or, if this is not available, the approximate one returned by the function mos_wavelength_calibration_raw(). The input spatial image is the one produced by the function mos_spatial_calibration()
(argument: calibration). Both images are expected to be oriented with horizontal dispersion direction and red wavelengths on the right side, and they should have the same sizes of the input spectra image. The slits table should be the same processed by the function mos_spatial_calibration()
. The polytraces table is the output of the function mos_poly_trace()
. If flux is different from 0, the factors to be applied for flux conservation are calculated and applied to the remapped image. The other arguments should be in principle the same specified for the function mos_spatial_calibration()
, even if it would be conceivable (and perhaps even reasonable) to specify shorter spectral ranges, and/or a smaller value of the dispersion (A/pixel) for supersampling the signal.
The target grid in lambda and pseudo spatial coordinates is defined on the basis of the indicated spectral range and dispersion, while the number of spatial pixels assigned to each slits are compatible with the positions listed in the slits table (column "position") following the convention used in the rest of the spectral reduction, in particular the functions mos_spatial_calibration() and mos_map_wavelengths()
.
Indicating with (x,y) a pixel position on the CCD, and with (L,S) a pixel position on one extracted slit, the mapping from (x,y) to (L,S) is done in the following way (for each slit): for each (x,y) read the corresponding value of lambda and space from the input images wavecalib and spatial; find the pixel (L,S) on the output (remapped) slit that has the highest lambda and space that are less than the lambda and space obtained above; read the values of the following CCD pixels from the input spectrum: (x,y), (x-1,y), (x+N,y+1), (x+N-1,y+1), where N is an offset pointing to the pixel on the row y+1 having the closest wavelength to the wavelength of pixel (x,y). This is a way to avoid possible discontinuities in the wavelength calibration along the cross-dispersion direction (due to slit irregularities, also commonly indicated with the expression "slit geometry"). Typically, it will always be N = 0.
The pixel value to assign to the pixel (L,S) is computed by linear interpolation to its corresponding (x',y') position of the 4 pixel values (horizontal interpolation followed by vertical interpolation of the interpolated values). The corresponding flux-conservation factor, if requested, is computed as (dL/dx)*(dS/dy). The interpolated value is multiplied by this factor before being written to the pixel (L,S).
DO NOT USE THIS FUNCTION, IT GIVES BAD RESULTS (and it should be eventually removed).
cpl_table* mos_sky_map_super | ( | cpl_image * | spectra, | |
cpl_image * | wavemap, | |||
double | dispersion, | |||
double | factor, | |||
int | minpoints, | |||
cpl_image * | skymap | |||
) |
Create a CCD median sky map.
spectra | CCD image of spectra | |
wavemap | CCD image of wavelengths | |
dispersion | Mean spectral dispersion | |
factor | Supersampling factor | |
minpoints | Minimum points required per supersampled spectrum bin | |
skymap | Returned CCD image of sky |
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 11604 of file moses.c.
Referenced by vimos_science_impl().
cpl_table* mos_sky_map | ( | cpl_image * | spectra, | |
cpl_image * | wavemap, | |||
double | dispersion, | |||
cpl_image * | skymap | |||
) |
Create a CCD median sky map.
spectra | CCD image of spectra | |
wavemap | CCD image of wavelengths | |
dispersion | Mean spectral dispersion | |
skymap | Returned CCD image of sky |
mos_wavelength_calibration_final()
, possibly modified by the function mos_wavelength_align()
used to align the wavelength solution to available sky lines. The computed sky spectrum will consist of pixels of size dispersion: typically the passed dispersion should be slightly smaller than the dispersion of the original spectra. How much smaller will affect the level of supersampling of the computed sky spectrum: a too small value will increase the noise of the output sky spectrum, leading to no advantage in the determination of the sky map to be subtracted from the scientific data. Each pixel of the resulting sky spectrum is computed as the median of all the pixel values of all the CCD spectra in the wavelength interval corresponding to that pixel. The skymap image should be preallocated: each one of its pixels, corresponding to a wavelength read from wavemap, will be assigned a value obtained by linear interpolation of the two pixels of the supersampled spectrum that are closest to its wavelength.
cpl_image* mos_sky_local_old | ( | cpl_image * | spectra, | |
cpl_table * | slits | |||
) |
Local determination of sky.
spectra | Rectified image of scientific spectra | |
slits | Slits positions table |
Definition at line 12179 of file moses.c.
Referenced by vimos_science_impl().
cpl_image* mos_sky_local | ( | cpl_image * | spectra, | |
cpl_table * | slits, | |||
int | order | |||
) |
Local determination of sky.
spectra | Rectified image of scientific spectra | |
slits | Slits positions table | |
order | Order of the polynomial fitting the sky. |
Definition at line 12281 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.
image | Input image to be cleaned (in ADU) | |
gain | Inverse gain factor (e-/ADU) | |
threshold | Threshold for cosmics detection, given in noise sigmas | |
ratio | Ratio for discrimination between objects and cosmics |
CPL_ERROR_NONE
in case of successDefinition at line 12636 of file moses.c.
References mos_clean_bad_pixels().
Referenced by vimos_science_impl().
cpl_image* mos_spatial_map | ( | cpl_image * | spectra, | |
cpl_table * | slits, | |||
cpl_table * | polytraces, | |||
double | reference, | |||
double | blue, | |||
double | red, | |||
double | dispersion | |||
) |
Create coordinate map from spectral curvature table.
spectra | CCD image of spectra | |
slits | Slits positions on the CCD | |
polytraces | Coefficients of spectral curvature polynomials | |
reference | Reference wavelength | |
blue | Start lambda for spatial remapping | |
red | End lambda for spatial remapping | |
dispersion | Mean spectral dispersion |
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.
cpl_image* mos_detect_objects | ( | cpl_image * | image, | |
cpl_table * | slits, | |||
int | margin, | |||
int | maxradius, | |||
int | conradius | |||
) |
Detect objects in rectified scientific frame.
image | Rectified image of scientific spectra | |
slits | Table with slits positions | |
margin | Number of pixels to exclude at slits edges | |
maxradius | Maximum extraction radius | |
conradius | Contamination radius |
Slits
mean flux spatial profileThe 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)
B_i = (P_i * L_j + P_j * L_i) / (L_i + L_j)
Definition at line 13405 of file moses.c.
References values_to_dx().
Referenced by mos_sky_local(), and vimos_science_impl().
cpl_image** mos_extract_objects | ( | cpl_image * | science, | |
cpl_image * | sky, | |||
cpl_table * | objects, | |||
int | extraction, | |||
double | ron, | |||
double | gain, | |||
int | ncombined | |||
) |
Extract detected objects from rectified scientific frame.
science | Rectified and sky subtracted scientific spectra | |
sky | Rectified sky spectra | |
objects | Spectra and objects position table | |
extraction | Extraction mode: 0 = aperture, 1 = optimal (Horne) | |
ron | Read-out-noise in ADU | |
gain | Conversion from ADU to electrons (e-/ADU) | |
ncombined | Number of combined scientific frames |
Images
with extracted science, sky, and error spectramos_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 13756 of file moses.c.
References mos_extraction(), and list::size.
Referenced by vimos_science_impl().
int mos_spectral_resolution | ( | cpl_image * | image, | |
double | lambda, | |||
double | startwave, | |||
double | dispersion, | |||
int | saturation, | |||
double * | mfwhm, | |||
double * | rmsfwhm, | |||
double * | resolution, | |||
double * | rmsres, | |||
int * | nlines | |||
) |
Compute mean spectral resolution at a given arc lamp line.
image | Rectified and wavelength calibrated arc lamp image | |
lambda | Wavelength to examine | |
startwave | Shortest wavelength in image. | |
dispersion | Wavelength units per image pixel | |
saturation | Saturation value | |
mfwhm | Returned: median FWHM | |
rmsfwhm | Returned: RMS of median FWHM | |
resolution | Returned: spectral resolution | |
rmsres | Returned: RMS of spectral resolution | |
nlines | Returned: Number of examined line profiles |
Definition at line 13960 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.
image | Rectified and wavelength calibrated arc lamp image | |
startwave | Shortest wavelength in image. | |
dispersion | Wavelength units per image pixel | |
saturation | Saturation value | |
lines | Line catalog |
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 14156 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.
image | CCD exposure | |
wavemap | Wavelengths map of CCD exposure | |
ystart | Start Y-pixel coordinate on CCD | |
yend | End Y-pixel coordinate on CCD | |
wstart | Start wavelength | |
wend | End wavelength |
cpl_table* mos_load_slits_fors_mxu | ( | cpl_propertylist * | header | ) |
Create slit location table from FITS header of FORS2-MXU data.
header | FITS header of FORS data containing slits information |
Definition at line 14316 of file moses.c.
References instrume.
cpl_table* mos_load_slits_fors_mos | ( | cpl_propertylist * | header | ) |
Create slit location table from FITS header of FORS1/2 MOS data.
header | FITS header of FORS data containing slits information |
Definition at line 14555 of file moses.c.
References instrume.
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.
header | FITS header of FORS data containing slits information |
Definition at line 14754 of file moses.c.
References instrume.
double mos_get_gain_vimos | ( | cpl_propertylist * | header | ) |
Return gain factor for a VIMOS exposure.
header | FITS header of VIMOS data containing information |
cpl_table* mos_load_slits_vimos | ( | cpl_propertylist * | header | ) |
Create slit location table from FITS header of VIMOS data.
header | FITS header of VIMOS data containing slits information |
Definition at line 14967 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.
slits | Slit positions produced by mos_load_slits_vimos() |
cpl_table* mos_load_overscans_vimos | ( | const cpl_propertylist * | header, | |
int | check_consistency | |||
) |
Get the overscan positions from FITS header of VIMOS data.
header | FITS header containing overscan information | |
check_consistency | If true (non-zero), this function fails if the sum of prescan, overscan and detector size is different from the actual FITS image size. (this does not hold true for old FORS data) |
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 15177 of file moses.c.
Referenced by mos_load_overscans_fors(), vimos_calib_impl(), and vimos_science_impl().
cpl_error_code mos_randomise_image | ( | cpl_image * | image, | |
double | ron, | |||
double | gain, | |||
double | bias | |||
) |
Randomise image.
image | Image to randomise (in place) | |
ron | Read out noise (ADU) | |
gain | Gain (electrons/ADU) | |
bias | Bias level (ADU) |
S = S + sqrt(V) * mos_randg(1)
Definition at line 15628 of file moses.c.
References mos_randg().
cpl_error_code mos_refmask_find_gaps | ( | cpl_mask * | refmask, | |
cpl_image * | master_flat, | |||
double | level | |||
) |
Reconstruct the gaps required for slit location.
refmask | Reference mask | |
master_flat | Masterflat. The gaps are detected and inserted based upon the values found in this image. |
Definition at line 15672 of file moses.c.
Referenced by vimos_calib_impl().
cpl_error_code mos_saturation_process | ( | cpl_image * | image | ) |
Process saturation.
image | Image to process saturation |
Definition at line 15765 of file moses.c.
Referenced by vimos_calib_impl().
cpl_error_code mos_subtract_background | ( | cpl_image * | image | ) |
Subtract the background.
image | Image to subtract the background |
Definition at line 15831 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.
slitss | Pointer to the list of slit tables | |
origslits | Pointer to output intersected table | |
nscience | Number of tables in the list | |
tolerance | Tolerance in object position (pixel) |
Definition at line 15861 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.
slits | Slits table |
Definition at line 16460 of file moses.c.
Referenced by fors_get_nobjs_perslit(), 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.
slits | Slits table |
Definition at line 16486 of file moses.c.
References mos_get_maxobjs_per_slit().
Referenced by mos_object_intersect().
int mos_check_slits | ( | cpl_table * | slits, | |
float | rescale | |||
) |
cpl_table* mos_load_slits_fors_pmos | ( | cpl_propertylist * | header | ) |
Create PMOS slit location table from FITS header of FORS1/2 MOS data.
header | FITS header of FORS data containing slits information |
Definition at line 16620 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.
spectra | Image with extracted spectra | |
startwave | Shortest wavelength in input image (Angstrom) | |
dispersion | Angstrom per pixel of input image | |
gain | Gain factor (e-/ADU) | |
exptime | Exposure time (seconds) | |
ext_table | Atmospheric extinction table | |
airmass | Airmass of observation | |
flux_table | Standard star catalog flux | |
order | Order of polynomial to model the instrument response |
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 16959 of file moses.c.
References cleanup, map_table(), and polysmooth().
Referenced by vimos_science_impl().
cpl_image* mos_ksigma_stack | ( | cpl_imagelist * | imlist, | |
double | klow, | |||
double | khigh, | |||
int | kiter, | |||
cpl_image ** | good | |||
) |
Stack images using k-sigma clipping.
imlist | List of images to stack | |
klow | Number of sigmas for rejection of lowest values | |
khigh | Number of sigmas for rejection of highest values | |
kiter | Max number of iterations |
Definition at line 17436 of file moses.c.
References ksigma_vector().
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.
spectra | Image containing extracted spectra (slits or objects) | |
response | Table including the response curve | |
ext_table | Atmospheric extinction table | |
startwave | Start wavelength | |
dispersion | Angstrom per pixel of input image | |
gain | Gain factor (e-/ADU) | |
exptime | Exposure time (seconds) | |
airmass | Airmass of observation |
Definition at line 17511 of file moses.c.
References map_table().
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.
errors | Image containing errors on extracted spectra (objects) | |
response | Table including the response curve errors | |
ext_table | Atmospheric extinction table | |
startwave | Start wavelength | |
dispersion | Angstrom per pixel of input image | |
gain | Gain factor (e-/ADU) | |
exptime | Exposure time (seconds) | |
airmass | Airmass of observation |
Definition at line 17604 of file moses.c.
References map_table(), and 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.
q_image | Image whose rows correspond to extracted spectra | |
q_error | Image with errors of q_image | |
u_image | Image whose rows correspond to extracted spectra | |
u_error | Image with errors of u_image | |
startwave | Start wavelength | |
dispersion | Angstrom per pixel of input image | |
band | Width of band where the signal is averaged (Angstrom) | |
pol_sta | Table with polarimetric standard stars parameters | |
ra | Right Ascension of center of field of view (degrees) | |
dec | Declination of center of field of view (degrees) | |
filter | Returned filter (UBVRI) to which the measurement refers | |
polarisation | Returned polarisation flag (0 = star is not polarised) | |
p_offset | Returned relative variation of P in filter | |
p_error | Returned error on p_offset | |
a_offset | Returned variation of angle in filter (degrees) | |
a_error | Returned error on a_offset (degrees) |
The parameter p_offset is defined as observed minus expected polarisation, divided by expected polarisation. Only in case the expected polarisation is zero, p_offset is simply defined as the observed polarisation.
The parameter p_error is obtained by propagating the measurement and the catalog errors.
The parameter a_offset is defined as observed minus expected polarisation angle. In case the expected polarisation is zero, a_offset is simply set to zero.
The parameter a_error is obtained by propagating the measurement and the catalog errors. In case the expected polarisation is zero, a_error is simply set to zero.
The applied algorithm is the following:
Each row of the input images corresponds to a different object. The row corresponding to the standard star is selected as the one where the S/N ratio is the greatest (this check is performed conventionally on q_error, which is minimal for high S/N objects). The selected row is extracted from all input images.
From the table pol_sta the standard star closest to the specified ra and dec coordinates is found, and if this is closer than half a degree from the input ra and dec is selected. From the available expected values at the different spectral bands (U, B, V, etc.) the one which is closest to the center of the valid spectral interval for the standard star observation is selected (the valid spectral interval is defined here as the region where the error is greater than zero). The following wavelengths are associated to each band:
U -> 3650 Angstrom B -> 4450 Angstrom V -> 5510 Angstrom R -> 6580 Angstrom I -> 8060 Angstrom
If the interval band centered at the wavelength closest to center of the valid spectral range is not entirely contained in the valid spectral range, this function fails and 1 is returned. Otherwise, within the defined band, the median values of Q and U, together with their median errors, are determined. From those the values for the output parameters are computed in the usual way.
int mos_compute_offset | ( | cpl_table * | reference, | |
cpl_table * | objects, | |||
double * | offset | |||
) |
Estimate offset between two object tables.
reference | Reference object table. | |
objects | Object table from offset frame. | |
offset | Returned offset in CCD pixels. |
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
mos_spatial_calibration()
. The returned offset is the median offset obtained from all slits.
Definition at line 18139 of file moses.c.
References fors_get_nobjs_perslit(), fors_get_object_position(), and fors_tools_get_kth_double().
cpl_error_code mos_image_shift | ( | cpl_image * | image, | |
double | dx, | |||
double | dy | |||
) |
int mos_slit_closest_to_center | ( | cpl_table * | slits, | |
int | nx, | |||
int | ny | |||
) |
Return slit closest to CCD center.
slits | Slit table | |
nx | X size of CCD | |
ny | Y size of CCD |
Definition at line 18400 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.
image | Image containing raw spectra. | |
slits | Table with slits properties. | |
dx | Pixels to extract along the dispersion direction (radius). | |
gain | In electrons/ADU, used for error computation. | |
o_flux | Returned integrated flux, in ADU/mm^2 | |
o_err | Returned error on integrated flux. |
Definition at line 18448 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.
image | Image containing remapped spectra. | |
slits | Table with slits properties. | |
lambda | Wavelength to examine | |
startwave | Shortest wavelength in image. | |
dispersion | Wavelength units per image pixel | |
dx | Pixels to extract along the dispersion direction (radius). | |
gain | In electrons/ADU, used for error computation. | |
o_flux | Returned integrated flux, in ADU/mm^2 | |
o_err | Returned error on integrated flux. |
Definition at line 18565 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.
table | Table with as many rows as rectified images | |
slits | Table with slits properties. | |
slit | Row in slits corresponding to slit to examine | |
label | Name of column to examine | |
mvalue | Returned median value |
Definition at line 18675 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.
image | Image to smooth | |
nx | Filter size in x. | |
ny | Filter size in y. |
Definition at line 18703 of file moses.c.
Referenced by fors_image_flat_fit_create(), mos_arc_background(), and mos_extraction().