Changeset 279e371 in sasview for sansmodels
- Timestamp:
- Apr 18, 2012 1:26:13 PM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 499fe7a
- Parents:
- 3ee4d96
- Location:
- sansmodels
- Files:
-
- 2 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/BEPolyelectrolyte.py
r27972c1d r279e371 1 #!/usr/bin/env python 2 """ 3 4 Provide F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ 1 """ 2 Provide F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ 5 3 *(q^(2)-(12*h*C/b^(2))) 6 4 BEPolyelectrolyte as a BaseComponent model 7 5 """ 8 6 … … 11 9 12 10 class BEPolyelectrolyte(BaseComponent): 13 14 11 """ 15 12 Class that evaluates a BEPolyelectrolyte. … … 37 34 ## Name of the model 38 35 self.name = "BEPolyelectrolyte" 39 self.description ="""36 self.description = """ 40 37 F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k^(2))/(1+(r02)^(2)) 41 38 *(q^(2)+k^(2))*(q^(2)-(12*h*C/b^(2)))+bkd … … 53 50 ## Define parameters 54 51 self.params = {} 55 self.params['k'] = 1056 self.params['lb'] = 7.157 self.params['h'] = 1258 self.params['b'] = 1059 self.params['cs'] = 0.060 self.params['alpha'] = 0.0561 self.params['c'] = 0.752 self.params['k'] = 10 53 self.params['lb'] = 7.1 54 self.params['h'] = 12 55 self.params['b'] = 10 56 self.params['cs'] = 0.0 57 self.params['alpha'] = 0.05 58 self.params['c'] = 0.7 62 59 self.params['background'] = 0.0 63 64 60 65 61 ## Parameter details [units, min, max] 66 62 self.details = {} 67 self.details['k'] = ['[barns]', None, None]68 self.details['lb'] = ['[A]', None, None]69 self.details['h'] = ['[1/A^(2)]', None, None]70 self.details['b'] = ['[A]', None, None]71 self.details['cs'] = ['[mol/L]', None, None]72 self.details['alpha'] 73 self.details['c'] = ['[mol/L]', None, None]63 self.details['k'] = ['[barns]', None, None] 64 self.details['lb'] = ['[A]', None, None] 65 self.details['h'] = ['[1/A^(2)]', None, None] 66 self.details['b'] = ['[A]', None, None] 67 self.details['cs'] = ['[mol/L]', None, None] 68 self.details['alpha'] = ['', None, None] 69 self.details['c'] = ['[mol/L]', None, None] 74 70 self.details['background'] = ['[1/cm]', None, None] 75 71 #list of parameter that cannot be fitted 76 self.fixed = []72 self.fixed = [] 77 73 78 74 def _BEPoly(self, x): … … 89 85 Ca = self.params['c'] * 6.022136e-4 90 86 #remove singulars 91 if self.params['alpha']<=0 or self.params['c']<=0 or self.params['b']==0 or self.params['lb']<=0: 87 if self.params['alpha']<=0 or self.params['c']<=0\ 88 or self.params['b']==0 or self.params['lb']<=0: 92 89 return 0 93 90 else: … … 97 94 98 95 r02 = 1.0/self.params['alpha']/math.sqrt(Ca) * \ 99 (self.params['b']/math.sqrt((48.0*math.pi *self.params['lb']))) 96 (self.params['b']/\ 97 math.sqrt((48.0*math.pi*self.params['lb']))) 100 98 101 return self.params['k']/( 4.0 * math.pi * self.params['lb'] * self.params['alpha']**2 ) \ 99 return self.params['k']/( 4.0 * math.pi * self.params['lb'] \ 100 * self.params['alpha']**2 ) \ 102 101 * ( x**2 + K2 ) / ( 1.0 + r02**2 * ( x**2 + K2 ) \ 103 102 * (x**2 - ( 12.0 * self.params['h'] \ 104 103 * Ca/(self.params['b']**2) ))) \ 105 104 + self.params['background'] 106 107 105 108 106 def run(self, x = 0.0): -
sansmodels/src/sans/models/BroadPeakModel.py
r411d8bf r279e371 1 #!/usr/bin/env python2 1 """ 3 BroadPeakModel function as a BaseComponent model2 BroadPeakModel function as a BaseComponent model 4 3 """ 5 4 … … 61 60 inten = self.params['scale_p']/pow(x,self.params['exponent_p']) 62 61 inten += self.params['scale_l']/(1.0 + \ 63 power((math.fabs(x-self.params['q_peak'])*self.params['length_l']),\ 62 power((math.fabs(x-self.params['q_peak'])\ 63 *self.params['length_l']),\ 64 64 self.params['exponent_l'])) 65 65 … … 78 78 return self._broadpeak(x[0]) 79 79 elif x.__class__.__name__ == 'tuple': 80 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"80 raise ValueError, "Tuples are not allowed as input to models" 81 81 else: 82 82 return self._broadpeak(x) … … 93 93 return self._broadpeak(q) 94 94 elif x.__class__.__name__ == 'tuple': 95 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"95 raise ValueError, "Tuples are not allowed as input to models" 96 96 else: 97 97 return self._broadpeak(x) -
sansmodels/src/sans/models/Constant.py
r988130c6 r279e371 1 #!/usr/bin/env python 2 """Provide constant function as a BaseComponent model1 """ 2 Provide constant function as a BaseComponent model 3 3 """ 4 4 … … 20 20 ## Name of the model 21 21 self.name = "Constant" 22 self.description ='F(c)= c where c is a constant'22 self.description = 'F(c)= c where c is a constant' 23 23 ## Parameter details [units, min, max] 24 24 self.details = {} … … 26 26 self.params['value'] = 1.0 27 27 #list of parameter that cannot be fitted 28 self.fixed = []28 self.fixed = [] 29 29 def clone(self): 30 30 """ Return a identical copy of self """ -
sansmodels/src/sans/models/CoreMultiShellModel.py
r339ce67 r279e371 1 1 """ 2 Core-Multi-Shell model 3 """ 2 4 from sans.models.BaseComponent import BaseComponent 3 5 from sans.models.CoreFourShellModel import CoreFourShellModel … … 11 13 def __init__(self, multfactor=1): 12 14 BaseComponent.__init__(self) 13 """14 :param n_shells: number of shells in the model, assumes 1<= n_shells <=4.15 """16 15 17 16 ## Setting model name model description 18 self.description=""19 17 model = CoreFourShellModel() 20 18 self.model = model 21 19 self.name = "CoreMultiShellModel" 22 self.description =""20 self.description = "" 23 21 self.n_shells = multfactor 24 22 ## Define parameters … … 45 43 # [int(maximum no. of functionality),"str(Titl), 46 44 # [str(name of function0),...], [str(x-asix name of sld),...]] 47 self.multiplicity_info = [max_nshells, "No. of Shells:",[],['Radius']]48 49 ## parameters with orientation: can be removed since there is no orientational params45 self.multiplicity_info = [max_nshells, "No. of Shells:", [], ['Radius']] 46 47 ## parameters with orientation: 50 48 for item in self.model.orientation_params: 51 49 self.orientation_params.append(item) 52 53 50 54 51 def _clone(self, obj): … … 57 54 data members to a fresh copy. 58 55 """ 59 obj.params 60 obj.description 61 obj.details 56 obj.params = copy.deepcopy(self.params) 57 obj.description = copy.deepcopy(self.description) 58 obj.details = copy.deepcopy(self.details) 62 59 obj.dispersion = copy.deepcopy(self.dispersion) 63 obj.model 60 obj.model = self.model.clone() 64 61 65 62 return obj 66 67 63 68 64 def _set_dispersion(self): … … 75 71 nshell = 0 76 72 if name.split('_')[0] == 'thick': 77 while nshell <self.n_shells:73 while nshell < self.n_shells: 78 74 nshell += 1 79 75 if name.split('_')[1] == 'shell%s' % str(nshell): 80 self.dispersion[name] = value76 self.dispersion[name] = value 81 77 else: 82 78 continue 83 79 else: 84 self.dispersion[name] = value80 self.dispersion[name] = value 85 81 86 82 … … 94 90 nshell = 0 95 91 if name.split('_')[0] == 'thick' or name.split('_')[0] == 'sld': 96 if name.split('_')[1] == 'solv' or name.split('_')[1] == 'core0': 97 self.params[name]= value 92 if name.split('_')[1] == 'solv' \ 93 or name.split('_')[1] == 'core0': 94 self.params[name] = value 98 95 continue 99 while nshell <self.n_shells:96 while nshell < self.n_shells: 100 97 nshell += 1 101 98 if name.split('_')[1] == 'shell%s' % str(nshell): 102 self.params[name] = value99 self.params[name] = value 103 100 continue 104 101 else: 105 self.params[name] = value102 self.params[name] = value 106 103 107 104 … … 116 113 for name ,detail in self.model.details.iteritems(): 117 114 if name in self.params.iterkeys(): 118 self.details[name] = detail115 self.details[name] = detail 119 116 120 117 … … 131 128 132 129 for nshell in range(self.n_shells,max_nshells): 133 if key.split('_')[0] == 'sld' and key.split('_')[1] == 'shell%s' % str(nshell+1): 130 if key.split('_')[0] == 'sld' and \ 131 key.split('_')[1] == 'shell%s' % str(nshell+1): 134 132 try: 135 133 value = self.model.params['sld_solv'] 136 134 self.model.setParam(key, value) 137 except: pass 135 except: 136 message = "CoreMultiShellModel evaluation problem" 137 raise RuntimeError, message 138 138 139 139 def getProfile(self): … … 155 155 156 156 # for shells 157 for n in range(1, self.n_shells+1):157 for n in range(1, self.n_shells+1): 158 158 # Left side of each shells 159 159 r0 = r[len(r)-1] … … 186 186 self._setParamHelper( name, value) 187 187 ## setParam to model 188 if name=='sld_solv': 189 # the sld_*** model.params not in params must set to value of sld_solv 188 if name == 'sld_solv': 189 # the sld_*** model.params not in params 190 # must set to value of sld_solv 190 191 for key in self.model.params.iterkeys(): 191 192 if key not in self.params.keys()and key.split('_')[0] == 'sld': 192 193 self.model.setParam(key, value) 193 194 self.model.setParam( name, value) 194 195 … … 199 200 #look for dispersion parameters 200 201 toks = name.split('.') 201 if len(toks) ==2:202 if len(toks) == 2: 202 203 for item in self.dispersion.keys(): 203 204 if item.lower()==toks[0].lower(): … … 224 225 225 226 self.fixed.sort() 226 pass227 227 228 228 def run(self, x = 0.0): … … 250 250 ## Now (May27,10) directly uses the model eval function 251 251 ## instead of the for-loop in Base Component. 252 def evalDistribution(self, x = []):252 def evalDistribution(self, x): 253 253 """ 254 254 Evaluate the model in cartesian coordinates … … 267 267 :dispersion: dispersion object of type DispersionModel 268 268 """ 269 value = None269 value = None 270 270 try: 271 271 if parameter in self.model.dispersion.keys(): 272 value = self.model.set_dispersion(parameter, dispersion)272 value = self.model.set_dispersion(parameter, dispersion) 273 273 self._set_dispersion() 274 274 return value -
sansmodels/src/sans/models/CorrLengthModel.py
r411d8bf r279e371 56 56 Model definition 57 57 """ 58 inten = self.params['scale_p']/pow(x, self.params['exponent_p'])58 inten = self.params['scale_p']/pow(x, self.params['exponent_p']) 59 59 inten += self.params['scale_l']/(1.0 + \ 60 power((x*self.params['length_l']), self.params['exponent_l']))60 power((x*self.params['length_l']), self.params['exponent_l'])) 61 61 inten += self.params['background'] 62 62 … … 73 73 return self._corrlength(x[0]) 74 74 elif x.__class__.__name__ == 'tuple': 75 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"75 raise ValueError, "Tuples are not allowed as input to models" 76 76 else: 77 77 return self._corrlength(x) … … 88 88 return self._corrlength(q) 89 89 elif x.__class__.__name__ == 'tuple': 90 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"90 raise ValueError, "Tuples are not allowed as input to models" 91 91 else: 92 92 return self._corrlength(x) -
sansmodels/src/sans/models/Cos.py
r96672c0 r279e371 1 #!/usr/bin/env python 2 """Provide cos(x) function as a BaseComponent model1 """ 2 Provide cos(x) function as a BaseComponent model 3 3 """ 4 4 … … 7 7 8 8 class Cos(BaseComponent): 9 """ Class that evaluates a cos(x) model. 9 """ 10 Class that evaluates a cos(x) model. 10 11 """ 11 12 … … 18 19 ## Name of the model 19 20 self.name = "Cos" 20 self.description ='F(x)=cos(x)'21 self.description = 'F(x)=cos(x)' 21 22 ## Parameter details [units, min, max] 22 23 self.details = {} … … 34 35 return math.cos(x[0]*math.cos(x[1]))*math.cos(x[0]*math.sin(x[1])) 35 36 elif x.__class__.__name__ == 'tuple': 36 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"37 raise ValueError, "Tuples are not allowed as input to models" 37 38 else: 38 39 return math.cos(x) … … 46 47 return math.cos(x[0])*math.cos(x[1]) 47 48 elif x.__class__.__name__ == 'tuple': 48 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"49 raise ValueError, "Tuples are not allowed as input to models" 49 50 else: 50 51 return math.cos(x) 51 52 # End of file 52 -
sansmodels/src/sans/models/DebyeModel.py
r26e4a24 r279e371 1 #!/usr/bin/env python2 1 """ 3 2 Provide F(x) = 2( exp(-x) + x - 1 )/x**2 … … 6 5 Debye function as a BaseComponent model 7 6 """ 8 9 7 from sans.models.BaseComponent import BaseComponent 10 8 import math 11 9 12 10 class DebyeModel(BaseComponent): 13 14 11 """ 15 12 Class that evaluates a Debye model. … … 32 29 ## Name of the model 33 30 self.name = "Debye" 34 self.description ="""31 self.description = """ 35 32 F(x) = 2( exp(-x) + x - 1 )/x**2 36 33 with x = (q*R_g)**2 … … 53 50 self.details['background'] = ['[1/cm]', None, None] 54 51 #list of parameter that cannot be fitted 55 self.fixed= [] 52 self.fixed = [] 53 56 54 def _debye(self, x): 57 55 """ … … 65 63 y = (x * self.params['rg'])**2.0 66 64 if x == 0: 67 D =165 D = 1 68 66 else: 69 D = 2.0*( math.exp(-y) + y -1.0 )/y**2.070 return self.params['scale'] * D + self.params['background']67 D = 2.0*( math.exp(-y) + y -1.0 )/y**2.0 68 return self.params['scale'] * D + self.params['background'] 71 69 72 70 def run(self, x = 0.0): … … 78 76 return self._debye(x[0]) 79 77 elif x.__class__.__name__ == 'tuple': 80 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"78 raise ValueError, "Tuples are not allowed as input to models" 81 79 else: 82 80 return self._debye(x) … … 91 89 return self._debye(q) 92 90 elif x.__class__.__name__ == 'tuple': 93 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"91 raise ValueError, "Tuples are not allowed as input to models" 94 92 else: 95 93 return self._debye(x) -
sansmodels/src/sans/models/DisperseModel.py
r0abf7bf r279e371 1 #!/usr/bin/env python2 1 """ 3 Wrapper for the Disperser class extension 4 5 :author: Mathieu Doucet / UTK 6 7 :contact: mathieu.doucet@nist.gov 8 2 Wrapper for the Disperser class extension 9 3 """ 10 11 4 from sans.models.BaseComponent import BaseComponent 12 5 from sans_extension.c_models import Disperser … … 14 7 class DisperseModel(Disperser, BaseComponent): 15 8 """ 16 17 18 19 20 21 22 23 24 25 26 27 28 29 9 Wrapper class for the Disperser extension 10 Python class that takes a model and averages its output 11 for a distribution of its parameters. 12 13 The parameters to be varied are specified at instantiation time. 14 The distributions are Gaussian, with std deviations specified for 15 each parameter at instantiation time. 16 17 Example: :: 18 19 cyl = CylinderModel() 20 disp = DisperseModel(cyl, ['cyl_phi'], [0.3]) 21 disp.run([0.01, 1.57]) 22 30 23 """ 31 24 … … 34 27 Initialization 35 28 36 37 38 39 29 :param model: Model to disperse [BaseComponent] 30 :param paramList: list of parameters to disperse [List of strings] 31 :param sigmaList: list of std deviations for Gaussian dispersion 32 [List of floats] 40 33 41 34 """ … … 48 41 ## Keep track of the underlying model 49 42 self.model = model 50 self.description =''43 self.description ='' 51 44 #list of parameter that cannot be fitted 52 self.fixed = []45 self.fixed = [] 53 46 54 47 def clone(self): 55 48 """ Return a identical copy of self """ 56 obj = DisperseModel(self.model, self.params['paramList'], self.params['sigmaList'])57 return obj49 return DisperseModel(self.model, self.params['paramList'], 50 self.params['sigmaList']) 58 51 59 52 def setParam(self, name, value): 60 """ 61 """ 62 if name.lower() in self.params: 63 BaseComponent.setParam(self, name, value) 64 else: 65 self.model.setParam(name, value) 53 """ 54 Set a parameter value 55 :param name: parameter name 56 """ 57 if name.lower() in self.params: 58 BaseComponent.setParam(self, name, value) 59 else: 60 self.model.setParam(name, value) 66 61 67 62 def getParam(self, name): 68 """ 69 """ 70 if name.lower() in self.params: 71 return BaseComponent.getParam(self, name) 72 else: 73 return self.model.getParam(name) 63 """ 64 Get the value of the given parameter 65 :param name: parameter name 66 """ 67 if name.lower() in self.params: 68 return BaseComponent.getParam(self, name) 69 else: 70 return self.model.getParam(name) 74 71 75 72 def run(self, x = 0.0): 76 73 """ 77 Evaluate the model 78 79 :param x: input q, or [q,phi] 80 81 :return: scattering function P(q) 82 74 Evaluate the model 75 :param x: input q, or [q,phi] 76 :return: scattering function P(q) 83 77 """ 84 78 return Disperser.run(self, x) … … 86 80 def runXY(self, x = 0.0): 87 81 """ 88 Evaluate the model 89 90 :param x: input q, or [q,phi] 91 92 :return: scattering function P(q) 93 82 Evaluate the model 83 :param x: input q, or [q,phi] 84 :return: scattering function P(q) 94 85 """ 95 86 return Disperser.runXY(self, x) -
sansmodels/src/sans/models/FractalCoreShellModel.py
r31f9d0c2 r279e371 131 131 if name == 'scale': 132 132 name = 'volfraction' 133 self.params[name] = value133 self.params[name] = value 134 134 self.params['frac_dim'] = 2.0 135 135 self.params['cor_length'] = 100.0 … … 206 206 +self._fractalcore(x[0])*self.model.run(x) 207 207 elif x.__class__.__name__ == 'tuple': 208 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"208 raise ValueError, "Tuples are not allowed as input to models" 209 209 else: 210 210 return self.params['background']\ … … 222 222 if x.__class__.__name__ == 'list': 223 223 q = math.sqrt(x[0]**2 + x[1]**2) 224 return self.params['background']+self._fractalcore(q)*self.model.runXY(x) 224 return self.params['background']\ 225 +self._fractalcore(q)*self.model.runXY(x) 225 226 elif x.__class__.__name__ == 'tuple': 226 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"227 raise ValueError, "Tuples are not allowed as input to models" 227 228 else: 228 return self.params['background'] +self._fractalcore(x)*self.model.runXY(x)229 229 return self.params['background']\ 230 +self._fractalcore(x)*self.model.runXY(x) 230 231 231 232 def set_dispersion(self, parameter, dispersion): -
sansmodels/src/sans/models/GaussLorentzGelModel.py
r79411b2 r279e371 1 #!/usr/bin/env python2 1 """ 3 Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0)4 GaussLorentzGel function as a BaseComponent model2 Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0) 3 GaussLorentzGel function as a BaseComponent model 5 4 """ 6 7 5 from sans.models.BaseComponent import BaseComponent 8 6 import math … … 56 54 #list of parameter that cannot be fitted 57 55 self.fixed = [] 56 58 57 def _gausslorentzgel(self, x): 59 58 """ 60 59 Model definition 61 60 """ 62 inten = self.params['scale_g']*math.exp(-1.0*x*x*self.params['stat_colength']* \ 61 inten = self.params['scale_g'] \ 62 *math.exp(-1.0*x*x*self.params['stat_colength']* \ 63 63 self.params['stat_colength']/2.0) + self.params['scale_l']/ \ 64 64 (1.0 + (x*self.params['dyn_colength'])* \ … … 74 74 return self._gausslorentzgel(x[0]) 75 75 elif x.__class__.__name__ == 'tuple': 76 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"76 raise ValueError, "Tuples are not allowed as input to models" 77 77 else: 78 78 return self._gausslorentzgel(x) … … 87 87 return self._gausslorentzgel(q) 88 88 elif x.__class__.__name__ == 'tuple': 89 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"89 raise ValueError, "Tuples are not allowed as input to models" 90 90 else: 91 91 return self._gausslorentzgel(x) -
sansmodels/src/sans/models/GuinierModel.py
r1ed3834 r279e371 1 #!/usr/bin/env python2 1 """ 3 2 Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0) 4 3 Guinier function as a BaseComponent model 5 4 """ 6 7 5 from sans.models.BaseComponent import BaseComponent 8 6 import math … … 28 26 ## Name of the model 29 27 self.name = "Guinier" 30 self.description =""" I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 )28 self.description = """ I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 ) 31 29 32 30 List of default parameters: … … 43 41 self.details['rg'] = ['[A]', None, None] 44 42 #list of parameter that cannot be fitted 45 self.fixed= [] 43 self.fixed = [] 44 46 45 def _guinier(self, x): 47 return self.params['scale'] * math.exp( -(self.params['rg']*x)**2 / 3.0 ) 46 """ 47 Evaluate guinier function 48 :param x: q-value 49 """ 50 return self.params['scale']*math.exp( -(self.params['rg']*x)**2/3.0 ) 48 51 49 52 def run(self, x = 0.0): 50 """ Evaluate the model 53 """ 54 Evaluate the model 51 55 @param x: input q-value (float or [float, float] as [r, theta]) 52 56 @return: (guinier value) … … 55 59 return self._guinier(x[0]) 56 60 elif x.__class__.__name__ == 'tuple': 57 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"61 raise ValueError, "Tuples are not allowed as input to models" 58 62 else: 59 63 return self._guinier(x) … … 68 72 return self._guinier(q) 69 73 elif x.__class__.__name__ == 'tuple': 70 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"74 raise ValueError, "Tuples are not allowed as input to models" 71 75 else: 72 76 return self._guinier(x) -
sansmodels/src/sans/models/GuinierPorodModel.py
r8f20419d r279e371 1 #!/usr/bin/env python2 1 """ 3 I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql4 = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql5 Guinier function as a BaseComponent model2 I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql 3 = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql 4 Guinier function as a BaseComponent model 6 5 """ 7 8 6 from sans.models.BaseComponent import BaseComponent 9 7 from math import sqrt,exp … … 24 22 ## Name of the model 25 23 self.name = "GuinierPorod" 26 self.description=""" I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql 24 self.description = """ 25 I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql 27 26 = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql 28 27 where ql = sqrt((m-s)(3-s)/2)/Rg. … … 49 48 50 49 #list of parameter that cannot be fitted 51 self.fixed = []50 self.fixed = [] 52 51 53 52 def _guinier_porod(self, x): … … 65 64 66 65 #do the calculation and return the function value 67 q1 =sqrt((n-3.0+m)*n/2.0)/Rg66 q1 = sqrt((n-3.0+m)*n/2.0)/Rg 68 67 if qval < q1: 69 68 F = (G/pow(qval,(3.0-n)))*exp((-qval*qval*Rg*Rg)/n) 70 69 else: 71 F = (G/pow(qval, m))*exp(-(n-3.0+m)/2.0)*pow(((n-3.0+m)*n/2.0),70 F = (G/pow(qval, m))*exp(-(n-3.0+m)/2.0)*pow(((n-3.0+m)*n/2.0), 72 71 ((n-3.0+m)/2.0))/pow(Rg,(n-3.0+m)) 73 72 inten = F + bgd … … 83 82 return self._guinier_porod(x[0]) 84 83 elif x.__class__.__name__ == 'tuple': 85 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"84 raise ValueError, "Tuples are not allowed as input to models" 86 85 else: 87 86 return self._guinier_porod(x) … … 96 95 return self._guinier_porod(q) 97 96 elif x.__class__.__name__ == 'tuple': 98 raise ValueError, "Tuples are not allowed as input to BaseComponentmodels"97 raise ValueError, "Tuples are not allowed as input to models" 99 98 else: 100 99 return self._guinier_porod(x) -
sansmodels/test/utest_other_models.py
r6e2d708 r279e371 1447 1447 self.comp.setParam('B', 0.0) 1448 1448 self.assertRaises(ZeroDivisionError, self.comp.run, 10) 1449 #self.assert_(numpy.isfinite(self.comp.run(0.0))) 1450 1451 1452 class TestFractalAbsModel(unittest.TestCase): 1453 """ Unit tests for FractalAbsModel""" 1454 1455 def setUp(self): 1456 from sans.models.FractalAbsModel import FractalAbsModel 1457 self.comp = FractalAbsModel() 1458 self.comp.setParam('scale', 0.05) 1459 self.comp.setParam('radius', 5.0) 1460 self.comp.setParam('fractal_dim', 2.0) 1461 self.comp.setParam('cor_length',100.0) 1462 self.comp.setParam('sldBlock', 2.0e-6) 1463 self.comp.setParam('sldSolv', 6.35e-6) 1464 self.comp.setParam('background',0.0) 1465 1466 self.x = numpy.array([0.4, 1.3]) 1467 self.y = numpy.array([0.5, 1.57]) 1468 1469 self.x_array = self.comp.evalDistribution(self.x) 1470 self.y_array = self.comp.evalDistribution(self.y) 1471 qx_prime = numpy.reshape(self.x, [1,len(self.x)]) 1472 qy_prime = numpy.reshape(self.y, [len(self.y),1]) 1473 self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) 1474 1475 def test1D(self): 1476 """ Test 1D model for a Fractal Abs Model""" 1477 self.assertAlmostEqual(self.comp.run(0.001), 39.2881, 3) 1478 1479 def test1D_2(self): 1480 """ Test 2D model for a Fractal Abs Model""" 1481 self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 39.2881, 3) 1482 1483 def testEval_1D(self): 1484 """ Test 1D model for a Fractal Abs Model with evalDistribution""" 1485 self.assertEquals(self.comp.run(0.4),self.x_array[0]) 1486 self.assertEquals(self.comp.run(1.3),self.x_array[1]) 1487 1488 def testEval_2D(self): 1489 """ Test 2D model for a Fractal Abs Model with evalDistribution""" 1490 self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) 1491 self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) 1492 1493 # No more singular point 1494 #def testCriticalPoint(self): 1495 # """ Test Fractal Abs at the critical point""" 1496 # self.assert_(numpy.isfinite(self.comp.run(0.0))) 1449 #self.assert_(numpy.isfinite(self.comp.run(0.0))) 1497 1450 1498 1451 class TestFractalModel(unittest.TestCase):
Note: See TracChangeset
for help on using the changeset viewer.