Changes in / [630aa5b:67ed543] in sasview
- Files:
-
- 3 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
run.py
r952ea1f rbc8b8a1 67 67 68 68 69 def prepare( rebuild=True):69 def prepare(): 70 70 # Don't create *.pyc files 71 71 sys.dont_write_bytecode = True … … 95 95 try: 96 96 import periodictable 97 except ImportError:97 except: 98 98 addpath(joinpath(root, '..', 'periodictable')) 99 99 100 100 try: 101 101 import bumps 102 except ImportError:102 except: 103 103 addpath(joinpath(root, '..', 'bumps')) 104 104 105 105 try: 106 106 import tinycc 107 except ImportError:107 except: 108 108 addpath(joinpath(root, '../tinycc/build/lib')) 109 109 … … 111 111 #addpath(os.path.join(root, '..','wxPython-src-3.0.0.0','wxPython')) 112 112 113 # Put the sas source tree on the path 114 addpath(joinpath(root, 'src')) 115 116 # Put sasmodels on the path 117 addpath(joinpath(root, '../sasmodels/')) 118 119 # Check if the C extensions are already built 120 try: 121 from sas.sascalc.pr import _pr_inversion 122 from sas.sascalc.calculator import _sld2i 123 from sas.sascalc.file_converter import _bsl_loader 124 except ImportError: 125 rebuild = True 126 127 # Build C extensions if necessary. Do an inplace build to simplify path. 128 if rebuild: 113 # Build project if the build directory does not already exist. 114 # PAK: with "update" we can always build since it is fast 115 if True or not os.path.exists(build_path): 129 116 import subprocess 130 build_cmd = [sys.executable, "setup.py", "build _ext", "--inplace", "update"]117 build_cmd = [sys.executable, "setup.py", "build", "update"] 131 118 if os.name == 'nt': 132 119 build_cmd.append('--compiler=tinycc') … … 135 122 with cd(root): 136 123 subprocess.call(build_cmd, shell=shell) 124 125 # Put the source trees on the path 126 addpath(joinpath(root, 'src')) 127 128 # sasmodels on the path 129 addpath(joinpath(root, '../sasmodels/')) 130 131 # The sas.models package Compiled Model files should be pulled in from the build directory even though 132 # the source is stored in src/sas/models. 133 134 # Compiled modules need to be pulled from the build directory. 135 # Some packages are not where they are needed, so load them explicitly. 136 import sas.sascalc.pr 137 sas.sascalc.pr.core = import_package('sas.sascalc.pr.core', 138 joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 139 140 # Compiled modules need to be pulled from the build directory. 141 # Some packages are not where they are needed, so load them explicitly. 142 import sas.sascalc.file_converter 143 sas.sascalc.file_converter.core = import_package('sas.sascalc.file_converter.core', 144 joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core')) 145 146 import sas.sascalc.calculator 147 sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core', 148 joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 149 150 sys.path.append(build_path) 137 151 138 152 set_git_tag() -
setup.py
r952ea1f rc16172d 12 12 import shutil 13 13 import sys 14 from distutils.command.build_ext import build_ext 15 from distutils.core import Command 14 16 15 17 import numpy as np 16 17 18 from setuptools import Extension, setup 18 from setuptools import Command19 from setuptools.command.build_ext import build_ext20 19 21 20 try: … … 23 22 except ImportError: 24 23 pass 25 26 # Convert "test" argument to "pytest" so 'python setup.py test' works27 sys.argv = [("pytest" if s == "test" else s) for s in sys.argv]28 24 29 25 # Manage version number ###################################### … … 250 246 # sas.sascalc.calculator 251 247 gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions") 248 package_dir["sas.sascalc.calculator.core"] = gen_dir 252 249 package_dir["sas.sascalc.calculator"] = os.path.join( 253 250 "src", "sas", "sascalc", "calculator") 254 packages. append("sas.sascalc.calculator")255 ext_modules.append(Extension("sas.sascalc.calculator. _sld2i",251 packages.extend(["sas.sascalc.calculator", "sas.sascalc.calculator.core"]) 252 ext_modules.append(Extension("sas.sascalc.calculator.core.sld2i", 256 253 sources=[ 257 254 os.path.join(gen_dir, "sld2i_module.c"), … … 261 258 ], 262 259 include_dirs=[gen_dir], 263 )) 260 ) 261 ) 264 262 265 263 # sas.sascalc.pr 266 264 srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions") 265 package_dir["sas.sascalc.pr.core"] = srcdir 267 266 package_dir["sas.sascalc.pr"] = os.path.join("src", "sas", "sascalc", "pr") 268 packages. append("sas.sascalc.pr")269 ext_modules.append(Extension("sas.sascalc.pr. _pr_inversion",267 packages.extend(["sas.sascalc.pr", "sas.sascalc.pr.core"]) 268 ext_modules.append(Extension("sas.sascalc.pr.core.pr_inversion", 270 269 sources=[os.path.join(srcdir, "Cinvertor.c"), 271 270 os.path.join(srcdir, "invertor.c"), … … 277 276 # sas.sascalc.file_converter 278 277 mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext") 278 package_dir["sas.sascalc.file_converter.core"] = mydir 279 279 package_dir["sas.sascalc.file_converter"] = os.path.join( 280 280 "src", "sas", "sascalc", "file_converter") 281 packages.append("sas.sascalc.file_converter") 282 ext_modules.append(Extension("sas.sascalc.file_converter._bsl_loader", 281 packages.extend(["sas.sascalc.file_converter", 282 "sas.sascalc.file_converter.core"]) 283 ext_modules.append(Extension("sas.sascalc.file_converter.core.bsl_loader", 283 284 sources=[os.path.join(mydir, "bsl_loader.c")], 284 285 include_dirs=[np.get_include()], … … 442 443 cmdclass={'build_ext': build_ext_subclass, 443 444 'docs': BuildSphinxCommand, 444 'disable_openmp': DisableOpenMPCommand}, 445 setup_requires=['pytest-runner'] if 'pytest' in sys.argv else [], 446 tests_require=['pytest'], 445 'disable_openmp': DisableOpenMPCommand} 447 446 ) -
src/sas/sascalc/calculator/c_extensions/sld2i_module.c
r7ba6470 ra1daf86 2 2 SLD2I module to perform point and I calculations 3 3 */ 4 #include <Python.h> 4 5 #include <stdio.h> 5 6 //#define Py_LIMITED_API 0x030200007 #include <Python.h>8 9 6 #include "sld2i.h" 10 7 … … 16 13 #endif 17 14 18 // Vector binding glue 19 #if (PY_VERSION_HEX > 0x03000000) && !defined(Py_LIMITED_API) 20 // Assuming that a view into a writable vector points to a 21 // non-changing pointer for the duration of the C call, capture 22 // the view pointer and immediately free the view. 23 #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 24 Py_buffer VEC_view; \ 25 int VEC_err = PyObject_GetBuffer(VEC_obj, &VEC_view, PyBUF_WRITABLE|PyBUF_FORMAT); \ 26 if (VEC_err < 0 || sizeof(*VEC_buf) != VEC_view.itemsize) return NULL; \ 27 VEC_buf = (typeof(VEC_buf))VEC_view.buf; \ 28 VEC_len = VEC_view.len/sizeof(*VEC_buf); \ 29 PyBuffer_Release(&VEC_view); \ 30 } while (0) 31 #else 32 #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \ 33 int VEC_err = PyObject_AsWriteBuffer(VEC_obj, (void **)(&VEC_buf), &VEC_len); \ 34 if (VEC_err < 0) return NULL; \ 35 VEC_len /= sizeof(*VEC_buf); \ 36 } while (0) 37 #endif 15 16 // Utilities 17 #define INVECTOR(obj,buf,len) \ 18 do { \ 19 int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \ 20 if (err < 0) return NULL; \ 21 len /= sizeof(*buf); \ 22 } while (0) 23 24 #define OUTVECTOR(obj,buf,len) \ 25 do { \ 26 int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \ 27 if (err < 0) return NULL; \ 28 len /= sizeof(*buf); \ 29 } while (0) 30 38 31 39 32 /** … … 80 73 //printf("new GenI\n"); 81 74 if (!PyArg_ParseTuple(args, "iOOOOOOOOddd", &is_avg, &x_val_obj, &y_val_obj, &z_val_obj, &sldn_val_obj, &mx_val_obj, &my_val_obj, &mz_val_obj, &vol_pix_obj, &inspin, &outspin, &stheta)) return NULL; 82 VECTOR(x_val_obj, x_val, n_x);83 VECTOR(y_val_obj, y_val, n_y);84 VECTOR(z_val_obj, z_val, n_z);85 VECTOR(sldn_val_obj, sldn_val, n_sld);86 VECTOR(mx_val_obj, mx_val, n_mx);87 VECTOR(my_val_obj, my_val, n_my);88 VECTOR(mz_val_obj, mz_val, n_mz);89 VECTOR(vol_pix_obj, vol_pix, n_vol_pix);75 INVECTOR(x_val_obj, x_val, n_x); 76 INVECTOR(y_val_obj, y_val, n_y); 77 INVECTOR(z_val_obj, z_val, n_z); 78 INVECTOR(sldn_val_obj, sldn_val, n_sld); 79 INVECTOR(mx_val_obj, mx_val, n_mx); 80 INVECTOR(my_val_obj, my_val, n_my); 81 INVECTOR(mz_val_obj, mz_val, n_mz); 82 INVECTOR(vol_pix_obj, vol_pix, n_vol_pix); 90 83 sld2i = PyMem_Malloc(sizeof(GenI)); 91 84 //printf("sldi:%p\n", sld2i); … … 115 108 if (!PyArg_ParseTuple(args, "OOOO", &gen_obj, &qx_obj, &qy_obj, &I_out_obj)) return NULL; 116 109 sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 117 VECTOR(qx_obj, qx, n_qx);118 VECTOR(qy_obj, qy, n_qy);119 VECTOR(I_out_obj, I_out, n_out);110 INVECTOR(qx_obj, qx, n_qx); 111 INVECTOR(qy_obj, qy, n_qy); 112 OUTVECTOR(I_out_obj, I_out, n_out); 120 113 //printf("qx, qy, I_out: %d %d %d, %d %d %d\n", qx, qy, I_out, n_qx, n_qy, n_out); 121 114 … … 143 136 if (!PyArg_ParseTuple(args, "OOO", &gen_obj, &q_obj, &I_out_obj)) return NULL; 144 137 sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 145 VECTOR(q_obj, q, n_q);146 VECTOR(I_out_obj, I_out, n_out);138 INVECTOR(q_obj, q, n_q); 139 OUTVECTOR(I_out_obj, I_out, n_out); 147 140 148 141 // Sanity check … … 167 160 168 161 #define MODULE_DOC "Sld2i C Library" 169 #define MODULE_NAME " _sld2i"170 #define MODULE_INIT2 init _sld2i171 #define MODULE_INIT3 PyInit_ _sld2i162 #define MODULE_NAME "sld2i" 163 #define MODULE_INIT2 initsld2i 164 #define MODULE_INIT3 PyInit_sld2i 172 165 #define MODULE_METHODS module_methods 173 166 -
src/sas/sascalc/calculator/sas_gen.py
r952ea1f r144e032a 14 14 import numpy as np 15 15 16 from . import _sld2i16 from .core import sld2i as mod 17 17 from .BaseComponent import BaseComponent 18 18 … … 145 145 self.params['Up_frac_out'], 146 146 self.params['Up_theta']) 147 model = _sld2i.new_GenI(*args)147 model = mod.new_GenI(*args) 148 148 if len(qy): 149 149 qx, qy = _vec(qx), _vec(qy) 150 150 I_out = np.empty_like(qx) 151 151 #print("npoints", qx.shape, "npixels", pos_x.shape) 152 _sld2i.genicomXY(model, qx, qy, I_out)152 mod.genicomXY(model, qx, qy, I_out) 153 153 #print("I_out after", I_out) 154 154 else: 155 155 qx = _vec(qx) 156 156 I_out = np.empty_like(qx) 157 _sld2i.genicom(model, qx, I_out)157 mod.genicom(model, qx, I_out) 158 158 vol_correction = self.data_total_volume / self.params['total_volume'] 159 159 result = (self.params['scale'] * vol_correction * I_out … … 304 304 z_dir2 *= z_dir2 305 305 mask = (x_dir2 + y_dir2 + z_dir2) <= 1.0 306 except Exception as exc:307 logger.error( exc)306 except Exception: 307 logger.error(sys.exc_value) 308 308 self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], 309 309 self.pos_z[mask], self.sld_n[mask], … … 600 600 y_lines.append(y_line) 601 601 z_lines.append(z_line) 602 except Exception as exc:603 logger.error( exc)602 except Exception: 603 logger.error(sys.exc_value) 604 604 605 605 output = MagSLD(pos_x, pos_y, pos_z, sld_n, sld_mx, sld_my, sld_mz) … … 691 691 _vol_pix = float(toks[7]) 692 692 vol_pix = np.append(vol_pix, _vol_pix) 693 except Exception as exc:693 except Exception: 694 694 vol_pix = None 695 except Exception as exc:695 except Exception: 696 696 # Skip non-data lines 697 logger.error( exc)697 logger.error(sys.exc_value) 698 698 output = MagSLD(pos_x, pos_y, pos_z, sld_n, 699 699 sld_mx, sld_my, sld_mz) -
src/sas/sascalc/file_converter/bsl_loader.py
r952ea1f rf00691d4 1 from sas.sascalc.file_converter. _bsl_loader import CLoader1 from sas.sascalc.file_converter.core.bsl_loader import CLoader 2 2 from sas.sascalc.dataloader.data_info import Data2D 3 3 from copy import deepcopy … … 67 67 'swap_bytes': int(metadata[3]) 68 68 } 69 except Exception:69 except: 70 70 is_valid = False 71 71 err_msg = "Invalid metadata in header file for {}" -
src/sas/sascalc/file_converter/c_ext/bsl_loader.c
r952ea1f rd5aeaa3 1 #include <Python.h> 2 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 3 #include <numpy/arrayobject.h> 1 4 #include <stdio.h> 2 5 #include <stdlib.h> 3 4 //#define Py_LIMITED_API 0x03020000 5 #include <Python.h> 6 #include <structmember.h> 7 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 8 #include <numpy/arrayobject.h> 9 6 #include "structmember.h" 10 7 #include "bsl_loader.h" 11 8 … … 295 292 296 293 #define MODULE_DOC "C module for loading bsl." 297 #define MODULE_NAME " _bsl_loader"298 #define MODULE_INIT2 init _bsl_loader299 #define MODULE_INIT3 PyInit_ _bsl_loader294 #define MODULE_NAME "bsl_loader" 295 #define MODULE_INIT2 initbsl_loader 296 #define MODULE_INIT3 PyInit_bsl_loader 300 297 #define MODULE_METHODS module_methods 301 298 -
src/sas/sascalc/pr/c_extensions/Cinvertor.c
r7ba6470 ra52f32f 5 5 * 6 6 */ 7 #include <Python.h> 8 #include "structmember.h" 7 9 #include <stdio.h> 8 10 #include <stdlib.h> … … 10 12 #include <time.h> 11 13 12 //#define Py_LIMITED_API 0x0305000013 #include <Python.h>14 #include <structmember.h>15 16 // Vector binding glue17 #if (PY_VERSION_HEX > 0x03000000) && !defined(Py_LIMITED_API)18 // Assuming that a view into a writable vector points to a19 // non-changing pointer for the duration of the C call, capture20 // the view pointer and immediately free the view.21 #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \22 Py_buffer VEC_view; \23 int VEC_err = PyObject_GetBuffer(VEC_obj, &VEC_view, PyBUF_WRITABLE|PyBUF_FORMAT); \24 if (VEC_err < 0 || sizeof(*VEC_buf) != VEC_view.itemsize) return NULL; \25 VEC_buf = (typeof(VEC_buf))VEC_view.buf; \26 VEC_len = VEC_view.len/sizeof(*VEC_buf); \27 PyBuffer_Release(&VEC_view); \28 } while (0)29 #else30 #define VECTOR(VEC_obj, VEC_buf, VEC_len) do { \31 int VEC_err = PyObject_AsWriteBuffer(VEC_obj, (void **)(&VEC_buf), &VEC_len); \32 if (VEC_err < 0) return NULL; \33 VEC_len /= sizeof(*VEC_buf); \34 } while (0)35 #endif36 37 14 #include "invertor.h" 15 38 16 39 17 /// Error object for raised exceptions 40 18 PyObject * CinvertorError; 19 20 #define INVECTOR(obj,buf,len) \ 21 do { \ 22 int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \ 23 if (err < 0) return NULL; \ 24 len /= sizeof(*buf); \ 25 } while (0) 26 27 #define OUTVECTOR(obj,buf,len) \ 28 do { \ 29 int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \ 30 if (err < 0) return NULL; \ 31 len /= sizeof(*buf); \ 32 } while (0) 33 41 34 42 35 // Class definition … … 106 99 107 100 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 108 VECTOR(data_obj,data,ndata);101 OUTVECTOR(data_obj,data,ndata); 109 102 110 103 free(self->params.x); … … 138 131 139 132 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 140 VECTOR(data_obj, data, ndata);133 OUTVECTOR(data_obj, data, ndata); 141 134 142 135 // Check that the input array is large enough … … 171 164 172 165 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 173 VECTOR(data_obj,data,ndata);166 OUTVECTOR(data_obj,data,ndata); 174 167 175 168 free(self->params.y); … … 203 196 204 197 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 205 VECTOR(data_obj, data, ndata);198 OUTVECTOR(data_obj, data, ndata); 206 199 207 200 // Check that the input array is large enough … … 236 229 237 230 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 238 VECTOR(data_obj,data,ndata);231 OUTVECTOR(data_obj,data,ndata); 239 232 240 233 free(self->params.err); … … 268 261 269 262 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 270 VECTOR(data_obj, data, ndata);263 OUTVECTOR(data_obj, data, ndata); 271 264 272 265 // Check that the input array is large enough … … 524 517 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 525 518 526 VECTOR(data_obj,pars,npars);519 OUTVECTOR(data_obj,pars,npars); 527 520 528 521 // PyList of residuals … … 575 568 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 576 569 577 VECTOR(data_obj,pars,npars);570 OUTVECTOR(data_obj,pars,npars); 578 571 579 572 // Should create this list only once and refill it … … 616 609 617 610 if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 618 VECTOR(data_obj,pars,npars);611 OUTVECTOR(data_obj,pars,npars); 619 612 620 613 iq_value = iq(pars, self->params.d_max, (int)npars, q); … … 641 634 642 635 if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 643 VECTOR(data_obj,pars,npars);636 OUTVECTOR(data_obj,pars,npars); 644 637 645 638 iq_value = iq_smeared(pars, self->params.d_max, (int)npars, … … 666 659 667 660 if (!PyArg_ParseTuple(args, "Od", &data_obj, &r)) return NULL; 668 VECTOR(data_obj,pars,npars);661 OUTVECTOR(data_obj,pars,npars); 669 662 670 663 pr_value = pr(pars, self->params.d_max, (int)npars, r); … … 693 686 694 687 if (!PyArg_ParseTuple(args, "OOd", &data_obj, &err_obj, &r)) return NULL; 695 VECTOR(data_obj,pars,npars);688 OUTVECTOR(data_obj,pars,npars); 696 689 697 690 if (err_obj == Py_None) { … … 699 692 pr_err_value = 0.0; 700 693 } else { 701 VECTOR(err_obj,pars_err,npars2);694 OUTVECTOR(err_obj,pars_err,npars2); 702 695 pr_err(pars, pars_err, self->params.d_max, (int)npars, r, &pr_value, &pr_err_value); 703 696 } … … 733 726 734 727 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 735 VECTOR(data_obj,pars,npars);728 OUTVECTOR(data_obj,pars,npars); 736 729 737 730 oscill = reg_term(pars, self->params.d_max, (int)npars, 100); … … 754 747 755 748 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 756 VECTOR(data_obj,pars,npars);749 OUTVECTOR(data_obj,pars,npars); 757 750 758 751 count = npeaks(pars, self->params.d_max, (int)npars, 100); … … 775 768 776 769 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 777 VECTOR(data_obj,pars,npars);770 OUTVECTOR(data_obj,pars,npars); 778 771 779 772 fraction = positive_integral(pars, self->params.d_max, (int)npars, 100); … … 799 792 800 793 if (!PyArg_ParseTuple(args, "OO", &data_obj, &err_obj)) return NULL; 801 VECTOR(data_obj,pars,npars);802 VECTOR(err_obj,pars_err,npars2);794 OUTVECTOR(data_obj,pars,npars); 795 OUTVECTOR(err_obj,pars_err,npars2); 803 796 804 797 fraction = positive_errors(pars, pars_err, self->params.d_max, (int)npars, 51); … … 820 813 821 814 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 822 VECTOR(data_obj,pars,npars);815 OUTVECTOR(data_obj,pars,npars); 823 816 824 817 value = rg(pars, self->params.d_max, (int)npars, 101); … … 840 833 841 834 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 842 VECTOR(data_obj,pars,npars);835 OUTVECTOR(data_obj,pars,npars); 843 836 844 837 value = 4.0*acos(-1.0)*int_pr(pars, self->params.d_max, (int)npars, 101); … … 881 874 882 875 if (!PyArg_ParseTuple(args, "iiOO", &nfunc, &nr, &a_obj, &b_obj)) return NULL; 883 VECTOR(a_obj,a,n_a);884 VECTOR(b_obj,b,n_b);876 OUTVECTOR(a_obj,a,n_a); 877 OUTVECTOR(b_obj,b,n_b); 885 878 886 879 assert(n_b>=nfunc); … … 954 947 955 948 if (!PyArg_ParseTuple(args, "iiOO", &nfunc, &nr, &a_obj, &cov_obj)) return NULL; 956 VECTOR(a_obj,a,n_a);957 VECTOR(cov_obj,inv_cov,n_cov);949 OUTVECTOR(a_obj,a,n_a); 950 OUTVECTOR(cov_obj,inv_cov,n_cov); 958 951 959 952 assert(n_cov>=nfunc*nfunc); … … 988 981 989 982 if (!PyArg_ParseTuple(args, "iiO", &nfunc, &nr, &a_obj)) return NULL; 990 VECTOR(a_obj,a,n_a);983 OUTVECTOR(a_obj,a,n_a); 991 984 992 985 assert(n_a>=nfunc*(nr+self->params.npoints)); … … 1128 1121 1129 1122 #define MODULE_DOC "C extension module for inversion to P(r)." 1130 #define MODULE_NAME " _pr_inversion"1131 #define MODULE_INIT2 init _pr_inversion1132 #define MODULE_INIT3 PyInit_ _pr_inversion1123 #define MODULE_NAME "pr_inversion" 1124 #define MODULE_INIT2 initpr_inversion 1125 #define MODULE_INIT3 PyInit_pr_inversion 1133 1126 #define MODULE_METHODS module_methods 1134 1127 -
src/sas/sascalc/pr/fit/BumpsFitting.py
r3e6829d r9a5097c 2 2 BumpsFitting module runs the bumps optimizer. 3 3 """ 4 from __future__ import division5 6 4 import os 7 5 from datetime import timedelta, datetime … … 36 34 class Progress(object): 37 35 def __init__(self, history, max_step, pars, dof): 38 remaining_time = int(history.time[0]*( max_step/history.step[0]-1))36 remaining_time = int(history.time[0]*(float(max_step)/history.step[0]-1)) 39 37 # Depending on the time remaining, either display the expected 40 38 # time of completion, or the amount of time remaining. Use precision -
src/sas/sascalc/pr/fit/Loader.py
r57e48ca r574adc7 1 """2 class Loader to load any kind of file3 """4 5 1 from __future__ import print_function 6 2 3 # class Loader to load any king of file 4 #import wx 5 #import string 7 6 import numpy as np 8 7 -
src/sas/sascalc/pr/invertor.py
r57e48ca r2469df7 6 6 FIXME: The way the Invertor interacts with its C component should be cleaned up 7 7 """ 8 from __future__ import division9 8 10 9 import numpy as np … … 18 17 from numpy.linalg import lstsq 19 18 from scipy import optimize 20 from sas.sascalc.pr. _pr_inversion import Cinvertor19 from sas.sascalc.pr.core.pr_inversion import Cinvertor 21 20 22 21 logger = logging.getLogger(__name__) … … 72 71 A[j][i] = (Fourier transformed base function for point j) 73 72 74 We the nchoose a number of r-points, n_r, to evaluate the second73 We them choose a number of r-points, n_r, to evaluate the second 75 74 derivative of P(r) at. This is used as our regularization term. 76 75 For a vector r of length n_r, the following n_r rows are set to :: … … 145 144 x, y, err, d_max, q_min, q_max and alpha 146 145 """ 147 if name == 'x':146 if name == 'x': 148 147 if 0.0 in value: 149 148 msg = "Invertor: one of your q-values is zero. " … … 269 268 A[i][j] = (Fourier transformed base function for point j) 270 269 271 We the nchoose a number of r-points, n_r, to evaluate the second270 We them choose a number of r-points, n_r, to evaluate the second 272 271 derivative of P(r) at. This is used as our regularization term. 273 272 For a vector r of length n_r, the following n_r rows are set to :: … … 417 416 A[i][j] = (Fourier transformed base function for point j) 418 417 419 We the nchoose a number of r-points, n_r, to evaluate the second418 We them choose a number of r-points, n_r, to evaluate the second 420 419 derivative of P(r) at. This is used as our regularization term. 421 420 For a vector r of length n_r, the following n_r rows are set to :: … … 474 473 475 474 # Perform the inversion (least square fit) 476 c, chi2, _, _ = lstsq(a, b , rcond=-1)475 c, chi2, _, _ = lstsq(a, b) 477 476 # Sanity check 478 477 try: … … 497 496 try: 498 497 cov = np.linalg.pinv(inv_cov) 499 err = math.fabs(chi2 / (npts - nfunc)) * cov500 except Exception as exc:498 err = math.fabs(chi2 / float(npts - nfunc)) * cov 499 except: 501 500 # We were not able to estimate the errors 502 501 # Return an empty error matrix 503 logger.error( exc)502 logger.error(sys.exc_value) 504 503 505 504 # Keep a copy of the last output … … 538 537 539 538 """ 540 from .num_term import NTermEstimator539 from num_term import NTermEstimator 541 540 estimator = NTermEstimator(self.clone()) 542 541 try: 543 542 return estimator.num_terms(isquit_func) 544 except Exception as exc:543 except: 545 544 # If we fail, estimate alpha and return the default 546 545 # number of terms 547 546 best_alpha, _, _ = self.estimate_alpha(self.nfunc) 548 logger.warning("Invertor.estimate_numterms: %s" % exc)547 logger.warning("Invertor.estimate_numterms: %s" % sys.exc_value) 549 548 return self.nfunc, best_alpha, "Could not estimate number of terms" 550 549 … … 632 631 return best_alpha, message, elapsed 633 632 634 except Exception as exc:635 message = "Invertor.estimate_alpha: %s" % exc633 except: 634 message = "Invertor.estimate_alpha: %s" % sys.exc_value 636 635 return 0, message, elapsed 637 636 … … 749 748 self.cov[i][i] = float(toks2[1]) 750 749 751 except Exception as exc:752 msg = "Invertor.from_file: corrupted file\n%s" % exc750 except: 751 msg = "Invertor.from_file: corrupted file\n%s" % sys.exc_value 753 752 raise RuntimeError(msg) 754 753 else: -
src/sas/sascalc/pr/num_term.py
r3e6829d r2469df7 1 from __future__ import print_function , division1 from __future__ import print_function 2 2 3 3 import math … … 51 51 osc = self.sort_osc() 52 52 dv = len(osc) 53 med = 0.5*dv53 med = float(dv) / 2.0 54 54 odd = self.is_odd(dv) 55 55 medi = 0 … … 140 140 nts = self.compare_err() 141 141 div = len(nts) 142 tem = 0.5*div142 tem = float(div) / 2.0 143 143 if self.is_odd(div): 144 144 nt = nts[int(tem)]
Note: See TracChangeset
for help on using the changeset viewer.