Changeset 9a5097c in sasview for src/sas/sascalc/pr


Ignore:
Timestamp:
Mar 26, 2017 11:33:16 PM (7 years ago)
Author:
andyfaff
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
ed2276f
Parents:
9146ed9
Message:

MAINT: import numpy as np

Location:
src/sas/sascalc/pr
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/pr/fit/AbstractFitEngine.py

    rfc18690 r9a5097c  
    44import sys 
    55import math 
    6 import numpy 
     6import numpy as np 
    77 
    88from sas.sascalc.dataloader.data_info import Data1D 
     
    162162        # constant, or dy data 
    163163        if dy is None or dy == [] or dy.all() == 0: 
    164             self.dy = numpy.ones(len(y)) 
     164            self.dy = np.ones(len(y)) 
    165165        else: 
    166             self.dy = numpy.asarray(dy).copy() 
     166            self.dy = np.asarray(dy).copy() 
    167167 
    168168        ## Min Q-value 
    169169        #Skip the Q=0 point, especially when y(q=0)=None at x[0]. 
    170170        if min(self.x) == 0.0 and self.x[0] == 0 and\ 
    171                      not numpy.isfinite(self.y[0]): 
     171                     not np.isfinite(self.y[0]): 
    172172            self.qmin = min(self.x[self.x != 0]) 
    173173        else: 
     
    188188        # Skip Q=0 point, (especially for y(q=0)=None at x[0]). 
    189189        # ToDo: Find better way to do it. 
    190         if qmin == 0.0 and not numpy.isfinite(self.y[qmin]): 
     190        if qmin == 0.0 and not np.isfinite(self.y[qmin]): 
    191191            self.qmin = min(self.x[self.x != 0]) 
    192192        elif qmin != None: 
     
    239239        """ 
    240240        # Compute theory data f(x) 
    241         fx = numpy.zeros(len(self.x)) 
     241        fx = np.zeros(len(self.x)) 
    242242        fx[self.idx_unsmeared] = fn(self.x[self.idx_unsmeared]) 
    243243        
     
    247247                              self._last_unsmeared_bin) 
    248248        ## Sanity check 
    249         if numpy.size(self.dy) != numpy.size(fx): 
     249        if np.size(self.dy) != np.size(fx): 
    250250            msg = "FitData1D: invalid error array " 
    251             msg += "%d <> %d" % (numpy.shape(self.dy), numpy.size(fx)) 
     251            msg += "%d <> %d" % (np.shape(self.dy), np.size(fx)) 
    252252            raise RuntimeError, msg 
    253253        return (self.y[self.idx] - fx[self.idx]) / self.dy[self.idx], fx[self.idx] 
     
    300300        ## new error image for fitting purpose 
    301301        if self.err_data == None or self.err_data == []: 
    302             self.res_err_data = numpy.ones(len(self.data)) 
     302            self.res_err_data = np.ones(len(self.data)) 
    303303        else: 
    304304            self.res_err_data = copy.deepcopy(self.err_data) 
    305305        #self.res_err_data[self.res_err_data==0]=1 
    306306         
    307         self.radius = numpy.sqrt(self.qx_data**2 + self.qy_data**2) 
     307        self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 
    308308         
    309309        # Note: mask = True: for MASK while mask = False for NOT to mask 
     
    311311                            (self.radius <= self.qmax)) 
    312312        self.idx = (self.idx) & (self.mask) 
    313         self.idx = (self.idx) & (numpy.isfinite(self.data)) 
    314         self.num_points = numpy.sum(self.idx) 
     313        self.idx = (self.idx) & (np.isfinite(self.data)) 
     314        self.num_points = np.sum(self.idx) 
    315315 
    316316    def set_smearer(self, smearer): 
     
    334334        if qmax != None: 
    335335            self.qmax = qmax 
    336         self.radius = numpy.sqrt(self.qx_data**2 + self.qy_data**2) 
     336        self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 
    337337        self.idx = ((self.qmin <= self.radius) &\ 
    338338                            (self.radius <= self.qmax)) 
    339339        self.idx = (self.idx) & (self.mask) 
    340         self.idx = (self.idx) & (numpy.isfinite(self.data)) 
     340        self.idx = (self.idx) & (np.isfinite(self.data)) 
    341341        self.idx = (self.idx) & (self.res_err_data != 0) 
    342342 
     
    351351        Number of measurement points in data set after masking, etc. 
    352352        """ 
    353         return numpy.sum(self.idx) 
     353        return np.sum(self.idx) 
    354354 
    355355    def residuals(self, fn): 
  • src/sas/sascalc/pr/fit/BumpsFitting.py

    rb699768 r9a5097c  
    55from datetime import timedelta, datetime 
    66 
    7 import numpy 
     7import numpy as np 
    88 
    99from bumps import fitters 
     
    9696        try: 
    9797            p = history.population_values[0] 
    98             n,p = len(p), numpy.sort(p) 
     98            n,p = len(p), np.sort(p) 
    9999            QI,Qmid, = int(0.2*n),int(0.5*n) 
    100100            self.convergence.append((best, p[0],p[QI],p[Qmid],p[-1-QI],p[-1])) 
     
    193193 
    194194    def numpoints(self): 
    195         return numpy.sum(self.data.idx) # number of fitted points 
     195        return np.sum(self.data.idx) # number of fitted points 
    196196 
    197197    def nllf(self): 
    198         return 0.5*numpy.sum(self.residuals()**2) 
     198        return 0.5*np.sum(self.residuals()**2) 
    199199 
    200200    def theory(self): 
     
    293293            R.success = result['success'] 
    294294            if R.success: 
    295                 R.stderr = numpy.hstack((result['stderr'][fitted_index], 
    296                                          numpy.NaN*numpy.ones(len(fitness.computed_pars)))) 
    297                 R.pvec = numpy.hstack((result['value'][fitted_index], 
     295                R.stderr = np.hstack((result['stderr'][fitted_index], 
     296                                      np.NaN*np.ones(len(fitness.computed_pars)))) 
     297                R.pvec = np.hstack((result['value'][fitted_index], 
    298298                                      [p.value for p in fitness.computed_pars])) 
    299                 R.fitness = numpy.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index)) 
     299                R.fitness = np.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index)) 
    300300            else: 
    301                 R.stderr = numpy.NaN*numpy.ones(len(param_list)) 
    302                 R.pvec = numpy.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars]) 
    303                 R.fitness = numpy.NaN 
     301                R.stderr = np.NaN*np.ones(len(param_list)) 
     302                R.pvec = np.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars]) 
     303                R.fitness = np.NaN 
    304304            R.convergence = result['convergence'] 
    305305            if result['uncertainty'] is not None: 
     
    331331    max_step = steps + options.get('burn', 0) 
    332332    pars = [p.name for p in problem._parameters] 
    333     #x0 = numpy.asarray([p.value for p in problem._parameters]) 
     333    #x0 = np.asarray([p.value for p in problem._parameters]) 
    334334    options['monitors'] = [ 
    335335        BumpsMonitor(handler, max_step, pars, problem.dof), 
     
    352352 
    353353    convergence_list = options['monitors'][-1].convergence 
    354     convergence = (2*numpy.asarray(convergence_list)/problem.dof 
    355                    if convergence_list else numpy.empty((0,1),'d')) 
     354    convergence = (2*np.asarray(convergence_list)/problem.dof 
     355                   if convergence_list else np.empty((0,1),'d')) 
    356356 
    357357    success = best is not None 
  • src/sas/sascalc/pr/fit/Loader.py

    rb699768 r9a5097c  
    22#import wx 
    33#import string 
    4 import numpy 
     4import numpy as np 
    55 
    66class Load: 
     
    5252                    self.y.append(y) 
    5353                    self.dy.append(dy) 
    54                     self.dx = numpy.zeros(len(self.x)) 
     54                    self.dx = np.zeros(len(self.x)) 
    5555                except: 
    5656                    print "READ ERROR", line 
  • src/sas/sascalc/pr/fit/expression.py

    rb699768 r9a5097c  
    271271 
    272272def test_deps(): 
    273     import numpy 
     273    import numpy as np 
    274274 
    275275    # Null case 
     
    279279    _check("test1",[(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)]) 
    280280    _check("test1 renumbered",[(6,1),(7,3),(7,4),(6,7),(5,7),(3,2)]) 
    281     _check("test1 numpy",numpy.array([(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)])) 
     281    _check("test1 numpy",np.array([(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)])) 
    282282 
    283283    # No dependencies 
     
    291291 
    292292    # large test for gross speed check 
    293     A = numpy.random.randint(4000,size=(1000,2)) 
     293    A = np.random.randint(4000,size=(1000,2)) 
    294294    A[:,1] += 4000  # Avoid cycles 
    295295    _check("test-large",A) 
     
    297297    # depth tests 
    298298    k = 200 
    299     A = numpy.array([range(0,k),range(1,k+1)]).T 
     299    A = np.array([range(0,k),range(1,k+1)]).T 
    300300    _check("depth-1",A) 
    301301 
    302     A = numpy.array([range(1,k+1),range(0,k)]).T 
     302    A = np.array([range(1,k+1),range(0,k)]).T 
    303303    _check("depth-2",A) 
    304304 
  • src/sas/sascalc/pr/invertor.py

    r2c60f304 r9a5097c  
    77""" 
    88 
    9 import numpy 
     9import numpy as np 
    1010import sys 
    1111import math 
     
    189189        #import numpy 
    190190        if name == 'x': 
    191             out = numpy.ones(self.get_nx()) 
     191            out = np.ones(self.get_nx()) 
    192192            self.get_x(out) 
    193193            return out 
    194194        elif name == 'y': 
    195             out = numpy.ones(self.get_ny()) 
     195            out = np.ones(self.get_ny()) 
    196196            self.get_y(out) 
    197197            return out 
    198198        elif name == 'err': 
    199             out = numpy.ones(self.get_nerr()) 
     199            out = np.ones(self.get_nerr()) 
    200200            self.get_err(out) 
    201201            return out 
     
    325325            raise RuntimeError, msg 
    326326 
    327         p = numpy.ones(nfunc) 
     327        p = np.ones(nfunc) 
    328328        t_0 = time.time() 
    329329        out, cov_x, _, _, _ = optimize.leastsq(self.residuals, p, full_output=1) 
     
    341341 
    342342        if cov_x is None: 
    343             cov_x = numpy.ones([nfunc, nfunc]) 
     343            cov_x = np.ones([nfunc, nfunc]) 
    344344            cov_x *= math.fabs(chisqr) 
    345345        return out, cov_x 
     
    358358            raise RuntimeError, msg 
    359359 
    360         p = numpy.ones(nfunc) 
     360        p = np.ones(nfunc) 
    361361        t_0 = time.time() 
    362362        out, cov_x, _, _, _ = optimize.leastsq(self.pr_residuals, p, full_output=1) 
     
    435435        """ 
    436436        # Note: To make sure an array is contiguous: 
    437         # blah = numpy.ascontiguousarray(blah_original) 
     437        # blah = np.ascontiguousarray(blah_original) 
    438438        # ... before passing it to C 
    439439 
     
    456456            nfunc += 1 
    457457 
    458         a = numpy.zeros([npts + nq, nfunc]) 
    459         b = numpy.zeros(npts + nq) 
    460         err = numpy.zeros([nfunc, nfunc]) 
     458        a = np.zeros([npts + nq, nfunc]) 
     459        b = np.zeros(npts + nq) 
     460        err = np.zeros([nfunc, nfunc]) 
    461461 
    462462        # Construct the a matrix and b vector that represent the problem 
     
    476476        self.chi2 = chi2 
    477477 
    478         inv_cov = numpy.zeros([nfunc, nfunc]) 
     478        inv_cov = np.zeros([nfunc, nfunc]) 
    479479        # Get the covariance matrix, defined as inv_cov = a_transposed * a 
    480480        self._get_invcov_matrix(nfunc, nr, a, inv_cov) 
     
    490490 
    491491        try: 
    492             cov = numpy.linalg.pinv(inv_cov) 
     492            cov = np.linalg.pinv(inv_cov) 
    493493            err = math.fabs(chi2 / float(npts - nfunc)) * cov 
    494494        except: 
     
    505505            self.background = c[0] 
    506506 
    507             err_0 = numpy.zeros([nfunc, nfunc]) 
    508             c_0 = numpy.zeros(nfunc) 
     507            err_0 = np.zeros([nfunc, nfunc]) 
     508            c_0 = np.zeros(nfunc) 
    509509 
    510510            for i in range(nfunc_0): 
     
    662662                                                   str(self.cov[i][i]))) 
    663663        file.write("<r>  <Pr>  <dPr>\n") 
    664         r = numpy.arange(0.0, self.d_max, self.d_max / npts) 
     664        r = np.arange(0.0, self.d_max, self.d_max / npts) 
    665665 
    666666        for r_i in r: 
     
    694694                        toks = line.split('=') 
    695695                        self.nfunc = int(toks[1]) 
    696                         self.out = numpy.zeros(self.nfunc) 
    697                         self.cov = numpy.zeros([self.nfunc, self.nfunc]) 
     696                        self.out = np.zeros(self.nfunc) 
     697                        self.cov = np.zeros([self.nfunc, self.nfunc]) 
    698698                    elif line.startswith('#alpha='): 
    699699                        toks = line.split('=') 
  • src/sas/sascalc/pr/num_term.py

    rb699768 r9a5097c  
    11import math 
    2 import numpy 
     2import numpy as np 
    33import copy 
    44import sys 
     
    152152def load(path): 
    153153    # Read the data from the data file 
    154     data_x = numpy.zeros(0) 
    155     data_y = numpy.zeros(0) 
    156     data_err = numpy.zeros(0) 
     154    data_x = np.zeros(0) 
     155    data_y = np.zeros(0) 
     156    data_err = np.zeros(0) 
    157157    scale = None 
    158158    min_err = 0.0 
     
    176176                    #err = 0 
    177177 
    178                 data_x = numpy.append(data_x, test_x) 
    179                 data_y = numpy.append(data_y, test_y) 
    180                 data_err = numpy.append(data_err, err) 
     178                data_x = np.append(data_x, test_x) 
     179                data_y = np.append(data_y, test_y) 
     180                data_err = np.append(data_err, err) 
    181181            except: 
    182182                logging.error(sys.exc_value) 
Note: See TracChangeset for help on using the changeset viewer.