-
Notifications
You must be signed in to change notification settings - Fork 21
docs: add examples for Mu calculation #371
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
Draft
cadenmyers13
wants to merge
4
commits into
diffpy:main
Choose a base branch
from
cadenmyers13:mu-ex
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ Landing page for diffpy.utils examples. | |
| resample_example | ||
| parsers_example | ||
| tools_example | ||
| mu_calc_examples | ||
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,123 @@ | ||
| .. _mu calc Example: | ||
|
|
||
| :tocdepth: -1 | ||
|
|
||
| X-ray Absorption Coefficient (μ) Examples | ||
| ######################################### | ||
|
|
||
| These examples will demonstrate how to calculate the X-ray absorption | ||
| coefficient, μ, using different methods provided in ``diffpy.utils``. | ||
|
|
||
|
|
||
| .. admonition:: Methods for obtaining X-ray absorption coefficient | ||
|
|
||
| Obtaining μ can be done in **two | ||
| different ways** using ``diffpy.utils``. | ||
|
|
||
| 1. **Using a "z-scan" measurement**: Perform a z-scan measurement | ||
| on the sample and use ``diffpy.utils.tools.compute_mud`` to calculate | ||
| μ. | ||
| 2. **Using tabulated values**: Given composition, density, and X-ray energy, | ||
| use ``diffpy.utils.tools.compute_mu_using_xraydb`` to calculate μ from | ||
| tabulated values. | ||
|
|
||
| Why is μ Important? | ||
| ----------------------- | ||
|
|
||
| The X-ray absorption coefficient, μ, quantifies how much X-ray | ||
| radiation is absorbed by a material per unit length. It is a critical | ||
| parameter in many scientific techniques. | ||
|
|
||
| For example, when calculating pair distribution functions (PDFs) | ||
| using ``diffpy.pdfgetx``, | ||
| a key assumption is that the X-ray absorption is negligible. | ||
| This is frequently the case for high-energy X-rays. However, | ||
| this must be corrected for when using low energy X-rays, such | ||
| as those from a laboratory source. To correct for X-ray absorption, | ||
| the X-ray absorption coefficient, μ, must be known. | ||
|
|
||
| .. admonition:: Correcting for X-ray Absorption with ``diffpy.labpdfproc`` | ||
|
|
||
| If your objective is to correct for X-ray absorption in PDF calculations, | ||
| please refer to our package ``diffpy.labpdfproc``. This package is specifically | ||
| designed to correct your laboratory X-ray PDF data for absorption effects. | ||
| More information can be found in the | ||
| `diffpy.labpdfproc documentation <https://www.diffpy.org/diffpy.labpdfproc//>`_. | ||
|
|
||
|
|
||
| Calculating μ from a "z-scan" Measurement | ||
| ----------------------------------------- | ||
|
|
||
| .. note:: | ||
|
|
||
| The data we will be using for this example can be found here, | ||
| `FIXME <https://www.diffpy.org/diffpy.utils/examples/zscan_example_data.txt>`_. | ||
|
|
||
| A "z-scan" measurement is the measured transmission of your X-ray incident beam | ||
| as a function of sample position. This is obtained by moving the sample | ||
| along the X-ray beam (z-direction) and recording the transmitted | ||
| intensity at each position. This measured data looks something like this, | ||
|
|
||
| .. image:: ../images/FIXME | ||
| :alt: Example of a z-scan measurement. | ||
| :align: center | ||
| :width: 200px | ||
|
|
||
| Using this z-scan data, you can calculate **μ·d**, where d is the inner diameter of | ||
| your sample capillary. To do this, simply pass your z-scan measurement to the ``compute_mud`` | ||
| function from the ``diffpy.utils.tools`` module. | ||
|
|
||
|
|
||
| First, import the ``compute_mud`` function, | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from diffpy.utils.tools import compute_mud | ||
|
|
||
| Next, pass the filepath to the function, | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| filepath = "zscan_example_data.txt" | ||
| capillary_diameter = 0.5 # mm | ||
| mud = compute_mud(filepath) | ||
| print(f"Calculated mu*d: {round(mud, 3)}") | ||
| print(f"Calculated mu: {round(mud / capillary_diameter, 3)} mm^-1") | ||
|
|
||
| This will output the calculated value of μ·d, which is unitless, and μ in mm\ :sup:`-1`. | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| Calculated mu*d: FIXME | ||
| Calculated mu: FIXME mm^-1 | ||
|
|
||
| Calculating μ from Tabulated Values | ||
| ----------------------------------- | ||
|
|
||
| The function to calculate μ from tabulated values is located | ||
| in the ``diffpy.utils.tools`` module. So first, import the function, | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from diffpy.utils.tools import compute_mu_using_xraydb | ||
|
|
||
| To calculate μ, you need to know the sample composition, and X-ray energy, and sample mass density (g/cm\ :sup:`3`). | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| composition = "Fe2O3" | ||
| energy_keV = 17.45 # Mo K-alpha energy | ||
| sample_mass_density = 5.24 # g/cm^3 | ||
|
|
||
| Now calculate μ using the ``compute_mu_using_xraydb`` function. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| mu = compute_mu_using_xraydb(composition, energy_keV, sample_mass_density) | ||
| print(f"Calculated mu: {round(mu, 3)} mm^-1") | ||
|
|
||
| This will output the calculated X-ray absorption coefficient, μ, in mm\ :sup:`-1`. | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| Calculated mu: 13.967 mm^-1 | ||
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,23 @@ | ||
| **Added:** | ||
|
|
||
| * Add examples for calculating absorption coefficient. | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
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.
Please double check this