def Lacosmic_WHTData(self, InputFile, OutputFile, Fits_Folder, CodeName, gain, readnoise, sigclip, verbose): #Load the data (array, header) = cosmics.fromfits(Fits_Folder + InputFile, verbose = verbose) upsample = 1 #Create the task object c = cosmics.cosmicsimage(array, pssl = 0.0, gain=1.16, readnoise=5, sigclip = 16, verbose = verbose) #Run the task c.run(maxiter = 4, verbose = verbose) #Proceed to generate the images #-- 1) The raw input array im = f2n.f2nimage(c.getrawarray(), verbose=False) im.setzscale() im.makepilimage("log") im.upsample(upsample) im.writetitle("Input image", colour = (0,255,0)) im.tonet(Fits_Folder + CodeName + "_1_raw.png") #-- 2) The raw input array #-- We output a list of the positions of detected cosmic ray hits. #-- This is made on purpose to be fed into f2n's drawstarslist : labeldict = c.labelmask() im = f2n.f2nimage(c.getrawarray(), verbose=False) im.setzscale() im.makepilimage("log") im.drawmask(c.getsatstars(), colour=(255, 0, 255)) im.upsample(upsample) im.drawstarslist(labeldict, colour=(255,0,0)) im.writetitle("Cosmic ray hits", colour = (0,255,0)) im.tonet(Fits_Folder + CodeName + "_2_labels.png") #-- 3) Tne png with the precise mask in green and a wider version in blue : im = f2n.f2nimage(c.getrawarray(), verbose=False) im.setzscale() im.makepilimage("log") im.drawmask(c.getdilatedmask(size=5), colour=(0, 0, 255)) im.drawmask(c.getmask(), colour=(0, 255, 0)) im.upsample(upsample) im.writetitle("Mask", colour = (0,255,0)) im.tonet(Fits_Folder + CodeName + "_3_mask.png") #-- 4) And of course one png with the clean array : im = f2n.f2nimage(c.getcleanarray(), verbose=False) im.setzscale() im.makepilimage("log") im.upsample(upsample) im.writetitle("Cleaned image", colour = (0,255,0)) im.tonet(Fits_Folder + CodeName + "_4_clean.png") #Save the FitsFile (CHECK THE HEADER): cosmics.tofits(Fits_Folder + OutputFile, c.cleanarray, header) return
# Demo_Folder = "/home/vital/Dropbox/Astrophysics/Tools/PyRaf/LaCosmic_Python/demo_2_withpng/" # Demo_Input = "euler.fits" # # import cosmics, f2n from Scientific_Lib import cosmics from Scientific_Lib import f2n Demo_Folder = "/home/vital/Dropbox/Astrophysics/Tools/PyRaf/LaCosmic_Python/demo_2_withpng/" Demo_Input = "euler.fits" Demo_Input = "obj8_c_f.fits" # Read the FITS : (array, header) = cosmics.fromfits(Demo_Folder + Demo_Input, verbose = True) # We can of course crop the numpy array : #array = array[100:500,210:525] # z1=170 # z2=5000 upsample = 1 # Build the object : c = cosmics.cosmicsimage(array, pssl = 0.0, gain=1.16, readnoise=5, sigclip = 16, verbose = True) # Run : c.run(maxiter = 4, verbose = False)