Changeset fb5914f in sasmodels
- Timestamp:
- Mar 30, 2016 1:34:16 AM (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:
- 7a1143b, 3a45c2c
- Parents:
- ce896fd
- Location:
- sasmodels
- Files:
-
- 3 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())
Note: See TracChangeset
for help on using the changeset viewer.