cosmicray_median#

ccdproc.cosmicray_median(ccd, error_image=None, thresh=5, mbox=11, gbox=0, rbox=0)[source]#

Identify cosmic rays through median technique. The median technique identifies cosmic rays by identifying pixels by subtracting a median image from the initial data array.

Parameters:
ccdCCDData or array-like

Data to have cosmic ray cleaned. If the input has a mask (the mask of a CCDData, or a numpy.ma.MaskedArray), masked pixels are never flagged as cosmic rays; see Notes.

threshfloat, optional

Threshold for detecting cosmic rays. Default is 5.

error_imagenumpy.ndarray, float or None, optional

Error level. If None, the task will use the standard deviation of the data. If an ndarray, it should have the same shape as data. Default is None.

mboxint, optional

Median box for detecting cosmic rays. Default is 11.

gboxint, optional

Box size to grow cosmic rays. If zero, no growing will be done. Default is 0.

rboxint, optional

Median box for calculating replacement values. If zero, no pixels will be replaced. Default is 0.

Returns:
nccdCCDData or array

An object of the same type as ccd is returned, in the array namespace and on the device of the input. If it is a CCDData, the mask attribute will also be updated with areas identified with cosmic rays masked.

nccdarray

If an array is provided as ccd, a boolean array, in the same array namespace and on the same device as the input, with the cosmic rays identified will also be returned.

Raises:
TypeError

If error_image is an array from a different array library than the data of ccd.

ValueError

If error_image is an array on a different device than the data of ccd.

Notes

Similar implementation to crmedian in iraf.imred.crutil.crmedian.

If ccd is a CCDData with a mask, or a numpy.ma.MaskedArray, the masked pixels are never flagged as cosmic rays (including by the gbox growth step), they are returned unchanged in the output data, and, when error_image is None, they are excluded from the noise estimate. They are not excluded from the median filter itself, so very bright masked pixels can still influence the local median of their unmasked neighbors. For a CCDData the returned mask is the union of the input mask and the detected cosmic rays.

Examples

  1. Given an numpy.ndarray object, the syntax for running cosmicray_median would be:

    >>> newdata, mask = cosmicray_median(data, error_image=error,
    ...                                  thresh=5, mbox=11,
    ...                                  rbox=11, gbox=5)
    

    where error is an array that is the same shape as data but includes the pixel error. This would return a data array, newdata, with the bad pixels replaced by the local median from a box of 11 pixels; and it would return a mask indicating the bad pixels.

  2. Given an CCDData object with an uncertainty frame, the syntax for running cosmicray_median would be:

    >>> newccd = cosmicray_median(ccd, thresh=5, mbox=11,
    ...                           rbox=11, gbox=5)
    

    The newccd object will have bad pixels in its data array replace and the mask of the object will be created if it did not previously exist or be updated with the detected cosmic rays.