@@ -92,18 +92,18 @@ def __init__(
92
92
The dependent variable array corresponding to intensity values.
93
93
xtype : str
94
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 {}.
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.
103
103
104
104
Examples
105
105
--------
106
- Create a DiffractionObject for X-ray scattering data
106
+ Create a DiffractionObject for X-ray scattering data:
107
107
>>> import numpy as np
108
108
>>> from diffpy.utils.diffraction_objects import DiffractionObject
109
109
...
@@ -180,30 +180,32 @@ def __add__(self, other):
180
180
181
181
Parameters
182
182
----------
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.
187
188
188
189
Returns
189
190
-------
190
191
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.
192
194
193
195
Raises
194
196
------
195
197
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 .
197
199
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.
199
201
200
202
Examples
201
203
--------
202
- Add a scalar value to the yarray of the DiffractionObject instance:
204
+ Add a scalar value to the yarray of a DiffractionObject instance:
203
205
>>> new_do = my_do + 10.1
204
206
>>> new_do = 10.1 + my_do
205
207
206
- Add the yarray of two DiffractionObject instances:
208
+ Combine the yarrays of two DiffractionObject instances:
207
209
>>> new_do = my_do_1 + my_do_2
208
210
"""
209
211
@@ -218,6 +220,21 @@ def __add__(self, other):
218
220
__radd__ = __add__
219
221
220
222
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
+
221
238
self ._check_operation_compatibility (other )
222
239
subtracted_do = deepcopy (self )
223
240
if isinstance (other , (int , float )):
@@ -229,6 +246,21 @@ def __sub__(self, other):
229
246
__rsub__ = __sub__
230
247
231
248
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
+
232
264
self ._check_operation_compatibility (other )
233
265
multiplied_do = deepcopy (self )
234
266
if isinstance (other , (int , float )):
@@ -240,6 +272,20 @@ def __mul__(self, other):
240
272
__rmul__ = __mul__
241
273
242
274
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
+ """
243
289
self ._check_operation_compatibility (other )
244
290
divided_do = deepcopy (self )
245
291
if isinstance (other , (int , float )):
@@ -288,7 +334,7 @@ def input_xtype(self):
288
334
289
335
Returns
290
336
-------
291
- str
337
+ input_xtype : str
292
338
The type of `xarray`, which must be one of {*XQUANTITIES}.
293
339
"""
294
340
return self ._input_xtype
@@ -303,7 +349,7 @@ def uuid(self):
303
349
304
350
Returns
305
351
-------
306
- uuid
352
+ uuid : UUID
307
353
The unique identifier of the DiffractionObject instance.
308
354
"""
309
355
return self ._uuid
@@ -325,7 +371,7 @@ def get_array_index(self, xtype, xvalue):
325
371
326
372
Returns
327
373
-------
328
- int
374
+ index : int
329
375
The index of the closest value in the array associated with the specified xtype and the value provided.
330
376
"""
331
377
@@ -378,7 +424,7 @@ def on_d(self):
378
424
return [self .all_arrays [:, 3 ], self .all_arrays [:, 0 ]]
379
425
380
426
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
382
428
rescaled in y to the target.
383
429
384
430
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):
400
446
401
447
Returns
402
448
-------
403
- scaled : DiffractionObject
449
+ scaled_do : DiffractionObject
404
450
The rescaled DiffractionObject as a new object.
405
451
"""
406
452
if offset is None :
407
453
offset = 0
408
- scaled = self .copy ()
454
+ scaled_do = self .copy ()
409
455
count = sum ([q is not None , tth is not None , d is not None ])
410
456
if count > 1 :
411
457
raise ValueError (
@@ -416,8 +462,8 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
416
462
if count == 0 :
417
463
q_target_max = max (target_diff_object .on_q ()[1 ])
418
464
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
421
467
422
468
xtype = "q" if q is not None else "tth" if tth is not None else "d"
423
469
data = self .on_xtype (xtype )
@@ -427,21 +473,26 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
427
473
428
474
xindex_data = (np .abs (data [0 ] - xvalue )).argmin ()
429
475
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
432
478
433
479
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.
436
481
437
482
Parameters
438
483
----------
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, }
441
491
442
492
Returns
443
493
-------
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.
445
496
"""
446
497
if xtype .lower () in ANGLEQUANTITIES :
447
498
return self .on_tth ()
@@ -482,6 +533,6 @@ def copy(self):
482
533
Returns
483
534
-------
484
535
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.
486
537
"""
487
538
return deepcopy (self )
0 commit comments