Changeset d0876c9d in sasmodels
- Timestamp:
- Mar 30, 2016 2:34:39 PM (9 years ago)
- 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:
- aaf75b6
- Parents:
- d1c4760 (diff), fb5914f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- sasmodels
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/core.py
rd19962c rfb5914f 241 241 else ([pars.get(p.name, p.default)], [])) 242 242 for p in parameters.call_parameters] 243 values, weights = zip(*vw_pairs) 244 243 244 details, weights, values = build_details(kernel, vw_pairs) 245 return kernel(details, weights, values, cutoff) 246 247 def build_details(kernel, pairs): 248 values, weights = zip(*pairs) 245 249 if max([len(w) for w in weights]) > 1: 246 250 details = generate.poly_details(kernel.info, weights) 247 251 else: 248 252 details = kernel.info['mono_details'] 249 250 253 weights, values = [np.hstack(v) for v in (weights, values)] 251 252 254 weights = weights.astype(dtype=kernel.dtype) 253 255 values = values.astype(dtype=kernel.dtype) 254 return kernel(details, weights, values, cutoff) 256 return details, weights, values 257 255 258 256 259 def call_ER_VR(model_info, vol_pars): -
sasmodels/modelinfo.py
rce896fd rfb5914f 432 432 if p.polydisperse and p.type != 'magnetic') 433 433 434 def user_parameters(self, pars , is2d):434 def user_parameters(self, pars={}, is2d=True): 435 435 """ 436 436 Return the list of parameters for the given data type. … … 493 493 if table: 494 494 # look up length from incoming parameters 495 table_length = int(pars [p.length_control])495 table_length = int(pars.get(p.length_control, p.length)) 496 496 del dependent[p.length_control] # first entry seen 497 497 for k in range(1, table_length+1): -
sasmodels/sasview_model.py
rce896fd rfb5914f 21 21 22 22 from . import core 23 from . import generate23 from . import weights 24 24 25 25 def standard_models(): … … 52 52 """ 53 53 def __init__(self): 54 self._ kernel = None54 self._model = None 55 55 model_info = self._model_info 56 56 parameters = model_info['parameters'] … … 75 75 self.params = collections.OrderedDict() 76 76 self.dispersion = dict() 77 partype = model_info['partype'] 78 79 for p in model_info['parameters']: 77 78 self.orientation_params = [] 79 self.magnetic_params = [] 80 self.fixed = [] 81 for p in parameters.user_parameters(): 80 82 self.params[p.name] = p.default 81 83 self.details[p.name] = [p.units] + p.limits 82 83 for name in partype['pd-2d']: 84 self.dispersion[name] = { 85 'width': 0, 86 'npts': 35, 87 'nsigmas': 3, 88 'type': 'gaussian', 89 } 90 91 self.orientation_params = ( 92 partype['orientation'] 93 + [n + '.width' for n in partype['orientation']] 94 + partype['magnetic']) 95 self.magnetic_params = partype['magnetic'] 96 self.fixed = [n + '.width' for n in partype['pd-2d']] 84 if p.polydisperse: 85 self.dispersion[p.name] = { 86 'width': 0, 87 'npts': 35, 88 'nsigmas': 3, 89 'type': 'gaussian', 90 } 91 if p.type == 'orientation': 92 self.orientation_params.append(p.name) 93 self.orientation_params.append(p.name+".width") 94 self.fixed.append(p.name+".width") 95 if p.type == 'magnetic': 96 self.orientation_params.append(p.name) 97 self.magnetic_params.append(p.name) 98 self.fixed.append(p.name+".width") 99 97 100 self.non_fittable = [] 98 101 … … 113 116 def __get_state__(self): 114 117 state = self.__dict__.copy() 115 model_id = self._model_info['id']116 118 state.pop('_kernel') 117 119 # May need to reload model info on set state since it has pointers … … 122 124 def __set_state__(self, state): 123 125 self.__dict__ = state 124 self._ kernel = None126 self._model = None 125 127 126 128 def __str__(self): … … 211 213 def getDispParamList(self): 212 214 """ 213 Return a list of all availableparameters for the model215 Return a list of polydispersity parameters for the model 214 216 """ 215 217 # TODO: fix test so that parameter order doesn't matter 216 ret = ['%s.%s' % (d.lower(), p) 217 for d in self._model_info['partype']['pd-2d'] 218 for p in ('npts', 'nsigmas', 'width')] 218 ret = ['%s.%s' % (p.name.lower(), ext) 219 for p in self._model_info['parameters'].user_parameters() 220 for ext in ('npts', 'nsigmas', 'width') 221 if p.polydisperse] 219 222 #print(ret) 220 223 return ret … … 289 292 # Check whether we have a list of ndarrays [qx,qy] 290 293 qx, qy = qdist 291 partype = self._model_info['partype'] 292 if not partype['orientation'] and not partype['magnetic']: 294 if not self._model_info['parameters'].has_2d: 293 295 return self.calculate_Iq(np.sqrt(qx ** 2 + qy ** 2)) 294 296 else: … … 312 314 to the card for each evaluation. 313 315 """ 314 if self._ kernel is None:315 self._ kernel = core.build_model(self._model_info)316 if self._model is None: 317 self._model = core.build_model(self._model_info, platform='dll') 316 318 q_vectors = [np.asarray(q) for q in args] 317 fn = self._kernel(q_vectors) 318 pars = [self.params[v] for v in fn.fixed_pars] 319 pd_pars = [self._get_weights(p) for p in fn.pd_pars] 320 result = fn(pars, pd_pars, self.cutoff) 321 fn.q_input.release() 322 fn.release() 319 kernel = self._model.make_kernel(q_vectors) 320 pairs = [self._get_weights(p) 321 for p in self._model_info['parameters'].call_parameters] 322 details, weights, values = core.build_details(kernel, pairs) 323 return kernel(details, weights, values, cutoff=self.cutoff) 324 kernel.q_input.release() 325 kernel.release() 323 326 return result 324 327 … … 393 396 def _get_weights(self, par): 394 397 """ 395 Return dispersion weights 396 :param par parameter name 397 """ 398 from . import weights 399 400 relative = self._model_info['partype']['pd-rel'] 401 limits = self._model_info['limits'] 402 dis = self.dispersion[par] 403 value, weight = weights.get_weights( 404 dis['type'], dis['npts'], dis['width'], dis['nsigmas'], 405 self.params[par], limits[par], par in relative) 406 return value, weight / np.sum(weight) 407 398 Return dispersion weights for parameter 399 """ 400 if par.polydisperse: 401 dis = self.dispersion[par.name] 402 value, weight = weights.get_weights( 403 dis['type'], dis['npts'], dis['width'], dis['nsigmas'], 404 self.params[par.name], par.limits, par.relative_pd) 405 return value, weight / np.sum(weight) 406 else: 407 return [self.params[par.name]], [] 408 409 def test_model(): 410 Cylinder = make_class('cylinder') 411 cylinder = Cylinder() 412 return cylinder.evalDistribution([0.1,0.1]) 413 414 if __name__ == "__main__": 415 print("cylinder(0.1,0.1)=%g"%test_model()) -
sasmodels/compare.py
rd19962c rd1c4760 784 784 n1 = int(args[1]) if len(args) > 1 else 1 785 785 n2 = int(args[2]) if len(args) > 2 else 1 786 use_sasview = any(engine=='sasview' and count>0 787 for engine, count in zip(engines, [n1, n2])) 786 788 787 789 # Get demo parameters from model definition, or use default parameters … … 811 813 #import pprint; pprint.pprint(model_info) 812 814 constrain_pars(model_info, pars) 813 constrain_new_to_old(model_info, pars) 815 if use_sasview: 816 constrain_new_to_old(model_info, pars) 814 817 if opts['show_pars']: 815 818 print(str(parlist(model_info, pars, opts['is2d']))) -
sasmodels/convert.py
rce896fd rd1c4760 138 138 namelist = name.split('*') if '*' in name else [name] 139 139 for name in namelist: 140 if name == 'pearl_necklace': 140 if name == 'stacked_disks': 141 _remove_pd(oldpars, 'n_stacking', name) 142 elif name == 'pearl_necklace': 141 143 _remove_pd(oldpars, 'num_pearls', name) 142 144 _remove_pd(oldpars, 'thick_string', name) -
sasmodels/models/_spherepy.py
r49da079 rd7028dc 1 1 r""" 2 For information about polarised and magnetic scattering, click here_. 3 4 .. _here: polar_mag_help.html 2 For information about polarised and magnetic scattering, see 3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 5 4 6 5 Definition -
sasmodels/models/fuzzy_sphere.py
r0cc31e1 rd7028dc 1 1 r""" 2 For information about polarised and magnetic scattering, click here_. 3 4 .. _here: polar_mag_help.html 2 For information about polarised and magnetic scattering, see 3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 5 4 6 5 Definition -
sasmodels/models/multilayer_vesicle.py
rc6ca41e rd7028dc 29 29 is used as the effective radius for *S(Q)* when $P(Q) * S(Q)$ is applied. 30 30 31 32 33 For information about polarised and magnetic scattering, click here_. 34 35 .. _here: polar_mag_help.html 31 For information about polarised and magnetic scattering, see 32 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 36 33 37 34 This code is based on the form factor calculations implemented in the NIST -
sasmodels/models/sphere.py
r49da079 rd7028dc 1 1 r""" 2 For information about polarised and magnetic scattering, click here_. 3 4 .. _here: polar_mag_help.html 2 For information about polarised and magnetic scattering, see 3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 5 4 6 5 Definition -
sasmodels/models/stacked_disks.py
re664a11 r53215cf 100 100 J S Higgins and H C Benoit, *Polymers and Neutron Scattering*, Clarendon, Oxford, 1994 101 101 102 **Author:** NIST IGOR/DANSE **on:** pre 2010 103 104 **Last Modified by:** Piotr Rozyczko **on:** February 18, 2016 105 106 **Last Reviewed by:** Richard Heenan **on:** March 22, 2016 102 107 """ 103 108 … … 157 162 158 163 tests = [ 159 # Accuracy tests based on content in test/utest_extra_models.py 164 # Accuracy tests based on content in test/utest_extra_models.py. 165 # Added 2 tests with n_stacked = 5 using SasView 3.1.2 - PDB 160 166 [{'core_thick': 10.0, 161 167 'layer_thick': 15.0, … … 171 177 'background': 0.001, 172 178 }, 0.001, 5075.12], 179 180 [{'core_thick': 10.0, 181 'layer_thick': 15.0, 182 'radius': 3000.0, 183 'n_stacking': 5.0, 184 'sigma_d': 0.0, 185 'sld_core': 4.0, 186 'sld_layer': -0.4, 187 'solvent_sd': 5.0, 188 'theta': 0.0, 189 'phi': 0.0, 190 'scale': 0.01, 191 'background': 0.001, 192 }, 0.001, 5065.12793824], 193 194 [{'core_thick': 10.0, 195 'layer_thick': 15.0, 196 'radius': 3000.0, 197 'n_stacking': 5.0, 198 'sigma_d': 0.0, 199 'sld_core': 4.0, 200 'sld_layer': -0.4, 201 'solvent_sd': 5.0, 202 'theta': 0.0, 203 'phi': 0.0, 204 'scale': 0.01, 205 'background': 0.001, 206 }, 0.164, 0.0127673597265], 173 207 174 208 [{'core_thick': 10.0,
Note: See TracChangeset
for help on using the changeset viewer.