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


Ignore:
Timestamp:
Apr 4, 2017 12:50:04 PM (7 years ago)
Author:
Ricardo Ferraz Leal <ricleal@…>
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:
f2940c4
Parents:
463e7ffc (diff), 1779e72 (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.
Message:

After merge conflict

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

    r463e7ffc r9c0f3c17  
    77""" 
    88 
    9 import numpy 
     9import numpy as np 
    1010import sys 
    1111import math 
     
    191191        #import numpy 
    192192        if name == 'x': 
    193             out = numpy.ones(self.get_nx()) 
     193            out = np.ones(self.get_nx()) 
    194194            self.get_x(out) 
    195195            return out 
    196196        elif name == 'y': 
    197             out = numpy.ones(self.get_ny()) 
     197            out = np.ones(self.get_ny()) 
    198198            self.get_y(out) 
    199199            return out 
    200200        elif name == 'err': 
    201             out = numpy.ones(self.get_nerr()) 
     201            out = np.ones(self.get_nerr()) 
    202202            self.get_err(out) 
    203203            return out 
     
    327327            raise RuntimeError, msg 
    328328 
    329         p = numpy.ones(nfunc) 
     329        p = np.ones(nfunc) 
    330330        t_0 = time.time() 
    331331        out, cov_x, _, _, _ = optimize.leastsq(self.residuals, p, full_output=1) 
     
    343343 
    344344        if cov_x is None: 
    345             cov_x = numpy.ones([nfunc, nfunc]) 
     345            cov_x = np.ones([nfunc, nfunc]) 
    346346            cov_x *= math.fabs(chisqr) 
    347347        return out, cov_x 
     
    360360            raise RuntimeError, msg 
    361361 
    362         p = numpy.ones(nfunc) 
     362        p = np.ones(nfunc) 
    363363        t_0 = time.time() 
    364364        out, cov_x, _, _, _ = optimize.leastsq(self.pr_residuals, p, full_output=1) 
     
    437437        """ 
    438438        # Note: To make sure an array is contiguous: 
    439         # blah = numpy.ascontiguousarray(blah_original) 
     439        # blah = np.ascontiguousarray(blah_original) 
    440440        # ... before passing it to C 
    441441 
     
    458458            nfunc += 1 
    459459 
    460         a = numpy.zeros([npts + nq, nfunc]) 
    461         b = numpy.zeros(npts + nq) 
    462         err = numpy.zeros([nfunc, nfunc]) 
     460        a = np.zeros([npts + nq, nfunc]) 
     461        b = np.zeros(npts + nq) 
     462        err = np.zeros([nfunc, nfunc]) 
    463463 
    464464        # Construct the a matrix and b vector that represent the problem 
     
    478478        self.chi2 = chi2 
    479479 
    480         inv_cov = numpy.zeros([nfunc, nfunc]) 
     480        inv_cov = np.zeros([nfunc, nfunc]) 
    481481        # Get the covariance matrix, defined as inv_cov = a_transposed * a 
    482482        self._get_invcov_matrix(nfunc, nr, a, inv_cov) 
     
    492492 
    493493        try: 
    494             cov = numpy.linalg.pinv(inv_cov) 
     494            cov = np.linalg.pinv(inv_cov) 
    495495            err = math.fabs(chi2 / float(npts - nfunc)) * cov 
    496496        except: 
     
    507507            self.background = c[0] 
    508508 
    509             err_0 = numpy.zeros([nfunc, nfunc]) 
    510             c_0 = numpy.zeros(nfunc) 
     509            err_0 = np.zeros([nfunc, nfunc]) 
     510            c_0 = np.zeros(nfunc) 
    511511 
    512512            for i in range(nfunc_0): 
     
    664664                                                   str(self.cov[i][i]))) 
    665665        file.write("<r>  <Pr>  <dPr>\n") 
    666         r = numpy.arange(0.0, self.d_max, self.d_max / npts) 
     666        r = np.arange(0.0, self.d_max, self.d_max / npts) 
    667667 
    668668        for r_i in r: 
     
    696696                        toks = line.split('=') 
    697697                        self.nfunc = int(toks[1]) 
    698                         self.out = numpy.zeros(self.nfunc) 
    699                         self.cov = numpy.zeros([self.nfunc, self.nfunc]) 
     698                        self.out = np.zeros(self.nfunc) 
     699                        self.cov = np.zeros([self.nfunc, self.nfunc]) 
    700700                    elif line.startswith('#alpha='): 
    701701                        toks = line.split('=') 
  • src/sas/sascalc/pr/num_term.py

    r463e7ffc r9c0f3c17  
    11import math 
    2 import numpy 
     2import numpy as np 
    33import copy 
    44import sys 
     
    154154def load(path): 
    155155    # Read the data from the data file 
    156     data_x = numpy.zeros(0) 
    157     data_y = numpy.zeros(0) 
    158     data_err = numpy.zeros(0) 
     156    data_x = np.zeros(0) 
     157    data_y = np.zeros(0) 
     158    data_err = np.zeros(0) 
    159159    scale = None 
    160160    min_err = 0.0 
     
    178178                    #err = 0 
    179179 
    180                 data_x = numpy.append(data_x, test_x) 
    181                 data_y = numpy.append(data_y, test_y) 
    182                 data_err = numpy.append(data_err, err) 
     180                data_x = np.append(data_x, test_x) 
     181                data_y = np.append(data_y, test_y) 
     182                data_err = np.append(data_err, err) 
    183183            except: 
    184184                logger.error(sys.exc_value) 
Note: See TracChangeset for help on using the changeset viewer.