Skip to content

Commit f96728a

Browse files
committed
Add class docstring for diffraction object and news
1 parent ce6c9cc commit f96728a

File tree

2 files changed

+96
-40
lines changed

2 files changed

+96
-40
lines changed

news/class-docstring.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* class docstring for `DiffractionObject`
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/utils/diffraction_objects.py

Lines changed: 73 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,50 +36,38 @@ def _setter_wmsg(attribute):
3636

3737
class DiffractionObject:
3838
"""
39-
Initialize a DiffractionObject instance.
39+
A class to represent diffraction data for various scientific experiments involving scattering
40+
techniques such as X-ray, neutron, and electron diffraction. This object can manage diffraction
41+
data including transformations between different scattering quantities like q (scattering vector),
42+
2θ (two-theta angle), and d (interplanar spacing), and perform various operations like scaling, addition,
43+
and subtraction of diffraction patterns.
4044
41-
Parameters
45+
Attributes
4246
----------
43-
xarray : array-like
44-
The independent variable array containing "q", "tth", or "d" values.
45-
yarray : array-like
46-
The dependent variable array corresponding to intensity values.
47-
xtype : str
48-
The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
49-
wavelength : float, optional
50-
The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
51-
scat_quantity : str, optional
47+
all_arrays : ndarray
48+
The array containing the quantity of q, tth, d values.
49+
input_xtype : str
50+
The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}
51+
id : uuid
52+
The unique identifier for the diffraction object.
53+
scat_quantity : str
5254
The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
53-
name : str, optional
55+
wavelength : float
56+
The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
57+
name: str
5458
The name or label for the scattering data. Default is an empty string "".
55-
metadata : dict, optional
56-
The additional metadata associated with the diffraction object. Default is {}.
57-
58-
Examples
59-
--------
60-
Create a DiffractionObject for X-ray scattering data:
61-
62-
>>> import numpy as np
63-
>>> from diffpy.utils.diffraction_objects import DiffractionObject
64-
...
65-
>>> x = np.array([0.12, 0.24, 0.31, 0.4]) # independent variable (e.g., q)
66-
>>> y = np.array([10, 20, 40, 60]) # intensity values
67-
>>> metadata = {
68-
... "sample": "rock salt from the beach",
69-
... "composition": "NaCl",
70-
... "temperature": "300 K,",
71-
... "experimenters": "Phill, Sally"
72-
... }
73-
>>> do = DiffractionObject(
74-
... xarray=x,
75-
... yarray=y,
76-
... xtype="q",
77-
... wavelength=1.54,
78-
... scat_quantity="x-ray",
79-
... name="beach_rock_salt_1",
80-
... metadata=metadata
81-
... )
82-
>>> print(do.metadata)
59+
qmin : float
60+
The minimum q value.
61+
qmax : float
62+
The maximum q value.
63+
tthmin : float
64+
The minimum two-theta value.
65+
tthmax : float
66+
The maximum two-theta value.
67+
dmin : float
68+
The minimum d-spacing value.
69+
dmax : float
70+
The maximum d-spacing value.
8371
"""
8472

8573
def __init__(
@@ -92,6 +80,51 @@ def __init__(
9280
name="",
9381
metadata={},
9482
):
83+
"""
84+
Initialize a DiffractionObject instance.
85+
86+
Parameters
87+
----------
88+
xarray : ndarray
89+
The independent variable array containing "q", "tth", or "d" values.
90+
yarray : ndarray
91+
The dependent variable array corresponding to intensity values.
92+
xtype : str
93+
The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
94+
wavelength : float, optional
95+
The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
96+
scat_quantity : str, optional
97+
The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
98+
name : str, optional
99+
The name or label for the scattering data. Default is an empty string "".
100+
metadata : dict, optional
101+
The additional metadata associated with the diffraction object. Default is {}.
102+
103+
Examples
104+
--------
105+
Create a DiffractionObject for X-ray scattering data
106+
>>> import numpy as np
107+
>>> from diffpy.utils.diffraction_objects import DiffractionObject
108+
...
109+
>>> x = np.array([0.12, 0.24, 0.31, 0.4]) # independent variable (e.g., q)
110+
>>> y = np.array([10, 20, 40, 60]) # intensity values
111+
>>> metadata = {
112+
... "sample": "rock salt from the beach",
113+
... "composition": "NaCl",
114+
... "temperature": "300 K,",
115+
... "experimenters": "Phill, Sally"
116+
... }
117+
>>> do = DiffractionObject(
118+
... xarray=x,
119+
... yarray=y,
120+
... xtype="q",
121+
... wavelength=1.54,
122+
... scat_quantity="x-ray",
123+
... name="beach_rock_salt_1",
124+
... metadata=metadata
125+
... )
126+
>>> print(do.metadata)
127+
"""
95128

96129
self._id = uuid.uuid4()
97130
self._input_data(xarray, yarray, xtype, wavelength, scat_quantity, name, metadata)

0 commit comments

Comments
 (0)