Changeset 9a5097c in sasview for src/sas/sascalc/data_util/uncertainty.py
- Timestamp:
- Mar 26, 2017 11:33:16 PM (8 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/data_util/uncertainty.py
rb699768 r9a5097c 17 17 from __future__ import division 18 18 19 import numpy 19 import numpy as np 20 20 import err1d 21 21 from formatnum import format_uncertainty … … 27 27 class Uncertainty(object): 28 28 # Make standard deviation available 29 def _getdx(self): return n umpy.sqrt(self.variance)29 def _getdx(self): return np.sqrt(self.variance) 30 30 def _setdx(self,dx): 31 31 # Direct operation … … 144 144 return self 145 145 def __abs__(self): 146 return Uncertainty(n umpy.abs(self.x),self.variance)146 return Uncertainty(np.abs(self.x),self.variance) 147 147 148 148 def __str__(self): 149 #return str(self.x)+" +/- "+str(n umpy.sqrt(self.variance))150 if n umpy.isscalar(self.x):151 return format_uncertainty(self.x,n umpy.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)) 152 152 else: 153 153 return [format_uncertainty(v,dv) 154 for v,dv in zip(self.x,n umpy.sqrt(self.variance))]154 for v,dv in zip(self.x,np.sqrt(self.variance))] 155 155 def __repr__(self): 156 156 return "Uncertainty(%s,%s)"%(str(self.x),str(self.variance)) … … 287 287 # =============== vector operations ================ 288 288 # Slicing 289 z = Uncertainty(n umpy.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])) 290 290 assert z[2].x == 3 and z[2].variance == 2 291 291 assert (z[2:4].x == [3,4]).all() 292 292 assert (z[2:4].variance == [2,3]).all() 293 z[2:4] = Uncertainty(n umpy.array([8,7]),numpy.array([4,5]))293 z[2:4] = Uncertainty(np.array([8,7]),np.array([4,5])) 294 294 assert z[2].x == 8 and z[2].variance == 4 295 A = Uncertainty(n umpy.array([a.x]*2),numpy.array([a.variance]*2))296 B = Uncertainty(n umpy.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)) 297 297 298 298 # TODO complete tests of copy and inplace operations for vectors and slices.
Note: See TracChangeset
for help on using the changeset viewer.