-
Notifications
You must be signed in to change notification settings - Fork 21
d_to_q, q_to_d #197
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
d_to_q, q_to_d #197
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
03eaa87
initial commit, add docstring and tests
yucongalicechen 76d8975
change value error to warning msg
yucongalicechen ccea574
better name for the warning msg
yucongalicechen 79399a2
add warning message about wavelength in tth_to_q
yucongalicechen 664df76
add news
yucongalicechen 6295aa5
small tweak to infinite d message
sbillinge 39f1c54
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] 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 |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ | |
| "The supplied q-array and wavelength will result in an impossible two-theta. " | ||
| "Please check these values and re-instantiate the DiffractionObject with correct values." | ||
| ) | ||
| invalid_input_emsg = ( | ||
| "Input values have resulted in an infinite output. Please ensure there are no zeros in the input." | ||
| ) | ||
|
|
||
|
|
||
| def _validate_inputs(q, wavelength): | ||
|
|
@@ -58,7 +61,7 @@ def q_to_tth(q, wavelength): | |
| ------- | ||
| tth : 1D array | ||
| The array of :math:`2\theta` values in degrees numpy.array([tths]). | ||
| This is the correct format for loading into diffpy.utils.DiffractionOject.on_tth | ||
| This is the correct format for loading into diffpy.utils.DiffractionObject.on_tth. | ||
yucongalicechen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| _validate_inputs(q, wavelength) | ||
| q.astype(float) | ||
|
|
@@ -92,21 +95,19 @@ def tth_to_q(tth, wavelength): | |
|
|
||
| Parameters | ||
| ---------- | ||
| tth : 2D array | ||
| The array of :math:`2\theta` values and :math: 'i' intensity values, np.array([[tths], [is]]). | ||
| This is the same format as, and so can accept, diffpy.utils.DiffractionOject.on_tth | ||
| tth : 1D array | ||
| The array of :math:`2\theta` values np.array([tths]). | ||
| The units of tth are expected in degrees. | ||
|
|
||
| wavelength : float | ||
| Wavelength of the incoming x-rays/neutrons/electrons | ||
|
|
||
| Returns | ||
| ------- | ||
| on_q : 2D array | ||
| The array of :math:`q` values and :math: 'i' intensity values unchanged, | ||
| np.array([[qs], [is]]). | ||
| q : 1D array | ||
| The array of :math:`q` values np.array([qs]). | ||
| The units for the q-values are the inverse of the units of the provided wavelength. | ||
| This is the correct format for loading into diffpy.utils.DiffractionOject.on_q | ||
| This is the correct format for loading into diffpy.utils.DiffractionObject.on_q. | ||
|
||
| """ | ||
| tth.astype(float) | ||
| if np.any(np.deg2rad(tth) > np.pi): | ||
|
|
@@ -121,17 +122,49 @@ def tth_to_q(tth, wavelength): | |
| return q | ||
|
|
||
|
|
||
| def q_to_d(qarray): | ||
| return 2.0 * np.pi / copy(qarray) | ||
| def q_to_d(q): | ||
| r""" | ||
| Helper function to convert q to d on independent variable axis, using :math:`d = \frac{2 \pi}{q}`. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| q : 1D array | ||
| The array of :math:`q` values np.array([qs]). | ||
| The units of q must be reciprocal of the units of wavelength. | ||
|
|
||
| Returns | ||
| ------- | ||
| d : 1D array | ||
| The array of :math:`d` values np.array([ds]). | ||
| """ | ||
| if 0 in q: | ||
| raise ValueError(invalid_input_emsg) | ||
|
||
| return 2.0 * np.pi / copy(q)[::-1] | ||
sbillinge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def tth_to_d(ttharray, wavelength): | ||
| qarray = tth_to_q(ttharray, wavelength) | ||
| return 2.0 * np.pi / copy(qarray) | ||
|
|
||
|
|
||
| def d_to_q(darray): | ||
| return 2.0 * np.pi / copy(darray) | ||
| def d_to_q(d): | ||
| r""" | ||
| Helper function to convert q to d using :math:`d = \frac{2 \pi}{q}`. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| d : 1D array | ||
| The array of :math:`d` values np.array([ds]). | ||
|
|
||
| Returns | ||
| ------- | ||
| q : 1D array | ||
| The array of :math:`q` values np.array([qs]). | ||
| The units of q must be reciprocal of the units of wavelength. | ||
| """ | ||
| if 0 in d: | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| raise ValueError(invalid_input_emsg) | ||
| return 2.0 * np.pi / copy(d)[::-1] | ||
|
|
||
|
|
||
| def d_to_tth(darray, wavelength): | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.