Changeset 823e620 in sasmodels


Ignore:
Timestamp:
Jan 29, 2016 8:46:54 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
eafc9fa
Parents:
803f835
Message:

delint

Files:
13 edited

Legend:

Unmodified
Added
Removed
  • extra/pylint.rc

    r803f835 r823e620  
    1010 
    1111# Profiled execution. 
    12 profile=no 
     12#profile=no 
    1313 
    1414# Add files or directories to the blacklist. They should be base names, not 
     
    9292# Add a comment according to your evaluation note. This is used by the global 
    9393# evaluation report (RP0004). 
    94 comment=no 
     94#comment=no 
    9595 
    9696# Template used to display messages. This is a python new-style format string 
     
    101101 
    102102# Required attributes for module, separated by a comma 
    103 required-attributes= 
     103#required-attributes= 
    104104 
    105105# List of builtins function names that should not be used, separated by a comma 
     
    280280# (useful for modules/projects where namespaces are manipulated during runtime 
    281281# and thus existing member attributes cannot be deduced by static analysis 
    282 ignored-modules=numpy,np 
     282ignored-modules=numpy,np,numpy.random, 
     283    bumps,sas, 
    283284 
    284285# List of classes names for which member attributes should not be checked 
     
    288289# When zope mode is activated, add a predefined set of Zope acquired attributes 
    289290# to generated-members. 
    290 zope=no 
     291#zope=no 
    291292 
    292293# List of members which are set dynamically and missed by pylint inference 
     
    318319# List of interface methods to ignore, separated by a comma. This is used for 
    319320# instance to not check methods defines in Zope's Interface base class. 
    320 ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by 
     321#ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by 
    321322 
    322323# List of method names used to declare (i.e. assign) instance attributes. 
  • extra/pylint_numpy.py

    r63b32bb r823e620  
    88    #print("processing",module.name) 
    99    if module.name.startswith('numpy'): 
    10         if module.name == 'numpy':  import numpy 
    11         elif module.name == 'numpy.random': import numpy.random 
     10        if module.name == 'numpy': 
     11            import numpy 
     12        elif module.name == 'numpy.random': 
     13            import numpy.random 
     14            from numpy.random import seed, get_state, set_state 
    1215 
  • extra/pylint_pyopencl.py

    r3c56da87 r823e620  
    99    if module.name == 'pyopencl': 
    1010        import pyopencl 
     11        import pyopencl as cl 
  • extra/run-pylint.py

    rf01e53d r823e620  
    66 
    77def main(): 
     8    extra = abspath(dirname(__file__)) 
     9    root = abspath(joinpath(extra, '..')) 
     10 
    811    envpath = os.environ.get('PYTHONPATH',None) 
    912    path = [envpath] if envpath else [] 
    10     path.append(abspath(dirname(__file__))) # so we can find the plugins 
     13    path.append(extra) 
     14 
     15    #bumps = abspath(joinpath(root, "..", "bumps")) 
     16    #periodictable = abspath(joinpath(root, "..", "periodictable")) 
     17    #sasview = abspath(joinpath(root, "..", "sasview", "src")) 
     18    #path.extend((bumps, periodictable, sasview)) 
     19 
    1120    os.environ['PYTHONPATH'] = ':'.join(path) 
    12     root = abspath(joinpath(dirname(__file__), '..')) 
     21 
     22    # Run the lint command 
     23    cmd = "pylint --rcfile extra/pylint.rc -f parseable sasmodels" 
    1324    os.chdir(root) 
    14     cmd = "pylint --rcfile extra/pylint.rc -f parseable sasmodels" 
    1525    status = os.system(cmd) 
    1626    sys.exit(status) 
  • sasmodels/exception.py

    reaca9eb r823e620  
    88except NameError: 
    99    class WindowsError(Exception): 
     10        """ 
     11        Fake WindowsException when not on Windows. 
     12        """ 
    1013        pass 
    1114 
     
    3134    # TODO: try to incorporate current stack trace in the raised exception 
    3235    if isinstance(exc, WindowsError): 
    33         raise OSError(str(exc)+" "+msg) 
     36        raise OSError(str(exc) + " " + msg) 
    3437 
    3538    args = exc.args 
     
    3841    else: 
    3942        try: 
    40             arg0 = " ".join((args[0],msg)) 
     43            arg0 = " ".join((args[0], msg)) 
    4144            exc.args = tuple([arg0] + list(args[1:])) 
    4245        except: 
    43             exc.args = (" ".join((str(exc),msg)),) 
     46            exc.args = (" ".join((str(exc), msg)),) 
  • sasmodels/generate.py

    r190fc2b r823e620  
    77    particular dimensions averaged over all orientations. 
    88 
    9     *Iqxy(qx, qy, p1, p2, ...)* returns the scattering at qx,qy for a form 
     9    *Iqxy(qx, qy, p1, p2, ...)* returns the scattering at qx, qy for a form 
    1010    with particular dimensions for a single orientation. 
    1111 
     
    4747the *sin* and *cos* values are needed for a particular argument.  Since 
    4848this function does not exist in C99, all use of *sincos* should be 
    49 replaced by the macro *SINCOS(value,sn,cn)* where *sn* and *cn* are 
     49replaced by the macro *SINCOS(value, sn, cn)* where *sn* and *cn* are 
    5050previously declared *double* variables.  When compiled for systems without 
    5151OpenCL, *SINCOS* will be replaced by *sin* and *cos* calls.   If *value* is 
     
    194194returns a list of files required by the model. 
    195195""" 
     196from __future__ import print_function 
    196197 
    197198# TODO: identify model files which have changed since loading and reload them. 
     
    372373 
    373374 
    374 def kernel_name(info, is_2D): 
     375def kernel_name(info, is_2d): 
    375376    """ 
    376377    Name of the exported kernel symbol. 
    377378    """ 
    378     return info['name'] + "_" + ("Iqxy" if is_2D else "Iq") 
     379    return info['name'] + "_" + ("Iqxy" if is_2d else "Iq") 
    379380 
    380381 
     
    419420 
    420421 
    421 def build_polydispersity_loops(pd_pars): 
    422     """ 
    423     Build polydispersity loops 
    424  
    425     Returns loop opening and loop closing 
    426     """ 
    427     LOOP_OPEN = """\ 
     422LOOP_OPEN = """\ 
    428423for (int %(name)s_i=0; %(name)s_i < N%(name)s; %(name)s_i++) { 
    429424  const double %(name)s = loops[2*(%(name)s_i%(offset)s)]; 
    430425  const double %(name)s_w = loops[2*(%(name)s_i%(offset)s)+1];\ 
    431426""" 
     427def build_polydispersity_loops(pd_pars): 
     428    """ 
     429    Build polydispersity loops 
     430 
     431    Returns loop opening and loop closing 
     432    """ 
    432433    depth = 4 
    433434    offset = "" 
     
    572573 
    573574    #for d in defines: print(d) 
    574     DEFINES = '\n'.join('#define %s %s' % (k, v) for k, v in defines) 
    575     SOURCES = '\n\n'.join(source) 
     575    defines = '\n'.join('#define %s %s' % (k, v) for k, v in defines) 
     576    sources = '\n\n'.join(source) 
    576577    return C_KERNEL_TEMPLATE % { 
    577         'DEFINES':DEFINES, 
    578         'SOURCES':SOURCES, 
     578        'DEFINES': defines, 
     579        'SOURCES': sources, 
    579580        } 
    580581 
     
    590591    demo_parameters = getattr(kernel_module, 'demo', None) 
    591592    if demo_parameters is None: 
    592         demo_parameters = dict((p[0],p[2]) for p in parameters) 
     593        demo_parameters = dict((p[0], p[2]) for p in parameters) 
    593594    filename = abspath(kernel_module.__file__) 
    594595    kernel_id = splitext(basename(filename))[0] 
     
    597598        name = " ".join(w.capitalize() for w in kernel_id.split('_')) 
    598599    info = dict( 
    599         id = kernel_id,  # string used to load the kernel 
     600        id=kernel_id,  # string used to load the kernel 
    600601        filename=abspath(kernel_module.__file__), 
    601602        name=name, 
     
    643644        elif section_marker.match(line): 
    644645            if len(line) >= len(prior): 
    645                 yield "".join( ("**",prior,"**") ) 
     646                yield "".join(("**", prior, "**")) 
    646647                prior = None 
    647648            else: 
  • sasmodels/kernelcl.py

    rcde11f0f r823e620  
    241241        self.info = info 
    242242        self.source = source 
    243         self.dtype = generate.F32 if dtype=='fast' else np.dtype(dtype) 
     243        self.dtype = generate.F32 if dtype == 'fast' else np.dtype(dtype) 
    244244        self.fast = (dtype == 'fast') 
    245245        self.program = None # delay program creation 
  • sasmodels/kerneldll.py

    r74667d3 r823e620  
    122122    models are allowed as DLLs. 
    123123    """ 
    124     if callable(info.get('Iq',None)): 
     124    if callable(info.get('Iq', None)): 
    125125        return PyModel(info) 
    126126 
     
    140140    source = generate.convert_type(source, dtype) 
    141141    source_files = generate.sources(info) + [info['filename']] 
    142     dll= dll_path(info, dtype) 
     142    dll = dll_path(info, dtype) 
    143143    newest = max(os.path.getmtime(f) for f in source_files) 
    144     if not os.path.exists(dll) or os.path.getmtime(dll)<newest: 
     144    if not os.path.exists(dll) or os.path.getmtime(dll) < newest: 
    145145        # Replace with a proper temp file 
    146         fid, filename = tempfile.mkstemp(suffix=".c",prefix=tempfile_prefix) 
    147         os.fdopen(fid,"w").write(source) 
     146        fid, filename = tempfile.mkstemp(suffix=".c", prefix=tempfile_prefix) 
     147        os.fdopen(fid, "w").write(source) 
    148148        command = COMPILE%{"source":filename, "output":dll} 
    149149        print("Compile command: "+command) 
     
    160160def load_dll(source, info, dtype="double"): 
    161161    """ 
    162     Create and load a dll corresponding to the source,info pair returned 
     162    Create and load a dll corresponding to the source, info pair returned 
    163163    from :func:`sasmodels.generate.make` compiled for the target precision. 
    164164 
     
    199199        Npd2d = len(self.info['partype']['pd-2d']) 
    200200 
    201         #print("dll",self.dllpath) 
     201        #print("dll", self.dllpath) 
    202202        try: 
    203203            self.dll = ct.CDLL(self.dllpath) 
     
    210210              else c_longdouble) 
    211211        pd_args_1d = [c_void_p, fp] + [c_int]*Npd1d if Npd1d else [] 
    212         pd_args_2d= [c_void_p, fp] + [c_int]*Npd2d if Npd2d else [] 
     212        pd_args_2d = [c_void_p, fp] + [c_int]*Npd2d if Npd2d else [] 
    213213        self.Iq = self.dll[generate.kernel_name(self.info, False)] 
    214214        self.Iq.argtypes = IQ_ARGS + pd_args_1d + [fp]*Nfixed1d 
     
    257257 
    258258    The resulting call method takes the *pars*, a list of values for 
    259     the fixed parameters to the kernel, and *pd_pars*, a list of (value,weight) 
     259    the fixed parameters to the kernel, and *pd_pars*, a list of (value, weight) 
    260260    vectors for the polydisperse parameters.  *cutoff* determines the 
    261261    integration limits: any points with combined weight less than *cutoff* 
  • sasmodels/list_pars.py

    r1d4017a r823e620  
    3131        print(columnize(list(sorted(partable.keys())))) 
    3232    else: 
    33         for k,v in sorted(partable.items()): 
     33        for k, v in sorted(partable.items()): 
    3434            print("%s: %s"%(k, ", ".join(v))) 
    3535 
  • sasmodels/model_test.py

    r9404dd3 r823e620  
    99    if model1 is 'all', then all except the remaining models will be tested 
    1010 
    11 Each model is tested using the default parameters at q=0.1, (qx,qy)=(0.1,0.1), 
     11Each model is tested using the default parameters at q=0.1, (qx, qy)=(0.1, 0.1), 
    1212and the ER and VR are computed.  The return values at these points are not 
    1313considered.  The test is only to verify that the models run to completion, 
     
    3030        [ {parameters}, (qx, qy), I(qx, Iqy)], 
    3131        [ {parameters}, [(qx1, qy1), (qx2, qy2), ...], 
    32                         [I(qx1,qy1), I(qx2,qy2), ...]], 
     32                        [I(qx1, qy1), I(qx2, qy2), ...]], 
    3333 
    3434        [ {parameters}, 'ER', ER(pars) ], 
     
    7575        # don't try to call cl kernel since it will not be 
    7676        # available in some environmentes. 
    77         is_py = callable(getattr(model_definition,'Iq', None)) 
     77        is_py = callable(getattr(model_definition, 'Iq', None)) 
    7878 
    7979        if is_py:  # kernel implemented in python 
     
    123123        def _runTest(self): 
    124124            smoke_tests = [ 
    125                 [{},0.1,None], 
    126                 [{},(0.1,0.1),None], 
    127                 [{},'ER',None], 
    128                 [{},'VR',None], 
     125                [{}, 0.1, None], 
     126                [{}, (0.1, 0.1), None], 
     127                [{}, 'ER', None], 
     128                [{}, 'VR', None], 
    129129                ] 
    130130 
     
    163163                actual = [call_VR(model.info, pars)] 
    164164            elif isinstance(x[0], tuple): 
    165                 Qx,Qy = zip(*x) 
     165                Qx, Qy = zip(*x) 
    166166                q_vectors = [np.array(Qx), np.array(Qy)] 
    167167                kernel = make_kernel(model, q_vectors) 
     
    179179                    # smoke test --- make sure it runs and produces a value 
    180180                    self.assertTrue(np.isfinite(actual_yi), 
    181                         'invalid f(%s): %s' % (xi, actual_yi)) 
     181                                    'invalid f(%s): %s' % (xi, actual_yi)) 
    182182                else: 
    183183                    err = abs(yi - actual_yi) 
    184184                    nrm = abs(yi) 
    185185                    self.assertLess(err * 10**5, nrm, 
    186                         'f(%s); expected:%s; actual:%s' % (xi, yi, actual_yi)) 
     186                                    'f(%s); expected:%s; actual:%s' 
     187                                    % (xi, yi, actual_yi)) 
    187188 
    188189    return ModelTestCase 
     
    237238    Run "nosetests sasmodels" on the command line to invoke it. 
    238239    """ 
    239     tests = make_suite(['opencl','dll'],['all']) 
     240    tests = make_suite(['opencl', 'dll'], ['all']) 
    240241    for test_i in tests: 
    241242        yield test_i._runTest 
  • sasmodels/resolution.py

    r190fc2b r823e620  
    1414           "pinhole_extend_q", "slit_extend_q", "bin_edges", 
    1515           "interpolate", "linear_extrapolation", "geometric_extrapolation", 
    16            ] 
     16          ] 
    1717 
    1818MINIMUM_RESOLUTION = 1e-8 
     
    8080        # default to Perfect1D if the pinhole geometry is not defined. 
    8181        self.q, self.q_width = q, q_width 
    82         self.q_calc = pinhole_extend_q(q, q_width, nsigma=nsigma) \ 
    83             if q_calc is None else np.sort(q_calc) 
    84         self.weight_matrix = pinhole_resolution(self.q_calc, 
    85                 self.q, np.maximum(q_width, MINIMUM_RESOLUTION)) 
     82        self.q_calc = (pinhole_extend_q(q, q_width, nsigma=nsigma) 
     83                       if q_calc is None else np.sort(q_calc)) 
     84        self.weight_matrix = pinhole_resolution( 
     85            self.q_calc, self.q, np.maximum(q_width, MINIMUM_RESOLUTION)) 
    8686 
    8787    def apply(self, theory): 
  • sasmodels/resolution2d.py

    r841753c r823e620  
    143143        if self.coords == 'polar': 
    144144            q_r = sqrt(qx**2 + qy**2) 
    145             qx_res = ((dqx*cos(dphi) + q_r) * cos(-q_phi) + 
    146                           dqy*sin(dphi) * sin(-q_phi)) 
    147             qy_res = (-(dqx*cos(dphi) + q_r) * sin(-q_phi) + 
    148                           dqy*sin(dphi) * cos(-q_phi)) 
     145            qx_res = ((dqx*cos(dphi) + q_r) * cos(-q_phi) 
     146                      + dqy*sin(dphi) * sin(-q_phi)) 
     147            qy_res = (-(dqx*cos(dphi) + q_r) * sin(-q_phi) 
     148                      + dqy*sin(dphi) * cos(-q_phi)) 
    149149        else: 
    150             qx_res = qx +  dqx*cos(dphi) 
    151             qy_res = qy +  dqy*sin(dphi) 
     150            qx_res = qx + dqx*cos(dphi) 
     151            qy_res = qy + dqy*sin(dphi) 
    152152 
    153153 
     
    162162            theory = np.reshape(theory, (nbins, nq)) 
    163163            ## Averaging with Gaussian weighting: normalization included. 
    164             value =np.average(theory, axis=0, weights=self.q_calc_weights) 
     164            value = np.average(theory, axis=0, weights=self.q_calc_weights) 
    165165            ## Return the smeared values in the range of self.index 
    166166            return value 
  • sasmodels/weights.py

    r3c56da87 r823e620  
    3636        *center* is the center of the distribution 
    3737 
    38         *lb*,*ub* are the min and max allowed values 
     38        *lb*, *ub* are the min and max allowed values 
    3939 
    4040        *relative* is True if the distribution width is proportional to the 
     
    8484    default = dict(npts=80, width=0, nsigmas=8) 
    8585    def _weights(self, center, sigma, lb, ub): 
    86         x = self._linspace(center, sigma, max(lb,1e-8), max(ub,1e-8)) 
     86        x = self._linspace(center, sigma, max(lb, 1e-8), max(ub, 1e-8)) 
    8787        px = np.exp(-0.5*(np.log(x)-center)**2)/sigma**2/(x*sigma) 
    8888        return x, px 
     
    9393    default = dict(npts=80, width=0, nsigmas=8) 
    9494    def _weights(self, center, sigma, lb, ub): 
    95         x = self._linspace(center, sigma, max(lb,1e-8), max(ub,1e-8)) 
    96         R= x/center 
     95        x = self._linspace(center, sigma, max(lb, 1e-8), max(ub, 1e-8)) 
     96        R = x/center 
    9797        z = (center/sigma)**2 
    9898        arg = z*np.log(z) + (z-1)*np.log(R) - R*z - np.log(center) - gammaln(z) 
     
    117117        # TODO: interpolate into the array dispersion using npts 
    118118        x = center + self.values*sigma 
    119         idx = (x>=lb)&(x<=ub) 
     119        idx = (x >= lb) & (x <= ub) 
    120120        x = x[idx] 
    121121        px = self.weights[idx] 
     
    124124 
    125125# dispersion name -> disperser lookup table. 
    126 models = dict((d.type,d) for d in ( 
     126models = dict((d.type, d) for d in ( 
    127127    GaussianDispersion, RectangleDispersion, 
    128128    ArrayDispersion, SchulzDispersion, LogNormalDispersion 
     
    149149    of the parameter, and false if it is an absolute width. 
    150150 
    151     Returns *(value,weight)*, where *value* and *weight* are vectors. 
     151    Returns *(value, weight)*, where *value* and *weight* are vectors. 
    152152    """ 
    153153    cls = models[disperser] 
    154154    obj = cls(n, width, nsigmas) 
    155     v,w = obj.get_weights(value, limits[0], limits[1], relative) 
    156     return v,w 
     155    v, w = obj.get_weights(value, limits[0], limits[1], relative) 
     156    return v, w 
    157157 
    158158# Hack to allow sasview dispersion objects to interoperate with sasmodels 
    159 dispersers = dict((v.__name__,k) for k,v in models.items()) 
     159dispersers = dict((v.__name__, k) for k, v in models.items()) 
    160160dispersers['DispersionModel'] = RectangleDispersion.type 
    161161 
Note: See TracChangeset for help on using the changeset viewer.