Beispiel #1
0
def stretch_all(sel=0):

	for string in ["CFHTLS_*_sci.fits"]:#
		for fits in file_seek("../Data/",string):
			if sel==0: stretch(fits)
			else: stretch_plus(fits)
			
	return
Beispiel #2
0
def stretch_all(sel=0):

    for string in ["CFHTLS_*_sci.fits"]:  #
        for fits in file_seek("../Data/", string):
            if sel == 0: stretch(fits)
            else: stretch_plus(fits)

    return
Beispiel #3
0
def stretch_plus(fits_original):
	
	## Stretching parameters	
	vmin,vmax=stretch(fits_original)
	
	## Apply to diagnostic files
	homedir=os.path.dirname(fits_original)
	for string in ["snap_*_sci.fits","samp_*_sci.fits","resi_*_sci.fits"]:#"CFHTLS_*_sci.fits"
		for fits in file_seek(homedir,string):
			stretch(fits, vmin,vmax)
			
	return
Beispiel #4
0
def stretch_plus(fits_original):

    ## Stretching parameters
    vmin, vmax = stretch(fits_original)

    ## Apply to diagnostic files
    homedir = os.path.dirname(fits_original)
    for string in ["snap_*_sci.fits", "samp_*_sci.fits",
                   "resi_*_sci.fits"]:  #"CFHTLS_*_sci.fits"
        for fits in file_seek(homedir, string):
            stretch(fits, vmin, vmax)

    return
Beispiel #5
0
def all_kernels(kdim, writefile=True, makeimage=False, vb=False):

    ## Get files -- path hard-coded
    allpngs = numpy.sort(file_seek("../Data/GPSF/",
                                   "snap*d0_CFHTLS_03_g*.png"))

    ## Collect pairs of files
    for i in range(0, len(allpngs), 2):

        ## Extract image info
        image1 = png_pix(allpngs[i])
        image2 = png_pix(allpngs[i + 1])

        ## Cut out extraneous white pixels
        image1 = pngcropwhite(image1)
        image2 = pngcropwhite(image2)

        ## Deconvolve
        A = get_kernel(image1, image2, kdim)
        B = get_kernel(image2, image1, kdim)

        ##------------------------------------------------------------

        ## Write kernels to file and make images

        ## Gaussian to PSF
        outfile = os.path.splitext(allpngs[i])[0][:-4] + "_GausstoPSF_" + str(
            A.shape[0]) + ".krn"
        f = open(outfile, "w")
        f.write(
            "## Convolution kernel taking 2D Gaussian to PSFEx image\n\n\n")
        writearray(f, A, True)
        if vb: print "DeconvolveToTargetPSF.py: kernel written to", outfile

        ## PSF to Gaussian
        outfile = os.path.splitext(allpngs[i])[0][:-4] + "_PSFtoGauss_" + str(
            B.shape[0]) + ".krn"
        f = open(outfile, "w")
        f.write(
            "## Convolution kernel taking PSFEx image to 2D Gaussian\n\n\n")
        writearray(f, B, True)
        if vb: print "DeconvolveToTargetPSF.py: kernel written to", outfile

        print "\n"

##------------------------------------------------------------

    return
Beispiel #6
0
def FITStoPNG(args):
  i=0 
  for f_img in file_seek(args[2], args[3]+"*.fits"):
		## Prepare destination directory
		outdir=os.path.dirname(f_img)+"/Enhanced_Original/" ## Needs to be commented when brightening
		if os.path.isdir(outdir)==False: os.mkdir(outdir)
		## Outfile name
		p_img = outdir+"/"+os.path.basename(f_img)[:-5]+".png"
		## File conversion
		#os.system("ds9 "+f_img+" -minmax -colorbar no -saveimage png "+p_img+" -exit")
		try:
			hdulist = pyfits.open(f_img)
			scipy.misc.imsave(f_img[:-4]+"png", hdulist[0].data)
			i+=1
		except:
			pass
  print "ImageScript.py: FITStoPNG: Converted",i,"files to png format."
  return
Beispiel #7
0
def all_kernels(kdim, writefile=True,makeimage=False, vb=False):
		
	## Get files -- path hard-coded
	allpngs = numpy.sort(file_seek("../Data/GPSF/","snap*d0_CFHTLS_03_g*.png"))
	
	## Collect pairs of files
	for i in range (0,len(allpngs),2):
	
		## Extract image info
		image1 = png_pix(allpngs[i])
		image2 = png_pix(allpngs[i+1])
		
		## Cut out extraneous white pixels
		image1 = pngcropwhite(image1)
		image2 = pngcropwhite(image2)
		
		## Deconvolve
		A=get_kernel(image1,image2, kdim)
		B=get_kernel(image2,image1, kdim)	

##------------------------------------------------------------
			
		## Write kernels to file and make images
		
		## Gaussian to PSF
		outfile=os.path.splitext(allpngs[i])[0][:-4]+"_GausstoPSF_"+str(A.shape[0])+".krn"
		f=open(outfile,"w")
		f.write("## Convolution kernel taking 2D Gaussian to PSFEx image\n\n\n")
		writearray(f,A,True)
		if vb: print "DeconvolveToTargetPSF.py: kernel written to",outfile
		
		## PSF to Gaussian		
		outfile=os.path.splitext(allpngs[i])[0][:-4]+"_PSFtoGauss_"+str(B.shape[0])+".krn"
		f=open(outfile,"w")
		f.write("## Convolution kernel taking PSFEx image to 2D Gaussian\n\n\n")
		writearray(f,B,True)
		if vb: print "DeconvolveToTargetPSF.py: kernel written to",outfile
		
		print "\n"

##------------------------------------------------------------	
	
	return
Beispiel #8
0
def FITStoPNG(args):
    i = 0
    for f_img in file_seek(args[2], args[3] + "*.fits"):
        ## Prepare destination directory
        outdir = os.path.dirname(
            f_img
        ) + "/Enhanced_Original/"  ## Needs to be commented when brightening
        if os.path.isdir(outdir) == False: os.mkdir(outdir)
        ## Outfile name
        p_img = outdir + "/" + os.path.basename(f_img)[:-5] + ".png"
        ## File conversion
        #os.system("ds9 "+f_img+" -minmax -colorbar no -saveimage png "+p_img+" -exit")
        try:
            hdulist = pyfits.open(f_img)
            scipy.misc.imsave(f_img[:-4] + "png", hdulist[0].data)
            i += 1
        except:
            pass
    print "ImageScript.py: FITStoPNG: Converted", i, "files to png format."
    return
Beispiel #9
0
def PSFtoPNG_all(args):
	for psffile in file_seek(args[2], "*.psf"):
		PSFtoPNG(psffile)		
	return
Beispiel #10
0
			krn_size = int(a)
		elif o in ("-s", "--fstr"):
			file_string = a
		elif o in ("--sim "):
			simul=True
		else:
			assert False, "Unhandled option."
			
	##--------------------------------------------------------------------
	
	## Is input a collection of files or directory?
	## filelist is a list of raw image files.
	filelist=[]
	for arg in args:
		if os.path.isfile(arg):  filelist+=[arg]
		elif os.path.isdir(arg): filelist+=file_seek(arg,file_string)
	
	if simul is False:
		single_deconvolve(filelist, krn_size, psf_width, vb)
	else:
		simultaneous_deconvolve(filelist, krn_size, vb)
	
	##--------------------------------------------------------------------
	
	if vb: print "deconvolve.py: deconvolution of",len(filelist),\
								"file(s) took",round(time.time()-t_init,3),"seconds."
	
	return

##============================================================
	
Beispiel #11
0
def bright_all(factor=8):
    for original in file_seek("../Data/", "CFHTLS_*sci.png"):
        brig(original, factor, 1)
    return
Beispiel #12
0
def all_psfs(topdir="~/Dropbox/Hogg_2012/Data/PSFs/",
             filestring="snap_*.fits"):
    for fitsfile in file_seek(topdir, filestring):
        GPSF(fitsfile)
    return
Beispiel #13
0
def PSFtoPNG_all(args):
    for psffile in file_seek(args[2], "*.psf"):
        PSFtoPNG(psffile)
    return
Beispiel #14
0
def all_psfs(topdir="~/Dropbox/Hogg_2012/Data/PSFs/", filestring="snap_*.fits"):	
	for fitsfile in file_seek(topdir, filestring):
		GPSF(fitsfile)
	return
Beispiel #15
0
def bright_all(factor=8):
	for original in file_seek("../Data/","CFHTLS_*sci.png"):
		brig(original,factor,1)
	return
Beispiel #16
0
			print main.__doc__
			return
		elif o in ("-v"):
			vb=True
		else:
			assert False, "Unhandled option"
			
	##--------------------------------------------------------------------
	

	t0=time.time()
	
	## If the input is a single file
	if os.path.isfile(args[0]):	fits_list = [args[0]]
	## If the input is a directory of files
	elif os.path.isdir(args[0]):	fits_list = file_seek(args[0], "CFHTLS_*sci.fits")
	
	## Run SExtractor and PSFEx on the image
	for fitsfile in fits_list:
		## Run SExtractor
		SEx(fitsfile, vb)		
		## Run PSFEx on fresh .cat
		PSFEx(fitsfile[:-4]+"cat", "snap", vb)
	
	
	if vb:
		print "\nSourceDiagnostics.py: analysed",len(fits_list),"FITS images."
		print "\tTook",round(time.time()-t0,2),"seconds."
		
	return
	
Beispiel #17
0
            return
        elif o in ("-v"):
            vb = True
        else:
            assert False, "Unhandled option"

    ##--------------------------------------------------------------------

    t0 = time.time()

    ## If the input is a single file
    if os.path.isfile(args[0]):
        fits_list = [args[0]]
        ## If the input is a directory of files
    elif os.path.isdir(args[0]):
        fits_list = file_seek(args[0], "CFHTLS_*sci.fits")

    ## Run SExtractor and PSFEx on the image
    for fitsfile in fits_list:
        ## Run SExtractor
        SEx(fitsfile, vb)
        ## Run PSFEx on fresh .cat
        PSFEx(fitsfile[:-4] + "cat", "snap", vb)

    if vb:
        print "\nSourceDiagnostics.py: analysed", len(
            fits_list), "FITS images."
        print "\tTook", round(time.time() - t0, 2), "seconds."

    return