Changeset 9f59333 in sasview for src/sas/sascalc/data_util
- Timestamp:
- Apr 10, 2017 9:45:27 AM (8 years ago)
- Branches:
- costrafo411
- Children:
- 7b15990
- Parents:
- ba91f71 (diff), d26f025 (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. - Location:
- src/sas/sascalc/data_util
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/data_util/calcthread.py
r934ce649 r7432acb 8 8 import traceback 9 9 import sys 10 import logging 10 11 11 12 if sys.platform.count("darwin") > 0: … … 21 22 from time import clock 22 23 from time import sleep 24 25 logger = logging.getLogger(__name__) 23 26 24 27 … … 202 205 def update(self, **kwargs): 203 206 """Update GUI with the lastest results from the current work unit.""" 204 if self.updatefn !=None and clock() > self._time_for_update:207 if self.updatefn is not None and clock() > self._time_for_update: 205 208 self._lock.acquire() 206 209 self._time_for_update = clock() + self._delay … … 218 221 def complete(self, **kwargs): 219 222 """Update the GUI with the completed results from a work unit.""" 220 if self.completefn !=None:223 if self.completefn is not None: 221 224 self.completefn(**kwargs) 222 225 sleep(self.yieldtime) … … 243 246 except Exception: 244 247 pass 245 import logging 246 logging.error(traceback.format_exc()) 248 logger.error(traceback.format_exc()) 247 249 #print 'CalcThread exception', 248 250 -
src/sas/sascalc/data_util/err1d.py
rb699768 r9a5097c 8 8 """ 9 9 from __future__ import division # Get true division 10 import numpy 10 import numpy as np 11 11 12 12 … … 59 59 def exp(X, varX): 60 60 """Exponentiation with error propagation""" 61 Z = n umpy.exp(X)61 Z = np.exp(X) 62 62 varZ = varX * Z**2 63 63 return Z, varZ … … 66 66 def log(X, varX): 67 67 """Logarithm with error propagation""" 68 Z = n umpy.log(X)68 Z = np.log(X) 69 69 varZ = varX / X**2 70 70 return Z, varZ … … 73 73 # def pow(X,varX, Y,varY): 74 74 # Z = X**Y 75 # varZ = (Y**2 * varX/X**2 + varY * n umpy.log(X)**2) * Z**275 # varZ = (Y**2 * varX/X**2 + varY * np.log(X)**2) * Z**2 76 76 # return Z,varZ 77 77 # -
src/sas/sascalc/data_util/formatnum.py
rb699768 r9a5097c 40 40 41 41 import math 42 import numpy 42 import numpy as np 43 43 __all__ = ['format_uncertainty', 'format_uncertainty_pm', 44 44 'format_uncertainty_compact'] … … 102 102 """ 103 103 # Handle indefinite value 104 if n umpy.isinf(value):104 if np.isinf(value): 105 105 return "inf" if value > 0 else "-inf" 106 if n umpy.isnan(value):106 if np.isnan(value): 107 107 return "NaN" 108 108 109 109 # Handle indefinite uncertainty 110 if uncertainty is None or uncertainty <= 0 or n umpy.isnan(uncertainty):110 if uncertainty is None or uncertainty <= 0 or np.isnan(uncertainty): 111 111 return "%g" % value 112 if n umpy.isinf(uncertainty):112 if np.isinf(uncertainty): 113 113 if compact: 114 114 return "%.2g(inf)" % value … … 279 279 280 280 # non-finite values 281 assert value_str(-n umpy.inf,None) == "-inf"282 assert value_str(n umpy.inf,None) == "inf"283 assert value_str(n umpy.NaN,None) == "NaN"281 assert value_str(-np.inf,None) == "-inf" 282 assert value_str(np.inf,None) == "inf" 283 assert value_str(np.NaN,None) == "NaN" 284 284 285 285 # bad or missing uncertainty 286 assert value_str(-1.23567,n umpy.NaN) == "-1.23567"287 assert value_str(-1.23567,-n umpy.inf) == "-1.23567"286 assert value_str(-1.23567,np.NaN) == "-1.23567" 287 assert value_str(-1.23567,-np.inf) == "-1.23567" 288 288 assert value_str(-1.23567,-0.1) == "-1.23567" 289 289 assert value_str(-1.23567,0) == "-1.23567" 290 290 assert value_str(-1.23567,None) == "-1.23567" 291 assert value_str(-1.23567,n umpy.inf) == "-1.2(inf)"291 assert value_str(-1.23567,np.inf) == "-1.2(inf)" 292 292 293 293 def test_pm(): … … 410 410 411 411 # non-finite values 412 assert value_str(-n umpy.inf,None) == "-inf"413 assert value_str(n umpy.inf,None) == "inf"414 assert value_str(n umpy.NaN,None) == "NaN"412 assert value_str(-np.inf,None) == "-inf" 413 assert value_str(np.inf,None) == "inf" 414 assert value_str(np.NaN,None) == "NaN" 415 415 416 416 # bad or missing uncertainty 417 assert value_str(-1.23567,n umpy.NaN) == "-1.23567"418 assert value_str(-1.23567,-n umpy.inf) == "-1.23567"417 assert value_str(-1.23567,np.NaN) == "-1.23567" 418 assert value_str(-1.23567,-np.inf) == "-1.23567" 419 419 assert value_str(-1.23567,-0.1) == "-1.23567" 420 420 assert value_str(-1.23567,0) == "-1.23567" 421 421 assert value_str(-1.23567,None) == "-1.23567" 422 assert value_str(-1.23567,n umpy.inf) == "-1.2 +/- inf"422 assert value_str(-1.23567,np.inf) == "-1.2 +/- inf" 423 423 424 424 def test_default(): -
src/sas/sascalc/data_util/qsmearing.py
rba91f71 r9f59333 9 9 #copyright 2008, University of Tennessee 10 10 ###################################################################### 11 import numpy12 11 import math 13 12 import logging … … 43 42 # This checks for 2D data (does not throw exception because fail is common) 44 43 if data.__class__.__name__ not in ['Data1D', 'Theory1D']: 45 if data ==None:44 if data is None: 46 45 return None 47 elif data.dqx_data == None or data.dqy_data ==None:46 elif data.dqx_data is None or data.dqy_data is None: 48 47 return None 49 48 return PySmear2D(data) … … 60 59 if data.dx is not None and data.isSesans: 61 60 #if data.dx[0] > 0.0: 62 if n umpy.size(data.dx[data.dx <= 0]) == 0:61 if np.size(data.dx[data.dx <= 0]) == 0: 63 62 _found_sesans = True 64 63 # if data.dx[0] <= 0.0: 65 if n umpy.size(data.dx[data.dx <= 0]) > 0:64 if np.size(data.dx[data.dx <= 0]) > 0: 66 65 raise ValueError('one or more of your dx values are negative, please check the data file!') 67 66 … … 126 125 self.resolution = resolution 127 126 if offset is None: 128 offset = n umpy.searchsorted(self.resolution.q_calc, self.resolution.q[0])127 offset = np.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 129 128 self.offset = offset 130 129 … … 140 139 """ 141 140 q_calc = self.resolution.q_calc 142 if isinstance(q_calc, tuple): 143 # We are 2D -> 1D! 144 iq_calc = self.model.evalDistribution(q_calc) 145 else: 146 if last_bin is None: last_bin = len(iq_in) 147 start, end = first_bin + self.offset, last_bin + self.offset 148 iq_calc = numpy.empty_like(q_calc) 149 if start > 0: 150 iq_calc[:start] = self.model.evalDistribution(q_calc[:start]) 151 if end+1 < len(q_calc): 152 iq_calc[end+1:] = self.model.evalDistribution(q_calc[end+1:]) 153 iq_calc[start:end+1] = iq_in[first_bin:last_bin+1] 141 iq_calc = np.empty_like(q_calc) 142 if start > 0: 143 iq_calc[:start] = self.model.evalDistribution(q_calc[:start]) 144 if end+1 < len(q_calc): 145 iq_calc[end+1:] = self.model.evalDistribution(q_calc[end+1:]) 146 iq_calc[start:end+1] = iq_in[first_bin:last_bin+1] 154 147 smeared = self.resolution.apply(iq_calc) 155 148 return smeared … … 166 159 """ 167 160 q = self.resolution.q 168 first = n umpy.searchsorted(q, q_min)169 last = n umpy.searchsorted(q, q_max)161 first = np.searchsorted(q, q_min) 162 last = np.searchsorted(q, q_max) 170 163 return first, min(last,len(q)-1) 171 164 … … 256 249 val = self.model.evalDistribution(q_calc) 257 250 return val 258 -
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.