Changeset c9e31e2 in sasmodels for sasmodels/sasview_model.py


Ignore:
Timestamp:
Mar 6, 2015 10:54:22 AM (9 years ago)
Author:
richardh
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.
Message:

Merge branch 'master' of https://github.com/SasView/sasmodels

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/sasview_model.py

    r0a82216 r3c56da87  
    2626try: 
    2727    from .kernelcl import load_model 
    28 except ImportError,exc: 
     28except ImportError, exc: 
    2929    warnings.warn(str(exc)) 
    3030    warnings.warn("using ctypes instead") 
     
    4141    will produce a class with a name compatible with SasView 
    4242    """ 
    43     model =  load_model(kernel_module, dtype=dtype) 
     43    model = load_model(kernel_module, dtype=dtype) 
    4444    def __init__(self, multfactor=1): 
    4545        SasviewModel.__init__(self, model) 
    4646    attrs = dict(__init__=__init__) 
    47     ConstructedModel = type(model.info[namestyle],  (SasviewModel,), attrs) 
     47    ConstructedModel = type(model.info[namestyle], (SasviewModel,), attrs) 
    4848    return ConstructedModel 
    4949 
     
    6969        self.dispersion = dict() 
    7070        partype = model.info['partype'] 
    71         for name,units,default,limits,ptype,description in model.info['parameters']: 
     71        for name, units, default, limits, _, _ in model.info['parameters']: 
    7272            self.params[name] = default 
    73             self.details[name] = [units]+limits 
     73            self.details[name] = [units] + limits 
    7474 
    7575        for name in partype['pd-2d']: 
     
    8383        self.orientation_params = ( 
    8484            partype['orientation'] 
    85             + [n+'.width' for n in partype['orientation']] 
     85            + [n + '.width' for n in partype['orientation']] 
    8686            + partype['magnetic']) 
    8787        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']] 
    8989        self.non_fittable = [] 
    9090 
    9191        ## 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}") 
    9696 
    9797        ## _persistency_dict is used by sas.perspectives.fitting.basepage 
     
    120120 
    121121 
     122    # pylint: disable=no-self-use 
    122123    def getProfile(self): 
    123124        """ 
     
    139140        # Look for dispersion parameters 
    140141        toks = name.split('.') 
    141         if len(toks)==2: 
     142        if len(toks) == 2: 
    142143            for item in self.dispersion.keys(): 
    143                 if item.lower()==toks[0].lower(): 
     144                if item.lower() == toks[0].lower(): 
    144145                    for par in self.dispersion[item]: 
    145146                        if par.lower() == toks[1].lower(): 
     
    149150            # Look for standard parameter 
    150151            for item in self.params.keys(): 
    151                 if item.lower()==name.lower(): 
     152                if item.lower() == name.lower(): 
    152153                    self.params[item] = value 
    153154                    return 
     
    164165        # Look for dispersion parameters 
    165166        toks = name.split('.') 
    166         if len(toks)==2: 
     167        if len(toks) == 2: 
    167168            for item in self.dispersion.keys(): 
    168                 if item.lower()==toks[0].lower(): 
     169                if item.lower() == toks[0].lower(): 
    169170                    for par in self.dispersion[item]: 
    170171                        if par.lower() == toks[1].lower(): 
     
    173174            # Look for standard parameter 
    174175            for item in self.params.keys(): 
    175                 if item.lower()==name.lower(): 
     176                if item.lower() == name.lower(): 
    176177                    return self.params[item] 
    177178 
     
    182183        Return a list of all available parameters for the model 
    183184        """ 
    184         list = self.params.keys() 
     185        param_list = self.params.keys() 
    185186        # WARNING: Extending the list with the dispersion parameters 
    186         list.extend(self.getDispParamList()) 
    187         return list 
     187        param_list.extend(self.getDispParamList()) 
     188        return param_list 
    188189 
    189190    def getDispParamList(self): 
     
    192193        """ 
    193194        # TODO: fix test so that parameter order doesn't matter 
    194         ret = ['%s.%s'%(d.lower(), p) 
     195        ret = ['%s.%s' % (d.lower(), p) 
    195196               for d in self._model.info['partype']['pd-2d'] 
    196197               for p in ('npts', 'nsigmas', 'width')] 
     
    212213        **DEPRECATED**: use calculate_Iq instead 
    213214        """ 
    214         if isinstance(x, (list,tuple)): 
     215        if isinstance(x, (list, tuple)): 
     216            # pylint: disable=unpacking-non-sequence 
    215217            q, phi = x 
    216218            return self.calculate_Iq([q * math.cos(phi)], 
     
    230232        **DEPRECATED**: use calculate_Iq instead 
    231233        """ 
    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] 
    234236        else: 
    235237            return self.calculate_Iq([float(x)])[0] 
     
    263265 
    264266 
    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)): 
    268271            # Check whether we have a list of ndarrays [qx,qy] 
    269272            qx, qy = qdist 
    270273            partype = self._model.info['partype'] 
    271274            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)) 
    273276            else: 
    274277                return self.calculate_Iq(qx, qy) 
     
    279282 
    280283        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)) 
    282286 
    283287    def calculate_Iq(self, *args): 
     
    313317            fv = ER(*values) 
    314318            #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) 
    316320 
    317321    def calculate_VR(self): 
     
    327331            vol_pars = self._model.info['partype']['volume'] 
    328332            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) 
    331335 
    332336    def set_dispersion(self, parameter, dispersion): 
     
    373377 
    374378    def _get_weights(self, par): 
     379        """ 
     380            Return dispersion weights 
     381            :param par parameter name 
     382        """ 
    375383        from . import weights 
    376384 
     
    378386        limits = self._model.info['limits'] 
    379387        dis = self.dispersion[par] 
    380         v,w = weights.get_weights( 
     388        value, weight = weights.get_weights( 
    381389            dis['type'], dis['npts'], dis['width'], dis['nsigmas'], 
    382390            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.