-
Notifications
You must be signed in to change notification settings - Fork 11
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
docs: for functions module #163
Merged
+145
−8
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
File renamed without changes.
This file contains 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,10 @@ | ||
.. _Examples: | ||
|
||
:tocdepth: -1 | ||
|
||
Examples | ||
######## | ||
Landing page for diffpy.labpdfproc examples. | ||
|
||
.. toctree:: | ||
functions_example |
This file contains 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,74 @@ | ||
.. _Functions Example: | ||
|
||
:tocdepth: -1 | ||
|
||
Functions Example | ||
################# | ||
|
||
This example will demonstrate how to use ``diffpy.labpdfproc.functions`` module independently | ||
to apply absorption correction to your 1D diffraction data. | ||
|
||
1. First, you will need to prepare and load your input diffraction data. | ||
For example, if you want to load data from ``zro2_mo.xy`` in the ``example_data`` directory, you can write: | ||
|
||
.. code-block:: python | ||
from diffpy.utils.parsers.loaddata import loadData | ||
from diffpy.utils.diffraction_objects import DiffractionObject | ||
filepath = "../example_data/zro2_mo.xy" | ||
xarray, yarray = loadData(filepath, unpack=True) | ||
input_pattern = DiffractionObject( | ||
xarray=xarray, | ||
yarray=yarray, | ||
xtype="tth", | ||
wavelength=0.7, | ||
scat_quantity="x-ray", | ||
name="input diffraction data", | ||
metadata={"beamline": "28ID-2"}, | ||
) | ||
For the full tutorial, please refer to https://www.diffpy.org/diffpy.utils/examples/diffraction_objects_example.html. | ||
|
||
2. Assume you have created your ``input_pattern`` and specified mu*D value as ``muD`` (e.g., ``muD=2``). | ||
You can now compute the absorption correction (cve) for the given mu*D using the ``compute_cve`` function, | ||
apply it to your input pattern, and save the corrected file. | ||
|
||
.. code-block:: python | ||
from diffpy.labpdfproc.functions import apply_corr, compute_cve | ||
absorption_correction = compute_cve(input_pattern, muD) # compute cve, default method is "polynomial_interpolation" | ||
corrected_pattern = apply_corr(input_pattern, absorption_correction) # apply cve correction | ||
corrected_data.dump("corrected pattern.chi", xtype="tth") # save the corrected pattern | ||
If you want to use brute-force computation instead, you can replace the first line with: | ||
|
||
.. code-block:: python | ||
absorption_correction = compute_cve(input_pattern, muD, method="brute_force") | ||
3. Now, you can visualize the effect of the absorption correction | ||
by plotting the original and corrected diffraction patterns. | ||
|
||
.. code-block:: python | ||
import matplotlib.pyplot as plt | ||
plt.plot(input_pattern.xarray, input_pattern.yarray, label="Original Intensity") | ||
plt.plot(corrected_pattern.xarray, corrected_pattern.yarray, label="Corrected Intensity") | ||
plt.xlabel("tth (degrees)") | ||
plt.ylabel("Intensity") | ||
plt.legend() | ||
plt.title("Original vs. Corrected Intensity") | ||
plt.show() | ||
4. You can modify the global parameters | ||
``N_POINTS_ON_DIAMETER`` (the number of points on each diameter to sample the circle) | ||
and ``TTH_GRID`` (the range of angles) when using the brute-force method. | ||
|
||
To speed up computation, you can reduce the range of ``TTH_GRID``. You can also increase ``N_POINTS_ON_DIAMETER`` | ||
for better accuracy, but keep in mind that this will increase computation time. | ||
For optimal results, we recommend setting it to an even number. | ||
|
||
Currently, the interpolation coefficients were computed using ``N_POINTS_ON_DIAMETER=2000``, | ||
which ensures good accuracy within the mu*D range of 0.5 to 6. | ||
This value also provides flexibility if we decide to extend the interpolation range in the future. |
This file contains 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
This file contains 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,23 @@ | ||
.. _Functions Utility: | ||
|
||
Functions Utility | ||
================= | ||
|
||
The ``diffpy.labpdfproc.functions`` module provides tools | ||
for computing and applying absorption correction (cve) to 1D diffraction patterns. | ||
|
||
- ``Gridded_circle``: This class supports absorption correction by | ||
creating a uniform grid of points within a circle for a given radius and mu (linear absorption coefficient), | ||
and computing the path length and effective volume for each grid point at a given angle. | ||
|
||
- ``compute_cve``: This function computes the absorption correction curve for a given mu*D | ||
(absorption coefficient mu and capillary diameter D). | ||
For brute force computation, it averages the effective volume across all grid points, | ||
then computes the cve values as the reciprocal of this average. | ||
For polynomial interpolation, it uses pre-computed coefficients to quickly interpolate cve values for a given mu*D. | ||
Polynomial interpolation is available for mu*D values between 0.5-6. | ||
|
||
- ``apply_corr``: This function applies the computed absorption correction to the input diffraction pattern | ||
by multiplying it with the computed cve, resulting in a corrected diffraction pattern. | ||
|
||
For a more in-depth tutorial for how to use these tools, click :ref:`here <Functions Example>`. |
This file contains 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,13 @@ | ||
.. _Utilities: | ||
|
||
:tocdepth: -1 | ||
|
||
Utilities | ||
######### | ||
Overview of utilities offered by ``diffpy.labpdfproc``. | ||
Check the :ref:`examples<Examples>` provided for how to use these. | ||
|
||
.. contents:: | ||
:depth: 2 | ||
|
||
.. include:: functions_utility.rst |
This file contains 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,23 @@ | ||
**Added:** | ||
|
||
* Documentation for functions module. | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
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.
For this section, I'm wondering if I should add these parameters in the brute force computation function, e.g.,
compute_cve(input_pattern, mud, method="polynomial_interpolation", xtype="tth", n_points_on_diameter=None, tth_grid=None)
so that people can edit these without modifying the global parameters. This is probably uncommon so we don't need to modify anything in the main app.
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.
This would make this more general and so better. However, for things like this we may want to wait until someone asks for it and then do it? Maybe put it as a feature request in the issues so we don't forget? We could create a milestone which is a holding place for feature requests, and we can move them to a release milestone when someone requiests it and we decide we want to do it?
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.
Sounds great, I'll do that!
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.
It seems that I can't add a new milestone.. but I created an issue for this