Example #1
0
def getbinlc(alpha, delta, qlat, qlong, dates, parmfit, parmflx, Gamma, t0par, SPITZ, use_fsfb, caustic=[]):
    t0, u0, te, rho, piex, piey, theta, q, s = parmfit
    fs, fb = parmflx
    rho2 = rho ** 2
    theta = theta / 180.0 * np.pi  # convert degree to radian
    if caustic == []:  # if no caustic found, calculate it first
        ## lens positions centered on the center of magnification ##
        if s < 1:
            offset_magcen = q / (1 + q) * s
        else:
            offset_magcen = q / (1 + q) / s
        x1 = -offset_magcen
        x2 = s - offset_magcen
        zcau, zcr = gencau.getCaustic(np.array([1.0, q]), np.array([x1, x2]), np.array([0.0, 0.0]), 1000)
        xcau = np.real(zcau)
        ycau = np.imag(zcau)
    else:  # otherwise use the available caustic
        xcau = caustic[0]
        ycau = caustic[1]
    ##############################
    if s < 1.0:
        offset_x = s * (-0.5 + 1.0 / (1 + q))
    else:
        offset_x = s / 2.0 - q / (1 + q) / s
    #    offset_x = s/2.
    magmap = []
    for i in range(len(dates)):
        taup, betap = gettraj(
            dates[i], t0, u0, te, piex, piey, alpha, delta, t0par, qlat, qlong, hjds, ras, decs, diss, SPITZ
        )
        xcm = taup * np.cos(theta) + betap * np.sin(theta)
        ycm = -taup * np.sin(theta) + betap * np.cos(theta)
        xs = xcm - offset_x
        ys = ycm
        dist2 = min((xcau - xcm) ** 2 + (ycau - ycm) ** 2)
        #        dist2 = min((xcau-xs)**2+(ycau-ys)**2)
        if dist2 < 4 * rho2:
            ### Jin code ###
            magbps, magnew, errorflag = getbmag.getmag_jin(xs, ys, s, q, rho, Gamma)
            magnew = -1
            if magnew < 1.0:
                print "looplinking failed, switch to mapmaking"
                magnew, errorflag = getmag_wei.getmag_wei(magbps, xs, ys, s, q, rho, Gamma)
        elif dist2 < 16 * rho2:
            ### hex approx ###
            magnew = getbmag.taylor_2(xs, ys, q, s, Gamma, rho, 4)
        elif dist2 < 100 * rho2:
            ### quad approx ###
            magnew = getbmag.taylor_2(xs, ys, q, s, Gamma, rho, 2)
        else:
            ### mon approx ###
            magnew = getbmag.taylor_2(xs, ys, q, s, Gamma, rho, 0)
        if use_fsfb == True:
            magnew = magnew * fs + fb
        magmap.append([xcm, ycm, magnew])
    return np.array(magmap), xcau, ycau
Example #2
0
def mapmaking(q,s,rho,Gamma,maplimits,gridsizes):
    xmin,xmax,ymin,ymax = maplimits
    xstep,ystep = gridsizes
    rho2 = rho**2
    ## lens positions centered on the center of magnification ##
    if s<1:
        offset_magcen = q/(1+q)*s
    else:
        offset_magcen = q/(1+q)/s
    x1 = -offset_magcen
    x2 = s-offset_magcen
#    zcau,zcr = gencau.getCaustic(np.array([1.,q]),np.array([0.,s]),np.array([0.,0.]),1000)
    zcau,zcr = gencau.getCaustic(np.array([1.,q]),np.array([x1,x2]),np.array([0.,0.]),1000)
    xcau = np.real(zcau)
    ycau = np.imag(zcau)
    if s < 1.:
        offset_x = s*(-0.5+1./(1+q))
    else:
        offset_x = s/2.-q/(1+q)/s
#    offset_x = s/2.
    magmap = []
    for xs in np.arange(xmin,xmax,xstep):
        for ys in np.arange(ymin,ymax,ystep):
            dist2 = min((xcau-xs)**2+(ycau-ys)**2)
            xs_corr = xs-offset_x
            if dist2 < 4*rho2:
            ### Jin code ###
                magbps,magnew,errorflag = getbmag.getmag_jin(xs_corr,ys,s,q,rho,Gamma)
                if magnew < 1.:
                    print 'looplinking failed, switch to mapmaking'
                    magnew,errorflag = getmag_wei.getmag_wei(magbps,xs_corr,ys,s,q,rho,Gamma)
            elif dist2 < 16*rho2:
            ### hex approx ###
                magnew = getbmag.taylor_2(xs_corr,ys,q,s,Gamma,rho,4)
            elif dist2 < 100*rho2:
            ### quad approx ###
                magnew = getbmag.taylor_2(xs_corr,ys,q,s,Gamma,rho,2)
            else:
            ### mon approx ###
                magnew = getbmag.taylor_2(xs_corr,ys,q,s,Gamma,rho,0)
            magmap.append([xs,ys,magnew])
    return np.array(magmap),xcau,ycau