示例#1
0
    def y(self):
        """
        Define the function in terms of x to return some value
        """
        q=self.x
        if self.dist=='Gaussian':
            if self.Rsig>1e-3:
                rdist=Gaussian.Gaussian(x=0.0,pos=self.R, wid=self.Rsig)
                rmin, rmax = max(0.001, self.R-5*self.Rsig),self.R+5*self.Rsig
                r = np.linspace(rmin, rmax, self.Nsample)
                rdist.x = r
                distr = rdist.y()
                self.output_params['R_distribution']={'x':r,'y':distr}
            else:
                r = np.array([self.R])
                distr=np.ones_like(r)
            if self.Hsig>1e-3:
                hdist=Gaussian.Gaussian(x=0.0,pos=self.H, wid=self.Hsig)
                hmin, hmax = max(0.001, self.H-5*self.Hsig),self.H+5*self.Hsig
                h = np.linspace(hmin, hmax, self.Nsample)
                hdist.x = h
                disth = hdist.y()
                self.output_params['H_distribution'] = {'x': h, 'y': disth}
                if self.Rsig < 1e-3:
                    r = np.ones_like(h) * self.R
                    distr=np.ones_like(r)
            else:
                h = np.ones_like(r) * self.H
                disth = np.ones_like(h)
        elif self.dist=='LogNormal':
            if self.Rsig > 1e-3:
                rdist = LogNormal.LogNormal(x=0.0, pos=self.R, wid=self.Rsig)
                rmin, rmax = max(0.001, self.R*(1 - np.exp(self.Rsig))), self.R*(1 + 2*np.exp(self.Rsig))
                r = np.linspace(rmin, rmax, self.Nsample)
                rdist.x = r
                distr = rdist.y()
                self.output_params['R_distribution'] = {'x': r, 'y': distr}
            else:
                r = np.array([self.R])
                distr = np.ones_like(r)
            if self.Hsig > 1e-3:
                hdist = LogNormal.LogNormal(x=0.0, pos=self.H,wid=self.Hsig)
                hmin, hmax = max(0.001, self.H*(1 - np.exp(self.Hsig))), self.H*(1 + 2*np.exp(self.Hsig))
                h = np.linspace(hmin, hmax, self.Nsample)
                hdist.x = h
                disth = hdist.y()
                self.output_params['H_distribution'] = {'x': h, 'y': disth}
                if self.Rsig < 1e-3:
                    r = np.ones_like(h) * self.R
                    distr=np.ones_like(r)
            else:
                h = np.ones_like(r) * self.H
                disth = np.ones_like(h)

        result = ff_cylinder_dist(q,r,distr,h,disth)
        return self.norm*result+self.bkg
示例#2
0
 def y(self):
     self.update_params()
     rho=self.rhoc-self.rhosol
     if self.dist == 'Gaussian':
         rmin, rmax = max(0.0001, np.min(self.__R__-5*self.__Rsig__)),np.max(self.__R__+5*self.__Rsig__)
         r=np.linspace(rmin,rmax,self.N)
     elif self.dist == 'LogNormal':
         rmin, rmax = max(0.0001, np.min(np.exp(np.log(self.__R__) - 5 * self.__Rsig__))), np.max(np.exp(np.log(self.__R__) + 5 * self.__Rsig__))
         r = np.logspace(np.log10(rmin), np.log10(rmax), self.N)
     else:
         maxr=np.max(self.__R__)
         rmin,rmax= 0.0,maxr+maxr*maxr**(1.0/np.max(self.__Rsig__))
         r = np.linspace(rmin,rmax, self.N)
     dist=np.zeros_like(r)
     tdist=[]
     for i in range(self.__Nl__):
         if self.dist == 'Gaussian':
             gau=Gaussian.Gaussian(x = r, pos = self.__R__[i], wid = self.__Rsig__[i])
             gau.x=r
             tdist.append(self.__Norm__[i]*gau.y())
             dist = dist + tdist[i]
         elif self.dist == 'LogNormal':
             lgn=LogNormal.LogNormal(x = r, pos = self.__R__[i], wid = self.__Rsig__[i])
             lgn.x = r
             tdist.append(self.__Norm__[i]*lgn.y())
             dist = dist + tdist[i]
         else:
             twdist=(self.__Rsig__[i]/self.__R__[i])*(r/self.__R__[i])**(self.__Rsig__[i]-1.0)*np.exp(-(r/self.__R__[i])**self.__Rsig__[i])
             tdist.append(self.__Norm__[i]*twdist)
             dist = dist  + tdist[i]
     sumdist = np.sum(dist)
     ffactor=calc_dist(self.x,r,dist,sumdist)
     I_total=self.norm * rho ** 2 * ffactor + self.bkg
     if not self.__fit__:
         self.output_params['I_total'] = {'x': self.x,'y': I_total}
         self.output_params['Distribution'] = {'x': r, 'y': dist / sumdist}
         mean = np.sum(r * dist) / sumdist
         self.output_params['scaler_parameters']['Rmean'] = mean
         self.output_params['scaler_parameters']['Rwidth'] = np.sqrt(np.sum((r - mean) ** 2 * dist) / sumdist)
         for i in range(len(tdist)):
             self.output_params[self.__mpar__['Distributions']['Dist'][i]] = {'x': r, 'y': tdist[i] / sumdist}
             tffactor=calc_dist(self.x,r,tdist[i],sumdist)
             self.output_params['I_'+self.__mpar__['Distributions']['Dist'][i]]={'x':self.x,'y':self.norm*rho**2*tffactor+self.bkg}
     return I_total
示例#3
0
文件: Sphere.py 项目: prjemian/XAnoS
 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)
示例#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)
示例#5
0
 def y(self):
     rho = self.rhoc - self.rhosol
     if self.Rsig < 1e-3:
         return self.norm * rho**2 * 16 * np.pi**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.integ == 'Trapezoid':
             if self.dist == 'Gaussian':
                 gau = Gaussian.Gaussian(x=0.001, pos=self.R, wid=self.Rsig)
                 rmin, rmax = max(0.001, self.R -
                                  5 * self.Rsig), self.R + 5 * 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
                 }
                 self.output_params['scaler_parameters']['Rmean'] = self.R
                 self.output_params['scaler_parameters'][
                     'Rwidth'] = 2.35482 * self.Rsig
                 print(dist)
                 if type(self.x) == np.ndarray:
                     ffactor = []
                     for x in self.x:
                         f = np.sum(
                             16.0 * np.pi**2 *
                             (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(
                         16 * np.pi**2 *
                         (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 = max(
                     0.001, np.exp(np.log(self.R) - 5 * self.Rsig)), np.exp(
                         np.log(self.R) + 5.0 * self.Rsig)
                 r = np.logspace(np.log10(rmin), np.log10(rmax), self.N)
                 lgn.x = r
                 dist = lgn.y()
                 sumdist = np.sum(dist)
                 self.output_params['Distribution'] = {
                     'x': r,
                     'y': dist / sumdist
                 }
                 self.output_params['scaler_parameters']['Rmean'] = np.exp(
                     np.log(self.R) + self.Rsig**2 / 2)
                 self.output_params['scaler_parameters'][
                     'Rwidth'] = np.sqrt(
                         (np.exp(self.Rsig**2) - 1) *
                         np.exp(2 * np.log(self.R) + self.Rsig**2))
                 if type(self.x) == np.ndarray:
                     ffactor = []
                     for x in self.x:
                         f = np.sum(
                             16 * np.pi**2 *
                             (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(
                         16 * np.pi**2 *
                         (np.sin(self.x * r) -
                          self.x * r * np.cos(self.x * r))**2 * dist /
                         self.x**6) / sumdist + self.bkg
         else:
             np.random.seed(100)
             if self.dist == 'Gaussian':
                 r = np.sort(np.random.normal(self.R, self.Rsig, 10000))
                 gau = Gaussian.Gaussian(x=r, pos=self.R, wid=self.Rsig)
                 dist = gau.y()
                 sumdist = np.sum(dist)
                 self.output_params['Distribution'] = {
                     'x': r,
                     'y': dist / sumdist
                 }
                 self.output_params['scaler_parameters']['Rmean'] = self.R
                 self.output_params['scaler_parameters'][
                     'Rwidth'] = 2.35482 * self.Rsig
                 if type(self.x) == np.ndarray:
                     ffactor = []
                     for x in self.x:
                         f = np.sum(
                             16.0 * np.pi**2 *
                             (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 * 16 * np.pi**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':
                 r = np.sort(
                     np.random.lognormal(np.log(self.R), self.Rsig, 10000))
                 lgn = LogNormal.LogNormal(x=r, pos=self.R, wid=self.Rsig)
                 dist = lgn.y()
                 sumdist = np.sum(dist)
                 self.output_params['Distribution'] = {
                     'x': r,
                     'y': dist / sumdist
                 }
                 self.output_params['scaler_parameters']['Rmean'] = np.exp(
                     np.log(self.R) + self.Rsig**2 / 2.0)
                 self.output_params['scaler_parameters'][
                     'Rwidth'] = np.sqrt(
                         (np.exp(self.Rsig**2) - 1) *
                         np.exp(2 * np.log(self.R) + self.Rsig**2))
                 if type(self.x) == np.ndarray:
                     ffactor = []
                     for x in self.x:
                         f = 16.0 * np.pi**2 * 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 * 16.0 * np.pi**2 * np.sum(
                         (np.sin(self.x * r) -
                          self.x * r * np.cos(self.x * r))**2 * dist /
                         self.x**6) / sumdist + self.bkg
示例#6
0
 def y(self):
     if self.Rsig < 1e-3 and self.shsig < 1e-3:
         amp, res = self.coreshell(self.x, self.R, self.rhoc, self.sh,
                                   self.rhosh, self.rhosol)
         return self.norm * res + self.bkg
     elif self.Rsig > 1e-3 and self.shsig < 1e-3:
         if self.dist == 'Gaussian':
             gau = Gaussian.Gaussian(x=0.001, pos=self.R, wid=self.Rsig)
             rmin, rmax = max(
                 0, self.R - 5 * self.Rsig
             ), self.R + 5 * self.Rsig  #find_minmax(gau,pos=self.R,wid=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:
                     amp, res = self.coreshell(x, r, self.rhoc, self.sh,
                                               self.rhosh, self.rhosol)
                     f = np.sum(res * dist)
                     ffactor.append(f / sumdist)
                 return self.norm * np.array(ffactor) + self.bkg
             else:
                 amp, res = self.coreshell(self.x, r, self.rhoc, self.sh,
                                           self.rhosh, self.rhosol)
                 return self.norm * np.sum(res * dist) / sumdist + self.bkg
         elif self.dist == 'LogNormal':
             lgn = LogNormal.LogNormal(x=0.001, pos=self.R, wid=self.Rsig)
             rmin, rmax = 0.001, self.R * (1 + np.exp(
                 5 * self.Rsig))  #find_minmax(lgn,pos=self.R,wid=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:
                     amp, res = self.coreshell(x, r, self.rhoc, self.sh,
                                               self.rhosh, self.rhosol)
                     f = np.sum(res * dist)
                     ffactor.append(f / sumdist)
                 return self.norm * np.array(ffactor) + self.bkg
             else:
                 amp, res = self.coreshell(self.x, r, self.rhoc, self.sh,
                                           self.rhosh, self.rhosol)
                 return self.norm * np.sum(res * dist) / sumdist + self.bkg
         else:
             #amp,res=self.coreshell(self.x,self.R,self.rhoc,self.sh,self.rhosh)
             return np.ones_like(self.x)
     elif self.Rsig < 1e-3 and self.shsig > 1e-3:
         if self.dist == 'Gaussian':
             gau = Gaussian.Gaussian(x=0.001, pos=self.sh, wid=self.shsig)
             shmin, shmax = max(
                 0, self.sh - 5 * self.shsig
             ), self.sh + 5 * self.shsig  #find_minmax(gau,pos=self.sh,wid=self.shsig)
             sh = np.linspace(shmin, shmax, self.N)
             gau.x = sh
             dist = gau.y()
             sumdist = np.sum(dist)
             self.output_params['Distribution'] = {
                 'x': sh,
                 'y': dist / sumdist
             }
             if type(self.x) == np.ndarray:
                 ffactor = []
                 for x in self.x:
                     amp, res = self.coreshell(x, self.R, self.rhoc, sh,
                                               self.rhosh, self.rhosol)
                     f = np.sum(res * dist)
                     ffactor.append(f / sumdist)
                 return self.norm * np.array(ffactor) + self.bkg
             else:
                 amp, res = self.coreshell(self.x, self.R, self.rhoc, sh,
                                           self.rhosh, self.rhosol)
                 return self.norm * np.sum(res * dist) / sumdist + self.bkg
         elif self.dist == 'LogNormal':
             lgn = LogNormal.LogNormal(x=0.001, pos=self.sh, wid=self.shsig)
             shmin, shmax = 0.001, self.sh * (
                 1 + np.exp(5 * self.shsig)
             )  #find_minmax(lgn,pos=self.sh,wid=self.shsig)
             sh = np.linspace(shmin, shmax, self.N)
             lgn.x = sh
             dist = lgn.y()
             sumdist = np.sum(dist)
             self.output_params['Distribution'] = {
                 'x': sh,
                 'y': dist / sumdist
             }
             if type(self.x) == np.ndarray:
                 ffactor = []
                 for x in self.x:
                     amp, res = self.coreshell(x, self.R, self.rhoc, sh,
                                               self.rhosh, self.rhosol)
                     f = np.sum(res * dist)
                     ffactor.append(f / sumdist)
                 return self.norm * np.array(ffactor) + self.bkg
             else:
                 amp, res = self.coreshell(self.x, self.R, self.rhoc, sh,
                                           self.rhosh, self.rhosol)
                 return self.norm * np.sum(res * dist) / sumdist + self.bkg
         else:
             #amp,res=self.coreshell(self.x,self.R,self.rhoc,self.sh,self.rhosh)
             return np.ones_like(self.x)
     else:
         if self.dist == 'Gaussian':
             gau = Gaussian.Gaussian(x=0.001, pos=self.R, wid=self.Rsig)
             rmin, rmax = max(
                 0, self.R - 5 * self.Rsig
             ), self.R + 5 * self.Rsig  #find_minmax(gau,pos=self.R,wid=self.Rsig)
             r = np.linspace(rmin, rmax, self.N)
             shmin, shmax = max(
                 0, self.sh - 5 * self.shsig
             ), self.sh + 5 * self.shsig  #find_minmax(gau,pos=self.sh,wid=self.shsig)
             sh = np.linspace(shmin, shmax, self.N)
             R, Sh = np.meshgrid(r, sh)
             dist = np.exp(-(R - self.R)**2 / 2.0 / self.Rsig**2) * np.exp(
                 -(Sh - self.sh)**2 / 2.0 / self.shsig**2)
             sumdist = np.sum(dist)
             self.output_params['Distribution2D'] = {
                 'x': R,
                 'y': Sh,
                 'z': dist / sumdist
             }
             self.output_params['Distribution1D_R'] = {
                 'x': r,
                 'y':
                 np.exp(-(r - self.R)**2 / 2.0 / self.Rsig**2) / sumdist
             }
             self.output_params['Distribution1D_sh'] = {
                 'x': sh,
                 'y':
                 np.exp(-(sh - self.sh)**2 / 2.0 / self.shsig**2) / sumdist
             }
             if type(self.x) == np.ndarray:
                 ffactor = []
                 for x in self.x:
                     amp, res = self.coreshell(x, R, self.rhoc, Sh,
                                               self.rhosh, self.rhosol)
                     f = np.sum(res * dist)
                     ffactor.append(f / sumdist)
                 return self.norm * np.array(ffactor) + self.bkg
             else:
                 amp, res = self.coreshell(self.x, R, self.rhoc, Sh,
                                           self.rhosh, self.rhosol)
                 return self.norm * np.sum(res * dist) / sumdist + self.bkg
         elif self.dist == 'LogNormal':
             lgn = LogNormal.LogNormal(x=0.001, pos=self.R, wid=self.Rsig)
             rmin, rmax = 0.001, self.R * (
                 1 + 5 * np.exp(self.Rsig)
             )  #min(0,self.R-5*self.Rsig),self.R+5*self.Rsig#find_minmax(lgn,pos=self.R,wid=self.Rsig)
             r = np.linspace(rmin, rmax, self.N)
             shmin, shmax = 0.001, self.sh * (
                 1 + 5 * np.exp(self.shsig)
             )  #find_minmax(lgn,pos=self.sh,wid=self.shsig)
             sh = np.linspace(shmin, shmax, self.N)
             R, Sh = np.meshgrid(r, sh)
             dist = np.exp(-(np.log(R) - np.log(self.R))**2 / 2.0 /
                           self.Rsig**2) * np.exp(
                               -(np.log(Sh) - np.log(self.sh))**2 / 2.0 /
                               self.shsig**2) / R / Sh
             sumdist = np.sum(dist)
             self.output_params['Distribution2D'] = {
                 'x': R,
                 'y': Sh,
                 'z': dist / sumdist
             }
             self.output_params['Distribution1D_R'] = {
                 'x':
                 r,
                 'y':
                 np.exp(-(np.log(r) - np.log(self.R))**2 / 2.0 /
                        self.Rsig**2) / r / sumdist
             }
             self.output_params['Distribution1D_sh'] = {
                 'x':
                 sh,
                 'y':
                 np.exp(-(np.log(sh) - np.log(self.sh))**2 / 2.0 /
                        self.shsig**2) / sh / sumdist
             }
             #self.srshdist=dist/sumdist
             if type(self.x) == np.ndarray:
                 ffactor = []
                 for x in self.x:
                     amp, res = self.coreshell(x, R, self.rhoc, Sh,
                                               self.rhosh, self.rhosol)
                     f = np.sum(res * dist)
                     ffactor.append(f / sumdist)
                 return self.norm * np.array(ffactor) + self.bkg
             else:
                 amp, res = self.coreshell(self.x, R, self.rhoc, Sh,
                                           self.rhosh, self.rhosol)
                 return self.norm * np.sum(res * dist) / sumdist + self.bkg
         else:
             #amp,res=self.coreshell(self.x,self.R,self.rhoc,self.sh,self.rhosh)
             return np.ones_like(self.x)