Changes in / [68b8734:3b12dea] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/sasview_model.py
rde97440 r2622b3f 23 23 from . import core 24 24 25 def standard_models(): 26 return [make_class(model_name) for model_name in core.list_models()] 27 28 def make_class(model_name, namestyle='name'): 25 def make_class(model_info, dtype='single', namestyle='name'): 29 26 """ 30 27 Load the sasview model defined in *kernel_module*. 31 28 32 Returns a class that can be used directly as a sasview model. t29 Returns a class that can be used directly as a sasview model. 33 30 34 31 Defaults to using the new name for a model. Setting … … 36 33 compatible with SasView. 37 34 """ 38 model _info = core.load_model_info(model_name)35 model = core.build_model(model_info, dtype=dtype) 39 36 def __init__(self, multfactor=1): 40 SasviewModel.__init__(self, model _info)37 SasviewModel.__init__(self, model) 41 38 attrs = dict(__init__=__init__) 42 ConstructedModel = type(model _info[namestyle], (SasviewModel,), attrs)39 ConstructedModel = type(model.info[namestyle], (SasviewModel,), attrs) 43 40 return ConstructedModel 44 41 … … 47 44 Sasview wrapper for opencl/ctypes model. 48 45 """ 49 def __init__(self, model _info):50 self._model_info = model_info51 self._ kernel = None52 53 self.name = model _info['name']54 self.oldname = model _info['oldname']55 self.description = model _info['description']46 def __init__(self, model): 47 """Initialization""" 48 self._model = model 49 50 self.name = model.info['name'] 51 self.oldname = model.info['oldname'] 52 self.description = model.info['description'] 56 53 self.category = None 57 54 self.multiplicity_info = None … … 63 60 self.params = collections.OrderedDict() 64 61 self.dispersion = dict() 65 partype = model _info['partype']66 67 for p in model _info['parameters']:62 partype = model.info['partype'] 63 64 for p in model.info['parameters']: 68 65 self.params[p.name] = p.default 69 66 self.details[p.name] = [p.units] + p.limits … … 86 83 87 84 ## independent parameter name and unit [string] 88 self.input_name = model _info.get("input_name", "Q")89 self.input_unit = model _info.get("input_unit", "A^{-1}")90 self.output_name = model _info.get("output_name", "Intensity")91 self.output_unit = model _info.get("output_unit", "cm^{-1}")85 self.input_name = model.info.get("input_name", "Q") 86 self.input_unit = model.info.get("input_unit", "A^{-1}") 87 self.output_name = model.info.get("output_name", "Intensity") 88 self.output_unit = model.info.get("output_unit", "cm^{-1}") 92 89 93 90 ## _persistency_dict is used by sas.perspectives.fitting.basepage … … 98 95 ## New fields introduced for opencl rewrite 99 96 self.cutoff = 1e-5 100 101 def __get_state__(self):102 state = self.__dict__.copy()103 model_id = self._model_info['id']104 state.pop('_kernel')105 # May need to reload model info on set state since it has pointers106 # to python implementations of Iq, etc.107 #state.pop('_model_info')108 return state109 110 def __set_state__(self, state):111 self.__dict__ = state112 self._kernel = None113 97 114 98 def __str__(self): … … 203 187 # TODO: fix test so that parameter order doesn't matter 204 188 ret = ['%s.%s' % (d.lower(), p) 205 for d in self._model _info['partype']['pd-2d']189 for d in self._model.info['partype']['pd-2d'] 206 190 for p in ('npts', 'nsigmas', 'width')] 207 191 #print(ret) … … 277 261 # Check whether we have a list of ndarrays [qx,qy] 278 262 qx, qy = qdist 279 partype = self._model _info['partype']263 partype = self._model.info['partype'] 280 264 if not partype['orientation'] and not partype['magnetic']: 281 265 return self.calculate_Iq(np.sqrt(qx ** 2 + qy ** 2)) … … 300 284 to the card for each evaluation. 301 285 """ 302 if self._kernel is None:303 self._kernel = core.build_model(self._model_info)304 286 q_vectors = [np.asarray(q) for q in args] 305 fn = self._ kernel(q_vectors)287 fn = self._model(q_vectors) 306 288 pars = [self.params[v] for v in fn.fixed_pars] 307 289 pd_pars = [self._get_weights(p) for p in fn.pd_pars] … … 317 299 :return: the value of the effective radius 318 300 """ 319 ER = self._model _info.get('ER', None)301 ER = self._model.info.get('ER', None) 320 302 if ER is None: 321 303 return 1.0 … … 332 314 :return: the value of the volf ratio 333 315 """ 334 VR = self._model _info.get('VR', None)316 VR = self._model.info.get('VR', None) 335 317 if VR is None: 336 318 return 1.0 … … 376 358 parameter set in the vector. 377 359 """ 378 pars = self._model _info['partype']['volume']360 pars = self._model.info['partype']['volume'] 379 361 return core.dispersion_mesh([self._get_weights(p) for p in pars]) 380 362 … … 386 368 from . import weights 387 369 388 relative = self._model _info['partype']['pd-rel']389 limits = self._model _info['limits']370 relative = self._model.info['partype']['pd-rel'] 371 limits = self._model.info['limits'] 390 372 dis = self.dispersion[par] 391 373 value, weight = weights.get_weights( … … 393 375 self.params[par], limits[par], par in relative) 394 376 return value, weight / np.sum(weight) 395
Note: See TracChangeset
for help on using the changeset viewer.