@@ -92,18 +92,18 @@ def __init__(
9292 The dependent variable array corresponding to intensity values.
9393 xtype : str
9494 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 {}.
95+ wavelength : float, optional, default is None.
96+ The wavelength of the incoming beam, specified in angstroms (Å)
97+ scat_quantity : str, optional, default is an empty string "".
98+ The type of scattering experiment (e.g., "x-ray", "neutron").
99+ name : str, optional, default is an empty string "".
100+ The name or label for the scattering data.
101+ metadata : dict, optional, default is an empty dictionary {}
102+ The additional metadata associated with the diffraction object.
103103
104104 Examples
105105 --------
106- Create a DiffractionObject for X-ray scattering data
106+ Create a DiffractionObject for X-ray scattering data:
107107 >>> import numpy as np
108108 >>> from diffpy.utils.diffraction_objects import DiffractionObject
109109 ...
@@ -180,30 +180,32 @@ def __add__(self, other):
180180
181181 Parameters
182182 ----------
183- other : DiffractionObject or int or float
184- The object to add to the current DiffractionObject. If `other` is a scalar value,
185- it will be added to all yarray. The length of the yarray must match if `other` is
186- an instance of DiffractionObject.
183+ other : DiffractionObject, int, or float
184+ The item to be added. If `other` is a scalar value, this value will be added to each element of the
185+ yarray of this DiffractionObject instance. If `other` is another DiffractionObject, the yarrays of the
186+ two DiffractionObjects will be combined element-wise. The result is a new DiffractionObject instance,
187+ representing the addition and using the xarray from the left-hand side DiffractionObject.
187188
188189 Returns
189190 -------
190191 DiffractionObject
191- The new and deep-copied DiffractionObject instance after adding values to the yarray.
192+ THe new DiffractionObject instance with modified yarray values. This instance is a deep copy of the
193+ original with the additions applied.
192194
193195 Raises
194196 ------
195197 ValueError
196- Raised when the length of the yarray of the two DiffractionObject instances do not match .
198+ Raised when the xarrays of two DiffractionObject instances are not equal .
197199 TypeError
198- Raised when the type of `other` is not an instance of DiffractionObject, int, or float.
200+ Raised when `other` is not an instance of DiffractionObject, int, or float.
199201
200202 Examples
201203 --------
202- Add a scalar value to the yarray of the DiffractionObject instance:
204+ Add a scalar value to the yarray of a DiffractionObject instance:
203205 >>> new_do = my_do + 10.1
204206 >>> new_do = 10.1 + my_do
205207
206- Add the yarray of two DiffractionObject instances:
208+ Combine the yarrays of two DiffractionObject instances:
207209 >>> new_do = my_do_1 + my_do_2
208210 """
209211
@@ -218,6 +220,21 @@ def __add__(self, other):
218220 __radd__ = __add__
219221
220222 def __sub__ (self , other ):
223+ """Subtract scalar value or another DiffractionObject to the yarray of
224+ the DiffractionObject.
225+
226+ This method behaves similarly to the `__add__` method, but performs subtraction instead of addition.
227+ For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
228+
229+ Examples
230+ --------
231+ Subtract a scalar value from the yarray of a DiffractionObject instance:
232+ >>> new_do = my_do - 10.1
233+
234+ Subtract the yarrays of two DiffractionObject instances:
235+ >>> new_do = my_do_1 - my_do_2
236+ """
237+
221238 self ._check_operation_compatibility (other )
222239 subtracted_do = deepcopy (self )
223240 if isinstance (other , (int , float )):
@@ -229,6 +246,21 @@ def __sub__(self, other):
229246 __rsub__ = __sub__
230247
231248 def __mul__ (self , other ):
249+ """Multiply a scalar value or another DiffractionObject with the yarray
250+ of this DiffractionObject.
251+
252+ This method behaves similarly to the `__add__` method, but performs multiplication instead of addition.
253+ For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
254+
255+ Examples
256+ --------
257+ Multiply a scalar value with the yarray of a DiffractionObject instance:
258+ >>> new_do = my_do * 3.5
259+
260+ Multiply the yarrays of two DiffractionObject instances:
261+ >>> new_do = my_do_1 * my_do_2
262+ """
263+
232264 self ._check_operation_compatibility (other )
233265 multiplied_do = deepcopy (self )
234266 if isinstance (other , (int , float )):
@@ -240,6 +272,20 @@ def __mul__(self, other):
240272 __rmul__ = __mul__
241273
242274 def __truediv__ (self , other ):
275+ """Divide the yarray of this DiffractionObject by a scalar value or
276+ another DiffractionObject.
277+
278+ This method behaves similarly to the `__add__` method, but performs division instead of addition.
279+ For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
280+
281+ Examples
282+ --------
283+ Divide the yarray of a DiffractionObject instance by a scalar value:
284+ >>> new_do = my_do / 2.0
285+
286+ Divide the yarrays of two DiffractionObject instances:
287+ >>> new_do = my_do_1 / my_do_2
288+ """
243289 self ._check_operation_compatibility (other )
244290 divided_do = deepcopy (self )
245291 if isinstance (other , (int , float )):
@@ -288,7 +334,7 @@ def input_xtype(self):
288334
289335 Returns
290336 -------
291- str
337+ input_xtype : str
292338 The type of `xarray`, which must be one of {*XQUANTITIES}.
293339 """
294340 return self ._input_xtype
@@ -303,7 +349,7 @@ def uuid(self):
303349
304350 Returns
305351 -------
306- uuid
352+ uuid : UUID
307353 The unique identifier of the DiffractionObject instance.
308354 """
309355 return self ._uuid
@@ -325,7 +371,7 @@ def get_array_index(self, xtype, xvalue):
325371
326372 Returns
327373 -------
328- int
374+ index : int
329375 The index of the closest value in the array associated with the specified xtype and the value provided.
330376 """
331377
@@ -378,7 +424,7 @@ def on_d(self):
378424 return [self .all_arrays [:, 3 ], self .all_arrays [:, 0 ]]
379425
380426 def scale_to (self , target_diff_object , q = None , tth = None , d = None , offset = None ):
381- """Returns a new diffraction object which is the current object but
427+ """Return a new diffraction object which is the current object but
382428 rescaled in y to the target.
383429
384430 By default, if `q`, `tth`, or `d` are not provided, scaling is based on the max intensity from each object.
@@ -400,12 +446,12 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
400446
401447 Returns
402448 -------
403- scaled : DiffractionObject
449+ scaled_do : DiffractionObject
404450 The rescaled DiffractionObject as a new object.
405451 """
406452 if offset is None :
407453 offset = 0
408- scaled = self .copy ()
454+ scaled_do = self .copy ()
409455 count = sum ([q is not None , tth is not None , d is not None ])
410456 if count > 1 :
411457 raise ValueError (
@@ -416,8 +462,8 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
416462 if count == 0 :
417463 q_target_max = max (target_diff_object .on_q ()[1 ])
418464 q_self_max = max (self .on_q ()[1 ])
419- scaled ._all_arrays [:, 0 ] = scaled ._all_arrays [:, 0 ] * q_target_max / q_self_max + offset
420- return scaled
465+ scaled_do ._all_arrays [:, 0 ] = scaled_do ._all_arrays [:, 0 ] * q_target_max / q_self_max + offset
466+ return scaled_do
421467
422468 xtype = "q" if q is not None else "tth" if tth is not None else "d"
423469 data = self .on_xtype (xtype )
@@ -427,21 +473,26 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
427473
428474 xindex_data = (np .abs (data [0 ] - xvalue )).argmin ()
429475 xindex_target = (np .abs (target [0 ] - xvalue )).argmin ()
430- scaled ._all_arrays [:, 0 ] = data [1 ] * target [1 ][xindex_target ] / data [1 ][xindex_data ] + offset
431- return scaled
476+ scaled_do ._all_arrays [:, 0 ] = data [1 ] * target [1 ][xindex_target ] / data [1 ][xindex_data ] + offset
477+ return scaled_do
432478
433479 def on_xtype (self , xtype ):
434- """Return a list of two 1D np array with x and y data, raise an error
435- if the specified xtype is invalid.
480+ """Return a tuple of two 1D numpy arrays containing x and y data.
436481
437482 Parameters
438483 ----------
439- xtype str
440- the type of quantity for the independent variable from {*XQUANTITIES, }
484+ xtype : str
485+ The type of quantity for the independent variable chosen from {*XQUANTITIES, }
486+
487+ Raises
488+ ------
489+ ValueError
490+ Raised when the specified xtype is not among {*XQUANTITIES, }
441491
442492 Returns
443493 -------
444- a list of two 1D np array with x and y data
494+ (xarray, yarray) : tuple of ndarray
495+ A tuple containing two 1D numpy arrays with x and y data for the specified xtype.
445496 """
446497 if xtype .lower () in ANGLEQUANTITIES :
447498 return self .on_tth ()
@@ -482,6 +533,6 @@ def copy(self):
482533 Returns
483534 -------
484535 DiffractionObject
485- A new instance of DiffractionObject, which is a deep copy of the current instance.
536+ The new instance of DiffractionObject, which is a deep copy of the current instance.
486537 """
487538 return deepcopy (self )
0 commit comments