@@ -35,51 +35,41 @@ def _setter_wmsg(attribute):
35
35
36
36
37
37
class DiffractionObject :
38
- """
39
- Initialize a DiffractionObject instance.
38
+ """Class for storing and manipulating diffraction data.
39
+
40
+ DiffractionObject stores data produced from X-ray, neutron,
41
+ and electron scattering experiments. The object can transform
42
+ between different scattering quantities such as q (scattering vector),
43
+ 2θ (two-theta angle), and d (interplanar spacing), and perform various
44
+ operations like scaling, addition, subtraction, and comparison for equality
45
+ between diffraction objects.
40
46
41
- Parameters
47
+ Attributes
42
48
----------
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
49
+ all_arrays : ndarray
50
+ The array containing the quantity of q, tth, d values.
51
+ input_xtype : str
52
+ The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}
53
+ id : uuid
54
+ The unique identifier for the diffraction object.
55
+ scat_quantity : str
52
56
The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
53
- name : str, optional
57
+ wavelength : float
58
+ The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
59
+ name: str
54
60
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)
61
+ qmin : float
62
+ The minimum q value.
63
+ qmax : float
64
+ The maximum q value.
65
+ tthmin : float
66
+ The minimum two-theta value.
67
+ tthmax : float
68
+ The maximum two-theta value.
69
+ dmin : float
70
+ The minimum d-spacing value.
71
+ dmax : float
72
+ The maximum d-spacing value.
83
73
"""
84
74
85
75
def __init__ (
@@ -92,6 +82,50 @@ def __init__(
92
82
name = "" ,
93
83
metadata = {},
94
84
):
85
+ """Initialize a DiffractionObject instance.
86
+
87
+ Parameters
88
+ ----------
89
+ xarray : ndarray
90
+ The independent variable array containing "q", "tth", or "d" values.
91
+ yarray : ndarray
92
+ The dependent variable array corresponding to intensity values.
93
+ xtype : str
94
+ The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
95
+ wavelength : float, optional
96
+ The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
97
+ scat_quantity : str, optional
98
+ The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
99
+ name : str, optional
100
+ The name or label for the scattering data. Default is an empty string "".
101
+ metadata : dict, optional
102
+ The additional metadata associated with the diffraction object. Default is {}.
103
+
104
+ Examples
105
+ --------
106
+ Create a DiffractionObject for X-ray scattering data
107
+ >>> import numpy as np
108
+ >>> from diffpy.utils.diffraction_objects import DiffractionObject
109
+ ...
110
+ >>> x = np.array([0.12, 0.24, 0.31, 0.4]) # independent variable (e.g., q)
111
+ >>> y = np.array([10, 20, 40, 60]) # intensity values
112
+ >>> metadata = {
113
+ ... "sample": "rock salt from the beach",
114
+ ... "composition": "NaCl",
115
+ ... "temperature": "300 K,",
116
+ ... "experimenters": "Phill, Sally"
117
+ ... }
118
+ >>> do = DiffractionObject(
119
+ ... xarray=x,
120
+ ... yarray=y,
121
+ ... xtype="q",
122
+ ... wavelength=1.54,
123
+ ... scat_quantity="x-ray",
124
+ ... name="beach_rock_salt_1",
125
+ ... metadata=metadata
126
+ ... )
127
+ >>> print(do.metadata)
128
+ """
95
129
96
130
self ._id = uuid .uuid4 ()
97
131
self ._input_data (xarray , yarray , xtype , wavelength , scat_quantity , name , metadata )
@@ -273,8 +307,8 @@ def id(self, _):
273
307
raise AttributeError (_setter_wmsg ("id" ))
274
308
275
309
def get_array_index (self , value , xtype = None ):
276
- """
277
- Return the index of the closest value in the array associated with the specified xtype.
310
+ """Return the index of the closest value in the array associated with
311
+ the specified xtype.
278
312
279
313
Parameters
280
314
----------
@@ -337,8 +371,8 @@ def on_d(self):
337
371
return [self .all_arrays [:, 3 ], self .all_arrays [:, 0 ]]
338
372
339
373
def scale_to (self , target_diff_object , q = None , tth = None , d = None , offset = 0 ):
340
- """
341
- returns a new diffraction object which is the current object but rescaled in y to the target
374
+ """Returns a new diffraction object which is the current object but
375
+ rescaled in y to the target.
342
376
343
377
The y-value in the target at the closest specified x-value will be used as the factor to scale to.
344
378
The entire array is scaled by this factor so that one object places on top of the other at that point.
@@ -379,8 +413,8 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=0):
379
413
return scaled
380
414
381
415
def on_xtype (self , xtype ):
382
- """
383
- Return a list of two 1D np array with x and y data, raise an error if the specified xtype is invalid
416
+ """Return a list of two 1D np array with x and y data, raise an error
417
+ if the specified xtype is invalid.
384
418
385
419
Parameters
386
420
----------
@@ -425,8 +459,7 @@ def dump(self, filepath, xtype=None):
425
459
np .savetxt (f , data_to_save , delimiter = " " )
426
460
427
461
def copy (self ):
428
- """
429
- Create a deep copy of the DiffractionObject instance.
462
+ """Create a deep copy of the DiffractionObject instance.
430
463
431
464
Returns
432
465
-------
0 commit comments