Changes in / [33e91b1:59c4c4e] in sasmodels
- Location:
- sasmodels
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/bumps_model.py
r5134b2c r9890053 437 437 data = load_data('DEC07086.DAT') 438 438 set_beam_stop(data, 0.004) 439 plot_data(data )439 plot_data(data, data.data) 440 440 import matplotlib.pyplot as plt; plt.show() 441 441 -
sasmodels/core.py
r84e01d2 r9890053 53 53 return v,w/np.sum(w) 54 54 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 55 70 def call_kernel(kernel, pars, cutoff=1e-5): 56 71 fixed_pars = [pars.get(name, kernel.info['defaults'][name]) … … 59 74 return kernel(fixed_pars, pd_pars, cutoff=cutoff) 60 75 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
r84e01d2 r9890053 1 1 # -*- coding: utf-8 -*- 2 2 """ 3 Created on Tue Feb 17 11:43:56 2015 4 5 @author: David 3 Run model unit tests. 4 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). 6 43 """ 7 44 … … 13 50 from .core import list_models, load_model_definition 14 51 from .core import load_model_cl, load_model_dll 15 from .core import make_kernel, call_kernel 52 from .core import make_kernel, call_kernel, call_ER, call_VR 16 53 17 54 def annotate_exception(exc, msg): … … 54 91 model_definition = load_model_definition(model_name) 55 92 56 smoke_tests = [[{},0.1,None],[{},(0.1,0.1),None]] 93 smoke_tests = [ 94 [{},0.1,None], 95 [{},(0.1,0.1),None], 96 [{},'ER',None], 97 [{},'VR',None], 98 ] 57 99 tests = smoke_tests + getattr(model_definition, 'tests', []) 58 100 … … 102 144 pars, Q, I = test 103 145 146 if not isinstance(I, list): 147 I = [I] 104 148 if not isinstance(Q, list): 105 149 Q = [Q] 106 if not isinstance(I, list): 107 I = [I] 108 109 if isinstance(Q[0], tuple): 150 151 self.assertEqual(len(I), len(Q)) 152 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): 110 158 Qx,Qy = zip(*Q) 111 159 Q_vectors = [np.array(Qx), np.array(Qy)] 160 kernel = make_kernel(model, Q_vectors) 161 Iq = call_kernel(kernel, pars) 112 162 else: 113 163 Q_vectors = [np.array(Q)] 114 115 self.assertEqual(len(I), len(Q)) 116 117 kernel = make_kernel(model, Q_vectors) 118 Iq = call_kernel(kernel, pars) 164 kernel = make_kernel(model, Q_vectors) 165 Iq = call_kernel(kernel, pars) 119 166 120 167 self.assertGreater(len(Iq), 0) … … 122 169 123 170 for q, i, iq in zip(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)) 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)) 129 178 130 179 except Exception,exc: -
sasmodels/models/barbell.py
ra5d0d00 r9890053 127 127 source = [ "lib/J1.c", "lib/gauss76.c", "barbell.c" ] 128 128 129 def ER(radius, length):130 return 1.0131 132 129 # parameters for demo 133 130 demo = dict( -
sasmodels/models/bcc.py
r6272968 r9890053 128 128 source = [ "lib/J1.c", "lib/gauss150.c", "bcc.c" ] 129 129 130 def ER(radius, length):131 return 0132 133 130 # parameters for demo 134 131 demo = dict( -
sasmodels/models/cylinder.py
ra5d0d00 r9890053 172 172 173 173 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 double185 # May want a limited precision version that checks for 8-n or 15-n digits respectively186 174 qx,qy = 0.2*np.cos(2.5), 0.2*np.sin(2.5) 187 175 tests = [ -
sasmodels/models/fcc.py
ra5d0d00 r9890053 103 103 source = [ "lib/J1.c", "lib/gauss150.c", "fcc.c" ] 104 104 105 def ER(radius, length):106 return 0107 108 105 # parameters for demo 109 106 demo = dict(
Note: See TracChangeset
for help on using the changeset viewer.