3.2. scipy¶
The scipy module contains a few convenience functions mostly designed to make fitting easier.
-
class
scisalt.scipy.GaussResults(x, y, sigma_y, func, popt, pcov=None, chisq_red=None)[source]¶ A class containing the full results of
gaussfit().-
chisq_red= None¶ The reduced chi square value
-
func= None¶ The function used to fit
-
pcov= None¶ The covariance matrix
-
popt= None¶ The fit values (amp, mu, var) where var is either rms or rms**2
-
sigma_y= None¶ The error on
data points
-
x= None¶ The
data points
-
y= None¶ The
data points
-
-
class
scisalt.scipy.LinLsqFit(y_unweighted, X_unweighted, y_error=None)[source]¶ Gets the linear least squares for
of a problem given
.As input, it takes y_unweighted as the measured
, X_unweighted for
, and y_error as the measurement error on
.-
X¶ The
weighted properly by the errors from y_error
-
X_unweighted¶ The
. Setting this attribute forces a recalculation.
-
beta¶ The result
of the linear least squares
-
chisq_red¶ The reduced chi-square of the linear least squares
-
covar¶ The covariance matrix for the result

-
y¶ The
weighted properly by the errors from y_error
-
y_error¶ The measured error of
of the problem
. Setting this attribute forces a recalculation.
-
y_fit¶ Using the result of the linear least squares, the result of

-
y_unweighted¶ The
of the problem
. Setting this attribute forces a recalculation.
-
-
scisalt.scipy.chisquare(observe, expect, error, ddof, verbose=True)[source]¶ Finds the reduced chi square difference of observe and expect with a given error and ddof degrees of freedom.
verbose flag determines if the reduced chi square is printed to the terminal.
-
scisalt.scipy.curve_fit_unscaled(*args, **kwargs)[source]¶ Use the reduced chi square to unscale
scipy‘s scaledscipy.optimize.curve_fit(). *args and **kwargs are passed through toscipy.optimize.curve_fit(). The tuple popt, pcov, chisq_red is returned, where popt is the optimal values for the parameters, pcov is the estimated covariance of popt, and chisq_red is the reduced chi square. See http://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.optimize.curve_fit.html.
-
scisalt.scipy.fft(values, freq=None, timestamps=None, fill_missing=False)[source]¶ Adds options to
scipy.fftpack.rfft():- freq is the frequency the samples were taken at
- timestamps is the time the samples were taken, to help with filling in missing data if fill_missing is true
-
scisalt.scipy.gaussfit(x, y, sigma_y=None, plot=True, p0=None, verbose=False, variance_bool=False, background_bool=False, bg=0)[source]¶ Fits a gaussian to a curve specified by pairs x and y, with error on y of sigma_y.
- plot: Determines whether the plot is shown
- p0: Initial guess given by amplitude amp, mean mu, and standard deviation rms, in the form of:
[amp, mu, rms**2]if variance_bool is true[amp, mu, rms]if variance_bool is false
- verbose: If true, prints details to terminal
- background_bool: If true, uses a background term in the fit, with initial guess bg
Returns full statistical results in the form of an instance of class
GaussResults.