Skip to content
39 changes: 16 additions & 23 deletions doc/source/examples/diffractionobjectsexample.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,27 @@ Diffraction Objects Example
This example will demonstrate how to use the ``DiffractionObject`` class in the
``diffpy.utils.scattering_objects.diffraction_objects`` module to process and analyze diffraction data.

1) We have the function ``q_to_tth`` to convert q to two theta values in degrees, and ``tth_to_q`` to do the reverse.
You can use these functions with a pre-defined ``DiffractionObject``. ::
1) Assuming we have created a ``DiffractionObject`` called my_diffraction_pattern from a measured diffraction pattern,
and we have specified the wavelength (see Section ??, to be added),
we can use the ``q_to_tth`` and ``tth_to_q`` functions to convert between q and two-theta. ::

# convert q to tth
from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject
test = DiffractionObject(wavelength=1.54)
test.on_q = [[0, 0.2, 0.4, 0.6, 0.8, 1], [1, 2, 3, 4, 5, 6]]
test.q_to_tth()
# Example: convert q to tth
my_diffraction_pattern.on_q = [[0, 0.2, 0.4, 0.6, 0.8, 1], [1, 2, 3, 4, 5, 6]]
my_diffraction_pattern.q_to_tth()

This function will convert your provided q array and return a two theta array in degrees.
To load the converted array, you can either call ``test.q_to_tth()`` or ``test.on_q[0]``.

Similarly, use the function ``tth_to_q`` to convert two theta values in degrees to q values. ::
To load the converted array, you can either call ``test.q_to_tth()`` or ``test.on_q[0]``. ::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is confusing. Doesn't this function do it in place and just set the tth array? In this respect, shouldn't this just be a private function and not used by the user at all? In other words, I would load my diffraction data into the object and the object automatically populates all the different arrays. So to get my data on q if I loaded it on tth I would just do my_diffraction_data.on_q

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a private function for now (I didn't see the "_" in the function name)? We need to call insert_scattering_quantity in order for it to populate on all arrays automatically. If they just do my_diffraction_pattern = DiffractionObjects() and my_diffraction_pattern.on_q = ... it is not automatically populated to tth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if they do that they are just instantiating an empty DO so there is nothing to populate anywhere..... So that is desired behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is what behavior do we want? I want to be able to get my intensity data on all the different x-grids, but I can do that by typing my_pattern.on_q orwhatever. What is the UC where I would want to run that function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Does this sound better?

Assuming we have created a DiffractionObject called my_diffraction_pattern from a measured diffraction pattern, and we have specified the wavelength (see Section ??, to be added), we can use the q_to_tth and tth_to_q functions to convert between q and two-theta. For example, my_diffraction_pattern.q_to_tth() converts q to two-theta, while my_diffraction_pattern.tth_to_q() converts two-theta to q. The converted array can be accessed using by calling my_diffraction_pattern.on_q[0] for q, or my_diffraction_pattern.on_tth[0] for two-theta.


# convert tth to q
# Example: convert tth to q
from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject
test = DiffractionObject(wavelength=1.54)
test.on_tth = [[0, 30, 60, 90, 120, 180], [1, 2, 3, 4, 5, 6]]
test.tth_to_q()
my_diffraction_pattern.on_tth = [[0, 30, 60, 90, 120, 180], [1, 2, 3, 4, 5, 6]]
my_diffraction_pattern.tth_to_q()

To load the converted array, you can either call ``test.tth_to_q()`` or ``test.on_tth[0]``.
Similarly, to load the converted array, you can either call ``test.tth_to_q()`` or ``test.on_tth[0]``.

2) You can use these functions without specifying a wavelength. However, if so, the function will return an empty array,
so we strongly encourage you to specify a wavelength when using these functions. ::

from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject
test = DiffractionObject()
test.on_q = [[0, 0.2, 0.4, 0.6, 0.8, 1], [1, 2, 3, 4, 5, 6]]
test.q_to_tth()
2) Both functions require a wavelength to perform conversions. Without a wavelength, they will return empty arrays.
Therefore, we strongly encourage you to specify a wavelength when using these functions. ::

In this case, the function will return an empty array on two theta.
# Example: without wavelength specified
my_diffraction_pattern.on_q = [[0, 0.2, 0.4, 0.6, 0.8, 1], [1, 2, 3, 4, 5, 6]]
my_diffraction_pattern.q_to_tth() # returns an empty array
7 changes: 2 additions & 5 deletions doc/source/utilities/diffractionobjectsutility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ The ``diffpy.utils.scattering_objects.diffraction_objects`` module provides func
for managing and analyzing diffraction data, including angle-space conversions
and interactions between diffraction data.

- ``q_to_tth()``: Converts an array of q values to their corresponding two theta values, based on specified wavelength.
- ``tth_to_q()``: Converts an array of two theta values to their corresponding q values, based on specified wavelength.

These functions help developers standardize diffraction data and update the arrays
in the associated ``DiffractionObject``, enabling easier analysis and further processing.
These functions help developers standardize diffraction data and update the arrays
in the associated ``DiffractionObject``, enabling easier analysis and further processing.

For a more in-depth tutorial for how to use these functions, click :ref:`here <Diffraction Objects Example>`.
Loading