Changeset 31df0c9 in sasmodels
- Timestamp:
- Aug 1, 2017 2:38:47 PM (7 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 1511c37c
- Parents:
- d49ca5c
- Location:
- sasmodels
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
r109d963 r31df0c9 270 270 Randomize a single parameter. 271 271 """ 272 # Set the amount of polydispersity/angular dispersion, but by default pd_n 273 # is zero so there is no polydispersity. This allows us to turn on/off 274 # pd by setting pd_n, and still have randomly generated values 272 275 if name.endswith('_pd'): 273 276 par = model_info.parameters[name[:-3]] … … 279 282 return np.random.beta(1.5, 7) 280 283 284 # pd is selected globally rather than per parameter, so set to 0 for no pd 285 # In particular, when multiple pd dimensions, want to decrease the number 286 # of points per dimension for faster computation 281 287 if name.endswith('_pd_n'): 282 # let pd be selected globally rather than per parameter283 288 return 0 284 289 290 # Don't mess with distribution type for now 285 291 if name.endswith('_pd_type'): 286 # Don't mess with distribution type for now287 292 return 'gaussian' 288 293 294 # type-dependent value of number of sigmas; for gaussian use 3. 289 295 if name.endswith('_pd_nsigma'): 290 # type-dependent value; for gaussian use 3.291 296 return 3. 292 297 298 # background in the range [0.01, 1] 293 299 if name == 'background': 294 return np.random.uniform(0, 1) 295 300 return 10**np.random.uniform(-2, 0) 301 302 # scale defaults to 0.1% to 30% volume fraction 296 303 if name == 'scale': 297 return 10**np.random.uniform(-5,0) 298 304 return 10**np.random.uniform(-3, -0.5) 305 306 # If it is a list of choices, pick one at random with equal probability 307 # In practice, the model specific random generator will override. 299 308 par = model_info.parameters[name] 300 309 if len(par.limits) > 2: # choice list 301 310 return np.random.randint(len(par.limits)) 302 311 312 # If it is a fixed range, pick from it with equal probability. 313 # For logarithmic ranges, the model will have to override. 303 314 if np.isfinite(par.limits).all(): 304 315 return np.random.uniform(*par.limits) 305 316 317 # If the paramter is marked as an sld use the range of neutron slds 318 # Should be doing something with randomly selected contrast matching 319 # but for now use random contrasts. Since real data is contrast-matched, 320 # this will favour selection of hollow models when they exist. 306 321 if par.type == 'sld': 307 322 # Range of neutron SLDs 308 323 return np.random.uniform(-0.5, 12) 309 324 325 # Guess at the random length/radius/thickness. In practice, all models 326 # are going to set their own reasonable ranges. 310 327 if par.type == 'volume': 311 328 if ('length' in par.name or 312 329 'radius' in par.name or 313 330 'thick' in par.name): 314 return 10**np.random.uniform(2,4) 315 331 return 10**np.random.uniform(2, 4) 332 333 # In the absence of any other info, select a value in [0, 2v], or 334 # [-2|v|, 2|v|] if v is negative, or [0, 1] if v is zero. Mostly the 335 # model random parameter generators will override this default. 316 336 low, high = parameter_range(par.name, value) 317 337 limits = (max(par.limits[0], low), min(par.limits[1], high)) -
sasmodels/models/barbell.py
ra151caa r31df0c9 117 117 def random(): 118 118 import numpy as np 119 # TODO: increase volume range once problem with bell radius is fixed 120 # The issue is that bell radii of more than about 200 fail at high q 121 V = 10**np.random.uniform(7, 9) 122 bar_volume = 10**np.random.uniform(-4, -1)*V 123 bell_volume = V - bar_volume 124 bell_radius = (bell_volume/6)**0.3333 # approximate 125 min_bar = bar_volume/np.pi/bell_radius**2 126 bar_length = 10**np.random.uniform(0, 3)*min_bar 127 bar_radius = np.sqrt(bar_volume/bar_length/np.pi) 128 if bar_radius > bell_radius: 129 bell_radius, bar_radius = bar_radius, bell_radius 119 130 pars = dict( 120 scale=10**np.random.uniform(-4,-1), 121 radius_bell=10**np.random.uniform(1.3,3), 122 length=10**np.random.uniform(0,3), 131 #background=0, 132 radius_bell=bell_radius, 133 radius=bar_radius, 134 length=bar_length, 123 135 ) 124 pars['radius'] = pars['radius_bell']*np.random.uniform(0,1)125 if pars['radius_bell'] < 100:126 pars['length'] *= 10127 pars['scale'] *= 100128 136 return pars 129 137 -
sasmodels/models/capped_cylinder.py
r9802ab3 r31df0c9 80 80 81 81 .. [#] H Kaya, *J. Appl. Cryst.*, 37 (2004) 223-230 82 .. [#] H Kaya and N-R deSouza, *J. Appl. Cryst.*, 37 (2004) 508-509 (addenda 82 .. [#] H Kaya and N-R deSouza, *J. Appl. Cryst.*, 37 (2004) 508-509 (addenda 83 83 and errata) 84 84 … … 136 136 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "capped_cylinder.c"] 137 137 138 def random(): 139 import numpy as np 140 # TODO: increase volume range once problem with bell radius is fixed 141 # The issue is that bell radii of more than about 200 fail at high q 142 V = 10**np.random.uniform(7, 9) 143 bar_volume = 10**np.random.uniform(-4, -1)*V 144 bell_volume = V - bar_volume 145 bell_radius = (bell_volume/6)**0.3333 # approximate 146 min_bar = bar_volume/np.pi/bell_radius**2 147 bar_length = 10**np.random.uniform(0, 3)*min_bar 148 bar_radius = np.sqrt(bar_volume/bar_length/np.pi) 149 if bar_radius > bell_radius: 150 bell_radius, bar_radius = bar_radius, bell_radius 151 pars = dict( 152 #background=0, 153 radius_cap=bell_radius, 154 radius=bar_radius, 155 length=bar_length, 156 ) 157 return pars 158 159 138 160 demo = dict(scale=1, background=0, 139 161 sld=6, sld_solvent=1, -
sasmodels/models/core_shell_ellipsoid.py
r9802ab3 r31df0c9 25 25 ellipsoid. This may have some undesirable effects if the aspect ratio of the 26 26 ellipsoid is large (ie, if $X << 1$ or $X >> 1$ ), when the $S(q)$ 27 - which assumes spheres - will not in any case be valid. Generating a 28 custom product model will enable separate effective volume fraction and effective 27 - which assumes spheres - will not in any case be valid. Generating a 28 custom product model will enable separate effective volume fraction and effective 29 29 radius in the $S(q)$. 30 30 … … 44 44 45 45 .. math:: 46 \begin{align} 46 \begin{align} 47 47 F(q,\alpha) = &f(q,radius\_equat\_core,radius\_equat\_core.x\_core,\alpha) \\ 48 48 &+ f(q,radius\_equat\_core + thick\_shell,radius\_equat\_core.x\_core + thick\_shell.x\_polar\_shell,\alpha) 49 \end{align} 49 \end{align} 50 50 51 51 where 52 52 53 53 .. math:: 54 54 … … 77 77 F^2(q)=\int_{0}^{\pi/2}{F^2(q,\alpha)\sin(\alpha)d\alpha} 78 78 79 For oriented ellipsoids the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 79 For oriented ellipsoids the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 80 80 see the :ref:`elliptical-cylinder` model for further information. 81 81 … … 151 151 return ellipsoid_ER(polar_outer, equat_outer) 152 152 153 154 demo = dict(scale=0.05, background=0.001, 155 radius_equat_core=20.0, 156 x_core=3.0, 157 thick_shell=30.0, 158 x_polar_shell=1.0, 159 sld_core=2.0, 160 sld_shell=1.0, 161 sld_solvent=6.3, 162 theta=0, 163 phi=0) 153 def random(): 154 import numpy as np 155 V = 10**np.random.uniform(5, 12) 156 radius_polar = 10**np.random.uniform(1.3, 4) 157 radius_equatorial = np.sqrt(V/radius_polar) # ignore 4/3 pi 158 thickness_polar = np.random.uniform(0.01, 1)*radius_polar 159 thickness_equatorial = np.random.uniform(0.01, 1)*radius_equatorial 160 radius_polar -= thickness_polar 161 radius_equatorial -= thickness_equatorial 162 x_core = radius_polar/radius_equatorial 163 x_polar_shell = thickness_polar/thickness_equatorial 164 pars = dict( 165 #background=0, sld=0, sld_solvent=1, 166 radius_equat_core=radius_equatorial, 167 x_core=x_core, 168 thick_shell=thickness_equatorial, 169 x_polar_shell=x_polar_shell, 170 ) 171 return pars 164 172 165 173 q = 0.1 -
sasmodels/models/core_shell_sphere.py
rd49ca5c r31df0c9 104 104 radius = np.random.uniform(0, 1)*total_radius 105 105 thickness = total_radius - radius 106 Vf = 10**np.random.uniform(4, 6)/total_radius**3107 106 pars = dict( 108 scale=Vf,109 107 radius=radius, 110 108 thickness=thickness, -
sasmodels/models/cylinder.py
r9802ab3 r31df0c9 63 63 .. figure:: img/cylinder_angle_definition.png 64 64 65 Definition of the $\theta$ and $\phi$ orientation angles for a cylinder relative 66 to the beam line coordinates, plus an indication of their orientation distributions 67 which are described as rotations about each of the perpendicular axes $\delta_1$ and $\delta_2$ 65 Definition of the $\theta$ and $\phi$ orientation angles for a cylinder relative 66 to the beam line coordinates, plus an indication of their orientation distributions 67 which are described as rotations about each of the perpendicular axes $\delta_1$ and $\delta_2$ 68 68 in the frame of the cylinder itself, which when $\theta = \phi = 0$ are parallel to the $Y$ and $X$ axes. 69 69 … … 72 72 Examples for oriented cylinders. 73 73 74 The $\theta$ and $\phi$ parameters to orient the cylinder only appear in the model when fitting 2d data. 74 The $\theta$ and $\phi$ parameters to orient the cylinder only appear in the model when fitting 2d data. 75 75 On introducing "Orientational Distribution" in the angles, "distribution of theta" and "distribution of phi" parameters will 76 appear. These are actually rotations about the axes $\delta_1$ and $\delta_2$ of the cylinder, which when $\theta = \phi = 0$ are parallel 76 appear. These are actually rotations about the axes $\delta_1$ and $\delta_2$ of the cylinder, which when $\theta = \phi = 0$ are parallel 77 77 to the $Y$ and $X$ axes of the instrument respectively. Some experimentation may be required to understand the 2d patterns fully. 78 (Earlier implementations had numerical integration issues in some circumstances when orientation distributions passed through 90 degrees, such 79 situations, with very broad distributions, should still be approached with care.) 78 (Earlier implementations had numerical integration issues in some circumstances when orientation distributions passed through 90 degrees, such 79 situations, with very broad distributions, should still be approached with care.) 80 80 81 81 Validation … … 150 150 return 0.5 * (ddd) ** (1. / 3.) 151 151 152 def random(): 153 import numpy as np 154 V = 10**np.random.uniform(5, 12) 155 length = 10**np.random.uniform(-2, 2)*V**0.333 156 radius = np.sqrt(V/length/np.pi) 157 pars = dict( 158 #scale=1, 159 #background=0, 160 length=length, 161 radius=radius, 162 ) 163 return pars 164 165 152 166 # parameters for demo 153 167 demo = dict(scale=1, background=0, -
sasmodels/models/ellipsoid.py
r404ebbd r31df0c9 184 184 def random(): 185 185 import numpy as np 186 V = 10**np.random.uniform( 4, 12)186 V = 10**np.random.uniform(5, 12) 187 187 radius_polar = 10**np.random.uniform(1.3, 4) 188 188 radius_equatorial = np.sqrt(V/radius_polar) # ignore 4/3 pi 189 Vf = 10**np.random.uniform(-4, -2)190 189 pars = dict( 191 190 #background=0, sld=0, sld_solvent=1, 192 scale=1e9*Vf/V,193 191 radius_polar=radius_polar, 194 192 radius_equatorial=radius_equatorial, -
sasmodels/models/flexible_cylinder.py
r42356c8 r31df0c9 86 86 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/wrc_cyl.c", "flexible_cylinder.c"] 87 87 88 demo = dict(scale=1.0, background=0.0001, 89 length=1000.0, 90 kuhn_length=100.0, 91 radius=20.0, 92 sld=1.0, 93 sld_solvent=6.3) 88 def random(): 89 import numpy as np 90 length = 10**np.random.uniform(2, 6) 91 radius = 10**np.random.uniform(1, 3) 92 kuhn_length = 10**np.random.uniform(-2, -0.7)*length # at least 10 segments 93 pars = dict( 94 length=length, 95 radius=radius, 96 kuhn_length=kuhn_length, 97 ) 98 return pars 94 99 95 100 tests = [ -
sasmodels/models/flexible_cylinder_elliptical.py
r40a87fa r31df0c9 112 112 "flexible_cylinder_elliptical.c"] 113 113 114 demo = dict(scale=1.0, background=0.0001, 115 length=1000.0, 116 kuhn_length=100.0, 117 radius=20.0, 118 axis_ratio=1.5, 119 sld=1.0, 120 sld_solvent=6.3) 114 def random(): 115 import numpy as np 116 length = 10**np.random.uniform(2, 6) 117 radius = 10**np.random.uniform(1, 3) 118 axis_ratio = 10**np.random.uniform(-1, 1) 119 kuhn_length = 10**np.random.uniform(-2, -0.7)*length # at least 10 segments 120 pars = dict( 121 length=length, 122 radius=radius, 123 axis_ratio=axis_ratio, 124 kuhn_length=kuhn_length, 125 ) 126 return pars 121 127 122 128 tests = [ -
sasmodels/models/fuzzy_sphere.py
r925ad6e r31df0c9 105 105 # VR defaults to 1.0 106 106 107 def random(): 108 import numpy as np 109 radius = 10**np.random.uniform(1, 4.7) 110 fuzziness = 10**np.random.uniform(-2, -0.5)*radius # 1% to 31% fuzziness 111 pars = dict( 112 radius=radius, 113 fuzziness=fuzziness, 114 ) 115 return pars 116 107 117 demo = dict(scale=1, background=0.001, 108 118 sld=1, sld_solvent=3, -
sasmodels/models/hollow_cylinder.py
rf102a96 r31df0c9 54 54 55 55 * **Author:** NIST IGOR/DANSE **Date:** pre 2010 56 * **Last Modified by:** Richard Heenan **Date:** October 06, 2016 56 * **Last Modified by:** Richard Heenan **Date:** October 06, 2016 57 57 (reparametrised to use thickness, not outer radius) 58 58 * **Last Reviewed by:** Richard Heenan **Date:** October 06, 2016 … … 121 121 return vol_shell, vol_total 122 122 123 # parameters for demo 124 demo = dict(scale=1.0, background=0.0, length=400.0, radius=20.0, 125 thickness=10, sld=6.3, sld_solvent=1, theta=90, phi=0, 126 thickness_pd=0.2, thickness_pd_n=9, 127 length_pd=.2, length_pd_n=10, 128 radius_pd=.2, radius_pd_n=9, 129 theta_pd=10, theta_pd_n=5, 130 ) 123 def random(): 124 import numpy as np 125 length = 10**np.random.uniform(2, 6) 126 radius = 10**np.random.uniform(1, 3) 127 kuhn_length = 10**np.random.uniform(-2, -0.7)*length # at least 10 segments 128 pars = dict( 129 length=length, 130 radius=radius, 131 kuhn_length=kuhn_length, 132 ) 133 return pars 134 131 135 q = 0.1 132 136 # april 6 2017, rkh added a 2d unit test, assume correct! -
sasmodels/models/hollow_rectangular_prism.py
rab2aea8 r31df0c9 146 146 147 147 148 def random(): 149 import numpy as np 150 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 151 thickness = np.random.uniform(0.01, 0.49) * min(a, b, c) 152 pars = dict( 153 length_a=a, 154 b2a_ratio=b/a, 155 c2a_ratio=c/a, 156 thickness=thickness, 157 ) 158 return pars 159 160 148 161 # parameters for demo 149 162 demo = dict(scale=1, background=0, -
sasmodels/models/hollow_rectangular_prism_thin_walls.py
rab2aea8 r31df0c9 127 127 128 128 129 def random(): 130 import numpy as np 131 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 132 pars = dict( 133 length_a=a, 134 b2a_ratio=b/a, 135 c2a_ratio=c/a, 136 ) 137 return pars 138 139 129 140 # parameters for demo 130 141 demo = dict(scale=1, background=0, -
sasmodels/models/parallelepiped.py
r34a9e4e r31df0c9 22 22 .. note:: 23 23 24 The three dimensions of the parallelepiped (strictly here a cuboid) may be given in 24 The three dimensions of the parallelepiped (strictly here a cuboid) may be given in 25 25 $any$ size order. To avoid multiple fit solutions, especially 26 with Monte-Carlo fit methods, it may be advisable to restrict their ranges. There may 27 be a number of closely similar "best fits", so some trial and error, or fixing of some 26 with Monte-Carlo fit methods, it may be advisable to restrict their ranges. There may 27 be a number of closely similar "best fits", so some trial and error, or fixing of some 28 28 dimensions at expected values, may help. 29 29 … … 115 115 116 116 On introducing "Orientational Distribution" in the angles, "distribution of theta" and "distribution of phi" parameters will 117 appear. These are actually rotations about axes $\delta_1$ and $\delta_2$ of the parallelepiped, perpendicular to the $a$ x $c$ and $b$ x $c$ faces. 118 (When $\theta = \phi = 0$ these are parallel to the $Y$ and $X$ axes of the instrument.) The third orientation distribution, in $\psi$, is 119 about the $c$ axis of the particle, perpendicular to the $a$ x $b$ face. Some experimentation may be required to 120 understand the 2d patterns fully. (Earlier implementations had numerical integration issues in some circumstances when orientation 121 distributions passed through 90 degrees, such situations, with very broad distributions, should still be approached with care.) 122 123 117 appear. These are actually rotations about axes $\delta_1$ and $\delta_2$ of the parallelepiped, perpendicular to the $a$ x $c$ and $b$ x $c$ faces. 118 (When $\theta = \phi = 0$ these are parallel to the $Y$ and $X$ axes of the instrument.) The third orientation distribution, in $\psi$, is 119 about the $c$ axis of the particle, perpendicular to the $a$ x $b$ face. Some experimentation may be required to 120 understand the 2d patterns fully. (Earlier implementations had numerical integration issues in some circumstances when orientation 121 distributions passed through 90 degrees, such situations, with very broad distributions, should still be approached with care.) 122 123 124 124 For a given orientation of the parallelepiped, the 2D form factor is 125 125 calculated as … … 241 241 242 242 # VR defaults to 1.0 243 244 245 def random(): 246 import numpy as np 247 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 248 pars = dict( 249 length_a=a, 250 length_b=b, 251 length_c=c, 252 ) 253 return pars 254 243 255 244 256 # parameters for demo -
sasmodels/models/rectangular_prism.py
rab2aea8 r31df0c9 104 104 ["length_a", "Ang", 35, [0, inf], "volume", 105 105 "Shorter side of the parallelepiped"], 106 ["b2a_ratio", " Ang", 1, [0, inf], "volume",106 ["b2a_ratio", "", 1, [0, inf], "volume", 107 107 "Ratio sides b/a"], 108 ["c2a_ratio", " Ang", 1, [0, inf], "volume",108 ["c2a_ratio", "", 1, [0, inf], "volume", 109 109 "Ratio sides c/a"], 110 110 ] … … 125 125 return 0.5 * (ddd) ** (1. / 3.) 126 126 127 def random(): 128 import numpy as np 129 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 130 pars = dict( 131 length_a=a, 132 b2a_ratio=b/a, 133 c2a_ratio=c/a, 134 ) 135 return pars 127 136 128 137 # parameters for demo -
sasmodels/models/sphere.py
r404ebbd r31df0c9 86 86 def random(): 87 87 import numpy as np 88 Vf = 10**np.random.uniform(-4, -2)89 88 radius = 10**np.random.uniform(1.3, 4) 90 V = radius**391 89 pars = dict( 92 #background=0, sld=1, sld_solvent=0,93 scale=1e10*Vf/V,94 90 radius=radius, 95 91 ) -
sasmodels/models/triaxial_ellipsoid.py
r34a9e4e r31df0c9 71 71 small angle diffraction situations there may be a number of closely similar "best fits", 72 72 so some trial and error, or fixing of some radii at expected values, may help. 73 73 74 74 To provide easy access to the orientation of the triaxial ellipsoid, 75 75 we define the axis of the cylinder using the angles $\theta$, $\phi$ … … 79 79 .. figure:: img/elliptical_cylinder_angle_definition.png 80 80 81 Definition of angles for oriented triaxial ellipsoid, where radii are for illustration here 81 Definition of angles for oriented triaxial ellipsoid, where radii are for illustration here 82 82 $a < b << c$ and angle $\Psi$ is a rotation around the axis of the particle. 83 83 84 For oriented ellipsoids the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 84 For oriented ellipsoids the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 85 85 see the :ref:`elliptical-cylinder` model for further information. 86 86 … … 173 173 return ellipsoid_ER(polar, equatorial) 174 174 175 def random(): 176 import numpy as np 177 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 178 pars = dict( 179 radius_equat_minor=a, 180 radius_equat_major=b, 181 radius_polar=c, 182 ) 183 return pars 184 185 175 186 demo = dict(scale=1, background=0, 176 187 sld=6, sld_solvent=1,
Note: See TracChangeset
for help on using the changeset viewer.