-
Notifications
You must be signed in to change notification settings - Fork 21
q_to_tth & tth_to_q #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
q_to_tth & tth_to_q #178
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7841ff2
fix docstring and add error messages
yucongalicechen 1b0fa19
add tests
yucongalicechen 4e85b0a
edit error message
yucongalicechen a33482b
add more tests
yucongalicechen 3efde28
add warning msg for wavelength, edit error msg
yucongalicechen a53461f
edit warning msg for wavelength, change index error to runtime error
yucongalicechen 2a5a819
add functionality for handling error messages
yucongalicechen 64d8693
remove docstring from private test functions
yucongalicechen 728ff36
add news
yucongalicechen 490486c
add example and utility
yucongalicechen d481253
edits on docs
yucongalicechen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
.. _Diffraction Objects Example: | ||
|
||
:tocdepth: -1 | ||
|
||
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``. :: | ||
|
||
# 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() | ||
|
||
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. :: | ||
|
||
# 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() | ||
|
||
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() | ||
|
||
In this case, the function will return an empty array on two theta. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.. _Diffraction Objects Utility: | ||
|
||
Diffraction Objects Utility | ||
=========================== | ||
|
||
The ``diffpy.utils.scattering_objects.diffraction_objects`` module provides functions | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need this here. It will be auto-generated in the API docs, and it is shown as an aexample above. |
||
- ``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. | ||
|
||
For a more in-depth tutorial for how to use these functions, click :ref:`here <Diffraction Objects Example>`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of test let's call it
my_diffraction_pattern
We are not writing all of the docs here, so you can start with something like "assuming we have created a
DiffractionObject
calledmy_diffraction_pattern
from a measured diffraction pattern, and we have specified the wavelenth (see Section ??) we can use theq_to_tth
andtth_to_q
functions to convert between Q and two-theta by typingmy_diffraction_pattern.q_to_tth()
..." ..and so on. Let's make an issue to add to docs "How to set a wavelength" and how to instantiate a diffraction object and how to add a diffraction pattern.