Skip to content

Commit

Permalink
Add class docstring for diffraction object and news
Browse files Browse the repository at this point in the history
  • Loading branch information
bobleesj committed Dec 22, 2024
1 parent ce6c9cc commit f96728a
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 40 deletions.
23 changes: 23 additions & 0 deletions news/class-docstring.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* class docstring for `DiffractionObject`

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
113 changes: 73 additions & 40 deletions src/diffpy/utils/diffraction_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,50 +36,38 @@ def _setter_wmsg(attribute):

class DiffractionObject:
"""
Initialize a DiffractionObject instance.
A class to represent diffraction data for various scientific experiments involving scattering
techniques such as X-ray, neutron, and electron diffraction. This object can manage diffraction
data including transformations between different scattering quantities like q (scattering vector),
2θ (two-theta angle), and d (interplanar spacing), and perform various operations like scaling, addition,
and subtraction of diffraction patterns.
Parameters
Attributes
----------
xarray : array-like
The independent variable array containing "q", "tth", or "d" values.
yarray : array-like
The dependent variable array corresponding to intensity values.
xtype : str
The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
wavelength : float, optional
The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
scat_quantity : str, optional
all_arrays : ndarray
The array containing the quantity of q, tth, d values.
input_xtype : str
The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}
id : uuid
The unique identifier for the diffraction object.
scat_quantity : str
The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
name : str, optional
wavelength : float
The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
name: str
The name or label for the scattering data. Default is an empty string "".
metadata : dict, optional
The additional metadata associated with the diffraction object. Default is {}.
Examples
--------
Create a DiffractionObject for X-ray scattering data:
>>> import numpy as np
>>> from diffpy.utils.diffraction_objects import DiffractionObject
...
>>> x = np.array([0.12, 0.24, 0.31, 0.4]) # independent variable (e.g., q)
>>> y = np.array([10, 20, 40, 60]) # intensity values
>>> metadata = {
... "sample": "rock salt from the beach",
... "composition": "NaCl",
... "temperature": "300 K,",
... "experimenters": "Phill, Sally"
... }
>>> do = DiffractionObject(
... xarray=x,
... yarray=y,
... xtype="q",
... wavelength=1.54,
... scat_quantity="x-ray",
... name="beach_rock_salt_1",
... metadata=metadata
... )
>>> print(do.metadata)
qmin : float
The minimum q value.
qmax : float
The maximum q value.
tthmin : float
The minimum two-theta value.
tthmax : float
The maximum two-theta value.
dmin : float
The minimum d-spacing value.
dmax : float
The maximum d-spacing value.
"""

def __init__(
Expand All @@ -92,6 +80,51 @@ def __init__(
name="",
metadata={},
):
"""
Initialize a DiffractionObject instance.
Parameters
----------
xarray : ndarray
The independent variable array containing "q", "tth", or "d" values.
yarray : ndarray
The dependent variable array corresponding to intensity values.
xtype : str
The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
wavelength : float, optional
The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
scat_quantity : str, optional
The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
name : str, optional
The name or label for the scattering data. Default is an empty string "".
metadata : dict, optional
The additional metadata associated with the diffraction object. Default is {}.
Examples
--------
Create a DiffractionObject for X-ray scattering data
>>> import numpy as np
>>> from diffpy.utils.diffraction_objects import DiffractionObject
...
>>> x = np.array([0.12, 0.24, 0.31, 0.4]) # independent variable (e.g., q)
>>> y = np.array([10, 20, 40, 60]) # intensity values
>>> metadata = {
... "sample": "rock salt from the beach",
... "composition": "NaCl",
... "temperature": "300 K,",
... "experimenters": "Phill, Sally"
... }
>>> do = DiffractionObject(
... xarray=x,
... yarray=y,
... xtype="q",
... wavelength=1.54,
... scat_quantity="x-ray",
... name="beach_rock_salt_1",
... metadata=metadata
... )
>>> print(do.metadata)
"""

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

0 comments on commit f96728a

Please sign in to comment.