Changeset 841753c in sasmodels
- Timestamp:
- Jan 28, 2016 5:42:34 PM (9 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- d4666ca
- Parents:
- 69ec80f
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
extra/pylint.rc
r37a7252 r841753c 64 64 star-args, 65 65 unbalanced-tuple-unpacking, 66 locally-enabled, 66 67 locally-disabled, 67 68 … … 107 108 good-names=_, 108 109 input, 109 i,j,k,n,x,y,z,110 h,i,j,k,n,w,x,y,z, 110 111 q,qx,qy,qz, 111 112 dt,dx,dy,dz,id, 112 Iq,dIq,Qx,Qy,Qz, 113 Iq,dIq,Qx,Qy,Qz,Iqxy, 113 114 p, 114 115 ER, call_ER, VR, call_VR, 116 Rmax, SElength, 115 117 116 118 # Bad variable names which should always be refused, separated by a comma … … 335 337 336 338 # Maximum number of arguments for function / method 337 max-args= 5339 max-args=15 338 340 339 341 # Argument names that match this expression will be ignored. Default to name … … 342 344 343 345 # Maximum number of locals for function / method body 344 max-locals= 15346 max-locals=25 345 347 346 348 # Maximum number of return / yield for function / method body -
sasmodels/compare.py
r4f2478e r841753c 533 533 if Nbase > 0: 534 534 if Ncomp > 0: plt.subplot(131) 535 plot_theory(data, base_value, view=view, plot_data=False, limits=limits)535 plot_theory(data, base_value, view=view, use_data=False, limits=limits) 536 536 plt.title("%s t=%.1f ms"%(base.engine, base_time)) 537 537 #cbar_title = "log I" 538 538 if Ncomp > 0: 539 539 if Nbase > 0: plt.subplot(132) 540 plot_theory(data, comp_value, view=view, plot_data=False, limits=limits)540 plot_theory(data, comp_value, view=view, use_data=False, limits=limits) 541 541 plt.title("%s t=%.1f ms"%(comp.engine, comp_time)) 542 542 #cbar_title = "log I" … … 548 548 err, errstr, errview = abs(relerr), "rel err", "log" 549 549 #err,errstr = base/comp,"ratio" 550 plot_theory(data, None, resid=err, view=errview, plot_data=False)550 plot_theory(data, None, resid=err, view=errview, use_data=False) 551 551 plt.title("max %s = %.3g"%(errstr, max(abs(err)))) 552 552 #cbar_title = errstr if errview=="linear" else "log "+errstr -
sasmodels/models/be_polyelectrolyte.py
r07a6700 r841753c 50 50 """ 51 51 52 from numpy import inf, p ower, pi, sqrt52 from numpy import inf, pi, sqrt 53 53 54 54 name = "be_polyelectrolyte" 55 55 title = "Polyelectrolyte with the RPA expression derived by Borue and Erukhimovich" 56 56 description = """ 57 58 59 57 Evaluate 58 F(x) = K 1/(4 pi Lb (alpha)^(2)) (q^(2)+k2)/(1+(r02)^(2)) 59 (q^(2)+k2) (q^(2)-(12 h C/b^(2))) 60 60 61 62 63 64 65 61 has 3 internal parameters : 62 The inverse Debye Length: K2 = 4 pi Lb (2 Cs+alpha C) 63 r02 =1/alpha/Ca^(0.5) (B/(48 pi Lb)^(0.5)) 64 Ca = 6.022136e-4 C 65 """ 66 66 category = "shape-independent" 67 67 68 # ["name", "units", default, [lower, upper], "type", "description"], 69 parameters = [["contrast_factor", "barns", 10.0, [-inf, inf], "", "Contrast factor of the polymer"], 70 ["bjerrum_length", "Ang", 7.1, [0, inf], "", "Bjerrum length"], 71 ["virial_param", "1/Ang^2", 12.0, [-inf, inf], "", "Virial parameter"], 72 ["monomer_length", "Ang", 10.0, [0, inf], "", "Monomer length"], 73 ["salt_concentration", "mol/L", 0.0, [-inf, inf], "", "Concentration of monovalent salt"], 74 ["ionization_degree", "", 0.05, [0, inf], "", "Degree of ionization"], 75 ["polymer_concentration", "mol/L", 0.7, [0, inf], "", "Polymer molar concentration"], 76 ] 68 # pylint: disable=bad-whitespace,line-too-long 69 # ["name", "units", default, [lower, upper], "type", "description"], 70 parameters = [ 71 ["contrast_factor", "barns", 10.0, [-inf, inf], "", "Contrast factor of the polymer"], 72 ["bjerrum_length", "Ang", 7.1, [0, inf], "", "Bjerrum length"], 73 ["virial_param", "1/Ang^2", 12.0, [-inf, inf], "", "Virial parameter"], 74 ["monomer_length", "Ang", 10.0, [0, inf], "", "Monomer length"], 75 ["salt_concentration", "mol/L", 0.0, [-inf, inf], "", "Concentration of monovalent salt"], 76 ["ionization_degree", "", 0.05, [0, inf], "", "Degree of ionization"], 77 ["polymer_concentration", "mol/L", 0.7, [0, inf], "", "Polymer molar concentration"], 78 ] 79 # pylint: enable=bad-whitespace,line-too-long 77 80 78 81 … … 106 109 107 110 def Iqxy(qx, qy, *args): 108 iq = Iq(sqrt(qx**2 + qy**2), *args) 109 110 return iq 111 return Iq(sqrt(qx**2 + qy**2), *args) 111 112 112 113 Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values … … 133 134 polymer_concentration='c') 134 135 136 # pylint: disable=bad-whitespace 135 137 tests = [ 136 137 138 139 140 141 142 143 144 145 138 # Accuracy tests based on content in test/utest_other_models.py 139 [{'contrast_factor': 10.0, 140 'bjerrum_length': 7.1, 141 'virial_param': 12.0, 142 'monomer_length': 10.0, 143 'salt_concentration': 0.0, 144 'ionization_degree': 0.05, 145 'polymer_concentration': 0.7, 146 'background': 0.001, 147 }, 0.001, 0.0948379], 146 148 147 148 149 150 151 152 153 154 155 149 # Additional tests with larger range of parameters 150 [{'contrast_factor': 10.0, 151 'bjerrum_length': 100.0, 152 'virial_param': 3.0, 153 'monomer_length': 1.0, 154 'salt_concentration': 10.0, 155 'ionization_degree': 2.0, 156 'polymer_concentration': 10.0, 157 }, 0.1, -3.75693800588], 156 158 157 158 159 160 161 162 163 164 165 159 [{'contrast_factor': 10.0, 160 'bjerrum_length': 100.0, 161 'virial_param': 3.0, 162 'monomer_length': 1.0, 163 'salt_concentration': 10.0, 164 'ionization_degree': 2.0, 165 'polymer_concentration': 10.0, 166 'background': 100.0 167 }, 5.0, 100.029142149], 166 168 167 [{'contrast_factor': 100.0, 168 'bjerrum_length': 10.0, 169 'virial_param': 180.0, 170 'monomer_length': 1.0, 171 'salt_concentration': 0.1, 172 'ionization_degree': 0.5, 173 'polymer_concentration': 0.1, 174 }, 200., 1.80664667511e-06], 175 ] 169 [{'contrast_factor': 100.0, 170 'bjerrum_length': 10.0, 171 'virial_param': 180.0, 172 'monomer_length': 1.0, 173 'salt_concentration': 0.1, 174 'ionization_degree': 0.5, 175 'polymer_concentration': 0.1, 176 }, 200., 1.80664667511e-06], 177 ] 178 # pylint: enable=bad-whitespace -
sasmodels/models/pearl_necklace.py
rcf404cb r841753c 1 1 r""" 2 This model provides the form factor for a pearl necklace composed of two 3 elements: *N* pearls (homogeneous spheres of radius *R*) freely jointed by *M* 2 This model provides the form factor for a pearl necklace composed of two 3 elements: *N* pearls (homogeneous spheres of radius *R*) freely jointed by *M* 4 4 rods (like strings - with a total mass *Mw* = *M* \* *m*\ :sub:`r` + *N* \* *m*\ 5 :sub:`s`, and the string segment length (or edge separation) *l* 5 :sub:`s`, and the string segment length (or edge separation) *l* 6 6 (= *A* - 2\ *R*)). *A* is the center-to-center pearl separation distance. 7 7 … … 13 13 ---------- 14 14 15 The output of the scattering intensity function for the PearlNecklaceModel is 15 The output of the scattering intensity function for the PearlNecklaceModel is 16 16 given by (Schweins, 2004) 17 17 … … 37 37 \beta(q) &= \frac{\int_{qR}^{q(A-R)}\frac{sin(t)}{t}dt}{ql} 38 38 39 where the mass *m*\ :sub:`i` is (SLD\ :sub:`i` - SLD\ :sub:`solvent`) \* 39 where the mass *m*\ :sub:`i` is (SLD\ :sub:`i` - SLD\ :sub:`solvent`) \* 40 40 (volume of the *N* pearls/rods). *V* is the total volume of the necklace. 41 41 42 The 2D scattering intensity is the same as $P(q)$ above, regardless of the 42 The 2D scattering intensity is the same as $P(q)$ above, regardless of the 43 43 orientation of the *q* vector. 44 44 … … 54 54 REFERENCE 55 55 56 R Schweins and K Huber, *Particle Scattering Factor of Pearl Necklace Chains*, 56 R Schweins and K Huber, *Particle Scattering Factor of Pearl Necklace Chains*, 57 57 *Macromol. Symp.* 211 (2004) 25-42 2004 58 58 """ … … 79 79 80 80 # ["name", "units", default, [lower, upper], "type","description"], 81 parameters = [["radius", "Angstrom", 80.0, [0, inf], "volume", 81 parameters = [["radius", "Angstrom", 80.0, [0, inf], "volume", 82 82 "Mean radius of the chained spheres"], 83 ["edge_separation", "Angstrom", 350.0, [0, inf], "volume", 83 ["edge_separation", "Angstrom", 350.0, [0, inf], "volume", 84 84 "Mean separation of chained particles"], 85 ["string_thickness", "Angstrom", 2.5, [0, inf], "volume", 85 ["string_thickness", "Angstrom", 2.5, [0, inf], "volume", 86 86 "Thickness of the chain linkage"], 87 ["number_of_pearls", "none", 3, [0, inf], "volume", 87 ["number_of_pearls", "none", 3, [0, inf], "volume", 88 88 "Mean number of pearls in each necklace"], 89 ["sld", "Angstrom^2", 1.0, [-inf, inf], "", 89 ["sld", "Angstrom^2", 1.0, [-inf, inf], "", 90 90 "Scattering length density of the chained spheres"], 91 ["string_sld", "Angstrom^2", 1.0, [-inf, inf], "", 91 ["string_sld", "Angstrom^2", 1.0, [-inf, inf], "", 92 92 "Scattering length density of the chain linkage"], 93 ["solvent_sld", "Angstrom^2", 6.3, [-inf, inf], "", 93 ["solvent_sld", "Angstrom^2", 6.3, [-inf, inf], "", 94 94 "Scattering length density of the solvent"], 95 95 ] 96 96 97 97 source = ["lib/Si.c", "pearl_necklace.c"] … … 110 110 # names and the target sasview model name. 111 111 oldname = 'PearlNecklaceModel' 112 oldpars = dict(scale='scale', background='background',radius='radius',112 oldpars = dict(scale='scale', background='background', radius='radius', 113 113 number_of_pearls='num_pearls', solvent_sld='sld_solv', 114 114 string_thickness='thick_string', sld='sld_pearl', -
sasmodels/models/power_law.py
reb69cce r841753c 12 12 I(q) = \text{scale} \cdot q^{-\text{power}} + \text{background} 13 13 14 Note the minus sign in front of the exponent. The exponent *power* 14 Note the minus sign in front of the exponent. The exponent *power* 15 15 should therefore be entered as a **positive** number for fitting. 16 16 17 Also note that unlike many other models, *scale* in this model 18 is NOT explicitly related to a volume fraction. Be careful if 17 Also note that unlike many other models, *scale* in this model 18 is NOT explicitly related to a volume fraction. Be careful if 19 19 combining this model with other models. 20 20 … … 31 31 from numpy import inf, sqrt 32 32 33 name = 33 name = "power_law" 34 34 title = "Simple power law with a flat background" 35 35 36 description = """ \37 38 39 40 36 description = """ 37 Evaluates the function 38 I(q) = scale * q^(-power) + background 39 NB: enter power as a positive number! 40 """ 41 41 category = "shape-independent" 42 42 … … 45 45 46 46 # NB: Scale and Background are implicit parameters on every model 47 def Iq(q,power): 47 def Iq(q, power): 48 # pylint: disable=missing-docstring 48 49 inten = (q**-power) 49 50 return inten … … 51 52 52 53 def Iqxy(qx, qy, *args): 54 # pylint: disable=missing-docstring 53 55 return Iq(sqrt(qx ** 2 + qy ** 2), *args) 54 56 Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values … … 64 66 65 67 tests = [ 66 [ {'scale': 1.0, 'power': 4.0, 'background' : 0.0}, [0.0106939, 0.469418], [7.64644e+07, 20.5949]] 67 ] 68 [{'scale': 1.0, 'power': 4.0, 'background' : 0.0}, 69 [0.0106939, 0.469418], [7.64644e+07, 20.5949]], 70 ] -
sasmodels/resolution2d.py
r9404dd3 r841753c 2 2 #This software was developed by the University of Tennessee as part of the 3 3 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 #project funded by the US National Science Foundation. 4 #project funded by the US National Science Foundation. 5 5 #See the license text in license.txt 6 6 """ … … 19 19 ## Defaults 20 20 NR = {'xhigh':10, 'high':5, 'med':5, 'low':3} 21 NPHI = {'xhigh':20, 'high':12, 'med':6, 'low':4}21 NPHI = {'xhigh':20, 'high':12, 'med':6, 'low':4} 22 22 23 23 class Pinhole2D(Resolution): … … 25 25 Gaussian Q smearing class for SAS 2d data 26 26 """ 27 27 28 28 def __init__(self, data=None, index=None, 29 29 nsigma=NSIGMA, accuracy='Low', coords='polar'): 30 30 """ 31 31 Assumption: equally spaced bins in dq_r, dq_phi space. 32 32 33 33 :param data: 2d data used to set the smearing parameters 34 34 :param index: 1d array with len(data) to define the range … … 42 42 ## number of bins in r axis for over-sampling 43 43 self.nr = NR[accuracy.lower()] 44 ## number of bins in phi axis for over-sampling 44 ## number of bins in phi axis for over-sampling 45 45 self.nphi = NPHI[accuracy.lower()] 46 46 ## maximum nsigmas 47 self.nsigma = nsigma47 self.nsigma = nsigma 48 48 self.coords = coords 49 49 self._init_data(data, index) … … 85 85 def _calc_res(self): 86 86 """ 87 Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, 87 Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, 88 88 then find smeared intensity 89 """ 89 """ 90 90 nr, nphi = self.nr, self.nphi 91 91 # Total number of bins = # of bins … … 143 143 if self.coords == 'polar': 144 144 q_r = sqrt(qx**2 + qy**2) 145 qx_res = ( 145 qx_res = ((dqx*cos(dphi) + q_r) * cos(-q_phi) + 146 146 dqy*sin(dphi) * sin(-q_phi)) 147 147 qy_res = (-(dqx*cos(dphi) + q_r) * sin(-q_phi) + … … 167 167 else: 168 168 return theory 169 170 """171 if __name__ == '__main__':172 ## Test w/ 2D linear function173 x = 0.001*np.arange(1, 11)174 dx = np.ones(len(x))*0.0003175 y = 0.001*np.arange(1, 11)176 dy = np.ones(len(x))*0.001177 z = np.ones(10)178 dz = sqrt(z)179 180 from sas.dataloader import Data2D181 #for i in range(10): print(i, 0.001 + i*0.008/9.0)182 #for i in range(100): print(i, int(math.floor( (i/ (100/9.0)) )))183 out = Data2D()184 out.data = z185 out.qx_data = x186 out.qy_data = y187 out.dqx_data = dx188 out.dqy_data = dy189 out.q_data = sqrt(dx * dx + dy * dy)190 index = np.ones(len(x), dtype = bool)191 out.mask = index192 from sas.models.LineModel import LineModel193 model = LineModel()194 model.setParam("A", 0)195 196 smear = Smearer2D(out, model, index)197 #smear.set_accuracy('Xhigh')198 value = smear.get_value()199 ## All data are ones, so the smeared should also be ones.200 print("Data length =", len(value))201 print(" 2D linear function, I = 0 + 1*qy")202 text = " Gaussian weighted averaging on a 2D linear function will "203 text += "provides the results same as without the averaging."204 print(text)205 print("qx_data", "qy_data", "I_nonsmear", "I_smeared")206 for ind in range(len(value)):207 print(x[ind], y[ind], model.evalDistribution([x, y])[ind], value[ind])208 209 210 if __name__ == '__main__':211 ## Another Test w/ constant function212 x = 0.001*np.arange(1,11)213 dx = np.ones(len(x))*0.001214 y = 0.001*np.arange(1,11)215 dy = np.ones(len(x))*0.001216 z = np.ones(10)217 dz = sqrt(z)218 219 from DataLoader import Data2D220 #for i in range(10): print(i, 0.001 + i*0.008/9.0)221 #for i in range(100): print(i, int(math.floor( (i/ (100/9.0)) )))222 out = Data2D()223 out.data = z224 out.qx_data = x225 out.qy_data = y226 out.dqx_data = dx227 out.dqy_data = dy228 index = np.ones(len(x), dtype = bool)229 out.mask = index230 from sas.models.Constant import Constant231 model = Constant()232 233 value = Smearer2D(out,model,index).get_value()234 ## All data are ones, so the smeared values should also be ones.235 print("Data length =",len(value), ", Data=",value)236 """
Note: See TracChangeset
for help on using the changeset viewer.