hexrd.wppf.WPPF module

class hexrd.wppf.WPPF.AbstractWPPF[source]

Bases: ABC

Methods used by both LeBail and Rietveld

property DOC
property background
property bkgmethod
calcRwp(params)[source]
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 05/19/2020 SS 1.0 original >> @DETAILS: this routine computes the weighted error between

calculated and experimental spectra. goodness of fit is also calculated. the weights are the inverse squareroot of the experimental intensities

property calc_Iobs_fcn
calctth()[source]
property cheb_coef
property cheb_init_coef
property cheb_polynomial
chebyshevfit()[source]

03/08/2021 SS spectrum_expt is a list now. accounting for that change

property computespectrum_fcn
dump_hdf5(file)[source]
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 01/19/2021 SS 1.0 original >> @DETAILS: write out the hdf5 file with all the spectrum, parameters

and phases pecified by filename or h5py.File object

abstract generate_default_parameters() Parameters[source]
property init_bkg
initialize_bkg()[source]

the cubic spline seems to be the ideal route in terms of determining the background intensity. this involves selecting a small (~5) number of points from the spectrum, usually called the anchor points. a cubic spline interpolation is performed on this subset to estimate the overall background. scipy provides some useful routines for this

the other option implemented is the chebyshev polynomials. this basically automates the background determination and removes the user from the loop which is required for the spline type background.

property num_vary: int
property params
params_vary_off()[source]

no params are varied

params_vary_on()[source]

all params are varied

property peakshape
reset_background_params()[source]
property spectrum_expt
property spectrum_sim
splinefit(points)[source]

03/08/2021 SS adding tth as input. this is the list of points for which background is estimated

property total_area
property tth_list
update_parameters()[source]
property weights
class hexrd.wppf.WPPF.LeBail(expt_spectrum=None, params=None, phases=None, wavelength={'kalpha1': [valWUnit('lp', 'LENGTH', 0.15406, 'nm'), 1.0], 'kalpha2': [valWUnit('lp', 'LENGTH', 0.154443, 'nm'), 1.0]}, bkgmethod={'spline': None}, intensity_init=None, peakshape='pvfcj', amorphous_model=None, reset_background_params=True)[source]

Bases: AbstractWPPF


>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 05/19/2020 SS 1.0 original

09/11/2020 SS 1.1 expt_spectrum, params and phases now have multiple input option for easy integration with hexrdgui 09/14/2020 SS 1.2 bkgmethod is now a dictionary. if method is ‘chebyshev’, the the value specifies the degree of the polynomial to use for background estimation 01/22/2021 SS 1.3 added intensity_init option to initialize intensity with structure factors if the user so chooses 01/22/2021 SS 1.4 added option to specify background via a filename or numpy array 03/12/2021 SS 1.5 added _generate_default_parameter function

>> @DETAILS: this is the main LeBail class and contains all the refinable

parameters for the analysis. Since the LeBail method has no structural information during refinement, the refinable parameters for this model will be:

  1. a, b, c, alpha, beta, gamma : unit cell parameters

  2. U, V, W : cagliotti paramaters

  3. 2theta_0 : Instrumental zero shift error

  4. eta1, eta2, eta3 : weight factor for gaussian vs lorentzian

@NOTE: All angles are always going to be in degrees

>> @PARAMETERS:
expt_spectrum: name of file or numpy array or Spectrum

class of experimental intensity

params: yaml file or dictionary or Parameter class phases: yaml file or dictionary or Phases_Lebail class wavelength: dictionary of wavelengths bkgmethod: method to estimate background. either spline or chebyshev

fit or filename or numpy array (last two options added 01/22/2021 SS)

Intensity_init: if set to none, then some power of 10 is used.

User has option to pass in dictionary of structure factors. must ensure that the size of structure factor matches the possible reflections (added 01/22/2021 SS)


CalcIobs()[source]
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 06/08/2020 SS 1.0 original >> @DETAILS: this is one of the main functions to partition the expt

intensities to overlapping peaks in the calculated pattern

Refine()[source]
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 05/19/2020 SS 1.0 original >> @DETAILS: this routine performs the least squares refinement for all

variables which are allowed to be varied.

RefineCycle(print_to_screen=True)[source]
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 06/08/2020 SS 1.0 original

01/28/2021 SS 1.1 added optional print_to_screen argument

>> @DETAILS: this is one refinement cycle for the least squares,

typically few 10s to 100s of cycles may be required for convergence

computespectrum()[source]
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 06/08/2020 SS 1.0 original >> @DETAILS: compute the simulated spectrum

generate_default_parameters() Parameters[source]
initialize_Icalc()[source]

@DATE 01/22/2021 SS modified the function so Icalc can be initialized with a dictionary of structure factors

property phases
class hexrd.wppf.WPPF.Rietveld(expt_spectrum=None, params=None, phases=None, wavelength={'kalpha1': [valWUnit('lp', 'LENGTH', 0.15406, 'nm'), 1.0], 'kalpha2': [valWUnit('lp', 'LENGTH', 0.154443, 'nm'), 0.52]}, bkgmethod={'spline': None}, peakshape='pvfcj', shape_factor=1.0, particle_size=1.0, phi=0.0, amorphous_model=None, reset_background_params=True, texture_model=None, eta_min=-180, eta_max=180, eta_step=5.0)[source]

Bases: AbstractWPPF


>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 01/08/2020 SS 1.0 original
07/13/2020 SS 2.0 complete rewrite to include new

parameter/material/pattern class

02/01/2021 SS 2.1 peak shapes from Thompson,Cox and Hastings

formula using X anf Y parameters for the lorentzian peak widths

>> @DETAILS: this is the main rietveld class and contains all the refinable

parameters for the analysis. the member classes are as follows (in order of initialization):

  1. Spectrum contains the experimental spectrum

  2. Background contains the background extracted from

    spectrum

  3. Refine contains all the machinery for refinement


PolarizationFactor()[source]
Refine()[source]
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 05/19/2020 SS 1.0 original >> @DETAILS: this routine performs the least squares refinement for all

variables that are allowed to be varied.

RefineTexture()[source]
property any_texture_params_varied
calcsf()[source]
compute_intensities()[source]

this function computes the intensities of the xray diffraction excluding any texture. this function will replace part of the code in the computespectrum function

compute_texture_data(pv_binned: ndarray, bvec: ndarray | None = None, evec: ndarray | None = None, azimuthal_interval: float = 5)[source]

Compute texture data to use in texture refinement

Using the current parameters on the Rietveld object, fit the peaks to LeBail models in order to determine their intensities, and then compute a dictionary of texture contributions. These texture contributions are automatically set on the pfdata of the texture models.

A simulated spectrum is returned.

compute_tth_after_shifts(p, k)[source]

another helper function to be used by both Rietveld.computspectrum and Rietveld.computespectrum_2d

Parameters

p: str

name of the phase

k: str

wavelength key

computespectrum()[source]

>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab >> @EMAIL: saransh1@llnl.gov >> @DATE: 06/08/2020 SS 1.0 original >> @DETAILS: compute the simulated spectrum

computespectrum_2D()[source]

this function computes the 2D pattern for the Rietevld model. if there is no texture, the pattern is uniform in the azimuthal direction. if there is a texture model present, then the azimuthal intensities are modulated based on the texture model.

Parameters

eta_min: float

minimum azimuthal angle

eta_max: float

maximum azimuthal angle

eta_step: float

step size in azimuth. this determines the dimensions in the azimuthal direction

Returns

simulated_2d: np.ndarray

simulated 2D diffraction pattern

computespectrum_phase(p, k, Ic, texture_factor=None)[source]

this is a helper function so which is use by both the Rietveld.computspectrum and Rietveld.computespectrum_2d function to avoid code repetition.

Parameters

p: str

name of the phase

k: str

wavelength key

texture_factor: numpy.ndarray

azimuthally averaged texture factor

property eta_max
property eta_min
property eta_step
generate_default_parameters() Parameters[source]
property phases
property texture_index
property texture_model
property texture_models_have_pfdata
texture_parameters_vary(vary=False)[source]

helper function to turn texture related parameters on or off

hexrd.wppf.WPPF.extract_intensities(polar_view, tth_array, params=None, phases=None, wavelength={'kalpha1': valWUnit('lp', 'LENGTH', 0.15406, 'nm'), 'kalpha2': valWUnit('lp', 'LENGTH', 0.154443, 'nm')}, bkgmethod={'chebyshev': 10}, intensity_init=None, termination_condition={'max_iter': 100, 'rwp_perct_change': 0.05}, peakshape='pvtch')[source]
>> @AUTHOR: Saransh Singh, Lanwrence Livermore National Lab,

saransh1@llnl.gov

>> @DATE: 01/28/2021 SS 1.0 original

03/03/2021 SS 1.1 removed detector_mask since polar_view is now a masked array

>> @DETAILS: this function is used for extracting the experimental pole

figure intensities from the polar 2theta-eta map. The workflow is to simply run the LeBail class, in parallel, over the different azimuthal profiles and return the Icalc values for the different wavelengths in the calculation. For now, the multiprocessing is done using the multiprocessing module which comes natively with python. Extension to MPI will be done later if necessary.

>> @PARAMS polar_view: mxn array with the polar view. the parallelization

is done !!! this is now a masked numpy array !!! over “m” i.e. the eta dimension

tth_array: nx1 array with two theta values at each sampling

point

params: parameter values for the LeBail class. Could be in

the form of yaml file, dictionary or Parameter class

phases: materials to use in intensity extraction. could be

a list of material objects, or file or dictionary

wavelength: dictionary of wavelengths to be used in the

computation

bkgmethod: “spline” or “chebyshev” or “snip”

default is chebyshev

intensity_init: initial intensities for each reflection.

If none, then it is specified to some power of 10 depending on maximum intensity in spectrum (only used for powder simulator)

hexrd.wppf.WPPF.join_regions(vector_list, global_index, global_shape)[source]

@author Saransh Singh Lawrence Livermore National Lab @date 03/08/2021 SS 1.0 original @details utility function for joining different pieces of masked array into one masked array

hexrd.wppf.WPPF.separate_regions(masked_spec_array)[source]

utility function for separating array into separate islands as dictated by mask. this function was taken from stackoverflow https://stackoverflow.com/questions/43385877/ efficient-numpy-subarrays-extraction-from-a-mask

hexrd.wppf.WPPF.single_azimuthal_extraction(expt_spectrum, params=None, phases=None, wavelength={'kalpha1': valWUnit('lp', 'LENGTH', 0.15406, 'nm'), 'kalpha2': valWUnit('lp', 'LENGTH', 0.154443, 'nm')}, bkgmethod={'chebyshev': 10}, intensity_init=None, termination_condition=None, peakshape='pvtch')[source]