Changeset 9a5097c in sasview for src/sas/sascalc/pr
- 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
- Location:
- src/sas/sascalc/pr
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/pr/fit/AbstractFitEngine.py
rfc18690 r9a5097c 4 4 import sys 5 5 import math 6 import numpy 6 import numpy as np 7 7 8 8 from sas.sascalc.dataloader.data_info import Data1D … … 162 162 # constant, or dy data 163 163 if dy is None or dy == [] or dy.all() == 0: 164 self.dy = n umpy.ones(len(y))164 self.dy = np.ones(len(y)) 165 165 else: 166 self.dy = n umpy.asarray(dy).copy()166 self.dy = np.asarray(dy).copy() 167 167 168 168 ## Min Q-value 169 169 #Skip the Q=0 point, especially when y(q=0)=None at x[0]. 170 170 if min(self.x) == 0.0 and self.x[0] == 0 and\ 171 not n umpy.isfinite(self.y[0]):171 not np.isfinite(self.y[0]): 172 172 self.qmin = min(self.x[self.x != 0]) 173 173 else: … … 188 188 # Skip Q=0 point, (especially for y(q=0)=None at x[0]). 189 189 # ToDo: Find better way to do it. 190 if qmin == 0.0 and not n umpy.isfinite(self.y[qmin]):190 if qmin == 0.0 and not np.isfinite(self.y[qmin]): 191 191 self.qmin = min(self.x[self.x != 0]) 192 192 elif qmin != None: … … 239 239 """ 240 240 # Compute theory data f(x) 241 fx = n umpy.zeros(len(self.x))241 fx = np.zeros(len(self.x)) 242 242 fx[self.idx_unsmeared] = fn(self.x[self.idx_unsmeared]) 243 243 … … 247 247 self._last_unsmeared_bin) 248 248 ## Sanity check 249 if n umpy.size(self.dy) != numpy.size(fx):249 if np.size(self.dy) != np.size(fx): 250 250 msg = "FitData1D: invalid error array " 251 msg += "%d <> %d" % (n umpy.shape(self.dy), numpy.size(fx))251 msg += "%d <> %d" % (np.shape(self.dy), np.size(fx)) 252 252 raise RuntimeError, msg 253 253 return (self.y[self.idx] - fx[self.idx]) / self.dy[self.idx], fx[self.idx] … … 300 300 ## new error image for fitting purpose 301 301 if self.err_data == None or self.err_data == []: 302 self.res_err_data = n umpy.ones(len(self.data))302 self.res_err_data = np.ones(len(self.data)) 303 303 else: 304 304 self.res_err_data = copy.deepcopy(self.err_data) 305 305 #self.res_err_data[self.res_err_data==0]=1 306 306 307 self.radius = n umpy.sqrt(self.qx_data**2 + self.qy_data**2)307 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 308 308 309 309 # Note: mask = True: for MASK while mask = False for NOT to mask … … 311 311 (self.radius <= self.qmax)) 312 312 self.idx = (self.idx) & (self.mask) 313 self.idx = (self.idx) & (n umpy.isfinite(self.data))314 self.num_points = n umpy.sum(self.idx)313 self.idx = (self.idx) & (np.isfinite(self.data)) 314 self.num_points = np.sum(self.idx) 315 315 316 316 def set_smearer(self, smearer): … … 334 334 if qmax != None: 335 335 self.qmax = qmax 336 self.radius = n umpy.sqrt(self.qx_data**2 + self.qy_data**2)336 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 337 337 self.idx = ((self.qmin <= self.radius) &\ 338 338 (self.radius <= self.qmax)) 339 339 self.idx = (self.idx) & (self.mask) 340 self.idx = (self.idx) & (n umpy.isfinite(self.data))340 self.idx = (self.idx) & (np.isfinite(self.data)) 341 341 self.idx = (self.idx) & (self.res_err_data != 0) 342 342 … … 351 351 Number of measurement points in data set after masking, etc. 352 352 """ 353 return n umpy.sum(self.idx)353 return np.sum(self.idx) 354 354 355 355 def residuals(self, fn): -
src/sas/sascalc/pr/fit/BumpsFitting.py
rb699768 r9a5097c 5 5 from datetime import timedelta, datetime 6 6 7 import numpy 7 import numpy as np 8 8 9 9 from bumps import fitters … … 96 96 try: 97 97 p = history.population_values[0] 98 n,p = len(p), n umpy.sort(p)98 n,p = len(p), np.sort(p) 99 99 QI,Qmid, = int(0.2*n),int(0.5*n) 100 100 self.convergence.append((best, p[0],p[QI],p[Qmid],p[-1-QI],p[-1])) … … 193 193 194 194 def numpoints(self): 195 return n umpy.sum(self.data.idx) # number of fitted points195 return np.sum(self.data.idx) # number of fitted points 196 196 197 197 def nllf(self): 198 return 0.5*n umpy.sum(self.residuals()**2)198 return 0.5*np.sum(self.residuals()**2) 199 199 200 200 def theory(self): … … 293 293 R.success = result['success'] 294 294 if R.success: 295 R.stderr = n umpy.hstack((result['stderr'][fitted_index],296 numpy.NaN*numpy.ones(len(fitness.computed_pars))))297 R.pvec = n umpy.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], 298 298 [p.value for p in fitness.computed_pars])) 299 R.fitness = n umpy.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index))299 R.fitness = np.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index)) 300 300 else: 301 R.stderr = n umpy.NaN*numpy.ones(len(param_list))302 R.pvec = n umpy.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars])303 R.fitness = n umpy.NaN301 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 304 304 R.convergence = result['convergence'] 305 305 if result['uncertainty'] is not None: … … 331 331 max_step = steps + options.get('burn', 0) 332 332 pars = [p.name for p in problem._parameters] 333 #x0 = n umpy.asarray([p.value for p in problem._parameters])333 #x0 = np.asarray([p.value for p in problem._parameters]) 334 334 options['monitors'] = [ 335 335 BumpsMonitor(handler, max_step, pars, problem.dof), … … 352 352 353 353 convergence_list = options['monitors'][-1].convergence 354 convergence = (2*n umpy.asarray(convergence_list)/problem.dof355 if convergence_list else n umpy.empty((0,1),'d'))354 convergence = (2*np.asarray(convergence_list)/problem.dof 355 if convergence_list else np.empty((0,1),'d')) 356 356 357 357 success = best is not None -
src/sas/sascalc/pr/fit/Loader.py
rb699768 r9a5097c 2 2 #import wx 3 3 #import string 4 import numpy 4 import numpy as np 5 5 6 6 class Load: … … 52 52 self.y.append(y) 53 53 self.dy.append(dy) 54 self.dx = n umpy.zeros(len(self.x))54 self.dx = np.zeros(len(self.x)) 55 55 except: 56 56 print "READ ERROR", line -
src/sas/sascalc/pr/fit/expression.py
rb699768 r9a5097c 271 271 272 272 def test_deps(): 273 import numpy 273 import numpy as np 274 274 275 275 # Null case … … 279 279 _check("test1",[(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)]) 280 280 _check("test1 renumbered",[(6,1),(7,3),(7,4),(6,7),(5,7),(3,2)]) 281 _check("test1 numpy",n umpy.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)])) 282 282 283 283 # No dependencies … … 291 291 292 292 # large test for gross speed check 293 A = n umpy.random.randint(4000,size=(1000,2))293 A = np.random.randint(4000,size=(1000,2)) 294 294 A[:,1] += 4000 # Avoid cycles 295 295 _check("test-large",A) … … 297 297 # depth tests 298 298 k = 200 299 A = n umpy.array([range(0,k),range(1,k+1)]).T299 A = np.array([range(0,k),range(1,k+1)]).T 300 300 _check("depth-1",A) 301 301 302 A = n umpy.array([range(1,k+1),range(0,k)]).T302 A = np.array([range(1,k+1),range(0,k)]).T 303 303 _check("depth-2",A) 304 304 -
src/sas/sascalc/pr/invertor.py
r2c60f304 r9a5097c 7 7 """ 8 8 9 import numpy 9 import numpy as np 10 10 import sys 11 11 import math … … 189 189 #import numpy 190 190 if name == 'x': 191 out = n umpy.ones(self.get_nx())191 out = np.ones(self.get_nx()) 192 192 self.get_x(out) 193 193 return out 194 194 elif name == 'y': 195 out = n umpy.ones(self.get_ny())195 out = np.ones(self.get_ny()) 196 196 self.get_y(out) 197 197 return out 198 198 elif name == 'err': 199 out = n umpy.ones(self.get_nerr())199 out = np.ones(self.get_nerr()) 200 200 self.get_err(out) 201 201 return out … … 325 325 raise RuntimeError, msg 326 326 327 p = n umpy.ones(nfunc)327 p = np.ones(nfunc) 328 328 t_0 = time.time() 329 329 out, cov_x, _, _, _ = optimize.leastsq(self.residuals, p, full_output=1) … … 341 341 342 342 if cov_x is None: 343 cov_x = n umpy.ones([nfunc, nfunc])343 cov_x = np.ones([nfunc, nfunc]) 344 344 cov_x *= math.fabs(chisqr) 345 345 return out, cov_x … … 358 358 raise RuntimeError, msg 359 359 360 p = n umpy.ones(nfunc)360 p = np.ones(nfunc) 361 361 t_0 = time.time() 362 362 out, cov_x, _, _, _ = optimize.leastsq(self.pr_residuals, p, full_output=1) … … 435 435 """ 436 436 # Note: To make sure an array is contiguous: 437 # blah = n umpy.ascontiguousarray(blah_original)437 # blah = np.ascontiguousarray(blah_original) 438 438 # ... before passing it to C 439 439 … … 456 456 nfunc += 1 457 457 458 a = n umpy.zeros([npts + nq, nfunc])459 b = n umpy.zeros(npts + nq)460 err = n umpy.zeros([nfunc, nfunc])458 a = np.zeros([npts + nq, nfunc]) 459 b = np.zeros(npts + nq) 460 err = np.zeros([nfunc, nfunc]) 461 461 462 462 # Construct the a matrix and b vector that represent the problem … … 476 476 self.chi2 = chi2 477 477 478 inv_cov = n umpy.zeros([nfunc, nfunc])478 inv_cov = np.zeros([nfunc, nfunc]) 479 479 # Get the covariance matrix, defined as inv_cov = a_transposed * a 480 480 self._get_invcov_matrix(nfunc, nr, a, inv_cov) … … 490 490 491 491 try: 492 cov = n umpy.linalg.pinv(inv_cov)492 cov = np.linalg.pinv(inv_cov) 493 493 err = math.fabs(chi2 / float(npts - nfunc)) * cov 494 494 except: … … 505 505 self.background = c[0] 506 506 507 err_0 = n umpy.zeros([nfunc, nfunc])508 c_0 = n umpy.zeros(nfunc)507 err_0 = np.zeros([nfunc, nfunc]) 508 c_0 = np.zeros(nfunc) 509 509 510 510 for i in range(nfunc_0): … … 662 662 str(self.cov[i][i]))) 663 663 file.write("<r> <Pr> <dPr>\n") 664 r = n umpy.arange(0.0, self.d_max, self.d_max / npts)664 r = np.arange(0.0, self.d_max, self.d_max / npts) 665 665 666 666 for r_i in r: … … 694 694 toks = line.split('=') 695 695 self.nfunc = int(toks[1]) 696 self.out = n umpy.zeros(self.nfunc)697 self.cov = n umpy.zeros([self.nfunc, self.nfunc])696 self.out = np.zeros(self.nfunc) 697 self.cov = np.zeros([self.nfunc, self.nfunc]) 698 698 elif line.startswith('#alpha='): 699 699 toks = line.split('=') -
src/sas/sascalc/pr/num_term.py
rb699768 r9a5097c 1 1 import math 2 import numpy 2 import numpy as np 3 3 import copy 4 4 import sys … … 152 152 def load(path): 153 153 # Read the data from the data file 154 data_x = n umpy.zeros(0)155 data_y = n umpy.zeros(0)156 data_err = n umpy.zeros(0)154 data_x = np.zeros(0) 155 data_y = np.zeros(0) 156 data_err = np.zeros(0) 157 157 scale = None 158 158 min_err = 0.0 … … 176 176 #err = 0 177 177 178 data_x = n umpy.append(data_x, test_x)179 data_y = n umpy.append(data_y, test_y)180 data_err = n umpy.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) 181 181 except: 182 182 logging.error(sys.exc_value)
Note: See TracChangeset
for help on using the changeset viewer.