API Reference
Global Methods
- class powerxrd.braggs(twotheta, lmda=1.54, is_scalar=False)
Calculate interplanar spacing “d_hkl” from Bragg’s law. - twotheta: Angle in degrees, can be a scalar or an array. - lmda: Wavelength in Angstroms, default is 1.54. - is_scalar: Flag to indicate if twotheta is a scalar (True) or an array (False).
- class powerxrd.scherrer(K, lmda, beta, theta)
Scherrer equation
- class powerxrd.funcgauss(x, y0, a, mean, sigma)
Gaussian equation
Data Manipulation
The Data class
The Chart class
- class powerxrd.Chart(x, y)
- __init__(x, y)
Chart structure. Constructs x-y XRD data to manipulate and analyze.
Parameters
- xnp.array(float)
array with x-data 2-theta values
- ynp.array(float)
array with y-data peak intensity values
- Kfloat
dimensionless shape factor for Scherrer equation (default 0.9)
- lambdaKafloat
X-ray wavelength of alpha radiation
- lambdaKifloat
X-ray wavelength of “i” radiation (beta, gamma, other)
- SchPeak(xrange=[12, 13], verbose=True, show=True)
Scherrer width calculation for peak within a specified range
Parameters
- xrange[](float)
range of x-axis (2-theta) where peak to be calculated is found
- show: bool
show plot of XRD chart
- XRD_int_ratio(xR1=[8.88, 9.6], xR2=[10.81, 11.52])
Calculate relative peak intensity (i.e. comparing one peak to another)
- allpeaks(tols=(0.2, 0.8), verbose=False, show=True)
Driver code for allpeaks recursion : Automated Scherrer width calculation of all peaks
Parameters
- tols(float, float)
tolerances for recursion tol[0]: Minimum peak height to be calculated as a percent of the chart’s global maximum (default=0.2 [20% of global maximum]) tol[1]: Average distance from peak (top) to trough (bottom) of all peak (default=0.8)
- show: bool
show plot of XRD chart
- allpeaks_recur(left=0, right=1, tols_=(200000.0, 0.8), schpeaks=[], verbose=False, show=True)
recursion component function for main allpeaks function below
- backsub(tol=1, inplace=False, show=False)
Perform a simple tolerance-based background subtraction.
This algorithm subtracts local minima based on a rolling comparison with a forward-offset window, zeroing out data points that fall below a tolerance threshold.
Parameters
- tolfloat, optional
Tolerance threshold. Background is subtracted if a forward intensity exceeds the current point by more than tol times. Default is 1.
- inplacebool, optional
If True, modifies self.y in-place. Default is False.
- showbool, optional
If True, plot the resulting background-subtracted data.
Returns
- tuple or Chart
(self.x, backsub_y) if inplace is False, otherwise returns self.
- emission_lines(xrange_Ka=[10, 20], show=True)
Emission lines arising from different types of radiation i.e. K_beta radiation wavelength of K_beta == 0.139 nm
Parameters
- show: bool
show plot of XRD chart
- xrange_Ka[](float)
range of x-axis (2-theta) for K_alpha radiation
- gaussfit(verbose=True)
Fit of a Gaussian curve (“bell curve”) to raw x-y data
- local_max(xrange=[12, 13])
Maximum finder in specified xrange
Parameters
- xrange_Ka[](float)
range of x to find globalmax
- mav(n=1, inplace=False, show=False, return_x=True)
Apply an n-point moving average to the XRD data.
Parameters
- nint, optional
Number of points to average over (window size). Must be >= 1. Default is 1.
- inplacebool, optional
If True, update self.x and self.y with the smoothed data. Default is False.
- showbool, optional
If True, display the smoothed data using matplotlib.
- return_xbool, optional
If False, only return the smoothed y-data. Useful for post-processing. Default is True.
Returns
- tuple or ndarray or Chart
Returns (newx, newy) if inplace is False and return_x is True, newy if return_x is False, or self if inplace is True.
Refinement Interfaces
The CubicModel class
- class powerxrd.model.CubicModel(wavelength=1.5406, atomic_positions=None, atomic_numbers=None)
Minimal model for cubic (Pm-3m, rocksalt/NaCl) structure. Parameters to refine: a, U, W, scale, (optional background slope/intercept)
- generate_hkl_list(a, wavelength, max_2theta=90)
Generate allowed HKLs for cubic up to max 2θ.
- pseudo_voigt(x, center, fwhm, eta=0.5)
Normalized pseudo-Voigt profile (eta=mixing).
The RefinementWorkflow class
- class powerxrd.RefinementWorkflow(model, x_exp, y_exp)
High-level Rietveld refinement workflow for PowerXRD.
This class wraps around a model instance, experimental data, and tracks the history of parameter sets at each refinement stage.
Users can perform staged refinements, plot fits, and export logs.
- Example usage:
from powerxrd.model import CubicModel from powerxrd.workflow import RefinementWorkflow x_exp, y_exp = … # Load your data model = CubicModel() rw = RefinementWorkflow(model, x_exp, y_exp) rw.refine([‘scale’]) rw.plot_fit() rw.refine([‘a’]) rw.save_log(‘refinement_log.json’)
- plot_fit()
Plot the current fit vs. experiment, print statistics.