Changeset 16a8c63 in sasmodels


Ignore:
Timestamp:
Apr 7, 2017 8:59:30 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
3fd0499, 1f65db5
Parents:
e6ab0d3 (diff), 43ff77c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'ticket-852-unit-tests' into ticket-890

Location:
sasmodels/models
Files:
6 added
5 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/barbell.py

    rfcb33e4 r0b56f38  
    8787* **Last Reviewed by:** Richard Heenan **Date:** January 4, 2017 
    8888""" 
    89 from numpy import inf 
     89from numpy import inf, sin, cos, pi 
    9090 
    9191name = "barbell" 
     
    125125            phi_pd=15, phi_pd_n=0, 
    126126           ) 
     127q = 0.1 
     128# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
     129qx = q*cos(pi/6.0) 
     130qy = q*sin(pi/6.0) 
     131tests = [[{}, 0.075, 25.5691260532], 
     132        [{'theta':80., 'phi':10.}, (qx, qy), 3.04233067789], 
     133        ] 
     134del qx, qy  # not necessary to delete, but cleaner 
  • sasmodels/models/bcc_paracrystal.py

    r925ad6e re2d6e3b  
    9999""" 
    100100 
    101 from numpy import inf 
     101from numpy import inf, pi 
    102102 
    103103name = "bcc_paracrystal" 
     
    141141    psi_pd=15, psi_pd_n=0, 
    142142    ) 
     143# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
     144# add 2d test later 
     145q =4.*pi/220. 
     146tests = [ 
     147    [{ }, 
     148     [0.001, q, 0.215268], [1.46601394721, 2.85851284174, 0.00866710287078]], 
     149] 
  • sasmodels/models/capped_cylinder.py

    rfcb33e4 r0b56f38  
    9191 
    9292""" 
    93 from numpy import inf 
     93from numpy import inf, sin, cos, pi 
    9494 
    9595name = "capped_cylinder" 
     
    145145            theta_pd=15, theta_pd_n=45, 
    146146            phi_pd=15, phi_pd_n=1) 
     147q = 0.1 
     148# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
     149qx = q*cos(pi/6.0) 
     150qy = q*sin(pi/6.0) 
     151tests = [[{}, 0.075, 26.0698570695], 
     152        [{'theta':80., 'phi':10.}, (qx, qy), 0.561811990502], 
     153        ] 
     154del qx, qy  # not necessary to delete, but cleaner 
  • sasmodels/models/core_shell_bicelle.py

    r3b9a526 r0b56f38  
    8888""" 
    8989 
    90 from numpy import inf, sin, cos 
     90from numpy import inf, sin, cos, pi 
    9191 
    9292name = "core_shell_bicelle" 
     
    155155            theta=90, 
    156156            phi=0) 
     157q = 0.1 
     158# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
     159qx = q*cos(pi/6.0) 
     160qy = q*sin(pi/6.0) 
     161tests = [[{}, 0.05, 7.4883545957], 
     162        [{'theta':80., 'phi':10.}, (qx, qy), 2.81048892474 ], 
     163        ] 
     164del qx, qy  # not necessary to delete, but cleaner 
    157165 
    158 #qx, qy = 0.4 * cos(pi/2.0), 0.5 * sin(0) 
  • sasmodels/models/core_shell_bicelle_elliptical.py

    r15a90c1 r16a8c63  
    9999""" 
    100100 
    101 from numpy import inf, sin, cos 
     101from numpy import inf, sin, cos, pi 
    102102 
    103103name = "core_shell_bicelle_elliptical" 
     
    150150            psi=0) 
    151151 
    152 #qx, qy = 0.4 * cos(pi/2.0), 0.5 * sin(0) 
     152q = 0.1 
     153# april 6 2017, rkh added a 2d unit test, NOT READY YET pull #890 branch assume correct! 
     154qx = q*cos(pi/6.0) 
     155qy = q*sin(pi/6.0) 
    153156 
    154157tests = [ 
     
    159162    'sld_core':4.0, 'sld_face':7.0, 'sld_rim':1.0, 'sld_solvent':6.0, 'background':0.0}, 
    160163    0.015, 286.540286], 
    161 ] 
     164#    [{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ], 
     165        ] 
     166 
     167del qx, qy  # not necessary to delete, but cleaner 
  • sasmodels/models/core_shell_cylinder.py

    rfcb33e4 r0b56f38  
    7373""" 
    7474 
    75 from numpy import pi, inf 
     75from numpy import pi, inf, sin, cos 
    7676 
    7777name = "core_shell_cylinder" 
     
    151151            theta_pd=15, theta_pd_n=45, 
    152152            phi_pd=15, phi_pd_n=1) 
    153  
     153q = 0.1 
     154# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
     155qx = q*cos(pi/6.0) 
     156qy = q*sin(pi/6.0) 
     157tests = [[{}, 0.075, 10.8552692237], 
     158        [{}, (qx, qy), 0.444618752741 ], 
     159        ] 
     160del qx, qy  # not necessary to delete, but cleaner 
  • sasmodels/models/ellipsoid.py

    r4b0a294 r0b56f38  
    120120""" 
    121121 
    122 from numpy import inf 
     122from numpy import inf, sin, cos, pi 
    123123 
    124124name = "ellipsoid" 
     
    190190            theta_pd=15, theta_pd_n=45, 
    191191            phi_pd=15, phi_pd_n=1) 
     192q = 0.1 
     193# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
     194qx = q*cos(pi/6.0) 
     195qy = q*sin(pi/6.0) 
     196tests = [[{}, 0.05, 54.8525847025], 
     197        [{'theta':80., 'phi':10.}, (qx, qy), 1.74134670026 ], 
     198        ] 
     199del qx, qy  # not necessary to delete, but cleaner 
  • sasmodels/models/elliptical_cylinder.py

    r15a90c1 r16a8c63  
    109109""" 
    110110 
    111 from numpy import pi, inf, sqrt 
     111from numpy import pi, inf, sqrt, sin, cos 
    112112 
    113113name = "elliptical_cylinder" 
     
    150150                           + (length + radius) * (length + pi * radius)) 
    151151    return 0.5 * (ddd) ** (1. / 3.) 
     152q = 0.1 
     153# april 6 2017, rkh added a 2d unit test, NOT READY YET pull #890 branch assume correct! 
     154qx = q*cos(pi/6.0) 
     155qy = q*sin(pi/6.0) 
    152156 
    153157tests = [ 
     
    159163      'sld_solvent':1.0, 'background':0.0}, 
    160164     0.001, 675.504402], 
     165#    [{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ], 
    161166] 
  • sasmodels/models/fcc_paracrystal.py

    r925ad6e re2d6e3b  
    9090""" 
    9191 
    92 from numpy import inf 
     92from numpy import inf, pi 
    9393 
    9494name = "fcc_paracrystal" 
     
    128128            psi_pd=15, psi_pd_n=0, 
    129129           ) 
     130# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
     131# add 2d test later 
     132q =4.*pi/220. 
     133tests = [ 
     134    [{ }, 
     135     [0.001, q, 0.215268], [0.275164706668, 5.7776842567, 0.00958167119232]], 
     136] 
  • sasmodels/models/hollow_cylinder.py

    raea2e2a r0b56f38  
    6060""" 
    6161 
    62 from numpy import pi, inf 
     62from numpy import pi, inf, sin, cos 
    6363 
    6464name = "hollow_cylinder" 
     
    129129            theta_pd=10, theta_pd_n=5, 
    130130           ) 
    131  
     131q = 0.1 
     132# april 6 2017, rkh added a 2d unit test, assume correct! 
     133qx = q*cos(pi/6.0) 
     134qy = q*sin(pi/6.0) 
    132135# Parameters for unit tests 
    133136tests = [ 
    134137    [{}, 0.00005, 1764.926], 
    135138    [{}, 'VR', 1.8], 
    136     [{}, 0.001, 1756.76] 
    137     ] 
     139    [{}, 0.001, 1756.76], 
     140    [{}, (qx, qy), 2.36885476192  ], 
     141        ] 
     142del qx, qy  # not necessary to delete, but cleaner 
  • sasmodels/models/stacked_disks.py

    rc3ccaec r0b56f38  
    103103""" 
    104104 
    105 from numpy import inf 
     105from numpy import inf, sin, cos, pi 
    106106 
    107107name = "stacked_disks" 
     
    152152# After redefinition of spherical coordinates - 
    153153# tests had in old coords theta=0, phi=0; new coords theta=90, phi=0 
    154 # but should not matter here as so far all the tests are 1D not 2D 
     154q = 0.1 
     155# april 6 2017, rkh added a 2d unit test, assume correct! 
     156qx = q*cos(pi/6.0) 
     157qy = q*sin(pi/6.0) 
    155158tests = [ 
    156159# Accuracy tests based on content in test/utest_extra_models.py. 
     
    186189    [{'thick_core': 10.0, 
    187190      'thick_layer': 15.0, 
     191      'radius': 100.0, 
     192      'n_stacking': 5, 
     193      'sigma_d': 0.0, 
     194      'sld_core': 4.0, 
     195      'sld_layer': -0.4, 
     196      'solvent_sd': 5.0, 
     197      'theta': 90.0, 
     198      'phi': 20.0, 
     199      'scale': 0.01, 
     200      'background': 0.001}, 
     201      (qx, qy), 0.0491167089952  ], 
     202    [{'thick_core': 10.0, 
     203      'thick_layer': 15.0, 
    188204      'radius': 3000.0, 
    189205      'n_stacking': 5, 
     
    228244      'background': 0.001, 
    229245     }, ([0.4, 0.5]), [0.00105074, 0.00121761]], 
     246    [{'thick_core': 10.0, 
     247      'thick_layer': 15.0, 
     248      'radius': 3000.0, 
     249      'n_stacking': 1.0, 
     250      'sigma_d': 0.0, 
     251      'sld_core': 4.0, 
     252      'sld_layer': -0.4, 
     253      'solvent_sd': 5.0, 
     254      'theta': 90.0, 
     255      'phi': 20.0, 
     256      'scale': 0.01, 
     257      'background': 0.001, 
     258     }, (qx, qy), 0.0341738733124 ], 
    230259 
    231260    [{'thick_core': 10.0, 
  • sasmodels/models/triaxial_ellipsoid.py

    r15a90c1 r16a8c63  
    8686The contrast $\Delta\rho$ is defined as SLD(ellipsoid) - SLD(solvent).  In the 
    8787parameters, $R_a$ is the minor equatorial radius, $R_b$ is the major 
    88 equatorial radius, and $R_c$ is the polar radius of the ellipsoid.  
     88equatorial radius, and $R_c$ is the polar radius of the ellipsoid. 
    8989 
    9090NB: The 2nd virial coefficient of the triaxial solid ellipsoid is 
     
    117117""" 
    118118 
    119 from numpy import inf 
     119from numpy import inf, sin, cos, pi 
    120120 
    121121name = "triaxial_ellipsoid" 
     
    157157    from .ellipsoid import ER as ellipsoid_ER 
    158158 
    159     # now that radii can be in any size order, radii need sorting a,b,c where a~b and c is either much smaller  
     159    # now that radii can be in any size order, radii need sorting a,b,c where a~b and c is either much smaller 
    160160    # or much larger 
    161161    radii = np.vstack((radius_equat_major, radius_equat_minor, radius_polar)) 
     
    177177            psi_pd=15, psi_pd_n=1) 
    178178 
    179 # TODO: need some unit tests! 
     179q = 0.1 
     180# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! 
     181# add 2d test after pull #890 
     182qx = q*cos(pi/6.0) 
     183qy = q*sin(pi/6.0) 
     184tests = [[{}, 0.05, 24.8839548033], 
     185#        [{'theta':80., 'phi':10.}, (qx, qy), 9999. ], 
     186        ] 
     187del qx, qy  # not necessary to delete, but cleaner 
  • sasmodels/models/core_shell_parallelepiped.py

    r933af72 r1916c52  
    1010 
    1111.. note:: 
    12    This model was originally ported from NIST IGOR macros. However,t is not 
    13    yet fully understood by the SasView developers and is currently review. 
     12   This model was originally ported from NIST IGOR macros. However, it is not 
     13   yet fully understood by the SasView developers and is currently under review. 
    1414 
    1515The form factor is normalized by the particle volume $V$ such that 
     
    5151 
    5252    F_{a}(Q,\alpha,\beta)= 
    53     \left[\frac{\sin(Q(L_A+2t_A)/2\sin\alpha \sin\beta)}{Q(L_A+2t_A)/2\sin\alpha\sin\beta} 
    54     - \frac{\sin(QL_A/2\sin\alpha \sin\beta)}{QL_A/2\sin\alpha \sin\beta} \right] 
    55     \left[\frac{\sin(QL_B/2\sin\alpha \sin\beta)}{QL_B/2\sin\alpha \sin\beta} \right] 
    56     \left[\frac{\sin(QL_C/2\sin\alpha \sin\beta)}{QL_C/2\sin\alpha \sin\beta} \right] 
     53    \left[\frac{\sin(\tfrac{1}{2}Q(L_A+2t_A)\sin\alpha \sin\beta)}{\tfrac{1}{2}Q(L_A+2t_A)\sin\alpha\sin\beta} 
     54    - \frac{\sin(\tfrac{1}{2}QL_A\sin\alpha \sin\beta)}{\tfrac{1}{2}QL_A\sin\alpha \sin\beta} \right] 
     55    \left[\frac{\sin(\tfrac{1}{2}QL_B\sin\alpha \sin\beta)}{\tfrac{1}{2}QL_B\sin\alpha \sin\beta} \right] 
     56    \left[\frac{\sin(\tfrac{1}{2}QL_C\sin\alpha \sin\beta)}{\tfrac{1}{2}QL_C\sin\alpha \sin\beta} \right] 
    5757 
    5858.. note:: 
    5959 
     60    Why does t_B not appear in the above equation? 
    6061    For the calculation of the form factor to be valid, the sides of the solid 
    61     MUST be chosen such that** $A < B < C$. 
     62    MUST (perhaps not any more?) be chosen such that** $A < B < C$. 
    6263    If this inequality is not satisfied, the model will not report an error, 
    6364    but the calculation will not be correct and thus the result wrong. 
     
    8081NB: The 2nd virial coefficient of the core_shell_parallelepiped is calculated 
    8182based on the the averaged effective radius $(=\sqrt{(A+2t_A)(B+2t_B)/\pi})$ 
    82 and length $(C+2t_C)$ values, and used as the effective radius 
    83 for $S(Q)$ when $P(Q) * S(Q)$ is applied. 
     83and length $(C+2t_C)$ values, after appropriately 
     84sorting the three dimensions to give an oblate or prolate particle, to give an  
     85effective radius, for $S(Q)$ when $P(Q) * S(Q)$ is applied. 
    8486 
    8587To provide easy access to the orientation of the parallelepiped, we define the 
     
    9092*x*-axis of the detector. 
    9193 
    92 .. figure:: img/parallelepiped_angle_definition.jpg 
     94.. figure:: img/parallelepiped_angle_definition.png 
    9395 
    9496    Definition of the angles for oriented core-shell parallelepipeds. 
    9597 
    96 .. figure:: img/parallelepiped_angle_projection.jpg 
     98.. figure:: img/parallelepiped_angle_projection.png 
    9799 
    98100    Examples of the angles for oriented core-shell parallelepipeds against the 
     
    119121 
    120122import numpy as np 
    121 from numpy import pi, inf, sqrt 
     123from numpy import pi, inf, sqrt, cos, sin 
    122124 
    123125name = "core_shell_parallelepiped" 
     
    193195            psi_pd=10, psi_pd_n=1) 
    194196 
    195 qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5) 
     197# rkh 7/4/17 add random unit test for 2d, note make all params different, 2d values not tested against other codes or models 
     198qx, qy = 0.2 * cos(pi/6.), 0.2 * sin(pi/6.) 
    196199tests = [[{}, 0.2, 0.533149288477], 
    197200         [{}, [0.2], [0.533149288477]], 
    198          [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.032102135569], 
    199          [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.032102135569]], 
     201         [{'theta':10.0, 'phi':20.0}, (qx, qy), 0.0853299803222], 
     202         [{'theta':10.0, 'phi':20.0}, [(qx, qy)], [0.0853299803222]], 
    200203        ] 
    201204del qx, qy  # not necessary to delete, but cleaner 
  • sasmodels/models/cylinder.py

    rb7e8b94 r15a90c1  
    6464 
    6565    Definition of the angles for oriented cylinders. 
     66 
     67.. figure:: img/cylinder_angle_projection.png 
     68 
     69    Examples for oriented cylinders. 
    6670 
    6771The $\theta$ and $\phi$ parameters only appear in the model when fitting 2d data. 
  • sasmodels/models/parallelepiped.py

    red0827a r1916c52  
    1515.. _parallelepiped-image: 
    1616 
     17 
    1718.. figure:: img/parallelepiped_geometry.jpg 
    1819 
     
    2122.. note:: 
    2223 
    23    The edge of the solid must satisfy the condition that $A < B < C$. 
    24    This requirement is not enforced in the model, so it is up to the 
    25    user to check this during the analysis. 
     24   The edge of the solid used to have to satisfy the condition that $A < B < C$. 
     25   After some improvements to the effective radius calculation, used with an S(Q), 
     26   it is beleived that this is no longer the case.  
    2627 
    2728The 1D scattering intensity $I(q)$ is calculated as: 
     
    7172 
    7273NB: The 2nd virial coefficient of the parallelepiped is calculated based on 
    73 the averaged effective radius $(=\sqrt{A B / \pi})$ and 
     74the averaged effective radius, after appropriately 
     75sorting the three dimensions, to give an oblate or prolate particle, $(=\sqrt{A B / \pi})$ and 
    7476length $(= C)$ values, and used as the effective radius for 
    7577$S(q)$ when $P(q) \cdot S(q)$ is applied. 
     
    102104.. _parallelepiped-orientation: 
    103105 
    104 .. figure:: img/parallelepiped_angle_definition.jpg 
    105  
    106     Definition of the angles for oriented parallelepipeds. 
    107  
    108 .. figure:: img/parallelepiped_angle_projection.jpg 
    109  
    110     Examples of the angles for oriented parallelepipeds against the 
     106.. figure:: img/parallelepiped_angle_definition.png 
     107 
     108    Definition of the angles for oriented parallelepiped, shown with $A < B < C$. 
     109 
     110.. figure:: img/parallelepiped_angle_projection.png 
     111 
     112    Examples of the angles for an oriented parallelepiped against the 
    111113    detector plane. 
    112114 
     
    116118.. math:: 
    117119 
    118     P(q_x, q_y) = \left[\frac{\sin(qA\cos\alpha/2)}{(qA\cos\alpha/2)}\right]^2 
    119                   \left[\frac{\sin(qB\cos\beta/2)}{(qB\cos\beta/2)}\right]^2 
    120                   \left[\frac{\sin(qC\cos\gamma/2)}{(qC\cos\gamma/2)}\right]^2 
     120    P(q_x, q_y) = \left[\frac{\sin(\tfrac{1}{2}qA\cos\alpha)}{(\tfrac{1}{2}qA\cos\alpha)}\right]^2 
     121                  \left[\frac{\sin(\tfrac{1}{2}qB\cos\beta)}{(\tfrac{1}{2}qB\cos\beta)}\right]^2 
     122                  \left[\frac{\sin(\tfrac{1}{2}qC\cos\gamma)}{(\tfrac{1}{2}qC\cos\gamma)}\right]^2 
    121123 
    122124with 
     
    154156angles. 
    155157 
    156 This model is based on form factor calculations implemented in a c-library 
    157 provided by the NIST Center for Neutron Research (Kline, 2006). 
    158158 
    159159References 
     
    163163 
    164164R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 
     165 
     166Authorship and Verification 
     167---------------------------- 
     168 
     169* **Author:** This model is based on form factor calculations implemented in a c-library 
     170provided by the NIST Center for Neutron Research (Kline, 2006). 
     171* **Last Modified by:**  Paul Kienzle **Date:** April 05, 2017 
     172* **Last Reviewed by:**  Richard Heenan **Date:** April 06, 2017 
     173 
    165174""" 
    166175 
    167176import numpy as np 
    168 from numpy import pi, inf, sqrt 
     177from numpy import pi, inf, sqrt, sin, cos 
    169178 
    170179name = "parallelepiped" 
     
    208217def ER(length_a, length_b, length_c): 
    209218    """ 
    210         Return effective radius (ER) for P(q)*S(q) 
     219    Return effective radius (ER) for P(q)*S(q) 
    211220    """ 
    212  
     221    # now that axes can be in any size order, need to sort a,b,c where a~b and c is either much smaller  
     222    # or much larger 
     223    abc = np.vstack((length_a, length_b, length_c)) 
     224    abc = np.sort(abc, axis=0) 
     225    selector = (abc[1] - abc[0]) > (abc[2] - abc[1]) 
     226    length = np.where(selector, abc[0], abc[2]) 
    213227    # surface average radius (rough approximation) 
    214     surf_rad = sqrt(length_a * length_b / pi) 
    215  
    216     ddd = 0.75 * surf_rad * (2 * surf_rad * length_c + (length_c + surf_rad) * (length_c + pi * surf_rad)) 
     228    radius = np.sqrt(np.where(~selector, abc[0]*abc[1], abc[1]*abc[2]) / pi) 
     229 
     230    ddd = 0.75 * radius * (2*radius*length + (length + radius)*(length + pi*radius)) 
    217231    return 0.5 * (ddd) ** (1. / 3.) 
    218232 
     
    230244            phi_pd=10, phi_pd_n=1, 
    231245            psi_pd=10, psi_pd_n=10) 
    232  
    233 qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5) 
     246# rkh 7/4/17 add random unit test for 2d, note make all params different, 2d values not tested against other codes or models 
     247qx, qy = 0.2 * cos(pi/6.), 0.2 * sin(pi/6.) 
    234248tests = [[{}, 0.2, 0.17758004974], 
    235249         [{}, [0.2], [0.17758004974]], 
    236          [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.00560296014], 
    237          [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.00560296014]], 
     250         [{'theta':10.0, 'phi':20.0}, (qx, qy), 0.0089517140475], 
     251         [{'theta':10.0, 'phi':20.0}, [(qx, qy)], [0.0089517140475]], 
    238252        ] 
    239253del qx, qy  # not necessary to delete, but cleaner 
Note: See TracChangeset for help on using the changeset viewer.