Changeset c9e31e2 in sasmodels for sasmodels/sasview_model.py
- Timestamp:
- Mar 6, 2015 10:54:22 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:
- 9f6f2f8, ab87a12
- Parents:
- d60b433 (diff), 3c56da87 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/sasview_model.py
r0a82216 r3c56da87 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,descriptionin model.info['parameters']:71 for name, units, default, limits, _, _ 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 … … 120 120 121 121 122 # pylint: disable=no-self-use 122 123 def getProfile(self): 123 124 """ … … 139 140 # Look for dispersion parameters 140 141 toks = name.split('.') 141 if len(toks) ==2:142 if len(toks) == 2: 142 143 for item in self.dispersion.keys(): 143 if item.lower() ==toks[0].lower():144 if item.lower() == toks[0].lower(): 144 145 for par in self.dispersion[item]: 145 146 if par.lower() == toks[1].lower(): … … 149 150 # Look for standard parameter 150 151 for item in self.params.keys(): 151 if item.lower() ==name.lower():152 if item.lower() == name.lower(): 152 153 self.params[item] = value 153 154 return … … 164 165 # Look for dispersion parameters 165 166 toks = name.split('.') 166 if len(toks) ==2:167 if len(toks) == 2: 167 168 for item in self.dispersion.keys(): 168 if item.lower() ==toks[0].lower():169 if item.lower() == toks[0].lower(): 169 170 for par in self.dispersion[item]: 170 171 if par.lower() == toks[1].lower(): … … 173 174 # Look for standard parameter 174 175 for item in self.params.keys(): 175 if item.lower() ==name.lower():176 if item.lower() == name.lower(): 176 177 return self.params[item] 177 178 … … 182 183 Return a list of all available parameters for the model 183 184 """ 184 list = self.params.keys()185 param_list = self.params.keys() 185 186 # WARNING: Extending the list with the dispersion parameters 186 list.extend(self.getDispParamList())187 return list187 param_list.extend(self.getDispParamList()) 188 return param_list 188 189 189 190 def getDispParamList(self): … … 192 193 """ 193 194 # TODO: fix test so that parameter order doesn't matter 194 ret = ['%s.%s' %(d.lower(), p)195 ret = ['%s.%s' % (d.lower(), p) 195 196 for d in self._model.info['partype']['pd-2d'] 196 197 for p in ('npts', 'nsigmas', 'width')] … … 212 213 **DEPRECATED**: use calculate_Iq instead 213 214 """ 214 if isinstance(x, (list,tuple)): 215 if isinstance(x, (list, tuple)): 216 # pylint: disable=unpacking-non-sequence 215 217 q, phi = x 216 218 return self.calculate_Iq([q * math.cos(phi)], … … 230 232 **DEPRECATED**: use calculate_Iq instead 231 233 """ 232 if isinstance(x, (list, tuple)):233 return self.calculate_Iq([float(x[0])], [float(x[1])])[0]234 if isinstance(x, (list, tuple)): 235 return self.calculate_Iq([float(x[0])], [float(x[1])])[0] 234 236 else: 235 237 return self.calculate_Iq([float(x)])[0] … … 263 265 264 266 265 :param qdist: ndarray of scalar q-values or list [qx,qy] where qx,qy are 1D ndarrays 266 """ 267 if isinstance(qdist, (list,tuple)): 267 :param qdist: ndarray of scalar q-values or list [qx,qy] 268 where qx,qy are 1D ndarrays 269 """ 270 if isinstance(qdist, (list, tuple)): 268 271 # Check whether we have a list of ndarrays [qx,qy] 269 272 qx, qy = qdist 270 273 partype = self._model.info['partype'] 271 274 if not partype['orientation'] and not partype['magnetic']: 272 return self.calculate_Iq(np.sqrt(qx **2+qy**2))275 return self.calculate_Iq(np.sqrt(qx ** 2 + qy ** 2)) 273 276 else: 274 277 return self.calculate_Iq(qx, qy) … … 279 282 280 283 else: 281 raise TypeError("evalDistribution expects q or [qx, qy], not %r"%type(qdist)) 284 raise TypeError("evalDistribution expects q or [qx, qy], not %r" 285 % type(qdist)) 282 286 283 287 def calculate_Iq(self, *args): … … 313 317 fv = ER(*values) 314 318 #print values[0].shape, weights.shape, fv.shape 315 return np.sum(weights *fv) / np.sum(weights)319 return np.sum(weights * fv) / np.sum(weights) 316 320 317 321 def calculate_VR(self): … … 327 331 vol_pars = self._model.info['partype']['volume'] 328 332 values, weights = self._dispersion_mesh(vol_pars) 329 whole, part = VR(*values)330 return np.sum(weights *part)/np.sum(weights*whole)333 whole, part = VR(*values) 334 return np.sum(weights * part) / np.sum(weights * whole) 331 335 332 336 def set_dispersion(self, parameter, dispersion): … … 373 377 374 378 def _get_weights(self, par): 379 """ 380 Return dispersion weights 381 :param par parameter name 382 """ 375 383 from . import weights 376 384 … … 378 386 limits = self._model.info['limits'] 379 387 dis = self.dispersion[par] 380 v ,w= weights.get_weights(388 value, weight = weights.get_weights( 381 389 dis['type'], dis['npts'], dis['width'], dis['nsigmas'], 382 390 self.params[par], limits[par], par in relative) 383 return v ,w/w.max()384 391 return value, weight / np.sum(weight) 392
Note: See TracChangeset
for help on using the changeset viewer.