Changeset 1580cc3 in sasview
- Timestamp:
- Nov 13, 2018 2:52:30 PM (6 years ago)
- Branches:
- ticket-1094-headless
- Children:
- ffbf35ee
- Parents:
- 1dc134e6 (diff), f560e23 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 2 added
- 3 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
docs/sphinx-docs/source/user/RELEASE.rst
r9849f8a r67ed543 60 60 * An error in the be_polyelectrolyte model was identified and rectified, but 61 61 the fix is yet to be validated. 62 * (Added post-release) An error with the reporting of the scale parameter 63 from the spinodal model was rectified. 62 64 * A number of issues and inconsistencies with the creation of 63 65 sum|multiply models have been rectified. … … 187 189 * Fixes #1010: Win64 build script not creating working executable 188 190 * Fixes #1011: sld_test failing on ubuntu 189 * Fixes #1012: ESS GUI not updating after fitting190 191 * Fixes #1013: FileReaderBaseClass output[] not reset - same file loaded multiple times 191 192 * Fixes #1018: add Boltzmann distribution … … 233 234 * Fixes #1179: PDF Report should contain SasView Version Number 234 235 * Fixes #1183: Test from creating new model reset all parameters to default in all open FitPages 236 * Fixes #1188: fitpage hangs if change model while magnetism is on 237 * Fixes #1191: Correct erroneous Scale reported by Spinodal model 235 238 236 239 **It is recommended that all users upgrade to this version, but your … … 868 871 found and corrected, corrected versions will be uploaded to the 869 872 marketplace. 873 * (Added after Release 4.2.0) The scale parameter reported from the spinodal 874 model is the square root of the true value. 870 875 871 876 3.1- All systems -
installers/license.txt
r73c51df rc6a4d143 8 8 Participating facilities include (in alphabetical order): 9 9 the Australian National Science & Technology Centre for Neutron 10 Scattering, the Diamond Light Source, the European Spallation Source, 11 the Institut Laue Langevin, the ISIS Pulsed Neutron & Muon Source, 12 the National Institute of Standards & Technology Center for Neutron 13 Research, the Oak Ridge National Laboratory Neutron Sciences 14 Directorate, and the Technical University Delft Reactor Institute. 10 Scattering, the Bundesanstalt fur Materialforschung und prufung, the 11 Diamond Light Source, the European Spallation Source, the Institut 12 Laue Langevin, the ISIS Pulsed Neutron & Muon Source, the National 13 Institute of Standards & Technology Center for Neutron Research, 14 the Oak Ridge National Laboratory Neutron Sciences Directorate, 15 and the Technical University Delft Reactor Institute. 15 16 16 17 SasView is distributed under a 'Three-clause' BSD licence which you -
run.py
r3388337 r1580cc3 95 95 try: 96 96 import periodictable 97 except :97 except ImportError: 98 98 addpath(joinpath(root, '..', 'periodictable')) 99 99 100 100 try: 101 101 import bumps 102 except :102 except ImportError: 103 103 addpath(joinpath(root, '..', 'bumps')) 104 104 105 105 try: 106 106 import tinycc 107 except :107 except ImportError: 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 <<<<<<< HEAD 113 114 # Build project if the build directory does not already exist. 114 115 # PAK: with "update" we can always build since it is fast 115 116 if rebuild or not os.path.exists(build_path): 117 ======= 118 # Put the sas source tree on the path 119 addpath(joinpath(root, 'src')) 120 121 # Put sasmodels on the path 122 addpath(joinpath(root, '../sasmodels/')) 123 124 # Check if the C extensions are already built 125 try: 126 from sas.sascalc.pr import _pr_inversion 127 from sas.sascalc.calculator import _sld2i 128 from sas.sascalc.file_converter import _bsl_loader 129 except ImportError: 130 rebuild = True 131 132 # Build C extensions if necessary. Do an inplace build to simplify path. 133 if rebuild: 134 >>>>>>> master 116 135 import subprocess 117 build_cmd = [sys.executable, "setup.py", "build ", "update"]136 build_cmd = [sys.executable, "setup.py", "build_ext", "--inplace", "update"] 118 137 if os.name == 'nt': 119 138 build_cmd.append('--compiler=tinycc') … … 122 141 with cd(root): 123 142 subprocess.call(build_cmd, shell=shell) 124 125 # Put the source trees on the path126 addpath(joinpath(root, 'src'))127 128 # sasmodels on the path129 addpath(joinpath(root, '../sasmodels/'))130 131 # The sas.models package Compiled Model files should be pulled in from the build directory even though132 # 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.pr137 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_converter143 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.calculator147 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)151 143 152 144 set_git_tag() -
setup.py
rc16172d r952ea1f 12 12 import shutil 13 13 import sys 14 from distutils.command.build_ext import build_ext15 from distutils.core import Command16 14 17 15 import numpy as np 16 18 17 from setuptools import Extension, setup 18 from setuptools import Command 19 from setuptools.command.build_ext import build_ext 19 20 20 21 try: … … 22 23 except ImportError: 23 24 pass 25 26 # Convert "test" argument to "pytest" so 'python setup.py test' works 27 sys.argv = [("pytest" if s == "test" else s) for s in sys.argv] 24 28 25 29 # Manage version number ###################################### … … 246 250 # sas.sascalc.calculator 247 251 gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions") 248 package_dir["sas.sascalc.calculator.core"] = gen_dir249 252 package_dir["sas.sascalc.calculator"] = os.path.join( 250 253 "src", "sas", "sascalc", "calculator") 251 packages. extend(["sas.sascalc.calculator", "sas.sascalc.calculator.core"])252 ext_modules.append(Extension("sas.sascalc.calculator. core.sld2i",254 packages.append("sas.sascalc.calculator") 255 ext_modules.append(Extension("sas.sascalc.calculator._sld2i", 253 256 sources=[ 254 257 os.path.join(gen_dir, "sld2i_module.c"), … … 258 261 ], 259 262 include_dirs=[gen_dir], 260 ) 261 ) 263 )) 262 264 263 265 # sas.sascalc.pr 264 266 srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions") 265 package_dir["sas.sascalc.pr.core"] = srcdir266 267 package_dir["sas.sascalc.pr"] = os.path.join("src", "sas", "sascalc", "pr") 267 packages. extend(["sas.sascalc.pr", "sas.sascalc.pr.core"])268 ext_modules.append(Extension("sas.sascalc.pr. core.pr_inversion",268 packages.append("sas.sascalc.pr") 269 ext_modules.append(Extension("sas.sascalc.pr._pr_inversion", 269 270 sources=[os.path.join(srcdir, "Cinvertor.c"), 270 271 os.path.join(srcdir, "invertor.c"), … … 276 277 # sas.sascalc.file_converter 277 278 mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext") 278 package_dir["sas.sascalc.file_converter.core"] = mydir279 279 package_dir["sas.sascalc.file_converter"] = os.path.join( 280 280 "src", "sas", "sascalc", "file_converter") 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", 281 packages.append("sas.sascalc.file_converter") 282 ext_modules.append(Extension("sas.sascalc.file_converter._bsl_loader", 284 283 sources=[os.path.join(mydir, "bsl_loader.c")], 285 284 include_dirs=[np.get_include()], … … 443 442 cmdclass={'build_ext': build_ext_subclass, 444 443 'docs': BuildSphinxCommand, 445 'disable_openmp': DisableOpenMPCommand} 444 'disable_openmp': DisableOpenMPCommand}, 445 setup_requires=['pytest-runner'] if 'pytest' in sys.argv else [], 446 tests_require=['pytest'], 446 447 ) -
src/sas/sascalc/calculator/c_extensions/sld2i_module.c
ra1daf86 r7ba6470 2 2 SLD2I module to perform point and I calculations 3 3 */ 4 #include <stdio.h> 5 6 //#define Py_LIMITED_API 0x03020000 4 7 #include <Python.h> 5 #include <stdio.h> 8 6 9 #include "sld2i.h" 7 10 … … 13 16 #endif 14 17 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 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 31 38 32 39 /** … … 73 80 //printf("new GenI\n"); 74 81 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; 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);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); 83 90 sld2i = PyMem_Malloc(sizeof(GenI)); 84 91 //printf("sldi:%p\n", sld2i); … … 108 115 if (!PyArg_ParseTuple(args, "OOOO", &gen_obj, &qx_obj, &qy_obj, &I_out_obj)) return NULL; 109 116 sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 110 INVECTOR(qx_obj, qx, n_qx);111 INVECTOR(qy_obj, qy, n_qy);112 OUTVECTOR(I_out_obj, I_out, n_out);117 VECTOR(qx_obj, qx, n_qx); 118 VECTOR(qy_obj, qy, n_qy); 119 VECTOR(I_out_obj, I_out, n_out); 113 120 //printf("qx, qy, I_out: %d %d %d, %d %d %d\n", qx, qy, I_out, n_qx, n_qy, n_out); 114 121 … … 136 143 if (!PyArg_ParseTuple(args, "OOO", &gen_obj, &q_obj, &I_out_obj)) return NULL; 137 144 sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 138 INVECTOR(q_obj, q, n_q);139 OUTVECTOR(I_out_obj, I_out, n_out);145 VECTOR(q_obj, q, n_q); 146 VECTOR(I_out_obj, I_out, n_out); 140 147 141 148 // Sanity check … … 160 167 161 168 #define MODULE_DOC "Sld2i C Library" 162 #define MODULE_NAME " sld2i"163 #define MODULE_INIT2 init sld2i164 #define MODULE_INIT3 PyInit_ sld2i169 #define MODULE_NAME "_sld2i" 170 #define MODULE_INIT2 init_sld2i 171 #define MODULE_INIT3 PyInit__sld2i 165 172 #define MODULE_METHODS module_methods 166 173 -
src/sas/sascalc/calculator/sas_gen.py
r144e032a r952ea1f 14 14 import numpy as np 15 15 16 from . core import sld2i as mod16 from . import _sld2i 17 17 from .BaseComponent import BaseComponent 18 18 … … 145 145 self.params['Up_frac_out'], 146 146 self.params['Up_theta']) 147 model = mod.new_GenI(*args)147 model = _sld2i.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 mod.genicomXY(model, qx, qy, I_out)152 _sld2i.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 mod.genicom(model, qx, I_out)157 _sld2i.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 :307 logger.error( sys.exc_value)306 except Exception as exc: 307 logger.error(exc) 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 :603 logger.error( sys.exc_value)602 except Exception as exc: 603 logger.error(exc) 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 :693 except Exception as exc: 694 694 vol_pix = None 695 except Exception :695 except Exception as exc: 696 696 # Skip non-data lines 697 logger.error( sys.exc_value)697 logger.error(exc) 698 698 output = MagSLD(pos_x, pos_y, pos_z, sld_n, 699 699 sld_mx, sld_my, sld_mz) -
src/sas/sascalc/dataloader/file_reader_base_class.py
r4a8d55c rfee520ec 276 276 dataset.xmax = np.max(dataset.qx_data) 277 277 dataset.ymin = np.min(dataset.qy_data) 278 dataset.ymax = np.max(dataset.q x_data)278 dataset.ymax = np.max(dataset.qy_data) 279 279 280 280 def format_unit(self, unit=None): -
src/sas/sascalc/file_converter/bsl_loader.py
rf00691d4 r952ea1f 1 from sas.sascalc.file_converter. core.bsl_loader import CLoader1 from sas.sascalc.file_converter._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 :69 except Exception: 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
rd5aeaa3 r952ea1f 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 //#define Py_LIMITED_API 0x03020000 1 5 #include <Python.h> 6 #include <structmember.h> 2 7 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 3 8 #include <numpy/arrayobject.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include "structmember.h" 9 7 10 #include "bsl_loader.h" 8 11 … … 292 295 293 296 #define MODULE_DOC "C module for loading bsl." 294 #define MODULE_NAME " bsl_loader"295 #define MODULE_INIT2 init bsl_loader296 #define MODULE_INIT3 PyInit_ bsl_loader297 #define MODULE_NAME "_bsl_loader" 298 #define MODULE_INIT2 init_bsl_loader 299 #define MODULE_INIT3 PyInit__bsl_loader 297 300 #define MODULE_METHODS module_methods 298 301 -
src/sas/sascalc/pr/c_extensions/Cinvertor.c
ra52f32f r7ba6470 5 5 * 6 6 */ 7 #include <Python.h>8 #include "structmember.h"9 7 #include <stdio.h> 10 8 #include <stdlib.h> … … 12 10 #include <time.h> 13 11 12 //#define Py_LIMITED_API 0x03050000 13 #include <Python.h> 14 #include <structmember.h> 15 16 // Vector binding glue 17 #if (PY_VERSION_HEX > 0x03000000) && !defined(Py_LIMITED_API) 18 // Assuming that a view into a writable vector points to a 19 // non-changing pointer for the duration of the C call, capture 20 // 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 #else 30 #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 #endif 36 14 37 #include "invertor.h" 15 16 38 17 39 /// Error object for raised exceptions 18 40 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 34 41 35 42 // Class definition … … 99 106 100 107 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 101 OUTVECTOR(data_obj,data,ndata);108 VECTOR(data_obj,data,ndata); 102 109 103 110 free(self->params.x); … … 131 138 132 139 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 133 OUTVECTOR(data_obj, data, ndata);140 VECTOR(data_obj, data, ndata); 134 141 135 142 // Check that the input array is large enough … … 164 171 165 172 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 166 OUTVECTOR(data_obj,data,ndata);173 VECTOR(data_obj,data,ndata); 167 174 168 175 free(self->params.y); … … 196 203 197 204 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 198 OUTVECTOR(data_obj, data, ndata);205 VECTOR(data_obj, data, ndata); 199 206 200 207 // Check that the input array is large enough … … 229 236 230 237 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 231 OUTVECTOR(data_obj,data,ndata);238 VECTOR(data_obj,data,ndata); 232 239 233 240 free(self->params.err); … … 261 268 262 269 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 263 OUTVECTOR(data_obj, data, ndata);270 VECTOR(data_obj, data, ndata); 264 271 265 272 // Check that the input array is large enough … … 517 524 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 518 525 519 OUTVECTOR(data_obj,pars,npars);526 VECTOR(data_obj,pars,npars); 520 527 521 528 // PyList of residuals … … 568 575 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 569 576 570 OUTVECTOR(data_obj,pars,npars);577 VECTOR(data_obj,pars,npars); 571 578 572 579 // Should create this list only once and refill it … … 609 616 610 617 if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 611 OUTVECTOR(data_obj,pars,npars);618 VECTOR(data_obj,pars,npars); 612 619 613 620 iq_value = iq(pars, self->params.d_max, (int)npars, q); … … 634 641 635 642 if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 636 OUTVECTOR(data_obj,pars,npars);643 VECTOR(data_obj,pars,npars); 637 644 638 645 iq_value = iq_smeared(pars, self->params.d_max, (int)npars, … … 659 666 660 667 if (!PyArg_ParseTuple(args, "Od", &data_obj, &r)) return NULL; 661 OUTVECTOR(data_obj,pars,npars);668 VECTOR(data_obj,pars,npars); 662 669 663 670 pr_value = pr(pars, self->params.d_max, (int)npars, r); … … 686 693 687 694 if (!PyArg_ParseTuple(args, "OOd", &data_obj, &err_obj, &r)) return NULL; 688 OUTVECTOR(data_obj,pars,npars);695 VECTOR(data_obj,pars,npars); 689 696 690 697 if (err_obj == Py_None) { … … 692 699 pr_err_value = 0.0; 693 700 } else { 694 OUTVECTOR(err_obj,pars_err,npars2);701 VECTOR(err_obj,pars_err,npars2); 695 702 pr_err(pars, pars_err, self->params.d_max, (int)npars, r, &pr_value, &pr_err_value); 696 703 } … … 726 733 727 734 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 728 OUTVECTOR(data_obj,pars,npars);735 VECTOR(data_obj,pars,npars); 729 736 730 737 oscill = reg_term(pars, self->params.d_max, (int)npars, 100); … … 747 754 748 755 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 749 OUTVECTOR(data_obj,pars,npars);756 VECTOR(data_obj,pars,npars); 750 757 751 758 count = npeaks(pars, self->params.d_max, (int)npars, 100); … … 768 775 769 776 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 770 OUTVECTOR(data_obj,pars,npars);777 VECTOR(data_obj,pars,npars); 771 778 772 779 fraction = positive_integral(pars, self->params.d_max, (int)npars, 100); … … 792 799 793 800 if (!PyArg_ParseTuple(args, "OO", &data_obj, &err_obj)) return NULL; 794 OUTVECTOR(data_obj,pars,npars);795 OUTVECTOR(err_obj,pars_err,npars2);801 VECTOR(data_obj,pars,npars); 802 VECTOR(err_obj,pars_err,npars2); 796 803 797 804 fraction = positive_errors(pars, pars_err, self->params.d_max, (int)npars, 51); … … 813 820 814 821 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 815 OUTVECTOR(data_obj,pars,npars);822 VECTOR(data_obj,pars,npars); 816 823 817 824 value = rg(pars, self->params.d_max, (int)npars, 101); … … 833 840 834 841 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 835 OUTVECTOR(data_obj,pars,npars);842 VECTOR(data_obj,pars,npars); 836 843 837 844 value = 4.0*acos(-1.0)*int_pr(pars, self->params.d_max, (int)npars, 101); … … 874 881 875 882 if (!PyArg_ParseTuple(args, "iiOO", &nfunc, &nr, &a_obj, &b_obj)) return NULL; 876 OUTVECTOR(a_obj,a,n_a);877 OUTVECTOR(b_obj,b,n_b);883 VECTOR(a_obj,a,n_a); 884 VECTOR(b_obj,b,n_b); 878 885 879 886 assert(n_b>=nfunc); … … 947 954 948 955 if (!PyArg_ParseTuple(args, "iiOO", &nfunc, &nr, &a_obj, &cov_obj)) return NULL; 949 OUTVECTOR(a_obj,a,n_a);950 OUTVECTOR(cov_obj,inv_cov,n_cov);956 VECTOR(a_obj,a,n_a); 957 VECTOR(cov_obj,inv_cov,n_cov); 951 958 952 959 assert(n_cov>=nfunc*nfunc); … … 981 988 982 989 if (!PyArg_ParseTuple(args, "iiO", &nfunc, &nr, &a_obj)) return NULL; 983 OUTVECTOR(a_obj,a,n_a);990 VECTOR(a_obj,a,n_a); 984 991 985 992 assert(n_a>=nfunc*(nr+self->params.npoints)); … … 1121 1128 1122 1129 #define MODULE_DOC "C extension module for inversion to P(r)." 1123 #define MODULE_NAME " pr_inversion"1124 #define MODULE_INIT2 init pr_inversion1125 #define MODULE_INIT3 PyInit_ pr_inversion1130 #define MODULE_NAME "_pr_inversion" 1131 #define MODULE_INIT2 init_pr_inversion 1132 #define MODULE_INIT3 PyInit__pr_inversion 1126 1133 #define MODULE_METHODS module_methods 1127 1134 -
src/sas/sascalc/pr/fit/BumpsFitting.py
r9a5097c r3e6829d 2 2 BumpsFitting module runs the bumps optimizer. 3 3 """ 4 from __future__ import division 5 4 6 import os 5 7 from datetime import timedelta, datetime … … 34 36 class Progress(object): 35 37 def __init__(self, history, max_step, pars, dof): 36 remaining_time = int(history.time[0]*( float(max_step)/history.step[0]-1))38 remaining_time = int(history.time[0]*(max_step/history.step[0]-1)) 37 39 # Depending on the time remaining, either display the expected 38 40 # time of completion, or the amount of time remaining. Use precision -
src/sas/sascalc/pr/fit/Loader.py
r574adc7 r57e48ca 1 """ 2 class Loader to load any kind of file 3 """ 4 1 5 from __future__ import print_function 2 6 3 # class Loader to load any king of file4 #import wx5 #import string6 7 import numpy as np 7 8 -
src/sas/sascalc/pr/invertor.py
r2469df7 r57e48ca 6 6 FIXME: The way the Invertor interacts with its C component should be cleaned up 7 7 """ 8 from __future__ import division 8 9 9 10 import numpy as np … … 17 18 from numpy.linalg import lstsq 18 19 from scipy import optimize 19 from sas.sascalc.pr. core.pr_inversion import Cinvertor20 from sas.sascalc.pr._pr_inversion import Cinvertor 20 21 21 22 logger = logging.getLogger(__name__) … … 71 72 A[j][i] = (Fourier transformed base function for point j) 72 73 73 We the mchoose a number of r-points, n_r, to evaluate the second74 We then choose a number of r-points, n_r, to evaluate the second 74 75 derivative of P(r) at. This is used as our regularization term. 75 76 For a vector r of length n_r, the following n_r rows are set to :: … … 144 145 x, y, err, d_max, q_min, q_max and alpha 145 146 """ 146 if 147 if name == 'x': 147 148 if 0.0 in value: 148 149 msg = "Invertor: one of your q-values is zero. " … … 268 269 A[i][j] = (Fourier transformed base function for point j) 269 270 270 We the mchoose a number of r-points, n_r, to evaluate the second271 We then choose a number of r-points, n_r, to evaluate the second 271 272 derivative of P(r) at. This is used as our regularization term. 272 273 For a vector r of length n_r, the following n_r rows are set to :: … … 416 417 A[i][j] = (Fourier transformed base function for point j) 417 418 418 We the mchoose a number of r-points, n_r, to evaluate the second419 We then choose a number of r-points, n_r, to evaluate the second 419 420 derivative of P(r) at. This is used as our regularization term. 420 421 For a vector r of length n_r, the following n_r rows are set to :: … … 473 474 474 475 # Perform the inversion (least square fit) 475 c, chi2, _, _ = lstsq(a, b )476 c, chi2, _, _ = lstsq(a, b, rcond=-1) 476 477 # Sanity check 477 478 try: … … 496 497 try: 497 498 cov = np.linalg.pinv(inv_cov) 498 err = math.fabs(chi2 / float(npts - nfunc)) * cov499 except :499 err = math.fabs(chi2 / (npts - nfunc)) * cov 500 except Exception as exc: 500 501 # We were not able to estimate the errors 501 502 # Return an empty error matrix 502 logger.error( sys.exc_value)503 logger.error(exc) 503 504 504 505 # Keep a copy of the last output … … 537 538 538 539 """ 539 from num_term import NTermEstimator540 from .num_term import NTermEstimator 540 541 estimator = NTermEstimator(self.clone()) 541 542 try: 542 543 return estimator.num_terms(isquit_func) 543 except :544 except Exception as exc: 544 545 # If we fail, estimate alpha and return the default 545 546 # number of terms 546 547 best_alpha, _, _ = self.estimate_alpha(self.nfunc) 547 logger.warning("Invertor.estimate_numterms: %s" % sys.exc_value)548 logger.warning("Invertor.estimate_numterms: %s" % exc) 548 549 return self.nfunc, best_alpha, "Could not estimate number of terms" 549 550 … … 631 632 return best_alpha, message, elapsed 632 633 633 except :634 message = "Invertor.estimate_alpha: %s" % sys.exc_value634 except Exception as exc: 635 message = "Invertor.estimate_alpha: %s" % exc 635 636 return 0, message, elapsed 636 637 … … 748 749 self.cov[i][i] = float(toks2[1]) 749 750 750 except :751 msg = "Invertor.from_file: corrupted file\n%s" % sys.exc_value751 except Exception as exc: 752 msg = "Invertor.from_file: corrupted file\n%s" % exc 752 753 raise RuntimeError(msg) 753 754 else: -
src/sas/sascalc/pr/num_term.py
r2469df7 r3e6829d 1 from __future__ import print_function 1 from __future__ import print_function, division 2 2 3 3 import math … … 51 51 osc = self.sort_osc() 52 52 dv = len(osc) 53 med = float(dv) / 2.053 med = 0.5*dv 54 54 odd = self.is_odd(dv) 55 55 medi = 0 … … 140 140 nts = self.compare_err() 141 141 div = len(nts) 142 tem = float(div) / 2.0142 tem = 0.5*div 143 143 if self.is_odd(div): 144 144 nt = nts[int(tem)] -
src/sas/sasgui/perspectives/fitting/basepage.py
ra4a1ac9 r5323490 2884 2884 self.magnetic_on = True 2885 2885 button.SetLabel("Magnetic OFF") 2886 m_value = 1 .0e-062886 m_value = 1 2887 2887 for key in self.model.magnetic_params: 2888 2888 if key.count('M0') > 0: 2889 2889 self.model.setParam(key, m_value) 2890 m_value += 0.5 e-062890 m_value += 0.5 2891 2891 else: 2892 2892 self.magnetic_on = False -
src/sas/sasgui/perspectives/fitting/gpu_options.py
r388aefb r8e109f9 8 8 ''' 9 9 10 import json 11 import platform 10 12 import logging 11 13 import os 12 14 import sys 15 13 16 import wx 17 18 try: 19 import pyopencl as cl 20 except ImportError: 21 cl = None 22 14 23 import sasmodels 24 import sasmodels.model_test 25 import sasmodels.kernelcl 26 15 27 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 16 28 … … 169 181 clinfo = [] 170 182 platforms = [] 171 try: 172 import pyopencl as cl 173 platforms = cl.get_platforms() 174 except ImportError: 183 184 if cl is None: 175 185 logger.warn("Unable to import the pyopencl package. It may not " 176 186 "have been installed. If you wish to use OpenCL, try " 177 187 "running pip install --user pyopencl") 178 except cl.LogicError as err: 179 logger.warn("Unable to fetch the OpenCL platforms. This likely " 180 "means that the opencl drivers for your system are " 181 "not installed.") 182 logger.warn(err) 188 else: 189 try: 190 platforms = cl.get_platforms() 191 except cl.LogicError as err: 192 logger.warn("Unable to fetch the OpenCL platforms. This likely " 193 "means that the opencl drivers for your system are " 194 "not installed.") 195 logger.warn(err) 183 196 184 197 p_index = 0 … … 226 239 if "SAS_OPENCL" in os.environ: 227 240 del os.environ["SAS_OPENCL"] 228 229 #Sasmodels kernelcl doesn't exist when initiated with None 230 if 'sasmodels.kernelcl' in sys.modules: 231 sasmodels.kernelcl.ENV = None 232 233 reload(sasmodels.core) 241 sasmodels.kernelcl.reset_environment() 234 242 event.Skip() 235 243 … … 247 255 Run sasmodels check from here and report results from 248 256 """ 249 import json250 import platform251 #import sasmodels252 253 257 #The same block of code as for OK but it is needed if we want to have 254 258 #active response to Test button … … 261 265 if "SAS_OPENCL" in os.environ: 262 266 del os.environ["SAS_OPENCL"] 263 264 #Sasmodels kernelcl doesn't exist when initiated with None 265 if 'sasmodels.kernelcl' in sys.modules: 266 sasmodels.kernelcl.ENV = None 267 268 269 #Need to reload sasmodels.core module to account SAS_OPENCL = "None" 270 reload(sasmodels.core) 271 272 273 from sasmodels.model_test import model_tests 267 sasmodels.kernelcl.reset_environment() 274 268 275 269 try: 276 from sasmodels.kernelcl import environment 277 env = environment() 270 env = sasmodels.kernelcl.environment() 278 271 clinfo = [(ctx.devices[0].platform.vendor, 279 272 ctx.devices[0].platform.version, … … 282 275 ctx.devices[0].version) 283 276 for ctx in env.context] 284 except ImportError:277 except Exception: 285 278 clinfo = None 286 279 287 280 failures = [] 288 281 tests_completed = 0 289 for test in model_tests():282 for test in sasmodels.model_test.model_tests(): 290 283 try: 291 284 test() -
src/sas/sascalc/fit/BumpsFitting.py
r1386b2f r0aeba4e 2 2 BumpsFitting module runs the bumps optimizer. 3 3 """ 4 from __future__ import print_function 5 4 6 import os 5 7 from datetime import timedelta, datetime … … 9 11 10 12 from bumps import fitters 13 11 14 try: 12 15 from bumps.options import FIT_CONFIG 16 # Preserve bumps default fitter in case someone wants it later 17 BUMPS_DEFAULT_FITTER = FIT_CONFIG.selected_id 13 18 # Default bumps to use the Levenberg-Marquardt optimizer 14 19 FIT_CONFIG.selected_id = fitters.LevenbergMarquardtFit.id … … 17 22 except ImportError: 18 23 # CRUFT: Bumps changed its handling of fit options around 0.7.5.6 24 # Preserve bumps default fitter in case someone wants it later 25 BUMPS_DEFAULT_FITTER = fitters.FIT_DEFAULT 19 26 # Default bumps to use the Levenberg-Marquardt optimizer 20 27 fitters.FIT_DEFAULT = 'lm' … … 126 133 if initial_values is not None: 127 134 self._reset_pars(fitted, initial_values) 135 #print("constraints", constraints) 128 136 self.constraints = dict(constraints) 129 137 self.set_fitted(fitted) … … 222 230 def _setup(self): 223 231 exprs = {} 224 for M in self.models: 225 exprs.update((".".join((M.name, k)), v) for k, v in M.constraints.items()) 232 for model in self.models: 233 exprs.update((".".join((model.name, k)), v) 234 for k, v in model.constraints.items()) 226 235 if exprs: 227 symtab = dict((".".join(( M.name, k)), p)228 for Min self.models229 for k, p in M.parameters().items())236 symtab = dict((".".join((model.name, k)), p) 237 for model in self.models 238 for k, p in model.parameters().items()) 230 239 self.update = compile_constraints(symtab, exprs) 231 240 else: -
src/sas/sascalc/fit/pagestate.py
r863ac2c r1dc134e6 1 1 """ 2 2 Class that holds a fit page state 3 4 Pagestate fields reflect the names of the gui controls from the sasview 3.x 5 fit page, so they are somewhat difficult to interpret. 6 7 Pagestate attributes are as follows: 8 9 # =>name: desc indicates the attribute is derived 10 # name(xml): desc indicates the attribute name differs from the xml tag 11 12 # SasView version which saved the file 13 version: (4, 1, 2) from <fitting_plug_in version="major.minor.point"> 14 15 # Session information 16 group_id: unique id for fit page in running system (int) 17 => data_group_id: unique id for data item in running system (None) 18 19 # Data file 20 data: contents of <SASdata> (Data1D or Data2D) 21 data_name: filename + [num] (latex_smeared.xml [1]) 22 data_id: filename + [num] + timestamp (latex_smeared.xml [1]1523303027.73) 23 file: filename + [date time] (latex_smeared.xml [Apr 09 15:45]) 24 name: ?? (None) 25 npts: number of points (float) 26 enable2D: True if data is 2D (or if model is 2D and no data) 27 is_data: True (pagestate will not save if there is no data attached) 28 29 # Data weighting 30 dI_didata: True if dy = data.dy 31 dI_idata: True if dy = data.y 32 dI_noweight: True if dy = 1 33 dI_sqrdata: True if dy = sqrt(data.y) 34 35 # Data selection 36 qmax: maximum q (float) 37 qmin: minimum q (float) 38 => qmax_x: ?? (None) 39 => qmin_x: ?? (None) 40 41 # Resolution smearing 42 enable_smearer: True if use data.dx 43 disable_smearer: True if no smearing 44 pinhole_smearer: True if custom pinhole smear 45 slit_smearer: True if custom slit smear 46 dq_l: 2D resolution <dQp> 47 dq_r: 2D resolution <dQs> 48 dx_old: True for 3.x version of custom pinhole, which used dx_min rather 49 than dx_percent, with dx_percent interpreted as 100 * dx_percent/q[0] 50 dx_percent: custom pinhole resolution percentage 51 dxl: slit height for custom slit resolution 52 dxw: slit width for custom slit resolution 53 smearer: repr() for active smearer (None on load) 54 smear_type: None (None on load) 55 56 # Model selection 57 categorycombobox: model category 58 formfactorcombobox: model name (could be "[plug-in] name") 59 structurecombobox: structure factor model name (string or None or "None") 60 multi_factor: multiplicity (integer or None) 61 magnetic_on: True if model is magnetic (only for 2D data for now) 62 => model: active model object (None on load) 63 64 # Model parameters 65 # Parameter is a tuple with the following structure. The parentheses 66 # indicate xml attribute for the <parameter .../> tag: 67 # fitted(selected_to_fit): True if parameter is fitted 68 # name(name): display name for the parameter (string) 69 # value(value): displayed parameter value (string) 70 # => plusminus: '+/-' (constant string) 71 # => uncertainty: tuple 72 # (uncertainty_displayed): True if there is an uncertainty 73 # (uncertainty_value): displayed uncertainty (string) 74 # => lower: tuple 75 # (minimum_displayed): True if there is a lower bound 76 # (minimum_value): displayed lower bound (string) 77 # => upper: tuple 78 # (maximum_displayed): True if there is a upper bound 79 # (maximum_value): displayed upper bound (string) 80 # units(unit): displayed units 81 parameters: list of normal parameters 82 fixed_param: list of non-fitting parameters (nsigma, npts in dispersity) 83 fittable_param: list of fittable dispersity parameters (distribution width) 84 str_parameters: list of selection parameters (e.g, shell forms in spherical_sld) 85 orientation_params(orientation_parameters): list of orientation and 86 magnetic parameters (already included in parameters, so safe to ignore) 87 orientation_params_disp(dispersity_parameters): list of orientation 88 disperisty parameters (already included in fixed_param and 89 fittable_param so safe to ignore) 90 91 # Dispersity controls 92 enable_disp: True if dispersity parameters 93 disable_disp: True if no dispersity parameters 94 disp_obj_dict(disp_obj): {'parameter.width': 'dispersity distribution'} 95 values: {'parameter.width': [array distribution parameter values] } 96 weights: {'parameter.width': [array distribution parameter weights] } 97 => disp_box 0 98 => disp_cb_dict {} 99 => disp_list [] 100 101 # Simultaneous fitting 102 103 => images: None (initialized but unused?) 104 => reset: False (initialized but unused?) 105 => event_owner None 106 => m_name None 107 => manager None 108 => page_name 109 => param_toFit: [] 110 => process: list of process done on object [] (maybe managed by guiframe?) 111 => saved_states {} 112 => cb1: False (simfit cb1 is now stored in select_all) 113 114 tcChi 1.3463 115 theory_data None 116 timestamp 1523303103.74 117 118 Constraint attributes are as follows: 119 120 constraint_dict {} 121 constraints_list 122 {'model_cbox': 'M2', 'param_cbox': 'scale', 'egal_txt': ' = ', 'constraint': 'M1.scale'} 123 {'model_cbox': 'M2', 'param_cbox': 'radius', 'egal_txt': ' = ', 'constraint': 'M1.radius'} 124 {'model_cbox': 'M2', 'param_cbox': 'radius.width', 'egal_txt': ' = ', 'constraint': 'M1.radius.width'} 125 fit_page_no None 126 model_list 127 {'fit_number': '393', 'checked': 'True', 'fit_page_source': 'M2', 'name': 'latex_smeared.xml [1]1523535051.03', 'model_name': 'sphere'} 128 {'fit_number': '335', 'checked': 'True', 'fit_page_source': 'M1', 'name': 'latex_smeared.xml 1523535050.03', 'model_name': 'sphere'} 129 model_to_fit 130 no_constraint 0 131 select_all True 132 133 3 134 """ 4 135 # TODO: Refactor code so we don't need to use getattr/setattr … … 162 293 self.theory_data = None 163 294 # Is 2D 164 self.is_2D = False165 295 self.images = None 166 296 … … 557 687 temp_parameters = [] 558 688 temp_fittable_param = [] 559 if self.data.__class__.__name__ == "Data2D":560 self.is_2D = True561 else:562 self.is_2D = False563 689 if self.data is not None: 564 if not self.is_2D: 690 is_2D = (self.data.__class__.__name__ == "Data2D") 691 if not is_2D: 565 692 for item in self.parameters: 566 693 if item not in self.orientation_params: -
src/sas/sasgui/perspectives/fitting/fitpage.py
rba1c145 r1dc134e6 52 52 # draw sizer 53 53 self._fill_data_sizer() 54 self.is_2D = None55 54 self.fit_started = False 56 55 self.weightbt_string = None
Note: See TracChangeset
for help on using the changeset viewer.