Changeset d86f0fc in sasmodels for sasmodels/multiscat.py
- Timestamp:
- Mar 26, 2018 3:52:24 PM (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:
- 802c412
- Parents:
- f4ae8c4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/multiscat.py
r49d1f8b8 rd86f0fc 261 261 262 262 def scattering_coeffs(p, coverage=0.99): 263 r""" 264 Return the coefficients of the scattering powers for transmission 265 probability *p*. This is just the corresponding values for the 266 Poisson distribution for $\lambda = -\ln(1-p)$ such that 267 $\sum_{k = 0 \ldots n} P(k; \lambda)$ is larger than *coverage*. 268 """ 263 269 L = -np.log(1-p) 264 270 num_scatter = truncated_poisson_invcdf(coverage, L) … … 266 272 return coeffs 267 273 268 def truncated_poisson_invcdf( p, L):274 def truncated_poisson_invcdf(coverage, L): 269 275 r""" 270 Return smallest k such that cdf(k; L) > pfrom the truncated Poisson276 Return smallest k such that cdf(k; L) > coverage from the truncated Poisson 271 277 probability excluding k=0 272 278 """ … … 275 281 pmf = -np.exp(-L) / np.expm1(-L) 276 282 k = 0 277 while cdf < p:283 while cdf < coverage: 278 284 k += 1 279 285 pmf *= L/k … … 305 311 306 312 class MultipleScattering(Resolution): 313 r""" 314 Compute multiple scattering using Fourier convolution. 315 316 The fourier steps are determined by *qmax*, the maximum $q$ value 317 desired, *nq* the number of $q$ steps and *window*, the amount 318 of padding around the circular convolution. The $q$ spacing 319 will be $\Delta q = 2 q_\mathrm{max} w / n_q$. If *nq* is not 320 given it will use $n_q = 2^k$ such that $\Delta q < q_\mathrm{min}$. 321 322 *probability* is related to the expected number of scattering 323 events in the sample $\lambda$ as $p = 1 = e^{-\lambda}$. As a 324 hack to allow probability to be a fitted parameter, the "value" 325 can be a function that takes no parameters and returns the current 326 value of the probability. *coverage* determines how many scattering 327 steps to consider. The default is 0.99, which sets $n$ such that 328 $1 \ldots n$ covers 99% of the Poisson probability mass function. 329 330 *is2d* is True then 2D scattering is used, otherwise it accepts 331 and returns 1D scattering. 332 333 *resolution* is the resolution function to apply after multiple 334 scattering. If present, then the resolution $q$ vectors will provide 335 default values for *qmin*, *qmax* and *nq*. 336 """ 307 337 def __init__(self, qmin=None, qmax=None, nq=None, window=2, 308 338 probability=None, coverage=0.99, 309 339 is2d=False, resolution=None, 310 340 dtype=PRECISION): 311 r"""312 Compute multiple scattering using Fourier convolution.313 314 The fourier steps are determined by *qmax*, the maximum $q$ value315 desired, *nq* the number of $q$ steps and *window*, the amount316 of padding around the circular convolution. The $q$ spacing317 will be $\Delta q = 2 q_\mathrm{max} w / n_q$. If *nq* is not318 given it will use $n_q = 2^k$ such that $\Delta q < q_\mathrm{min}$.319 320 *probability* is related to the expected number of scattering321 events in the sample $\lambda$ as $p = 1 = e^{-\lambda}$. As a322 hack to allow probability to be a fitted parameter, the "value"323 can be a function that takes no parameters and returns the current324 value of the probability. *coverage* determines how many scattering325 steps to consider. The default is 0.99, which sets $n$ such that326 $1 \ldots n$ covers 99% of the Poisson probability mass function.327 328 *is2d* is True then 2D scattering is used, otherwise it accepts329 and returns 1D scattering.330 331 *resolution* is the resolution function to apply after multiple332 scattering. If present, then the resolution $q$ vectors will provide333 default values for *qmin*, *qmax* and *nq*.334 """335 341 # Infer qmin, qmax from instrument resolution calculator, if present 336 342 if resolution is not None: … … 424 430 # Prepare the multiple scattering calculator (either numpy or OpenCL) 425 431 self.transform = Calculator((2*nq, 2*nq), dtype=dtype) 432 433 # Iq and Iqxy will be set during apply 434 self.Iq = None # type: np.ndarray 435 self.Iqxy = None # type: np.ndarray 426 436 427 437 def apply(self, theory): … … 471 481 472 482 def radial_profile(self, Iqxy): 483 """ 484 Compute that radial profile for the given Iqxy grid. The grid should 485 be defined as for 486 """ 473 487 # circular average, no anti-aliasing 474 488 Iq = np.histogram(self._radius, bins=self._edges, weights=Iqxy)[0]/self._norm … … 478 492 def annular_average(qxy, Iqxy, qbins): 479 493 """ 480 Compute annular average of points at 494 Compute annular average of points in *Iqxy* at *qbins*. The $q_x$, $q_y$ 495 coordinates for *Iqxy* are given in *qxy*. 481 496 """ 482 497 qxy, Iqxy = qxy.flatten(), Iqxy.flatten()
Note: See TracChangeset
for help on using the changeset viewer.