2.2.2. scipy

The scipy module contains a few convenience functions mostly designed to make fitting easier.

class scisalt.scipy.GaussResults(x, y, sigma_y=None, p0=None, variance=False, background=False)[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
  • 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.

chisq_red

The reduced chi square.

pcov

The covariance for the fit parameters.

popt

The fit parameters for the fit function.

class scisalt.scipy.LinLsqFit(y_unweighted, X_unweighted, y_error=None)[source]

Gets the linear least squares for \beta of a problem given X_{ij} \beta_{i} = y_j.

As input, it takes y_unweighted as the measured y, X_unweighted for X, and y_error as the measurement error on y.

X

The X weighted properly by the errors from y_error

X_unweighted

The X. Setting this attribute forces a recalculation.

beta

The result \beta of the linear least squares

chisq_red

The reduced chi-square of the linear least squares

covar

The covariance matrix for the result \beta

y

The X weighted properly by the errors from y_error

y_error

The measured error of y of the problem X_{ij} \beta_{i} = y_j. Setting this attribute forces a recalculation.

y_fit

Using the result of the linear least squares, the result of X_{ij}\beta_i

y_unweighted

The y of the problem X_{ij} \beta_{i} = y_j. 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 scaled scipy.optimize.curve_fit(). *args and **kwargs are passed through to scipy.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