PHS1011

This documents the monashspa.PHS1011 library that you will import into code used in the PHS1011 unit.

monashspa.PHS1011.get_fit_parameters(fit_result)[source]

Returns the parameters from a fit result as a dictionary.

This function takes a lmfit.model.ModelResult object from the lmfit Python library and extracts the parameters of the fit along with their uncertainties. These are returned to you in a Python dictionary format. The format of the dictionary depends on the model used to perform the fit. For example, a linear fit would result in the following dictionary:

parameters = {
    'slope': <value>,
    'u_slope': <value>,
    'intercept': <value>,
    'u_intercept': <value>,
}

The parameter names always match those of the lmfit model, and the uncertainties are always the identical parameter name prefixed with u_.

Parameters:fit_result – A lmfit.model.ModelResult object from the lmfit Python library.
Returns:A dictionary containing the fit parameters and their associated uncertainties.
monashspa.PHS1011.linear_fit(x, y, u_y=None, slope_guess=None, intercept_guess=None)[source]

General purpose linear fit function.

This function takes your x and y data (as numpy arrays) and returns a lmfit.model.ModelResult object from the lmfit Python library. It attempts to fit your data to a model define by:

\(y=mx+c\)

where \(m = slope\) and \(c = intercept\). If guesses for the slope and intercept are not explicitly provided when calling this function, they will be inferred from the provided data arrays.

Parameters:
  • x – A 1D numpy array of x data points
  • y – A 1D numpy array of y data points
Keyword Arguments:
 
  • u_y – An optional argument for providing a 1D numpy array of uncertainty values for the y data points
  • slope_guess – An optional argument for providing an initial guess for the value of the slope parameter
  • intercept_guess – An optional argument for providing an initial guess for the value of the intercept parameter
Returns:

A lmfit.model.ModelResult object from the lmfit Python library

monashspa.PHS1011.savefig(fname, dpi=600, bbox_inches='tight', **kwargs)[source]

A wrapper for matplotlib.pyplot.savefig() with sensible defaults.

By default, if a matplotlib legend is located outside of the plot axes, then matplotlib.pyplot.savefig() may cut off the legend when saving the figure. This function fixes this issue by setting bbox_inches='tight' and setting bbox_extra_artists to be a list of the current figure legends, unless the user chooses to define them otherwise. This function also sets the default for dpi to 600, which is large enough for most purposes.

This function accepts any keyword argument from matplotlib.pyplot.savefig() and returns the result of the call to that function. See matplotlib.pyplot.savefig() for usage.