Ignore:
Timestamp:
Mar 26, 2017 11:33:16 PM (8 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/data_util/uncertainty.py

    rb699768 r9a5097c  
    1717from __future__ import division 
    1818 
    19 import numpy 
     19import numpy as np 
    2020import err1d 
    2121from formatnum import format_uncertainty 
     
    2727class Uncertainty(object): 
    2828    # Make standard deviation available 
    29     def _getdx(self): return numpy.sqrt(self.variance) 
     29    def _getdx(self): return np.sqrt(self.variance) 
    3030    def _setdx(self,dx):  
    3131        # Direct operation 
     
    144144        return self 
    145145    def __abs__(self): 
    146         return Uncertainty(numpy.abs(self.x),self.variance) 
     146        return Uncertainty(np.abs(self.x),self.variance) 
    147147 
    148148    def __str__(self): 
    149         #return str(self.x)+" +/- "+str(numpy.sqrt(self.variance)) 
    150         if numpy.isscalar(self.x): 
    151             return format_uncertainty(self.x,numpy.sqrt(self.variance)) 
     149        #return str(self.x)+" +/- "+str(np.sqrt(self.variance)) 
     150        if np.isscalar(self.x): 
     151            return format_uncertainty(self.x,np.sqrt(self.variance)) 
    152152        else: 
    153153            return [format_uncertainty(v,dv)  
    154                     for v,dv in zip(self.x,numpy.sqrt(self.variance))] 
     154                    for v,dv in zip(self.x,np.sqrt(self.variance))] 
    155155    def __repr__(self): 
    156156        return "Uncertainty(%s,%s)"%(str(self.x),str(self.variance)) 
     
    287287    # =============== vector operations ================ 
    288288    # Slicing 
    289     z = Uncertainty(numpy.array([1,2,3,4,5]),numpy.array([2,1,2,3,2])) 
     289    z = Uncertainty(np.array([1,2,3,4,5]),np.array([2,1,2,3,2])) 
    290290    assert z[2].x == 3 and z[2].variance == 2 
    291291    assert (z[2:4].x == [3,4]).all() 
    292292    assert (z[2:4].variance == [2,3]).all() 
    293     z[2:4] = Uncertainty(numpy.array([8,7]),numpy.array([4,5])) 
     293    z[2:4] = Uncertainty(np.array([8,7]),np.array([4,5])) 
    294294    assert z[2].x == 8 and z[2].variance == 4 
    295     A = Uncertainty(numpy.array([a.x]*2),numpy.array([a.variance]*2)) 
    296     B = Uncertainty(numpy.array([b.x]*2),numpy.array([b.variance]*2)) 
     295    A = Uncertainty(np.array([a.x]*2),np.array([a.variance]*2)) 
     296    B = Uncertainty(np.array([b.x]*2),np.array([b.variance]*2)) 
    297297 
    298298    # TODO complete tests of copy and inplace operations for vectors and slices. 
Note: See TracChangeset for help on using the changeset viewer.