Changes in / [5f1acda:d247047] in sasmodels
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
sascomp
r6708a6a r424fe00 19 19 20 20 import sasmodels.compare 21 sasmodels.compare.main( )21 sasmodels.compare.main(*sys.argv[1:]) 22 22 23 23 if __name__ == "__main__": -
sasmodels/__init__.py
rb2377b0 r79906d1 14 14 defining new models. 15 15 """ 16 __version__ = "0.9 3"16 __version__ = "0.94" 17 17 18 18 def data_files(): -
sasmodels/compare.py
r050c2c8 r050c2c8 789 789 790 790 791 def parse_opts( ):792 # type: ( ) -> Dict[str, Any]791 def parse_opts(argv): 792 # type: (List[str]) -> Dict[str, Any] 793 793 """ 794 794 Parse command line options. 795 795 """ 796 796 MODELS = core.list_models() 797 flags = [arg for arg in sys.argv[1:]797 flags = [arg for arg in argv 798 798 if arg.startswith('-')] 799 values = [arg for arg in sys.argv[1:]799 values = [arg for arg in argv 800 800 if not arg.startswith('-') and '=' in arg] 801 args = [arg for arg in sys.argv[1:]801 positional_args = [arg for arg in argv 802 802 if not arg.startswith('-') and '=' not in arg] 803 803 models = "\n ".join("%-15s"%v for v in MODELS) 804 if len( args) == 0:804 if len(positional_args) == 0: 805 805 print(USAGE) 806 806 print("\nAvailable models:") 807 807 print(columnize(MODELS, indent=" ")) 808 sys.exit(1)809 if len( args) > 3:808 return None 809 if len(positional_args) > 3: 810 810 print("expected parameters: model N1 N2") 811 811 812 name = args[0]812 name = positional_args[0] 813 813 try: 814 814 model_info = core.load_model_info(name) … … 816 816 print(str(exc)) 817 817 print("Could not find model; use one of:\n " + models) 818 sys.exit(1)818 return None 819 819 820 820 invalid = [o[1:] for o in flags … … 823 823 if invalid: 824 824 print("Invalid options: %s"%(", ".join(invalid))) 825 sys.exit(1)825 return None 826 826 827 827 … … 898 898 del engines[2:] 899 899 900 n1 = int( args[1]) if len(args) > 1 else 1901 n2 = int( args[2]) if len(args) > 2 else 1900 n1 = int(positional_args[1]) if len(positional_args) > 1 else 1 901 n2 = int(positional_args[2]) if len(positional_args) > 2 else 1 902 902 use_sasview = any(engine == 'sasview' and count > 0 903 903 for engine, count in zip(engines, [n1, n2])) … … 916 916 s = set(p.split('_pd')[0] for p in pars) 917 917 print("%r invalid; parameters are: %s"%(k, ", ".join(sorted(s)))) 918 sys.exit(1)918 return None 919 919 presets[k] = float(v) if not k.endswith('type') else v 920 920 … … 970 970 from bumps.gui.app_frame import AppFrame # type: ignore 971 971 972 is_mac = "cocoa" in wx.version() 973 # Create an app if not running embedded 974 app = wx.App() if wx.GetApp() is None else None 972 975 problem = FitProblem(Explore(opts)) 973 is_mac = "cocoa" in wx.version() 974 app = wx.App() 975 frame = AppFrame(parent=None, title="explore") 976 frame = AppFrame(parent=None, title="explore", size=(1000,700)) 976 977 if not is_mac: frame.Show() 977 978 frame.panel.set_model(model=problem) … … 979 980 frame.panel.aui.Split(0, wx.TOP) 980 981 if is_mac: frame.Show() 981 app.MainLoop() 982 # If running withing an app, start the main loop 983 if app: app.MainLoop() 982 984 983 985 class Explore(object): … … 1048 1050 1049 1051 1050 def main( ):1051 # type: ( ) -> None1052 def main(*argv): 1053 # type: (*str) -> None 1052 1054 """ 1053 1055 Main program. 1054 1056 """ 1055 opts = parse_opts() 1056 if opts['explore']: 1057 explore(opts) 1058 else: 1059 compare(opts) 1057 opts = parse_opts(argv) 1058 if opts is not None: 1059 if opts['explore']: 1060 explore(opts) 1061 else: 1062 compare(opts) 1060 1063 1061 1064 if __name__ == "__main__": 1062 main( )1065 main(*sys.argv[1:]) -
sasmodels/compare_many.py
r40a87fa r424fe00 229 229 print_models() 230 230 231 def main( ):231 def main(argv): 232 232 """ 233 233 Main program. 234 234 """ 235 if len( sys.argv) not in (6, 7):235 if len(argv) not in (5, 6): 236 236 print_help() 237 sys.exit(1)238 239 model = sys.argv[1]237 return 238 239 model = argv[0] 240 240 if not (model in MODELS) and (model != "all"): 241 241 print('Bad model %s. Use "all" or one of:'%model) 242 242 print_models() 243 sys.exit(1)243 return 244 244 try: 245 count = int( sys.argv[2])246 is2D = sys.argv[3].startswith('2d')247 assert sys.argv[3][1] == 'd'248 Nq = int( sys.argv[3][2:])249 mono = sys.argv[4] == 'mono'250 cutoff = float( sys.argv[4]) if not mono else 0251 base = sys.argv[5]252 comp = sys.argv[6] if len(sys.argv) > 6else "sasview"245 count = int(argv[1]) 246 is2D = argv[2].startswith('2d') 247 assert argv[2][1] == 'd' 248 Nq = int(argv[2][2:]) 249 mono = argv[3] == 'mono' 250 cutoff = float(argv[3]) if not mono else 0 251 base = argv[4] 252 comp = argv[5] if len(argv) > 5 else "sasview" 253 253 except Exception: 254 254 traceback.print_exc() 255 255 print_usage() 256 sys.exit(1)256 return 257 257 258 258 data, index = make_data({'qmax':1.0, 'is2d':is2D, 'nq':Nq, 'res':0., … … 265 265 if __name__ == "__main__": 266 266 #from .compare import push_seed 267 #with push_seed(1): main( )268 main( )267 #with push_seed(1): main(sys.argv[1:]) 268 main(sys.argv[1:]) -
sasmodels/custom/__init__.py
r40a87fa r2a0c7a6 17 17 def load_module_from_path(fullname, path): 18 18 """load module from *path* as *fullname*""" 19 spec = spec_from_file_location(fullname, path)19 spec = spec_from_file_location(fullname, os.path.expanduser(path)) 20 20 module = module_from_spec(spec) 21 21 spec.loader.exec_module(module) … … 26 26 def load_module_from_path(fullname, path): 27 27 """load module from *path* as *fullname*""" 28 module = imp.load_source(fullname, path)28 module = imp.load_source(fullname, os.path.expanduser(path)) 29 29 #os.unlink(path+"c") # remove the automatic pyc file 30 30 return module … … 35 35 name = basename(splitext(path)[0]) 36 36 # Placing the model in the 'sasmodels.custom' name space. 37 kernel_module = load_module_from_path('sasmodels.custom.'+name, path) 37 kernel_module = load_module_from_path('sasmodels.custom.'+name, 38 os.path.expanduser(path)) 38 39 return kernel_module -
sasmodels/direct_model.py
rbde38b5 r4cc161e 85 85 if model_info.ER is None: 86 86 return 1.0 87 elif not model_info.parameters.form_volume_parameters: 88 # handle the case where ER is provided but model is not polydisperse 89 return model_info.ER() 87 90 else: 88 91 value, weight = _vol_pars(model_info, pars) … … 101 104 if model_info.VR is None: 102 105 return 1.0 106 elif not model_info.parameters.form_volume_parameters: 107 # handle the case where ER is provided but model is not polydisperse 108 return model_info.VR() 103 109 else: 104 110 value, weight = _vol_pars(model_info, pars) … … 152 158 for p in model_info.parameters.call_parameters 153 159 if p.type == 'volume'] 160 #import pylab; pylab.plot(vol_pars[0][0],vol_pars[0][1]); pylab.show() 154 161 value, weight = dispersion_mesh(model_info, vol_pars) 155 162 return value, weight … … 395 402 model = build_model(model_info) 396 403 calculator = DirectModel(data, model) 397 pars = dict((k, float(v))404 pars = dict((k, (float(v) if not k.endswith("_pd_type") else v)) 398 405 for pair in sys.argv[3:] 399 406 for k, v in [pair.split('=')]) -
sasmodels/generate.py
r52ec91e r2e49f9e 362 362 for long double precision. 363 363 """ 364 source = _fix_tgmath_int(source) 364 365 if dtype == F16: 365 366 fbytes = 2 … … 391 392 source = re.sub(r'(^|[^a-zA-Z0-9_]c?)double(([248]|16)?($|[^a-zA-Z0-9_]))', 392 393 r'\1%s\2'%type_name, source) 394 source = _tag_float(source, constant_flag) 395 return source 396 397 TGMATH_INT_RE = re.compile(r""" 398 (?: # Non-capturing match; not lookbehind since pattern length is variable 399 \b # word boundary 400 # various math functions 401 (a?(sin|cos|tan)h? | atan2 402 | erfc? | tgamma 403 | exp(2|10|m1)? | log(2|10|1p)? | pow[nr]? | sqrt | rsqrt | rootn 404 | fabs | fmax | fmin 405 ) 406 \s*[(]\s* # open parenthesis 407 ) 408 [+-]?(0|[1-9]\d*) # integer 409 (?= # lookahead match: don't want to move from end of int 410 \s*[,)] # comma or close parenthesis for end of argument 411 ) # end lookahead 412 """, re.VERBOSE) 413 def _fix_tgmath_int(source): 414 # type: (str) -> str 415 """ 416 Replace f(integer) with f(integer.) for sin, cos, pow, etc. 417 418 OS X OpenCL complains that it can't resolve the type generic calls to 419 the standard math functions when they are called with integer constants, 420 but this does not happen with the Windows Intel driver for example. 421 To avoid confusion on the matrix marketplace, automatically promote 422 integers to floats if we recognize them in the source. 423 424 The specific functions we look for are: 425 426 trigonometric: sin, asin, sinh, asinh, etc., and atan2 427 exponential: exp, exp2, exp10, expm1, log, log2, log10, logp1 428 power: pow, pown, powr, sqrt, rsqrt, rootn 429 special: erf, erfc, tgamma 430 float: fabs, fmin, fmax 431 432 Note that we don't convert the second argument of dual argument 433 functions: atan2, fmax, fmin, pow, powr. This could potentially 434 be a problem for pow(x, 2), but that case seems to work without change. 435 """ 436 out = TGMATH_INT_RE.sub(r'\g<0>.', source) 437 return out 438 439 440 # Floating point regular expression 441 # 442 # Define parts: 443 # 444 # E = [eE][+-]?\d+ : Exponent 445 # P = [.] : Decimal separator 446 # N = [1-9]\d* : Natural number, no leading zeros 447 # Z = 0 : Zero 448 # F = \d+ : Fractional number, maybe leading zeros 449 # F? = \d* : Optional fractional number 450 # 451 # We want to reject bare natural numbers and bare decimal points, so we 452 # need to tediously outline the cases where we have either a fraction or 453 # an exponent: 454 # 455 # ( ZP | ZPF | ZE | ZPE | ZPFE | NP | NPF | NE | NPE | NPFE | PF | PFE ) 456 # 457 # 458 # We can then join cases by making parts optional. The following are 459 # some ways to do this: 460 # 461 # ( (Z|N)(P|PF|E|PE|PFE) | PFE? ) # Split on lead 462 # => ( (Z|N)(PF?|(PF?)?E) | PFE? ) 463 # ( ((Z|N)PF?|PF)E? | (Z|N)E) # Split on point 464 # ( (ZP|ZPF|NP|NPF|PF) | (Z|ZP|ZPF|N|NP|NPF|PF)E ) # Split on E 465 # => ( ((Z|N)PF?|PF) | ((Z|N)(PF?)? | PF) E ) 466 FLOAT_RE = re.compile(r""" 467 (?<!\w) # use negative lookbehind since '.' confuses \b test 468 # use split on lead to match float ( (Z|N)(PF?|(PF?)?E) | PFE? ) 469 ( ( 0 | [1-9]\d* ) # ( ( Z | N ) 470 ([.]\d* | ([.]\d*)? [eE][+-]?\d+ ) # (PF? | (PF?)? E ) 471 | [.]\d+ ([eE][+-]?\d+)? # | PF (E)? 472 ) # ) 473 (?!\w) # use negative lookahead since '.' confuses \b test 474 """, re.VERBOSE) 475 def _tag_float(source, constant_flag): 393 476 # Convert floating point constants to single by adding 'f' to the end, 394 477 # or long double with an 'L' suffix. OS/X complains if you don't do this. 395 source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 396 r'\g<0>%s'%constant_flag, source) 397 return source 478 out = FLOAT_RE.sub(r'\g<0>%s'%constant_flag, source) 479 #print("in",repr(source),"out",repr(out), constant_flag) 480 return out 481 482 def test_tag_float(): 483 484 cases=""" 485 ZP : 0. 486 ZPF : 0.0,0.01,0.1 487 Z E: 0e+001 488 ZP E: 0.E0 489 ZPFE: 0.13e-031 490 NP : 1., 12. 491 NPF : 1.0001, 1.1, 1.0 492 N E: 1e0, 37E-080 493 NP E: 1.e0, 37.E-080 494 NPFE: 845.017e+22 495 PF : .1, .0, .0100 496 PFE: .6e+9, .82E-004 497 # isolated cases 498 0. 499 1e0 500 0.13e-013 501 # untouched 502 struct3.e3, 03.05.67, 37 503 # expressions 504 3.75+-1.6e-7-27+13.2 505 a3.e2 - 0. 506 4*atan(1) 507 4.*atan(1.) 508 """ 509 510 output=""" 511 ZP : 0.f 512 ZPF : 0.0f,0.01f,0.1f 513 Z E: 0e+001f 514 ZP E: 0.E0f 515 ZPFE: 0.13e-031f 516 NP : 1.f, 12.f 517 NPF : 1.0001f, 1.1f, 1.0f 518 N E: 1e0f, 37E-080f 519 NP E: 1.e0f, 37.E-080f 520 NPFE: 845.017e+22f 521 PF : .1f, .0f, .0100f 522 PFE: .6e+9f, .82E-004f 523 # isolated cases 524 0.f 525 1e0f 526 0.13e-013f 527 # untouched 528 struct3.e3, 03.05.67, 37 529 # expressions 530 3.75f+-1.6e-7f-27+13.2f 531 a3.e2 - 0.f 532 4*atan(1) 533 4.f*atan(1.f) 534 """ 535 536 for case_in, case_out in zip(cases.split('\n'), output.split('\n')): 537 out = _tag_float(case_in, 'f') 538 assert case_out == out, "%r => %r"%(case_in, out) 398 539 399 540 … … 706 847 Iq_units = "The returned value is scaled to units of |cm^-1| |sr^-1|, absolute scale." 707 848 Sq_units = "The returned value is a dimensionless structure factor, $S(q)$." 708 docs = convert_section_titles_to_boldface(model_info.docs) 849 docs = model_info.docs if model_info.docs is not None else "" 850 docs = convert_section_titles_to_boldface(docs) 709 851 pars = make_partable(model_info.parameters.COMMON 710 852 + model_info.parameters.kernel_parameters) … … 718 860 719 861 862 # TODO: need a single source for rst_prolog; it is also in doc/rst_prolog 863 RST_PROLOG = """\ 864 .. |Ang| unicode:: U+212B 865 .. |Ang^-1| replace:: |Ang|\ :sup:`-1` 866 .. |Ang^2| replace:: |Ang|\ :sup:`2` 867 .. |Ang^-2| replace:: |Ang|\ :sup:`-2` 868 .. |1e-6Ang^-2| replace:: 10\ :sup:`-6`\ |Ang|\ :sup:`-2` 869 .. |Ang^3| replace:: |Ang|\ :sup:`3` 870 .. |Ang^-3| replace:: |Ang|\ :sup:`-3` 871 .. |Ang^-4| replace:: |Ang|\ :sup:`-4` 872 .. |cm^-1| replace:: cm\ :sup:`-1` 873 .. |cm^2| replace:: cm\ :sup:`2` 874 .. |cm^-2| replace:: cm\ :sup:`-2` 875 .. |cm^3| replace:: cm\ :sup:`3` 876 .. |1e15cm^3| replace:: 10\ :sup:`15`\ cm\ :sup:`3` 877 .. |cm^-3| replace:: cm\ :sup:`-3` 878 .. |sr^-1| replace:: sr\ :sup:`-1` 879 .. |P0| replace:: P\ :sub:`0`\ 880 881 .. |equiv| unicode:: U+2261 882 .. |noteql| unicode:: U+2260 883 .. |TM| unicode:: U+2122 884 885 .. |cdot| unicode:: U+00B7 886 .. |deg| unicode:: U+00B0 887 .. |g/cm^3| replace:: g\ |cdot|\ cm\ :sup:`-3` 888 .. |mg/m^2| replace:: mg\ |cdot|\ m\ :sup:`-2` 889 .. |fm^2| replace:: fm\ :sup:`2` 890 .. |Ang*cm^-1| replace:: |Ang|\ |cdot|\ cm\ :sup:`-1` 891 """ 892 893 # TODO: make a better fake reference role 894 RST_ROLES = """\ 895 .. role:: ref 896 897 .. role:: numref 898 899 """ 900 720 901 def make_html(model_info): 721 902 """ … … 723 904 """ 724 905 from . import rst2html 725 return rst2html.convert(make_doc(model_info)) 906 907 rst = make_doc(model_info) 908 return rst2html.rst2html("".join((RST_ROLES, RST_PROLOG, rst))) 909 910 def view_html(model_name): 911 from . import rst2html 912 from . import modelinfo 913 kernel_module = load_kernel_module(model_name) 914 info = modelinfo.make_model_info(kernel_module) 915 url = "file://"+dirname(info.filename)+"/" 916 rst2html.wxview(make_html(info), url=url) 726 917 727 918 def demo_time(): -
sasmodels/kerneldll.py
r14a15a3 r3764ec1 2 2 DLL driver for C kernels 3 3 4 The global attribute *ALLOW_SINGLE_PRECISION_DLLS* should be set to *True* if 5 you wish to allow single precision floating point evaluation for the compiled 6 models, otherwise it defaults to *False*. 7 8 The compiler command line is stored in the attribute *COMPILE*, with string 9 substitutions for %(source)s and %(output)s indicating what to compile and 10 where to store it. The actual command is system dependent. 11 12 On windows systems, you have a choice of compilers. *MinGW* is the GNU 13 compiler toolchain, available in packages such as anaconda and PythonXY, 14 or available stand alone. This toolchain has had difficulties on some 15 systems, and may or may not work for you. In order to build DLLs, *gcc* 16 must be on your path. If the environment variable *SAS_OPENMP* is given 17 then -fopenmp is added to the compiler flags. This requires a version 18 of MinGW compiled with OpenMP support. 19 20 An alternative toolchain uses the Microsoft Visual C++ compiler, available 21 free from microsoft: 4 If the environment variable *SAS_OPENMP* is set, then sasmodels 5 will attempt to compile with OpenMP flags so that the model can use all 6 available kernels. This may or may not be available on your compiler 7 toolchain. Depending on operating system and environment. 8 9 Windows does not have provide a compiler with the operating system. 10 Instead, we assume that TinyCC is installed and available. This can 11 be done with a simple pip command if it is not already available:: 12 13 pip install tinycc 14 15 If Microsoft Visual C++ is available (because VCINSTALLDIR is 16 defined in the environment), then that will be used instead. 17 Microsoft Visual C++ for Python is available from Microsoft: 22 18 23 19 `<http://www.microsoft.com/en-us/download/details.aspx?id=44266>`_ 24 20 25 Again, this requires that the compiler is available on your path. This is 26 done by running vcvarsall.bat in a windows terminal. Install locations are 27 system dependent, such as: 21 If neither compiler is available, sasmodels will check for *MinGW*, 22 the GNU compiler toolchain. This available in packages such as Anaconda 23 and PythonXY, or available stand alone. This toolchain has had 24 difficulties on some systems, and may or may not work for you. 25 26 You can control which compiler to use by setting SAS_COMPILER in the 27 environment: 28 29 - tinycc (Windows): use the TinyCC compiler shipped with SasView 30 - msvc (Windows): use the Microsoft Visual C++ compiler 31 - mingw (Windows): use the MinGW GNU cc compiler 32 - unix (Linux): use the system cc compiler. 33 - unix (Mac): use the clang compiler. You will need XCode installed, and 34 the XCode command line tools. Mac comes with OpenCL drivers, so generally 35 this will not be needed. 36 37 Both *msvc* and *mingw* require that the compiler is available on your path. 38 For *msvc*, this can done by running vcvarsall.bat in a windows terminal. 39 Install locations are system dependent, such as: 28 40 29 41 C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat … … 33 45 C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 34 46 35 And again, the environment variable *SAS_OPENMP* controls whether OpenMP is 36 used to compile the C code. This requires the Microsoft vcomp90.dll library, 37 which doesn't seem to be included with the compiler, nor does there appear 38 to be a public download location. There may be one on your machine already 39 in a location such as: 47 OpenMP for *msvc* requires the Microsoft vcomp90.dll library, which doesn't 48 seem to be included with the compiler, nor does there appear to be a public 49 download location. There may be one on your machine already in a location 50 such as: 40 51 41 52 C:\Windows\winsxs\x86_microsoft.vc90.openmp*\vcomp90.dll 42 53 43 If you copy this onto your path, such as the python directory or the install 44 directory for this application, then OpenMP should be supported. 54 If you copy this to somewhere on your path, such as the python directory or 55 the install directory for this application, then OpenMP should be supported. 56 57 For full control of the compiler, define a function 58 *compile_command(source,output)* which takes the name of the source file 59 and the name of the output file and returns a compile command that can be 60 evaluated in the shell. For even more control, replace the entire 61 *compile(source,output)* function. 62 63 The global attribute *ALLOW_SINGLE_PRECISION_DLLS* should be set to *False* if 64 you wish to prevent single precision floating point evaluation for the compiled 65 models, otherwise set it defaults to *True*. 45 66 """ 46 67 from __future__ import print_function … … 90 111 compiler = "unix" 91 112 92 ARCH = "" if sys.maxint > 2**32 else "x86" # maxint=2**31-1 on 32 bit113 ARCH = "" if ct.sizeof(c_void_p) > 4 else "x86" # 4 byte pointers on x86 93 114 if compiler == "unix": 94 115 # Generic unix compile -
sasmodels/model_test.py
r40a87fa r897ca7f 50 50 import numpy as np # type: ignore 51 51 52 from .core import list_models, load_model_info, build_model, HAVE_OPENCL 52 from . import core 53 from .core import list_models, load_model_info, build_model 53 54 from .direct_model import call_kernel, call_ER, call_VR 54 55 from .exception import annotate_exception … … 98 99 if is_py: # kernel implemented in python 99 100 test_name = "Model: %s, Kernel: python"%model_name 100 test_method_name = "test_%s_python" % model_ name101 test_method_name = "test_%s_python" % model_info.id 101 102 test = ModelTestCase(test_name, model_info, 102 103 test_method_name, … … 106 107 else: # kernel implemented in C 107 108 # test using opencl if desired and available 108 if 'opencl' in loaders and HAVE_OPENCL:109 if 'opencl' in loaders and core.HAVE_OPENCL: 109 110 test_name = "Model: %s, Kernel: OpenCL"%model_name 110 test_method_name = "test_%s_opencl" % model_ name111 test_method_name = "test_%s_opencl" % model_info.id 111 112 # Using dtype=None so that the models that are only 112 113 # correct for double precision are not tested using … … 122 123 if 'dll' in loaders: 123 124 test_name = "Model: %s, Kernel: dll"%model_name 124 test_method_name = "test_%s_dll" % model_ name125 test_method_name = "test_%s_dll" % model_info.id 125 126 test = ModelTestCase(test_name, model_info, 126 127 test_method_name, … … 249 250 return abs(target-actual)/shift < 1.5*10**-digits 250 251 251 def main(): 252 # type: () -> int 253 """ 254 Run tests given is sys.argv. 252 def run_one(model): 253 # type: (str) -> None 254 """ 255 Run the tests for a single model, printing the results to stdout. 256 257 *model* can by a python file, which is handy for checking user defined 258 plugin models. 259 """ 260 # Note that running main() directly did not work from within the 261 # wxPython pycrust console. Instead of the results appearing in the 262 # window they were printed to the underlying console. 263 from unittest.runner import TextTestResult, _WritelnDecorator 264 265 # Build a object to capture and print the test results 266 stream = _WritelnDecorator(sys.stdout) # Add writeln() method to stream 267 verbosity = 2 268 descriptions = True 269 result = TextTestResult(stream, descriptions, verbosity) 270 271 # Build a test suite containing just the model 272 loaders = ['opencl'] 273 models = [model] 274 try: 275 suite = make_suite(loaders, models) 276 except Exception: 277 import traceback 278 stream.writeln(traceback.format_exc()) 279 return 280 281 # Run the test suite 282 suite.run(result) 283 284 # Print the failures and errors 285 for _, tb in result.errors: 286 stream.writeln(tb) 287 for _, tb in result.failures: 288 stream.writeln(tb) 289 290 # Check if there are user defined tests. 291 # Yes, it is naughty to peek into the structure of the test suite, and 292 # to assume that it contains only one test. 293 if not suite._tests[0].info.tests: 294 stream.writeln("Note: %s has no user defined tests."%model) 295 296 297 def main(*models): 298 # type: (*str) -> int 299 """ 300 Run tests given is models. 255 301 256 302 Returns 0 if success or 1 if any tests fail. … … 263 309 test_args = {} 264 310 265 models = sys.argv[1:]266 311 if models and models[0] == '-v': 267 312 verbosity = 2 … … 270 315 verbosity = 1 271 316 if models and models[0] == 'opencl': 272 if not HAVE_OPENCL:317 if not core.HAVE_OPENCL: 273 318 print("opencl is not available") 274 319 return 1 … … 318 363 319 364 if __name__ == "__main__": 320 sys.exit(main( ))365 sys.exit(main(*sys.argv[1:])) -
sasmodels/models/core_multi_shell.py
r8c6fbbc r7b68dc5 132 132 def ER(radius, n, thickness): 133 133 """Effective radius""" 134 n = n[0]# n cannot be polydisperse134 n = int(n[0]) # n cannot be polydisperse 135 135 return np.sum(thickness[:n], axis=0) + radius 136 136 -
sasmodels/models/onion.py
r3cd1001 r7b68dc5 368 368 def ER(core_radius, n, thickness): 369 369 """Effective radius""" 370 return np.sum(thickness[: n[0]], axis=0) + core_radius370 return np.sum(thickness[:int(n[0])], axis=0) + core_radius 371 371 372 372 demo = { -
sasmodels/models/sphere.py
r9a4811a r7e6bea81 2 2 For information about polarised and magnetic scattering, see 3 3 the :ref:`magnetism` documentation. 4 documentation.5 4 6 5 Definition … … 16 15 17 16 where *scale* is a volume fraction, $V$ is the volume of the scatterer, 18 $r$ is the radius of the sphere , *background* is the background level and17 $r$ is the radius of the sphere and *background* is the background level. 19 18 *sld* and *sld_solvent* are the scattering length densities (SLDs) of the 20 scatterer and the solvent respectively .19 scatterer and the solvent respectively, whose difference is $\Delta\rho$. 21 20 22 21 Note that if your data is in absolute scale, the *scale* should represent … … 91 90 radius=120, 92 91 radius_pd=.2, radius_pd_n=45) 92 93 tests = [ 94 [{}, 0.2, 0.726362], 95 [{"scale": 1., "background": 0., "sld": 6., "sld_solvent": 1., 96 "radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, 97 0.2, 0.228843], 98 [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "ER", 120.], 99 [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "VR", 1.], 100 ] 101 102 -
sasmodels/rst2html.py
r40a87fa rb217c71 10 10 from contextlib import contextmanager 11 11 12 # CRUFT: locale.getlocale() fails on some versions of OS X 13 # See https://bugs.python.org/issue18378 14 import locale 15 if hasattr(locale, '_parse_localename'): 16 try: 17 locale._parse_localename('UTF-8') 18 except ValueError: 19 _old_parse_localename = locale._parse_localename 20 def _parse_localename(localename): 21 code = locale.normalize(localename) 22 if code == 'UTF-8': 23 return None, code 24 else: 25 return _old_parse_localename(localename) 26 locale._parse_localename = _parse_localename 27 12 28 from docutils.core import publish_parts 13 29 from docutils.writers.html4css1 import HTMLTranslator 14 30 from docutils.nodes import SkipNode 15 31 32 def wxview(html, url="", size=(850, 540)): 33 import wx 34 from wx.html2 import WebView 35 frame = wx.Frame(None, -1, size=size) 36 view = WebView.New(frame) 37 view.SetPage(html, url) 38 frame.Show() 39 return frame 16 40 17 def rst2html(rst, part="whole", math_output="html"): 41 def view_rst(filename): 42 from os.path import expanduser 43 with open(expanduser(filename)) as fid: 44 rst = fid.read() 45 html = rst2html(rst) 46 wxview(html) 47 48 def rst2html(rst, part="whole", math_output="mathjax"): 18 49 r""" 19 50 Convert restructured text into simple html. … … 44 75 else: 45 76 settings = {"math-output": math_output} 77 78 # TODO: support stylesheets 79 #html_root = "/full/path/to/_static/" 80 #sheets = [html_root+s for s in ["basic.css","classic.css"]] 81 #settings["embed_styesheet"] = True 82 #settings["stylesheet_path"] = sheets 46 83 47 84 # math2html and mathml do not support \frac12 … … 104 141 assert replace_dollar(u"and $mid$ too") == u"and :math:`mid` too" 105 142 assert replace_dollar(u"$first$, $mid$, $last$") == u":math:`first`, :math:`mid`, :math:`last`" 106 assert replace_dollar(u r"dollar\$ escape") == u"dollar$ escape"107 assert replace_dollar(u r"dollar \$escape\$ too") == u"dollar $escape$ too"143 assert replace_dollar(u"dollar\\$ escape") == u"dollar$ escape" 144 assert replace_dollar(u"dollar \\$escape\\$ too") == u"dollar $escape$ too" 108 145 assert replace_dollar(u"spaces $in the$ math") == u"spaces :math:`in the` math" 109 assert replace_dollar(u r"emb\ $ed$\ ed") == ur"emb\ :math:`ed`\ ed"146 assert replace_dollar(u"emb\\ $ed$\\ ed") == u"emb\\ :math:`ed`\\ ed" 110 147 assert replace_dollar(u"$first$a") == u"$first$a" 111 148 assert replace_dollar(u"a$last$") == u"a$last$" -
sasmodels/weights.py
rf1a8811 rf1a8811 10 10 import numpy as np # type: ignore 11 11 from scipy.special import gammaln # type: ignore 12 13 # TODO: include dispersion docs with the disperser models 12 14 13 15 class Dispersion(object):
Note: See TracChangeset
for help on using the changeset viewer.