Ejemplo n.º 1
0
 def affine_grid(self,Hz,rhoz,Lam):
     """
     Get data on regular spatial grid
     """
     #First find dimensionless density params
     Om0 = 8*pi*rhoz[0]/(3*Hz[0]**2)
     OL0 = Lam/(3*Hz[0]**2)
     Ok0 = 1-Om0-OL0
     #Get t0
     t0 = self.get_age(Om0,Ok0,OL0,Hz[0])
     #Set affine parameter vals        
     dvo = uvs(self.z,1/(self.uz**2*Hz),k=3,s=0.0)
     vzo = dvo.antiderivative()
     vz = vzo(self.z)
     vz[0] = 0.0
     #Compute grid sizes that gives num error od err
     NJ = int(ceil(vz[-1]/sqrt(self.err) + 1))
     NI = int(ceil(3.0*(NJ - 1)*(t0 - self.tmin)/vz[-1] + 1))
     #Get functions on regular grid
     v = linspace(0,vz[-1],NJ)
     delv = (v[-1] - v[0])/(NJ-1)
     if delv > sqrt(self.err):
         print 'delv > sqrt(err)'
     Ho = uvs(vz,Hz,s=0.0,k=3)
     H = Ho(v)
     rhoo = uvs(vz,rhoz,s=0.0,k=3)
     rho = rhoo(v)
     uo = uvs(vz,self.uz,s=0.0,k=3)
     u = uo(v)
     u[0] = 1.0
     return v,vzo,H,rho,u,NJ,NI,delv,Om0,OL0,Ok0,t0
Ejemplo n.º 2
0
 def get_PLC0_observables(self,vzo,D,A,u,udot,up):
     #Get dzdw(v)
     dzdw = self.get_dzdw(u,udot,up,A)
     #Get mu(v)
     #mu = zeros(self.NJ)
     mu = zeros(self.NJ)
     mu[1::] = 5*log10(1e8*u[1::]**2*D[1::])
     mu[0] = -1e-15  #Should be close enough to -inf
     #Convert to functions of z
     z = u-1
     vz = vzo(z)
     Dz = uvs(vz,D,k=3,s=0.0)(vzo(self.z))
     muz=zeros(self.np)
     muz[0] = -inf
     muz[1::] = uvs(vz,mu,k=3,s=0.0)(vzo(self.z[1::]))
     dzdwz = uvs(vz,dzdw,k=3,s=0.0)(vzo(self.z))
     return Dz, muz, dzdwz
Ejemplo n.º 3
0
 def evaluate(self,rho,u,v,vmaxi,Lam):
     """
     This functions evaluates CIVP variables on a PLC from the values of rho and u on that PLC
     """
     #Interpolate u and rho
     uo = uvs(v,u,s=0.0,k=5)
     rhoo = uvs(v,rho,s=0.0,k=5)
     #Solve hyp equations
     y = odeint(self.hypeq,self.y0,v,args=(rhoo,uo,Lam),atol=0.01*self.err,rtol=0.01*self.err)
     #Get spatial derivatives of rho and u
     upo = uo.derivative()
     uppo = uo.derivative(2)
     up = upo(v)
     upp = uppo(v)
     rhopo = rhoo.derivative()
     rhop = rhopo(v)
     #Get udot and rhodot corresponding to these solutions
     ud = self.dotu(u,y[:,3],up,y[:,4])     
     rhod = self.dotrho(rho,u,rhop,up,y[:,0],y[:,1],y[:,2],y[:,3],vmaxi)
     return y[:,0], y[:,1], y[:,2], y[:,3], y[:,4], ud, rhod, up, rhop, upp
Ejemplo n.º 4
0
 def get_funcs(self):
     """
     Return quantities of interest
     """
     #Here we do the shear and curvature tests on two pncs
     umax = int(self.Istar)
     njf = int(self.vmaxi[umax]) #This is the max value of index on final pnc considered
     
     #All functions will be returned with the domain normalised between 0 and 1
     l = linspace(0,1,self.nret)
     #Curvetest
     T2i = self.curve_test(0,self.NJ)
     self.Kiraw = T2i
     T2io = uvs(self.v/self.v[-1],T2i,k=3,s=0.0)
     T2i = T2io(l)
     T2f = self.curve_test(umax,self.NJ)
     #self.Kfraw = Kf
     T2fo = uvs(self.v[0:njf]/self.v[njf-1],T2f[0:njf],k=3,s=0.0)
     T2f = T2fo(l)
     #shear test
     T1i = self.shear_test(0,self.NJ)
     T1io = uvs(self.v/self.v[-1],T1i,k=3,s=0.0)
     T1i = T1io(l)
     T1f = self.shear_test(umax,self.NJ)
     T1fo = uvs(self.v[0:njf]/self.v[njf-1],T1f[0:njf],k=3,s=0.0)
     T1f = T1fo(l)
     #Get the LLTB consistency relation
     jmaxf = self.vmaxi[-1]
     LLTBConsi = uvs(self.v[0:jmaxf],self.LLTBCon[0,0:jmaxf],k=3,s=0.0)(l)
     LLTBConsf = uvs(self.v[0:jmaxf],self.LLTBCon[-1,0:jmaxf],k=3,s=0.0)(l)
     #Get constant t slices
     I = range(self.Istar)
     rmax = self.rstar[self.Istar-1]
     r = self.rstar[I]/rmax
     rhostar = interp(l,r,self.rhostar[I])
     Dstar = interp(l,r,self.Dstar[I])
     Dstar[0] = 0.0
     Xstar = interp(l,r,self.Xstar[I])
     Hperpstar = interp(l,r,self.Hperpstar[I])
     return self.Dz,self.muz,self.dzdw,T1i, T1f,T2i,T2f,LLTBConsi,LLTBConsf,rhostar,Dstar,Xstar,Hperpstar,rmax,self.Om0,self.OL0,self.t0
Ejemplo n.º 5
0
    def transform(self):
        #get dt components
        self.dtdw = (self.A*self.v1**2 + 1)/(-2*self.v1)
        self.dtdv = self.v1
        self.dwdt = -self.v1
        self.dvdt = (self.A*self.v1**2 - 1)/(-2*self.v1)
        #set initial d data
        self.d = zeros([self.NI,self.NJ])
        self.c = zeros([self.NI,self.NJ])
        self.b = zeros([self.NI,self.NJ])
        self.a = zeros([self.NI,self.NJ])
        self.d[0,:] = -self.v1nu[0,:]*self.D[0,:] -self.v1[0,:]*self.S[0,:]
        self.c[0,:] = self.d[0,:]*(self.A[0,:]*self.v1[0,:]**2-1)/(2*self.v1[0,:]**2)
        self.a[0,:] = -self.v1[0,:]**2/self.d[0,:]
        self.b[0,:] = (1+self.A[0,:]*self.v1[0,:]**2)/(2*self.d[0,:])
        #Get dprime and ddot to evaluate dXdr below
        self.F = zeros([self.NI,self.NJ])
        self.ddot = zeros([self.NI,self.NJ])
        self.dprime = zeros([self.NI,self.NJ])
        self.F[0,:] = self.d[0,:]*(self.A[0,:] - 1.0/self.v1[0,:]**2)/2.0
        self.ddot[0,0] = (-self.F[0,2]/2.0 + 2.0*self.F[0,1] - 3.0*self.F[0,0]/2.0)/self.delnu
        self.ddot[0,1:self.NJ-1] = (self.F[0,2:self.NJ] - self.F[0,0:self.NJ-2])/(2*self.delnu)
        self.ddot[0,self.NJ-1] = (3.0*self.F[0,self.NJ-1]/2.0 - 2.0*self.F[0,self.NJ-2] + self.F[0,self.NJ-3]/2.0)/self.delnu        
        self.dprime[0,0] = (-self.d[0,2]/2.0 + 2.0*self.d[0,1] - 3.0*self.d[0,0]/2.0)/self.delnu
        self.dprime[0,1:self.NJ-1] = (self.d[0,2:self.NJ] - self.d[0,0:self.NJ-2])/(2*self.delnu)
        self.dprime[0,self.NJ-1] = (3.0*self.d[0,self.NJ-1]/2.0 - 2.0*self.d[0,self.NJ-2] + self.d[0,self.NJ-3]/2.0)/self.delnu
        self.X = zeros([self.NI,self.NJ])
        self.X[0,:] = -self.v1[0,:]/self.d[0,:]
        self.tv = zeros([self.NI,self.NJ])
        self.rv = zeros([self.NI,self.NJ])
        dto = uvs(self.v,self.v1[0,:],k=3,s=0.0)
        self.tv[0,:] = self.w0[0] + dto.antiderivative()(self.v)
        dro = uvs(self.v,self.d[0,:],k=3,s=0.0)
        self.rv[0,:] = dro.antiderivative()(self.v)
        for n in range(self.NI-1):
            jmax = int(self.vmaxi[n+1])
            #Use forward differences to get value at origin
            self.d[n+1,0] = self.d[n,0] + self.delu*(-self.F_d(n,2)/2.0 + 2.0*self.F_d(n,1) - 3.0*self.F_d(n,0)/2.0)/self.delnu
            arrup = arange(2,jmax)
            arrmid = arange(1,jmax-1)
            arrdown = arange(0,jmax-2)
            self.d[n+1,arrmid] = (self.d[n,arrup] + self.d[n,arrdown])/2.0 + self.delu*(self.F_d(n,arrup) - self.F_d(n,arrdown))/(2*self.delnu)
            #Use backward differences to get value at jmax
            self.d[n+1,jmax-1] = self.d[n,jmax-1] + self.delu*(3.0*self.F_d(n,jmax-1)/2.0 - 2*self.F_d(n,jmax-2) + self.F_d(n,jmax-3)/2.0)/self.delnu
            #get remaining transformation components
            self.c[n+1,0:jmax] = self.d[n+1,0:jmax]*(self.A[n+1,0:jmax]*self.v1[n+1,0:jmax]**2-1.0)/(2.0*self.v1[n+1,0:jmax]**2.0)
            self.a[n+1,0:jmax] = -self.v1[n+1,0:jmax]**2/self.d[n+1,0:jmax]
            self.b[n+1,0:jmax] = (1.0+self.A[n+1,0:jmax]*self.v1[n+1,0:jmax]**2.0)/(2.0*self.d[n+1,0:jmax])
            #Get dprime and ddot to evaluate dXdr below
            self.F[n+1,0:jmax] = self.d[n+1,0:jmax]*(self.A[n+1,0:jmax] - 1.0/self.v1[n+1,0:jmax]**2)/2.0
            self.ddot[n+1,0] = (-self.F[n+1,2]/2.0 + 2.0*self.F[n+1,1] - 3.0*self.F[n+1,0]/2.0)/self.delnu
            self.ddot[n+1,arrmid] = (self.F[n+1,arrup] - self.F[n+1,arrdown])/(2*self.delnu)
            self.ddot[n+1,jmax-1] = (3.0*self.F[n+1,jmax-1]/2.0 - 2.0*self.F[n+1,jmax-2] + self.F[n+1,jmax-3]/2.0)/self.delnu
            self.dprime[n+1,0] = (-self.d[n+1,2]/2.0 + 2.0*self.d[n+1,1] - 3.0*self.d[n+1,0]/2.0)/self.delnu
            self.dprime[n+1,arrmid] = (self.d[n+1,arrup] - self.d[n+1,arrdown])/(2*self.delnu)
            self.dprime[n+1,jmax-1] = (3.0*self.d[n+1,jmax-1]/2.0 - 2.0*self.d[n+1,jmax-2] + self.d[n+1,jmax-3]/2.0)/self.delnu
            self.X[n+1,0:jmax] = -self.v1[n+1,0:jmax]/self.d[n+1,0:jmax]
#            self.dXdr[n+1,0:jmax] = self.a[n+1,0:jmax]*(-self.v1u[n+1,0:jmax]/self.d[n+1,0:jmax] + self.v1[n+1,0:jmax]*self.ddot[n+1,0:jmax]/self.d[n+1,0:jmax]**2) + self.b[n+1,0:jmax]*(-self.v1nu[n+1,0:jmax]/self.d[n+1,0:jmax] + self.v1[n+1,0:jmax]*self.dprime[n+1,0:jmax]/self.d[n+1,0:jmax]**2)
#            self.Hr[n+1,0:jmax] = self.dXdr[n+1,0:jmax]/self.X[n+1,0:jmax]
#            self.dDdr[n+1,0:jmax] = self.a[n+1,0:jmax]*self.RR[n+1,0:jmax] + self.b[n+1,0:jmax]*self.S[n+1,0:jmax]
            #Get t(v) and r(v)
            dto = uvs(self.v[0:jmax],self.v1[n+1,0:jmax],k=3,s=0.0)
            self.tv[n+1,0:jmax] =  self.w0[n+1] + dto.antiderivative()(self.v[0:jmax])
            dro = uvs(self.v[0:jmax],self.d[n+1,0:jmax],k=3,s=0.0)
            self.rv[n+1,0:jmax] = dro.antiderivative()(self.v[0:jmax])
        return              
Ejemplo n.º 6
0
        tsvalue = Data.sampleData.popleft()
        t = tsvalue[1]
        v = tsvalue[0]

    print("Pop from buffer:", perf_counter() - time)
    time = perf_counter()

    for i in range(c.PIX_PER_UPDATE):
        ##        p.setPen(QColor(0, 0, 0, 255)
        color = ColorsLUT[8]
        p.setPen(color)

    print("Set Pen:", perf_counter() - time)
    time = perf_counter()

    fakelutx = uvs([0, 1], [0, 1], k=1)
    fakeluty = uvs([0, 1], [0, 1], k=1)

    for i in range(c.PIX_PER_UPDATE):
        ##        a = data.LUTX(0 % (c.bill / c.XHz))
        ##        b = data.LUTY(0) * 4
        a = fakelutx(0)
        b = fakeluty(0)
##        plotx = gen.TriaLUT(t % (c.bill / c.XHz), c.defw, c.bill / c.XHz)
##        ploty = gen.SawtLUT(t, c.defh, c.bill / c.YHz) * 4

    print("Use LUT or conversion:", perf_counter() - time)
    time = perf_counter()

    ##    for i in range(c.PIX_PER_UPDATE):
    ##        a = np.sin(78)