From 01e71dc9c61124c903c2cead537a40d0f814612f Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sun, 15 Dec 2024 16:25:44 -0500 Subject: [PATCH] initial commit --- .../examples/diffractionobjectsexample.rst | 34 ------------ doc/source/examples/transformsexample.rst | 53 +++++++++++++++++++ .../utilities/diffractionobjectsutility.rst | 13 ----- doc/source/utilities/transformsutility.rst | 14 +++++ 4 files changed, 67 insertions(+), 47 deletions(-) delete mode 100644 doc/source/examples/diffractionobjectsexample.rst create mode 100644 doc/source/examples/transformsexample.rst delete mode 100644 doc/source/utilities/diffractionobjectsutility.rst create mode 100644 doc/source/utilities/transformsutility.rst diff --git a/doc/source/examples/diffractionobjectsexample.rst b/doc/source/examples/diffractionobjectsexample.rst deleted file mode 100644 index 48409432..00000000 --- a/doc/source/examples/diffractionobjectsexample.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. _Diffraction Objects Example: - -:tocdepth: -1 - -Diffraction Objects Example -########################### - -This example will demonstrate how to use the ``DiffractionObject`` class in the -``diffpy.utils.diffraction_objects`` module to process and analyze diffraction data. - -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. :: - - # 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]``. :: - - # Example: convert tth to q - from diffpy.utils.diffraction_objects import DiffractionObject - my_diffraction_pattern.on_tth = [[0, 30, 60, 90, 120, 180], [1, 2, 3, 4, 5, 6]] - my_diffraction_pattern.tth_to_q() - - Similarly, to load the converted array, you can either call ``test.tth_to_q()`` or ``test.on_tth[0]``. - -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. :: - - # 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 diff --git a/doc/source/examples/transformsexample.rst b/doc/source/examples/transformsexample.rst new file mode 100644 index 00000000..7877f866 --- /dev/null +++ b/doc/source/examples/transformsexample.rst @@ -0,0 +1,53 @@ +.. _Transforms Example: + +:tocdepth: -1 + +Transforms Example +################## + +This example will demonstrate how to use the functions in the +``diffpy.utils.transforms`` module to process and analyze diffraction data. + +1) Converting from ``q`` to ``2theta`` or ``d``: + If you have a 1D ``q``-array, you can use the ``q_to_tth`` and ``q_to_d`` functions + to convert it to ``2theta`` or ``d``. :: + + # Example: convert q to 2theta + from diffpy.utils.transformers import q_to_tth + wavelength = 0.71 + q = np.array([0, 0.2, 0.4, 0.6, 0.8, 1]) + tth = q_to_tth(q, wavelength) + + # Example: convert q to d + from diffpy.utils.transformers import q_to_d + q = np.array([0, 0.2, 0.4, 0.6, 0.8, 1]) + d = q_to_d(q) + +(2) Converting from ``2theta`` to ``q`` or ``d``: + For a 1D ``2theta`` array, you can convert it to ``q`` or ``d`` in a similar way. :: + + # Example: convert 2theta to q + from diffpy.utils.transformers import tth_to_q + wavelength = 0.71 + tth = np.array([0, 30, 60, 90, 120, 180]) + q = tth_to_q(tth, wavelength) + + # Example: convert 2theta to d + from diffpy.utils.transformers import tth_to_d + wavelength = 0.71 + tth = np.array([0, 30, 60, 90, 120, 180]) + d = tth_to_d(tth, wavelength) + +(3) Converting from ``d`` to ``q`` or ``2theta``: + For a 1D ``d`` array, you can convert it to ``q`` or ``2theta``. :: + + # Example: convert d to q + from diffpy.utils.transformers import tth_to_q + d = np.array([1.0, 0.8, 0.6, 0.4, 0.2]) + q = d_to_q(d) + + # Example: convert d to 2theta + from diffpy.utils.transformers import d_to_tth + wavelength = 0.71 + d = np.array([1.0, 0.8, 0.6, 0.4, 0.2]) + tth = d_to_tth(d, wavelength) diff --git a/doc/source/utilities/diffractionobjectsutility.rst b/doc/source/utilities/diffractionobjectsutility.rst deleted file mode 100644 index 94cb1308..00000000 --- a/doc/source/utilities/diffractionobjectsutility.rst +++ /dev/null @@ -1,13 +0,0 @@ -.. _Diffraction Objects Utility: - -Diffraction Objects Utility -=========================== - -The ``diffpy.utils.diffraction_objects`` module provides functions -for managing and analyzing diffraction data, including angle-space conversions -and interactions between diffraction data. - -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 `. diff --git a/doc/source/utilities/transformsutility.rst b/doc/source/utilities/transformsutility.rst new file mode 100644 index 00000000..5e2bac2a --- /dev/null +++ b/doc/source/utilities/transformsutility.rst @@ -0,0 +1,14 @@ +.. _Transforms Utility: + +Transforms Utility +================== + +The ``diffpy.utils.transforms`` module provides a set of functions for managing and analyzing diffraction data, +including angle-space transformations between ``q``, ``2theta``, and ``d``-spacing. + +These functions allow developers to standardize diffraction data and convert it between different spacings, +simplifying analysis, visualization, and processing. +They are also internally used by the ``DiffractionObject`` class for efficient data manipulation. +For more information about this, click :ref:`here `. + +For a more in-depth tutorial for how to use these functions, click :ref:`here `.