Ejemplo n.º 1
0
 def calc_Rdist(self, R, Rsig, dist, N):
     totalR = np.sum(R[:-1])
     fdist = eval(dist + '.' + dist +
                  '(x=0.001, pos=totalR, wid=self.Rsig)')
     rmin, rmax = find_minmax(fdist, totalR, Rsig)
     dr = np.linspace(rmin, rmax, N)
     fdist.x = dr
     rdist = fdist.y()
     sumdist = np.sum(rdist)
     rdist = rdist / sumdist
     self.output_params['Distribution'] = {'x': dr, 'y': rdist}
     return dr, rdist, totalR
Ejemplo n.º 2
0
 def y(self):
     rho=self.rhoc-self.rhosol
     self.output_params={}
     if self.Rsig<1e-3:
         return self.norm*rho**2*(np.sin(self.x*self.R)-self.x*self.R*np.cos(self.x*self.R))**2/self.x**6+self.bkg
     else:
         if self.dist=='Gaussian':
             gau=Gaussian.Gaussian(x=0.001,pos=self.R,wid=self.Rsig)
             rmin,rmax=find_minmax(gau,self.R,self.Rsig)
             r=np.linspace(rmin,rmax,self.N)
             gau.x=r
             dist=gau.y()
             sumdist=np.sum(dist)
             self.output_params['Distribution']={'x':r,'y':dist/sumdist}
             if type(self.x)==np.ndarray:
                 ffactor=[]
                 for x in self.x:
                     f=np.sum((np.sin(x*r)-x*r*np.cos(x*r))**2*dist/x**6)
                     ffactor.append(f/sumdist)
                 return self.norm*rho**2*np.array(ffactor)+self.bkg
             else:
                 return self.norm*rho**2*np.sum((np.sin(self.x*r)-self.x*r*np.cos(self.x*r))**2*dist/self.x**6)/sumdist+self.bkg
         elif self.dist=='LogNormal':
             lgn=LogNormal.LogNormal(x=0.001,pos=self.R,wid=self.Rsig)
             rmin,rmax=find_minmax(lgn,self.R,self.Rsig)
             r=np.linspace(rmin,rmax,self.N)
             lgn.x=r
             dist=lgn.y()
             sumdist=np.sum(dist)
             self.output_params['Distribution']={'x':r,'y':dist/sumdist}
             if type(self.x)==np.ndarray:
                 ffactor=[]
                 for x in self.x:
                     f=np.sum((np.sin(x*r)-x*r*np.cos(x*r))**2*dist/x**6)
                     ffactor.append(f/sumdist)
                 return self.norm*rho**2*np.array(ffactor)+self.bkg
             else:
                 return self.norm*rho**2*np.sum((np.sin(self.x*r)-self.x*r*np.cos(self.x*r))**2*dist/self.x**6)/sumdist+self.bkg
         else:
             return np.ones_like(x)
Ejemplo n.º 3
0
 def calc_Rdist(self, R, Rsig, dist, Np):
     if Rsig > 0.001:
         fdist = eval(dist + '.' + dist + '(x=0.001, pos=R, wid=Rsig)')
         rmin, rmax = find_minmax(fdist, R, Rsig)
         dr = np.linspace(rmin, rmax, Np)
         fdist.x = dr
         rdist = fdist.y()
         sumdist = np.sum(rdist)
         rdist = rdist / sumdist
         self.output_params['Distribution'] = {'x': dr, 'y': rdist}
         return dr, rdist
     else:
         return [R], [1.0]
Ejemplo n.º 4
0
    def y(self):
        self.output_params={}
        R=[self.params['__R__%03d'%i] for i in range(len(self.__mpar__['R']))]
        rho=[self.params['__rho__%03d'%i] for i in range(len(self.__mpar__['rho']))]
        if self.Rsig<0.001:
            return self.norm*self.csphere(R,rho)+self.bkg
        else:
            if self.dist=='Gaussian':
                gau=Gaussian.Gaussian(x=0.0,pos=R[0],wid=self.Rsig)
                rmin,rmax=find_minmax(gau,pos=R[0],wid=self.Rsig)
                dr=np.linspace(rmin,rmax,self.N)
                gau.x=dr
                dist=gau.y()
                sumdist=np.sum(dist)
                self.output_params['Distribution']={'x':dr,'y':dist/sumdist}
                res=np.zeros_like(self.x)
                for i in range(len(dr)):
                    r=R+dr[i]-R[0]
                    res=res+dist[i]*self.csphere(r,rho)
                return self.norm*res/sumdist+self.bkg

            elif self.dist=='LogNormal':
                lgn=LogNormal.LogNormal(x=0.0,pos=R[0],wid=self.Rsig)
                rmin,rmax=find_minmax(lgn,pos=R[0],wid=self.Rsig)
                dr=np.linspace(rmin,rmax,self.N)
                lgn.x=dr
                dist=lgn.y()
                sumdist=np.sum(dist)
                self.output_params['Distribution']={'x':dr,'y':dist/sumdist}
                res=np.zeros_like(self.x)
                for i in range(len(dr)):
                    r=R+dr[i]-R[0]
                    res=res+dist[i]*self.csphere(r,rho)
                return self.norm*res/sumdist+self.bkg
            else:
                return np.ones_like(self.x)
Ejemplo n.º 5
0
 def calc_Rdist(self, R, Rsig, dist, N):
     R = np.array(R)
     totalR = np.sum(R[:-1])
     if Rsig > 0.001:
         fdist = eval(dist + '.' + dist + '(x=0.001, pos=totalR, wid=Rsig)')
         rmin, rmax = find_minmax(fdist, totalR, Rsig)
         dr = np.linspace(rmin, rmax, N)
         fdist.x = dr
         rdist = fdist.y()
         sumdist = np.sum(rdist)
         rdist = rdist / sumdist
         self.output_params['Distribution'] = {'x': dr, 'y': rdist}
         return dr, rdist, totalR
     else:
         self.output_params['Distribution'] = {'x': [totalR], 'y': [1.0]}
         return [totalR], [1.0], totalR
Ejemplo n.º 6
0
 def calc_mesh(self, R=[1.0], Rsig=[0.0], Np=100):
     """
     Computes a multi-dimensional meshgrid of radii (R) of interfaces with a finite widths (Rsig>0.001) of distribution
     :param R:
     :param Rsig:
     :return:
     """
     r1 = 'np.meshgrid('
     for (i, r) in enumerate(R):
         if Rsig[i] > 0.001:
             lgn = eval(self.dist + '.' + self.dist +
                        '(x=0.001, pos=r, wid=Rsig[i])')
             rmin, rmax = find_minmax(lgn, r, Rsig[i])
             r1 = r1 + 'np.linspace(%.10f,%.10f,%d),' % (rmin, rmax, Np)
         else:
             r1 = r1 + '[%.10f],' % r
     r1 = r1[:-1] + ',sparse=True)'
     return (eval(r1))