Skip to content

Latest commit

 

History

History
126 lines (100 loc) · 5.53 KB

diffraction_objects_example.rst

File metadata and controls

126 lines (100 loc) · 5.53 KB
tocdepth:-1

Diffraction Objects Example

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.

  1. To create a DiffractionObject, you need to specify the type of the independent variable (referred to as xtype, one of q, tth, or d), an xarray of the corresponding values, and a yarray of the intensity values. It is strongly encouraged to specify the wavelength in order to access most of the other functionalities in the class. Additionally, you can specify the type of your scattering experiment using the scat_quantity parameter, the name of your diffraction object using the name parameter, and a metadata dictionary containing relevant information about the data. Here's an example:
  1. DiffractionObject automatically populates the xarray onto q, tth, and d-spacing. If you want to access your diffraction data in a specific spacing, you can do this:
  1. Once the DiffractionObject is created, you can use get_array_index to get the index of the closest value in the xarray to a specified value. This is useful for alignment or comparison tasks. For example, assume you have created a DiffractionObject called do, and you want to find the closest index of tth=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 the xtype used when creating the DiffractionObject. For example, if you have created a DiffractionObject called do with xtype="q", you can find its closest index for q=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")
    
  2. 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 specified xarray. This makes it easier for visualizing and comparing two intensity curves on the same plot. For example, to scale do1 to match do2 at tth=60:

  1. 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()
    
  2. The dump function saves the diffraction data and relevant information to a specified file. You can choose one of the data axis (q, tth, or d) to export, with q as the default.