@@ -93,18 +93,18 @@ def __init__(
93
93
The dependent variable array corresponding to intensity values.
94
94
xtype : str
95
95
The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
96
- wavelength : float, optional
97
- The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
98
- scat_quantity : str, optional
99
- The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
100
- name : str, optional
101
- The name or label for the scattering data. Default is an empty string "".
102
- metadata : dict, optional
103
- The additional metadata associated with the diffraction object. Default is {}.
96
+ wavelength : float, optional, default is None.
97
+ The wavelength of the incoming beam, specified in angstroms (Å)
98
+ scat_quantity : str, optional, default is an empty string "".
99
+ The type of scattering experiment (e.g., "x-ray", "neutron").
100
+ name : str, optional, default is an empty string "".
101
+ The name or label for the scattering data.
102
+ metadata : dict, optional, default is an empty dictionary {}
103
+ The additional metadata associated with the diffraction object.
104
104
105
105
Examples
106
106
--------
107
- Create a DiffractionObject for X-ray scattering data
107
+ Create a DiffractionObject for X-ray scattering data:
108
108
>>> import numpy as np
109
109
>>> from diffpy.utils.diffraction_objects import DiffractionObject
110
110
...
@@ -181,30 +181,32 @@ def __add__(self, other):
181
181
182
182
Parameters
183
183
----------
184
- other : DiffractionObject or int or float
185
- The object to add to the current DiffractionObject. If `other` is a scalar value,
186
- it will be added to all yarray. The length of the yarray must match if `other` is
187
- an instance of DiffractionObject.
184
+ other : DiffractionObject, int, or float
185
+ The item to be added. If `other` is a scalar value, this value will be added to each element of the
186
+ yarray of this DiffractionObject instance. If `other` is another DiffractionObject, the yarrays of the
187
+ two DiffractionObjects will be combined element-wise. The result is a new DiffractionObject instance,
188
+ representing the addition and using the xarray from the left-hand side DiffractionObject.
188
189
189
190
Returns
190
191
-------
191
192
DiffractionObject
192
- The new and deep-copied DiffractionObject instance after adding values to the yarray.
193
+ The new DiffractionObject instance with modified yarray values. This instance is a deep copy of the
194
+ original with the additions applied.
193
195
194
196
Raises
195
197
------
196
198
ValueError
197
- Raised when the length of the yarray of the two DiffractionObject instances do not match .
199
+ Raised when the xarrays of two DiffractionObject instances are not equal .
198
200
TypeError
199
- Raised when the type of `other` is not an instance of DiffractionObject, int, or float.
201
+ Raised when `other` is not an instance of DiffractionObject, int, or float.
200
202
201
203
Examples
202
204
--------
203
- Add a scalar value to the yarray of the DiffractionObject instance:
205
+ Add a scalar value to the yarray of a DiffractionObject instance:
204
206
>>> new_do = my_do + 10.1
205
207
>>> new_do = 10.1 + my_do
206
208
207
- Add the yarray of two DiffractionObject instances:
209
+ Combine the yarrays of two DiffractionObject instances:
208
210
>>> new_do = my_do_1 + my_do_2
209
211
"""
210
212
@@ -219,6 +221,21 @@ def __add__(self, other):
219
221
__radd__ = __add__
220
222
221
223
def __sub__ (self , other ):
224
+ """Subtract scalar value or another DiffractionObject to the yarray of
225
+ the DiffractionObject.
226
+
227
+ This method behaves similarly to the `__add__` method, but performs subtraction instead of addition.
228
+ For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
229
+
230
+ Examples
231
+ --------
232
+ Subtract a scalar value from the yarray of a DiffractionObject instance:
233
+ >>> new_do = my_do - 10.1
234
+
235
+ Subtract the yarrays of two DiffractionObject instances:
236
+ >>> new_do = my_do_1 - my_do_2
237
+ """
238
+
222
239
self ._check_operation_compatibility (other )
223
240
subtracted_do = deepcopy (self )
224
241
if isinstance (other , (int , float )):
@@ -230,6 +247,21 @@ def __sub__(self, other):
230
247
__rsub__ = __sub__
231
248
232
249
def __mul__ (self , other ):
250
+ """Multiply a scalar value or another DiffractionObject with the yarray
251
+ of this DiffractionObject.
252
+
253
+ This method behaves similarly to the `__add__` method, but performs multiplication instead of addition.
254
+ For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
255
+
256
+ Examples
257
+ --------
258
+ Multiply a scalar value with the yarray of a DiffractionObject instance:
259
+ >>> new_do = my_do * 3.5
260
+
261
+ Multiply the yarrays of two DiffractionObject instances:
262
+ >>> new_do = my_do_1 * my_do_2
263
+ """
264
+
233
265
self ._check_operation_compatibility (other )
234
266
multiplied_do = deepcopy (self )
235
267
if isinstance (other , (int , float )):
@@ -241,6 +273,20 @@ def __mul__(self, other):
241
273
__rmul__ = __mul__
242
274
243
275
def __truediv__ (self , other ):
276
+ """Divide the yarray of this DiffractionObject by a scalar value or
277
+ another DiffractionObject.
278
+
279
+ This method behaves similarly to the `__add__` method, but performs division instead of addition.
280
+ For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
281
+
282
+ Examples
283
+ --------
284
+ Divide the yarray of a DiffractionObject instance by a scalar value:
285
+ >>> new_do = my_do / 2.0
286
+
287
+ Divide the yarrays of two DiffractionObject instances:
288
+ >>> new_do = my_do_1 / my_do_2
289
+ """
244
290
self ._check_operation_compatibility (other )
245
291
divided_do = deepcopy (self )
246
292
if isinstance (other , (int , float )):
@@ -291,7 +337,7 @@ def input_xtype(self):
291
337
292
338
Returns
293
339
-------
294
- str
340
+ input_xtype : str
295
341
The type of `xarray`, which must be one of {*XQUANTITIES}.
296
342
"""
297
343
return self ._input_xtype
@@ -306,7 +352,7 @@ def uuid(self):
306
352
307
353
Returns
308
354
-------
309
- uuid
355
+ uuid : UUID
310
356
The unique identifier of the DiffractionObject instance.
311
357
"""
312
358
return self ._uuid
@@ -328,7 +374,7 @@ def get_array_index(self, xtype, xvalue):
328
374
329
375
Returns
330
376
-------
331
- int
377
+ index : int
332
378
The index of the closest value in the array associated with the specified xtype and the value provided.
333
379
"""
334
380
@@ -381,7 +427,7 @@ def on_d(self):
381
427
return [self .all_arrays [:, 3 ], self .all_arrays [:, 0 ]]
382
428
383
429
def scale_to (self , target_diff_object , q = None , tth = None , d = None , offset = None ):
384
- """Returns a new diffraction object which is the current object but
430
+ """Return a new diffraction object which is the current object but
385
431
rescaled in y to the target.
386
432
387
433
By default, if `q`, `tth`, or `d` are not provided, scaling is based on the max intensity from each object.
@@ -403,12 +449,12 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
403
449
404
450
Returns
405
451
-------
406
- scaled : DiffractionObject
452
+ scaled_do : DiffractionObject
407
453
The rescaled DiffractionObject as a new object.
408
454
"""
409
455
if offset is None :
410
456
offset = 0
411
- scaled = self .copy ()
457
+ scaled_do = self .copy ()
412
458
count = sum ([q is not None , tth is not None , d is not None ])
413
459
if count > 1 :
414
460
raise ValueError (
@@ -419,8 +465,8 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
419
465
if count == 0 :
420
466
q_target_max = max (target_diff_object .on_q ()[1 ])
421
467
q_self_max = max (self .on_q ()[1 ])
422
- scaled ._all_arrays [:, 0 ] = scaled ._all_arrays [:, 0 ] * q_target_max / q_self_max + offset
423
- return scaled
468
+ scaled_do ._all_arrays [:, 0 ] = scaled_do ._all_arrays [:, 0 ] * q_target_max / q_self_max + offset
469
+ return scaled_do
424
470
425
471
xtype = "q" if q is not None else "tth" if tth is not None else "d"
426
472
data = self .on_xtype (xtype )
@@ -430,21 +476,26 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
430
476
431
477
xindex_data = (np .abs (data [0 ] - xvalue )).argmin ()
432
478
xindex_target = (np .abs (target [0 ] - xvalue )).argmin ()
433
- scaled ._all_arrays [:, 0 ] = data [1 ] * target [1 ][xindex_target ] / data [1 ][xindex_data ] + offset
434
- return scaled
479
+ scaled_do ._all_arrays [:, 0 ] = data [1 ] * target [1 ][xindex_target ] / data [1 ][xindex_data ] + offset
480
+ return scaled_do
435
481
436
482
def on_xtype (self , xtype ):
437
- """Return a list of two 1D np array with x and y data, raise an error
438
- if the specified xtype is invalid.
483
+ """Return a tuple of two 1D numpy arrays containing x and y data.
439
484
440
485
Parameters
441
486
----------
442
- xtype str
443
- the type of quantity for the independent variable from {*XQUANTITIES, }
487
+ xtype : str
488
+ The type of quantity for the independent variable chosen from {*XQUANTITIES, }
489
+
490
+ Raises
491
+ ------
492
+ ValueError
493
+ Raised when the specified xtype is not among {*XQUANTITIES, }
444
494
445
495
Returns
446
496
-------
447
- a list of two 1D np array with x and y data
497
+ (xarray, yarray) : tuple of ndarray
498
+ The tuple containing two 1D numpy arrays with x and y data for the specified xtype.
448
499
"""
449
500
if xtype .lower () in ANGLEQUANTITIES :
450
501
return self .on_tth ()
@@ -485,6 +536,6 @@ def copy(self):
485
536
Returns
486
537
-------
487
538
DiffractionObject
488
- A new instance of DiffractionObject, which is a deep copy of the current instance.
539
+ The new instance of DiffractionObject, which is a deep copy of the current instance.
489
540
"""
490
541
return deepcopy (self )
0 commit comments