def get_om10_cc(xi1, xi2, om10_id):
    db = om10.DB(catalog="./qso_mock.fits")

    lens = db.get_lens(om10_id)
    zl = lens.ZLENS[0]
    zs = lens.ZSRC[0]
    qe = 1.0 / (1.0 - lens.ELLIP[0])
    phi = lens.PHIE[0]
    vd0 = lens.VELDISP[0]  # needed from OM10

    re = aa.re_sv(vd0, zl, zs)

    lpars = np.zeros((6))

    lpars[
        0] = 0.0  # x coordinate of the center of lens (in units of Einstein radius).
    lpars[
        1] = 0.0  # y coordinate of the center of lens (in units of Einstein radius).
    lpars[2] = 1.0 / qe  # Axis ratio of lens.
    lpars[3] = 0.0  # Core size of lens (in units of Einstein radius).
    lpars[4] = re  # Einstein radius of lens (in units of arcsec).
    lpars[5] = phi  # Orientation of lens (in units of degree).

    alpha1, alpha2, kappa, shears1, shear2, mu = lensing_model_SIE(
        xi1, xi2, lpars)
    return alpha1, alpha2, mu, kappa
def main():
    zl = 0.17
    zs = 3.0
    sigmav = 600           #km/s
    re0 = aa.re_sv(sigmav,zl,zs)
    me0 = aa.m200_sv(sigmav,zl)


    #zs_arr = np.linspace(zl,10.0,100)
    #re_arr = zs_arr*0.0
    #for i in xrange(len(zs_arr)):
        #re_arr[i] = aa.re_sv(sigmav,zl,zs_arr[i])

    #pl.figure()
    #pl.plot(zs_arr,re_arr,'-')



    nrbins = 5
    nnn = 128*nrbins
    #dsx = boxsize/nnn
    dsx = 0.396/nrbins # arcsec
    bsz = dsx*nnn # in the units of Einstein Radius
    print re0,me0,bsz

    #nnn = 512
    #bsz = 40 # in the units of Einstein Radius
    #dsx = bsz/nnn # arcsec

    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)
    #----------------------------------------------------------------------
    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  = re0       #Einstein radius of lens.
    pha = 5.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

    #pl.figure()
    #pl.contour(xi2,xi1,mua)
    #pl.colorbar()

    #pl.figure()
    #pl.contour(yi2,yi1,mua)
    #pl.colorbar()

    mags_of_sources = 100.0
    #ys1 = 0.85
    #ys2 = -0.22

    #ys11 = ys1
    #ys12 = ys2

    #xroot1,xroot2,nroots = trf.roots_zeros(xi1,xi2,ai1,ai2,ys1,ys2)

    #idr1 = ((np.array(xroot1)+bsz/2.0-dsx/2.0)/dsx).astype('int')
    #idr2 = ((np.array(xroot2)+bsz/2.0-dsx/2.0)/dsx).astype('int')
    g_limage = xi1*0.0
    #g_limage[idr1,idr2] = mags_of_sources*np.abs(mua[idr1,idr2])

    ys1 = 0.67
    ys2 = 0.75

    ys21 = ys1
    ys22 = ys2

    xroot1,xroot2,nroots = trf.roots_zeros(xi1,xi2,ai1,ai2,ys1,ys2)

    #pl.figure()
    #pl.xlim(-bsz/2,bsz/2)
    #pl.ylim(-bsz/2,bsz/2)
    #pl.plot(ys11,ys12,'wo')
    #pl.plot(ys21,ys22,'yo')

    idr1 = ((np.array(xroot1)+bsz/2.0-dsx/2.0)/dsx).astype('int')
    idr2 = ((np.array(xroot2)+bsz/2.0-dsx/2.0)/dsx).astype('int')
    g_limage[idr1,idr2] = g_limage[idr1,idr2] + mags_of_sources*np.abs(mua[idr1,idr2])

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

    #pl.figure()
    #pl.contour(yi1,yi2,mua)
    #pl.colorbar()
    #print xroot1,xroot2
    #pl.figure(figsize=(10,10))
    #pl.xlim(-2.0,2.0)
    #pl.ylim(-2.0,2.0)
    #pl.plot(xroot1,xroot2,'go')
    #pl.plot(ys1,ys2,'ko')
    #----------------------------------------------------------------------
    g_amp = 0.1*re      # peak brightness value
    g_sig = 300.*re      # Gaussian "sigma" (i.e., size)
    g_xcen = xc1    # x position of center (also try (0.0,0.14)
    g_ycen = xc2    # y position of center
    g_axrat = q     # minor-to-major axis ratio
    g_pa = pha+90      # major-axis position angle (degrees) c.c.w. from x axis
    gpar = np.asarray([g_amp,g_sig,g_xcen,g_ycen,g_axrat,g_pa])
    #----------------------------------------------------------------------
    #g_simage = gauss_2d(xi1,xi2,gpar) # modeling source as 2d Gaussian with input parameters.
    g_lensimage = gauss_2d(xi1,xi2,gpar)
    g_limage = g_limage + g_lensimage/3.0/nrbins**2.0

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

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

    #g_psf = congrid.congrid(g_psf,[np.shape(g_psf)[0]*nrbins,np.shape(g_psf)[1]*nrbins])
    #g_psf = sil.RectBivariateSpline(g_psf,
                                #bbox=[np.shape(g_psf)[0]*nrbins,np.shape(g_psf)[1]*nrbins,np.shape(g_psf)[0]*nrbins,np.shape(g_psf)[1]*nrbins], kx=3, ky=3, s=0)

    #print np.shape(g_psf),np.max(g_lensimage)

    #pl.figure()
    ##pl.contourf(g_limage)
    ##pl.colorbar()
    #pl.plot(ys11,ys12,'wo')
    #pl.plot(ys21,ys22,'yo')


    #file_noise = "./sdssgal.fits"
    #g_noise = pyfits.getdata(file_noise)-1000.0
    #g_limage = ss.fftconvolve(g_limage,g_psf,mode="same")

    #file_noise = "./sdssgal.fits"
    #g_noise = pyfits.getdata(file_noise)-1000.0
    nstd = 0.5001
    g_noise=nstd*np.random.normal(0.0,1.0,(nnn,nnn))
    g_limage = gaussian_filter(g_limage,5)

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

    g_limage = g_limage+g_noise

    output_filename = "./test.fits"
    pyfits.writeto(output_filename,g_limage,clobber=True)


    return 0
예제 #3
0
    idr2 = ((np.array(xroot2)+bsz/2.0-dsx/2.0)/dsx).astype('int')
    g_limage[idr1,idr2] = g_limage[idr1,idr2] + spar[2]*np.abs(mua[idr1,idr2])

    return g_limage
#------------------------------------------------------------------------------
if __name__ == '__main__':
    nnn = 512
    bsz = 50.0 # in the units of Einstein Radius
    dsx = bsz/nnn # arcsec

    xi1,xi2  = make_r_coor(nnn,dsx)
    #----------------------------------------------------------------------
    zl = 0.17
    zs = 3.0
    sigmav = 600           #km/s
    re0 = aa.re_sv(sigmav,zl,zs)
    #----------------------------------------------------------------------
    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  = re0       #Einstein radius of lens.
    pha = 5.0      #Orintation of lens.
    lpar = np.asarray([xc1,xc2,q,rc,re,pha])
    ai1,ai2,mua = lens_equation_sie(xi1,xi2,lpar)
    #----------------------------------------------------------------------
    ys1 = 0.0
    ys2 = 0.0
    mags_of_sources = 100.0
    spar = np.asarray([ys1,ys2,mags_of_sources])
    #----------------------------------------------------------------------
def calculate_lc_of_imgs():

    zl = 0.5
    zs = 2.0
    ql0 = 0.699999999999
    rc0 = 0.000000000000
    svt = 255.0
    re0 = aa.re_sv(svt,zl,zs)

    print re0

    nnn = 512
    bsz = 4.0
    dsx = bsz/nnn

    xb1 = 0.0
    xb2 = 0.0

    xl1 = 0.0
    xl2 = 0.0

    #ys1 = np.random.random(1)*(0.2-0.1)+0.05
    #ys2 = np.random.random(1)*(0.2-0.1)+0.05
    #print ys1,ys2,dsx

    ys1 = 0.09892207 #Fold images
    ys2 = 0.09783113 #Fold images

    #ys1 = 0.14250078
    #ys2 = 0.12287053

    xroot1,xroot2,xroot3,nroots = roots_zeros(xb1,xb2,xl1,xl2,bsz,nnn,ys1,ys2)
    xi1,xi2 = standard_grids(xb1,xb2,bsz,nnn)
    alpha1,alpha2 = nie_alphas(xi1,xi2,xl1,xl2,re0,rc0,ql0)
    yi1 = xi1-alpha1
    yi2 = xi2-alpha2
    xrv1,xrv2,xrv3,nroots = mapping_triangles(ys1,ys2,xi1,xi2,yi1,yi2)

    xroot1 = np.array(xrv1)
    xroot2 = np.array(xrv2)
    xroot3 = np.array(xrv3)

    xr1 = (xroot1[0,:]+xroot2[0,:]+xroot3[0,:])/3.0
    xr2 = (xroot1[1,:]+xroot2[1,:]+xroot3[1,:])/3.0
    td = td_nie_single(svt,xr1,xr2,ql0,rc0,0.5,2.0)
    mu = nie_mu(xr1,xr2,re0,rc0,ql0)
    time_days,mags = np.loadtxt("./SN_opsim.csv",dtype='string', delimiter=',', usecols=(1, 4), unpack=True)
    time_days = time_days.astype("double")
    days1 = time_days+td[0]
    days2 = time_days+td[1]
    days3 = time_days+td[2]
    days4 = time_days+td[3]
    days5 = time_days+td[4]

    mags = mags.astype("double")
    mags1 = mags-2.5*np.log10(np.abs(mu[0]))
    mags2 = mags-2.5*np.log10(np.abs(mu[1]))
    mags3 = mags-2.5*np.log10(np.abs(mu[2]))
    mags4 = mags-2.5*np.log10(np.abs(mu[3]))
    mags5 = mags-2.5*np.log10(np.abs(mu[4]))

    #mui = lens.MAG[0]
    #nim = lens.NIMG[0]
    #ms = lens.MAGI_IN[0]
    #mi = ms - 2.5*np.log10(np.abs(mui[:nim]))
    #print "om10.plot_lens: source magnitudes, magnification, image magnitudes:",ms,mui[:nim],mi
    #print time_days
    #print mags
    #from astropy.time import Time
    #t = Time(time_days, format='mjd')
    #print t.isot

    pl.figure()
    pl.ylim(32,22)
    pl.plot(days1-49500,mags1,'r-')
    pl.plot(days2-49500,mags2,'g-')
    pl.plot(days3-49500,mags3,'y-')
    pl.plot(days4-49500,mags4,'b-')
    pl.plot(days5-49500,mags5,'m-')

    mua = nie_mu(xi1,xi2,re0,rc0,ql0)

    pl.figure(figsize=(5,5))
    pl.xlim(-2.0,2.0)
    pl.ylim(-2.0,2.0)
    pl.plot(xr1[0],xr2[0],'ro')
    pl.plot(xr1[1],xr2[1],'go')
    pl.plot(xr1[2],xr2[2],'yo')
    pl.plot(xr1[3],xr2[3],'bo')
    pl.plot(xr1[4],xr2[4],'mo')
    pl.contour(xi1,xi2,mua,colors=('r',))
    pl.contour(yi1,yi2,mua,colors=('g',))
    pl.plot(ys1,ys2,'ko')

    return [xr1,xr2],[days1,days2,days3,days4,days5], [mags1,mags2,mags3,mags4,mags5]