Changes in / [59c4c4e:33e91b1] in sasmodels
- Location:
- sasmodels
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/bumps_model.py
r9890053 r5134b2c 437 437 data = load_data('DEC07086.DAT') 438 438 set_beam_stop(data, 0.004) 439 plot_data(data , data.data)439 plot_data(data) 440 440 import matplotlib.pyplot as plt; plt.show() 441 441 -
sasmodels/core.py
r9890053 r84e01d2 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 j60 and w is a vector containing the products for weights for each61 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, weights69 70 55 def call_kernel(kernel, pars, cutoff=1e-5): 71 56 fixed_pars = [pars.get(name, kernel.info['defaults'][name]) … … 74 59 return kernel(fixed_pars, pd_pars, cutoff=cutoff) 75 60 76 def call_ER(kernel, pars):77 ER = kernel.info.get('ER', None)78 if ER is None:79 return 1.080 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.shape86 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.092 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 1 1 # -*- coding: utf-8 -*- 2 2 """ 3 Run model unit tests. 3 Created on Tue Feb 17 11:43:56 2015 4 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). 5 @author: David 43 6 """ 44 7 … … 50 13 from .core import list_models, load_model_definition 51 14 from .core import load_model_cl, load_model_dll 52 from .core import make_kernel, call_kernel , call_ER, call_VR15 from .core import make_kernel, call_kernel 53 16 54 17 def annotate_exception(exc, msg): … … 91 54 model_definition = load_model_definition(model_name) 92 55 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]] 99 57 tests = smoke_tests + getattr(model_definition, 'tests', []) 100 58 … … 144 102 pars, Q, I = test 145 103 104 if not isinstance(Q, list): 105 Q = [Q] 146 106 if not isinstance(I, list): 147 107 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)] 150 114 151 115 self.assertEqual(len(I), len(Q)) 152 116 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) 166 119 167 120 self.assertGreater(len(Iq), 0) … … 169 122 170 123 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)) 178 129 179 130 except Exception,exc: -
sasmodels/models/barbell.py
r9890053 ra5d0d00 127 127 source = [ "lib/J1.c", "lib/gauss76.c", "barbell.c" ] 128 128 129 def ER(radius, length): 130 return 1.0 131 129 132 # parameters for demo 130 133 demo = dict( -
sasmodels/models/bcc.py
r9890053 r6272968 128 128 source = [ "lib/J1.c", "lib/gauss150.c", "bcc.c" ] 129 129 130 def ER(radius, length): 131 return 0 132 130 133 # parameters for demo 131 134 demo = dict( -
sasmodels/models/cylinder.py
r9890053 ra5d0d00 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 double 185 # May want a limited precision version that checks for 8-n or 15-n digits respectively 174 186 qx,qy = 0.2*np.cos(2.5), 0.2*np.sin(2.5) 175 187 tests = [ -
sasmodels/models/fcc.py
r9890053 ra5d0d00 103 103 source = [ "lib/J1.c", "lib/gauss150.c", "fcc.c" ] 104 104 105 def ER(radius, length): 106 return 0 107 105 108 # parameters for demo 106 109 demo = dict(
Note: See TracChangeset
for help on using the changeset viewer.