Public Member Functions | |
def | __init__ |
def | set_data |
def | set_scan |
def | set_function |
def | fit |
def | store_fit |
def | set_parameters |
def | set_gauss_parameters |
def | set_lorentz_parameters |
def | set_sinusoid_parameters |
def | add_constraint |
def | get_area |
def | get_errors |
def | get_parameters |
def | get_estimate |
def | get_residual |
def | get_chi2 |
def | get_fit |
def | commit |
def | plot |
def | auto_fit |
Public Attributes | |
fitter | |
x | |
y | |
mask | |
fitfunc | |
fitfuncs | |
fitted | |
data | |
components | |
uselinear | |
blpars | |
Private Member Functions | |
def | _format_pars |
Private Attributes | |
_fittedrow | |
_p | |
_selection | |
_constraints |
The fitting class for ASAP.
Definition at line 7 of file asapfitter.py.
def asap.asapfitter.fitter.__init__ | ( | self | ) |
Create a fitter object. No state is set.
Definition at line 11 of file asapfitter.py.
def asap.asapfitter.fitter._format_pars | ( | self, | |
pars, | |||
fixed, | |||
errors, | |||
area | |||
) | [private] |
Definition at line 472 of file asapfitter.py.
References asap.asapfitter.fitter.data, and asap.asapfitter.fitter.fitfunc.
Referenced by asap.asapfitter.fitter.get_estimate(), and asap.asapfitter.fitter.get_parameters().
def asap.asapfitter.fitter.add_constraint | ( | self, | |
xpar, | |||
y | |||
) |
Add parameter constraints to the fit. This is done by setting up linear equations for the related parameters. For example a two component gaussian fit where the amplitudes are constraint by amp1 = 2*amp2 and paramaters for the two components in the order [amp1,peakv1,sigma1,amp2,peakv2,sigma2] needs a constraint add_constraint([1, 0, 0, -2, 0, 0], 0) as the linear equation is 1*amp1 + 0*peakv1 + 0*sigma1 -2*amp2 + 0*peakv2 + 0*sigma2 = 0 and similarly for a velocity difference of v2-v1=17 add_constraint([0.,-1.,0.,0.,1.,0.], 17.)
Definition at line 357 of file asapfitter.py.
def asap.asapfitter.fitter.auto_fit | ( | self, | |
insitu = None , |
|||
plot = False |
|||
) |
Return a scan where the function is applied to all rows for all Beams/IFs/Pols.
Definition at line 682 of file asapfitter.py.
References asap.asapfitter.fitter.data.
def asap.asapfitter.fitter.commit | ( | self | ) |
Return a new scan where the fits have been commited (subtracted)
Definition at line 557 of file asapfitter.py.
References asap.asapfitter.fitter.data, asap.asapfitter.fitter.fitted, and asap.asapfitter.fitter.plot().
def asap.asapfitter.fitter.fit | ( | self, | |
row = 0 , |
|||
estimate = False |
|||
) |
Execute the actual fitting process. All the state has to be set. Parameters: row: specify the row in the scantable estimate: auto-compute an initial parameter set (default False) This can be used to compute estimates even if fit was called before. Example: s = scantable('myscan.asap') s.set_cursor(thepol=1) # select second pol f = fitter() f.set_scan(s) f.set_function(poly=0) f.fit(row=0) # fit first row
Definition at line 137 of file asapfitter.py.
References asap.asapfitter.fitter._constraints, asap.asapfitter.fitter._fittedrow, asap.asapfitter.fitter.data, asap.asapfitter.fitter.fitfunc, asap.asapfitter.fitter.fitted, tests.test_imcontsub.list, asap.asapfitter.fitter.mask, asap.utils.mask_and(), asap.asapfitter.fitter.uselinear, asap.asapfitter.fitter.x, and asap.asapfitter.fitter.y.
def asap.asapfitter.fitter.get_area | ( | self, | |
component = None |
|||
) |
Return the area under the fitted gaussian/lorentzian component. Parameters: component: the gaussian/lorentzian component selection, default (None) is the sum of all components Note: This will only work for gaussian/lorentzian fits.
Definition at line 380 of file asapfitter.py.
References asap.asapfitter.fitter.components, asap.asapfitter.fitter.fitfunc, asap.asapfitter.fitter.fitted, tests.test_imcontsub.list, and irc_cs_task_regression.sum.
Referenced by asap.asapfitter.fitter.get_parameters().
def asap.asapfitter.fitter.get_chi2 | ( | self | ) |
Return chi^2.
Definition at line 535 of file asapfitter.py.
References asap.asapfitter.fitter.fitted.
def asap.asapfitter.fitter.get_errors | ( | self, | |
component = None |
|||
) |
Return the errors in the parameters. Parameters: component: get the errors for the specified component only, default is all components
Definition at line 410 of file asapfitter.py.
References asap.asapfitter.fitter.fitfunc, asap.asapfitter.fitter.fitted, and tests.test_imcontsub.list.
def asap.asapfitter.fitter.get_estimate | ( | self | ) |
Return the parameter estimates (for non-linear functions).
Definition at line 515 of file asapfitter.py.
References asap.asapfit.asapfit._format_pars(), and asap.asapfitter.fitter._format_pars().
def asap.asapfitter.fitter.get_fit | ( | self | ) |
Return the fitted ordinate values.
Definition at line 547 of file asapfitter.py.
References asap.asapfitter.fitter.fitted.
def asap.asapfitter.fitter.get_parameters | ( | self, | |
component = None , |
|||
errors = False |
|||
) |
Return the fit paramters. Parameters: component: get the parameters for the specified component only, default is all components
Definition at line 432 of file asapfitter.py.
References asap.asapfit.asapfit._format_pars(), asap.asapfitter.fitter._format_pars(), asap.asapfitter.fitter.components, asap.asapfitter.fitter.fitfunc, asap.asapfitter.fitter.fitted, asap.asapfitter.fitter.get_area(), and tests.test_imcontsub.list.
Referenced by asap.asapfitter.fitter.plot().
def asap.asapfitter.fitter.get_residual | ( | self | ) |
Return the residual of the fit.
Definition at line 525 of file asapfitter.py.
References asap.asapfitter.fitter.fitted.
Referenced by asap.asapfitter.fitter.plot().
def asap.asapfitter.fitter.plot | ( | self, | |
residual = False , |
|||
components = None , |
|||
plotparms = False , |
|||
filename = None |
|||
) |
Plot the last fit. Parameters: residual: an optional parameter indicating if the residual should be plotted (default 'False') components: a list of components to plot, e.g [0,1], -1 plots the total fit. Default is to only plot the total fit. plotparms: Inidicates if the parameter values should be present on the plot
Definition at line 574 of file asapfitter.py.
References asap.asapfitter.fitter._fittedrow, asap.asapfitter.fitter._p, listvis_regression.array, asap.asapfitter.fitter.components, asap.asapfitter.fitter.data, asap.asapfitter.fitter.fitfuncs, asap.asapfitter.fitter.fitted, asap.asapfitter.fitter.get_parameters(), asap.asapfitter.fitter.get_residual(), asap.asapfitter.fitter.mask, irc_cs_task_regression.max, asap.asapplotter.new_asaplot(), asap.asapfitter.fitter.x, and asap.asapfitter.fitter.y.
Referenced by asap.asapfitter.fitter.commit(), task_sdgrid.sdgrid_worker.finalize(), asap.asaplotbase.asaplotbase.hist(), asap.asapplotter.asapplotter.set_abcissa(), asap.asapplotter.asapplotter.set_colors(), asap.asapplotter.asapplotter.set_data(), asap.asapplotter.asapplotter.set_font(), asap.asapplotter.asapplotter.set_histogram(), asap.asapplotter.asapplotter.set_layout(), asap.asapplotter.asapplotter.set_legend(), asap.asapplotter.asapplotter.set_linestyles(), asap.asapplotter.asapplotter.set_margin(), asap.asapplotter.asapplotter.set_mask(), asap.asapplotter.asapplotter.set_mode(), asap.asapplotter.asapplotter.set_ordinate(), asap.asapplotter.asapplotter.set_range(), asap.asapplotter.asapplotter.set_selection(), and asap.asapplotter.asapplotter.set_title().
def asap.asapfitter.fitter.set_data | ( | self, | |
xdat, | |||
ydat, | |||
mask = None |
|||
) |
Set the absissa and ordinate for the fit. Also set the mask indicating valid points. This can be used for data vectors retrieved from a scantable. For scantable fitting use 'fitter.set_scan(scan, mask)'. Parameters: xdat: the abcissa values ydat: the ordinate values mask: an optional mask
Definition at line 30 of file asapfitter.py.
References asap.utils._n_bools(), asap.asapfitter.fitter.fitted, asap.asapfitter.fitter.mask, asap.asapfitter.fitter.x, and asap.asapfitter.fitter.y.
Referenced by asap.asapplotter.asapplotter.plot(), and asap.asapplotter.asapplotter.plotgrid().
def asap.asapfitter.fitter.set_function | ( | self, | |
kwargs | |||
) |
Set the function to be fit. Parameters: poly: use a polynomial of the order given with nonlinear least squares fit lpoly: use polynomial of the order given with linear least squares fit gauss: fit the number of gaussian specified lorentz: fit the number of lorentzian specified sinusoid: fit the number of sinusoid specified Example: fitter.set_function(poly=3) # will fit a 3rd order polynomial # via nonlinear method fitter.set_function(lpoly=3) # will fit a 3rd order polynomial # via linear method fitter.set_function(gauss=2) # will fit two gaussians fitter.set_function(lorentz=2) # will fit two lorentzians fitter.set_function(sinusoid=3) # will fit three sinusoids
Definition at line 72 of file asapfitter.py.
References asap.asapfitter.fitter._constraints, asap.asapfitter.fitter.components, asap.asapfitter.fitter.fitfunc, asap.asapfitter.fitter.fitfuncs, asap.asapfitter.fitter.fitted, and asap.asapfitter.fitter.uselinear.
def asap.asapfitter.fitter.set_gauss_parameters | ( | self, | |
peak, | |||
centre, | |||
fwhm, | |||
peakfixed = 0 , |
|||
centrefixed = 0 , |
|||
fwhmfixed = 0 , |
|||
component = 0 |
|||
) |
Set the Parameters of a 'Gaussian' component, set with set_function. Parameters: peak, centre, fwhm: The gaussian parameters peakfixed, centrefixed, fwhmfixed: Optional parameters to indicate if the paramters should be held fixed during the fitting process. The default is to keep all parameters flexible. component: The number of the component (Default is the component 0)
Definition at line 273 of file asapfitter.py.
References asap.asapfitter.fitter.components, asap.asapfitter.fitter.fitfunc, asap.asapfitter.fitter.set_lorentz_parameters(), and asap.asapfitter.fitter.set_parameters().
Referenced by asap.asapfitter.fitter.set_parameters().
def asap.asapfitter.fitter.set_lorentz_parameters | ( | self, | |
peak, | |||
centre, | |||
fwhm, | |||
peakfixed = 0 , |
|||
centrefixed = 0 , |
|||
fwhmfixed = 0 , |
|||
component = 0 |
|||
) |
Set the Parameters of a 'Lorentzian' component, set with set_function. Parameters: peak, centre, fwhm: The lorentzian parameters peakfixed, centrefixed, fwhmfixed: Optional parameters to indicate if the paramters should be held fixed during the fitting process. The default is to keep all parameters flexible. component: The number of the component (Default is the component 0)
Definition at line 302 of file asapfitter.py.
References asap.asapfitter.fitter.components, asap.asapfitter.fitter.fitfunc, asap.asapfitter.fitter.set_parameters(), and asap.asapfitter.fitter.set_sinusoid_parameters().
Referenced by asap.asapfitter.fitter.set_gauss_parameters().
def asap.asapfitter.fitter.set_parameters | ( | self, | |
args, | |||
kwargs | |||
) |
Set the parameters to be fitted. Parameters: params: a vector of parameters fixed: a vector of which parameters are to be held fixed (default is none) component: in case of multiple gaussians/lorentzians/sinusoidals, the index of the target component
Definition at line 228 of file asapfitter.py.
References asap.utils._n_bools(), asap.asapfitter.fitter.components, asap.asapfitter.fitter.fitfunc, asap.asapfitter.fitter.fitted, tests.test_imcontsub.list, asap.asapfitter.fitter.set_gauss_parameters(), and irc_cs_task_regression.sum.
Referenced by asap.asapfitter.fitter.set_gauss_parameters(), asap.asapfitter.fitter.set_lorentz_parameters(), and asap.asapfitter.fitter.set_sinusoid_parameters().
def asap.asapfitter.fitter.set_scan | ( | self, | |
thescan = None , |
|||
mask = None |
|||
) |
Set the 'data' (a scantable) of the fitter. Parameters: thescan: a scantable mask: a msk retrieved from the scantable
Definition at line 52 of file asapfitter.py.
References asap.utils._n_bools(), asap.asapfitter.fitter.data, asap.asapfitter.fitter.fitted, and asap.asapfitter.fitter.mask.
def asap.asapfitter.fitter.set_sinusoid_parameters | ( | self, | |
ampl, | |||
period, | |||
x0, | |||
amplfixed = 0 , |
|||
periodfixed = 0 , |
|||
x0fixed = 0 , |
|||
component = 0 |
|||
) |
Set the Parameters of a 'Sinusoidal' component, set with set_function. Parameters: ampl, period, x0: The sinusoidal parameters amplfixed, periodfixed, x0fixed: Optional parameters to indicate if the paramters should be held fixed during the fitting process. The default is to keep all parameters flexible. component: The number of the component (Default is the component 0)
Definition at line 331 of file asapfitter.py.
References asap.asapfitter.fitter.components, asap.asapfitter.fitter.fitfunc, and asap.asapfitter.fitter.set_parameters().
Referenced by asap.asapfitter.fitter.set_lorentz_parameters().
def asap.asapfitter.fitter.store_fit | ( | self, | |
filename = None |
|||
) |
Save the fit parameters. Parameters: filename: if specified save as an ASCII file, if None (default) store it in the scnatable
Definition at line 201 of file asapfitter.py.
References asap.asapfitter.fitter._fittedrow, asap.asapfitter.fitter.components, asap.asapfitter.fitter.data, asap.asapfitter.fitter.fitfuncs, asap.asapfitter.fitter.fitted, and tests.test_imcontsub.list.
Definition at line 15 of file asapfitter.py.
Referenced by task_sdfit.sdfit_worker.__initial_guess().
asap.asapfitter.fitter._constraints [private] |
Definition at line 28 of file asapfitter.py.
Referenced by asap.asapfitter.fitter.fit(), and asap.asapfitter.fitter.set_function().
asap.asapfitter.fitter._fittedrow [private] |
Definition at line 24 of file asapfitter.py.
Referenced by asap.asapfitter.fitter.fit(), asap.asapfitter.fitter.plot(), and asap.asapfitter.fitter.store_fit().
asap.asapfitter.fitter._p [private] |
Definition at line 25 of file asapfitter.py.
Referenced by asap.asapfitter.fitter.plot().
asap.asapfitter.fitter._selection [private] |
Definition at line 26 of file asapfitter.py.
Referenced by asap.asapplotter.asapplotter._plot(), and asap.asapplotter.asapplotter.set_selection().
Definition at line 700 of file asapfitter.py.
Definition at line 23 of file asapfitter.py.
Referenced by asap.asapfitter.fitter.get_area(), asap.asapfitter.fitter.get_parameters(), asap.asapfitter.fitter.plot(), asap.asapfitter.fitter.set_function(), asap.asapfitter.fitter.set_gauss_parameters(), asap.asapfitter.fitter.set_lorentz_parameters(), asap.asapfitter.fitter.set_parameters(), asap.asapfitter.fitter.set_sinusoid_parameters(), and asap.asapfitter.fitter.store_fit().
Definition at line 22 of file asapfitter.py.
Referenced by asap.asapfitter.fitter._format_pars(), tests.test_sdgrid.sdgrid_flagging._testresult(), asap.asapfitter.fitter.auto_fit(), asap.asapfitter.fitter.commit(), asap.asapfitter.fitter.fit(), tests.test_sdgrid.sdgrid_unittest_base.getdata(), asap.asapfitter.fitter.plot(), asap.asapfitter.fitter.set_scan(), asap.asapfitter.fitter.store_fit(), tests.test_sdgrid.sdgrid_single_integ.test100(), tests.test_sdgrid.sdgrid_single_integ.test101(), tests.test_sdgrid.sdgrid_single_integ.test102(), tests.test_sdgrid.sdgrid_single_integ.test103(), tests.test_sdgrid.sdgrid_clipping.test200(), tests.test_sdgrid.sdgrid_weighting.test400(), tests.test_sdgrid.sdgrid_weighting.test401(), tests.test_sdgrid.sdgrid_weighting.test402(), tests.test_sdgrid.sdgrid_weighting.test403(), tests.test_sdgrid.sdgrid_map.test500(), tests.test_sdgrid.sdgrid_map.test501(), tests.test_sdgrid.sdgrid_map.test502(), and tests.test_sdgrid.sdgrid_map.test503().
Definition at line 19 of file asapfitter.py.
Referenced by task_sdfit.sdfit_worker.__initial_guess(), task_sdfit.sdfit_worker.__store_fit(), asap.asapfitter.fitter._format_pars(), asap.asapfitter.fitter.fit(), asap.asapfitter.fitter.get_area(), asap.asapfitter.fitter.get_errors(), asap.asapfitter.fitter.get_parameters(), asap.asapfitter.fitter.set_function(), asap.asapfitter.fitter.set_gauss_parameters(), asap.asapfitter.fitter.set_lorentz_parameters(), asap.asapfitter.fitter.set_parameters(), and asap.asapfitter.fitter.set_sinusoid_parameters().
Definition at line 20 of file asapfitter.py.
Referenced by asap.asapfitter.fitter.plot(), asap.asapfitter.fitter.set_function(), and asap.asapfitter.fitter.store_fit().
Definition at line 21 of file asapfitter.py.
Referenced by asap.asapfitter.fitter.commit(), asap.asapfitter.fitter.fit(), asap.asapfitter.fitter.get_area(), asap.asapfitter.fitter.get_chi2(), asap.asapfitter.fitter.get_errors(), asap.asapfitter.fitter.get_fit(), asap.asapfitter.fitter.get_parameters(), asap.asapfitter.fitter.get_residual(), asap.asapfitter.fitter.plot(), asap.asapfitter.fitter.set_data(), asap.asapfitter.fitter.set_function(), asap.asapfitter.fitter.set_parameters(), asap.asapfitter.fitter.set_scan(), and asap.asapfitter.fitter.store_fit().
Definition at line 18 of file asapfitter.py.
Referenced by asap.interactivemask.interactivemask._plot_mask(), asap.interactivemask.interactivemask._update_mask(), asap.asapfitter.fitter.fit(), asap.interactivemask.interactivemask.get_mask(), asap.asapfitter.fitter.plot(), asap.interactivemask.interactivemask.set_basemask(), asap.asapfitter.fitter.set_data(), asap.asapfitter.fitter.set_scan(), and tests.test_clean.clean_multims_test.test_multims5().
Definition at line 27 of file asapfitter.py.
Referenced by asap.asapfitter.fitter.fit(), and asap.asapfitter.fitter.set_function().
Definition at line 16 of file asapfitter.py.
Referenced by asap.asapfitter.fitter.fit(), asap.asapfitter.fitter.plot(), and asap.asapfitter.fitter.set_data().
Definition at line 17 of file asapfitter.py.
Referenced by asap.asapfitter.fitter.fit(), asap.asapfitter.fitter.plot(), and asap.asapfitter.fitter.set_data().