def doFit(p=None,doReg=True,updateReg=True,checkImgs=True,levMar=False):
    global reg
    # Check if using levMar-style parameters
    if p is not None:
        for i in range(len(p)):
            pars[i].value = p[i]
            # If the parameter is out-of-bounds return a bad fit
            try:
                a = pars[i].logp
            except:
                return iflt/sflt

    for l in lenses:
        l.setPars()
    xl,yl = pylens.getDeflections(lenses,coords)

    src.update(xl,yl,doReg=doReg)
    lmat = PSFm*src.lmat
    if doReg==True:
        rmat = src.rmat
    else:
        rmat = None
    nupdate = 0
    if doReg==True and updateReg==True:
        nupdate = 10
    res,fit,model,_,regg = aT.getModelG(ifltm,vfltm,lmat,cmatm,rmat,reg,nupdate)
    reg = regg[0]
    if checkImgs is False:
        if levMar:
            res = res**0.5+ifltm*0.
        return -0.5*res
    # This checks is images are formed outside of the masked region
    xl,yl = pylens.getDeflections(lenses,[xflt,yflt])
    oimg,pix = src.eval(xl,yl,fit,domask=False)
    oimg = PSF*oimg
    res = (iflt-oimg)/sflt
    if levMar:
        return res
    return -0.5*(res**2).sum()
ym = y[mask]
coords = [xm,ym]

PSF = pT.getPSFMatrix(psf,img.shape)
PSFm = pT.maskPSFMatrix(PSF,mask)

iflt = img.flatten()
sflt = sig.flatten()
vflt = sflt**2

xflt = x.flatten()
yflt = y.flatten()

src = aT.AdaptiveSource(ifltm/sfltm,ifltm.size/Npnts)

xl,yl = pylens.getDeflections(lenses,coords)
src.update(xl,yl)
osrc = showRes(xl,yl,src,PSFm,img,sig,mask,ifltm,vfltm,cmatm,1e-5,1,400)
pylab.show()
'''

G,L,S,offsets,shear = numpy.load(guiFile)
pars = []
cov = []
lenses = []
for name in L.keys():
    model = L[name]
    lpars = {}
    for key in 'x','y','q','pa','b','eta':
        lo,hi = model[key]['lower'],model[key]['upper']
        val = dic[name+' '+key][a1,a2,a3]
Пример #3
0
from pylens import MassModels,pylens
from scipy.special import gamma,gammainc
import itertools
import numpy as np, pylab as pl

sersic = lambda n,Re,k,R:  np.exp(-k*((R/Re)**(1./n))) * (k**(2.*n)) / (2.*np.pi*n*gamma(2.*n)*  gammainc(2.*n,k*(240./Re)**(1./n))  * Re**2)

x,y=np.linspace(-20,20,700),np.linspace(-20,20,700)
ii = np.array(list(itertools.product(x,y)))
lens = MassModels.PowerLaw('Lens1', {'x':0,'y':0,'q':1,'pa':0,'b':10,'eta':0.7})
xd,yd = pylens.getDeflections(lens,ii.T)
rl = np.sqrt(xd**2. + yd**2.)
SB = sersic(4,30,(2.*4-0.324), rl)

#pl.figure()
#pl.scatter(ii[:,0],ii[:,1],c=SB,edgecolors='none',s=100)
#pl.figure()
#pl.scatter(xd,yd,c=SB,edgecolors='none',s=100)

# caustic?
# source relative to galaxy?

DXs,DYs = np.linspace(0.1,1,3), np.linspace(0.1,1,3)
jj = np.array(list(itertools.product(DXs,DYs)))
for i in range(jj.shape[0]):
    DX,DY=jj[i]
    rl = np.sqrt((xd-DX)**2. + (yd-DY)**2.)
    SB = sersic(4,30,(2.*4-0.324), rl)
    pl.figure()
    pl.scatter(ii[:,0],ii[:,1],c=SB,edgecolors='none',s=100)
    pl.scatter(0,0,color='White')