Index: sasmodels/compare.py
===================================================================
--- sasmodels/compare.py	(revision 3bfd9244700230889d9d5b718ebdc9c2b992d983)
+++ sasmodels/compare.py	(revision 110f69cfa1143196495c76df1d5cff08c6ce884e)
@@ -150,6 +150,12 @@
 kerneldll.ALLOW_SINGLE_PRECISION_DLLS = True
 
-# list of math functions for use in evaluating parameters
-MATH = dict((k,getattr(math, k)) for k in dir(math) if not k.startswith('_'))
+def build_math_context():
+    # type: () -> Dict[str, Callable]
+    """build dictionary of functions from math module"""
+    return dict((k, getattr(math, k))
+                for k in dir(math) if not k.startswith('_'))
+
+#: list of math functions for use in evaluating parameters
+MATH = build_math_context()
 
 # CRUFT python 2.6
@@ -231,5 +237,5 @@
         pass
 
-    def __exit__(self, exc_type, exc_value, traceback):
+    def __exit__(self, exc_type, exc_value, tb):
         # type: (Any, BaseException, Any) -> None
         # TODO: better typing for __exit__ method
@@ -374,4 +380,16 @@
 
 def _random_pd(model_info, pars):
+    # type: (ModelInfo, Dict[str, float]) -> None
+    """
+    Generate a random dispersity distribution for the model.
+
+    1% no shape dispersity
+    85% single shape parameter
+    13% two shape parameters
+    1% three shape parameters
+
+    If oriented, then put dispersity in theta, add phi and psi dispersity
+    with 10% probability for each.
+    """
     pd = [p for p in model_info.parameters.kernel_parameters if p.polydisperse]
     pd_volume = []
@@ -444,5 +462,5 @@
         value = pars[p.name]
         if p.units == 'Ang' and value > maxdim:
-            pars[p.name] = maxdim*10**np.random.uniform(-3,0)
+            pars[p.name] = maxdim*10**np.random.uniform(-3, 0)
 
 def constrain_pars(model_info, pars):
@@ -490,5 +508,4 @@
         if pars['radius'] < pars['thick_string']:
             pars['radius'], pars['thick_string'] = pars['thick_string'], pars['radius']
-        pass
 
     elif name == 'rpa':
@@ -608,4 +625,5 @@
     return pars
 
+# TODO: remove support for sasview 3.x models
 def eval_sasview(model_info, data):
     # type: (Modelinfo, Data) -> Calculator
@@ -621,5 +639,5 @@
     from sas.models.dispersion_models import models as dispersers
 
-    def get_model_class(name):
+    def _get_model_class(name):
         # type: (str) -> "sas.models.BaseComponent"
         #print("new",sorted(_pars.items()))
@@ -641,5 +659,5 @@
         composition_type, parts = model_info.composition
         if composition_type == 'product':
-            P, S = [get_model_class(revert_name(p))() for p in parts]
+            P, S = [_get_model_class(revert_name(p))() for p in parts]
             model = [MultiplicationModel(P, S)]
         else:
@@ -649,6 +667,6 @@
         if old_name is None:
             raise ValueError("model %r does not exist in old sasview"
-                            % model_info.id)
-        ModelClass = get_model_class(old_name)
+                             % model_info.id)
+        ModelClass = _get_model_class(old_name)
         model = [ModelClass()]
     model[0].disperser_handles = {}
@@ -847,5 +865,5 @@
             # print a separate seed for each dataset for better reproducibility
             new_seed = np.random.randint(1000000)
-            print("Set %d uses -random=%i"%(k+1,new_seed))
+            print("Set %d uses -random=%i"%(k+1, new_seed))
             np.random.seed(new_seed)
         opts['pars'] = parse_pars(opts, maxdim=maxdim)
@@ -868,4 +886,7 @@
 def run_models(opts, verbose=False):
     # type: (Dict[str, Any]) -> Dict[str, Any]
+    """
+    Process a parameter set, return calculation results and times.
+    """
 
     base, comp = opts['engines']
@@ -941,4 +962,7 @@
 def plot_models(opts, result, limits=None, setnum=0):
     # type: (Dict[str, Any], Dict[str, Any], Optional[Tuple[float, float]]) -> Tuple[float, float]
+    """
+    Plot the results from :func:`run_model`.
+    """
     import matplotlib.pyplot as plt
 
@@ -987,6 +1011,6 @@
                 errview = 'linear'
         if 0:  # 95% cutoff
-            sorted = np.sort(err.flatten())
-            cutoff = sorted[int(sorted.size*0.95)]
+            sorted_err = np.sort(err.flatten())
+            cutoff = sorted_err[int(sorted_err.size*0.95)]
             err[err > cutoff] = cutoff
         #err,errstr = base/comp,"ratio"
@@ -1106,8 +1130,10 @@
 
 INTEGER_RE = re.compile("^[+-]?[1-9][0-9]*$")
-def isnumber(str):
-    match = FLOAT_RE.match(str)
-    isfloat = (match and not str[match.end():])
-    return isfloat or INTEGER_RE.match(str)
+def isnumber(s):
+    # type: (str) -> bool
+    """Return True if string contains an int or float"""
+    match = FLOAT_RE.match(s)
+    isfloat = (match and not s[match.end():])
+    return isfloat or INTEGER_RE.match(s)
 
 # For distinguishing pairs of models for comparison
@@ -1314,4 +1340,5 @@
 
 def set_spherical_integration_parameters(opts, steps):
+    # type: (Dict[str, Any], int) -> None
     """
     Set integration parameters for spherical integration over the entire
@@ -1337,7 +1364,17 @@
             'psi_pd_type=rectangle',
         ])
-        pass
 
 def parse_pars(opts, maxdim=np.inf):
+    # type: (Dict[str, Any], float) -> Tuple[Dict[str, float], Dict[str, float]]
+    """
+    Generate a parameter set.
+
+    The default values come from the model, or a randomized model if a seed
+    value is given.  Next, evaluate any parameter expressions, constraining
+    the value of the parameter within and between models.  If *maxdim* is
+    given, limit parameters with units of Angstrom to this value.
+
+    Returns a pair of parameter dictionaries for base and comparison models.
+    """
     model_info, model_info2 = opts['info']
 
@@ -1378,5 +1415,5 @@
             print("%r invalid; parameters are: %s"%(k, ", ".join(sorted(s))))
             return None
-        v1, v2 = v.split(PAR_SPLIT, 2) if PAR_SPLIT in v else (v,v)
+        v1, v2 = v.split(PAR_SPLIT, 2) if PAR_SPLIT in v else (v, v)
         if v1 and k in pars:
             presets[k] = float(v1) if isnumber(v1) else v1
@@ -1434,5 +1471,5 @@
     html = make_html(info)
     path = os.path.dirname(info.filename)
-    url = "file://"+path.replace("\\","/")[2:]+"/"
+    url = "file://" + path.replace("\\", "/")[2:] + "/"
     rst2html.view_html_qtapp(html, url)
 
@@ -1458,8 +1495,8 @@
     frame.panel.Layout()
     frame.panel.aui.Split(0, wx.TOP)
-    def reset_parameters(event):
+    def _reset_parameters(event):
         model.revert_values()
         signal.update_parameters(problem)
-    frame.Bind(wx.EVT_TOOL, reset_parameters, frame.ToolBar.GetToolByPos(1))
+    frame.Bind(wx.EVT_TOOL, _reset_parameters, frame.ToolBar.GetToolByPos(1))
     if is_mac: frame.Show()
     # If running withing an app, start the main loop
@@ -1504,8 +1541,16 @@
 
     def revert_values(self):
+        # type: () -> None
+        """
+        Restore starting values of the parameters.
+        """
         for k, v in self.starting_values.items():
             self.pars[k].value = v
 
     def model_update(self):
+        # type: () -> None
+        """
+        Respond to signal that model parameters have been changed.
+        """
         pass
 
Index: sasmodels/details.py
===================================================================
--- sasmodels/details.py	(revision ce9975453d8f4b67a4ae4030b5472518132a7526)
+++ sasmodels/details.py	(revision 110f69cfa1143196495c76df1d5cff08c6ce884e)
@@ -23,4 +23,5 @@
     # CRUFT: np.meshgrid requires multiple vectors
     def meshgrid(*args):
+        """See docs from a recent version of numpy"""
         if len(args) > 1:
             return np.meshgrid(*args)
@@ -231,7 +232,7 @@
     npars = kernel.info.parameters.npars
     nvalues = kernel.info.parameters.nvalues
-    scalars = [value for value, dispersity, weight in mesh]
+    scalars = [value for value, _dispersity, _weight in mesh]
     # skipping scale and background when building values and weights
-    values, dispersity, weights = zip(*mesh[2:npars+2]) if npars else ((), (), ())
+    _values, dispersity, weights = zip(*mesh[2:npars+2]) if npars else ((), (), ())
     #weights = correct_theta_weights(kernel.info.parameters, dispersity, weights)
     length = np.array([len(w) for w in weights])
@@ -287,5 +288,5 @@
     mag = values[parameters.nvalues-3*parameters.nmagnetic:parameters.nvalues]
     mag = mag.reshape(-1, 3)
-    scale = mag[:,0]
+    scale = mag[:, 0]
     if np.any(scale):
         theta, phi = radians(mag[:, 1]), radians(mag[:, 2])
Index: sasmodels/models/core_shell_bicelle_elliptical_belt_rough.py
===================================================================
--- sasmodels/models/core_shell_bicelle_elliptical_belt_rough.py	(revision 129bdc402ee898067c26d6c28ad0e6d66518e12c)
+++ sasmodels/models/core_shell_bicelle_elliptical_belt_rough.py	(revision 110f69cfa1143196495c76df1d5cff08c6ce884e)
@@ -6,8 +6,8 @@
 core-shell scattering length density profile. Thus this is a variation
 of the core-shell bicelle model, but with an elliptical cylinder for the core.
-In this version the "rim" or "belt" does NOT extend the full length of the particle,
-but has the same length as the core.
-Outer shells on the rims and flat ends may be of different thicknesses and 
-scattering length densities. The form factor is normalized by the total particle volume.
+In this version the "rim" or "belt" does NOT extend the full length of
+the particle, but has the same length as the core. Outer shells on the
+rims and flat ends may be of different thicknesses and scattering length
+densities. The form factor is normalized by the total particle volume.
 This version includes an approximate "interfacial roughness".
 
@@ -15,11 +15,11 @@
 .. figure:: img/core_shell_bicelle_belt_geometry.png
 
-    Schematic cross-section of bicelle with belt. Note however that the model here
-    calculates for rectangular, not curved, rims as shown below.
+    Schematic cross-section of bicelle with belt. Note however that the model
+    here calculates for rectangular, not curved, rims as shown below.
 
 .. figure:: img/core_shell_bicelle_belt_parameters.png
 
-   Cross section of model used here. Users will have 
-   to decide how to distribute "heads" and "tails" between the rim, face 
+   Cross section of model used here. Users will have
+   to decide how to distribute "heads" and "tails" between the rim, face
    and core regions in order to estimate appropriate starting parameters.
 
@@ -30,32 +30,38 @@
 .. math::
 
-    \rho(r) = 
-      \begin{cases} 
+    \rho(r) =
+      \begin{cases}
       &\rho_c \text{ for } 0 \lt r \lt R;   -L/2 \lt z\lt L/2 \\[1.5ex]
-      &\rho_f \text{ for } 0 \lt r \lt R;   -(L/2 +t_{face}) \lt z\lt -L/2;  
-      L/2 \lt z\lt (L/2+t_{face}) \\[1.5ex]
-      &\rho_r\text{ for } R \lt r \lt R+t_{rim}; -L/2 \lt z\lt L/2
+      &\rho_f \text{ for } 0 \lt r \lt R;   -(L/2 +t_\text{face}) \lt z\lt -L/2;
+      L/2 \lt z\lt (L/2+t_\text{face}) \\[1.5ex]
+      &\rho_r\text{ for } R \lt r \lt R+t_\text{rim}; -L/2 \lt z\lt L/2
       \end{cases}
 
 The form factor for the bicelle is calculated in cylindrical coordinates, where
-$\alpha$ is the angle between the $Q$ vector and the cylinder axis, and $\psi$ is the angle
-for the ellipsoidal cross section core, to give:
+$\alpha$ is the angle between the $Q$ vector and the cylinder axis, and $\psi$
+is the angle for the ellipsoidal cross section core, to give:
 
 .. math::
 
-    I(Q,\alpha,\psi) = \frac{\text{scale}}{V_t} \cdot
-        F(Q,\alpha, \psi)^2.sin(\alpha).exp\left \{ -\frac{1}{2}Q^2\sigma^2 \right \} + \text{background}
+    I(Q,\alpha,\psi) = \frac{\text{scale}}{V_t}
+        \cdot F(Q,\alpha, \psi)^2 \cdot \sin(\alpha)
+        \cdot\exp\left\{ -\frac{1}{2}Q^2\sigma^2 \right\} + \text{background}
 
-where a numerical integration of $F(Q,\alpha, \psi)^2.sin(\alpha)$ is carried out over \alpha and \psi for:
+where a numerical integration of $F(Q,\alpha, \psi)^2\sin(\alpha)$ is
+carried out over $\alpha$ and $\psi$ for:
 
 .. math::
 
-        \begin{align}    
-    F(Q,\alpha,\psi) = &\bigg[ 
-    (\rho_c -\rho_r - \rho_f + \rho_s) V_c \frac{2J_1(QR'sin \alpha)}{QR'sin\alpha}\frac{sin(QLcos\alpha/2)}{Q(L/2)cos\alpha} \\
-    &+(\rho_f - \rho_s) V_{c+f} \frac{2J_1(QR'sin\alpha)}{QR'sin\alpha}\frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} \\
-    &+(\rho_r - \rho_s) V_{c+r} \frac{2J_1(Q(R'+t_r)sin\alpha)}{Q(R'+t_r)sin\alpha}\frac{sin(Q(L/2)cos\alpha)}{Q(L/2)cos\alpha}
+    F(Q,\alpha,\psi) = &\bigg[
+      (\rho_c -\rho_r - \rho_f + \rho_s) V_c
+      \frac{2J_1(QR'\sin \alpha)}{QR'\sin\alpha}
+      \frac{\sin(QL\cos\alpha/2)}{Q(L/2)\cos\alpha} \\
+    &+(\rho_f - \rho_s) V_{c+f}
+      \frac{2J_1(QR'\sin\alpha)}{QR'\sin\alpha}
+      \frac{\sin(Q(L/2+t_f)\cos\alpha)}{Q(L/2+t_f)\cos\alpha} \\
+    &+(\rho_r - \rho_s) V_{c+r}
+      \frac{2J_1(Q(R'+t_r)\sin\alpha)}{Q(R'+t_r)\sin\alpha}
+      \frac{\sin(Q(L/2)\cos\alpha)}{Q(L/2)\cos\alpha}
     \bigg]
-    \end{align} 
 
 where
@@ -63,34 +69,40 @@
 .. math::
 
-    R'=\frac{R}{\sqrt{2}}\sqrt{(1+X_{core}^{2}) + (1-X_{core}^{2})cos(\psi)}
-    
-    
-and $V_t = \pi.(R+t_r)(Xcore.R+t_r).L + 2.\pi.Xcore.R^2.t_f$ is the total volume of the bicelle, 
-$V_c = \pi.Xcore.R^2.L$ the volume of the core, $V_{c+f} = \pi.Xcore.R^2.(L+2.t_f)$ 
-the volume of the core plus the volume of the faces, $V_{c+r} = \pi.(R+t_r)(Xcore.R+t_r),.L$ 
-the volume of the core plus the rim, $R$ is the radius
-of the core, $Xcore$ is the axial ratio of the core, $L$ the length of the core, 
-$t_f$ the thickness of the face, $t_r$ the thickness of the rim and $J_1$ the usual 
-first order bessel function. The core has radii $R$ and $Xcore.R$ so is circular, 
-as for the core_shell_bicelle model, for $Xcore$ =1. Note that you may need to 
-limit the range of $Xcore$, especially if using the Monte-Carlo algorithm, as 
-setting radius to $R/Xcore$ and axial ratio to $1/Xcore$ gives an equivalent solution!
+    R' = \frac{R}{\sqrt{2}}
+        \sqrt{(1+X_\text{core}^{2}) + (1-X_\text{core}^{2})\cos(\psi)}
 
-An approximation for the effects of "Gaussian interfacial roughness" $\sigma$ is included, 
-by multiplying $I(Q)$ by $exp\left \{ -\frac{1}{2}Q^2\sigma^2 \right \}$ . This 
-applies, in some way, to all interfaces in the model not just the external ones.
-(Note that for a one dimensional system convolution of the scattering length density profile
-with a Gaussian of standard deviation $\sigma$ does exactly this multiplication.) Leave 
-$\sigma$ set to zero for the usual sharp interfaces.
+
+and $V_t = \pi (R+t_r)(X_\text{core} R+t_r) L + 2 \pi X_\text{core} R^2 t_f$ is
+the total volume of the bicelle, $V_c = \pi X_\text{core} R^2 L$ the volume of
+the core, $V_{c+f} = \pi X_\text{core} R^2 (L+2 t_f)$ the volume of the core
+plus the volume of the faces, $V_{c+r} = \pi (R+t_r)(X_\text{core} R+t_r) L$
+the volume of the core plus the rim, $R$ is the radius of the core,
+$X_\text{core}$ is the axial ratio of the core, $L$ the length of the core,
+$t_f$ the thickness of the face, $t_r$ the thickness of the rim and $J_1$ the
+usual first order bessel function. The core has radii $R$ and $X_\text{core} R$
+so is circular, as for the core_shell_bicelle model, for $X_\text{core}=1$.
+Note that you may need to limit the range of $X_\text{core}$, especially if
+using the Monte-Carlo algorithm, as setting radius to $R/X_\text{core}$ and
+axial ratio to $1/X_\text{core}$ gives an equivalent solution!
+
+An approximation for the effects of "Gaussian interfacial roughness" $\sigma$
+is included, by multiplying $I(Q)$ by
+$\exp\left \{ -\frac{1}{2}Q^2\sigma^2 \right \}$. This applies, in some way, to
+all interfaces in the model not just the external ones. (Note that for a one
+dimensional system convolution of the scattering length density profile with
+a Gaussian of standard deviation $\sigma$ does exactly this multiplication.)
+Leave $\sigma$ set to zero for the usual sharp interfaces.
 
 The output of the 1D scattering intensity function for randomly oriented
 bicelles is then given by integrating over all possible $\alpha$ and $\psi$.
 
-For oriented bicelles the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 
-for further details of the calculation and angular dispersions  see :ref:`orientation` .
+For oriented bicelles the *theta*, *phi* and *psi* orientation parameters
+will appear when fitting 2D data, for further details of the calculation
+and angular dispersions  see :ref:`orientation` .
 
 .. figure:: img/elliptical_cylinder_angle_definition.png
 
-    Definition of the angles for the oriented core_shell_bicelle_elliptical particles.   
+    Definition of the angles for the oriented core_shell_bicelle_elliptical
+    particles.
 
 
@@ -115,5 +127,5 @@
 description = """
     core_shell_bicelle_elliptical_belt_rough
-    Elliptical cylinder core, optional shell on the two flat faces, and "belt" shell of 
+    Elliptical cylinder core, optional shell on the two flat faces, and "belt" shell of
     uniform thickness on its rim (in this case NOT extending around the end faces).
     with approximate interfacial roughness.
@@ -173,8 +185,8 @@
 
     [{'radius': 30.0, 'x_core': 3.0, 'thick_rim':8.0, 'thick_face':14.0, 'length':50.0,
-    'sld_core':4.0, 'sld_face':7.0, 'sld_rim':1.0, 'sld_solvent':6.0, 'background':0.0},
-    0.015, 189.328],
-#    [{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ],
-        ]
+      'sld_core':4.0, 'sld_face':7.0, 'sld_rim':1.0, 'sld_solvent':6.0, 'background':0.0},
+     0.015, 189.328],
+    #[{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ],
+]
 
 del qx, qy  # not necessary to delete, but cleaner
Index: sasmodels/models/ellipsoid.py
===================================================================
--- sasmodels/models/ellipsoid.py	(revision eda8b306f3ccd288f34d3e66c7fcf5754162bb2c)
+++ sasmodels/models/ellipsoid.py	(revision 110f69cfa1143196495c76df1d5cff08c6ce884e)
@@ -53,10 +53,10 @@
     r = R_e \left[ 1 + u^2\left(R_p^2/R_e^2 - 1\right)\right]^{1/2}
 
-For 2d data from oriented ellipsoids the direction of the rotation axis of 
-the ellipsoid is defined using two angles $\theta$ and $\phi$ as for the 
+For 2d data from oriented ellipsoids the direction of the rotation axis of
+the ellipsoid is defined using two angles $\theta$ and $\phi$ as for the
 :ref:`cylinder orientation figure <cylinder-angle-definition>`.
 For the ellipsoid, $\theta$ is the angle between the rotational axis
 and the $z$ -axis in the $xz$ plane followed by a rotation by $\phi$
-in the $xy$ plane, for further details of the calculation and angular 
+in the $xy$ plane, for further details of the calculation and angular
 dispersions see :ref:`orientation` .
 
@@ -209,5 +209,5 @@
 qy = q*sin(pi/6.0)
 tests = [[{}, 0.05, 54.8525847025],
-        [{'theta':80., 'phi':10.}, (qx, qy), 1.74134670026 ],
+        [{'theta':80., 'phi':10.}, (qx, qy), 1.74134670026],
         ]
 del qx, qy  # not necessary to delete, but cleaner
Index: sasmodels/models/stacked_disks.py
===================================================================
--- sasmodels/models/stacked_disks.py	(revision eda8b306f3ccd288f34d3e66c7fcf5754162bb2c)
+++ sasmodels/models/stacked_disks.py	(revision 110f69cfa1143196495c76df1d5cff08c6ce884e)
@@ -74,14 +74,17 @@
     the layers.
 
-2d scattering from oriented stacks is calculated in the same way as for cylinders,
-for further details of the calculation and angular dispersions see :ref:`orientation` . 
+2d scattering from oriented stacks is calculated in the same way as for
+cylinders, for further details of the calculation and angular dispersions
+see :ref:`orientation`.
 
 .. figure:: img/cylinder_angle_definition.png
 
     Angles $\theta$ and $\phi$ orient the stack of discs relative
-    to the beam line coordinates, where the beam is along the $z$ axis. Rotation $\theta$, initially 
-    in the $xz$ plane, is carried out first, then rotation $\phi$ about the $z$ axis. Orientation distributions
-    are described as rotations about two perpendicular axes $\delta_1$ and $\delta_2$
-    in the frame of the cylinder itself, which when $\theta = \phi = 0$ are parallel to the $Y$ and $X$ axes.
+    to the beam line coordinates, where the beam is along the $z$ axis.
+    Rotation $\theta$, initially in the $xz$ plane, is carried out first,
+    then rotation $\phi$ about the $z$ axis. Orientation distributions are
+    described as rotations about two perpendicular axes $\delta_1$ and
+    $\delta_2$ in the frame of the cylinder itself, which when
+    $\theta = \phi = 0$ are parallel to the $Y$ and $X$ axes.
 
 
Index: sasmodels/special.py
===================================================================
--- sasmodels/special.py	(revision 706f46620c115bdbc319d902ba7678c9d247d6d0)
+++ sasmodels/special.py	(revision 110f69cfa1143196495c76df1d5cff08c6ce884e)
@@ -105,5 +105,5 @@
 
     p1evl(x, c, n):
-        Evaluation of normalized polynomial $p(x) = x^n + \sum_{i=0}^{n-1} c_i x^i$
+        Evaluate normalized polynomial $p(x) = x^n + \sum_{i=0}^{n-1} c_i x^i$
         using Horner's method so it is faster and more accurate.
 
@@ -155,7 +155,9 @@
         .. math::
 
-             \text{Si}(x) \sim \frac{\pi}{2}
-             - \frac{\cos(x)}{x}\left(1 - \frac{2!}{x^2} + \frac{4!}{x^4} - \frac{6!}{x^6} \right)
-             - \frac{\sin(x)}{x}\left(\frac{1}{x} - \frac{3!}{x^3} + \frac{5!}{x^5} - \frac{7!}{x^7}\right)
+            \text{Si}(x) \sim \frac{\pi}{2}
+             - \frac{\cos(x)}{x}
+            \left(1 - \frac{2!}{x^2} + \frac{4!}{x^4} - \frac{6!}{x^6} \right)
+             - \frac{\sin(x)}{x}
+            \left(\frac{1}{x} - \frac{3!}{x^3} + \frac{5!}{x^5} - \frac{7!}{x^7}\right)
 
         For small arguments,
@@ -207,33 +209,5 @@
 # erf, erfc, tgamma, lgamma  **do not use**
 
-# Rotations of q
-def ORIENT_SYMMETRIC(qx, qy, theta, phi):
-    q = sqrt(qx*qx + qy*qy)
-    q = sqrt(qx*qx + qy*qy)
-    sin_phi, cos_phi = sin(radians(phi)), cos(radians(phi))
-    cn = (cn*qx + sn*qy)/q * sin(radians(theta))
-    cn[q==0.] = 1.
-    sn = sqrt(1 - cn**2)
-    return q, cn, sn
-
-def ORIENT_ASYMMETRIC(qx, qy, theta, phi, psi):
-    q = sqrt(qx*qx + qy*qy)
-    qxhat = qx/q
-    qyhat = qy/q
-    sin_theta, cos_theta = sin(radians(theta)), cos(radians(theta))
-    sin_phi, cos_phi = sin(radians(phi)), cos(radians(phi))
-    sin_psi, cos_psi = sin(radians(psi)), cos(radians(psi))
-
-    xhat = (qxhat*(-sin_phi*sin_psi + cos_theta*cos_phi*cos_psi)
-          + qyhat*( cos_phi*sin_psi + cos_theta*sin_phi*cos_psi))
-    yhat = (qxhat*(-sin_phi*cos_psi - cos_theta*cos_phi*sin_psi)
-          + qyhat*( cos_phi*cos_psi - cos_theta*sin_phi*sin_psi))
-    zhat = (qxhat*(-sin_theta*cos_phi)
-          + qyhat*(-sin_theta*sin_phi))
-    return q, xhat, yhat, zhat
-
-
 # non-standard constants and functions
-
 M_PI_180, M_4PI_3 = M_PI/180, 4*M_PI/3
 
@@ -262,5 +236,4 @@
 from scipy.special import jn as sas_JN
 
-# missing sas_Si
 def sas_Si(x):
     return scipy.special.sici(x)[0]
@@ -289,5 +262,5 @@
         with np.errstate(all='ignore'):
             retvalue = 2*sas_J1(x)/x
-        retvalue[x==0] = 1.
+        retvalue[x == 0] = 1.
     return retvalue
 
@@ -500,306 +473,306 @@
 
 Gauss150Z = np.array([
-      -0.9998723404457334,
-      -0.9993274305065947,
-      -0.9983473449340834,
-      -0.9969322929775997,
-      -0.9950828645255290,
-      -0.9927998590434373,
-      -0.9900842691660192,
-      -0.9869372772712794,
-      -0.9833602541697529,
-      -0.9793547582425894,
-      -0.9749225346595943,
-      -0.9700655145738374,
-      -0.9647858142586956,
-      -0.9590857341746905,
-      -0.9529677579610971,
-      -0.9464345513503147,
-      -0.9394889610042837,
-      -0.9321340132728527,
-      -0.9243729128743136,
-      -0.9162090414984952,
-      -0.9076459563329236,
-      -0.8986873885126239,
-      -0.8893372414942055,
-      -0.8795995893549102,
-      -0.8694786750173527,
-      -0.8589789084007133,
-      -0.8481048644991847,
-      -0.8368612813885015,
-      -0.8252530581614230,
-      -0.8132852527930605,
-      -0.8009630799369827,
-      -0.7882919086530552,
-      -0.7752772600680049,
-      -0.7619248049697269,
-      -0.7482403613363824,
-      -0.7342298918013638,
-      -0.7198995010552305,
-      -0.7052554331857488,
-      -0.6903040689571928,
-      -0.6750519230300931,
-      -0.6595056411226444,
-      -0.6436719971150083,
-      -0.6275578900977726,
-      -0.6111703413658551,
-      -0.5945164913591590,
-      -0.5776035965513142,
-      -0.5604390262878617,
-      -0.5430302595752546,
-      -0.5253848818220803,
-      -0.5075105815339176,
-      -0.4894151469632753,
-      -0.4711064627160663,
-      -0.4525925063160997,
-      -0.4338813447290861,
-      -0.4149811308476706,
-      -0.3959000999390257,
-      -0.3766465660565522,
-      -0.3572289184172501,
-      -0.3376556177463400,
-      -0.3179351925907259,
-      -0.2980762356029071,
-      -0.2780873997969574,
-      -0.2579773947782034,
-      -0.2377549829482451,
-      -0.2174289756869712,
-      -0.1970082295132342,
-      -0.1765016422258567,
-      -0.1559181490266516,
-      -0.1352667186271445,
-      -0.1145563493406956,
-      -0.0937960651617229,
-      -0.0729949118337358,
-      -0.0521619529078925,
-      -0.0313062657937972,
-      -0.0104369378042598,
-      0.0104369378042598,
-      0.0313062657937972,
-      0.0521619529078925,
-      0.0729949118337358,
-      0.0937960651617229,
-      0.1145563493406956,
-      0.1352667186271445,
-      0.1559181490266516,
-      0.1765016422258567,
-      0.1970082295132342,
-      0.2174289756869712,
-      0.2377549829482451,
-      0.2579773947782034,
-      0.2780873997969574,
-      0.2980762356029071,
-      0.3179351925907259,
-      0.3376556177463400,
-      0.3572289184172501,
-      0.3766465660565522,
-      0.3959000999390257,
-      0.4149811308476706,
-      0.4338813447290861,
-      0.4525925063160997,
-      0.4711064627160663,
-      0.4894151469632753,
-      0.5075105815339176,
-      0.5253848818220803,
-      0.5430302595752546,
-      0.5604390262878617,
-      0.5776035965513142,
-      0.5945164913591590,
-      0.6111703413658551,
-      0.6275578900977726,
-      0.6436719971150083,
-      0.6595056411226444,
-      0.6750519230300931,
-      0.6903040689571928,
-      0.7052554331857488,
-      0.7198995010552305,
-      0.7342298918013638,
-      0.7482403613363824,
-      0.7619248049697269,
-      0.7752772600680049,
-      0.7882919086530552,
-      0.8009630799369827,
-      0.8132852527930605,
-      0.8252530581614230,
-      0.8368612813885015,
-      0.8481048644991847,
-      0.8589789084007133,
-      0.8694786750173527,
-      0.8795995893549102,
-      0.8893372414942055,
-      0.8986873885126239,
-      0.9076459563329236,
-      0.9162090414984952,
-      0.9243729128743136,
-      0.9321340132728527,
-      0.9394889610042837,
-      0.9464345513503147,
-      0.9529677579610971,
-      0.9590857341746905,
-      0.9647858142586956,
-      0.9700655145738374,
-      0.9749225346595943,
-      0.9793547582425894,
-      0.9833602541697529,
-      0.9869372772712794,
-      0.9900842691660192,
-      0.9927998590434373,
-      0.9950828645255290,
-      0.9969322929775997,
-      0.9983473449340834,
-      0.9993274305065947,
-      0.9998723404457334
+    -0.9998723404457334,
+    -0.9993274305065947,
+    -0.9983473449340834,
+    -0.9969322929775997,
+    -0.9950828645255290,
+    -0.9927998590434373,
+    -0.9900842691660192,
+    -0.9869372772712794,
+    -0.9833602541697529,
+    -0.9793547582425894,
+    -0.9749225346595943,
+    -0.9700655145738374,
+    -0.9647858142586956,
+    -0.9590857341746905,
+    -0.9529677579610971,
+    -0.9464345513503147,
+    -0.9394889610042837,
+    -0.9321340132728527,
+    -0.9243729128743136,
+    -0.9162090414984952,
+    -0.9076459563329236,
+    -0.8986873885126239,
+    -0.8893372414942055,
+    -0.8795995893549102,
+    -0.8694786750173527,
+    -0.8589789084007133,
+    -0.8481048644991847,
+    -0.8368612813885015,
+    -0.8252530581614230,
+    -0.8132852527930605,
+    -0.8009630799369827,
+    -0.7882919086530552,
+    -0.7752772600680049,
+    -0.7619248049697269,
+    -0.7482403613363824,
+    -0.7342298918013638,
+    -0.7198995010552305,
+    -0.7052554331857488,
+    -0.6903040689571928,
+    -0.6750519230300931,
+    -0.6595056411226444,
+    -0.6436719971150083,
+    -0.6275578900977726,
+    -0.6111703413658551,
+    -0.5945164913591590,
+    -0.5776035965513142,
+    -0.5604390262878617,
+    -0.5430302595752546,
+    -0.5253848818220803,
+    -0.5075105815339176,
+    -0.4894151469632753,
+    -0.4711064627160663,
+    -0.4525925063160997,
+    -0.4338813447290861,
+    -0.4149811308476706,
+    -0.3959000999390257,
+    -0.3766465660565522,
+    -0.3572289184172501,
+    -0.3376556177463400,
+    -0.3179351925907259,
+    -0.2980762356029071,
+    -0.2780873997969574,
+    -0.2579773947782034,
+    -0.2377549829482451,
+    -0.2174289756869712,
+    -0.1970082295132342,
+    -0.1765016422258567,
+    -0.1559181490266516,
+    -0.1352667186271445,
+    -0.1145563493406956,
+    -0.0937960651617229,
+    -0.0729949118337358,
+    -0.0521619529078925,
+    -0.0313062657937972,
+    -0.0104369378042598,
+    0.0104369378042598,
+    0.0313062657937972,
+    0.0521619529078925,
+    0.0729949118337358,
+    0.0937960651617229,
+    0.1145563493406956,
+    0.1352667186271445,
+    0.1559181490266516,
+    0.1765016422258567,
+    0.1970082295132342,
+    0.2174289756869712,
+    0.2377549829482451,
+    0.2579773947782034,
+    0.2780873997969574,
+    0.2980762356029071,
+    0.3179351925907259,
+    0.3376556177463400,
+    0.3572289184172501,
+    0.3766465660565522,
+    0.3959000999390257,
+    0.4149811308476706,
+    0.4338813447290861,
+    0.4525925063160997,
+    0.4711064627160663,
+    0.4894151469632753,
+    0.5075105815339176,
+    0.5253848818220803,
+    0.5430302595752546,
+    0.5604390262878617,
+    0.5776035965513142,
+    0.5945164913591590,
+    0.6111703413658551,
+    0.6275578900977726,
+    0.6436719971150083,
+    0.6595056411226444,
+    0.6750519230300931,
+    0.6903040689571928,
+    0.7052554331857488,
+    0.7198995010552305,
+    0.7342298918013638,
+    0.7482403613363824,
+    0.7619248049697269,
+    0.7752772600680049,
+    0.7882919086530552,
+    0.8009630799369827,
+    0.8132852527930605,
+    0.8252530581614230,
+    0.8368612813885015,
+    0.8481048644991847,
+    0.8589789084007133,
+    0.8694786750173527,
+    0.8795995893549102,
+    0.8893372414942055,
+    0.8986873885126239,
+    0.9076459563329236,
+    0.9162090414984952,
+    0.9243729128743136,
+    0.9321340132728527,
+    0.9394889610042837,
+    0.9464345513503147,
+    0.9529677579610971,
+    0.9590857341746905,
+    0.9647858142586956,
+    0.9700655145738374,
+    0.9749225346595943,
+    0.9793547582425894,
+    0.9833602541697529,
+    0.9869372772712794,
+    0.9900842691660192,
+    0.9927998590434373,
+    0.9950828645255290,
+    0.9969322929775997,
+    0.9983473449340834,
+    0.9993274305065947,
+    0.9998723404457334
 ])
 
 Gauss150Wt = np.array([
-      0.0003276086705538,
-      0.0007624720924706,
-      0.0011976474864367,
-      0.0016323569986067,
-      0.0020663664924131,
-      0.0024994789888943,
-      0.0029315036836558,
-      0.0033622516236779,
-      0.0037915348363451,
-      0.0042191661429919,
-      0.0046449591497966,
-      0.0050687282939456,
-      0.0054902889094487,
-      0.0059094573005900,
-      0.0063260508184704,
-      0.0067398879387430,
-      0.0071507883396855,
-      0.0075585729801782,
-      0.0079630641773633,
-      0.0083640856838475,
-      0.0087614627643580,
-      0.0091550222717888,
-      0.0095445927225849,
-      0.0099300043714212,
-      0.0103110892851360,
-      0.0106876814158841,
-      0.0110596166734735,
-      0.0114267329968529,
-      0.0117888704247183,
-      0.0121458711652067,
-      0.0124975796646449,
-      0.0128438426753249,
-      0.0131845093222756,
-      0.0135194311690004,
-      0.0138484622795371,
-      0.0141714592928592,
-      0.0144882814685445,
-      0.0147987907597169,
-      0.0151028518701744,
-      0.0154003323133401,
-      0.0156911024699895,
-      0.0159750356447283,
-      0.0162520081211971,
-      0.0165218992159766,
-      0.0167845913311726,
-      0.0170399700056559,
-      0.0172879239649355,
-      0.0175283451696437,
-      0.0177611288626114,
-      0.0179861736145128,
-      0.0182033813680609,
-      0.0184126574807331,
-      0.0186139107660094,
-      0.0188070535331042,
-      0.0189920016251754,
-      0.0191686744559934,
-      0.0193369950450545,
-      0.0194968900511231,
-      0.0196482898041878,
-      0.0197911283358190,
-      0.0199253434079123,
-      0.0200508765398072,
-      0.0201676730337687,
-      0.0202756819988200,
-      0.0203748563729175,
-      0.0204651529434560,
-      0.0205465323660984,
-      0.0206189591819181,
-      0.0206824018328499,
-      0.0207368326754401,
-      0.0207822279928917,
-      0.0208185680053983,
-      0.0208458368787627,
-      0.0208640227312962,
-      0.0208731176389954,
-      0.0208731176389954,
-      0.0208640227312962,
-      0.0208458368787627,
-      0.0208185680053983,
-      0.0207822279928917,
-      0.0207368326754401,
-      0.0206824018328499,
-      0.0206189591819181,
-      0.0205465323660984,
-      0.0204651529434560,
-      0.0203748563729175,
-      0.0202756819988200,
-      0.0201676730337687,
-      0.0200508765398072,
-      0.0199253434079123,
-      0.0197911283358190,
-      0.0196482898041878,
-      0.0194968900511231,
-      0.0193369950450545,
-      0.0191686744559934,
-      0.0189920016251754,
-      0.0188070535331042,
-      0.0186139107660094,
-      0.0184126574807331,
-      0.0182033813680609,
-      0.0179861736145128,
-      0.0177611288626114,
-      0.0175283451696437,
-      0.0172879239649355,
-      0.0170399700056559,
-      0.0167845913311726,
-      0.0165218992159766,
-      0.0162520081211971,
-      0.0159750356447283,
-      0.0156911024699895,
-      0.0154003323133401,
-      0.0151028518701744,
-      0.0147987907597169,
-      0.0144882814685445,
-      0.0141714592928592,
-      0.0138484622795371,
-      0.0135194311690004,
-      0.0131845093222756,
-      0.0128438426753249,
-      0.0124975796646449,
-      0.0121458711652067,
-      0.0117888704247183,
-      0.0114267329968529,
-      0.0110596166734735,
-      0.0106876814158841,
-      0.0103110892851360,
-      0.0099300043714212,
-      0.0095445927225849,
-      0.0091550222717888,
-      0.0087614627643580,
-      0.0083640856838475,
-      0.0079630641773633,
-      0.0075585729801782,
-      0.0071507883396855,
-      0.0067398879387430,
-      0.0063260508184704,
-      0.0059094573005900,
-      0.0054902889094487,
-      0.0050687282939456,
-      0.0046449591497966,
-      0.0042191661429919,
-      0.0037915348363451,
-      0.0033622516236779,
-      0.0029315036836558,
-      0.0024994789888943,
-      0.0020663664924131,
-      0.0016323569986067,
-      0.0011976474864367,
-      0.0007624720924706,
-      0.0003276086705538
+    0.0003276086705538,
+    0.0007624720924706,
+    0.0011976474864367,
+    0.0016323569986067,
+    0.0020663664924131,
+    0.0024994789888943,
+    0.0029315036836558,
+    0.0033622516236779,
+    0.0037915348363451,
+    0.0042191661429919,
+    0.0046449591497966,
+    0.0050687282939456,
+    0.0054902889094487,
+    0.0059094573005900,
+    0.0063260508184704,
+    0.0067398879387430,
+    0.0071507883396855,
+    0.0075585729801782,
+    0.0079630641773633,
+    0.0083640856838475,
+    0.0087614627643580,
+    0.0091550222717888,
+    0.0095445927225849,
+    0.0099300043714212,
+    0.0103110892851360,
+    0.0106876814158841,
+    0.0110596166734735,
+    0.0114267329968529,
+    0.0117888704247183,
+    0.0121458711652067,
+    0.0124975796646449,
+    0.0128438426753249,
+    0.0131845093222756,
+    0.0135194311690004,
+    0.0138484622795371,
+    0.0141714592928592,
+    0.0144882814685445,
+    0.0147987907597169,
+    0.0151028518701744,
+    0.0154003323133401,
+    0.0156911024699895,
+    0.0159750356447283,
+    0.0162520081211971,
+    0.0165218992159766,
+    0.0167845913311726,
+    0.0170399700056559,
+    0.0172879239649355,
+    0.0175283451696437,
+    0.0177611288626114,
+    0.0179861736145128,
+    0.0182033813680609,
+    0.0184126574807331,
+    0.0186139107660094,
+    0.0188070535331042,
+    0.0189920016251754,
+    0.0191686744559934,
+    0.0193369950450545,
+    0.0194968900511231,
+    0.0196482898041878,
+    0.0197911283358190,
+    0.0199253434079123,
+    0.0200508765398072,
+    0.0201676730337687,
+    0.0202756819988200,
+    0.0203748563729175,
+    0.0204651529434560,
+    0.0205465323660984,
+    0.0206189591819181,
+    0.0206824018328499,
+    0.0207368326754401,
+    0.0207822279928917,
+    0.0208185680053983,
+    0.0208458368787627,
+    0.0208640227312962,
+    0.0208731176389954,
+    0.0208731176389954,
+    0.0208640227312962,
+    0.0208458368787627,
+    0.0208185680053983,
+    0.0207822279928917,
+    0.0207368326754401,
+    0.0206824018328499,
+    0.0206189591819181,
+    0.0205465323660984,
+    0.0204651529434560,
+    0.0203748563729175,
+    0.0202756819988200,
+    0.0201676730337687,
+    0.0200508765398072,
+    0.0199253434079123,
+    0.0197911283358190,
+    0.0196482898041878,
+    0.0194968900511231,
+    0.0193369950450545,
+    0.0191686744559934,
+    0.0189920016251754,
+    0.0188070535331042,
+    0.0186139107660094,
+    0.0184126574807331,
+    0.0182033813680609,
+    0.0179861736145128,
+    0.0177611288626114,
+    0.0175283451696437,
+    0.0172879239649355,
+    0.0170399700056559,
+    0.0167845913311726,
+    0.0165218992159766,
+    0.0162520081211971,
+    0.0159750356447283,
+    0.0156911024699895,
+    0.0154003323133401,
+    0.0151028518701744,
+    0.0147987907597169,
+    0.0144882814685445,
+    0.0141714592928592,
+    0.0138484622795371,
+    0.0135194311690004,
+    0.0131845093222756,
+    0.0128438426753249,
+    0.0124975796646449,
+    0.0121458711652067,
+    0.0117888704247183,
+    0.0114267329968529,
+    0.0110596166734735,
+    0.0106876814158841,
+    0.0103110892851360,
+    0.0099300043714212,
+    0.0095445927225849,
+    0.0091550222717888,
+    0.0087614627643580,
+    0.0083640856838475,
+    0.0079630641773633,
+    0.0075585729801782,
+    0.0071507883396855,
+    0.0067398879387430,
+    0.0063260508184704,
+    0.0059094573005900,
+    0.0054902889094487,
+    0.0050687282939456,
+    0.0046449591497966,
+    0.0042191661429919,
+    0.0037915348363451,
+    0.0033622516236779,
+    0.0029315036836558,
+    0.0024994789888943,
+    0.0020663664924131,
+    0.0016323569986067,
+    0.0011976474864367,
+    0.0007624720924706,
+    0.0003276086705538
 ])
