Skip to content

Commit 490486c

Browse files
add example and utility
1 parent 728ff36 commit 490486c

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

Diff for: doc/source/examples/diffractionobjectsexample.rst

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _Diffraction Objects Example:
2+
3+
:tocdepth: -1
4+
5+
Diffraction Objects Example
6+
###########################
7+
8+
This example will demonstrate how to use the ``DiffractionObject`` class in the
9+
``diffpy.utils.scattering_objects.diffraction_objects`` module to process and analyze diffraction data.
10+
11+
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.
12+
You can use these functions with a pre-defined ``DiffractionObject``. ::
13+
14+
# convert q to tth
15+
from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject
16+
test = DiffractionObject(wavelength=1.54)
17+
test.on_q = [[0, 0.2, 0.4, 0.6, 0.8, 1], [1, 2, 3, 4, 5, 6]]
18+
test.q_to_tth()
19+
20+
This function will convert your provided q array and return a two theta array in degrees.
21+
To load the converted array, you can either call ``test.q_to_tth()`` or ``test.on_q[0]``.
22+
23+
Similarly, use the function ``tth_to_q`` to convert two theta values in degrees to q values. ::
24+
25+
# convert tth to q
26+
from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject
27+
test = DiffractionObject(wavelength=1.54)
28+
test.on_tth = [[0, 30, 60, 90, 120, 180], [1, 2, 3, 4, 5, 6]]
29+
test.tth_to_q()
30+
31+
To load the converted array, you can either call ``test.tth_to_q()`` or ``test.on_tth[0]``.
32+
33+
2) You can use these functions without specifying a wavelength. However, if so, the function will return an empty array,
34+
so we strongly encourage you to specify a wavelength when using these functions. ::
35+
36+
from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject
37+
test = DiffractionObject()
38+
test.on_q = [[0, 0.2, 0.4, 0.6, 0.8, 1], [1, 2, 3, 4, 5, 6]]
39+
test.q_to_tth()
40+
41+
In this case, the function will return an empty array on two theta.

Diff for: doc/source/utilities/diffractionobjectsutility.rst

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. _Diffraction Objects Utility:
2+
3+
Diffraction Objects Utility
4+
===========================
5+
6+
The ``diffpy.utils.scattering_objects.diffraction_objects`` module provides functions
7+
for managing and analyzing diffraction data, including angle-space conversions
8+
and interactions between diffraction data.
9+
10+
- ``q_to_tth()``: Converts an array of q values to their corresponding two theta values, based on specified wavelength.
11+
- ``tth_to_q()``: Converts an array of two theta values to their corresponding q values, based on specified wavelength.
12+
13+
These functions help developers standardize diffraction data and update the arrays
14+
in the associated ``DiffractionObject``, enabling easier analysis and further processing.
15+
16+
For a more in-depth tutorial for how to use these functions, click :ref:`here <Diffraction Objects Example>`.

0 commit comments

Comments
 (0)