Пример #1
0
def test():

    nn = 101.
    x, y = np.mgrid[0:nn, 0:nn]
    xx = sorted(list(set(x.flatten().tolist())))

    GaussPars = 3., 15., 190. * np.pi / 180
    #GaussPars=0.001,0.001,30.*np.pi/180

    Sm, SM, PA = GaussPars

    #########
    psfPars = 1, 10., 120. * np.pi / 180
    #psfPars=0.001,.001,30.*np.pi/180
    PSm, PSM, PPA = psfPars
    z1 = Gaussian.GaussianXY(x, y, 1., off=(50, 50), sig=(PSm, PSM), pa=PPA)
    #########

    CPSF = ClassConfPSF(psfPars)
    GaussParsConv = CPSF.GiveConvGaussPars(GaussPars)
    Sm2, SM2, PA2 = GaussParsConv

    z0 = Gaussian.GaussianXY(x, y, 1., off=(50, 50), sig=(Sm, SM), pa=PA)
    z2 = Gaussian.GaussianXY(x, y, 1., off=(50, 50), sig=(Sm2, SM2), pa=PA2)

    pylab.clf()
    pylab.subplot(1, 3, 1)
    pylab.imshow(z0, interpolation="nearest")
    pylab.subplot(1, 3, 2)
    pylab.imshow(z1, interpolation="nearest")
    pylab.subplot(1, 3, 3)
    pylab.imshow(z2, interpolation="nearest")
    pylab.draw()
    pylab.show(False)
Пример #2
0
    def GiveCovMat(self):

        x = self.x
        y = self.y

        N = x.size

        dN = 10
        N = 2 * dN + 1
        x, y = np.mgrid[-dN:dN:N * 1j, -dN:dN:N * 1j]
        x = x.flatten()
        y = y.flatten()

        N = x.size
        GG = np.zeros((N, N), np.float32)
        for i in range(N):
            GG[i, :] = Gaussian.GaussianXY(x[i] - x,
                                           y[i] - y,
                                           self.noise**2,
                                           sig=(self.psf[0], self.psf[1]),
                                           pa=self.psf[2])

        Ginv = ModLinAlg.invSVD(GG)

        pylab.clf()
        pylab.subplot(1, 2, 1)
        pylab.imshow(GG, interpolation="nearest")
        pylab.subplot(1, 2, 2)
        pylab.imshow(np.real(Ginv), interpolation="nearest")
        pylab.draw()
        pylab.show(False)
        stop
Пример #3
0
    def GiveGuess(self, Nsources):
        x, y, z = self.data.copy()
        S = []

        #self.plotIter(self.data[2],z)

        DicoGuess = {}
        for i in range(Nsources):
            DicoGuess[i] = {}
            ind = np.argmax(z)
            x0, y0, s0 = x[ind], y[ind], z[ind]
            #print s0,np.max(z)
            z -= Gaussian.GaussianXY(x0 - x,
                                     y0 - y,
                                     s0,
                                     sig=(self.psf[0], self.psf[1]),
                                     pa=self.psf[2])
            S.append([x0, y0, s0])
            DicoGuess[i]["l"] = x0
            DicoGuess[i]["m"] = y0
            DicoGuess[i]["s"] = s0
            #self.plotIter2(x,y,self.data[2],z)
            #self.plotIter(self.data[2],z)
            self.AddMissingDefault(DicoGuess[i])
        #S=np.array(S).T.flatten()
        #S=np.array(S.tolist()+[.1])

        Lout = self.DicoToListFreePars(DicoGuess)
        return Lout
Пример #4
0
 def func(self, pars, xyz):
     x, y, z = xyz
     l, m, s = self.GetPars(pars)
     G = np.zeros_like(x)
     for i in range(l.shape[0]):
         G += Gaussian.GaussianXY(l[i] - x,
                                  m[i] - y,
                                  s[i],
                                  sig=(self.psf[0], self.psf[1]),
                                  pa=self.psf[2])
     return G
Пример #5
0
def init():
    nn = 101.
    x, y = np.mgrid[0:nn, 0:nn]
    xx = sorted(list(set(x.flatten().tolist())))
    dx = xx[1] - xx[0]
    dx = 1.5
    z = Gaussian.GaussianXY(x,
                            y,
                            1.,
                            off=(50, 50),
                            sig=(1.2 * dx, 1.2 * dx),
                            pa=20. * np.pi / 180)
    z += Gaussian.GaussianXY(x,
                             y,
                             1.,
                             off=(55, 50),
                             sig=(1.2 * dx, 1.2 * dx),
                             pa=20. * np.pi / 180)
    z += Gaussian.GaussianXY(x,
                             y,
                             .5,
                             off=(25, 25),
                             sig=(1.2 * dx, 1.2 * dx),
                             pa=20. * np.pi / 180)
    z += Gaussian.GaussianXY(x,
                             y,
                             .5,
                             off=(75, 25),
                             sig=(1.2 * dx, 1.2 * dx),
                             pa=20. * np.pi / 180)
    noise = 0.01
    #z+=np.random.randn(nn,nn)*noise
    # z+=Gaussian.GaussianXY(x,y,1.,off=(50,50),sig=(1*dx,1*dx),pa=20.*np.pi/180)
    #pylab.clf()
    dx *= 1.5
    pylab.imshow(z, interpolation="nearest")
    pylab.show()
    Fit = ClassPointFit(x, y, z, psf=(dx, dx, 0.), noise=noise)
    Fit.DoAllFit()
Пример #6
0
    def func(self, pars, xyz):
        x, y, z = xyz
        l, m, s, dp = self.GetPars(pars)
        psf = self.givePsf(dp)
        # print "psf0: %s"%str(self.psf)
        # print "psf1: %s"%str(psf)

        G = np.zeros_like(x)
        for i in range(l.shape[0]):
            G += Gaussian.GaussianXY(l[i] - x,
                                     m[i] - y,
                                     s[i],
                                     sig=(psf[0], psf[1]),
                                     pa=self.psf[2])
        return G
Пример #7
0
def test():
    nn = 101.
    x, y = np.mgrid[0:nn, 0:nn]
    xx = sorted(list(set(x.flatten().tolist())))
    dx = xx[1] - xx[0]
    dx = 1.
    adp = 1.

    psfPars = 1, 10., 120. * np.pi / 180
    PSm, PSM, PPA = psfPars
    CPSF = ClassConvPSF(psfPars)

    GaussPars = 3, 10, 10. * np.pi / 180.
    GaussParsConv = CPSF.GiveConvGaussPars(GaussPars)
    Sm2, SM2, PA2 = GaussParsConv

    # z=Gaussian.GaussianXY(x,y,1.,off=(50,50),sig=(adp*dx,adp*dx),pa=20.*np.pi/180)
    # z+=Gaussian.GaussianXY(x,y,1.,off=(55,50),sig=(adp*dx,adp*dx),pa=20.*np.pi/180)
    # z+=Gaussian.GaussianXY(x,y,.5,off=(25,25),sig=(adp*dx,adp*dx),pa=20.*np.pi/180)
    # z+=Gaussian.GaussianXY(x,y,.5,off=(75,25),sig=(adp*dx,adp*dx),pa=20.*np.pi/180)

    # #z+=Gaussian.GaussianXY(x,y,.5,off=(75,75),sig=(5*adp*dx,adp*dx),pa=20.*np.pi/180)
    # z+=Gaussian.GaussianXY(x,y,.5,off=(50,50),sig=(5*adp*dx,adp*dx),pa=20.*np.pi/180)

    z = Gaussian.GaussianXY(x, y, .5, off=(75, 75), sig=(Sm2, SM2), pa=PA2)

    noise = 0.01
    #z+=np.random.randn(nn,nn)*noise
    # z+=Gaussian.GaussianXY(x,y,1.,off=(50,50),sig=(1*dx,1*dx),pa=20.*np.pi/180)
    #pylab.clf()
    #dx*=1.5
    #pylab.ion()

    pylab.clf()
    pylab.imshow(z, interpolation="nearest")
    pylab.draw()
    pylab.show(False)
    #Fit=ClassGaussFit(x,y,z,psf=(dx,dx,0.),noise=noise,FreePars=["l", "m","s","Sm","SM","PA"])
    Fit = ClassGaussFit(x,
                        y,
                        z,
                        psf=psfPars,
                        noise=noise,
                        FreePars=["l", "m", "s", "Sm", "SM", "PA"])
    Fit.DoAllFit()
Пример #8
0
    def GiveGuess(self, Nsources):
        x, y, z = self.data.copy()
        S = []

        #self.plotIter(self.data[2],z)
        for i in range(Nsources):
            ind = np.argmax(z)
            x0, y0, s0 = x[ind], y[ind], z[ind]
            #print s0,np.max(z)
            z -= Gaussian.GaussianXY(x0 - x,
                                     y0 - y,
                                     s0,
                                     sig=(self.psf[0], self.psf[1]),
                                     pa=self.psf[2])
            S.append([x0, y0, s0])
            #self.plotIter2(x,y,self.data[2],z)
            #self.plotIter(self.data[2],z)
        return S
Пример #9
0
    def funcNoPSF(self, pars, xyz):
        x, y, z = xyz

        #l,m,s,dp=self.GetPars(pars)
        DicoPars = self.ListToDicoPars(pars)
        l, m, s, Sm, SM, PA = self.DicoToListPars(DicoPars)

        dp = 0.
        psf = self.givePsf(dp)

        G = np.zeros_like(x)
        for i in range(l.shape[0]):
            G += Gaussian.GaussianXY(l[i] - x,
                                     m[i] - y,
                                     s[i],
                                     sig=(Sm[i], SM[i]),
                                     pa=PA[i])

        return G
Пример #10
0
    def func(self, pars, xyz):
        x, y, z = xyz

        #l,m,s,dp=self.GetPars(pars)
        DicoPars = self.ListToDicoPars(pars)
        l, m, s, Sm, SM, PA = self.DicoToListPars(DicoPars)
        #print Sm,SM,pars
        dp = 0.
        psf = self.givePsf(dp)

        G = np.zeros_like(x)
        for i in range(l.shape[0]):
            #G+=Gaussian.GaussianXY(l[i]-x,m[i]-y,s[i],sig=(psf[0],psf[1]),pa=self.psf[2])
            ThisSm, ThisSM, ThisPA = self.giveConvPsf((Sm[i], SM[i], PA[i]))
            G += Gaussian.GaussianXY(l[i] - x,
                                     m[i] - y,
                                     s[i],
                                     sig=(ThisSm, ThisSM),
                                     pa=ThisPA)

        return G