Changeset 823e620 in sasmodels
- Timestamp:
- Jan 29, 2016 8:46:54 PM (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:
- eafc9fa
- Parents:
- 803f835
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
extra/pylint.rc
r803f835 r823e620 10 10 11 11 # Profiled execution. 12 profile=no12 #profile=no 13 13 14 14 # Add files or directories to the blacklist. They should be base names, not … … 92 92 # Add a comment according to your evaluation note. This is used by the global 93 93 # evaluation report (RP0004). 94 comment=no94 #comment=no 95 95 96 96 # Template used to display messages. This is a python new-style format string … … 101 101 102 102 # Required attributes for module, separated by a comma 103 required-attributes=103 #required-attributes= 104 104 105 105 # List of builtins function names that should not be used, separated by a comma … … 280 280 # (useful for modules/projects where namespaces are manipulated during runtime 281 281 # and thus existing member attributes cannot be deduced by static analysis 282 ignored-modules=numpy,np 282 ignored-modules=numpy,np,numpy.random, 283 bumps,sas, 283 284 284 285 # List of classes names for which member attributes should not be checked … … 288 289 # When zope mode is activated, add a predefined set of Zope acquired attributes 289 290 # to generated-members. 290 zope=no291 #zope=no 291 292 292 293 # List of members which are set dynamically and missed by pylint inference … … 318 319 # List of interface methods to ignore, separated by a comma. This is used for 319 320 # 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_by321 #ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by 321 322 322 323 # List of method names used to declare (i.e. assign) instance attributes. -
extra/pylint_numpy.py
r63b32bb r823e620 8 8 #print("processing",module.name) 9 9 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 12 15 -
extra/pylint_pyopencl.py
r3c56da87 r823e620 9 9 if module.name == 'pyopencl': 10 10 import pyopencl 11 import pyopencl as cl -
extra/run-pylint.py
rf01e53d r823e620 6 6 7 7 def main(): 8 extra = abspath(dirname(__file__)) 9 root = abspath(joinpath(extra, '..')) 10 8 11 envpath = os.environ.get('PYTHONPATH',None) 9 12 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 11 20 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" 13 24 os.chdir(root) 14 cmd = "pylint --rcfile extra/pylint.rc -f parseable sasmodels"15 25 status = os.system(cmd) 16 26 sys.exit(status) -
sasmodels/exception.py
reaca9eb r823e620 8 8 except NameError: 9 9 class WindowsError(Exception): 10 """ 11 Fake WindowsException when not on Windows. 12 """ 10 13 pass 11 14 … … 31 34 # TODO: try to incorporate current stack trace in the raised exception 32 35 if isinstance(exc, WindowsError): 33 raise OSError(str(exc) +" "+msg)36 raise OSError(str(exc) + " " + msg) 34 37 35 38 args = exc.args … … 38 41 else: 39 42 try: 40 arg0 = " ".join((args[0], msg))43 arg0 = " ".join((args[0], msg)) 41 44 exc.args = tuple([arg0] + list(args[1:])) 42 45 except: 43 exc.args = (" ".join((str(exc), msg)),)46 exc.args = (" ".join((str(exc), msg)),) -
sasmodels/generate.py
r190fc2b r823e620 7 7 particular dimensions averaged over all orientations. 8 8 9 *Iqxy(qx, qy, p1, p2, ...)* returns the scattering at qx, qy for a form9 *Iqxy(qx, qy, p1, p2, ...)* returns the scattering at qx, qy for a form 10 10 with particular dimensions for a single orientation. 11 11 … … 47 47 the *sin* and *cos* values are needed for a particular argument. Since 48 48 this 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* are49 replaced by the macro *SINCOS(value, sn, cn)* where *sn* and *cn* are 50 50 previously declared *double* variables. When compiled for systems without 51 51 OpenCL, *SINCOS* will be replaced by *sin* and *cos* calls. If *value* is … … 194 194 returns a list of files required by the model. 195 195 """ 196 from __future__ import print_function 196 197 197 198 # TODO: identify model files which have changed since loading and reload them. … … 372 373 373 374 374 def kernel_name(info, is_2 D):375 def kernel_name(info, is_2d): 375 376 """ 376 377 Name of the exported kernel symbol. 377 378 """ 378 return info['name'] + "_" + ("Iqxy" if is_2 Delse "Iq")379 return info['name'] + "_" + ("Iqxy" if is_2d else "Iq") 379 380 380 381 … … 419 420 420 421 421 def build_polydispersity_loops(pd_pars): 422 """ 423 Build polydispersity loops 424 425 Returns loop opening and loop closing 426 """ 427 LOOP_OPEN = """\ 422 LOOP_OPEN = """\ 428 423 for (int %(name)s_i=0; %(name)s_i < N%(name)s; %(name)s_i++) { 429 424 const double %(name)s = loops[2*(%(name)s_i%(offset)s)]; 430 425 const double %(name)s_w = loops[2*(%(name)s_i%(offset)s)+1];\ 431 426 """ 427 def build_polydispersity_loops(pd_pars): 428 """ 429 Build polydispersity loops 430 431 Returns loop opening and loop closing 432 """ 432 433 depth = 4 433 434 offset = "" … … 572 573 573 574 #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) 576 577 return C_KERNEL_TEMPLATE % { 577 'DEFINES': DEFINES,578 'SOURCES': SOURCES,578 'DEFINES': defines, 579 'SOURCES': sources, 579 580 } 580 581 … … 590 591 demo_parameters = getattr(kernel_module, 'demo', None) 591 592 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) 593 594 filename = abspath(kernel_module.__file__) 594 595 kernel_id = splitext(basename(filename))[0] … … 597 598 name = " ".join(w.capitalize() for w in kernel_id.split('_')) 598 599 info = dict( 599 id =kernel_id, # string used to load the kernel600 id=kernel_id, # string used to load the kernel 600 601 filename=abspath(kernel_module.__file__), 601 602 name=name, … … 643 644 elif section_marker.match(line): 644 645 if len(line) >= len(prior): 645 yield "".join( ("**",prior,"**"))646 yield "".join(("**", prior, "**")) 646 647 prior = None 647 648 else: -
sasmodels/kernelcl.py
rcde11f0f r823e620 241 241 self.info = info 242 242 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) 244 244 self.fast = (dtype == 'fast') 245 245 self.program = None # delay program creation -
sasmodels/kerneldll.py
r74667d3 r823e620 122 122 models are allowed as DLLs. 123 123 """ 124 if callable(info.get('Iq', None)):124 if callable(info.get('Iq', None)): 125 125 return PyModel(info) 126 126 … … 140 140 source = generate.convert_type(source, dtype) 141 141 source_files = generate.sources(info) + [info['filename']] 142 dll = dll_path(info, dtype)142 dll = dll_path(info, dtype) 143 143 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: 145 145 # 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) 148 148 command = COMPILE%{"source":filename, "output":dll} 149 149 print("Compile command: "+command) … … 160 160 def load_dll(source, info, dtype="double"): 161 161 """ 162 Create and load a dll corresponding to the source, info pair returned162 Create and load a dll corresponding to the source, info pair returned 163 163 from :func:`sasmodels.generate.make` compiled for the target precision. 164 164 … … 199 199 Npd2d = len(self.info['partype']['pd-2d']) 200 200 201 #print("dll", self.dllpath)201 #print("dll", self.dllpath) 202 202 try: 203 203 self.dll = ct.CDLL(self.dllpath) … … 210 210 else c_longdouble) 211 211 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 [] 213 213 self.Iq = self.dll[generate.kernel_name(self.info, False)] 214 214 self.Iq.argtypes = IQ_ARGS + pd_args_1d + [fp]*Nfixed1d … … 257 257 258 258 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) 260 260 vectors for the polydisperse parameters. *cutoff* determines the 261 261 integration limits: any points with combined weight less than *cutoff* -
sasmodels/list_pars.py
r1d4017a r823e620 31 31 print(columnize(list(sorted(partable.keys())))) 32 32 else: 33 for k, v in sorted(partable.items()):33 for k, v in sorted(partable.items()): 34 34 print("%s: %s"%(k, ", ".join(v))) 35 35 -
sasmodels/model_test.py
r9404dd3 r823e620 9 9 if model1 is 'all', then all except the remaining models will be tested 10 10 11 Each model is tested using the default parameters at q=0.1, (qx, qy)=(0.1,0.1),11 Each model is tested using the default parameters at q=0.1, (qx, qy)=(0.1, 0.1), 12 12 and the ER and VR are computed. The return values at these points are not 13 13 considered. The test is only to verify that the models run to completion, … … 30 30 [ {parameters}, (qx, qy), I(qx, Iqy)], 31 31 [ {parameters}, [(qx1, qy1), (qx2, qy2), ...], 32 [I(qx1, qy1), I(qx2,qy2), ...]],32 [I(qx1, qy1), I(qx2, qy2), ...]], 33 33 34 34 [ {parameters}, 'ER', ER(pars) ], … … 75 75 # don't try to call cl kernel since it will not be 76 76 # available in some environmentes. 77 is_py = callable(getattr(model_definition, 'Iq', None))77 is_py = callable(getattr(model_definition, 'Iq', None)) 78 78 79 79 if is_py: # kernel implemented in python … … 123 123 def _runTest(self): 124 124 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], 129 129 ] 130 130 … … 163 163 actual = [call_VR(model.info, pars)] 164 164 elif isinstance(x[0], tuple): 165 Qx, Qy = zip(*x)165 Qx, Qy = zip(*x) 166 166 q_vectors = [np.array(Qx), np.array(Qy)] 167 167 kernel = make_kernel(model, q_vectors) … … 179 179 # smoke test --- make sure it runs and produces a value 180 180 self.assertTrue(np.isfinite(actual_yi), 181 'invalid f(%s): %s' % (xi, actual_yi))181 'invalid f(%s): %s' % (xi, actual_yi)) 182 182 else: 183 183 err = abs(yi - actual_yi) 184 184 nrm = abs(yi) 185 185 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)) 187 188 188 189 return ModelTestCase … … 237 238 Run "nosetests sasmodels" on the command line to invoke it. 238 239 """ 239 tests = make_suite(['opencl', 'dll'],['all'])240 tests = make_suite(['opencl', 'dll'], ['all']) 240 241 for test_i in tests: 241 242 yield test_i._runTest -
sasmodels/resolution.py
r190fc2b r823e620 14 14 "pinhole_extend_q", "slit_extend_q", "bin_edges", 15 15 "interpolate", "linear_extrapolation", "geometric_extrapolation", 16 16 ] 17 17 18 18 MINIMUM_RESOLUTION = 1e-8 … … 80 80 # default to Perfect1D if the pinhole geometry is not defined. 81 81 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 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)) 86 86 87 87 def apply(self, theory): -
sasmodels/resolution2d.py
r841753c r823e620 143 143 if self.coords == 'polar': 144 144 q_r = sqrt(qx**2 + qy**2) 145 qx_res = ((dqx*cos(dphi) + q_r) * cos(-q_phi) +146 147 qy_res = (-(dqx*cos(dphi) + q_r) * sin(-q_phi) +148 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)) 149 149 else: 150 qx_res = qx + 151 qy_res = qy + 150 qx_res = qx + dqx*cos(dphi) 151 qy_res = qy + dqy*sin(dphi) 152 152 153 153 … … 162 162 theory = np.reshape(theory, (nbins, nq)) 163 163 ## 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) 165 165 ## Return the smeared values in the range of self.index 166 166 return value -
sasmodels/weights.py
r3c56da87 r823e620 36 36 *center* is the center of the distribution 37 37 38 *lb*, *ub* are the min and max allowed values38 *lb*, *ub* are the min and max allowed values 39 39 40 40 *relative* is True if the distribution width is proportional to the … … 84 84 default = dict(npts=80, width=0, nsigmas=8) 85 85 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)) 87 87 px = np.exp(-0.5*(np.log(x)-center)**2)/sigma**2/(x*sigma) 88 88 return x, px … … 93 93 default = dict(npts=80, width=0, nsigmas=8) 94 94 def _weights(self, center, sigma, lb, ub): 95 x = self._linspace(center, sigma, max(lb, 1e-8), max(ub,1e-8))96 R = x/center95 x = self._linspace(center, sigma, max(lb, 1e-8), max(ub, 1e-8)) 96 R = x/center 97 97 z = (center/sigma)**2 98 98 arg = z*np.log(z) + (z-1)*np.log(R) - R*z - np.log(center) - gammaln(z) … … 117 117 # TODO: interpolate into the array dispersion using npts 118 118 x = center + self.values*sigma 119 idx = (x >=lb)&(x<=ub)119 idx = (x >= lb) & (x <= ub) 120 120 x = x[idx] 121 121 px = self.weights[idx] … … 124 124 125 125 # dispersion name -> disperser lookup table. 126 models = dict((d.type, d) for d in (126 models = dict((d.type, d) for d in ( 127 127 GaussianDispersion, RectangleDispersion, 128 128 ArrayDispersion, SchulzDispersion, LogNormalDispersion … … 149 149 of the parameter, and false if it is an absolute width. 150 150 151 Returns *(value, weight)*, where *value* and *weight* are vectors.151 Returns *(value, weight)*, where *value* and *weight* are vectors. 152 152 """ 153 153 cls = models[disperser] 154 154 obj = cls(n, width, nsigmas) 155 v, w = obj.get_weights(value, limits[0], limits[1], relative)156 return v, w155 v, w = obj.get_weights(value, limits[0], limits[1], relative) 156 return v, w 157 157 158 158 # Hack to allow sasview dispersion objects to interoperate with sasmodels 159 dispersers = dict((v.__name__, k) for k,v in models.items())159 dispersers = dict((v.__name__, k) for k, v in models.items()) 160 160 dispersers['DispersionModel'] = RectangleDispersion.type 161 161
Note: See TracChangeset
for help on using the changeset viewer.