def hoggtest(): t0 = time.time() ## Define true scene, kernel, and data ## Arguments are image size, width of Gaussian (x,y), centre (x,y), total flux scene_t = DT.Gauss_2D(*[31, 4., 4., 15, 15, 1.]) kernel_t = DT.Gauss_2D(*[11, 3., 3., 5, 5, 1.]) data_t = DT.Gauss_2D(*[31, 5., 5., 15, 15, 1.]) scipy.misc.imsave("hoggtest_scene_true.png", scene_t) scipy.misc.imsave("hoggtest_kernel_true.png", kernel_t) scipy.misc.imsave("hoggtest_data_true.png", data_t) ## Use code. ## Data: convolve the scene with the kernel data = scipy.signal.fftconvolve(scene_t, kernel_t, "same") scipy.misc.imsave("hoggtest_data.png", data) ## Kernel: data = scene * k --> kernel kernel = DT.get_kernel(scene_t, data_t, [11,11], False) scipy.misc.imsave("hoggtest_kernel.png",kernel) ## Scene: data = scene * k --> scene scene = DT.deconvolve_image(data_t, kernel_t, False) scipy.misc.imsave("hoggtest_scene.png",scene) ## Moments #print DT.moments(scene) #print DT.moments(kernel) #print DT.moments(data) print "Total time:",round(time.time()-t0,3),"seconds." return
def imdectest(): t0 = time.time() ## Make composite image psfobs = DT.Gauss_2D(*[50, 7., 7., 25, 25, 1.]) scipy.misc.imsave("imdec_psfobs.png",psfobs) bigorig = numpy.tile(psfobs, [2,2]) scipy.misc.imsave("imdec_obig.png",bigorig) ## Target psfref = DT.Gauss_2D(*[50, 3., 3., 25, 25, 1.]) scipy.misc.imsave("imdec_psfref.png",psfref) ## Kernel: psfobs = psfref * k --> kernel kernarr = DT.get_kernel(psfref, psfobs, [5,5], False) scipy.misc.imsave("imdec_kern.png",kernarr) ## Deconvolution: img = kern * refimg --> refimg decarr = DT.deconvolve_image(psfobs, kernarr, vb=False) scipy.misc.imsave("imdec_odec.png",decarr) print "Total",round(time.time()-t0,3) return
def hoggtest(): t0 = time.time() ## Define true scene, kernel, and data ## Arguments are image size, width of Gaussian (x,y), centre (x,y), total flux scene_t = DT.Gauss_2D(*[31, 4., 4., 15, 15, 1.]) kernel_t = DT.Gauss_2D(*[11, 3., 3., 5, 5, 1.]) data_t = DT.Gauss_2D(*[31, 5., 5., 15, 15, 1.]) scipy.misc.imsave("hoggtest_scene_true.png", scene_t) scipy.misc.imsave("hoggtest_kernel_true.png", kernel_t) scipy.misc.imsave("hoggtest_data_true.png", data_t) ## Use code. ## Data: convolve the scene with the kernel data = scipy.signal.fftconvolve(scene_t, kernel_t, "same") scipy.misc.imsave("hoggtest_data.png", data) ## Kernel: data = scene * k --> kernel kernel = DT.get_kernel(scene_t, data_t, [11, 11], False) scipy.misc.imsave("hoggtest_kernel.png", kernel) ## Scene: data = scene * k --> scene scene = DT.deconvolve_image(data_t, kernel_t, False) scipy.misc.imsave("hoggtest_scene.png", scene) ## Moments #print DT.moments(scene) #print DT.moments(kernel) #print DT.moments(data) print "Total time:", round(time.time() - t0, 3), "seconds." return
def imdectest(): t0 = time.time() ## Make composite image psfobs = DT.Gauss_2D(*[50, 7., 7., 25, 25, 1.]) scipy.misc.imsave("imdec_psfobs.png", psfobs) bigorig = numpy.tile(psfobs, [2, 2]) scipy.misc.imsave("imdec_obig.png", bigorig) ## Target psfref = DT.Gauss_2D(*[50, 3., 3., 25, 25, 1.]) scipy.misc.imsave("imdec_psfref.png", psfref) ## Kernel: psfobs = psfref * k --> kernel kernarr = DT.get_kernel(psfref, psfobs, [5, 5], False) scipy.misc.imsave("imdec_kern.png", kernarr) ## Deconvolution: img = kern * refimg --> refimg decarr = DT.deconvolve_image(psfobs, kernarr, vb=False) scipy.misc.imsave("imdec_odec.png", decarr) print "Total", round(time.time() - t0, 3) return
def simultaneous_deconvolve(filelist, krn_size, vb): s2_max = 0.0 ## Find largest PSF in ensemble for infile in filelist: ## Run SExtractor to generate source-catalogue catfile = SD.SEx(infile, vb) ## Run PSFEx to generate model image of PSF psf_obs = SD.PSFEx(catfile, "snap", vb) ### NEED to find FWHM from images without going through the ### following rigmarole: ## Convert PSF image to an array psf_obs = IM.pngcropwhite(IM.fits_pix(psf_obs)) ## Here is how we decide what PSF to use ## Product of the two widths = s2 m = DT.moments(psf_obs) s2 = m[1] * m[2] ## Which image has largest s2? Call this psf_OBS. if s2 > s2_max: s2_max = s2 psf_OBS = psf_obs ##------------------------------------------------------------ ## Make target psf array psf_ref = DT.Gauss_2D(*DT.moments(psf_OBS)) ## Calculate kernel array for obs->ref kernarr = DT.get_kernel(psf_OBS, psf_ref, [krn_size, krn_size], vb) ##------------------------------------------------------------ ## Deconvolve to the target PSF for infile in filelist: DT.deconvolve_image(infile, kernarr, vb) return
def simultaneous_deconvolve(filelist, krn_size, vb): s2_max = 0.0 ## Find largest PSF in ensemble for infile in filelist: ## Run SExtractor to generate source-catalogue catfile = SD.SEx(infile, vb) ## Run PSFEx to generate model image of PSF psf_obs = SD.PSFEx(catfile, "snap", vb) ### NEED to find FWHM from images without going through the ### following rigmarole: ## Convert PSF image to an array psf_obs = IM.pngcropwhite(IM.fits_pix(psf_obs)) ## Here is how we decide what PSF to use ## Product of the two widths = s2 m=DT.moments(psf_obs) s2 = m[1]*m[2] ## Which image has largest s2? Call this psf_OBS. if s2 > s2_max: s2_max = s2 psf_OBS = psf_obs ##------------------------------------------------------------ ## Make target psf array psf_ref = DT.Gauss_2D(*DT.moments(psf_OBS)) ## Calculate kernel array for obs->ref kernarr = DT.get_kernel(psf_OBS, psf_ref, [krn_size,krn_size],vb) ##------------------------------------------------------------ ## Deconvolve to the target PSF for infile in filelist: DT.deconvolve_image(infile, kernarr, vb) return
def single_deconvolve(filelist, krn_size, vb): ## Deconvolve all FITS images in list for infile in filelist: ## Run SExtractor to generate source-catalogue catfile = SD.SEx(infile, vb) ## Run PSFEx to generate model image of PSF psf_obs = SD.PSFEx(catfile, "snap", vb) ## Intermediate step: convert PSF image to an array psf_obs = IM.pngcropwhite(IM.fits_pix(psf_obs)) ## Make target psf array psf_ref = DT.Gauss_2D(*DT.moments(psf_obs)) ## Calculate kernel array kernarr = DT.get_kernel(psf_obs, psf_ref, [krn_size, krn_size], vb) ## Deconvolve image DT.deconvolve_image(infile, kernarr, vb) return
def single_deconvolve(filelist, krn_size, vb): ## Deconvolve all FITS images in list for infile in filelist: ## Run SExtractor to generate source-catalogue catfile = SD.SEx(infile, vb) ## Run PSFEx to generate model image of PSF psf_obs = SD.PSFEx(catfile, "snap", vb) ## Intermediate step: convert PSF image to an array psf_obs = IM.pngcropwhite(IM.fits_pix(psf_obs)) ## Make target psf array psf_ref = DT.Gauss_2D(*DT.moments(psf_obs)) ## Calculate kernel array kernarr = DT.get_kernel(psf_obs, psf_ref,[krn_size,krn_size],vb) ## Deconvolve image DT.deconvolve_image(infile, kernarr, vb) return
def decontest(): ## Original image parameters imwidth = 50 o_pars = [imwidth, 5., 5., imwidth / 2, imwidth / 2, 1.] ## Noise model paramters mu = 0.01 sigma = 0.005 ## Reference PSF paramters rPSF_pars = [imwidth, 2., 2., imwidth / 2, imwidth / 2, 1.] ## Deconvolution krn_size = 15 ##---------------------------------------------------------- ## Original image, a point at (0,0) with a Gaussian PSF origarr = DT.Gauss_2D(*o_pars) scipy.misc.imsave("original.png", origarr) ## Noise origarr += 0.3 * origarr.max() * scipy.random.standard_normal( origarr.shape) + 0.2 * origarr.max() scipy.misc.imsave("original+noise.png", origarr) ## Sensible range origarr.clip(0, 1) ##---------------------------------------------------------- ## Reference PSF psf_ref = DT.Gauss_2D(*rPSF_pars) scipy.misc.imsave("decon_psf_ref.png", psf_ref) ## Calculate deconvolution-kernel array kernarr = DT.get_kernel(origarr, psf_ref, [krn_size, krn_size], False) ## Deconvolve image decarr = DT.deconvolve_image(origarr, kernarr) ##---------------------------------------------------------- ## Residuals psf_ref = DT.shave(decarr.shape, psf_ref) resarr = psf_ref - decarr resarr -= resarr.min() ## Shift zero resarr /= resarr.max() ## Put in range [0,1] ### Need to stretch ### scipy.misc.imsave("decon_residuals.png", resarr) return
def decontest(): ## Original image parameters imwidth = 50 o_pars = [imwidth, 5., 5., imwidth/2, imwidth/2, 1.] ## Noise model paramters mu = 0.01; sigma = 0.005 ## Reference PSF paramters rPSF_pars = [imwidth, 2., 2., imwidth/2, imwidth/2, 1.] ## Deconvolution krn_size = 15 ##---------------------------------------------------------- ## Original image, a point at (0,0) with a Gaussian PSF origarr = DT.Gauss_2D(*o_pars) scipy.misc.imsave("original.png",origarr) ## Noise origarr += 0.3*origarr.max()*scipy.random.standard_normal(origarr.shape)+0.2*origarr.max() scipy.misc.imsave("original+noise.png",origarr) ## Sensible range origarr.clip(0,1) ##---------------------------------------------------------- ## Reference PSF psf_ref = DT.Gauss_2D(*rPSF_pars) scipy.misc.imsave("decon_psf_ref.png",psf_ref) ## Calculate deconvolution-kernel array kernarr = DT.get_kernel(origarr, psf_ref,[krn_size,krn_size], False) ## Deconvolve image decarr = DT.deconvolve_image(origarr, kernarr) ##---------------------------------------------------------- ## Residuals psf_ref = DT.shave(decarr.shape, psf_ref) resarr = psf_ref - decarr resarr -= resarr.min() ## Shift zero resarr /= resarr.max() ## Put in range [0,1] ### Need to stretch ### scipy.misc.imsave("decon_residuals.png", resarr) return