Changeset 9404dd3 in sasmodels
- Timestamp:
- Dec 4, 2015 12:41:47 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:
- eaca9eb
- Parents:
- 7bb290c
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/conf.py
r0496031 r9404dd3 22 22 sys.path.insert(0, os.path.abspath('_extensions')) 23 23 sys.path.insert(0, os.path.abspath('.')) # needed for extension tests 24 print "\n".join(sys.path)24 print("\n".join(sys.path)) 25 25 import sasmodels 26 26 -
doc/gentoc.py
r7bb290c r9404dd3 1 from __future__ import print_function 2 1 3 import sys 2 4 # make sure sasmodels is on the path … … 39 41 def _maybe_make_category(category, models, cat_files, model_toc): 40 42 if category not in cat_files: 41 print >>sys.stderr, "Unexpected category %s containing"%category, models43 print("Unexpected category %s containing"%category, models, file=sys.stderr) 42 44 title = category.capitalize()+" Functions" 43 45 cat_files[category] = _make_category(category, category, title, model_toc) … … 45 47 def generate_toc(model_files): 46 48 if not model_files: 47 print >>sys.stderr, "gentoc needs a list of model files"49 print("gentoc needs a list of model files", file=sys.stderr) 48 50 49 51 # find all categories … … 55 57 model_definition = load_model_definition(model_name) 56 58 if not hasattr(model_definition, 'category'): 57 print >>sys.stderr, "Missing category for",item59 print("Missing category for", item, file=sys.stderr) 58 60 else: 59 61 category.setdefault(model_definition.category,[]).append(model_name) … … 62 64 for k,v in category.items(): 63 65 if len(v) == 1: 64 print >>sys.stderr, "Category %s contains only %s"%(k,v[0])66 print("Category %s contains only %s"%(k,v[0]), file=sys.stderr) 65 67 66 68 # Generate category files for the table of contents. -
sasmodels/bumps_model.py
r0e9048f r9404dd3 122 122 fixed_pars = [getattr(self.model, p).value for p in self._fn.fixed_pars] 123 123 pd_pars = [self._get_weights(p) for p in self._fn.pd_pars] 124 #print fixed_pars,pd_pars124 #print(fixed_pars,pd_pars) 125 125 Iq_calc = self._fn(fixed_pars, pd_pars, self.cutoff) 126 126 #self._theory[:] = self._fn.eval(pars, pd_pars) … … 137 137 138 138 def residuals(self): 139 #if np.any(self.err ==0): print "zeros in err"139 #if np.any(self.err ==0): print("zeros in err") 140 140 return (self.theory() - self.Iq) / self.dIq 141 141 142 142 def nllf(self): 143 143 delta = self.residuals() 144 #if np.any(np.isnan(R)): print "NaN in residuals"144 #if np.any(np.isnan(R)): print("NaN in residuals") 145 145 return 0.5 * np.sum(delta ** 2) 146 146 -
sasmodels/compare.py
r1ec7efa r9404dd3 71 71 """ 72 72 # convert model parameters from sasmodel form to sasview form 73 #print "old",sorted(pars.items())73 #print("old",sorted(pars.items())) 74 74 modelname, pars = revert_model(model_definition, pars) 75 #print "new",sorted(pars.items())75 #print("new",sorted(pars.items())) 76 76 sas = __import__('sas.models.'+modelname) 77 77 ModelClass = getattr(getattr(sas.models,modelname,None),modelname,None) … … 193 193 try: 194 194 model = core.load_model(model_definition, dtype=dtype, platform="ocl") 195 except Exception ,exc:196 print exc197 print "... trying again with single precision"195 except Exception as exc: 196 print(exc) 197 print("... trying again with single precision") 198 198 model = core.load_model(model_definition, dtype='single', platform="ocl") 199 199 calculator = DirectModel(data, model, cutoff=cutoff) … … 267 267 seed = int(opt_values['-random']) if '-random' in opt_values else None 268 268 pars, seed = randomize_model(pars, seed=seed) 269 print "Randomize using -random=%i"%seed269 print("Randomize using -random=%i"%seed) 270 270 pars.update(set_pars) # set value after random to control value 271 271 constrain_pars(model_definition, pars) … … 275 275 suppress_pd(pars) 276 276 if '-pars' in opts: 277 print "pars",parlist(pars)277 print("pars "+str(parlist(pars))) 278 278 279 279 # Base calculation … … 287 287 base, base_time = eval_sasview(model_definition, pars, data, Ncomp) 288 288 base_name = "sasview" 289 #print "base/sasview", (base-pars['background'])/(comp-pars['background'])290 print "sasview t=%.1f ms, intensity=%.0f"%(base_time, sum(base))291 #print "sasview",comp289 #print("base/sasview", (base-pars['background'])/(comp-pars['background'])) 290 print("sasview t=%.1f ms, intensity=%.0f"%(base_time, sum(base))) 291 #print("sasview",comp) 292 292 except ImportError: 293 293 traceback.print_exc() … … 297 297 dtype=dtype, cutoff=cutoff, Nevals=Nbase) 298 298 base_name = "ocl" 299 print "opencl t=%.1f ms, intensity=%.0f"%(base_time, sum(base))300 #print "base", base301 #print max(base), min(base)299 print("opencl t=%.1f ms, intensity=%.0f"%(base_time, sum(base))) 300 #print("base " + base) 301 #print(max(base), min(base)) 302 302 303 303 # Comparison calculation … … 306 306 dtype=dtype, cutoff=cutoff, Nevals=Ncomp) 307 307 comp_name = "ctypes" 308 print "ctypes t=%.1f ms, intensity=%.0f"%(comp_time, sum(comp))308 print("ctypes t=%.1f ms, intensity=%.0f"%(comp_time, sum(comp))) 309 309 elif Ncomp > 0: 310 310 try: 311 311 comp, comp_time = eval_sasview(model_definition, pars, data, Ncomp) 312 312 comp_name = "sasview" 313 #print "base/sasview", (base-pars['background'])/(comp-pars['background'])314 print "sasview t=%.1f ms, intensity=%.0f"%(comp_time, sum(comp))315 #print "sasview",comp313 #print("base/sasview", (base-pars['background'])/(comp-pars['background'])) 314 print("sasview t=%.1f ms, intensity=%.0f"%(comp_time, sum(comp))) 315 #print("sasview",comp) 316 316 except ImportError: 317 317 traceback.print_exc() … … 320 320 # Compare, but only if computing both forms 321 321 if Nbase > 0 and Ncomp > 0: 322 #print "speedup %.2g"%(comp_time/base_time)323 #print "max |base/comp|", max(abs(base/comp)), "%.15g"%max(abs(base)), "%.15g"%max(abs(comp))322 #print("speedup %.2g"%(comp_time/base_time)) 323 #print("max |base/comp|", max(abs(base/comp)), "%.15g"%max(abs(base)), "%.15g"%max(abs(comp))) 324 324 #comp *= max(base/comp) 325 325 resid = (base - comp) 326 326 relerr = resid/comp 327 327 #bad = (relerr>1e-4) 328 #print relerr[bad],comp[bad],base[bad],data.qx_data[bad],data.qy_data[bad]328 #print(relerr[bad],comp[bad],base[bad],data.qx_data[bad],data.qy_data[bad]) 329 329 _print_stats("|%s-%s|"%(base_name,comp_name)+(" "*(3+len(comp_name))), resid) 330 330 _print_stats("|(%s-%s)/%s|"%(base_name,comp_name,comp_name), relerr) … … 379 379 "zero-offset:%+.3e"%np.mean(err), 380 380 ] 381 print label," ".join(data)381 print(label+" ".join(data)) 382 382 383 383 … … 466 466 sys.exit(1) 467 467 if args[0] not in MODELS: 468 print "Model %r not available. Use one of:\n %s"%(args[0],models)468 print("Model %r not available. Use one of:\n %s"%(args[0],models)) 469 469 sys.exit(1) 470 470 if len(args) > 3: … … 475 475 and not any(o.startswith('-%s='%t) for t in VALUE_OPTIONS)] 476 476 if invalid: 477 print "Invalid options: %s"%(", ".join(invalid))477 print("Invalid options: %s"%(", ".join(invalid))) 478 478 sys.exit(1) 479 479 … … 500 500 # extract base name without distribution 501 501 s = set(p.split('_pd')[0] for p in pars) 502 print "%r invalid; parameters are: %s"%(k,", ".join(sorted(s)))502 print("%r invalid; parameters are: %s"%(k,", ".join(sorted(s)))) 503 503 sys.exit(1) 504 504 set_pars[k] = float(v) if not v.endswith('type') else v -
sasmodels/compare_many.py
r4b41184 r9404dd3 53 53 raise 54 54 except: 55 print >>sys.stderr, traceback.format_exc()56 print >>sys.stderr, "when comparing",name,"for seed",seed55 traceback.print_exc() 56 print("when comparing %s for %d"%(name, seed)) 57 57 if hasattr(data, 'qx_data'): 58 58 result = np.NaN*data.data … … 71 71 max_diff = [0] 72 72 for k in range(N): 73 print >>sys.stderr, name, k73 print("%s %d"%(name, k)) 74 74 pars_i, seed = randomize_model(pars) 75 75 constrain_pars(model_definition, pars_i) … … 109 109 else: 110 110 print(("%d,"%seed)+','.join("%g"%v for v in columns)) 111 print '"good","%d/%d","max diff",%g'%(num_good, N, max_diff[0])111 print('"good","%d/%d","max diff",%g'%(num_good, N, max_diff[0])) 112 112 113 113 114 114 def print_usage(): 115 print "usage: compare_many.py MODEL COUNT (1dNQ|2dNQ) (CUTOFF|mono) (single|double|quad)"115 print("usage: compare_many.py MODEL COUNT (1dNQ|2dNQ) (CUTOFF|mono) (single|double|quad)") 116 116 117 117 … … 155 155 model = sys.argv[1] 156 156 if not (model in MODELS) and (model != "all"): 157 print 'Bad model %s. Use "all" or one of:'157 print('Bad model %s. Use "all" or one of:') 158 158 print_models() 159 159 sys.exit(1) -
sasmodels/core.py
r7cf2cfd r9404dd3 179 179 value, weight = dispersion_mesh(vol_pars) 180 180 individual_radii = ER(*value) 181 #print values[0].shape, weights.shape, fv.shape181 #print(values[0].shape, weights.shape, fv.shape) 182 182 return np.sum(weight*individual_radii) / np.sum(weight) 183 183 -
sasmodels/data.py
rac21c7f r9404dd3 274 274 plt.subplot(121) 275 275 276 #print vmin, vmax276 #print(vmin, vmax) 277 277 positive = False 278 278 if plot_data: -
sasmodels/direct_model.py
r7cf2cfd r9404dd3 140 140 141 141 if len(sys.argv) < 3: 142 print "usage: python -m sasmodels.direct_model modelname (q|qx,qy) par=val ..."142 print("usage: python -m sasmodels.direct_model modelname (q|qx,qy) par=val ...") 143 143 sys.exit(1) 144 144 model_name = sys.argv[1] … … 156 156 data = empty_data2D([qx],[qy]) 157 157 else: 158 print "use q or qx,qy or ER or VR"158 print("use q or qx,qy or ER or VR") 159 159 sys.exit(1) 160 160 else: … … 168 168 for k,v in [pair.split('=')]) 169 169 if call == "ER": 170 print calculator.ER(**pars)170 print(calculator.ER(**pars)) 171 171 elif call == "VR": 172 print calculator.VR(**pars)172 print(calculator.VR(**pars)) 173 173 else: 174 174 Iq = calculator(**pars) 175 print Iq[0]175 print(Iq[0]) 176 176 177 177 if __name__ == "__main__": -
sasmodels/exception.py
rd138d43 r9404dd3 20 20 >>> D = {} 21 21 >>> try: 22 ... print D['hello']23 ... except Exception ,exc:22 ... print(D['hello']) 23 ... except Exception as exc: 24 24 ... annotate_exception(exc, "while accessing 'D'") 25 25 ... raise -
sasmodels/generate.py
re88bb78 r9404dd3 546 546 defines.append(('IQXY_HAS_THETA', '1')) 547 547 548 #for d in defines: print d548 #for d in defines: print(d) 549 549 DEFINES = '\n'.join('#define %s %s' % (k, v) for k, v in defines) 550 550 SOURCES = '\n\n'.join(source) … … 558 558 Interpret the model definition file, categorizing the parameters. 559 559 """ 560 #print kernelfile560 #print(kernelfile) 561 561 category = getattr(kernel_module, 'category', None) 562 562 parameters = COMMON_PARAMETERS + kernel_module.parameters … … 655 655 make(cylinder) 656 656 toc = (datetime.datetime.now() - tic).total_seconds() 657 print "time:", toc657 print("time: %g"%toc) 658 658 659 659 def main(): 660 660 if len(sys.argv) <= 1: 661 print "usage: python -m sasmodels.generate modelname"661 print("usage: python -m sasmodels.generate modelname") 662 662 else: 663 663 name = sys.argv[1] … … 666 666 model = getattr(sasmodels.models, name) 667 667 source, _ = make(model) 668 print source668 print(source) 669 669 670 670 if __name__ == "__main__": -
sasmodels/kernelcl.py
r92da231 r9404dd3 57 57 # Ask OpenCL for the default context so that we know that one exists 58 58 cl.create_some_context(interactive=False) 59 except Exception ,exc:59 except Exception as exc: 60 60 warnings.warn(str(exc)) 61 61 raise RuntimeError("OpenCL not available") … … 184 184 try: 185 185 self.context = cl.create_some_context(interactive=False) 186 except Exception ,exc:186 except Exception as exc: 187 187 warnings.warn(str(exc)) 188 188 warnings.warn("pyopencl.create_some_context() failed") … … 191 191 def compile_program(self, name, source, dtype): 192 192 if name not in self.compiled: 193 #print "compiling",name193 #print("compiling",name) 194 194 self.compiled[name] = compile_model(self.context, source, dtype) 195 195 return self.compiled[name] … … 359 359 if pd_pars else np.empty(0, dtype=self.q_input.dtype) 360 360 loops = np.ascontiguousarray(loops.T, self.q_input.dtype).flatten() 361 #print "loops",Nloops, loops362 363 #import sys; print >>sys.stderr,"opencl eval",pars364 #print "opencl eval",pars361 #print("loops",Nloops, loops) 362 363 #import sys; print("opencl eval",pars) 364 #print("opencl eval",pars) 365 365 if len(loops) > 2 * MAX_LOOPS: 366 366 raise ValueError("too many polydispersity points") -
sasmodels/kerneldll.py
rd138d43 r9404dd3 146 146 os.fdopen(fid,"w").write(source) 147 147 command = COMPILE%{"source":filename, "output":dll} 148 print "Compile command:",command148 print("Compile command: "+command) 149 149 status = os.system(command) 150 150 if status != 0 or not os.path.exists(dll): … … 152 152 else: 153 153 ## uncomment the following to keep the generated c file 154 os.unlink(filename); print "saving compiled file in %r"%filename154 os.unlink(filename); print("saving compiled file in %r"%filename) 155 155 return dll 156 156 … … 197 197 Npd2d = len(self.info['partype']['pd-2d']) 198 198 199 #print "dll",self.dllpath199 #print("dll",self.dllpath) 200 200 try: 201 201 self.dll = ct.CDLL(self.dllpath) 202 except Exception ,exc:202 except Exception as exc: 203 203 annotate_exception(exc, "while loading "+self.dllpath) 204 204 raise … … 291 291 fixed = [real(p) for p in fixed_pars] 292 292 args = self.q_input.q_pointers + [self.p_res, nq] + dispersed + fixed 293 #print pars293 #print(pars) 294 294 self.kernel(*args) 295 295 -
sasmodels/kernelpy.py
r062c56d r9404dd3 108 108 109 109 def __call__(self, fixed, pd, cutoff=1e-5): 110 #print "fixed",fixed111 #print "pd", pd110 #print("fixed",fixed) 111 #print("pd", pd) 112 112 args = self.args[:] # grab a copy of the args 113 113 form, form_volume = self.kernel, self.info['form_volume'] -
sasmodels/model_test.py
r2781b2e r9404dd3 68 68 model_definition = load_model_definition(model_name) 69 69 70 #print '------'71 #print 'found tests in', model_name72 #print '------'70 #print('------') 71 #print('found tests in', model_name) 72 #print('------') 73 73 74 74 # if ispy then use the dll loader to call pykernel … … 93 93 test_method_name, 94 94 platform="ocl", dtype='single') 95 #print "defining", test_name95 #print("defining", test_name) 96 96 suite.addTest(test) 97 97 … … 144 144 pass 145 145 146 except Exception ,exc:146 except Exception as exc: 147 147 annotate_exception(exc, self.test_name) 148 148 raise … … 201 201 if models and models[0] == 'opencl': 202 202 if not HAVE_OPENCL: 203 print >>sys.stderr, "opencl is not available"203 print("opencl is not available") 204 204 return 1 205 205 loaders = ['opencl'] … … 215 215 loaders = ['opencl', 'dll'] 216 216 if not models: 217 print >>sys.stderr,"""\217 print("""\ 218 218 usage: 219 219 python -m sasmodels.model_test [opencl|dll|opencl_and_dll] model1 model2 ... … … 221 221 If model1 is 'all', then all except the remaining models will be tested. 222 222 If no compute target is specified, then models will be tested with both opencl 223 and dll; the compute target is ignored for pure python models.""" 223 and dll; the compute target is ignored for pure python models.""") 224 224 225 225 return 1 -
sasmodels/resolution.py
rd138d43 r9404dd3 134 134 Apply the resolution weight matrix to the computed theory function. 135 135 """ 136 #print "apply shapes", theory.shape, weight_matrix.shape136 #print("apply shapes", theory.shape, weight_matrix.shape) 137 137 Iq = np.dot(theory[None,:], weight_matrix) 138 #print "result shape",Iq.shape138 #print("result shape",Iq.shape) 139 139 return Iq.flatten() 140 140 … … 287 287 weights = np.zeros((len(q), len(q_calc)), 'd') 288 288 289 #print q_calc289 #print(q_calc) 290 290 for i, (qi, w, h) in enumerate(zip(q, width, height)): 291 291 if w == 0. and h == 0.: … … 301 301 in_x = 1.0 * ((q_calc >= qi-h) & (q_calc <= qi+h)) 302 302 abs_x = 1.0*(q_calc < abs(qi - h)) if qi < h else 0. 303 #print qi - h, qi + h304 #print in_x + abs_x303 #print(qi - h, qi + h) 304 #print(in_x + abs_x) 305 305 weights[i,:] = (in_x + abs_x) * np.diff(q_edges) / (2*h) 306 306 else: … … 320 320 u_edges[q_edges > u_limit] = u_limit**2 - qi**2 321 321 weights = np.diff(np.sqrt(u_edges))/w 322 #print "i, qi",i,qi,qi+width323 #print q_calc324 #print weights322 #print("i, qi",i,qi,qi+width) 323 #print(q_calc) 324 #print(weights) 325 325 return weights 326 326 … … 521 521 u = sqrt((qi+h_grid)**2 + w_grid**2) 522 522 Iu = np.interp(u, q_calc, Iq) 523 #print np.trapz(Iu, w_grid, axis=1)523 #print(np.trapz(Iu, w_grid, axis=1)) 524 524 Is = np.trapz(np.trapz(Iu, w_grid, axis=1), h_grid[:,0]) 525 525 result[i] = Is / (2*h*w) … … 675 675 #idx = abs(err) >= tolerance 676 676 #problem = zip(q[idx], output[idx], answer[idx], err[idx]) 677 #print "\n".join(str(v) for v in problem)677 #print("\n".join(str(v) for v in problem)) 678 678 np.testing.assert_allclose(output, answer, rtol=tolerance) 679 679 … … 786 786 output = resolution.apply(eval_form(resolution.q_calc, form, pars)) 787 787 # TODO: 10% is too much error; use better algorithm 788 #print np.max(abs(answer-output)/answer)788 #print(np.max(abs(answer-output)/answer)) 789 789 self.compare(q, output, answer, 0.1) 790 790 -
sasmodels/resolution2d.py
rcd8dde1 r9404dd3 179 179 180 180 from sas.dataloader import Data2D 181 #for i in range(10): print i, 0.001 + i*0.008/9.0182 #for i in range(100): print i, int(math.floor( (i/ (100/9.0))))181 #for i in range(10): print(i, 0.001 + i*0.008/9.0) 182 #for i in range(100): print(i, int(math.floor( (i/ (100/9.0)) ))) 183 183 out = Data2D() 184 184 out.data = z … … 198 198 value = smear.get_value() 199 199 ## All data are ones, so the smeared should also be ones. 200 print "Data length =", len(value)201 print " 2D linear function, I = 0 + 1*qy"200 print("Data length =", len(value)) 201 print(" 2D linear function, I = 0 + 1*qy") 202 202 text = " Gaussian weighted averaging on a 2D linear function will " 203 203 text += "provides the results same as without the averaging." 204 print text205 print "qx_data", "qy_data", "I_nonsmear", "I_smeared"204 print(text) 205 print("qx_data", "qy_data", "I_nonsmear", "I_smeared") 206 206 for ind in range(len(value)): 207 print x[ind], y[ind], model.evalDistribution([x, y])[ind], value[ind]207 print(x[ind], y[ind], model.evalDistribution([x, y])[ind], value[ind]) 208 208 209 209 … … 218 218 219 219 from DataLoader import Data2D 220 #for i in range(10): print i, 0.001 + i*0.008/9.0221 #for i in range(100): print i, int(math.floor( (i/ (100/9.0))))220 #for i in range(10): print(i, 0.001 + i*0.008/9.0) 221 #for i in range(100): print(i, int(math.floor( (i/ (100/9.0)) ))) 222 222 out = Data2D() 223 223 out.data = z … … 233 233 value = Smearer2D(out,model,index).get_value() 234 234 ## All data are ones, so the smeared values should also be ones. 235 print "Data length =",len(value), ", Data=",value236 """ 235 print("Data length =",len(value), ", Data=",value) 236 """ -
sasmodels/sasview_model.py
rd138d43 r9404dd3 187 187 for d in self._model.info['partype']['pd-2d'] 188 188 for p in ('npts', 'nsigmas', 'width')] 189 #print ret189 #print(ret) 190 190 return ret 191 191 … … 303 303 values, weights = self._dispersion_mesh() 304 304 fv = ER(*values) 305 #print values[0].shape, weights.shape, fv.shape305 #print(values[0].shape, weights.shape, fv.shape) 306 306 return np.sum(weights * fv) / np.sum(weights) 307 307
Note: See TracChangeset
for help on using the changeset viewer.