[113] | 1 | import _asap
|
---|
[259] | 2 | from asap import rcParams
|
---|
[723] | 3 | from asap import print_log
|
---|
[113] | 4 |
|
---|
| 5 | class fitter:
|
---|
| 6 | """
|
---|
| 7 | The fitting class for ASAP.
|
---|
| 8 | """
|
---|
[723] | 9 |
|
---|
[113] | 10 | def __init__(self):
|
---|
| 11 | """
|
---|
| 12 | Create a fitter object. No state is set.
|
---|
| 13 | """
|
---|
| 14 | self.fitter = _asap.fitter()
|
---|
| 15 | self.x = None
|
---|
| 16 | self.y = None
|
---|
| 17 | self.mask = None
|
---|
| 18 | self.fitfunc = None
|
---|
[515] | 19 | self.fitfuncs = None
|
---|
[113] | 20 | self.fitted = False
|
---|
| 21 | self.data = None
|
---|
[515] | 22 | self.components = 0
|
---|
| 23 | self._fittedrow = 0
|
---|
[113] | 24 | self._p = None
|
---|
[515] | 25 | self._selection = None
|
---|
[113] | 26 |
|
---|
| 27 | def set_data(self, xdat, ydat, mask=None):
|
---|
| 28 | """
|
---|
[158] | 29 | Set the absissa and ordinate for the fit. Also set the mask
|
---|
[113] | 30 | indicationg valid points.
|
---|
| 31 | This can be used for data vectors retrieved from a scantable.
|
---|
| 32 | For scantable fitting use 'fitter.set_scan(scan, mask)'.
|
---|
| 33 | Parameters:
|
---|
[158] | 34 | xdat: the abcissa values
|
---|
[113] | 35 | ydat: the ordinate values
|
---|
| 36 | mask: an optional mask
|
---|
[723] | 37 |
|
---|
[113] | 38 | """
|
---|
| 39 | self.fitted = False
|
---|
| 40 | self.x = xdat
|
---|
| 41 | self.y = ydat
|
---|
| 42 | if mask == None:
|
---|
| 43 | from numarray import ones
|
---|
| 44 | self.mask = ones(len(xdat))
|
---|
| 45 | else:
|
---|
| 46 | self.mask = mask
|
---|
| 47 | return
|
---|
| 48 |
|
---|
| 49 | def set_scan(self, thescan=None, mask=None):
|
---|
| 50 | """
|
---|
| 51 | Set the 'data' (a scantable) of the fitter.
|
---|
| 52 | Parameters:
|
---|
| 53 | thescan: a scantable
|
---|
| 54 | mask: a msk retireved from the scantable
|
---|
| 55 | """
|
---|
| 56 | if not thescan:
|
---|
[723] | 57 | msg = "Please give a correct scan"
|
---|
| 58 | if rcParams['verbose']:
|
---|
| 59 | print msg
|
---|
| 60 | return
|
---|
| 61 | else:
|
---|
| 62 | raise TypeError(msg)
|
---|
[113] | 63 | self.fitted = False
|
---|
| 64 | self.data = thescan
|
---|
| 65 | if mask is None:
|
---|
| 66 | from numarray import ones
|
---|
| 67 | self.mask = ones(self.data.nchan())
|
---|
| 68 | else:
|
---|
| 69 | self.mask = mask
|
---|
| 70 | return
|
---|
| 71 |
|
---|
| 72 | def set_function(self, **kwargs):
|
---|
| 73 | """
|
---|
| 74 | Set the function to be fit.
|
---|
| 75 | Parameters:
|
---|
| 76 | poly: use a polynomial of the order given
|
---|
| 77 | gauss: fit the number of gaussian specified
|
---|
| 78 | Example:
|
---|
| 79 | fitter.set_function(gauss=2) # will fit two gaussians
|
---|
| 80 | fitter.set_function(poly=3) # will fit a 3rd order polynomial
|
---|
| 81 | """
|
---|
[723] | 82 | #default poly order 0
|
---|
[515] | 83 | n=0
|
---|
[113] | 84 | if kwargs.has_key('poly'):
|
---|
| 85 | self.fitfunc = 'poly'
|
---|
| 86 | n = kwargs.get('poly')
|
---|
[515] | 87 | self.components = [n]
|
---|
[113] | 88 | elif kwargs.has_key('gauss'):
|
---|
| 89 | n = kwargs.get('gauss')
|
---|
| 90 | self.fitfunc = 'gauss'
|
---|
[515] | 91 | self.fitfuncs = [ 'gauss' for i in range(n) ]
|
---|
| 92 | self.components = [ 3 for i in range(n) ]
|
---|
| 93 | else:
|
---|
[723] | 94 | msg = "Invalid function type."
|
---|
| 95 | if rcParams['verbose']:
|
---|
| 96 | print msg
|
---|
| 97 | return
|
---|
| 98 | else:
|
---|
| 99 | raise TypeError(msg)
|
---|
| 100 |
|
---|
[113] | 101 | self.fitter.setexpression(self.fitfunc,n)
|
---|
| 102 | return
|
---|
[723] | 103 |
|
---|
[515] | 104 | def fit(self, row=0):
|
---|
[113] | 105 | """
|
---|
| 106 | Execute the actual fitting process. All the state has to be set.
|
---|
| 107 | Parameters:
|
---|
[526] | 108 | row: specify the row in the scantable
|
---|
[113] | 109 | Example:
|
---|
[515] | 110 | s = scantable('myscan.asap')
|
---|
| 111 | s.set_cursor(thepol=1) # select second pol
|
---|
[113] | 112 | f = fitter()
|
---|
| 113 | f.set_scan(s)
|
---|
| 114 | f.set_function(poly=0)
|
---|
[723] | 115 | f.fit(row=0) # fit first row
|
---|
[113] | 116 | """
|
---|
| 117 | if ((self.x is None or self.y is None) and self.data is None) \
|
---|
| 118 | or self.fitfunc is None:
|
---|
[723] | 119 | msg = "Fitter not yet initialised. Please set data & fit function"
|
---|
| 120 | if rcParams['verbose']:
|
---|
| 121 | print msg
|
---|
| 122 | return
|
---|
| 123 | else:
|
---|
| 124 | raise RuntimeError(msg)
|
---|
| 125 |
|
---|
[113] | 126 | else:
|
---|
| 127 | if self.data is not None:
|
---|
[515] | 128 | self.x = self.data._getabcissa(row)
|
---|
| 129 | self.y = self.data._getspectrum(row)
|
---|
[723] | 130 | from asap import asaplog
|
---|
| 131 | asaplog.push("Fitting:")
|
---|
[943] | 132 | i = row
|
---|
| 133 | out = "Scan[%d] Beam[%d] IF[%d] Pol[%d] Cycle[%d]" % (self.data.getscan(i),self.data.getbeam(i),self.data.getif(i),self.data.getpol(i), self.data.getcycle(i))
|
---|
[876] | 134 | asaplog.push(out)
|
---|
[515] | 135 | self.fitter.setdata(self.x, self.y, self.mask)
|
---|
[113] | 136 | if self.fitfunc == 'gauss':
|
---|
| 137 | ps = self.fitter.getparameters()
|
---|
| 138 | if len(ps) == 0:
|
---|
| 139 | self.fitter.estimate()
|
---|
[626] | 140 | try:
|
---|
| 141 | self.fitter.fit()
|
---|
| 142 | except RuntimeError, msg:
|
---|
[723] | 143 | if rcParams['verbose']:
|
---|
| 144 | print msg
|
---|
| 145 | else:
|
---|
| 146 | raise
|
---|
[515] | 147 | self._fittedrow = row
|
---|
[113] | 148 | self.fitted = True
|
---|
[723] | 149 | print_log()
|
---|
[113] | 150 | return
|
---|
| 151 |
|
---|
[515] | 152 | def store_fit(self):
|
---|
[526] | 153 | """
|
---|
| 154 | Store the fit parameters in the scantable.
|
---|
| 155 | """
|
---|
[515] | 156 | if self.fitted and self.data is not None:
|
---|
| 157 | pars = list(self.fitter.getparameters())
|
---|
| 158 | fixed = list(self.fitter.getfixedparameters())
|
---|
[975] | 159 | from asap.asapfit import asapfit
|
---|
| 160 | fit = asapfit()
|
---|
| 161 | fit.setparameters(pars)
|
---|
| 162 | fit.setfixedparameters(fixed)
|
---|
| 163 | fit.setfunctions(self.fitfuncs)
|
---|
| 164 | fit.setcomponents(self.components)
|
---|
| 165 | fit.setframeinfo(self.data._getcoordinfo())
|
---|
| 166 | self.data._addfit(fit,self._fittedrow)
|
---|
[515] | 167 |
|
---|
| 168 | def set_parameters(self, params, fixed=None, component=None):
|
---|
[526] | 169 | """
|
---|
| 170 | Set the parameters to be fitted.
|
---|
| 171 | Parameters:
|
---|
| 172 | params: a vector of parameters
|
---|
| 173 | fixed: a vector of which parameters are to be held fixed
|
---|
| 174 | (default is none)
|
---|
| 175 | component: in case of multiple gaussians, the index of the
|
---|
| 176 | component
|
---|
| 177 | """
|
---|
[515] | 178 | if self.fitfunc is None:
|
---|
[723] | 179 | msg = "Please specify a fitting function first."
|
---|
| 180 | if rcParams['verbose']:
|
---|
| 181 | print msg
|
---|
| 182 | return
|
---|
| 183 | else:
|
---|
| 184 | raise RuntimeError(msg)
|
---|
[515] | 185 | if self.fitfunc == "gauss" and component is not None:
|
---|
| 186 | if not self.fitted:
|
---|
| 187 | from numarray import zeros
|
---|
| 188 | pars = list(zeros(len(self.components)*3))
|
---|
| 189 | fxd = list(zeros(len(pars)))
|
---|
| 190 | else:
|
---|
[723] | 191 | pars = list(self.fitter.getparameters())
|
---|
[515] | 192 | fxd = list(self.fitter.getfixedparameters())
|
---|
| 193 | i = 3*component
|
---|
| 194 | pars[i:i+3] = params
|
---|
| 195 | fxd[i:i+3] = fixed
|
---|
| 196 | params = pars
|
---|
[723] | 197 | fixed = fxd
|
---|
[113] | 198 | self.fitter.setparameters(params)
|
---|
| 199 | if fixed is not None:
|
---|
| 200 | self.fitter.setfixedparameters(fixed)
|
---|
[723] | 201 | print_log()
|
---|
[113] | 202 | return
|
---|
[515] | 203 |
|
---|
| 204 | def set_gauss_parameters(self, peak, centre, fhwm,
|
---|
| 205 | peakfixed=False, centerfixed=False,
|
---|
| 206 | fhwmfixed=False,
|
---|
| 207 | component=0):
|
---|
[113] | 208 | """
|
---|
[515] | 209 | Set the Parameters of a 'Gaussian' component, set with set_function.
|
---|
| 210 | Parameters:
|
---|
| 211 | peak, centre, fhwm: The gaussian parameters
|
---|
| 212 | peakfixed,
|
---|
| 213 | centerfixed,
|
---|
| 214 | fhwmfixed: Optional parameters to indicate if
|
---|
| 215 | the paramters should be held fixed during
|
---|
| 216 | the fitting process. The default is to keep
|
---|
| 217 | all parameters flexible.
|
---|
[526] | 218 | component: The number of the component (Default is the
|
---|
| 219 | component 0)
|
---|
[515] | 220 | """
|
---|
| 221 | if self.fitfunc != "gauss":
|
---|
[723] | 222 | msg = "Function only operates on Gaussian components."
|
---|
| 223 | if rcParams['verbose']:
|
---|
| 224 | print msg
|
---|
| 225 | return
|
---|
| 226 | else:
|
---|
| 227 | raise ValueError(msg)
|
---|
[515] | 228 | if 0 <= component < len(self.components):
|
---|
| 229 | self.set_parameters([peak, centre, fhwm],
|
---|
| 230 | [peakfixed, centerfixed, fhwmfixed],
|
---|
| 231 | component)
|
---|
| 232 | else:
|
---|
[723] | 233 | msg = "Please select a valid component."
|
---|
| 234 | if rcParams['verbose']:
|
---|
| 235 | print msg
|
---|
| 236 | return
|
---|
| 237 | else:
|
---|
| 238 | raise ValueError(msg)
|
---|
| 239 |
|
---|
[975] | 240 | def get_area(self, component=None):
|
---|
| 241 | """
|
---|
| 242 | Return the area under the fitted gaussian component.
|
---|
| 243 | Parameters:
|
---|
| 244 | component: the gaussian component selection,
|
---|
| 245 | default (None) is the sum of all components
|
---|
| 246 | Note:
|
---|
| 247 | This will only work for gaussian fits.
|
---|
| 248 | """
|
---|
| 249 | if not self.fitted: return
|
---|
| 250 | if self.fitfunc == "gauss":
|
---|
| 251 | pars = list(self.fitter.getparameters())
|
---|
| 252 | from math import log,pi,sqrt
|
---|
| 253 | fac = sqrt(pi/log(16.0))
|
---|
| 254 | areas = []
|
---|
| 255 | for i in range(len(self.components)):
|
---|
| 256 | j = i*3
|
---|
| 257 | cpars = pars[j:j+3]
|
---|
| 258 | areas.append(fac * cpars[0] * cpars[2])
|
---|
| 259 | else:
|
---|
| 260 | return None
|
---|
| 261 | if component is not None:
|
---|
| 262 | return areas[component]
|
---|
| 263 | else:
|
---|
| 264 | return sum(areas)
|
---|
| 265 |
|
---|
[515] | 266 | def get_parameters(self, component=None):
|
---|
| 267 | """
|
---|
[113] | 268 | Return the fit paramters.
|
---|
[526] | 269 | Parameters:
|
---|
| 270 | component: get the parameters for the specified component
|
---|
| 271 | only, default is all components
|
---|
[113] | 272 | """
|
---|
| 273 | if not self.fitted:
|
---|
[723] | 274 | msg = "Not yet fitted."
|
---|
| 275 | if rcParams['verbose']:
|
---|
| 276 | print msg
|
---|
| 277 | return
|
---|
| 278 | else:
|
---|
| 279 | raise RuntimeError(msg)
|
---|
[113] | 280 | pars = list(self.fitter.getparameters())
|
---|
| 281 | fixed = list(self.fitter.getfixedparameters())
|
---|
[723] | 282 | if component is not None:
|
---|
[515] | 283 | if self.fitfunc == "gauss":
|
---|
| 284 | i = 3*component
|
---|
| 285 | cpars = pars[i:i+3]
|
---|
| 286 | cfixed = fixed[i:i+3]
|
---|
| 287 | else:
|
---|
| 288 | cpars = pars
|
---|
[723] | 289 | cfixed = fixed
|
---|
[515] | 290 | else:
|
---|
| 291 | cpars = pars
|
---|
| 292 | cfixed = fixed
|
---|
[975] | 293 | fpars = self._format_pars(cpars, cfixed, self.get_area(component))
|
---|
[723] | 294 | if rcParams['verbose']:
|
---|
[515] | 295 | print fpars
|
---|
| 296 | return cpars, cfixed, fpars
|
---|
[723] | 297 |
|
---|
[975] | 298 | def _format_pars(self, pars, fixed, area):
|
---|
[113] | 299 | out = ''
|
---|
| 300 | if self.fitfunc == 'poly':
|
---|
| 301 | c = 0
|
---|
[515] | 302 | for i in range(len(pars)):
|
---|
| 303 | fix = ""
|
---|
| 304 | if fixed[i]: fix = "(fixed)"
|
---|
| 305 | out += ' p%d%s= %3.3f,' % (c,fix,pars[i])
|
---|
[113] | 306 | c+=1
|
---|
[515] | 307 | out = out[:-1] # remove trailing ','
|
---|
[113] | 308 | elif self.fitfunc == 'gauss':
|
---|
| 309 | i = 0
|
---|
| 310 | c = 0
|
---|
[515] | 311 | aunit = ''
|
---|
| 312 | ounit = ''
|
---|
[113] | 313 | if self.data:
|
---|
[515] | 314 | aunit = self.data.get_unit()
|
---|
| 315 | ounit = self.data.get_fluxunit()
|
---|
[113] | 316 | while i < len(pars):
|
---|
[975] | 317 | out += ' %2d: peak = %3.3f %s , centre = %3.3f %s, FWHM = %3.3f %s\n area = %3.3f %s %s\n' % (c,pars[i],ounit,pars[i+1],aunit,pars[i+2],aunit, area,ounit,aunit)
|
---|
[113] | 318 | c+=1
|
---|
| 319 | i+=3
|
---|
| 320 | return out
|
---|
[723] | 321 |
|
---|
[113] | 322 | def get_estimate(self):
|
---|
| 323 | """
|
---|
[515] | 324 | Return the parameter estimates (for non-linear functions).
|
---|
[113] | 325 | """
|
---|
| 326 | pars = self.fitter.getestimate()
|
---|
[943] | 327 | fixed = self.fitter.getfixedparameters()
|
---|
[723] | 328 | if rcParams['verbose']:
|
---|
[943] | 329 | print self._format_pars(pars,fixed)
|
---|
[113] | 330 | return pars
|
---|
| 331 |
|
---|
| 332 | def get_residual(self):
|
---|
| 333 | """
|
---|
| 334 | Return the residual of the fit.
|
---|
| 335 | """
|
---|
| 336 | if not self.fitted:
|
---|
[723] | 337 | msg = "Not yet fitted."
|
---|
| 338 | if rcParams['verbose']:
|
---|
| 339 | print msg
|
---|
| 340 | return
|
---|
| 341 | else:
|
---|
| 342 | raise RuntimeError(msg)
|
---|
[113] | 343 | return self.fitter.getresidual()
|
---|
| 344 |
|
---|
| 345 | def get_chi2(self):
|
---|
| 346 | """
|
---|
| 347 | Return chi^2.
|
---|
| 348 | """
|
---|
| 349 | if not self.fitted:
|
---|
[723] | 350 | msg = "Not yet fitted."
|
---|
| 351 | if rcParams['verbose']:
|
---|
| 352 | print msg
|
---|
| 353 | return
|
---|
| 354 | else:
|
---|
| 355 | raise RuntimeError(msg)
|
---|
[113] | 356 | ch2 = self.fitter.getchi2()
|
---|
[723] | 357 | if rcParams['verbose']:
|
---|
[113] | 358 | print 'Chi^2 = %3.3f' % (ch2)
|
---|
[723] | 359 | return ch2
|
---|
[113] | 360 |
|
---|
| 361 | def get_fit(self):
|
---|
| 362 | """
|
---|
| 363 | Return the fitted ordinate values.
|
---|
| 364 | """
|
---|
| 365 | if not self.fitted:
|
---|
[723] | 366 | msg = "Not yet fitted."
|
---|
| 367 | if rcParams['verbose']:
|
---|
| 368 | print msg
|
---|
| 369 | return
|
---|
| 370 | else:
|
---|
| 371 | raise RuntimeError(msg)
|
---|
[113] | 372 | return self.fitter.getfit()
|
---|
| 373 |
|
---|
| 374 | def commit(self):
|
---|
| 375 | """
|
---|
[526] | 376 | Return a new scan where the fits have been commited (subtracted)
|
---|
[113] | 377 | """
|
---|
| 378 | if not self.fitted:
|
---|
| 379 | print "Not yet fitted."
|
---|
[723] | 380 | msg = "Not yet fitted."
|
---|
| 381 | if rcParams['verbose']:
|
---|
| 382 | print msg
|
---|
| 383 | return
|
---|
| 384 | else:
|
---|
| 385 | raise RuntimeError(msg)
|
---|
[975] | 386 | from asap import scantable
|
---|
| 387 | if not isinstance(self.data, scantable):
|
---|
[723] | 388 | msg = "Not a scantable"
|
---|
| 389 | if rcParams['verbose']:
|
---|
| 390 | print msg
|
---|
| 391 | return
|
---|
| 392 | else:
|
---|
| 393 | raise TypeError(msg)
|
---|
[113] | 394 | scan = self.data.copy()
|
---|
[259] | 395 | scan._setspectrum(self.fitter.getresidual())
|
---|
[723] | 396 | print_log()
|
---|
[113] | 397 |
|
---|
[723] | 398 | def plot(self, residual=False, components=None, plotparms=False, filename=None):
|
---|
[113] | 399 | """
|
---|
| 400 | Plot the last fit.
|
---|
| 401 | Parameters:
|
---|
| 402 | residual: an optional parameter indicating if the residual
|
---|
| 403 | should be plotted (default 'False')
|
---|
[526] | 404 | components: a list of components to plot, e.g [0,1],
|
---|
| 405 | -1 plots the total fit. Default is to only
|
---|
| 406 | plot the total fit.
|
---|
| 407 | plotparms: Inidicates if the parameter values should be present
|
---|
| 408 | on the plot
|
---|
[113] | 409 | """
|
---|
| 410 | if not self.fitted:
|
---|
| 411 | return
|
---|
[723] | 412 | if not self._p or self._p.is_dead:
|
---|
| 413 | if rcParams['plotter.gui']:
|
---|
| 414 | from asap.asaplotgui import asaplotgui as asaplot
|
---|
| 415 | else:
|
---|
| 416 | from asap.asaplot import asaplot
|
---|
| 417 | self._p = asaplot()
|
---|
| 418 | self._p.hold()
|
---|
[113] | 419 | self._p.clear()
|
---|
[515] | 420 | self._p.set_panels()
|
---|
[652] | 421 | self._p.palette(0)
|
---|
[113] | 422 | tlab = 'Spectrum'
|
---|
[723] | 423 | xlab = 'Abcissa'
|
---|
[515] | 424 | m = ()
|
---|
[113] | 425 | if self.data:
|
---|
[515] | 426 | tlab = self.data._getsourcename(self._fittedrow)
|
---|
| 427 | xlab = self.data._getabcissalabel(self._fittedrow)
|
---|
| 428 | m = self.data._getmask(self._fittedrow)
|
---|
[626] | 429 | ylab = self.data._get_ordinate_label()
|
---|
[515] | 430 |
|
---|
[668] | 431 | colours = ["#777777","#bbbbbb","red","orange","purple","green","magenta", "cyan"]
|
---|
[652] | 432 | self._p.palette(0,colours)
|
---|
[515] | 433 | self._p.set_line(label='Spectrum')
|
---|
[113] | 434 | self._p.plot(self.x, self.y, m)
|
---|
| 435 | if residual:
|
---|
[652] | 436 | self._p.palette(1)
|
---|
[515] | 437 | self._p.set_line(label='Residual')
|
---|
[113] | 438 | self._p.plot(self.x, self.get_residual(), m)
|
---|
[652] | 439 | self._p.palette(2)
|
---|
[515] | 440 | if components is not None:
|
---|
| 441 | cs = components
|
---|
| 442 | if isinstance(components,int): cs = [components]
|
---|
[526] | 443 | if plotparms:
|
---|
| 444 | self._p.text(0.15,0.15,str(self.get_parameters()[2]),size=8)
|
---|
[515] | 445 | n = len(self.components)
|
---|
[652] | 446 | self._p.palette(3)
|
---|
[515] | 447 | for c in cs:
|
---|
| 448 | if 0 <= c < n:
|
---|
| 449 | lab = self.fitfuncs[c]+str(c)
|
---|
| 450 | self._p.set_line(label=lab)
|
---|
| 451 | self._p.plot(self.x, self.fitter.evaluate(c), m)
|
---|
| 452 | elif c == -1:
|
---|
[652] | 453 | self._p.palette(2)
|
---|
[515] | 454 | self._p.set_line(label="Total Fit")
|
---|
[723] | 455 | self._p.plot(self.x, self.get_fit(), m)
|
---|
[515] | 456 | else:
|
---|
[652] | 457 | self._p.palette(2)
|
---|
[515] | 458 | self._p.set_line(label='Fit')
|
---|
| 459 | self._p.plot(self.x, self.get_fit(), m)
|
---|
[723] | 460 | xlim=[min(self.x),max(self.x)]
|
---|
| 461 | self._p.axes.set_xlim(xlim)
|
---|
[113] | 462 | self._p.set_axes('xlabel',xlab)
|
---|
| 463 | self._p.set_axes('ylabel',ylab)
|
---|
| 464 | self._p.set_axes('title',tlab)
|
---|
| 465 | self._p.release()
|
---|
[723] | 466 | if (not rcParams['plotter.gui']):
|
---|
| 467 | self._p.save(filename)
|
---|
| 468 | print_log()
|
---|
[113] | 469 |
|
---|
[876] | 470 | def auto_fit(self, insitu=None):
|
---|
[113] | 471 | """
|
---|
[515] | 472 | Return a scan where the function is applied to all rows for
|
---|
| 473 | all Beams/IFs/Pols.
|
---|
[723] | 474 |
|
---|
[113] | 475 | """
|
---|
| 476 | from asap import scantable
|
---|
[515] | 477 | if not isinstance(self.data, scantable) :
|
---|
[723] | 478 | msg = "Data is not a scantable"
|
---|
| 479 | if rcParams['verbose']:
|
---|
| 480 | print msg
|
---|
| 481 | return
|
---|
| 482 | else:
|
---|
| 483 | raise TypeError(msg)
|
---|
[259] | 484 | if insitu is None: insitu = rcParams['insitu']
|
---|
| 485 | if not insitu:
|
---|
| 486 | scan = self.data.copy()
|
---|
| 487 | else:
|
---|
| 488 | scan = self.data
|
---|
[880] | 489 | rows = xrange(scan.nrow())
|
---|
[723] | 490 | from asap import asaplog
|
---|
[876] | 491 | asaplog.push("Fitting:")
|
---|
| 492 | for r in rows:
|
---|
[880] | 493 | out = " Scan[%d] Beam[%d] IF[%d] Pol[%d] Cycle[%d]" % (scan.getscan(r),scan.getbeam(r),scan.getif(r),scan.getpol(r), scan.getcycle(r))
|
---|
| 494 | asaplog.push(out, False)
|
---|
[876] | 495 | self.x = scan._getabcissa(r)
|
---|
| 496 | self.y = scan._getspectrum(r)
|
---|
| 497 | self.data = None
|
---|
| 498 | self.fit()
|
---|
| 499 | x = self.get_parameters()
|
---|
[880] | 500 | scan._setspectrum(self.fitter.getresidual(), r)
|
---|
[876] | 501 | print_log()
|
---|
| 502 | return scan
|
---|
[794] | 503 |
|
---|