Skip to content

Commit aff934c

Browse files
docs: add functions examples, move files around to make docs appear correctly
1 parent 09d6638 commit aff934c

File tree

8 files changed

+80
-22
lines changed

8 files changed

+80
-22
lines changed

Diff for: doc/examples/functions_example.rst

-10
This file was deleted.

Diff for: doc/source/api/diffpy.labpdfproc.rst

-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ diffpy.labpdfproc.tools module
3535
:undoc-members:
3636
:show-inheritance:
3737

38-
diffpy.labpdfproc.mud_calculator module
39-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40-
41-
.. automodule:: diffpy.labpdfproc.mud_calculator
42-
:members:
43-
:undoc-members:
44-
:show-inheritance:
45-
4638
diffpy.labpdfproc.labpdfprocapp module
4739
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4840

File renamed without changes.
File renamed without changes.

Diff for: doc/source/examples/functions_example.rst

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.. _Functions Example:
2+
3+
:tocdepth: -1
4+
5+
Functions Example
6+
#################
7+
8+
This example will demonstrate how to use ``diffpy.labpdfproc.functions`` module independently
9+
to apply absorption correction to your 1D diffraction data.
10+
11+
1. First, you will need to prepare and load your input diffraction data.
12+
For example, if you want to load data from ``zro2_mo.xy`` in the ``example_data`` directory, you can write:
13+
14+
.. code-block:: python
15+
16+
from diffpy.utils.parsers.loaddata import loadData
17+
from diffpy.utils.diffraction_objects import DiffractionObject
18+
19+
filepath = "../example_data/zro2_mo.xy"
20+
xarray, yarray = loadData(filepath, unpack=True)
21+
input_pattern = DiffractionObject(
22+
xarray=xarray,
23+
yarray=yarray,
24+
xtype="tth",
25+
wavelength=0.7,
26+
scat_quantity="x-ray",
27+
name="input diffraction data",
28+
metadata={"beamline": "28ID-2"},
29+
)
30+
31+
For the full tutorial, please refer to https://www.diffpy.org/diffpy.utils/examples/diffraction_objects_example.html.
32+
33+
2. Assume you have created your ``input_pattern`` and specified mu*D value as ``muD`` (e.g., ``muD=2``).
34+
You can now compute the absorption correction (cve) for the given mu*D using the ``compute_cve`` function,
35+
apply it to your input pattern, and save the corrected file.
36+
37+
.. code-block:: python
38+
39+
from diffpy.labpdfproc.functions import apply_corr, compute_cve
40+
absorption_correction = compute_cve(input_pattern, muD) # compute cve, default method is "polynomial_interpolation"
41+
corrected_pattern = apply_corr(input_pattern, absorption_correction) # apply cve correction
42+
corrected_data.dump("corrected pattern.chi", xtype="tth") # save the corrected pattern
43+
44+
If you want to use brute-force computation instead, you can replace the first line with:
45+
46+
.. code-block:: python
47+
48+
absorption_correction = compute_cve(input_pattern, muD, method="brute_force")
49+
50+
3. Now, you can visualize the effect of the absorption correction
51+
by plotting the original and corrected diffraction patterns.
52+
53+
.. code-block:: python
54+
55+
import matplotlib.pyplot as plt
56+
plt.plot(input_pattern.xarray, input_pattern.yarray, label="Original Intensity")
57+
plt.plot(corrected_pattern.xarray, corrected_pattern.yarray, label="Corrected Intensity")
58+
plt.xlabel("tth (degrees)")
59+
plt.ylabel("Intensity")
60+
plt.legend()
61+
plt.title("Original vs. Corrected Intensity")
62+
plt.show()
63+
64+
4. You can modify the global parameters
65+
``N_POINTS_ON_DIAMETER`` (the number of points on each diameter to sample the circle)
66+
and ``TTH_GRID`` (the range of angles) when using the brute-force method.
67+
68+
To speed up computation, you can reduce the range of ``TTH_GRID``. You can also increase ``N_POINTS_ON_DIAMETER``
69+
for better accuracy, but keep in mind that this will increase computation time.
70+
For optimal results, we recommend setting it to an even number.
71+
72+
Currently, the interpolation coefficients were computed using ``N_POINTS_ON_DIAMETER=2000``,
73+
which ensures good accuracy within the mu*D range of 0.5 to 6.
74+
This value also provides flexibility if we decide to extend the interpolation range in the future.

Diff for: doc/source/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Table of contents
3434

3535
license
3636
release
37+
Utilities <utilities/utilities>
38+
Examples <examples/examples>
3739
Package API <api/diffpy.labpdfproc>
3840

3941
=======

Diff for: doc/utilities/functions_utility.rst renamed to doc/source/utilities/functions_utility.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
Functions Utility
44
=================
55

6-
The `diffpy.labpdfproc.functions` module provides tools
6+
The ``diffpy.labpdfproc.functions`` module provides tools
77
for computing and applying absorption correction (cve) to 1D diffraction patterns.
88

9-
- `Gridded_circle`: This class supports absorption correction by
9+
- ``Gridded_circle``: This class supports absorption correction by
1010
creating a uniform grid of points within a circle for a given radius and mu (linear absorption coefficient),
1111
and computing the path length and effective volume for each grid point at a given angle.
1212

13-
- `compute_cve`: This function computes the absorption correction curve for a given mu*D
13+
- ``compute_cve``: This function computes the absorption correction curve for a given mu*D
1414
(absorption coefficient mu and capillary diameter D).
1515
For brute force computation, it averages the effective volume across all grid points,
1616
then computes the cve values as the reciprocal of this average.
1717
For polynomial interpolation, it uses pre-computed coefficients to quickly interpolate cve values for a given mu*D.
1818
Polynomial interpolation is available for mu*D values between 0.5-6.
1919

20-
- `apply_corr`: This function applies the computed absorption correction to the input diffraction pattern
20+
- ``apply_corr``: This function applies the computed absorption correction to the input diffraction pattern
2121
by multiplying it with the computed cve, resulting in a corrected diffraction pattern.
2222

2323
For a more in-depth tutorial for how to use these tools, click :ref:`here <Functions Example>`.
File renamed without changes.

0 commit comments

Comments
 (0)