Changes in / [1580cc3:1dc134e6] in sasview


Ignore:
Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • docs/sphinx-docs/source/user/RELEASE.rst

    r67ed543 r9849f8a  
    6060* An error in the be_polyelectrolyte model was identified and rectified, but  
    6161  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. 
    6462* A number of issues and inconsistencies with the creation of 
    6563  sum|multiply models have been rectified. 
     
    189187* Fixes #1010: Win64 build script not creating working executable 
    190188* Fixes #1011: sld_test failing on ubuntu 
     189* Fixes #1012: ESS GUI not updating after fitting 
    191190* Fixes #1013: FileReaderBaseClass output[] not reset - same file loaded multiple times 
    192191* Fixes #1018: add Boltzmann distribution 
     
    234233* Fixes #1179: PDF Report should contain SasView Version Number 
    235234* 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 
    238235 
    239236**It is recommended that all users upgrade to this version, but your  
     
    871868  found and corrected, corrected versions will be uploaded to the 
    872869  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. 
    875870 
    8768713.1- All systems 
  • installers/license.txt

    rc6a4d143 r73c51df  
    88Participating facilities include (in alphabetical order):  
    99the Australian National Science & Technology Centre for Neutron  
    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. 
     10Scattering, the Diamond Light Source, the European Spallation Source,  
     11the Institut Laue Langevin, the ISIS Pulsed Neutron & Muon Source,  
     12the National Institute of Standards & Technology Center for Neutron  
     13Research, the Oak Ridge National Laboratory Neutron Sciences  
     14Directorate, and the Technical University Delft Reactor Institute. 
    1615 
    1716SasView is distributed under a 'Three-clause' BSD licence which you  
  • run.py

    r952ea1f r3388337  
    9595    try: 
    9696        import periodictable 
    97     except ImportError: 
     97    except: 
    9898        addpath(joinpath(root, '..', 'periodictable')) 
    9999 
    100100    try: 
    101101        import bumps 
    102     except ImportError: 
     102    except: 
    103103        addpath(joinpath(root, '..', 'bumps')) 
    104104 
    105105    try: 
    106106        import tinycc 
    107     except ImportError: 
     107    except: 
    108108        addpath(joinpath(root, '../tinycc/build/lib')) 
    109109 
     
    111111    #addpath(os.path.join(root, '..','wxPython-src-3.0.0.0','wxPython')) 
    112112 
    113 <<<<<<< HEAD 
    114113    # Build project if the build directory does not already exist. 
    115114    # PAK: with "update" we can always build since it is fast 
    116115    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 
    135116        import subprocess 
    136         build_cmd = [sys.executable, "setup.py", "build_ext", "--inplace", "update"] 
     117        build_cmd = [sys.executable, "setup.py", "build", "update"] 
    137118        if os.name == 'nt': 
    138119            build_cmd.append('--compiler=tinycc') 
     
    141122        with cd(root): 
    142123            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) 
    143151 
    144152    set_git_tag() 
  • setup.py

    r952ea1f rc16172d  
    1212import shutil 
    1313import sys 
     14from distutils.command.build_ext import build_ext 
     15from distutils.core import Command 
    1416 
    1517import numpy as np 
    16  
    1718from setuptools import Extension, setup 
    18 from setuptools import Command 
    19 from setuptools.command.build_ext import build_ext 
    2019 
    2120try: 
     
    2322except ImportError: 
    2423    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] 
    2824 
    2925# Manage version number ###################################### 
     
    250246# sas.sascalc.calculator 
    251247gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions") 
     248package_dir["sas.sascalc.calculator.core"] = gen_dir 
    252249package_dir["sas.sascalc.calculator"] = os.path.join( 
    253250    "src", "sas", "sascalc", "calculator") 
    254 packages.append("sas.sascalc.calculator") 
    255 ext_modules.append(Extension("sas.sascalc.calculator._sld2i", 
     251packages.extend(["sas.sascalc.calculator", "sas.sascalc.calculator.core"]) 
     252ext_modules.append(Extension("sas.sascalc.calculator.core.sld2i", 
    256253                             sources=[ 
    257254                                 os.path.join(gen_dir, "sld2i_module.c"), 
     
    261258                             ], 
    262259                             include_dirs=[gen_dir], 
    263                              )) 
     260                             ) 
     261                   ) 
    264262 
    265263# sas.sascalc.pr 
    266264srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions") 
     265package_dir["sas.sascalc.pr.core"] = srcdir 
    267266package_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", 
     267packages.extend(["sas.sascalc.pr", "sas.sascalc.pr.core"]) 
     268ext_modules.append(Extension("sas.sascalc.pr.core.pr_inversion", 
    270269                             sources=[os.path.join(srcdir, "Cinvertor.c"), 
    271270                                      os.path.join(srcdir, "invertor.c"), 
     
    277276# sas.sascalc.file_converter 
    278277mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext") 
     278package_dir["sas.sascalc.file_converter.core"] = mydir 
    279279package_dir["sas.sascalc.file_converter"] = os.path.join( 
    280280    "src", "sas", "sascalc", "file_converter") 
    281 packages.append("sas.sascalc.file_converter") 
    282 ext_modules.append(Extension("sas.sascalc.file_converter._bsl_loader", 
     281packages.extend(["sas.sascalc.file_converter", 
     282                 "sas.sascalc.file_converter.core"]) 
     283ext_modules.append(Extension("sas.sascalc.file_converter.core.bsl_loader", 
    283284                             sources=[os.path.join(mydir, "bsl_loader.c")], 
    284285                             include_dirs=[np.get_include()], 
     
    442443    cmdclass={'build_ext': build_ext_subclass, 
    443444              '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} 
    447446) 
  • src/sas/sascalc/calculator/c_extensions/sld2i_module.c

    r7ba6470 ra1daf86  
    22  SLD2I module to perform point and I calculations 
    33 */ 
     4#include <Python.h> 
    45#include <stdio.h> 
    5  
    6 //#define Py_LIMITED_API 0x03020000 
    7 #include <Python.h> 
    8  
    96#include "sld2i.h" 
    107 
     
    1613#endif 
    1714 
    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 
    3831 
    3932/** 
     
    8073        //printf("new GenI\n"); 
    8174        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); 
    9083        sld2i = PyMem_Malloc(sizeof(GenI)); 
    9184        //printf("sldi:%p\n", sld2i); 
     
    115108        if (!PyArg_ParseTuple(args, "OOOO",  &gen_obj, &qx_obj, &qy_obj, &I_out_obj)) return NULL; 
    116109        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); 
    120113        //printf("qx, qy, I_out: %d %d %d, %d %d %d\n", qx, qy, I_out, n_qx, n_qy, n_out); 
    121114 
     
    143136        if (!PyArg_ParseTuple(args, "OOO",  &gen_obj, &q_obj, &I_out_obj)) return NULL; 
    144137        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); 
    147140 
    148141        // Sanity check 
     
    167160 
    168161#define MODULE_DOC "Sld2i C Library" 
    169 #define MODULE_NAME "_sld2i" 
    170 #define MODULE_INIT2 init_sld2i 
    171 #define MODULE_INIT3 PyInit__sld2i 
     162#define MODULE_NAME "sld2i" 
     163#define MODULE_INIT2 initsld2i 
     164#define MODULE_INIT3 PyInit_sld2i 
    172165#define MODULE_METHODS module_methods 
    173166 
  • src/sas/sascalc/calculator/sas_gen.py

    r952ea1f r144e032a  
    1414import numpy as np 
    1515 
    16 from . import _sld2i 
     16from .core import sld2i as mod 
    1717from .BaseComponent import BaseComponent 
    1818 
     
    145145            self.params['Up_frac_out'], 
    146146            self.params['Up_theta']) 
    147         model = _sld2i.new_GenI(*args) 
     147        model = mod.new_GenI(*args) 
    148148        if len(qy): 
    149149            qx, qy = _vec(qx), _vec(qy) 
    150150            I_out = np.empty_like(qx) 
    151151            #print("npoints", qx.shape, "npixels", pos_x.shape) 
    152             _sld2i.genicomXY(model, qx, qy, I_out) 
     152            mod.genicomXY(model, qx, qy, I_out) 
    153153            #print("I_out after", I_out) 
    154154        else: 
    155155            qx = _vec(qx) 
    156156            I_out = np.empty_like(qx) 
    157             _sld2i.genicom(model, qx, I_out) 
     157            mod.genicom(model, qx, I_out) 
    158158        vol_correction = self.data_total_volume / self.params['total_volume'] 
    159159        result = (self.params['scale'] * vol_correction * I_out 
     
    304304                z_dir2 *= z_dir2 
    305305                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) 
    308308        self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], 
    309309                             self.pos_z[mask], self.sld_n[mask], 
     
    600600                        y_lines.append(y_line) 
    601601                        z_lines.append(z_line) 
    602                 except Exception as exc: 
    603                     logger.error(exc) 
     602                except Exception: 
     603                    logger.error(sys.exc_value) 
    604604 
    605605            output = MagSLD(pos_x, pos_y, pos_z, sld_n, sld_mx, sld_my, sld_mz) 
     
    691691                            _vol_pix = float(toks[7]) 
    692692                            vol_pix = np.append(vol_pix, _vol_pix) 
    693                         except Exception as exc: 
     693                        except Exception: 
    694694                            vol_pix = None 
    695                     except Exception as exc: 
     695                    except Exception: 
    696696                        # Skip non-data lines 
    697                         logger.error(exc) 
     697                        logger.error(sys.exc_value) 
    698698            output = MagSLD(pos_x, pos_y, pos_z, sld_n, 
    699699                            sld_mx, sld_my, sld_mz) 
  • src/sas/sascalc/dataloader/file_reader_base_class.py

    rfee520ec r4a8d55c  
    276276                    dataset.xmax = np.max(dataset.qx_data) 
    277277                    dataset.ymin = np.min(dataset.qy_data) 
    278                     dataset.ymax = np.max(dataset.qy_data) 
     278                    dataset.ymax = np.max(dataset.qx_data) 
    279279 
    280280    def format_unit(self, unit=None): 
  • src/sas/sascalc/file_converter/bsl_loader.py

    r952ea1f rf00691d4  
    1 from sas.sascalc.file_converter._bsl_loader import CLoader 
     1from sas.sascalc.file_converter.core.bsl_loader import CLoader 
    22from sas.sascalc.dataloader.data_info import Data2D 
    33from copy import deepcopy 
     
    6767                    'swap_bytes': int(metadata[3]) 
    6868                } 
    69             except Exception: 
     69            except: 
    7070                is_valid = False 
    7171                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> 
    14#include <stdio.h> 
    25#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" 
    107#include "bsl_loader.h" 
    118 
     
    295292 
    296293#define MODULE_DOC "C module for loading bsl." 
    297 #define MODULE_NAME "_bsl_loader" 
    298 #define MODULE_INIT2 init_bsl_loader 
    299 #define MODULE_INIT3 PyInit__bsl_loader 
     294#define MODULE_NAME "bsl_loader" 
     295#define MODULE_INIT2 initbsl_loader 
     296#define MODULE_INIT3 PyInit_bsl_loader 
    300297#define MODULE_METHODS module_methods 
    301298 
  • src/sas/sascalc/pr/c_extensions/Cinvertor.c

    r7ba6470 ra52f32f  
    55 * 
    66 */ 
     7#include <Python.h> 
     8#include "structmember.h" 
    79#include <stdio.h> 
    810#include <stdlib.h> 
     
    1012#include <time.h> 
    1113 
    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  
    3714#include "invertor.h" 
     15 
    3816 
    3917/// Error object for raised exceptions 
    4018PyObject * 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 
    4134 
    4235// Class definition 
     
    10699 
    107100        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    108         VECTOR(data_obj,data,ndata); 
     101        OUTVECTOR(data_obj,data,ndata); 
    109102 
    110103        free(self->params.x); 
     
    138131 
    139132        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    140         VECTOR(data_obj, data, ndata); 
     133        OUTVECTOR(data_obj, data, ndata); 
    141134 
    142135        // Check that the input array is large enough 
     
    171164 
    172165        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    173         VECTOR(data_obj,data,ndata); 
     166        OUTVECTOR(data_obj,data,ndata); 
    174167 
    175168        free(self->params.y); 
     
    203196 
    204197        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    205         VECTOR(data_obj, data, ndata); 
     198        OUTVECTOR(data_obj, data, ndata); 
    206199 
    207200        // Check that the input array is large enough 
     
    236229 
    237230        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    238         VECTOR(data_obj,data,ndata); 
     231        OUTVECTOR(data_obj,data,ndata); 
    239232 
    240233        free(self->params.err); 
     
    268261 
    269262        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    270         VECTOR(data_obj, data, ndata); 
     263        OUTVECTOR(data_obj, data, ndata); 
    271264 
    272265        // Check that the input array is large enough 
     
    524517        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    525518 
    526         VECTOR(data_obj,pars,npars); 
     519        OUTVECTOR(data_obj,pars,npars); 
    527520 
    528521    // PyList of residuals 
     
    575568        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    576569 
    577         VECTOR(data_obj,pars,npars); 
     570        OUTVECTOR(data_obj,pars,npars); 
    578571 
    579572        // Should create this list only once and refill it 
     
    616609 
    617610        if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 
    618         VECTOR(data_obj,pars,npars); 
     611        OUTVECTOR(data_obj,pars,npars); 
    619612 
    620613        iq_value = iq(pars, self->params.d_max, (int)npars, q); 
     
    641634 
    642635        if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 
    643         VECTOR(data_obj,pars,npars); 
     636        OUTVECTOR(data_obj,pars,npars); 
    644637 
    645638        iq_value = iq_smeared(pars, self->params.d_max, (int)npars, 
     
    666659 
    667660        if (!PyArg_ParseTuple(args, "Od", &data_obj, &r)) return NULL; 
    668         VECTOR(data_obj,pars,npars); 
     661        OUTVECTOR(data_obj,pars,npars); 
    669662 
    670663        pr_value = pr(pars, self->params.d_max, (int)npars, r); 
     
    693686 
    694687        if (!PyArg_ParseTuple(args, "OOd", &data_obj, &err_obj, &r)) return NULL; 
    695         VECTOR(data_obj,pars,npars); 
     688        OUTVECTOR(data_obj,pars,npars); 
    696689 
    697690        if (err_obj == Py_None) { 
     
    699692                pr_err_value = 0.0; 
    700693        } else { 
    701                 VECTOR(err_obj,pars_err,npars2); 
     694                OUTVECTOR(err_obj,pars_err,npars2); 
    702695                pr_err(pars, pars_err, self->params.d_max, (int)npars, r, &pr_value, &pr_err_value); 
    703696        } 
     
    733726 
    734727        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    735         VECTOR(data_obj,pars,npars); 
     728        OUTVECTOR(data_obj,pars,npars); 
    736729 
    737730        oscill = reg_term(pars, self->params.d_max, (int)npars, 100); 
     
    754747 
    755748        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    756         VECTOR(data_obj,pars,npars); 
     749        OUTVECTOR(data_obj,pars,npars); 
    757750 
    758751        count = npeaks(pars, self->params.d_max, (int)npars, 100); 
     
    775768 
    776769        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    777         VECTOR(data_obj,pars,npars); 
     770        OUTVECTOR(data_obj,pars,npars); 
    778771 
    779772        fraction = positive_integral(pars, self->params.d_max, (int)npars, 100); 
     
    799792 
    800793        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); 
    803796 
    804797        fraction = positive_errors(pars, pars_err, self->params.d_max, (int)npars, 51); 
     
    820813 
    821814        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    822         VECTOR(data_obj,pars,npars); 
     815        OUTVECTOR(data_obj,pars,npars); 
    823816 
    824817        value = rg(pars, self->params.d_max, (int)npars, 101); 
     
    840833 
    841834        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
    842         VECTOR(data_obj,pars,npars); 
     835        OUTVECTOR(data_obj,pars,npars); 
    843836 
    844837        value = 4.0*acos(-1.0)*int_pr(pars, self->params.d_max, (int)npars, 101); 
     
    881874 
    882875        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); 
    885878 
    886879        assert(n_b>=nfunc); 
     
    954947 
    955948        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); 
    958951 
    959952        assert(n_cov>=nfunc*nfunc); 
     
    988981 
    989982        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); 
    991984 
    992985        assert(n_a>=nfunc*(nr+self->params.npoints)); 
     
    11281121 
    11291122#define MODULE_DOC "C extension module for inversion to P(r)." 
    1130 #define MODULE_NAME "_pr_inversion" 
    1131 #define MODULE_INIT2 init_pr_inversion 
    1132 #define MODULE_INIT3 PyInit__pr_inversion 
     1123#define MODULE_NAME "pr_inversion" 
     1124#define MODULE_INIT2 initpr_inversion 
     1125#define MODULE_INIT3 PyInit_pr_inversion 
    11331126#define MODULE_METHODS module_methods 
    11341127 
  • src/sas/sascalc/pr/fit/BumpsFitting.py

    r3e6829d r9a5097c  
    22BumpsFitting module runs the bumps optimizer. 
    33""" 
    4 from __future__ import division 
    5  
    64import os 
    75from datetime import timedelta, datetime 
     
    3634class Progress(object): 
    3735    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)) 
    3937        # Depending on the time remaining, either display the expected 
    4038        # 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 file 
    3 """ 
    4  
    51from __future__ import print_function 
    62 
     3# class Loader  to load any king of file 
     4#import wx 
     5#import string 
    76import numpy as np 
    87 
  • src/sas/sascalc/pr/invertor.py

    r57e48ca r2469df7  
    66FIXME: The way the Invertor interacts with its C component should be cleaned up 
    77""" 
    8 from __future__ import division 
    98 
    109import numpy as np 
     
    1817from numpy.linalg import lstsq 
    1918from scipy import optimize 
    20 from sas.sascalc.pr._pr_inversion import Cinvertor 
     19from sas.sascalc.pr.core.pr_inversion import Cinvertor 
    2120 
    2221logger = logging.getLogger(__name__) 
     
    7271        A[j][i] = (Fourier transformed base function for point j) 
    7372 
    74     We then choose a number of r-points, n_r, to evaluate the second 
     73    We them choose a number of r-points, n_r, to evaluate the second 
    7574    derivative of P(r) at. This is used as our regularization term. 
    7675    For a vector r of length n_r, the following n_r rows are set to :: 
     
    145144        x, y, err, d_max, q_min, q_max and alpha 
    146145        """ 
    147         if name == 'x': 
     146        if   name == 'x': 
    148147            if 0.0 in value: 
    149148                msg = "Invertor: one of your q-values is zero. " 
     
    269268            A[i][j] = (Fourier transformed base function for point j) 
    270269 
    271         We then choose a number of r-points, n_r, to evaluate the second 
     270        We them choose a number of r-points, n_r, to evaluate the second 
    272271        derivative of P(r) at. This is used as our regularization term. 
    273272        For a vector r of length n_r, the following n_r rows are set to :: 
     
    417416            A[i][j] = (Fourier transformed base function for point j) 
    418417 
    419         We then choose a number of r-points, n_r, to evaluate the second 
     418        We them choose a number of r-points, n_r, to evaluate the second 
    420419        derivative of P(r) at. This is used as our regularization term. 
    421420        For a vector r of length n_r, the following n_r rows are set to :: 
     
    474473 
    475474        # Perform the inversion (least square fit) 
    476         c, chi2, _, _ = lstsq(a, b, rcond=-1) 
     475        c, chi2, _, _ = lstsq(a, b) 
    477476        # Sanity check 
    478477        try: 
     
    497496        try: 
    498497            cov = np.linalg.pinv(inv_cov) 
    499             err = math.fabs(chi2 / (npts - nfunc)) * cov 
    500         except Exception as exc: 
     498            err = math.fabs(chi2 / float(npts - nfunc)) * cov 
     499        except: 
    501500            # We were not able to estimate the errors 
    502501            # Return an empty error matrix 
    503             logger.error(exc) 
     502            logger.error(sys.exc_value) 
    504503 
    505504        # Keep a copy of the last output 
     
    538537 
    539538        """ 
    540         from .num_term import NTermEstimator 
     539        from num_term import NTermEstimator 
    541540        estimator = NTermEstimator(self.clone()) 
    542541        try: 
    543542            return estimator.num_terms(isquit_func) 
    544         except Exception as exc: 
     543        except: 
    545544            # If we fail, estimate alpha and return the default 
    546545            # number of terms 
    547546            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) 
    549548            return self.nfunc, best_alpha, "Could not estimate number of terms" 
    550549 
     
    632631                return best_alpha, message, elapsed 
    633632 
    634         except Exception as exc: 
    635             message = "Invertor.estimate_alpha: %s" % exc 
     633        except: 
     634            message = "Invertor.estimate_alpha: %s" % sys.exc_value 
    636635            return 0, message, elapsed 
    637636 
     
    749748                        self.cov[i][i] = float(toks2[1]) 
    750749 
    751             except Exception as exc: 
    752                 msg = "Invertor.from_file: corrupted file\n%s" % exc 
     750            except: 
     751                msg = "Invertor.from_file: corrupted file\n%s" % sys.exc_value 
    753752                raise RuntimeError(msg) 
    754753        else: 
  • src/sas/sascalc/pr/num_term.py

    r3e6829d r2469df7  
    1 from __future__ import print_function, division 
     1from __future__ import print_function 
    22 
    33import math 
     
    5151        osc = self.sort_osc() 
    5252        dv = len(osc) 
    53         med = 0.5*dv 
     53        med = float(dv) / 2.0 
    5454        odd = self.is_odd(dv) 
    5555        medi = 0 
     
    140140            nts = self.compare_err() 
    141141            div = len(nts) 
    142             tem = 0.5*div 
     142            tem = float(div) / 2.0 
    143143            if self.is_odd(div): 
    144144                nt = nts[int(tem)] 
  • src/sas/sasgui/perspectives/fitting/basepage.py

    r5323490 rb4398819  
    28842884            self.magnetic_on = True 
    28852885            button.SetLabel("Magnetic OFF") 
    2886             m_value = 1 
     2886            m_value = 1.0e-06 
    28872887            for key in self.model.magnetic_params: 
    28882888                if key.count('M0') > 0: 
    28892889                    self.model.setParam(key, m_value) 
    2890                     m_value += 0.5 
     2890                    m_value += 0.5e-06 
    28912891        else: 
    28922892            self.magnetic_on = False 
  • src/sas/sasgui/perspectives/fitting/gpu_options.py

    r8e109f9 r388aefb  
    88''' 
    99 
    10 import json 
    11 import platform 
    1210import logging 
    1311import os 
    1412import sys 
    15  
    1613import wx 
    17  
    18 try: 
    19     import pyopencl as cl 
    20 except ImportError: 
    21     cl = None 
    22  
    2314import sasmodels 
    24 import sasmodels.model_test 
    25 import sasmodels.kernelcl 
    26  
    2715from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
    2816 
     
    181169        clinfo = [] 
    182170        platforms = [] 
    183  
    184         if cl is None: 
     171        try: 
     172            import pyopencl as cl 
     173            platforms = cl.get_platforms() 
     174        except ImportError: 
    185175            logger.warn("Unable to import the pyopencl package.  It may not " 
    186176                        "have been installed.  If you wish to use OpenCL, try " 
    187177                        "running pip install --user pyopencl") 
    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) 
     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) 
    196183 
    197184        p_index = 0 
     
    239226            if "SAS_OPENCL" in os.environ: 
    240227                del os.environ["SAS_OPENCL"] 
    241         sasmodels.kernelcl.reset_environment() 
     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) 
    242234        event.Skip() 
    243235 
     
    255247        Run sasmodels check from here and report results from 
    256248        """ 
     249        import json 
     250        import platform 
     251        #import sasmodels 
     252 
    257253        #The same block of code as for OK but it is needed if we want to have 
    258254        #active response to Test button 
     
    265261            if "SAS_OPENCL" in os.environ: 
    266262                del os.environ["SAS_OPENCL"] 
    267         sasmodels.kernelcl.reset_environment() 
     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 
    268274 
    269275        try: 
    270             env = sasmodels.kernelcl.environment() 
     276            from sasmodels.kernelcl import environment 
     277            env = environment() 
    271278            clinfo = [(ctx.devices[0].platform.vendor, 
    272279                       ctx.devices[0].platform.version, 
     
    275282                       ctx.devices[0].version) 
    276283                      for ctx in env.context] 
    277         except Exception: 
     284        except ImportError: 
    278285            clinfo = None 
    279286 
    280287        failures = [] 
    281288        tests_completed = 0 
    282         for test in sasmodels.model_test.model_tests(): 
     289        for test in model_tests(): 
    283290            try: 
    284291                test() 
Note: See TracChangeset for help on using the changeset viewer.