Changeset d4c33d6 in sasmodels for sasmodels/details.py
- Timestamp:
- Apr 12, 2017 10:50:29 AM (7 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 597878a
- Parents:
- 535fee6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/details.py
rccd5f01 rd4c33d6 15 15 16 16 import numpy as np # type: ignore 17 from numpy import pi, cos, sin 17 from numpy import pi, cos, sin, radians 18 18 19 19 try: … … 29 29 30 30 try: 31 from typing import List 31 from typing import List, Tuple, Sequence 32 32 except ImportError: 33 33 pass 34 34 else: 35 35 from .modelinfo import ModelInfo 36 from .modelinfo import ParameterTable 36 37 37 38 … … 53 54 coordinates, the total circumference decreases as latitude varies from 54 55 pi r^2 at the equator to 0 at the pole, and the weight associated 55 with a range of phivalues needs to be scaled by this circumference.56 with a range of latitude values needs to be scaled by this circumference. 56 57 This scale factor needs to be updated each time the theta value 57 58 changes. *theta_par* indicates which of the values in the parameter … … 231 232 nvalues = kernel.info.parameters.nvalues 232 233 scalars = [(v[0] if len(v) else np.NaN) for v, w in pairs] 233 values, weights = zip(*pairs[2:npars+2]) if npars else ((),()) 234 values, weights = zip(*pairs[2:npars+2]) if npars else ((), ()) 235 weights = correct_theta_weights(kernel.info.parameters, values, weights) 234 236 length = np.array([len(w) for w in weights]) 235 237 offset = np.cumsum(np.hstack((0, length))) … … 244 246 return call_details, data, is_magnetic 245 247 248 def correct_theta_weights(parameters, values, weights): 249 # type: (ParameterTable, Sequence[np.ndarray], Sequence[np.ndarray]) -> Sequence[np.ndarray] 250 """ 251 If there is a theta parameter, update the weights of that parameter so that 252 the cosine weighting required for polar integration is preserved. Avoid 253 evaluation strictly at the pole, which would otherwise send the weight to 254 zero. 255 """ 256 if parameters.theta_offset >= 0: 257 index = parameters.theta_offset+len(parameters.COMMON) 258 theta = values[index] 259 theta_weight = np.minimum(cos(radians(theta)), 1e-6) 260 # copy the weights list so we can update it 261 weights = list(weights) 262 weights[index] = theta_weight*weights[index] 263 weights = tuple(weights) 264 return weights 265 246 266 247 267 def convert_magnetism(parameters, values): 268 # type: (ParameterTable, Sequence[np.ndarray]) -> bool 248 269 """ 249 270 Convert magnetism values from polar to rectangular coordinates. … … 255 276 scale = mag[:,0] 256 277 if np.any(scale): 257 theta, phi = mag[:, 1]*pi/180., mag[:, 2]*pi/180.278 theta, phi = radians(mag[:, 1]), radians(mag[:, 2]) 258 279 cos_theta = cos(theta) 259 280 mag[:, 0] = scale*cos_theta*cos(phi) # mx … … 269 290 """ 270 291 Create a mesh grid of dispersion parameters and weights. 292 293 pars is a list of pairs (values, weights), where the values are the 294 individual parameter values at which to evaluate the polydispersity 295 distribution and weights are the weights associated with each value. 296 297 Only the volume parameters should be included in this list. Orientation 298 parameters do not affect the calculation of effective radius or volume 299 ratio. 271 300 272 301 Returns [p1,p2,...],w where pj is a vector of values for parameter j
Note: See TracChangeset
for help on using the changeset viewer.