Skip to content

Commit 53ee55d

Browse files
authored
Merge pull request #177 from yucongalicechen/docs-main
docs: for main module and also serves as a quick-start tutorial
2 parents 59198ce + e222d5a commit 53ee55d

12 files changed

+195
-37
lines changed

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ which is the most common geometry for lab PDF measurements.
4848

4949
The theory is described in the following paper:
5050

51-
An ad hoc Absorption Correction for Reliable
51+
An Absorption Correction for Reliable
5252
Pair-Distribution Functions from Low Energy x-ray Sources,
5353
Yucong Chen, Till Schertenleib, Andrew Yang, Pascal Schouwink,
5454
Wendy L. Queen and Simon J. L. Billinge, in preparation.
5555

5656
The related experimental data acquisition protocols are described in the following paper:
5757

58-
Protocols for Obtaining Reliable PDFs from Laboratory
58+
Testing Protocols for Obtaining Reliable PDFs from Laboratory
5959
x-ray Sources Using PDFgetX3,
6060
Till Schertenleib, Daniel Schmuckler, Yucong Chen, Geng Bang Jin,
6161
Wendy L. Queen and Simon J. L. Billinge, in preparation.

doc/source/examples/examples.rst

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ Examples
77
Landing page for diffpy.labpdfproc examples.
88

99
.. toctree::
10+
labpdfprocapp_example
1011
functions_example
1112
tools_example

doc/source/examples/functions_example.rst

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ This example will demonstrate how to use ``diffpy.labpdfproc.functions`` module
99
to apply absorption correction to your 1D diffraction data.
1010

1111
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:
12+
For example, if you want to load data from ``zro2_mo.xy`` in the ``example-data`` directory, you can write:
1313

1414
.. code-block:: python
1515
1616
from diffpy.utils.parsers.loaddata import loadData
1717
from diffpy.utils.diffraction_objects import DiffractionObject
1818
19-
filepath = "../example_data/zro2_mo.xy"
19+
filepath = "../example-data/zro2_mo.xy"
2020
xarray, yarray = loadData(filepath, unpack=True)
2121
input_pattern = DiffractionObject(
2222
xarray=xarray,
@@ -28,7 +28,8 @@ For example, if you want to load data from ``zro2_mo.xy`` in the ``example_data`
2828
metadata={"beamline": "28ID-2"},
2929
)
3030
31-
For the full tutorial, please refer to https://www.diffpy.org/diffpy.utils/examples/diffraction_objects_example.html.
31+
For the full tutorial on working with diffraction objects,
32+
please refer to https://www.diffpy.org/diffpy.utils/examples/diffraction_objects_example.html.
3233

3334
2. Assume you have created your ``input_pattern`` and specified mu*D value as ``muD`` (e.g., ``muD=2``).
3435
You can now compute the absorption correction (cve) for the given mu*D using the ``compute_cve`` function,
@@ -55,7 +56,7 @@ by plotting the original and corrected diffraction patterns.
5556
import matplotlib.pyplot as plt
5657
plt.plot(input_pattern.xarray, input_pattern.yarray, label="Original Intensity")
5758
plt.plot(corrected_pattern.xarray, corrected_pattern.yarray, label="Corrected Intensity")
58-
plt.xlabel("tth (degrees)")
59+
plt.xlabel("tth (degree)")
5960
plt.ylabel("Intensity")
6061
plt.legend()
6162
plt.title("Original vs. Corrected Intensity")
@@ -70,5 +71,5 @@ for better accuracy, but keep in mind that this will increase computation time.
7071
For optimal results, we recommend setting it to an even number.
7172

7273
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.
74+
which ensures good accuracy within the muD range of 0.5 to 7.
75+
This resolution also provides flexibility for extending the interpolation range in the future.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
.. _labpdfprocapp Example:
2+
3+
:tocdepth: -1
4+
5+
labpdfprocapp Example
6+
#####################
7+
8+
This example provides a quick-start tutorial for using ``diffpy.labpdfproc``
9+
to apply absorption correction to your 1D diffraction data using the command-line (CLI).
10+
Check ``labpdfproc --help`` for more information.
11+
A graphical user interface (GUI) is also available and is designed to be intuitive and easy to use.
12+
13+
14+
1. To use this application, you will need:
15+
(1) your input diffraction data file(s), and (2) information required to compute the muD value.
16+
To launch the GUI, use ``labpdfproc`` or ``labpdfproc --gui``.
17+
Note that the GUI is currently not supported on Python 3.13.
18+
19+
20+
2. Here we first provide a basic CLI example.
21+
Assume you have an uncorrected diffraction data file named ``zro2_mo.xy`` in the current directory
22+
with a muD of 2.5 on the two-theta x-axis. Then the minimum command would be:
23+
24+
.. code-block:: python
25+
26+
labpdfproc zro2_mo.xy --mud 2.5
27+
28+
29+
3. You must provide at least one file path, and filepath(s) should immediately follow ``labpdfproc``.
30+
31+
To process multiple files at once in the CLI, separate each file path with a whitespace.
32+
In general, avoid spaces in filenames, but if necessary, enclose them in quotes; otherwise, quotes are optional.
33+
For example, the following is a valid and more complex CLI command:
34+
35+
.. code-block:: python
36+
37+
labpdfproc "SiO2 uncorrected.xy" input_dir file_list.txt ./*.chi data* --mud 2.5
38+
39+
This command will process ``"SiO2 uncorrected.xy"``,
40+
all files in the ``input_dir`` directory, all files listed in ``file_list.txt``,
41+
all ``.chi`` files in the current directory, and all files matching the pattern ``data``,
42+
using a muD value of 2.5.
43+
Check ``labpdfproc --help`` to see all supported file types.
44+
45+
In the GUI, you can select multiple individual files via the file browser, but not entire directories.
46+
To include directories, you can either:
47+
(1) create a text file named ``file_list.txt`` containing the desired paths and load it,
48+
(2) manually select all files in a folder, or
49+
(3) enter paths manually separated by a colon with no spaces.
50+
51+
We will now continue using ``zro2_mo.xy`` as the example input throughout the rest of this tutorial.
52+
53+
54+
4. The muD value is required for absorption correction, and you can specify it in one of the four ways:
55+
56+
.. code-block:: python
57+
58+
# Option 1: Manual value
59+
labpdfproc zro2_mo.xy --mud 2.5
60+
# Option 2: From a z-scan file
61+
labpdfproc zro2_mo.xy -z zscan.xy
62+
# Option 3: Using sample mass density
63+
labpdfproc zro2_mo.xy -d ZrO2,17.45,1.2
64+
# Option 4: Using packing fraction
65+
labpdfproc zro2_mo.xy -p ZrO2,17.45,0.2
66+
67+
Note that you can only use one method at a time. The following examples are not allowed:
68+
69+
.. code-block:: python
70+
71+
labpdfproc zro2_mo.xy --mud 2.5 -z zscan.xy
72+
labpdfproc zro2_mo.xy --mud 2.5 -d ZrO2,17.45,1.2
73+
74+
If the packing fraction option is not supported at the moment, you can approximate the sample mass density as:
75+
``mass density = packing fraction * material density``, where the material density can be looked up manually.
76+
77+
78+
5. You can specify the wavelength in two ways:
79+
80+
.. code-block:: python
81+
82+
# Option 1: Manually enter wavelength
83+
labpdfproc zro2_mo.xy --mud 2.5 -w 0.71303
84+
# Option 2: Use a known anode type
85+
labpdfproc zro2_mo.xy --mud 2.5 -a Mo
86+
87+
Do not use both ``-w`` and ``-a`` at the same time. For example:
88+
89+
.. code-block:: python
90+
91+
labpdfproc zro2_mo.xy --mud 2.5 -w 0.71303 -a Mo
92+
93+
is not valid. This is to avoid confusion when wavelength conflicts with anode type.
94+
To avoid retyping, you can save your wavelength or anode type in a diffpy configuration file.
95+
See full instructions at https://www.diffpy.org/diffpy.labpdfproc/examples/tools_example.html.
96+
97+
98+
6. You are also encouraged to provide your information (name, email, and orcid) for reproducibility:
99+
100+
.. code-block:: python
101+
102+
labpdfproc zro2_mo.xy --mud 2.5 -n Joe -e Joe@email.com --orcid 0000-0000-0000-0000
103+
104+
105+
Alternatively, you can enter this information during the interactive prompts
106+
or save it in your diffpy configuration file.
107+
For more details, refer to https://www.diffpy.org/diffpy.utils/examples/tools_example.html.
108+
109+
110+
7. You can further customize the diffraction correction process using the following options:
111+
112+
- Choose xtype: use ``-x`` to specify your input data's xtype, which will be used for the output.
113+
- Select correction method: use ``-m`` to choose between "brute_force" or "polynomial_interpolation" (faster and preferred for muD 0.5-7).
114+
- Specify output directory: use ``-o`` to save the corrected file(s) to a specific folder.
115+
- Add custom metadata: use ``-u`` to provide key-value pair for information tracking (e.g., experimental details).
116+
- Output the cve file: use ``-c`` to export the cve file along with the corrected data.
117+
- Overwrite existing files: use ``-f`` to replace any previous corrected files with the same names.
118+
119+
120+
8. To summarize, a full command might look like this:
121+
122+
.. code-block:: python
123+
124+
labpdfproc zro2_mo.xy --mud 2.5 -w 0.71303 -n Joe -x q -m brute_force -o results -u "facility=NSLS II" beamline=28ID-2 -c -f
125+
126+
After running the command, check your output folder (in this case, ``results``)
127+
for the corrected data file and cve file (if ``-c`` was used).
128+
In this example, the corrected and cve files are called ``zro2_mo_corrected.chi`` and ``zro2_mo_cve.chi``.
129+
The headers include all the arguments you provided
130+
—such as diffraction settings, personal information, and metadata—making it easy to track your analysis.

doc/source/examples/tools_example.rst

+3-17
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,14 @@ You can do this in one of the following four ways:
1919
args = Namespace(mud=2)
2020
# Option 2: From a z-scan file
2121
args = Namespace(z_scan_file="zscan.xy")
22-
# Option 3: Using mass density
23-
args = Namespace(sample_composition="ZrO2", energy=1.745, density=1.2)
22+
# Option 3: Using sample mass density
23+
args = Namespace(theoretical_from_density="ZrO2,17.45,1.2")
2424
# Option 4: Using packing fraction
25-
args = Namespace(sample_composition="ZrO2", energy=1.745, packing_fraction=0.3)
25+
args = Namespace(theoretical_from_packing="ZrO2,17.45,0.3")
2626
# Set and view the computed mu*D value
2727
args = set_mud(args)
2828
print(args.mud)
2929
30-
Note that only one method should be used at a time. The following are invalid examples:
31-
32-
.. code-block:: python
33-
34-
# Invalid example 1: manual mu*D and z-scan file both provided
35-
args = Namespace(mud=2, z_scan_file="zscan.xy")
36-
# Invalid example 2: missing required energy
37-
args = Namespace(sample_composition="ZrO2", density=1.2)
38-
# Invalid example 3: both mass density and packing fraction specified
39-
args = Namespace(sample_composition="ZrO2", energy=1.745, density=1.2, packing_fraction=0.3)
40-
41-
If the packing fraction option is not supported at the moment, you can approximate
42-
``mass density = packing fraction * material density``, where the material density can be looked up manually.
43-
4430
4531
2. Next, we load the input files for correction using ``set_input_lists(args)``:
4632

doc/source/utilities/functions_utility.rst

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ The ``diffpy.labpdfproc.functions`` module provides tools
77
for computing and applying absorption correction (cve) to 1D diffraction patterns.
88

99
- ``Gridded_circle``: This class supports absorption correction by
10-
creating a uniform grid of points within a circle for a given radius and mu (linear absorption coefficient),
10+
creating a uniform grid of points within a circle for a given radius and linear absorption coefficient mu,
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
14-
(absorption coefficient mu and capillary diameter D).
15-
For brute force computation, it averages the effective volume across all grid points,
16-
then computes the cve values as the reciprocal of this average.
17-
For polynomial interpolation, it uses pre-computed coefficients to quickly interpolate cve values for a given mu*D.
18-
Polynomial interpolation is available for mu*D values between 0.5-6.
13+
- ``compute_cve``: This function computes the absorption correction curve for a given muD value
14+
(the product of mu and capillary diameter D).
15+
For brute-force computation, it averages the effective volume across all grid points
16+
and computes the cve values as the reciprocal of this average.
17+
Alternatively, for fast calculation,
18+
it uses polynomial interpolation with pre-computed coefficients to estimate cve values for a given muD.
19+
Polynomial interpolation is available for muD values between 0.5-7.
1920

2021
- ``apply_corr``: This function applies the computed absorption correction to the input diffraction pattern
21-
by multiplying it with the computed cve, resulting in a corrected diffraction pattern.
22+
by multiplying it with the corresponding cve, resulting in a corrected diffraction pattern.
2223

2324
For a more in-depth tutorial for how to use these tools, click :ref:`here <Functions Example>`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.. _labpdfprocapp Utility:
2+
3+
labpdfprocapp Utility
4+
=====================
5+
6+
The ``diffpy.labpdfproc.labpdfprocapp`` module provides both a command-line (CLI) and graphical user interface (GUI)
7+
for processing diffraction data, applying absorption correction, and saving the output files.
8+
9+
- ``get_args()``: This function parses all CLI arguments.
10+
11+
- ``gooey_parser()``: This function provides a GUI for argument input.
12+
13+
- ``main()``: This function validates all arguments, performs preprocessing, and saves the output files.
14+
15+
For a more in-depth tutorial for how to get started, click :ref:`here <labpdfprocapp Example>`.

doc/source/utilities/tools_utility.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ The ``diffpy.labpdfproc.tools`` module provides functions to
77
manage user inputs, output directories, and diffraction information.
88
These functions work mostly with an ``argparse.Namespace`` object and help prepare data for diffraction processing.
99

10-
- ``set_mud()``: This function determines the mu*D value used to compute absorption correction.
11-
Users can either provide mu*D directly, upload a z-scan file,
10+
- ``set_mud()``: This function determines the muD value used to compute absorption correction.
11+
Users can either provide the value directly, upload a z-scan file,
1212
or specify relevant chemical information to get a theoretical estimation.
1313

1414
- ``set_input_lists()``: This function parses all specified input files.
@@ -42,7 +42,7 @@ These functions work mostly with an ``argparse.Namespace`` object and help prepa
4242
- ``load_package_info()``: This functions stores the package name and version for record-keeping.
4343

4444
- ``preprocessing_args()``: This is a convenience function that runs all standard setup steps listed above.
45-
It ensures the input/output paths, wavelength, mu*D value, metadata, and user and package info are
45+
It ensures the input/output paths, wavelength, muD value, metadata, and user and package info are
4646
fully initialized before applying the correction.
4747

4848
- ``load_metadata()``: This function transfers all collected information from the ``argparse.Namespace`` object

doc/source/utilities/utilities.rst

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ Check the :ref:`examples<Examples>` provided for how to use these.
1010
.. contents::
1111
:depth: 2
1212

13+
.. include:: labpdfprocapp_utility.rst
1314
.. include:: functions_utility.rst
1415
.. include:: tools_utility.rst

news/main-doc.rst

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Utility and example documentation for the main module.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/labpdfproc/tools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def set_wavelength(args):
278278

279279

280280
def set_xtype(args):
281-
f"""Set the xtype based on the given input arguments,
281+
"""Set the xtype based on the given input arguments,
282282
raise an error if xtype is not one of {*XQUANTITIES, }.
283283
284284
Parameters

0 commit comments

Comments
 (0)