Module cosmics
[frames] | no frames]

Module cosmics

source code

About

cosmics.py is a small and simple python module to detect and clean cosmic ray hits on images (numpy arrays or FITS), using scipy, and based on Pieter van Dokkum's L.A.Cosmic algorithm.

L.A.Cosmic = Laplacian cosmic ray detection

http://www.astro.yale.edu/dokkum/lacosmic/

(article : http://arxiv.org/abs/astro-ph/0108003)

Additional features

I pimped this a bit to suit my needs :

But otherwise the core is really a 1-to-1 implementation of L.A.Cosmic, and uses the same parameters. Only the conventions on how filters are applied at the image edges might be different.

No surprise, this python module is much faster then the IRAF implementation, as it does not read/write every step to disk.

Usage

Everything is in the file cosmics.py, all you need to do is to import it. You need pyfits, numpy and scipy. See the demo scripts for example usages (the second demo uses f2n.py to make pngs, and thus also needs PIL).

Your image should have clean borders, cut away prescan/overscan etc.

Todo

Ideas for future improvements :

Malte Tewes, January 2010


Version: 0.4

Classes
  cosmicsimage
Functions
 
fromfits(infilename, hdu=0, verbose=True)
Reads a FITS file and returns a 2D numpy array of the data.
source code
 
tofits(outfilename, pixelarray, hdr=None, verbose=True)
Takes a 2D numpy array and write it into a FITS file.
source code
 
subsample(a)
Returns a 2x2-subsampled version of array a (no interpolation, just cutting pixels in 4).
source code
 
rebin(a, newshape)
Auxiliary function to rebin an ndarray a.
source code
 
rebin2x2(a)
Wrapper around rebin that actually rebins 2 by 2
source code
Variables
  laplkernel = np.array([[0.0,-1.0, 0.0], [-1.0, 4.0,-1.0], [0.0...
  growkernel = np.ones((3, 3))
  dilstruct = np.ones((5, 5))
Function Details

fromfits(infilename, hdu=0, verbose=True)

source code 

Reads a FITS file and returns a 2D numpy array of the data. Use hdu to specify which HDU you want (default = primary = 0)

tofits(outfilename, pixelarray, hdr=None, verbose=True)

source code 

Takes a 2D numpy array and write it into a FITS file. If you specify a header (pyfits format, as returned by fromfits()) it will be used for the image. You can give me boolean numpy arrays, I will convert them into 8 bit integers.

subsample(a)

source code 

Returns a 2x2-subsampled version of array a (no interpolation, just cutting pixels in 4). The version below is directly from the scipy cookbook on rebinning : http://www.scipy.org/Cookbook/Rebinning There is ndimage.zoom(cutout.array, 2, order=0, prefilter=False), but it makes funny borders.

rebin(a, newshape)

source code 

Auxiliary function to rebin an ndarray a. http://www.scipy.org/Cookbook/Rebinning

>>> a=rand(6,4); b=rebin(a,(3,2))

Variables Details

laplkernel

Value:
np.array([[0.0,-1.0, 0.0], [-1.0, 4.0,-1.0], [0.0,-1.0, 0.0]])