Changeset a5a12ca in sasmodels for sasmodels/weights.py
- Timestamp:
- Oct 28, 2017 4:02:56 AM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 75e4319
- Parents:
- 6db17bd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/weights.py
r41e7f2e ra5a12ca 55 55 """ 56 56 sigma = self.width * center if relative else self.width 57 if not relative: 58 # For orientation, the jitter is relative to 0 not the angle 59 center = 0 60 pass 57 61 if sigma == 0 or self.npts < 2: 58 62 if lb <= center <= ub: … … 186 190 return x, px 187 191 192 class BoltzmannDispersion(Dispersion): 193 r""" 194 Boltzmann dispersion, with $\sigma=k T/E$. 195 196 .. math:: 197 198 w = \exp\left( -|x - c|/\sigma\right) 199 """ 200 type = "boltzmann" 201 default = dict(npts=35, width=0, nsigmas=3) 202 def _weights(self, center, sigma, lb, ub): 203 x = self._linspace(center, sigma, lb, ub) 204 px = np.exp(-np.abs(x-center) / np.abs(sigma)) 205 return x, px 188 206 189 207 # dispersion name -> disperser lookup table. … … 196 214 GaussianDispersion, 197 215 SchulzDispersion, 216 BoltzmannDispersion 198 217 )) 199 218 … … 225 244 obj = cls(n, width, nsigmas) 226 245 v, w = obj.get_weights(value, limits[0], limits[1], relative) 227 return v, w 228 229 230 def plot_weights(model_info, pairs):231 # type: (ModelInfo, List[Tuple[ np.ndarray, np.ndarray]]) -> None246 return v, w/np.sum(w) 247 248 249 def plot_weights(model_info, mesh): 250 # type: (ModelInfo, List[Tuple[float, np.ndarray, np.ndarray]]) -> None 232 251 """ 233 252 Plot the weights returned by :func:`get_weights`. 234 253 235 *model_info* is 236 :param model_info: 237 :param pairs: 238 :return: 254 *model_info* defines model parameters, etc. 255 256 *mesh* is a list of tuples containing (*value*, *dispersity*, *weights*) 257 for each parameter, where (*dispersity*, *weights*) pairs are the 258 distributions to be plotted. 239 259 """ 240 260 import pylab 241 261 242 if any(len( values)>1 for values, weights in pairs):262 if any(len(dispersity)>1 for value, dispersity, weights in mesh): 243 263 labels = [p.name for p in model_info.parameters.call_parameters] 244 pylab.interactive(True)264 #pylab.interactive(True) 245 265 pylab.figure() 246 for (v,w), s in zip(pairs, labels): 247 if len(v) > 1: 248 #print("weights for", s, v, w) 249 pylab.plot(v, w, '-o', label=s) 266 for (v,x,w), s in zip(mesh, labels): 267 if len(x) > 1: 268 pylab.plot(x, w, '-o', label=s) 250 269 pylab.grid(True) 251 270 pylab.legend()
Note: See TracChangeset
for help on using the changeset viewer.