xrdfit package

xrdfit.plotting module

This module contain functions for plotting spectral data and the fits to it. None of these functions should be called directly by users - these functions are called from plot methods in spectrum_fitting.

xrdfit.plotting.plot_parameter(data: numpy.ndarray, fit_parameter: str, show_points: bool, show_error: bool, scale_by_error: bool = False, log_scale=False)[source]

Plot a parameter of a fit against time.

Parameters:
  • data – The data to plot, x data in the first column, y data in the second column and the y error in the third column.
  • fit_parameter – The name of the parameter being plotted, used to generate the y-axis label
  • show_points – Whether to show data points on the plot.
  • show_error – Whether to show error bars on the plot.
  • scale_by_error – If True auto scale the y-axis to the range of the error bars. If False, auto scale the y-axis to the range of the data.
  • log_scale – Whether to plot the y-axis on a log or linear scale.
xrdfit.plotting.plot_peak_fit(peak_fit: PeakFit, time_step: str = None, file_name: str = None, title: str = None, label_angle: float = None, log_scale=False)[source]

Plot the result of a peak fit as well as the raw data.

Parameters:
  • peak_fit – The result of a peak fit
  • time_step – If provided, used to generate the title of the plot.
  • file_name – If provided used as a on disk location to save the plot.
  • title – If provided, can be used to override the auto generated plot title.
  • label_angle – The angle to rotate maxima labels.
  • log_scale – Whether to plot the y axis on a log or linear scale.
xrdfit.plotting.plot_peak_params(peak_params: List[PeakParams], x_range: Tuple[float, float], label_angle: float)[source]

A visualisation to show the PeakParams. Peak bounds are indicated by a shaded grey area. Maxima bounds are shown by a dashed green line for the min bound and a dashed red line for the max bound. This method is called with an active plot environment and plots the peak params on top.

Parameters:
  • peak_params – The peak params to plot.
  • x_range – If supplied, restricts the x-axis of the plot to this range.
  • label_angle – If supplied, the angle to rotate the maxima labels.
xrdfit.plotting.plot_polar_heat_map(num_cakes: int, rad: Union[numpy.ndarray, List[int]], z_data: numpy.ndarray, first_cake_angle: int, cake_order: str)[source]

Plot a polar heat map using matplotlib.

Parameters:
  • num_cakes – The number of segments the polar map is divided into.
  • rad – The radial bin edges.
  • z_data – A num_cakes by rad shaped array of data to plot.
  • first_cake_angle – The angle clockwise from vertical at which to label the first cake.
  • cake_order – The order of cakes in the input data. Valid options are clockwise or anticlockwise
xrdfit.plotting.plot_spectrum(data: numpy.ndarray, cakes_to_plot: List[int], merge_cakes: bool, show_points: bool, x_range: Union[None, Tuple[float, float]] = None, log_scale=False)[source]

Plot a raw spectrum using matplotlib.

Parameters:
  • data – The data to plot, x_data in column 0, y data in columns 1-N where N is the number of cakes in the dataset.
  • cakes_to_plot – Which cakes (columns of y data) to plot.
  • merge_cakes – If True plot the sum of the selected cakes as a single line. If False plot all selected cakes individually.
  • show_points – Whether to show data points on the plot.
  • x_range – If supplied, restricts the x-axis of the plot to this range.
  • log_scale – If True, plot y axis on log scale. If False use linear scale.

xrdfit.pv_fit module

This module contain functions implementing the Pseudo-Voigt fit in lmfit. None of these functions should be called directly by users - these functions are called from methods in spectrum_fitting.

xrdfit.pv_fit.do_pv_fit(peak_data: numpy.ndarray, peak_param: PeakParams) → lmfit.model.ModelResult[source]

Pseudo-Voigt fit to the lattice plane peak intensity.

Parameters:
  • peak_data – The data to be fitted, two theta values (x-data) in column 0 and intensity (y-data) in column 1.
  • peak_param – A PeakParams object describing the peak to be fitted.
xrdfit.pv_fit.guess_params(model: lmfit.model.Model, old_fit_params: lmfit.parameter.Parameters, x_data: numpy.ndarray, y_data: numpy.ndarray, maxima_params: List[MaximumParams]) → lmfit.parameter.Parameters[source]

Given a dataset and some information about where the maxima are, guess some good initial values for the Pseudo-Voigt fit.

Parameters:
  • model – The lmfit Model to guess the params for.
  • old_fit_params – Any params that are to be passed on from a previous fit
  • x_data – The x data to be fitted.
  • y_data – The y data to be fitted.
  • maxima_params – The MaximaParams specified by the user.
xrdfit.pv_fit.guess_sigma(x_data: numpy.ndarray, maximum_range: Tuple[float, float]) → Tuple[float, float, float][source]

Guess an initial value of sigma for the Pseudo-Voigt fit.

Parameters:
  • x_data – The x_data to be fitted.
  • maximum_range – Two floats indicating the range of values that the maximum falls within.
Returns:

A maximum possible value for sigma, a minimum possible value and the initial guess of sigma.

xrdfit.spectrum_fitting module