Changes in / [fad5dc1:e17904a] in sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
explore/J1.py
ra5af4e1 raceac39 2 2 Show numerical precision of $2 J_1(x)/x$. 3 3 """ 4 import sys; sys.path.insert(0, '..') 4 5 5 6 import numpy as np 6 #from sympy.mpmath import mp 7 from mpmath import mp 7 try: 8 from mpmath import mp 9 except: 10 # CRUFT: mpmath split out into its own package 11 from sympy.mpmath import mp 8 12 #import matplotlib; matplotlib.use('TkAgg') 9 13 import pylab -
sasmodels/sasview_model.py
r2622b3f r08376e7 23 23 from . import core 24 24 25 def make_class(model_info, dtype='single', namestyle='name'): 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'): 26 29 """ 27 30 Load the sasview model defined in *kernel_module*. 28 31 29 Returns a class that can be used directly as a sasview model. 32 Returns a class that can be used directly as a sasview model.t 30 33 31 34 Defaults to using the new name for a model. Setting … … 33 36 compatible with SasView. 34 37 """ 35 model = core.build_model(model_info, dtype=dtype)38 model_info = core.load_model_info(model_name) 36 39 def __init__(self, multfactor=1): 37 SasviewModel.__init__(self , model)38 attrs = dict(__init__=__init__ )39 ConstructedModel = type(model .info[namestyle], (SasviewModel,), attrs)40 SasviewModel.__init__(self) 41 attrs = dict(__init__=__init__, _model_info=model_info) 42 ConstructedModel = type(model_info[namestyle], (SasviewModel,), attrs) 40 43 return ConstructedModel 41 44 … … 44 47 Sasview wrapper for opencl/ctypes model. 45 48 """ 46 def __init__(self , model):47 """Initialization"""48 self._model = model49 50 self.name = model .info['name']51 self.oldname = model .info['oldname']52 self.description = model .info['description']49 def __init__(self): 50 self._kernel = None 51 model_info = self._model_info 52 53 self.name = model_info['name'] 54 self.oldname = model_info['oldname'] 55 self.description = model_info['description'] 53 56 self.category = None 54 57 self.multiplicity_info = None … … 60 63 self.params = collections.OrderedDict() 61 64 self.dispersion = dict() 62 partype = model .info['partype']63 64 for p in model .info['parameters']:65 partype = model_info['partype'] 66 67 for p in model_info['parameters']: 65 68 self.params[p.name] = p.default 66 69 self.details[p.name] = [p.units] + p.limits … … 83 86 84 87 ## independent parameter name and unit [string] 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}")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}") 89 92 90 93 ## _persistency_dict is used by sas.perspectives.fitting.basepage … … 95 98 ## New fields introduced for opencl rewrite 96 99 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 pointers 106 # to python implementations of Iq, etc. 107 #state.pop('_model_info') 108 return state 109 110 def __set_state__(self, state): 111 self.__dict__ = state 112 self._kernel = None 97 113 98 114 def __str__(self): … … 187 203 # TODO: fix test so that parameter order doesn't matter 188 204 ret = ['%s.%s' % (d.lower(), p) 189 for d in self._model .info['partype']['pd-2d']205 for d in self._model_info['partype']['pd-2d'] 190 206 for p in ('npts', 'nsigmas', 'width')] 191 207 #print(ret) … … 261 277 # Check whether we have a list of ndarrays [qx,qy] 262 278 qx, qy = qdist 263 partype = self._model .info['partype']279 partype = self._model_info['partype'] 264 280 if not partype['orientation'] and not partype['magnetic']: 265 281 return self.calculate_Iq(np.sqrt(qx ** 2 + qy ** 2)) … … 284 300 to the card for each evaluation. 285 301 """ 302 if self._kernel is None: 303 self._kernel = core.build_model(self._model_info) 286 304 q_vectors = [np.asarray(q) for q in args] 287 fn = self._ model(q_vectors)305 fn = self._kernel(q_vectors) 288 306 pars = [self.params[v] for v in fn.fixed_pars] 289 307 pd_pars = [self._get_weights(p) for p in fn.pd_pars] … … 299 317 :return: the value of the effective radius 300 318 """ 301 ER = self._model .info.get('ER', None)319 ER = self._model_info.get('ER', None) 302 320 if ER is None: 303 321 return 1.0 … … 314 332 :return: the value of the volf ratio 315 333 """ 316 VR = self._model .info.get('VR', None)334 VR = self._model_info.get('VR', None) 317 335 if VR is None: 318 336 return 1.0 … … 358 376 parameter set in the vector. 359 377 """ 360 pars = self._model .info['partype']['volume']378 pars = self._model_info['partype']['volume'] 361 379 return core.dispersion_mesh([self._get_weights(p) for p in pars]) 362 380 … … 368 386 from . import weights 369 387 370 relative = self._model .info['partype']['pd-rel']371 limits = self._model .info['limits']388 relative = self._model_info['partype']['pd-rel'] 389 limits = self._model_info['limits'] 372 390 dis = self.dispersion[par] 373 391 value, weight = weights.get_weights( … … 375 393 self.params[par], limits[par], par in relative) 376 394 return value, weight / np.sum(weight) 395
Note: See TracChangeset
for help on using the changeset viewer.