diffpy.labpdfproc package

Tools for processing x-ray powder diffraction data from laboratory sources.

Subpackages

Submodules

diffpy.labpdfproc.functions module

class diffpy.labpdfproc.functions.Gridded_circle(radius=1, n_points_on_diameter=300, mu=None)[source]

Bases: object

set_distances_at_angle(angle)[source]

Given an angle, set the distances from the grid points to the entry and exit coordinates.

Parameters:

angle (float) – The angle of the output beam in degrees.

set_muls_at_angle(angle)[source]

Compute muls = exp(-mu*distance) for a given angle.

Parameters:

angle (float) – The angle of the output beam in degrees.

diffpy.labpdfproc.functions.apply_corr(input_pattern, absorption_correction)[source]

Apply absorption correction to the given diffraction object with the correction diffraction object.

Parameters:
  • input_pattern (DiffractionObject) – The input diffraction object to which the cve will be applied.

  • absorption_correction (DiffractionObject) – The diffraction object that contains the cve to be applied.

Returns:

corrected_pattern – The corrected diffraction object with the correction applied through multiplication.

Return type:

DiffractionObject

diffpy.labpdfproc.functions.compute_cve(input_pattern, mud, method='polynomial_interpolation', xtype='tth')[source]

diffpy.labpdfproc.tools module

diffpy.labpdfproc.tools.load_metadata(args, filepath)[source]

Load the relevant metadata from args to write into the header of the output files.

Parameters:
  • args (argparse.Namespace) – The arguments from the parser.

  • filepath (Path) – The filepath of the current input file.

Returns:

metadata – The dictionary with relevant arguments from the parser.

Return type:

dict

diffpy.labpdfproc.tools.load_package_info(args)[source]

Load diffpy.labpdfproc package name and version into args using get_package_info function from diffpy.utils.

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Returns:

args – The updated argparse Namespace with diffpy.labpdfproc name and version inserted.

Return type:

argparse.Namespace

diffpy.labpdfproc.tools.load_user_info(args)[source]

Load user info into args. If none is provided, call check_and_build_global_config function from diffpy.utils to prompt the user for inputs. Otherwise, call get_user_info with the provided arguments.

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Returns:

args – The updated argparse Namespace with username, email, and orcid inserted.

Return type:

argparse.Namespace

diffpy.labpdfproc.tools.load_user_metadata(args)[source]

Load user metadata into args, raise ValueError if it is in incorrect format.

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Returns:

args – The updated argparse Namespace with user metadata inserted as key-value pairs.

Return type:

argparse.Namespace

diffpy.labpdfproc.tools.load_wavelength_from_config_file(args)[source]

Load wavelength from config files.

It prioritizes values in the following order: 1. cli inputs, 2. local config file, 3. global config file.

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Returns:

args – The updated arguments with the updated wavelength and anode type.

Return type:

argparse.Namespace

diffpy.labpdfproc.tools.normalize_wavelength(args)[source]

Normalize args.wavelength to a float.

If args.wavelength is: - None: return args unchanged - float-like: convert to float - string: look up corresponding value in WAVELENGTHS (case-insensitive)

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Returns:

args – The updated arguments with args.wavelength.

Return type:

argparse.Namespace

Raises:

ValueError – If a string wavelength is not a known source.

diffpy.labpdfproc.tools.preprocessing_args(args)[source]

Perform preprocessing on the provided args. The process includes loading package and user information, setting input, output, wavelength, anode type, xtype, mu*D, and loading user metadata.

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Returns:

args – The updated argparse Namespace with arguments preprocessed.

Return type:

argparse.Namespace

diffpy.labpdfproc.tools.set_input_lists(args)[source]

Set input directory and files. It takes cli inputs, checks if they are files or directories and creates a list of files to be processed which is stored in the args Namespace.

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Raises:

FileNotFoundError – Raised when an input is invalid.

Returns:

args – The updated arguments with the modified input list.

Return type:

argparse.Namespace

diffpy.labpdfproc.tools.set_mud(args)[source]

Compute and set mu*D based on the selected method.

Options include: 1. Manually entering a value. 2. Estimating from a z-scan file. 3. Estimating theoretically based on sample mass density. 4. Estimating theoretically based on packing fraction.

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Returns:

args – The updated arguments with mu*D.

Return type:

argparse.Namespace

diffpy.labpdfproc.tools.set_output_directory(args)[source]

Set the output directory based on the given input arguments.

It is determined as follows: If user provides an output directory, use it. Otherwise, we set it to the current directory if nothing is provided. We then create the directory if it does not exist.

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Returns:

args – The updated arguments, with output_directory as the full path to the output file directory.

Return type:

argparse.Namespace

diffpy.labpdfproc.tools.set_wavelength(args)[source]

Set the wavelength based on args.wavelength.

args.wavelength may be: - None - a number (explicit wavelength in Å) - a string (X-ray source name)

If a string is provided, it must match a key in WAVELENGTHS.

Parameters:

args (argparse.Namespace)

Raises:

ValueError – If wavelength is required but missing, if a string wavelength is not a known source, or if a numeric wavelength is non-positive.

Returns:

args – Updated arguments with args.wavelength as a float.

Return type:

argparse.Namespace

diffpy.labpdfproc.tools.set_xtype(args)[source]

Set the xtype based on the given input arguments, raise an error if xtype is not one of {*XQUANTITIES, }.

Parameters:

args (argparse.Namespace) – The arguments from the parser.

Returns:

args – The updated arguments with the xtype as one of q, tth, or d.

Return type:

argparse.Namespace

diffpy.labpdfproc.labpdfprocapp module