Changeset 793e52f in sasview
- Timestamp:
- Jan 11, 2010 8:59:14 AM (15 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 2a11d09
- Parents:
- 9e37661
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Invariant/invariant.py
r9e37661 r793e52f 66 66 """ 67 67 self.data = data 68 69 # Set qmin as the lowest non-zero value 70 self.qmin = Q_MINIMUM 71 for q_value in self.data.x: 72 if q_value>0: 73 self.qmin = q_value 74 break 75 self.qmax = max(self.data.x) 76 68 x_len = len(self.data.x) -1 69 #fitting range 70 self.qmin = self.data.x[0] 71 if self.qmin == 0: 72 self.qmin = Q_MINIMUM 73 74 self.qmax = self.data.x[x_len] 75 #Unsmeared q range 76 self._qmin_unsmeared = 0 77 self._qmax_unsmeared = self.data.x[x_len] 78 79 #bin for smear data 80 self._first_unsmeared_bin = 0 81 self._last_unsmeared_bin = x_len 82 83 # Identify the bin range for the unsmeared and smeared spaces 84 self.idx = (self.data.x >= self.qmin) & (self.data.x <= self.qmax) 85 self.idx_unsmeared = (self.data.x >= self._qmin_unsmeared) \ 86 & (self.data.x <= self._qmax_unsmeared) 87 77 88 #get the smear object of data 78 89 self.smearer = smear_selection( self.data ) 79 # Set the q-range information to allow smearing80 self.set_fit_range()81 90 82 91 def set_fit_range(self ,qmin=None, qmax=None): … … 92 101 self._qmax_unsmeared = self.qmax 93 102 94 if self.smearer is not None: 103 self._first_unsmeared_bin = 0 104 self._last_unsmeared_bin = len(self.data.x)-1 105 106 if self.smearer!=None: 95 107 self._first_unsmeared_bin, self._last_unsmeared_bin = self.smearer.get_bin_range(self.qmin, self.qmax) 96 108 self._qmin_unsmeared = self.data.x[self._first_unsmeared_bin] … … 107 119 @param power = a fixed, otherwise None 108 120 """ 121 power = power 109 122 fx = numpy.zeros(len(self.data.x)) 110 111 # Uncertainty 112 if type(self.data.y)==numpy.ndarray and len(self.data.y)==len(self.data.x): 113 sigma = self.data.y 114 else: 115 sigma = numpy.ones(len(self.data.x)) 123 one = numpy.ones(len(self.data.x)) 124 125 #define dy^2 126 try: 127 sigma = self.data.dy[self.idx_unsmeared ] 128 except: 129 print "The dy data for Invariant calculation should be prepared before get to FitFunctor.fit()..." 130 sigma = one[self.idx_unsmeared ] 131 sigma2 = sigma * sigma 116 132 117 133 # Compute theory data f(x) 118 fx [self.idx_unsmeared] = self.data.y[self.idx_unsmeared]134 fx = self.data.y[self.idx_unsmeared ]/sigma 119 135 ## Smear theory data 120 136 if self.smearer is not None: 121 137 fx = self.smearer(fx, self._first_unsmeared_bin,self._last_unsmeared_bin) 122 138 123 fx[self.idx_unsmeared] = fx[self.idx_unsmeared]/sigma[self.idx_unsmeared]124 125 139 ##power is given only for function = power_law 126 140 if power != None: 127 sigma2 = sigma * sigma128 141 a = -(power) 129 b = (numpy.sum(fx [self.idx]/sigma[self.idx]) - a*numpy.sum(self.data.x[self.idx]/sigma2[self.idx]))/numpy.sum(numpy.ones(len(sigma2[self.idx]))/sigma2[self.idx])142 b = (numpy.sum(fx/sigma) - a*numpy.sum(self.data.x[self.idx]/sigma2))/numpy.sum(numpy.ones(len(sigma2))/sigma2) 130 143 return a, b 131 144 else: 132 A = numpy.vstack([ self.data.x[self.idx]/sigma [self.idx],133 numpy.ones(len(self.data.x[self.idx]))/sigma [self.idx]]).T145 A = numpy.vstack([ self.data.x[self.idx]/sigma, 146 numpy.ones(len(self.data.x[self.idx]))/sigma]).T 134 147 135 a, b = numpy.linalg.lstsq(A, fx [self.idx])[0]148 a, b = numpy.linalg.lstsq(A, fx)[0] 136 149 return a, b 137 150 … … 152 165 Initialize variables 153 166 @param data: data must be of type DataLoader.Data1D 154 @param background: Background value. The data will be corrected before processing155 @param scale: Scaling factor for I(q). The data will be corrected before processing167 @param contrast: contrast value of type float 168 @param pConst: Porod Constant of type float 156 169 """ 157 170 # Background and scale should be private data member if the only way to … … 189 202 #Process only data that inherited from DataLoader.Data_info.Data1D 190 203 raise ValueError,"Data must be of type DataLoader.Data1D" 191 192 new_data = (self._scale * data) - self._background 193 194 # Copy data that is not copied by the operations 195 #TODO: fix this in DataLoader 196 new_data.dxl = data.dxl 197 new_data.dxw = data.dxw 204 new_data = self._scale * data - self._background 205 try: 206 #All data should pass here. 207 new_data.dy = data.dy 208 new_data.dxl = data.dxl 209 new_data.dxw = data.dxw 210 except: 211 #in case... 212 new_data.dy = numpy.ones(len(data.x)) 213 new_data.dxl = numpy.zeros(len(data.x)) 214 new_data.dxw = numpy.zeros(len(data.x)) 198 215 199 216 return new_data … … 393 410 note: if data doesn't contain dy assume dy= math.sqrt(data.y) 394 411 """ 412 if data is None: 413 data = self.data 414 395 415 if len(data.x) <= 1 or len(data.y) <= 1 or \ 396 416 len(self.data.x) != len(self.data.y): … … 528 548 qmin = self._data.x[0] 529 549 qmax = self._data.x[self._low_extrapolation_npts - 1] 530 531 # Extrapolate the low-Q data 532 #TODO: this fit fails. Fix it. 533 a, b = self._fit(function=self._low_extrapolation_function, 534 qmin=qmin, 535 qmax=qmax, 536 power=self._low_extrapolation_power) 550 try: 551 # fit the data with a model to get the appropriate parameters 552 a, b = self._fit(function=self._low_extrapolation_function, 553 qmin=qmin, 554 qmax=qmax, 555 power=self._low_extrapolation_power) 556 except: 557 #raise 558 return None 537 559 538 560 #q_start point
Note: See TracChangeset
for help on using the changeset viewer.