Changes in sasmodels/details.py [ccd5f01:f39759c] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/details.py
rccd5f01 rf39759c 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 # skipping scale and background when building values and weights 235 values, weights = zip(*pairs[2:npars+2]) if npars else ((), ()) 236 weights = correct_theta_weights(kernel.info.parameters, values, weights) 234 237 length = np.array([len(w) for w in weights]) 235 238 offset = np.cumsum(np.hstack((0, length))) … … 244 247 return call_details, data, is_magnetic 245 248 249 def correct_theta_weights(parameters, values, weights): 250 # type: (ParameterTable, Sequence[np.ndarray], Sequence[np.ndarray]) -> Sequence[np.ndarray] 251 """ 252 If there is a theta parameter, update the weights of that parameter so that 253 the cosine weighting required for polar integration is preserved. Avoid 254 evaluation strictly at the pole, which would otherwise send the weight to 255 zero. 256 257 Note: values and weights do not include scale and background 258 """ 259 # TODO: document code, explaining why scale and background are skipped 260 # given that we don't have scale and background in the list, we 261 # should be calling the variables something other than values and weights 262 # Apparently the parameters.theta_offset similarly skips scale and 263 # and background, so the indexing works out. 264 if parameters.theta_offset >= 0: 265 index = parameters.theta_offset 266 theta = values[index] 267 theta_weight = np.minimum(abs(cos(radians(theta))), 1e-6) 268 # copy the weights list so we can update it 269 weights = list(weights) 270 weights[index] = theta_weight*np.asarray(weights[index]) 271 weights = tuple(weights) 272 return weights 273 246 274 247 275 def convert_magnetism(parameters, values): 276 # type: (ParameterTable, Sequence[np.ndarray]) -> bool 248 277 """ 249 278 Convert magnetism values from polar to rectangular coordinates. … … 255 284 scale = mag[:,0] 256 285 if np.any(scale): 257 theta, phi = mag[:, 1]*pi/180., mag[:, 2]*pi/180.286 theta, phi = radians(mag[:, 1]), radians(mag[:, 2]) 258 287 cos_theta = cos(theta) 259 288 mag[:, 0] = scale*cos_theta*cos(phi) # mx … … 269 298 """ 270 299 Create a mesh grid of dispersion parameters and weights. 300 301 pars is a list of pairs (values, weights), where the values are the 302 individual parameter values at which to evaluate the polydispersity 303 distribution and weights are the weights associated with each value. 304 305 Only the volume parameters should be included in this list. Orientation 306 parameters do not affect the calculation of effective radius or volume 307 ratio. 271 308 272 309 Returns [p1,p2,...],w where pj is a vector of values for parameter j
Note: See TracChangeset
for help on using the changeset viewer.