Module cosmics :: Class cosmicsimage
[frames] | no frames]

Class cosmicsimage

source code

Instance Methods
 
__init__(self, rawarray, pssl=0.0, gain=2.2, readnoise=10.0, sigclip=5.0, sigfrac=0.3, objlim=5.0, satlevel=50000.0, verbose=True)
sigclip : increase this if you detect cosmics where there are none.
source code
 
__str__(self)
Gives a summary of the current state, including the number of cosmic pixels in the mask etc.
source code
 
labelmask(self, verbose=None)
Finds and labels the cosmic "islands" and returns a list of dicts containing their positions.
source code
 
getdilatedmask(self, size=3)
Returns a morphologically dilated copy of the current mask.
source code
 
clean(self, mask=None, verbose=None)
Given the mask, we replace the actual problematic pixels with the masked 5x5 median value.
source code
 
findsatstars(self, verbose=None)
Uses the satlevel to find saturated stars (not cosmics !), and puts the result as a mask in self.satstars.
source code
 
getsatstars(self, verbose=None)
Returns the mask of saturated stars after finding them if not yet done.
source code
 
getmask(self) source code
 
getrawarray(self)
For external use only, as it returns the rawarray minus pssl !
source code
 
getcleanarray(self)
For external use only, as it returns the cleanarray minus pssl !
source code
 
guessbackgroundlevel(self)
Estimates the background level.
source code
 
lacosmiciteration(self, verbose=None)
Performs one iteration of the L.A.Cosmic algorithm.
source code
 
findholes(self, verbose=True)
Detects "negative cosmics" in the cleanarray and adds them to the mask.
source code
 
run(self, maxiter=4, verbose=False)
Full artillery :-)
source code
Method Details

__init__(self, rawarray, pssl=0.0, gain=2.2, readnoise=10.0, sigclip=5.0, sigfrac=0.3, objlim=5.0, satlevel=50000.0, verbose=True)
(Constructor)

source code 

sigclip : increase this if you detect cosmics where there are none. Default is 5.0, a good value for earth-bound images. objlim : increase this if normal stars are detected as cosmics. Default is 5.0, a good value for earth-bound images.

Constructor of the cosmic class, takes a 2D numpy array of your image as main argument. sigclip : laplacian-to-noise limit for cosmic ray detection objlim : minimum contrast between laplacian image and fine structure image. Use 5.0 if your image is undersampled, HST, ...

satlevel : if we find agglomerations of pixels above this level, we consider it to be a saturated star and do not try to correct and pixels around it. A negative satlevel skips this feature.

pssl is the previously subtracted sky level !

real gain = 1.8 # gain (electrons/ADU) (0=unknown) real readn = 6.5 # read noise (electrons) (0=unknown) ##gain0 string statsec = "*,*" # section to use for automatic computation of gain real skyval = 0. # sky level that has been subtracted (ADU) real sigclip = 3.0 # detection limit for cosmic rays (sigma) real sigfrac = 0.5 # fractional detection limit for neighbouring pixels real objlim = 3.0 # contrast limit between CR and underlying object int niter = 1 # maximum number of iterations

labelmask(self, verbose=None)

source code 

Finds and labels the cosmic "islands" and returns a list of dicts containing their positions. This is made on purpose for visualizations a la f2n.drawstarslist, but could be useful anyway.

getdilatedmask(self, size=3)

source code 

Returns a morphologically dilated copy of the current mask. size = 3 or 5 decides how to dilate.

clean(self, mask=None, verbose=None)

source code 

Given the mask, we replace the actual problematic pixels with the masked 5x5 median value. This mimics what is done in L.A.Cosmic, but it's a bit harder to do in python, as there is no readymade masked median. So for now we do a loop... Saturated stars, if calculated, are also masked : they are not "cleaned", but their pixels are not used for the interpolation.

We will directly change self.cleanimage. Instead of using the self.mask, you can supply your own mask as argument. This might be useful to apply this cleaning function iteratively. But for the true L.A.Cosmic, we don't use this, i.e. we use the full mask at each iteration.

findsatstars(self, verbose=None)

source code 

Uses the satlevel to find saturated stars (not cosmics !), and puts the result as a mask in self.satstars. This can then be used to avoid these regions in cosmic detection and cleaning procedures. Slow ...

getsatstars(self, verbose=None)

source code 

Returns the mask of saturated stars after finding them if not yet done. Intended mainly for external use.

guessbackgroundlevel(self)

source code 

Estimates the background level. This could be used to fill pixels in large cosmics.

lacosmiciteration(self, verbose=None)

source code 

Performs one iteration of the L.A.Cosmic algorithm. It operates on self.cleanarray, and afterwards updates self.mask by adding the newly detected cosmics to the existing self.mask. Cleaning is not made automatically ! You have to call clean() after each iteration. This way you can run it several times in a row to to L.A.Cosmic "iterations". See function lacosmic, that mimics the full iterative L.A.Cosmic algorithm.

Returns a dict containing

  • niter : the number of cosmic pixels detected in this iteration
  • nnew : among these, how many were not yet in the mask
  • itermask : the mask of pixels detected in this iteration
  • newmask : the pixels detected that were not yet in the mask

If findsatstars() was called, we exclude these regions from the search.

findholes(self, verbose=True)

source code 

Detects "negative cosmics" in the cleanarray and adds them to the mask. This is not working yet.

run(self, maxiter=4, verbose=False)

source code 

Full artillery :-)

  • Find saturated stars
  • Run maxiter L.A.Cosmic iterations (stops if no more cosmics are found)

Stops if no cosmics are found or if maxiter is reached.