Changes in / [59c4c4e:33e91b1] in sasmodels


Ignore:
Location:
sasmodels
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/bumps_model.py

    r9890053 r5134b2c  
    437437    data = load_data('DEC07086.DAT') 
    438438    set_beam_stop(data, 0.004) 
    439     plot_data(data, data.data) 
     439    plot_data(data) 
    440440    import matplotlib.pyplot as plt; plt.show() 
    441441 
  • sasmodels/core.py

    r9890053 r84e01d2  
    5353    return v,w/np.sum(w) 
    5454 
    55 def dispersion_mesh(pars): 
    56     """ 
    57     Create a mesh grid of dispersion parameters and weights. 
    58  
    59     Returns [p1,p2,...],w where pj is a vector of values for parameter j 
    60     and w is a vector containing the products for weights for each 
    61     parameter set in the vector. 
    62     """ 
    63     values, weights = zip(*pars) 
    64     if len(values) > 1: 
    65         values = [v.flatten() for v in np.meshgrid(*values)] 
    66         weights = np.vstack([v.flatten() for v in np.meshgrid(*weights)]) 
    67         weights = np.prod(weights, axis=0) 
    68     return values, weights 
    69  
    7055def call_kernel(kernel, pars, cutoff=1e-5): 
    7156    fixed_pars = [pars.get(name, kernel.info['defaults'][name]) 
     
    7459    return kernel(fixed_pars, pd_pars, cutoff=cutoff) 
    7560 
    76 def call_ER(kernel, pars): 
    77     ER = kernel.info.get('ER', None) 
    78     if ER is None: 
    79         return 1.0 
    80     else: 
    81         vol_pars = [get_weights(kernel, pars, name) 
    82                     for name in kernel.info['partype']['volume']] 
    83         values, weights = dispersion_mesh(vol_pars) 
    84         fv = ER(*values) 
    85         #print values[0].shape, weights.shape, fv.shape 
    86         return np.sum(weights*fv) / np.sum(weights) 
    87  
    88 def call_VR(kernel, pars): 
    89     VR = kernel.info.get('VR', None) 
    90     if VR is None: 
    91         return 1.0 
    92     else: 
    93         vol_pars = [get_weights(kernel, pars, name) 
    94                     for name in kernel.info['partype']['volume']] 
    95         values, weights = dispersion_mesh(vol_pars) 
    96         whole,part = VR(*values) 
    97         return np.sum(weights*part)/np.sum(weights*whole) 
    98  
  • sasmodels/model_test.py

    r9890053 r84e01d2  
    11# -*- coding: utf-8 -*- 
    22""" 
    3 Run model unit tests. 
     3Created on Tue Feb 17 11:43:56 2015 
    44 
    5 Usage:: 
    6  
    7      python -m sasmodels.model_test [opencl|dll|opencl_and_dll] model1 model2 ... 
    8  
    9      if model1 is 'all', then all except the remaining models will be tested 
    10  
    11 Each model is tested using the default parameters at q=0.1, (qx,qy)=(0.1,0.1), 
    12 and the ER and VR are computed.  The return values at these points are not 
    13 considered.  The test is only to verify that the models run to completion, 
    14 and do not produce inf or NaN. 
    15  
    16 Tests are defined with the *tests* attribute in the model.py file.  *tests* 
    17 is a list of individual tests to run, where each test consists of the 
    18 parameter values for the test, the q-values and the expected results.  For 
    19 the effective radius test, the q-value should be 'ER'.  For the VR test, 
    20 the q-value should be 'VR'.  For 1-D tests, either specify the q value or 
    21 a list of q-values, and the corresponding I(q) value, or list of I(q) values. 
    22  
    23 That is:: 
    24  
    25     tests = [ 
    26         [ {parameters}, q, I(q)], 
    27         [ {parameters}, [q], [I(q)] ], 
    28         [ {parameters}, [q1, q2, ...], [I(q1), I(q2), ...]], 
    29  
    30         [ {parameters}, (qx, qy), I(qx, Iqy)], 
    31         [ {parameters}, [(qx1, qy1), (qx2, qy2), ...], [I(qx1,qy1), I(qx2,qy2), ...], 
    32  
    33         [ {parameters}, 'ER', ER(pars) ], 
    34         [ {parameters}, 'VR', VR(pars) ], 
    35         ... 
    36     ] 
    37  
    38 Parameters are *key:value* pairs, where key is one of the parameters of the 
    39 model and value is the value to use for the test.  Any parameters not given 
    40 in the parameter list will take on the default parameter value. 
    41  
    42 Precision defaults to 5 digits (relative). 
     5@author: David 
    436""" 
    447 
     
    5013from .core import list_models, load_model_definition 
    5114from .core import load_model_cl, load_model_dll 
    52 from .core import make_kernel, call_kernel, call_ER, call_VR 
     15from .core import make_kernel, call_kernel 
    5316 
    5417def annotate_exception(exc, msg): 
     
    9154        model_definition = load_model_definition(model_name) 
    9255 
    93         smoke_tests = [ 
    94             [{},0.1,None], 
    95             [{},(0.1,0.1),None], 
    96             [{},'ER',None], 
    97             [{},'VR',None], 
    98             ] 
     56        smoke_tests = [[{},0.1,None],[{},(0.1,0.1),None]] 
    9957        tests = smoke_tests + getattr(model_definition, 'tests', []) 
    10058         
     
    144102                pars, Q, I = test 
    145103 
     104                if not isinstance(Q, list): 
     105                    Q = [Q] 
    146106                if not isinstance(I, list): 
    147107                    I = [I] 
    148                 if not isinstance(Q, list): 
    149                     Q = [Q] 
     108                     
     109                if isinstance(Q[0], tuple): 
     110                    Qx,Qy = zip(*Q) 
     111                    Q_vectors = [np.array(Qx), np.array(Qy)] 
     112                else: 
     113                    Q_vectors = [np.array(Q)] 
    150114 
    151115                self.assertEqual(len(I), len(Q)) 
    152116 
    153                 if Q[0] == 'ER': 
    154                     Iq = [call_ER(kernel, pars)] 
    155                 elif Q[0] == 'VR': 
    156                     Iq = [call_VR(kernel, pars)] 
    157                 elif isinstance(Q[0], tuple): 
    158                     Qx,Qy = zip(*Q) 
    159                     Q_vectors = [np.array(Qx), np.array(Qy)] 
    160                     kernel = make_kernel(model, Q_vectors) 
    161                     Iq = call_kernel(kernel, pars) 
    162                 else: 
    163                     Q_vectors = [np.array(Q)] 
    164                     kernel = make_kernel(model, Q_vectors) 
    165                     Iq = call_kernel(kernel, pars) 
     117                kernel = make_kernel(model, Q_vectors) 
     118                Iq = call_kernel(kernel, pars) 
    166119             
    167120                self.assertGreater(len(Iq), 0)     
     
    169122                 
    170123                for q, i, iq in zip(Q, I, Iq): 
    171                     if i is None: 
    172                         # smoke test --- make sure it runs and produces a value 
    173                         self.assertTrue(np.isfinite(iq), 'q:%s; not finite; actual:%s' % (q, iq)) 
    174                     else: 
    175                         err = abs(i - iq) 
    176                         nrm = abs(i) 
    177                         self.assertLess(err * 10**5, nrm, 'q:%s; expected:%s; actual:%s' % (q, i, iq)) 
     124                    if i is None: continue # smoke test --- make sure it runs 
     125                    err = abs(i - iq) 
     126                    nrm = abs(i) 
     127             
     128                    self.assertLess(err * 10**5, nrm, 'q:%s; expected:%s; actual:%s' % (q, i, iq)) 
    178129                     
    179130        except Exception,exc:  
  • sasmodels/models/barbell.py

    r9890053 ra5d0d00  
    127127source = [ "lib/J1.c", "lib/gauss76.c", "barbell.c" ] 
    128128 
     129def ER(radius, length): 
     130    return 1.0 
     131 
    129132# parameters for demo 
    130133demo = dict( 
  • sasmodels/models/bcc.py

    r9890053 r6272968  
    128128source = [ "lib/J1.c", "lib/gauss150.c", "bcc.c" ] 
    129129 
     130def ER(radius, length): 
     131    return 0 
     132 
    130133# parameters for demo 
    131134demo = dict( 
  • sasmodels/models/cylinder.py

    r9890053 ra5d0d00  
    172172 
    173173 
     174# test values: 
     175# [ 
     176#   [ {parameters}, q, I(q)], 
     177#   [ {parameters}, [q], [I(q)] ], 
     178#   [ {parameters}, [q1, q2, ...], [I(q1), I(q2), ...]], 
     179 
     180#   [ {parameters}, (qx, qy), I(qx, Iqy)], 
     181#   [ {parameters}, [(qx1, qy1), (qx2, qy2), ...], [I(qx1,qy1), I(qx2,qy2), ...], 
     182#   ... 
     183# ] 
     184# Precision defaults to 7 digits (relative) for single, 14 for double 
     185# May want a limited precision version that checks for 8-n or 15-n digits respectively 
    174186qx,qy = 0.2*np.cos(2.5), 0.2*np.sin(2.5) 
    175187tests = [ 
  • sasmodels/models/fcc.py

    r9890053 ra5d0d00  
    103103source = [ "lib/J1.c", "lib/gauss150.c", "fcc.c" ] 
    104104 
     105def ER(radius, length): 
     106    return 0 
     107 
    105108# parameters for demo 
    106109demo = dict( 
Note: See TracChangeset for help on using the changeset viewer.