Changeset 6652522 in sasmodels


Ignore:
Timestamp:
Mar 28, 2019 10:23:00 AM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ticket-1257-vesicle-product, ticket_1156, ticket_822_more_unit_tests
Children:
f942f4d
Parents:
a430f5f
Message:

update cylinder R_eff tests

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    ra430f5f r6652522  
    329329            else: 
    330330                y1 = y 
    331                 y2 = test[3] if not isinstance(test[3], list) else [test[3]] 
    332                 F1, F2, R_eff, volume, volume_ratio = call_Fq(kernel, pars) 
    333                 if F1 is not None:  # F1 is none for models with Iq instead of Fq 
    334                     self._check_vectors(x, y1, F1, 'F') 
    335                 self._check_vectors(x, y2, F2, 'F^2') 
     331                y2 = test[3] if isinstance(test[3], list) else [test[3]] 
     332                F, Fsq, R_eff, volume, volume_ratio = call_Fq(kernel, pars) 
     333                if F is not None:  # F is none for models with Iq instead of Fq 
     334                    self._check_vectors(x, y1, F, 'F') 
     335                self._check_vectors(x, y2, Fsq, 'F^2') 
    336336                self._check_scalar(test[4], R_eff, 'R_eff') 
    337337                self._check_scalar(test[5], volume, 'volume') 
    338338                self._check_scalar(test[6], volume_ratio, 'form:shell ratio') 
    339                 return F2 
     339                return Fsq 
    340340 
    341341        def _check_scalar(self, target, actual, name): 
     
    414414    """ 
    415415    import math 
     416    if target == 0.: 
     417        return actual == 0. 
    416418    shift = 10**math.ceil(math.log10(np.abs(target))) 
    417419    return np.abs(target-actual)/shift < 1.5*10**-digits 
  • sasmodels/models/cylinder.py

    r0b8a1fc r6652522  
    110110---------------------------- 
    111111 
    112 * **Author:**  
    113 * **Last Modified by:**  
    114 * **Last Reviewed by:**  
     112* **Author:** 
     113* **Last Modified by:** 
     114* **Last Reviewed by:** 
    115115* **Source added by :** Steve King **Date:** March 25, 2019 
    116116""" 
     
    184184            phi_pd=10, phi_pd_n=5) 
    185185 
    186 # pylint: disable=bad-whitespace, line-too-long 
     186# Test 1-D and 2-D models 
    187187qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5) 
    188 # After redefinition of angles, find new tests values.  Was 10 10 in old coords 
     188theta, phi = 80.1534480601659, 10.1510817110481  # (10, 10) in sasview 3.x 
    189189tests = [ 
    190190    [{}, 0.2, 0.042761386790780453], 
    191191    [{}, [0.2], [0.042761386790780453]], 
    192     #  new coords 
    193     [{'theta':80.1534480601659, 'phi':10.1510817110481}, (qx, qy), 0.03514647218513852], 
    194     [{'theta':80.1534480601659, 'phi':10.1510817110481}, [(qx, qy)], [0.03514647218513852]], 
    195     # old coords 
    196     #[{'theta':10.0, 'phi':10.0}, (qx, qy), 0.03514647218513852], 
    197     #[{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.03514647218513852]], 
     192    [{'theta': theta, 'phi': phi}, (qx, qy), 0.03514647218513852], 
     193    [{'theta': theta, 'phi': phi}, [(qx, qy)], [0.03514647218513852]], 
    198194] 
    199 del qx, qy  # not necessary to delete, but cleaner 
    200  
    201 # Default radius and length 
    202 def calc_volume(radius, length): 
    203     """Return form volume for cylinder.""" 
    204     return pi*radius**2*length 
    205 def calc_r_effs(radius, length): 
    206     """Return effective radii for modes 0-7 of cylinder.""" 
    207     return [ 
     195del qx, qy, theta, phi  # not necessary to delete, but cleaner 
     196 
     197def _extend_with_reff_tests(radius, length): 
     198    """Test R_eff and form volume calculations""" 
     199    # V and Vr are the same for each R_eff mode 
     200    V = pi*radius**2*length  # shell volume = form volume for solid objects 
     201    Vr = 1.0  # form:shell volume ratio 
     202    # Use test value for I(0.2) from above to check Fsq value.  Need to 
     203    # remove scale and background before testing. 
     204    q = 0.2 
     205    scale, background = V, 0.001 
     206    Fsq = (0.042761386790780453 - background)*scale 
     207    F = None  # Need target value for <F> 
     208    # Various values for R_eff, depending on mode 
     209    r_effs = [ 
    208210        0., 
    209211        0.5*(0.75*radius*(2.0*radius*length 
     
    216218        np.sqrt(4*radius**2 + length**2)/2., 
    217219    ] 
    218 r_effs = calc_r_effs(parameters[2][2], parameters[3][2]) 
    219 cyl_vol = calc_volume(parameters[2][2], parameters[3][2]) 
    220 #tests.extend([ 
    221 #    ({'effective_radius_type': 0}, 0.1, 667.7347318577124, 1.0000, r_effs[0], cyl_vol, 1.0), 
    222      # first & second None do not work here, replacind 2nd Non by real number gives error also 
    223 #    ({'effective_radius_type': 1}, 0.1, None, None, r_effs[1], None, None), 
    224 #    ({'effective_radius_type': 2}, 0.1, None, None, r_effs[2], None, None), 
    225 #   ({'effective_radius_type': 3}, 0.1, None, None, r_effs[3], None, None), 
    226 #    ({'effective_radius_type': 4}, 0.1, None, None, r_effs[4], None, None), 
    227 #    ({'effective_radius_type': 5}, 0.1, None, None, r_effs[5], None, None), 
    228 #    ({'effective_radius_type': 6}, 0.1, None, None, r_effs[6], None, None), 
    229 #    ({'effective_radius_type': 7}, 0.1, None, None, r_effs[7], None, None), 
    230 #]) 
    231 del r_effs, cyl_vol 
    232 # pylint: enable=bad-whitespace, line-too-long 
     220    tests.extend([ 
     221        ({'radius_effective_mode': 0}, q, F, Fsq, r_effs[0], V, Vr), 
     222        ({'radius_effective_mode': 1}, q, F, Fsq, r_effs[1], V, Vr), 
     223        ({'radius_effective_mode': 2}, q, F, Fsq, r_effs[2], V, Vr), 
     224        ({'radius_effective_mode': 3}, q, F, Fsq, r_effs[3], V, Vr), 
     225        ({'radius_effective_mode': 4}, q, F, Fsq, r_effs[4], V, Vr), 
     226        ({'radius_effective_mode': 5}, q, F, Fsq, r_effs[5], V, Vr), 
     227        ({'radius_effective_mode': 6}, q, F, Fsq, r_effs[6], V, Vr), 
     228        ({'radius_effective_mode': 7}, q, F, Fsq, r_effs[7], V, Vr), 
     229    ]) 
     230 
     231# Test Reff and volume with default model parameters 
     232_extend_with_reff_tests(parameters[2][2], parameters[3][2]) 
     233del _extend_with_reff_tests 
    233234 
    234235# ADDED by:  RKH  ON: 18Mar2016 renamed sld's etc 
Note: See TracChangeset for help on using the changeset viewer.