Пример #1
0
  alpha = fwhm/(2.0*np.sqrt(2.0**(1/beta)-1.0))/0.2
  x,y   = np.mgrid[0:nx,0:ny]
  rr    = np.sqrt((x-xc)**2+(y-yc)**2) 
  image = flx*(beta-1.0)*(1+(rr/alpha)**2)**(-beta)/pi/alpha/alpha
    
  return image

#----------------------------------------------------------------------
def lnlike(theta,psfimage,sigsky,flux,beta,fwhm,nx,ny):
    xc,yc  = theta 
    model  = moff(xc,yc,fwhm,beta,flux,nx,ny)
    invsig = 1.0/(sigsky*sigsky)
    
    return -0.5*(np.sum(model-psfimage)**2*invsig-np.log(invsig))
#---------------------------------------------------------------------
etc = lsstetc.ETC('r',pixel_scale=0.2)
narr     = 2000
psf_fwhm = np.random.uniform(low=0.6,high=0.8,size=narr)
beta     = np.random.uniform(low=2.4,high=2.5,size=narr)
#psf_fwhm = 0.7
#beta     = 2.5
mag      = np.random.uniform(low=22.5,high=23.0,size=narr)

nx,ny    = 48,48
xin,yin  = 23.5,23.5
ic       = 0
while ic< narr:
    i =ic
    xc,yc    = np.random.uniform(low=xin-1.,high=xin+1,size=2)
    imnull   = galsim.Sersic(3.0,half_light_radius=1.9).withFlux(10000000.0).shear(e1=0.5,e2=-0.1)
    imm      = imnull.drawImage(nx=nx,ny=ny,scale=0.2)
Пример #2
0
shear_cata = para_path + "shear.npz"
shear = numpy.load(shear_cata)
g1 = shear["arr_0"][shear_id]
g2 = shear["arr_1"][shear_id]

paras = para_path + "para_%d.hdf5" % shear_id
f = h5py.File(paras, 'r')
e1s = f["/e1"].value
e2s = f["/e2"].value
radius = f["/radius"].value
flux = f["/flux"].value
fbt = f['/btr'].value
f.close()

prop = lsstetc.ETC(band='r',
                   pixel_scale=pixel_scale,
                   stamp_size=stamp_size,
                   nvisits=180)
noise_sig = prop.sigma_sky

psf = galsim.Moffat(beta=3.5, scale_radius=0.8, flux=1.0)
psf_img = galsim.ImageD(stamp_size, stamp_size)
psf.drawImage(image=psf_img, scale=pixel_scale)

#psf = psf_o.shear(e1=0.081, e2=-0.066)

if rank == 0:
    hdu = fits.PrimaryHDU(psf_img.array)
    psf_path = total_path + 'psf.fits'
    hdu.writeto(psf_path, overwrite=True)
    logger.info(
        "size: %d, pixel_scale: %.2f, noise_sig: %.2f, total galaxy number: %d"
Пример #3
0
def main():

    xc = 32.
    yc = 32.
    dx = 2.5
    dy = 3.5

    beta = 2.4
    fwhm = 0.7
    etc = lsstetc.ETC('r', pixel_scale=0.2)
    flux = etc.flux(20.0)
    nax = 64
    imnull = gs.Sersic(2.0, half_light_radius=0.1).withFlux(0.0)
    imm = imnull.drawImage(nx=nax, ny=nax, scale=0.2)
    noise = gs.GaussianNoise(sigma=etc.sigma_sky)
    #imm.addNoise(noise)
    noiseim = imm.array

    psfmock = moff(xc, yc, fwhm, beta, flux, nax, nax) + noiseim
    shiftvec = [dy, dx]
    psfshift = ndimg.shift(psfmock, shiftvec) + noiseim

    #fftimgcen= np.fft.fftshift(np.abs(np.fft.fft2(psfmock)))
    fftimgcen = np.fft.fftshift(np.fft.fft2(psfmock))
    #fftimgcen= (np.fft.fft2(psfmock))
    #fftimgoff= np.fft.fftshift(np.abs(np.fft.fft2(psfshift)))
    #fftimgoff= np.fft.fft2(psfshift)
    fftimgoff = np.fft.fftshift((np.fft.fft2(psfshift)))
    fftimgceni = np.log(np.imag(np.fft.fftshift(np.fft.fft2(psfmock))))
    fftimgcenr = np.log(np.real(np.fft.fftshift(np.fft.fft2(psfmock))))
    fftimgoffi = np.log(np.imag(np.fft.fftshift(np.fft.fft2(psfshift))))
    fftimgoffr = np.log(np.real(np.fft.fftshift(np.fft.fft2(psfshift))))
    phase1 = getphase(fftimgcen)
    phase2 = getphase(fftimgoff)

    #test=(np.mod(phase1,pi))
    test = np.floor(phase1 / pi)
    ixa = (phase1) >= 3.0
    ixb = (phase1) <= -3.0
    #phase1[ixa]=phase1[ixa]-pi
    #phase1[ixb]=phase1[ixb]+pi

    #plt.hist(phase2.reshape(64*64),50,facecolor='blue')
    #plt.hist(phase1.reshape(64*64),50,facecolor='red')
    #plt.show()
    ftsize = 18
    fig, axes = plt.subplots(2, 2)
    print np.max(test), np.min(test)
    #plt.subplot(2,2,1)
    axes[0, 0].imshow(np.log10(psfmock), interpolation='nearest')
    axes[0, 0].set_title('perfectly centered', fontsize=ftsize)
    axes[0, 0].hlines(32, xmin=0, xmax=64)
    axes[0, 0].vlines(32, 0, 64)
    #plt.subplot(2,2,2)
    #im=axes[0,1].imshow((phase1%pi)%pi,interpolation='nearest')
    im = axes[0, 1].imshow(phase1, interpolation='nearest')
    #plt.hlines(32,xmin=0,xmax=64)
    #plt.vlines(32,0,64)
    #plt.imshow((phase1%pi)%pi,interpolation='nearest')
    plt.colorbar(im, ax=axes[0, 1])
    axes[0, 1].set_title('phase pattern', fontsize=ftsize)
    #plt.subplot(2,2,3)
    axes[1, 0].imshow(np.log10(psfshift), interpolation='nearest')
    #plt.hlines(32,xmin=0,xmax=48)
    #axes[1,0].set_vlines(24,ymin=0,ymax=48,ls='--')
    axes[1, 0].set_title('off centered', fontsize=ftsize)
    im2 = axes[1, 1].imshow((phase2 % pi) % pi, interpolation='nearest')
    axes[1, 0].hlines(32, xmin=0, xmax=64)
    axes[1, 0].vlines(32, 0, 64)
    plt.colorbar(im2, ax=axes[1, 1])
    axes[1, 1].set_title('phase pattern', fontsize=ftsize)
    fig.tight_layout()
    plt.subplots_adjust(wspace=-0.5, hspace=0.3)
    plt.savefig('phase_pattern.eps')
    plt.show()
Пример #4
0
def main():
    narr = 8000
    imstar_3d = np.zeros((narr, 48 * 48))
    for i in range(narr):
        #fname    = 'shiftims/shifted_'+str(i+1)+'.fits'
        fname = 'test_04_13/starim_shifted_' + str(i + 1) + '.fits'
        #fname    = 'test_04_13/starim_original_'+str(i+1)+'.fits'
        #fname    = 'cfht_stars_for_pca/starim_'+str(i+1)+'.fits'
        image = pf.getdata(fname)
        imstar_3d[i][:] = image.reshape(48 * 48) / np.sum(image)

    etc = lsst.ETC('r', pixel_scale=0.2)
    flux = etc.flux(23.0)
    psim = 0.0
    xfc, yfc = np.mgrid[:48, :48]
    fac = 1. + 0.01 + 0.5 * xfc + 0.5 * yfc + 0.1 * xfc**2 + 0.2 * yfc**2 + 0.1 * xfc * yfc
    #for i in range(1000):
    #   noise = gs.GaussianNoise(sigma=etc.sigma_sky)
    #   gal   = gs.Sersic(2.5,half_light_radius=0.6).withFlux(flux).shear(e1=0.3,e2=0.1)
    #   img   = gal.drawImage(nx=48,ny=48,scale=0.2)
    #   img.addNoise(noise)
    #   galimg= fac*img
    #   psim  = psim+np.real(np.fft.fftshift(galimg)*np.fft.fftshift(galimg))
    #print np.max(img.array),np.min(img.array)

    noise = gs.GaussianNoise(sigma=etc.sigma_sky)
    gal = gs.Sersic(2.5, half_light_radius=0.6).withFlux(flux).shear(e1=0.3,
                                                                     e2=0.1)
    img = gal.drawImage(nx=48, ny=48, scale=0.2)
    galim = fac * img.array
    img.addNoise(noise)
    #psim  = psim+np.real(np.fft.fftshift(img.array)*np.conj(np.fft.fftshift(img.array)))
    #galim = img.array
    #psim  = psim+np.real(np.fft.fft2(galim)*np.conj(np.fft.fft2(galim)))
    #psim  = psim+np.real(fft2d(galim)*np.conj(fft2d(galim)))
    psfc = np.fft.fftshift(np.abs(np.fft.fft2(galim))**2)
    #plt.subplot(2,1,1)
    #plt.imshow(galim,interpolation='nearest')
    #plt.subplot(2,1,2)
    #plt.imshow(psim,interpolation='nearest')
    #plt.show()

    pcstr = pcaimages(imstar_3d)
    com0 = pcstr['comps'][0]
    com1 = pcstr['comps'][1]
    com2 = pcstr['comps'][2]
    com3 = pcstr['comps'][3]
    com4 = pcstr['comps'][4]
    com5 = pcstr['comps'][5]
    com6 = pcstr['comps'][6]
    com7 = pcstr['comps'][7]
    com8 = pcstr['comps'][8]
    com9 = pcstr['comps'][9]
    com10 = pcstr['comps'][10]
    com11 = pcstr['comps'][11]
    com12 = pcstr['comps'][12]
    com13 = pcstr['comps'][13]
    com14 = pcstr['comps'][14]
    com15 = pcstr['comps'][15]
    #print com0
    psim1 = np.fft.fftshift(np.abs(np.fft.fft2(com3.reshape((48, 48)))))
    psim2 = np.fft.fftshift(np.abs(np.fft.fft2(com4.reshape((48, 48)))))
    psim3 = np.fft.fftshift(np.abs(np.fft.fft2(com5.reshape((48, 48)))))
    #psfc=np.fft.fftshift(np.abs(np.fft.fft2(fac))**2)
    #print np.max(psim),np.max(psfc)
    #psim=np.real(np.fft.fftshift(img.array)*np.fft.fftshift(img.array))
    #psim=np.real(np.fft.fft2(img.array)*np.fft.fft2(img.array))
    plt.subplot(4, 4, 1)
    plt.imshow(com0.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 2)
    plt.imshow(com1.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 3)
    plt.imshow(com2.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 4)
    plt.imshow(com3.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 5)
    plt.imshow(com4.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 6)
    plt.imshow(com5.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 7)
    plt.imshow(com6.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 8)
    plt.imshow(com7.reshape((48, 48)), interpolation='nearest')
    #plt.imshow(psim2,interpolation='nearest')
    plt.subplot(4, 4, 9)
    plt.imshow(com8.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 10)
    plt.imshow(com9.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 11)
    plt.imshow(com10.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 12)
    plt.imshow(com11.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 13)
    plt.imshow(psfc.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 14)
    plt.imshow(psim3.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 15)
    plt.imshow(psim2.reshape((48, 48)), interpolation='nearest')
    plt.subplot(4, 4, 16)
    plt.imshow(psim3.reshape((48, 48)) / psim3.sum() + psfc / psfc.sum(),
               interpolation='nearest')
    #plt.imshow(psim3,interpolation='nearest')
    plt.show()
Пример #5
0
                           minimum_fft_size=64)

optics = galsim.OpticalPSF(lam_over_diam,
                           coma1=-0.,
                           coma2=-0.14,
                           gsparams=gsparams)

coma = optics.drawImage()
plt.imshow(coma.array, interpolation='nearest')
plt.colorbar()
plt.savefig('anisotropy_2.eps')
plt.show()

narr = 2000
pixscale = 0.2
etc = lsstetc.ETC('r', pixel_scale=pixscale)
scales = 2.0
opt_defocus = np.random.uniform(low=0.0, high=0.53 / scales, size=narr)
opt_a1 = np.random.uniform(low=0.0, high=-0.29 / scales, size=narr)
opt_a2 = np.random.uniform(low=0.0, high=0.12 / scales, size=narr)
opt_c1 = np.random.uniform(low=0.0, high=0.64 / scales, size=narr)
opt_c2 = np.random.uniform(low=0.0, high=-0.33 / scales, size=narr)
opt_obscuration = np.random.uniform(low=0.0, high=0.3 / scales, size=narr)
psf_fwhm = np.random.uniform(low=0.5, high=0.7, size=narr)
beta = np.random.uniform(low=2.2, high=2.5, size=narr)
mag = np.random.uniform(low=22.5, high=23.0, size=narr)

nx, ny = 48, 48
xin, yin = 23.5, 23.5
ic = 0
ep1 = -0.03