Changeset d86f0fc in sasmodels for sasmodels/multiscat.py


Ignore:
Timestamp:
Mar 26, 2018 3:52:24 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
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
Message:

lint reduction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/multiscat.py

    r49d1f8b8 rd86f0fc  
    261261 
    262262def 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    """ 
    263269    L = -np.log(1-p) 
    264270    num_scatter = truncated_poisson_invcdf(coverage, L) 
     
    266272    return coeffs 
    267273 
    268 def truncated_poisson_invcdf(p, L): 
     274def truncated_poisson_invcdf(coverage, L): 
    269275    r""" 
    270     Return smallest k such that cdf(k; L) > p from the truncated Poisson 
     276    Return smallest k such that cdf(k; L) > coverage from the truncated Poisson 
    271277    probability excluding k=0 
    272278    """ 
     
    275281    pmf = -np.exp(-L) / np.expm1(-L) 
    276282    k = 0 
    277     while cdf < p: 
     283    while cdf < coverage: 
    278284        k += 1 
    279285        pmf *= L/k 
     
    305311 
    306312class 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    """ 
    307337    def __init__(self, qmin=None, qmax=None, nq=None, window=2, 
    308338                 probability=None, coverage=0.99, 
    309339                 is2d=False, resolution=None, 
    310340                 dtype=PRECISION): 
    311         r""" 
    312         Compute multiple scattering using Fourier convolution. 
    313  
    314         The fourier steps are determined by *qmax*, the maximum $q$ value 
    315         desired, *nq* the number of $q$ steps and *window*, the amount 
    316         of padding around the circular convolution.  The $q$ spacing 
    317         will be $\Delta q = 2 q_\mathrm{max} w / n_q$.  If *nq* is not 
    318         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 scattering 
    321         events in the sample $\lambda$ as $p = 1 = e^{-\lambda}$.  As a 
    322         hack to allow probability to be a fitted parameter, the "value" 
    323         can be a function that takes no parameters and returns the current 
    324         value of the probability.  *coverage* determines how many scattering 
    325         steps to consider.  The default is 0.99, which sets $n$ such that 
    326         $1 \ldots n$ covers 99% of the Poisson probability mass function. 
    327  
    328         *is2d* is True then 2D scattering is used, otherwise it accepts 
    329         and returns 1D scattering. 
    330  
    331         *resolution* is the resolution function to apply after multiple 
    332         scattering.  If present, then the resolution $q$ vectors will provide 
    333         default values for *qmin*, *qmax* and *nq*. 
    334         """ 
    335341        # Infer qmin, qmax from instrument resolution calculator, if present 
    336342        if resolution is not None: 
     
    424430        # Prepare the multiple scattering calculator (either numpy or OpenCL) 
    425431        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 
    426436 
    427437    def apply(self, theory): 
     
    471481 
    472482    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        """ 
    473487        # circular average, no anti-aliasing 
    474488        Iq = np.histogram(self._radius, bins=self._edges, weights=Iqxy)[0]/self._norm 
     
    478492def annular_average(qxy, Iqxy, qbins): 
    479493    """ 
    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*. 
    481496    """ 
    482497    qxy, Iqxy = qxy.flatten(), Iqxy.flatten() 
Note: See TracChangeset for help on using the changeset viewer.