reduction.crrej.crrej

reduction.crrej.crrej(
    ccd,
    mask=None,
    inbkg=None,
    invar=None,
    propagate_crmask=False,
    update_header=True,
    add_process=True,
    gain=None,
    rdnoise=None,
    sigclip=4.5,
    sigfrac=0.5,
    objlim=1.0,
    satlevel=np.inf,
    niter=4,
    sepmed=False,
    cleantype='medmask',
    fs='median',
    psffwhm=2.5,
    psfsize=7,
    psfbeta=4.765,
    verbose=True,
)

Do cosmic-ray rejection using L.A.Cosmic default parameters.

Parameters

ccd : ~astropy.nddata.CCDData

The ccd to be processed. The data must be in ADU, not electrons.

propagate_crmask : bool, optional. = False

Whether to save (propagate) the mask from CR rejection (~astroscrappy) to the CCD’s mask. Default is False.

inbkg : float, ~numpy.ndarray, path-like to FITS = None

A pre-determined background image, to be subtracted from ccd before running the main detection algorithm. This is used primarily with spectroscopic data, to remove sky lines and the cross-section of an object continuum during iteration, “protecting” them from spurious rejection (see the above paper). This background is not removed from the final, cleaned output (cleanarr). This should be in units of “counts”, the same units of ccd. inbkg should be free from cosmic rays. When estimating the cosmic-ray free noise of the image, we will treat inbkg as a constant Poisson contribution to the variance. Default: None.

Note

Originally pssl, which stood for “previously subtracted sky level” in ADU (in astroscrappy < 1.1.0 or original L.A.Cosmic). Since astroscrappy ver > 1.1.0, a 2-D sky level is supported by inbkg (it was bkg in == 1.1.0, which is a hasty bug in argument naming).

invar : float numpy array, path-like to FITS = None

A pre-determined estimate of the data variance (ie. noise squared) in each pixel, generated by previous processing of ccd. If provided, this is used in place of an internal noise model based on ccd, gain and readnoise. This still gets median filtered and cleaned internally, to estimate what the noise in each pixel would be in the absence of cosmic rays. This should be in units of “counts” squared. (it was var in == 1.1.0, which is a hasty bug in argument naming)

gain : None, float, astropy.~astropy.units.Quantity, optional. = None

The gain and readnoise value. If not Quantity, they must be in electrons per adu and electron unit, respectively.

rdnoise : None, float, astropy.~astropy.units.Quantity, optional. = None

The gain and readnoise value. If not Quantity, they must be in electrons per adu and electron unit, respectively.

sigclip : float = 4.5

Laplacian-to-noise limit for cosmic ray detection. Lower values will flag more pixels as cosmic rays. Default: 4.5.

sigfrac : float = 0.5

Fractional detection limit for neighboring pixels. For cosmic ray neighbor pixels, a lapacian-to-noise detection limit of sigfrac * sigclip will be used. Default: 0.5.

objlim : float = 1.0

Minimum contrast between Laplacian image and the fine structure image. Increase this value if cores of bright stars are flagged as cosmic rays. Default: 1.0.

satlevel : float = np.inf

Saturation of level of the image (electrons). This value is used to detect saturated stars and pixels at or above this level are added to the mask. Default: np.inf.

niter : int = 4

Number of iterations of the LA Cosmic algorithm to perform. Default: 4.

sepmed : boolean = False

Use the separable median filter instead of the full median filter. The separable median is not identical to the full median filter, but they are approximately the same and the separable median filter is significantly faster and still detects cosmic rays well. Default: False

cleantype : {\'median\', \'medmask\', \'meanmask\', \'idw\'} = 'medmask'

Set which clean algorithm is used:

  • 'median': An umasked 5x5 median filter
  • 'medmask': A masked 5x5 median filter
  • 'meanmask': A masked 5x5 mean filter
  • 'idw': A masked 5x5 inverse distance weighted interpolation

Default: "medmask".

fs : {\'median\', \'gauss\', \'gaussx\', \'gaussy\', \'moffat\'}, ~numpy.ndarray, None, optional. = 'median'

Method to generate the fine structure. Combination of fsmode, psfmodel, psfk of astroscrappy.

  • 'median': Use the median filter in the standard LA Cosmic algorithm. None of psffwhm, psfsize, and psfbeta are used.
  • other str: Use a Gaussian/Moffat model to generate the psf kernel. 'gauss'|'moffat' produce circular PSF kernels. 'gaussx'|'gaussy' produce Gaussian kernels in the x and y directions respectively. psffwhm, psfsize (plus psfbeta if “moffat”) are used.
  • ~numpy.ndarray: PSF kernel array to use for the fine structure image. None of psffwhm, psfsize, and psfbeta are used.

Mapping between astroscrappy and imred options:

  • fsmode="median" == fs="median"
  • fsmode="convolve", psfmodel=* == fs=*, where * can be any of {'gauss', 'gaussx', 'gaussy', 'moffat'}.
  • fsmode="convolve", psfk=<`~numpy.ndarray`> == fs=<`~numpy.ndarray`>

If None, CR rejection will not happen and copy of input ccd will be returned.

Default: 'median'.

psffwhm : float = 2.5

Full Width Half Maximum of the PSF to use to generate the kernel. Default: 2.5.

psfsize : int = 7

Size of the kernel to calculate. Returned kernel will have size psfsize x psfsize. It should be an odd integer. Default: 7.

psfbeta : float = 4.765

Moffat beta parameter. Only used if fs='moffat'. Default: 4.765.

verbose : boolean = True

Print to the screen or not. Default: True.

Returns

**_ccd** : ~astropy.nddata.CCDData

The cosmic-ray cleaned ~astropy.nddata.CCDData in ADU. ~astroscrappy automatically does a gain correction, so I divided the ~astroscrappy result by gain to restore to ADU (not to surprise the users).

crmask : ~numpy.ndarray (mask)

The cosmic-ray mask from ~astroscrappy, propagated by the original mask of the ccd (if ccd.mask is not None) and mask given by the user.

update_header : bool, optional.

Whether to update the header if there is any.

add_process : bool, optional.

Whether to add PROCESS key to the header.

Notes

Important detection parameters are sigclip, sigfrac, and objlim. Fine-structure parameters are mapped through fs, psffwhm, psfsize, psfk, and psfbeta. Detector-specific parameters are gain and rdnoise.

(Note from astroscrappy) For best results on spectra, we recommend that you include an estimate of the background. One can generally obtain this by fitting columns with a smooth function. To efficiently identify cosmic rays, LA Cosmic and therefore astroscrappy estimates the cosmic ray free noise by smoothing the variance using a median filter. To minimize false positives on bright sky lines, if inbkg is provided, we do not smooth the variance contribution from the provided background. We only smooth the variance that is in addition to the Poisson contribution from the background so that we do not underestimate the noise (and therefore run the risk of flagging false positives) near narrow, bright sky lines.

All defaults are based on the IRAF version of L.A. Cosmic. The default parameters differ between L.A. Cosmic versions, so these follow the IRAF version written by van Dokkum.