Utilities
Overview of utilities offered by diffpy.utils
.
Check the examples provided for how to use these.
Parsers Utility
The diffpy.utils.parsers
module allows users to easily and robustly load file data into a Python project.
loadData()
: Find and load a data table/block from a text file. This seems to work for most datafiles including those generated by diffpy programs. Running onlynumpy.loadtxt
will result in errors for most these files as there is often excess data or parameters stored above the data block. Users can instead choose to load all the parameters of the form<param_name> = <param_value>
into a dictionary with this function by setting theheader
parameter toTrue
.The program identifies data blocks as the first matrix block with a constant number of columns. A user can tune the minimum number of rows this matrix block must have.
deserialize_data()
: Load data from a serial file format into a Python dictionary. Currently, the only supported serial format is.json
.serialize_data()
: Serialize the data generated byloadData()
into a serial file format. Currently, the only supported serial format is.json
.
For a more in-depth tutorial for how to use these parser utilities, click here.
Resample Utility
wsinterp()
: Allows users easily reample a PDF onto another grid. This makes use of the Whittaker-Shannon interpolation formula. To see the theory behind how this interpolation works and how to use it in practice, click here.
Tools Utility
The diffpy.utils.tools
module provides tool functions for use with diffpy apps.
get_user_info()
: This function is designed for managing and tracking username and email information.Developers can use this function to simplify the process of loading, merging, and saving information consistently and easily. Additionally, it saves the effort of re-entering information, and allows overriding current information by passing parameters.
get_package_info()
: This function loads package name and version information into a dictionary. It updates the package information under the key “package_info” in the format {“package_name”: “version_number”}, resulting in an entry in the passed metadata dictionary that looks like{"package_info": {"package1": "version_number1", "package2": "version_number2"}
if the function is called more than once.Users can use these functions to track and manage versions of packages that can later be stored, for example, in an output file header.
For a more in-depth tutorial for how to use these tools, click here.