def single_run_test(ind,ysc1,ysc2,q,vd,pha,zl,zs):
    dsx_sdss     = 0.396         # pixel size of SDSS detector.
    R  = 3.0000     #
    nnn = 300      #Image dimension
    bsz = 9.0 # arcsecs
    dsx = bsz/nnn         # pixel size of SDSS detector.
    nstd = 59 #^2

    xx01 = np.linspace(-bsz/2.0,bsz/2.0,nnn)+0.5*dsx
    xx02 = np.linspace(-bsz/2.0,bsz/2.0,nnn)+0.5*dsx
    xi2,xi1 = np.meshgrid(xx01,xx02)
    #----------------------------------------------------------------------
    dsi = 0.03
    g_source = pyfits.getdata("./439.0_149.482739_1.889989_processed.fits")
    g_source = np.array(g_source,dtype="<d")*10.0
    g_source[g_source<=0.0001] = 1e-6
    #----------------------------------------------------------------------
    xc1 = 0.0       #x coordinate of the center of lens (in units of Einstein radius).
    xc2 = 0.0       #y coordinate of the center of lens (in units of Einstein radius).
    #q   = 0.7       #Ellipticity of lens.
    rc  = 0.0       #Core size of lens (in units of Einstein radius).
    re  = re_sv(vd,zl,zs)       #Einstein radius of lens.
    #pha = 45.0      #Orintation of lens.
    lpar = np.asarray([xc1,xc2,q,rc,re,pha])
    #----------------------------------------------------------------------
    ai1,ai2,mua = lens_equation_sie(xi1,xi2,lpar)

    yi1 = xi1-ai1
    yi2 = xi2-ai2

    g_limage = lv4.call_ray_tracing(g_source,xi1,xi2,ysc1,ysc2,dsi)
    g_limage[g_limage<=0.0001] = 1e-6
    g_limage = p2p.cosccd2mag(g_limage)
    g_limage = p2p.mag2sdssccd(g_limage)

    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    dA = Planck13.comoving_distance(zl).value*1000./(1+zl)
    Re = dA*np.sin(R*np.pi/180./3600.)
    counts  =Brightness(Re,vd)
    vpar = np.asarray([counts,R,xc1,xc2,q,pha])
    #g_lens = deVaucouleurs(xi1,xi2,xc1,xc2,counts,R,1.0-q,pha)
    g_lens = de_vaucouleurs_2d(xi1,xi2,vpar)

    #pl.figure()
    #pl.contourf(g_lens)
    #pl.colorbar()

    g_clean_ccd1 = g_lens*0.0+g_limage
    g_clean_ccd2 = g_lens*1.0+g_limage
    from scipy.ndimage.filters import gaussian_filter
    pl.figure()
    pl.contourf(g_clean_ccd1)
    pl.colorbar()
    pl.savefig("/Users/uranus/GitHub/data_arc_finding_cnn/unlensed_output_pngs/"+str(i)+"_lensed_imgs_only.png")
    #-------------------------------------------------------------
    g_images_psf1 = gaussian_filter(g_clean_ccd1, 2.0)
    g_images_psf2 = gaussian_filter(g_clean_ccd2, 2.0)
    #g_images_psf = ss.convolve(g_clean_ccd,g_psf,mode="same")
    #g_images_psf = g_clean_ccd
    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    g_noise = noise_map(nnn,nnn,np.sqrt(nstd),"Gaussian")
    #output_filename = "./output_fits/noise_map.fits"
    #pyfits.writeto(output_filename,g_noise,clobber=True)
    #-------------------------------------------------------------
    g_final1 = g_images_psf1+g_noise
    output_filename = "/Users/uranus/GitHub/data_arc_finding_cnn/unlensed_output_fits/"+str(i)+"_lensed_imgs_only.fits"
    pyfits.writeto(output_filename,g_final1,clobber=True)
    #-------------------------------------------------------------
    g_final2 = g_images_psf2+g_noise
    output_filename = "/Users/uranus/GitHub/data_arc_finding_cnn/unlensed_output_fits/"+str(i)+"_all_imgs.fits"
    pyfits.writeto(output_filename,g_final2,clobber=True)

    return 0
示例#2
0
def single_run_test(ind, ysc1, ysc2, q, vd, pha, zl, zs):
    dsx_sdss = 0.396  # pixel size of SDSS detector.
    R = 3.0000  #
    nnn = 300  #Image dimension
    bsz = 9.0  # arcsecs
    dsx = bsz / nnn  # pixel size of SDSS detector.
    nstd = 59  #^2

    xx01 = np.linspace(-bsz / 2.0, bsz / 2.0, nnn) + 0.5 * dsx
    xx02 = np.linspace(-bsz / 2.0, bsz / 2.0, nnn) + 0.5 * dsx
    xi2, xi1 = np.meshgrid(xx01, xx02)
    #----------------------------------------------------------------------
    dsi = 0.03
    g_source = pyfits.getdata("./439.0_149.482739_1.889989_processed.fits")
    g_source = np.array(g_source, dtype="<d") * 10.0
    g_source[g_source <= 0.0001] = 1e-6
    #----------------------------------------------------------------------
    xc1 = 0.0  #x coordinate of the center of lens (in units of Einstein radius).
    xc2 = 0.0  #y coordinate of the center of lens (in units of Einstein radius).
    #q   = 0.7       #Ellipticity of lens.
    rc = 0.0  #Core size of lens (in units of Einstein radius).
    re = re_sv(vd, zl, zs)  #Einstein radius of lens.
    #pha = 45.0      #Orintation of lens.
    lpar = np.asarray([xc1, xc2, q, rc, re, pha])
    #----------------------------------------------------------------------
    ai1, ai2, mua = lens_equation_sie(xi1, xi2, lpar)

    yi1 = xi1 - ai1
    yi2 = xi2 - ai2

    g_limage = lv4.call_ray_tracing(g_source, yi1, yi2, ysc1, ysc2, dsi)
    g_limage[g_limage <= 0.0001] = 1e-6
    g_limage = p2p.cosccd2mag(g_limage)
    g_limage = p2p.mag2sdssccd(g_limage)

    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    dA = Planck13.comoving_distance(zl).value * 1000. / (1 + zl)
    Re = dA * np.sin(R * np.pi / 180. / 3600.)
    counts = Brightness(Re, vd)
    vpar = np.asarray([counts, R, xc1, xc2, q, pha])
    #g_lens = deVaucouleurs(xi1,xi2,xc1,xc2,counts,R,1.0-q,pha)
    g_lens = de_vaucouleurs_2d(xi1, xi2, vpar)

    #pl.figure()
    #pl.contourf(g_lens)
    #pl.colorbar()

    g_clean_ccd1 = g_lens * 0.0 + g_limage
    g_clean_ccd2 = g_lens * 1.0 + g_limage
    from scipy.ndimage.filters import gaussian_filter
    pl.figure()
    pl.contourf(g_clean_ccd1)
    pl.colorbar()
    pl.savefig("./output_pngs/" + str(i) + "_lensed_imgs_only.png")
    #-------------------------------------------------------------
    g_images_psf1 = gaussian_filter(g_clean_ccd1, 2.0)
    g_images_psf2 = gaussian_filter(g_clean_ccd2, 2.0)
    #g_images_psf = ss.convolve(g_clean_ccd,g_psf,mode="same")
    #g_images_psf = g_clean_ccd
    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    g_noise = noise_map(nnn, nnn, np.sqrt(nstd), "Gaussian")
    #output_filename = "./output_fits/noise_map.fits"
    #pyfits.writeto(output_filename,g_noise,clobber=True)
    #-------------------------------------------------------------
    g_final1 = g_images_psf1 + g_noise
    output_filename = "./output_fits/" + str(i) + "_lensed_imgs_only.fits"
    pyfits.writeto(output_filename, g_final1, clobber=True)
    #-------------------------------------------------------------
    g_final2 = g_images_psf2 + g_noise
    output_filename = "./output_fits/" + str(i) + "_all_imgs.fits"
    pyfits.writeto(output_filename, g_final2, clobber=True)

    return 0
示例#3
0
def single_run_test(ind,ysc1,ysc2,q,vd,pha,zl,zs):
    dsx_sdss     = 0.396         # pixel size of SDSS detector.
    R  = 3.0000     #
    #zl = 0.2     #zl is the redshift of the lens galaxy.
    #zs = 1.0
    #vd = 520    #Velocity Dispersion.
    nnn = 128      #Image dimension
    bsz = dsx_sdss*nnn # arcsecs
    dsx = bsz/nnn         # pixel size of SDSS detector.
    nstd = 59 #^2

    xx01 = np.linspace(-bsz/2.0,bsz/2.0,nnn)+0.5*dsx
    xx02 = np.linspace(-bsz/2.0,bsz/2.0,nnn)+0.5*dsx
    xi2,xi1 = np.meshgrid(xx01,xx02)
    #----------------------------------------------------------------------
    #ysc1 = 0.2
    #ysc2 = 0.5
    dsi = 0.03
    g_source = pyfits.getdata("./439.0_149.482739_1.889989_processed.fits")
    g_source = np.array(g_source,dtype="<d")*10.0
    g_source[g_source<=0.0001] = 1e-6
    #print np.sum(g_source)
    #print np.max(g_source)
    #pl.figure()
    #pl.contourf(g_source)
    #pl.colorbar()
    #g_source = p2p.cosccd2mag(g_source)
    ##g_source = p2p.mag2sdssccd(g_source)
    ##print np.max(g_source*13*13*52.0)
    #pl.figure()
    #pl.contourf(g_source)
    #pl.colorbar()
    #----------------------------------------------------------------------
    xc1 = 0.0       #x coordinate of the center of lens (in units of Einstein radius).
    xc2 = 0.0       #y coordinate of the center of lens (in units of Einstein radius).
    #q   = 0.7       #Ellipticity of lens.
    rc  = 0.0       #Core size of lens (in units of Einstein radius).
    re  = re_sv(vd,zl,zs)       #Einstein radius of lens.
    #pha = 45.0      #Orintation of lens.
    lpar = np.asarray([xc1,xc2,q,rc,re,pha])
    #----------------------------------------------------------------------
    ai1,ai2,mua = lens_equation_sie(xi1,xi2,lpar)

    yi1 = xi1-ai1
    yi2 = xi2-ai2

    g_limage = lv4.call_ray_tracing(g_source,yi1,yi2,ysc1,ysc2,dsi)
    g_limage[g_limage<=0.0001] = 1e-6
    g_limage = p2p.cosccd2mag(g_limage)
    g_limage = p2p.mag2sdssccd(g_limage)

    #pl.figure()
    #pl.imshow((g_limage),interpolation='lanczos',cmap=cm.gray)
    #pl.colorbar()

    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    dA = Planck13.comoving_distance(zl).value*1000./(1+zl)
    Re = dA*np.sin(R*np.pi/180./3600.)
    counts  =Brightness(Re,vd)
    vpar = np.asarray([counts,R,xc1,xc2,q,pha])
    #g_lens = deVaucouleurs(xi1,xi2,xc1,xc2,counts,R,1.0-q,pha)
    g_lens = de_vaucouleurs_2d(xi1,xi2,vpar)

    #pl.figure()
    #pl.imshow((g_lens),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    g_clean_ccd = g_lens+g_limage

    #pl.figure()
    #pl.imshow((g_clean_ccd),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    g_clean_ccd = congrid.congrid(g_clean_ccd,[128,128])

    #-------------------------------------------------------------
    file_psf = "../PSF_and_noise/sdsspsf.fits"
    g_psf = pyfits.getdata(file_psf)-1000.0
    g_psf = g_psf/np.sum(g_psf)

    #new_shape=[0,0]
    #new_shape[0]=np.shape(g_psf)[0]*dsx_sdss/dsx
    #new_shape[1]=np.shape(g_psf)[1]*dsx_sdss/dsx
    #g_psf = rebin_psf(g_psf,new_shape)

    g_images_psf = ss.fftconvolve(g_clean_ccd,g_psf,mode="same")
    #g_images_psf = ss.convolve(g_clean_ccd,g_psf,mode="same")
    #g_images_psf = g_clean_ccd

    #pl.figure()
    #pl.imshow((g_psf),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    #g_noise = noise_map(nnn,nnn,np.sqrt(nstd),"Gaussian")
    g_noise = noise_map(128,128,np.sqrt(nstd),"Gaussian")
    g_final = g_images_psf+g_noise

    #pl.figure()
    #pl.imshow((g_final.T),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    g_final_rebin = congrid.congrid(g_final,[128,128])

    #pl.figure()
    #pl.imshow((g_final_rebin.T),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

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

    output_filename = "../output_fits/"+str(ind)+".fits"
    pyfits.writeto(output_filename,g_final_rebin,clobber=True)

    pl.show()

    return 0
示例#4
0
def single_run_test(ind, ysc1, ysc2, q, vd, pha, zl, zs):
    dsx_sdss = 0.396  # pixel size of SDSS detector.
    R = 3.0000  #
    #zl = 0.2     #zl is the redshift of the lens galaxy.
    #zs = 1.0
    #vd = 520    #Velocity Dispersion.
    nnn = 128  #Image dimension
    bsz = dsx_sdss * nnn  # arcsecs
    dsx = bsz / nnn  # pixel size of SDSS detector.
    nstd = 59  #^2

    xx01 = np.linspace(-bsz / 2.0, bsz / 2.0, nnn) + 0.5 * dsx
    xx02 = np.linspace(-bsz / 2.0, bsz / 2.0, nnn) + 0.5 * dsx
    xi2, xi1 = np.meshgrid(xx01, xx02)
    #----------------------------------------------------------------------
    #ysc1 = 0.2
    #ysc2 = 0.5
    dsi = 0.03
    g_source = pyfits.getdata("./439.0_149.482739_1.889989_processed.fits")
    g_source = np.array(g_source, dtype="<d") * 10.0
    g_source[g_source <= 0.0001] = 1e-6
    #print np.sum(g_source)
    #print np.max(g_source)
    #pl.figure()
    #pl.contourf(g_source)
    #pl.colorbar()
    #g_source = p2p.cosccd2mag(g_source)
    ##g_source = p2p.mag2sdssccd(g_source)
    ##print np.max(g_source*13*13*52.0)
    #pl.figure()
    #pl.contourf(g_source)
    #pl.colorbar()
    #----------------------------------------------------------------------
    xc1 = 0.0  #x coordinate of the center of lens (in units of Einstein radius).
    xc2 = 0.0  #y coordinate of the center of lens (in units of Einstein radius).
    #q   = 0.7       #Ellipticity of lens.
    rc = 0.0  #Core size of lens (in units of Einstein radius).
    re = re_sv(vd, zl, zs)  #Einstein radius of lens.
    #pha = 45.0      #Orintation of lens.
    lpar = np.asarray([xc1, xc2, q, rc, re, pha])
    #----------------------------------------------------------------------
    ai1, ai2, mua = lens_equation_sie(xi1, xi2, lpar)

    yi1 = xi1 - ai1
    yi2 = xi2 - ai2

    g_limage = lv4.call_ray_tracing(g_source, yi1, yi2, ysc1, ysc2, dsi)
    g_limage[g_limage <= 0.0001] = 1e-6
    g_limage = p2p.cosccd2mag(g_limage)
    g_limage = p2p.mag2sdssccd(g_limage)

    #pl.figure()
    #pl.imshow((g_limage),interpolation='lanczos',cmap=cm.gray)
    #pl.colorbar()

    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    dA = Planck13.comoving_distance(zl).value * 1000. / (1 + zl)
    Re = dA * np.sin(R * np.pi / 180. / 3600.)
    counts = Brightness(Re, vd)
    vpar = np.asarray([counts, R, xc1, xc2, q, pha])
    #g_lens = deVaucouleurs(xi1,xi2,xc1,xc2,counts,R,1.0-q,pha)
    g_lens = de_vaucouleurs_2d(xi1, xi2, vpar)

    #pl.figure()
    #pl.imshow((g_lens),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    g_clean_ccd = g_lens + g_limage

    #pl.figure()
    #pl.imshow((g_clean_ccd),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    g_clean_ccd = congrid.congrid(g_clean_ccd, [128, 128])

    #-------------------------------------------------------------
    file_psf = "../PSF_and_noise/sdsspsf.fits"
    g_psf = pyfits.getdata(file_psf) - 1000.0
    g_psf = g_psf / np.sum(g_psf)

    #new_shape=[0,0]
    #new_shape[0]=np.shape(g_psf)[0]*dsx_sdss/dsx
    #new_shape[1]=np.shape(g_psf)[1]*dsx_sdss/dsx
    #g_psf = rebin_psf(g_psf,new_shape)

    g_images_psf = ss.fftconvolve(g_clean_ccd, g_psf, mode="same")
    #g_images_psf = ss.convolve(g_clean_ccd,g_psf,mode="same")
    #g_images_psf = g_clean_ccd

    #pl.figure()
    #pl.imshow((g_psf),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    #g_noise = noise_map(nnn,nnn,np.sqrt(nstd),"Gaussian")
    g_noise = noise_map(128, 128, np.sqrt(nstd), "Gaussian")
    g_final = g_images_psf + g_noise

    #pl.figure()
    #pl.imshow((g_final.T),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    g_final_rebin = congrid.congrid(g_final, [128, 128])

    #pl.figure()
    #pl.imshow((g_final_rebin.T),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

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

    output_filename = "../output_fits/" + str(ind) + ".fits"
    pyfits.writeto(output_filename, g_final_rebin, clobber=True)

    pl.show()

    return 0