Skip to content

Commit 913d824

Browse files
authored
Merge pull request #315 from sbillinge/sidocs
doc: simon tweaks on the docs before release
2 parents 5359054 + 0977b7f commit 913d824

File tree

6 files changed

+130
-55
lines changed

6 files changed

+130
-55
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Examples
77
Landing page for diffpy.utils examples.
88

99
.. toctree::
10-
parsers_example
10+
diffraction_objects_example
11+
transforms_example
1112
resample_example
13+
parsers_example
1214
tools_example
13-
transforms_example
14-
diffraction_objects_example

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

+56-26
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,65 @@ This example will demonstrate how diffpy.utils lets us easily process and serial
99
Using the parsers module, we can load file data into simple and easy-to-work-with Python objects.
1010

1111
1) To begin, unzip :download:`parser_data<./example_data/parser_data.zip>` and take a look at ``data.txt``.
12-
Our goal will be to extract and serialize the data table as well as the parameters listed in the header of this file.
12+
This is a fairly standard format for 1D powder diffraction data.
13+
Our goal will be to extract the data, and the parameters listed in the header, from this file and
14+
load it into our program.
1315

1416
2) To get the data table, we will use the ``loadData`` function. The default behavior of this
15-
function is to find and extract a data table from a file.::
17+
function is to find and extract a data table from a file.
18+
19+
.. code-block:: python
1620
1721
from diffpy.utils.parsers.loaddata import loadData
1822
data_table = loadData('<PATH to data.txt>')
1923
20-
While this will work with most datasets, on our ``data.txt`` file, we got a ``ValueError``. The reason for this is
21-
due to the comments ``$ Phase Transition Near This Temperature Range`` and ``--> Note Significant Jump in Rw <--``
22-
embedded within the dataset. To fix this, try using the ``comments`` parameter. ::
24+
While this will work with most datasets, on our ``data.txt`` file, we got a ``ValueError``. The reason for this is
25+
due to the comments ``$ Phase Transition Near This Temperature Range`` and ``--> Note Significant Jump in Rw <--``
26+
embedded within the dataset. To fix this, try using the ``comments`` parameter.
27+
28+
.. code-block:: python
2329
2430
data_table = loadData('<PATH to data.txt>', comments=['$', '-->'])
2531
26-
This parameter tells ``loadData`` that any lines beginning with ``$`` and ``-->`` are just comments and
27-
more entries in our data table may follow.
32+
This parameter tells ``loadData`` that any lines beginning with ``$`` and ``-->`` are just comments and
33+
more entries in our data table may follow.
2834

29-
Here are a few other parameters to test out:
35+
Here are a few other parameters to test out:
3036

3137
* ``delimiter=','``: Look for a comma-separated data table. Useful for csv file types.
32-
However, since ``data.txt`` is whitespace separated, running ::
38+
However, since ``data.txt`` is whitespace separated, running
39+
40+
.. code-block:: python
3341
3442
loadData('<PATH to data.txt>', comments=['$', '-->'], delimiter=',')
3543
36-
returns an empty list.
44+
returns an empty list.
3745
* ``minrows=50``: Only look for data tables with at least 50 rows. Since our data table has much less than that many
38-
rows, running ::
46+
rows, running
47+
48+
.. code-block:: python
3949
4050
loadData('<PATH to data.txt>', comments=['$', '-->'], minrows=50)
4151
42-
returns an empty list.
52+
returns an empty list.
4353
* ``usecols=[0, 3]``: Only return the 0th and 3rd columns (zero-indexed) of the data table. For ``data.txt``, this
44-
corresponds to the temperature and rw columns. ::
54+
corresponds to the temperature and rw columns.
55+
56+
.. code-block:: python
4557
4658
loadData('<PATH to data.txt>', comments=['$', '-->'], usecols=[0, 3])
4759
4860
3) Next, to get the header information, we can again use ``loadData``,
49-
but this time with the ``headers`` parameter enabled. ::
61+
but this time with the ``headers`` parameter enabled.
62+
63+
.. code-block:: python
5064
5165
hdata = loadData('<PATH to data.txt>', comments=['$', '-->'], headers=True)
5266
5367
4) Rather than working with separate ``data_table`` and ``hdata`` objects, it may be easier to combine them into a single
54-
dictionary. We can do so using the ``serialize_data`` function. ::
68+
dictionary. We can do so using the ``serialize_data`` function.
69+
70+
.. code-block:: python
5571
5672
from diffpy.utils.parsers.loaddata import serialize_data
5773
file_data = serialize_data('<PATH to data.txt', hdata, data_table)
@@ -60,45 +76,59 @@ Using the parsers module, we can load file data into simple and easy-to-work-wit
6076
# The entry is a dictionary containing data from hdata and data_table
6177
data_dict = file_data['data.txt']
6278
63-
This dictionary ``data_dict`` contains all entries in ``hdata`` and an additional entry named
64-
``data table`` containing ``data_table``. ::
79+
This dictionary ``data_dict`` contains all entries in ``hdata`` and an additional entry named
80+
``data table`` containing ``data_table``.
81+
82+
.. code-block:: python
6583
6684
here_is_the_data_table = data_dict['data table']
6785
68-
There is also an option to name columns in the data table and save those columns as entries instead. ::
86+
There is also an option to name columns in the data table and save those columns as entries instead.
87+
88+
.. code-block:: python
6989
7090
data_table_column_names = ['temperature', 'scale', 'stretch', 'rw'] # names of the columns in data.txt
7191
file_data = serialize_data('<PATH to data.txt>', hdata, data_table, dt_colnames=data_table_column_names)
7292
data_dict = file_data['data.txt']
7393
74-
Now we can extract specific data table columns from the dictionary. ::
94+
Now we can extract specific data table columns from the dictionary.
7595

96+
.. code-block:: python
7697
data_table_temperature_column = data_dict['temperature']
7798
data_table_rw_column = data_dict['rw']
7899
79-
5) When we are done working with the data, we can store it on disc for later use. This can also be done using the
80-
``serialize_data`` function with an additional ``serial_file`` parameter.::
100+
5) When we are done working with the data, we can store it on disk for later use. This can also be done using the
101+
``serialize_data`` function with an additional ``serial_file`` parameter.
102+
103+
.. code-block:: python
81104
82105
parsed_file_data = serialize_data('<PATH to data.txt>', hdata, data_table, serial_file='<PATH to serialfile.json>')
83106
84107
The returned value, ``parsed_file_data``, is the dictionary we just added to ``serialfile.json``.
85-
To extract the data from the serial file, we use ``deserialize_data``. ::
108+
To extract the data from the serial file, we use ``deserialize_data``.
109+
110+
.. code-block:: python
86111
87112
from diffpy.utils.parsers.serialization import deserialize_data
88113
parsed_file_data = deserialize_data('<PATH to serialdata.json>')
89114
90-
6) Finally, ``serialize_data`` allows us to store data from multiple text file in a single serial file. For one last bit
91-
of practice, we will extract and add the data from ``moredata.txt`` into the same ``serialdata.json`` file.::
115+
6) Finally, ``serialize_data`` allows us to store data from multiple text files in a single serial file. For one last bit
116+
of practice, we will extract and add the data from ``moredata.txt`` into the same ``serialdata.json`` file.
117+
118+
.. code-block:: python
92119
93120
data_table = loadData('<PATH to moredata.txt>')
94121
hdata = loadData('<PATH to moredata.txt>', headers=True)
95122
serialize_data('<PATH to moredata.txt>', hdata, data_table, serial_file='<PATH to serialdata.json>')
96123
97-
The serial file ``serialfile.json`` should now contain two entries: ``data.txt`` and ``moredata.txt``.
98-
The data from each file can be accessed using ::
124+
The serial file ``serialfile.json`` should now contain two entries: ``data.txt`` and ``moredata.txt``.
125+
The data from each file can be accessed using
126+
127+
.. code-block:: python
99128
100129
serial_data = deserialize_data('<PATH to serialdata.json>')
101130
data_txt_data = serial_data['data.txt'] # Access data.txt data
102131
moredata_txt_data = serial_data['moredata.txt'] # Access moredata.txt data
103132
104133
For more information, check out the :ref:`documentation<Parsers Documentation>` of the ``parsers`` module.
134+
b

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

+45-18
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,29 @@ given enough datapoints.
1313
1) To start, unzip :download:`parser_data<./example_data/parser_data.zip>`. Then, load the data table from ``Nickel.gr``
1414
and ``NiTarget.gr``. These datasets are based on data from `Atomic Pair Distribution Function Analysis: A Primer
1515
<https://global.oup.com/academic/product/atomic-pair-distribution-function-analysis-9780198885801?cc=us&lang=en&>`_.
16-
::
1716

18-
from diffpy.utils.parsers.loaddata import loadData
19-
nickel_datatable = loadData('<PATH to Nickel.gr>')
20-
nitarget_datatable = loadData('<PATH to NiTarget.gr>')
17+
.. code-block:: python
2118
22-
Each data table has two columns: first is the grid and second is the function value.
23-
To extract the columns, we can utilize the serialize function ... ::
19+
from diffpy.utils.parsers.loaddata import loadData
20+
nickel_datatable = loadData('<PATH to Nickel.gr>')
21+
nitarget_datatable = loadData('<PATH to NiTarget.gr>')
22+
23+
Each data table has two columns: first is the grid and second is the function value.
24+
To extract the columns, we can utilize the serialize function ...
25+
26+
.. code-block:: python
27+
28+
from diffpy.utils.parsers.serialization import serialize_data
29+
nickel_data = serialize_data('Nickel.gr', {}, nickel_datatable, dt_colnames=['grid', 'func'])
30+
nickel_grid = nickel_data['Nickel.gr']['grid']
31+
nickel_func = nickel_data['Nickel.gr']['func']
32+
target_data = serialize_data('NiTarget.gr', {}, nitarget_datatable, dt_colnames=['grid', 'function'])
33+
target_grid = nickel_data['Nickel.gr']['grid']
34+
target_func = nickel_data['Nickel.gr']['func']
35+
36+
To extract the columns, we can utilize the serialize function ...
37+
38+
.. code-block:: python
2439
2540
from diffpy.utils.parsers.serialization import serialize_data
2641
nickel_data = serialize_data('Nickel.gr', {}, nickel_datatable, dt_colnames=['grid', 'func'])
@@ -30,42 +45,52 @@ given enough datapoints.
3045
target_grid = nickel_data['Nickel.gr']['grid']
3146
target_func = nickel_data['Nickel.gr']['func']
3247
33-
... or you can use any other column extracting method you prefer.
48+
... or you can use any other column extracting method you prefer.
3449

35-
2) If we plot the two on top of each other ::
50+
2) If we plot the two on top of each other
51+
52+
.. code-block:: python
3653
3754
import matplotlib.pyplot as plt
3855
plt.plot(target_grid, target_func, linewidth=3)
3956
plt.plot(nickel_grid, nickel_func, linewidth=1)
4057
41-
they look pretty similar, but to truly see the difference, we should plot the difference between the two.
42-
We may want to run something like ... ::
58+
they look pretty similar, but to truly see the difference, we should plot the difference between the two.
59+
We may want to run something like ...
60+
61+
.. code-block:: python
4362
4463
import numpy as np
4564
difference = np.subtract(target_func, nickel_func)
4665
47-
... but this will only produce the right result if the ``target_func`` and ``nickel_func`` are on the same grid.
48-
Checking the lengths of ``target_grid`` and ``nickel_grid`` shows that these grids are clearly distinct.
66+
... but this will only produce the right result if the ``target_func`` and ``nickel_func`` are on the same grid.
67+
Checking the lengths of ``target_grid`` and ``nickel_grid`` shows that these grids are clearly distinct.
4968

5069
3) However, we can resample the two functions to be on the same grid. Since both functions have grids spanning
51-
``[0, 60]``, let us define a new grid ... ::
70+
``[0, 60]``, let us define a new grid ...
71+
72+
.. code-block:: python
5273
5374
grid = np.linspace(0, 60, 6001)
5475
55-
... and use the diffpy.utils ``wsinterp`` function to resample on this grid.::
76+
... and use the diffpy.utils ``wsinterp`` function to resample on this grid.
77+
78+
.. code-block:: python
5679
5780
from diffpy.utils.resampler import wsinterp
5881
nickel_resample = wsinterp(grid, nickel_grid, nickel_func)
5982
target_resample = wsinterp(grid, target_grid, target_func)
6083
61-
We can now plot the difference to see that these two functions are quite similar.::
84+
We can now plot the difference to see that these two functions are quite similar.
85+
86+
.. code-block:: python
6287
6388
plt.plot(grid, target_resample)
6489
plt.plot(grid, nickel_resample)
6590
plt.plot(grid, target_resample - nickel_resample)
6691
67-
This is the desired result as the data in ``Nickel.gr`` is every tenth data point in ``NiTarget.gr``.
68-
This also shows us that ``wsinterp`` can help us reconstruct a function from incomplete data.
92+
This is the desired result as the data in ``Nickel.gr`` is every tenth data point in ``NiTarget.gr``.
93+
This also shows us that ``wsinterp`` can help us reconstruct a function from incomplete data.
6994

7095
4) In order for our function reconstruction to be perfect up to a truncation error, we require that (a) the function is
7196
a Fourier transform of a band-limited dataset and (b) the original grid has enough equally-spaced datapoints based on
@@ -79,7 +104,9 @@ given enough datapoints.
79104
Thus, our original grid requires :math:`25.0 * 60.0 / \pi < 478`. Since our grid has :math:`601` datapoints, our
80105
reconstruction was perfect as shown from the comparison between ``Nickel.gr`` and ``NiTarget.gr``.
81106

82-
This computation is implemented in the function ``nsinterp``.::
107+
This computation is implemented in the function ``nsinterp``.
108+
109+
.. code-block:: python
83110
84111
from diffpy.utils.resampler import nsinterp
85112
qmin = 0

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

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This example will demonstrate how to use the functions in the
1616
1717
# Example: convert q to 2theta
1818
from diffpy.utils.transforms import q_to_tth
19+
1920
wavelength = 0.71
2021
q = np.array([0, 0.2, 0.4, 0.6, 0.8, 1])
2122
tth = q_to_tth(q, wavelength)
@@ -32,6 +33,7 @@ This example will demonstrate how to use the functions in the
3233
3334
# Example: convert 2theta to q
3435
from diffpy.utils.transforms import tth_to_q
36+
3537
wavelength = 0.71
3638
tth = np.array([0, 30, 60, 90, 120, 180])
3739
q = tth_to_q(tth, wavelength)
@@ -49,11 +51,13 @@ This example will demonstrate how to use the functions in the
4951
5052
# Example: convert d to q
5153
from diffpy.utils.transforms import d_to_q
54+
5255
d = np.array([1.0, 0.8, 0.6, 0.4, 0.2])
5356
q = d_to_q(d)
5457
5558
# Example: convert d to 2theta
5659
from diffpy.utils.transforms import d_to_tth
60+
5761
wavelength = 0.71
5862
d = np.array([1.0, 0.8, 0.6, 0.4, 0.2])
5963
tth = d_to_tth(d, wavelength)

Diff for: doc/source/index.rst

+20-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44

55
.. |title| replace:: diffpy.utils documentation
66

7-
diffpy.utils - Shared utilities for diffpy packages.
7+
diffpy.utils - General utilities for analyzing diffraction data
88

99
| Software version |release|.
1010
| Last updated |today|.
1111
12-
The diffpy.utils package provides general functions for extracting data from variously formatted text files as well as
13-
some PDF-specific functionality. These include wx GUI utilities used by the PDFgui program and an interpolation function
14-
based on the Whittaker-Shannon formula for resampling a bandlimited PDF or other profile function.
12+
The diffpy.utils package provides a number of functions and classes designed to help
13+
researchers analyze their diffraction data. It also includes some functionality for
14+
carrying out PDF analysis. Examples are parsers for reading common format diffraction
15+
data files, ``DiffractionObjects`` that allow you to do algebra on diffraction patterns,
16+
tools for better capture and propagation of metadata,
17+
diffraction-friendly interpolation routines, as well as some other tools used across
18+
diffpy libraries.
1519

1620
Click :ref:`here<Utilities>` for a full list of utilities offered by diffpy.utils.
1721

@@ -20,6 +24,7 @@ Examples
2024
========
2125
Illustrations of when and how one would use various diffpy.utils functions.
2226

27+
* :ref:`Manipulate and do algebra on diffraction data<Diffraction Objects Example>`
2328
* :ref:`File Data Extraction<Parsers Example>`
2429
* :ref:`Resampling and Data Reconstruction<Resample Example>`
2530
* :ref:`Load and Manage User and Package Information<Tools Example>`
@@ -30,8 +35,9 @@ Authors
3035

3136
diffpy.utils is developed by members of the Billinge Group at
3237
Columbia University and at Brookhaven National Laboratory including
33-
Pavol Juhás, Christopher L. Farrow, the Billinge Group
34-
and its community contributors.
38+
Pavol Juhás, Christopher L. Farrow, Simon J. L. Billinge, Andrew Yang,
39+
with contributions from many Billinge Group members and
40+
members of the diffpy community.
3541

3642
For a detailed list of contributors see
3743
https://github.com/diffpy/diffpy.utils/graphs/contributors.
@@ -43,6 +49,14 @@ Installation
4349
See the `README <https://github.com/diffpy/diffpy.utils#installation>`_
4450
file included with the distribution.
4551

52+
========
53+
Citation
54+
========
55+
56+
If you use this program for a scientific research that leads to publication, we ask that you acknowledge use of the program by citing the following paper in your publication:
57+
58+
P. Juhás, C. L. Farrow, X. Yang, K. R. Knox and S. J. L. Billinge, Complex modeling: a strategy and software program for combining multiple information sources to solve ill posed structure and nanostructure inverse problems, Acta Crystallogr. A 71, 562-568 (2015).
59+
4660
=================
4761
Table of contents
4862
=================

Diff for: doc/source/license.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ OPEN SOURCE LICENSE AGREEMENT
1414
Lawrence Berkeley National Laboratory
1515
| Copyright (c) 2014, Australian Synchrotron Research Program Inc., ("ASRP")
1616
| Copyright (c) 2006-2007, Board of Trustees of Michigan State University
17-
| Copyright (c) 2008-2012, The Trustees of Columbia University in
18-
the City of New York
1917
| Copyright (c) 2014-2019, Brookhaven Science Associates,
2018
Brookhaven National Laboratory
19+
| Copyright (c) 2008-2025, The Trustees of Columbia University in
20+
the City of New York
2121
2222

2323
The "DiffPy-CMI" is distributed subject to the following license conditions:

0 commit comments

Comments
 (0)