Changeset 9c0f3c17 in sasview for src/sas/sascalc/pr
- Timestamp:
- Apr 4, 2017 12:50:04 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:
- 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. - 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
r463e7ffc r9c0f3c17 7 7 """ 8 8 9 import numpy 9 import numpy as np 10 10 import sys 11 11 import math … … 191 191 #import numpy 192 192 if name == 'x': 193 out = n umpy.ones(self.get_nx())193 out = np.ones(self.get_nx()) 194 194 self.get_x(out) 195 195 return out 196 196 elif name == 'y': 197 out = n umpy.ones(self.get_ny())197 out = np.ones(self.get_ny()) 198 198 self.get_y(out) 199 199 return out 200 200 elif name == 'err': 201 out = n umpy.ones(self.get_nerr())201 out = np.ones(self.get_nerr()) 202 202 self.get_err(out) 203 203 return out … … 327 327 raise RuntimeError, msg 328 328 329 p = n umpy.ones(nfunc)329 p = np.ones(nfunc) 330 330 t_0 = time.time() 331 331 out, cov_x, _, _, _ = optimize.leastsq(self.residuals, p, full_output=1) … … 343 343 344 344 if cov_x is None: 345 cov_x = n umpy.ones([nfunc, nfunc])345 cov_x = np.ones([nfunc, nfunc]) 346 346 cov_x *= math.fabs(chisqr) 347 347 return out, cov_x … … 360 360 raise RuntimeError, msg 361 361 362 p = n umpy.ones(nfunc)362 p = np.ones(nfunc) 363 363 t_0 = time.time() 364 364 out, cov_x, _, _, _ = optimize.leastsq(self.pr_residuals, p, full_output=1) … … 437 437 """ 438 438 # Note: To make sure an array is contiguous: 439 # blah = n umpy.ascontiguousarray(blah_original)439 # blah = np.ascontiguousarray(blah_original) 440 440 # ... before passing it to C 441 441 … … 458 458 nfunc += 1 459 459 460 a = n umpy.zeros([npts + nq, nfunc])461 b = n umpy.zeros(npts + nq)462 err = n umpy.zeros([nfunc, nfunc])460 a = np.zeros([npts + nq, nfunc]) 461 b = np.zeros(npts + nq) 462 err = np.zeros([nfunc, nfunc]) 463 463 464 464 # Construct the a matrix and b vector that represent the problem … … 478 478 self.chi2 = chi2 479 479 480 inv_cov = n umpy.zeros([nfunc, nfunc])480 inv_cov = np.zeros([nfunc, nfunc]) 481 481 # Get the covariance matrix, defined as inv_cov = a_transposed * a 482 482 self._get_invcov_matrix(nfunc, nr, a, inv_cov) … … 492 492 493 493 try: 494 cov = n umpy.linalg.pinv(inv_cov)494 cov = np.linalg.pinv(inv_cov) 495 495 err = math.fabs(chi2 / float(npts - nfunc)) * cov 496 496 except: … … 507 507 self.background = c[0] 508 508 509 err_0 = n umpy.zeros([nfunc, nfunc])510 c_0 = n umpy.zeros(nfunc)509 err_0 = np.zeros([nfunc, nfunc]) 510 c_0 = np.zeros(nfunc) 511 511 512 512 for i in range(nfunc_0): … … 664 664 str(self.cov[i][i]))) 665 665 file.write("<r> <Pr> <dPr>\n") 666 r = n umpy.arange(0.0, self.d_max, self.d_max / npts)666 r = np.arange(0.0, self.d_max, self.d_max / npts) 667 667 668 668 for r_i in r: … … 696 696 toks = line.split('=') 697 697 self.nfunc = int(toks[1]) 698 self.out = n umpy.zeros(self.nfunc)699 self.cov = n umpy.zeros([self.nfunc, self.nfunc])698 self.out = np.zeros(self.nfunc) 699 self.cov = np.zeros([self.nfunc, self.nfunc]) 700 700 elif line.startswith('#alpha='): 701 701 toks = line.split('=') -
src/sas/sascalc/pr/num_term.py
r463e7ffc r9c0f3c17 1 1 import math 2 import numpy 2 import numpy as np 3 3 import copy 4 4 import sys … … 154 154 def load(path): 155 155 # Read the data from the data file 156 data_x = n umpy.zeros(0)157 data_y = n umpy.zeros(0)158 data_err = n umpy.zeros(0)156 data_x = np.zeros(0) 157 data_y = np.zeros(0) 158 data_err = np.zeros(0) 159 159 scale = None 160 160 min_err = 0.0 … … 178 178 #err = 0 179 179 180 data_x = n umpy.append(data_x, test_x)181 data_y = n umpy.append(data_y, test_y)182 data_err = n umpy.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) 183 183 except: 184 184 logger.error(sys.exc_value)
Note: See TracChangeset
for help on using the changeset viewer.