Changeset 9a5097c in sasview for src/sas/sascalc/invariant
- Timestamp:
- Mar 26, 2017 9: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/invariant/invariant.py
rb699768 r9a5097c 17 17 """ 18 18 import math 19 import numpy 19 import numpy as np 20 20 21 21 from sas.sascalc.dataloader.data_info import Data1D as LoaderData1D … … 50 50 dy = data.dy 51 51 else: 52 dy = n umpy.ones(len(data.y))52 dy = np.ones(len(data.y)) 53 53 54 54 # Transform the data … … 63 63 64 64 # Create Data1D object 65 x_out = n umpy.asarray(x_out)66 y_out = n umpy.asarray(y_out)67 dy_out = n umpy.asarray(dy_out)65 x_out = np.asarray(x_out) 66 y_out = np.asarray(y_out) 67 dy_out = np.asarray(dy_out) 68 68 linear_data = LoaderData1D(x=x_out, y=y_out, dy=dy_out) 69 69 … … 158 158 :param x: array of q-values 159 159 """ 160 p1 = n umpy.array([self.dscale * math.exp(-((self.radius * q) ** 2 / 3)) \160 p1 = np.array([self.dscale * math.exp(-((self.radius * q) ** 2 / 3)) \ 161 161 for q in x]) 162 p2 = n umpy.array([self.scale * math.exp(-((self.radius * q) ** 2 / 3))\162 p2 = np.array([self.scale * math.exp(-((self.radius * q) ** 2 / 3))\ 163 163 * (-(q ** 2 / 3)) * 2 * self.radius * self.dradius for q in x]) 164 164 diq2 = p1 * p1 + p2 * p2 165 return n umpy.array([math.sqrt(err) for err in diq2])165 return np.array([math.sqrt(err) for err in diq2]) 166 166 167 167 def _guinier(self, x): … … 182 182 msg = "Rg expected positive value, but got %s" % self.radius 183 183 raise ValueError(msg) 184 value = n umpy.array([math.exp(-((self.radius * i) ** 2 / 3)) for i in x])184 value = np.array([math.exp(-((self.radius * i) ** 2 / 3)) for i in x]) 185 185 return self.scale * value 186 186 … … 232 232 :param x: array of q-values 233 233 """ 234 p1 = n umpy.array([self.dscale * math.pow(q, -self.power) for q in x])235 p2 = n umpy.array([self.scale * self.power * math.pow(q, -self.power - 1)\234 p1 = np.array([self.dscale * math.pow(q, -self.power) for q in x]) 235 p2 = np.array([self.scale * self.power * math.pow(q, -self.power - 1)\ 236 236 * self.dpower for q in x]) 237 237 diq2 = p1 * p1 + p2 * p2 238 return n umpy.array([math.sqrt(err) for err in diq2])238 return np.array([math.sqrt(err) for err in diq2]) 239 239 240 240 def _power_law(self, x): … … 259 259 raise ValueError(msg) 260 260 261 value = n umpy.array([math.pow(i, -self.power) for i in x])261 value = np.array([math.pow(i, -self.power) for i in x]) 262 262 return self.scale * value 263 263 … … 304 304 idx = (self.data.x >= qmin) & (self.data.x <= qmax) 305 305 306 fx = n umpy.zeros(len(self.data.x))306 fx = np.zeros(len(self.data.x)) 307 307 308 308 # Uncertainty 309 if type(self.data.dy) == n umpy.ndarray and \309 if type(self.data.dy) == np.ndarray and \ 310 310 len(self.data.dy) == len(self.data.x) and \ 311 numpy.all(self.data.dy > 0):311 np.all(self.data.dy > 0): 312 312 sigma = self.data.dy 313 313 else: 314 sigma = n umpy.ones(len(self.data.x))314 sigma = np.ones(len(self.data.x)) 315 315 316 316 # Compute theory data f(x) … … 332 332 sigma2 = linearized_data.dy * linearized_data.dy 333 333 a = -(power) 334 b = (n umpy.sum(linearized_data.y / sigma2) \335 - a * n umpy.sum(linearized_data.x / sigma2)) / numpy.sum(1.0 / sigma2)334 b = (np.sum(linearized_data.y / sigma2) \ 335 - a * np.sum(linearized_data.x / sigma2)) / np.sum(1.0 / sigma2) 336 336 337 337 338 338 deltas = linearized_data.x * a + \ 339 numpy.ones(len(linearized_data.x)) * b - linearized_data.y340 residuals = n umpy.sum(deltas * deltas / sigma2)341 342 err = math.fabs(residuals) / n umpy.sum(1.0 / sigma2)339 np.ones(len(linearized_data.x)) * b - linearized_data.y 340 residuals = np.sum(deltas * deltas / sigma2) 341 342 err = math.fabs(residuals) / np.sum(1.0 / sigma2) 343 343 return [a, b], [0, math.sqrt(err)] 344 344 else: 345 A = n umpy.vstack([linearized_data.x / linearized_data.dy, 1.0 / linearized_data.dy]).T346 (p, residuals, _, _) = n umpy.linalg.lstsq(A, linearized_data.y / linearized_data.dy)345 A = np.vstack([linearized_data.x / linearized_data.dy, 1.0 / linearized_data.dy]).T 346 (p, residuals, _, _) = np.linalg.lstsq(A, linearized_data.y / linearized_data.dy) 347 347 348 348 # Get the covariance matrix, defined as inv_cov = a_transposed * a 349 err = n umpy.zeros(2)349 err = np.zeros(2) 350 350 try: 351 inv_cov = n umpy.dot(A.transpose(), A)352 cov = n umpy.linalg.pinv(inv_cov)351 inv_cov = np.dot(A.transpose(), A) 352 cov = np.linalg.pinv(inv_cov) 353 353 err_matrix = math.fabs(residuals) * cov 354 354 err = [math.sqrt(err_matrix[0][0]), math.sqrt(err_matrix[1][1])] … … 434 434 if new_data.dy is None or len(new_data.x) != len(new_data.dy) or \ 435 435 (min(new_data.dy) == 0 and max(new_data.dy) == 0): 436 new_data.dy = n umpy.ones(len(new_data.x))436 new_data.dy = np.ones(len(new_data.x)) 437 437 return new_data 438 438 … … 571 571 """ 572 572 #create new Data1D to compute the invariant 573 q = n umpy.linspace(start=q_start,573 q = np.linspace(start=q_start, 574 574 stop=q_end, 575 575 num=npts, … … 580 580 result_data = LoaderData1D(x=q, y=iq, dy=diq) 581 581 if self._smeared != None: 582 result_data.dxl = self._smeared * n umpy.ones(len(q))582 result_data.dxl = self._smeared * np.ones(len(q)) 583 583 return result_data 584 584 … … 691 691 692 692 if q_start >= q_end: 693 return n umpy.zeros(0), numpy.zeros(0)693 return np.zeros(0), np.zeros(0) 694 694 695 695 return self._get_extrapolated_data(\ … … 719 719 720 720 if q_start >= q_end: 721 return n umpy.zeros(0), numpy.zeros(0)721 return np.zeros(0), np.zeros(0) 722 722 723 723 return self._get_extrapolated_data(\
Note: See TracChangeset
for help on using the changeset viewer.