tocdepth: | -1 |
---|
This example will demonstrate how to use the functions in the diffpy.utils.diffraction_objects
module
to create a DiffractionObject
instance and analyze your diffraction data using relevant functions.
- To create a
DiffractionObject
, you need to specify the type of the independent variable (referred to asxtype
, one ofq
,tth
, ord
), anxarray
of the corresponding values, and ayarray
of the intensity values. It is strongly encouraged to specify thewavelength
in order to access most of the other functionalities in the class. Additionally, you can specify the type of your scattering experiment using thescat_quantity
parameter, the name of your diffraction object using thename
parameter, and ametadata
dictionary containing relevant information about the data. Here's an example:
DiffractionObject
automatically populates thexarray
ontoq
,tth
, andd
-spacing. If you want to access your diffraction data in a specific spacing, you can do this:
Once the
DiffractionObject
is created, you can useget_array_index
to get the index of the closest value in thexarray
to a specified value. This is useful for alignment or comparison tasks. For example, assume you have created aDiffractionObject
calleddo
, and you want to find the closest index oftth=80
, you can type the following:index = do.get_array_index(80, xtype="tth")
If you do not specify an
xtype
, it will default to thextype
used when creating theDiffractionObject
. For example, if you have created aDiffractionObject
calleddo
withxtype="q"
, you can find its closest index forq=0.25
by typing either of the following:index = do.get_array_index(0.25) # no input xtype, defaults to q index = do.get_array_index(0.25, xtype="q")
You can compare diffraction objects too. For example, you can use the
scale_to
function to rescale one diffraction object to align its intensity values with a second diffraction object at a (closest) specified value on a specifiedxarray
. This makes it easier for visualizing and comparing two intensity curves on the same plot. For example, to scaledo1
to matchdo2
attth=60
:
You can create a copy of a diffraction object using the
copy
function, when you want to preserve the original data while working with a modified version.# Create a copy of Diffraction Object do do_copy = do.copy()
The
dump
function saves the diffraction data and relevant information to a specified file. You can choose one of the data axis (q
,tth
, ord
) to export, withq
as the default.