Changeset 40a87fa in sasmodels for sasmodels/model_test.py


Ignore:
Timestamp:
Aug 8, 2016 11:24:11 AM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
2472141
Parents:
2d65d51
Message:

lint and latex cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    r2c74c11 r40a87fa  
    5151 
    5252from .core import list_models, load_model_info, build_model, HAVE_OPENCL 
    53 from .details import dispersion_mesh 
    54 from .direct_model import call_kernel, get_weights 
     53from .direct_model import call_kernel, call_ER, call_VR 
    5554from .exception import annotate_exception 
    5655from .modelinfo import expand_pars 
     
    6362    from .modelinfo import ParameterTable, ParameterSet, TestCondition, ModelInfo 
    6463    from .kernel import KernelModel 
    65  
    66 def call_ER(model_info, pars): 
    67     # type: (ModelInfo, ParameterSet) -> float 
    68     """ 
    69     Call the model ER function using *values*. 
    70  
    71     *model_info* is either *model.info* if you have a loaded model, 
    72     or *kernel.info* if you have a model kernel prepared for evaluation. 
    73     """ 
    74     if model_info.ER is None: 
    75         return 1.0 
    76     else: 
    77         value, weight = _vol_pars(model_info, pars) 
    78         individual_radii = model_info.ER(*value) 
    79         return np.sum(weight*individual_radii) / np.sum(weight) 
    80  
    81 def call_VR(model_info, pars): 
    82     # type: (ModelInfo, ParameterSet) -> float 
    83     """ 
    84     Call the model VR function using *pars*. 
    85  
    86     *model_info* is either *model.info* if you have a loaded model, 
    87     or *kernel.info* if you have a model kernel prepared for evaluation. 
    88     """ 
    89     if model_info.VR is None: 
    90         return 1.0 
    91     else: 
    92         value, weight = _vol_pars(model_info, pars) 
    93         whole, part = model_info.VR(*value) 
    94         return np.sum(weight*part)/np.sum(weight*whole) 
    95  
    96 def _vol_pars(model_info, pars): 
    97     # type: (ModelInfo, ParameterSet) -> Tuple[np.ndarray, np.ndarray] 
    98     vol_pars = [get_weights(p, pars) 
    99                 for p in model_info.parameters.call_parameters 
    100                 if p.type == 'volume'] 
    101     value, weight = dispersion_mesh(model_info, vol_pars) 
    102     return value, weight 
    10364 
    10465 
     
    194155        def run_all(self): 
    195156            # type: () -> None 
     157            """ 
     158            Run all the tests in the test suite, including smoke tests. 
     159            """ 
    196160            smoke_tests = [ 
    197161                # test validity at reasonable values 
     
    230194        def run_one(self, model, test): 
    231195            # type: (KernelModel, TestCondition) -> None 
     196            """Run a single test case.""" 
    232197            user_pars, x, y = test 
    233198            pars = expand_pars(self.info.parameters, user_pars) 
     
    269234                    # is_near does not work for infinite values, so also test 
    270235                    # for exact values.  Note that this will not 
    271                     self.assertTrue(yi==actual_yi or is_near(yi, actual_yi, 5), 
     236                    self.assertTrue(yi == actual_yi or is_near(yi, actual_yi, 5), 
    272237                                    'f(%s); expected:%s; actual:%s' 
    273238                                    % (xi, yi, actual_yi)) 
     
    293258    try: 
    294259        from xmlrunner import XMLTestRunner as TestRunner 
    295         test_args = { 'output': 'logs' } 
     260        test_args = {'output': 'logs'} 
    296261    except ImportError: 
    297262        from unittest import TextTestRunner as TestRunner 
    298         test_args = { } 
     263        test_args = {} 
    299264 
    300265    models = sys.argv[1:] 
Note: See TracChangeset for help on using the changeset viewer.