Changeset 1e3169c in sasview for park_integration/AbstractFitEngine.py
- Timestamp:
- Oct 27, 2009 1:56:39 PM (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:
- b37f72f
- Parents:
- cc1500d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r2eaaf1a r1e3169c 1 1 import logging, sys 2 2 import park,numpy,math, copy 3 3 from DataLoader.data_info import Data1D 4 from DataLoader.data_info import Data2D 4 5 class SansParameter(park.Parameter): 5 6 """ … … 119 120 120 121 121 class FitData1D(object): 122 """ Wrapper class for SANS data """ 123 def __init__(self,sans_data1d, smearer=None): 124 """ 125 Data can be initital with a data (sans plottable) 126 or with vectors. 127 128 self.smearer is an object of class QSmearer or SlitSmearer 122 class FitData1D(Data1D): 123 """ 124 Wrapper class for SANS data 125 FitData1D inherits from DataLoader.data_info.Data1D. Implements 126 a way to get residuals from data. 127 """ 128 def __init__(self,x, y,dx= None, dy=None, smearer=None): 129 Data1D.__init__(self, x=x, y=y, dx=dx, dy=dy) 130 """ 131 @param smearer: is an object of class QSmearer or SlitSmearer 129 132 that will smear the theory data (slit smearing or resolution 130 133 smearing) when set. … … 134 137 135 138 from DataLoader.qsmearing import smear_selection 136 fitdata1d = FitData1D(some_data) 137 fitdata1d.smearer = smear_selection(some_data) 138 139 smearer = smear_selection(some_data) 140 fitdata1d = FitData1D( x= [1,3,..,], 141 y= [3,4,..,8], 142 dx=None, 143 dy=[1,2...], smearer= smearer) 144 139 145 Note that some_data _HAS_ to be of class DataLoader.data_info.Data1D 140 146 … … 144 150 145 151 self.smearer = smearer 146 147 # Initialize from Data1D object 148 self.data=sans_data1d 149 self.x= numpy.array(sans_data1d.x) 150 self.y= numpy.array(sans_data1d.y) 151 self.dx= sans_data1d.dx 152 if sans_data1d.dy ==None or sans_data1d.dy==[]: 152 if dy ==None or dy==[]: 153 153 self.dy= numpy.zeros(len(self.y)) 154 154 else: 155 self.dy= numpy.asarray( sans_data1d.dy)155 self.dy= numpy.asarray(dy) 156 156 157 157 # For fitting purposes, replace zero errors by 1 … … 162 162 ## Min Q-value 163 163 #Skip the Q=0 point, especially when y(q=0)=None at x[0]. 164 if min (self. data.x) ==0.0 and self.data.x[0]==0 and not numpy.isfinite(self.data.y[0]):165 self.qmin = min(self. data.x[self.data.x!=0])164 if min (self.x) ==0.0 and self.x[0]==0 and not numpy.isfinite(self.y[0]): 165 self.qmin = min(self.x[self.x!=0]) 166 166 else: 167 self.qmin= min (self. data.x)167 self.qmin= min (self.x) 168 168 ## Max Q-value 169 self.qmax = max (self.data.x)169 self.qmax = max (self.x) 170 170 171 171 # Range used for input to smearing … … 182 182 # Skip Q=0 point, (especially for y(q=0)=None at x[0]). 183 183 #ToDo: Fix this. 184 if qmin==0.0 and not numpy.isfinite(self. data.y[qmin]):185 self.qmin = min(self. data.x[self.data.x!=0])184 if qmin==0.0 and not numpy.isfinite(self.y[qmin]): 185 self.qmin = min(self.x[self.x!=0]) 186 186 elif qmin!=None: 187 187 self.qmin = qmin … … 196 196 197 197 self._first_unsmeared_bin = 0 198 self._last_unsmeared_bin = len(self. data.x)-1198 self._last_unsmeared_bin = len(self.x)-1 199 199 200 200 if self.smearer!=None: 201 201 self._first_unsmeared_bin, self._last_unsmeared_bin = self.smearer.get_bin_range(self.qmin, self.qmax) 202 self._qmin_unsmeared = self. data.x[self._first_unsmeared_bin]203 self._qmax_unsmeared = self. data.x[self._last_unsmeared_bin]202 self._qmin_unsmeared = self.x[self._first_unsmeared_bin] 203 self._qmax_unsmeared = self.x[self._last_unsmeared_bin] 204 204 205 205 # Identify the bin range for the unsmeared and smeared spaces … … 249 249 250 250 251 class FitData2D( object):251 class FitData2D(Data2D): 252 252 """ Wrapper class for SANS data """ 253 def __init__(self,sans_data2d): 253 def __init__(self,sans_data2d ,data=None, err_data=None,): 254 Data2D.__init__(self, data= data, err_data= err_data) 254 255 """ 255 256 Data can be initital with a data (sans plottable) 256 257 or with vectors. 257 258 """ 258 self.data=sans_data2d 259 self.image = sans_data2d.data 260 self.err_image = sans_data2d.err_data 259 self.x_bins_array = [] 260 self.y_bins_array = [] 261 self.res_err_image=[] 262 self.index_model=[] 263 self.qmin= None 264 self.qmax= None 265 self.set_data(sans_data2d ) 266 267 268 def set_data(self, sans_data2d ): 269 """ 270 Determine the correct x_bin and y_bin to fit 271 """ 272 self.err_data = sans_data2d.err_data 261 273 self.x_bins_array= numpy.reshape(sans_data2d.x_bins, 262 274 [1,len(sans_data2d.x_bins)]) … … 264 276 [len(sans_data2d.y_bins),1]) 265 277 266 x = max(self.data.xmin, self.data.xmax)267 y = max(self.data.ymin, self.data.ymax)278 x_max = max(self.data.xmin, self.data.xmax) 279 y_max = max(self.data.ymin, self.data.ymax) 268 280 269 281 ## fitting range 270 282 self.qmin = 1e-16 271 self.qmax = math.sqrt(x *x +y*y)283 self.qmax = math.sqrt(x_max*x_max +y_max*y_max) 272 284 ## new error image for fitting purpose 273 285 if self.err_image== None or self.err_image ==[]: … … 467 479 """ 468 480 if data.__class__.__name__=='Data2D': 469 fitdata=FitData2D( data)470 else: 471 fitdata=FitData1D( data,smearer)481 fitdata=FitData2D(sans_data2d=data, data=data.data, err_data= data.err_data) 482 else: 483 fitdata=FitData1D(x=data.x, y=data.y , dx= data.dx,dy=data.dy,smearer=smearer) 472 484 473 485 fitdata.setFitRange(qmin=qmin,qmax=qmax)
Note: See TracChangeset
for help on using the changeset viewer.