lacosmic

lacosmic.lacosmic(data, contrast, cr_threshold, neighbor_threshold, error=None, mask=None, background=None, effective_gain=None, readnoise=None, maxiter=4, border_mode='mirror')[source]

Remove cosmic rays from an astronomical image using the L.A.Cosmic algorithm.

The L.A.Cosmic algorithm is based on Laplacian edge detection and is described in van Dokkum (2001; PASP 113, 1420).

Parameters:
dataarray_like

The 2D array of the image.

contrastfloat

Contrast threshold between the Laplacian image and the fine-structure image. If your image is critically sampled, use a value around 2. If your image is undersampled (e.g., HST data), a value of 4 or 5 (or more) is more appropriate. If your image is oversampled, use a value between 1 and 2. For details, please see PASP 113, 1420 (2001), which calls this parameter \(f_{\mbox{lim}}\). In particular, Figure 4 shows the approximate relationship between the contrast parameter and the full-width half-maximum (in pixels) of stars in your image.

cr_thresholdfloat

The Laplacian signal-to-noise ratio threshold for cosmic-ray detection.

neighbor_thresholdfloat

The Laplacian signal-to-noise ratio threshold for detection of cosmic rays in pixels neighboring the initially-identified cosmic rays.

errorarray_like, optional

The 1-sigma errors of the input data. If error is not input, then effective_gain and readnoise will be used to construct an approximate model of the error. If error is input, it will override the effective_gain and readnoise parameters. error must have the same shape as data.

maskarray_like (bool), optional

A boolean mask, with the same shape as data, where a True value indicates the corresponding element of data is masked. Masked pixels are ignored when identifying cosmic rays. It is highly recommended that saturated stars be included in mask.

backgroundfloat or array_like, optional

The background level previously subtracted from the input data. background may either be a scalar value or a 2D image with the same shape as the input data. If the input data has not been background subtracted, then set background=None (default).

effective_gainfloat, array-like, optional

Ratio of counts (e.g., electrons or photons) to the units of data. For example, if your input data are in units of ADU, then effective_gain should represent electrons/ADU. If your input data are in units of electrons/s then effective_gain should be the exposure time (or an exposure time map). effective_gain and readnoise must be specified if error is not input.

readnoisefloat, optional

The read noise (in electrons) in the input data. effective_gain and readnoise must be specified if error is not input.

maxiterfloat, optional

The maximum number of iterations. The default is 4. The routine will automatically exit if no additional cosmic rays are identified in an iteration. If the routine is still identifying cosmic rays after four iterations, then you are likely digging into sources (e.g., saturated stars) and/or the noise. In that case, try inputing a mask or increasing the value of cr_threshold.

border_mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional

The mode in which the array borders are handled during convolution and median filtering. For ‘constant’, the fill value is 0. The default is ‘mirror’, which matches the original L.A.Cosmic algorithm.

Returns:
cleaned_imagendarray

The cosmic-ray cleaned image.

crmaskndarray (bool)

A mask image of the identified cosmic rays. Cosmic-ray pixels have a value of True.