Changeset de0c4ba in sasmodels
- Timestamp:
- Mar 3, 2015 4:14:06 PM (10 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:
- 6c8db9e
- Parents:
- e930946
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/sasview_model.py
r0a82216 rde0c4ba 26 26 try: 27 27 from .kernelcl import load_model 28 except ImportError, exc:28 except ImportError, exc: 29 29 warnings.warn(str(exc)) 30 30 warnings.warn("using ctypes instead") … … 41 41 will produce a class with a name compatible with SasView 42 42 """ 43 model = 43 model = load_model(kernel_module, dtype=dtype) 44 44 def __init__(self, multfactor=1): 45 45 SasviewModel.__init__(self, model) 46 46 attrs = dict(__init__=__init__) 47 ConstructedModel = type(model.info[namestyle], 47 ConstructedModel = type(model.info[namestyle], (SasviewModel,), attrs) 48 48 return ConstructedModel 49 49 … … 69 69 self.dispersion = dict() 70 70 partype = model.info['partype'] 71 for name, units,default,limits,ptype,description in model.info['parameters']:71 for name, units, default, limits, ptype, description in model.info['parameters']: 72 72 self.params[name] = default 73 self.details[name] = [units] +limits73 self.details[name] = [units] + limits 74 74 75 75 for name in partype['pd-2d']: … … 83 83 self.orientation_params = ( 84 84 partype['orientation'] 85 + [n +'.width' for n in partype['orientation']]85 + [n + '.width' for n in partype['orientation']] 86 86 + partype['magnetic']) 87 87 self.magnetic_params = partype['magnetic'] 88 self.fixed = [n +'.width' for n in partype['pd-2d']]88 self.fixed = [n + '.width' for n in partype['pd-2d']] 89 89 self.non_fittable = [] 90 90 91 91 ## independent parameter name and unit [string] 92 self.input_name = model.info.get("input_name", "Q")93 self.input_unit = model.info.get("input_unit", "A^{-1}")94 self.output_name = model.info.get("output_name", "Intensity")95 self.output_unit = model.info.get("output_unit", "cm^{-1}")92 self.input_name = model.info.get("input_name", "Q") 93 self.input_unit = model.info.get("input_unit", "A^{-1}") 94 self.output_name = model.info.get("output_name", "Intensity") 95 self.output_unit = model.info.get("output_unit", "cm^{-1}") 96 96 97 97 ## _persistency_dict is used by sas.perspectives.fitting.basepage … … 139 139 # Look for dispersion parameters 140 140 toks = name.split('.') 141 if len(toks) ==2:141 if len(toks) == 2: 142 142 for item in self.dispersion.keys(): 143 if item.lower() ==toks[0].lower():143 if item.lower() == toks[0].lower(): 144 144 for par in self.dispersion[item]: 145 145 if par.lower() == toks[1].lower(): … … 149 149 # Look for standard parameter 150 150 for item in self.params.keys(): 151 if item.lower() ==name.lower():151 if item.lower() == name.lower(): 152 152 self.params[item] = value 153 153 return … … 164 164 # Look for dispersion parameters 165 165 toks = name.split('.') 166 if len(toks) ==2:166 if len(toks) == 2: 167 167 for item in self.dispersion.keys(): 168 if item.lower() ==toks[0].lower():168 if item.lower() == toks[0].lower(): 169 169 for par in self.dispersion[item]: 170 170 if par.lower() == toks[1].lower(): … … 173 173 # Look for standard parameter 174 174 for item in self.params.keys(): 175 if item.lower() ==name.lower():175 if item.lower() == name.lower(): 176 176 return self.params[item] 177 177 … … 182 182 Return a list of all available parameters for the model 183 183 """ 184 list = self.params.keys()184 param_list = self.params.keys() 185 185 # WARNING: Extending the list with the dispersion parameters 186 list.extend(self.getDispParamList())187 return list186 param_list.extend(self.getDispParamList()) 187 return param_list 188 188 189 189 def getDispParamList(self): … … 192 192 """ 193 193 # TODO: fix test so that parameter order doesn't matter 194 ret = ['%s.%s' %(d.lower(), p)194 ret = ['%s.%s' % (d.lower(), p) 195 195 for d in self._model.info['partype']['pd-2d'] 196 196 for p in ('npts', 'nsigmas', 'width')] … … 212 212 **DEPRECATED**: use calculate_Iq instead 213 213 """ 214 if isinstance(x, (list, tuple)):214 if isinstance(x, (list, tuple)): 215 215 q, phi = x 216 216 return self.calculate_Iq([q * math.cos(phi)], … … 230 230 **DEPRECATED**: use calculate_Iq instead 231 231 """ 232 if isinstance(x, (list, tuple)):233 return self.calculate_Iq([float(x[0])], [float(x[1])])[0]232 if isinstance(x, (list, tuple)): 233 return self.calculate_Iq([float(x[0])], [float(x[1])])[0] 234 234 else: 235 235 return self.calculate_Iq([float(x)])[0] … … 265 265 :param qdist: ndarray of scalar q-values or list [qx,qy] where qx,qy are 1D ndarrays 266 266 """ 267 if isinstance(qdist, (list, tuple)):267 if isinstance(qdist, (list, tuple)): 268 268 # Check whether we have a list of ndarrays [qx,qy] 269 269 qx, qy = qdist 270 270 partype = self._model.info['partype'] 271 271 if not partype['orientation'] and not partype['magnetic']: 272 return self.calculate_Iq(np.sqrt(qx **2+qy**2))272 return self.calculate_Iq(np.sqrt(qx ** 2 + qy ** 2)) 273 273 else: 274 274 return self.calculate_Iq(qx, qy) … … 279 279 280 280 else: 281 raise TypeError("evalDistribution expects q or [qx, qy], not %r" %type(qdist))281 raise TypeError("evalDistribution expects q or [qx, qy], not %r" % type(qdist)) 282 282 283 283 def calculate_Iq(self, *args): … … 313 313 fv = ER(*values) 314 314 #print values[0].shape, weights.shape, fv.shape 315 return np.sum(weights *fv) / np.sum(weights)315 return np.sum(weights * fv) / np.sum(weights) 316 316 317 317 def calculate_VR(self): … … 327 327 vol_pars = self._model.info['partype']['volume'] 328 328 values, weights = self._dispersion_mesh(vol_pars) 329 whole, part = VR(*values)330 return np.sum(weights *part)/np.sum(weights*whole)329 whole, part = VR(*values) 330 return np.sum(weights * part) / np.sum(weights * whole) 331 331 332 332 def set_dispersion(self, parameter, dispersion): … … 373 373 374 374 def _get_weights(self, par): 375 """ 376 Return dispersion weights 377 :param par parameter name 378 """ 375 379 from . import weights 376 380 … … 378 382 limits = self._model.info['limits'] 379 383 dis = self.dispersion[par] 380 v, w = weights.get_weights(384 v, w = weights.get_weights( 381 385 dis['type'], dis['npts'], dis['width'], dis['nsigmas'], 382 386 self.params[par], limits[par], par in relative) 383 return v, w/w.max()384 387 return v, w / w.max() 388
Note: See TracChangeset
for help on using the changeset viewer.