31
31
]
32
32
33
33
x_values_not_equal_emsg = (
34
- "The two objects have different values in x arrays (my_do.all_arrays[:, [1, 2, 3]]). "
35
- "Please ensure the x values of the two objects are identical by re-instantiating "
36
- "the DiffractionObject with the correct x value inputs."
34
+ "The two objects have different values in x arrays "
35
+ "my_do.all_arrays[:, [1, 2, 3]]). Please ensure the x values of the two "
36
+ "objects are identical by re-instantiating the DiffractionObject with the "
37
+ "correct x value inputs."
37
38
)
38
39
39
40
invalid_add_type_emsg = (
40
- "You may only add a DiffractionObject with another DiffractionObject or a scalar value. "
41
- "Please rerun by adding another DiffractionObject instance or a scalar value. "
41
+ "You may only add a DiffractionObject with another DiffractionObject or a"
42
+ "scalar value. Please rerun by adding another DiffractionObject or "
43
+ "a scalar value. "
42
44
"e.g., my_do_1 + my_do_2 or my_do + 10 or 10 + my_do"
43
45
)
44
46
@@ -70,11 +72,14 @@ class DiffractionObject:
70
72
Attributes
71
73
----------
72
74
scat_quantity : str
73
- The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
75
+ The type of scattering experiment (e.g., "x-ray", "neutron").
76
+ Default is an empty string "".
74
77
wavelength : float
75
- The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
78
+ The wavelength of the incoming beam, specified in angstroms (Å).
79
+ Default is none.
76
80
name: str
77
- The name or label for the scattering data. Default is an empty string "".
81
+ The name or label for the scattering data. Default is an empty
82
+ string "".
78
83
qmin : float
79
84
The minimum q value.
80
85
qmax : float
@@ -104,11 +109,13 @@ def __init__(
104
109
Parameters
105
110
----------
106
111
xarray : ndarray
107
- The independent variable array containing "q", "tth", or "d" values.
112
+ The independent variable array containing "q", "tth", or "d"
113
+ values.
108
114
yarray : ndarray
109
115
The dependent variable array corresponding to intensity values.
110
116
xtype : str
111
- The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
117
+ The type of the independent variable in `xarray`.
118
+ Must be one of {*XQUANTITIES}.
112
119
wavelength : float, optional, default is None.
113
120
The wavelength of the incoming beam, specified in angstroms (Å)
114
121
scat_quantity : str, optional, default is an empty string "".
@@ -124,7 +131,8 @@ def __init__(
124
131
>>> import numpy as np
125
132
>>> from diffpy.utils.diffraction_objects import DiffractionObject
126
133
...
127
- >>> x = np.array([0.12, 0.24, 0.31, 0.4]) # independent variable (e.g., q)
134
+ >>> # independent variable (e.g., q)
135
+ >>> x = np.array([0.12, 0.24, 0.31, 0.4])
128
136
>>> y = np.array([10, 20, 40, 60]) # intensity values
129
137
>>> metadata = {
130
138
... "sample": "rock salt from the beach",
@@ -211,23 +219,28 @@ def __add__(self, other):
211
219
Parameters
212
220
----------
213
221
other : DiffractionObject, int, or float
214
- The item to be added. If `other` is a scalar value, this value will be added to each element of the
215
- yarray of this DiffractionObject instance. If `other` is another DiffractionObject, the yarrays of the
216
- two DiffractionObjects will be combined element-wise. The result is a new DiffractionObject instance,
217
- representing the addition and using the xarray from the left-hand side DiffractionObject.
222
+ The item to be added. If `other` is a scalar value, this value will
223
+ be added to each element of the yarray of this DiffractionObject
224
+ instance. If `other` is another DiffractionObject, the yarrays of
225
+ the two DiffractionObjects will be combined element-wise.The result
226
+ is a new DiffractionObject instance,representing the addition and
227
+ using the xarray from the left-hand side DiffractionObject.
218
228
219
229
Returns
220
230
-------
221
231
DiffractionObject
222
- The new DiffractionObject instance with modified yarray values. This instance is a deep copy of the
223
- original with the additions applied.
232
+ The new DiffractionObject instance with modified yarray values.
233
+ This instance is a deep copy of the original with the additions
234
+ applied.
224
235
225
236
Raises
226
237
------
227
238
ValueError
228
- Raised when the xarrays of two DiffractionObject instances are not equal.
239
+ Raised when the xarrays of two DiffractionObject instances are not
240
+ equal.
229
241
TypeError
230
- Raised when `other` is not an instance of DiffractionObject, int, or float.
242
+ Raised when `other` is not an instance of DiffractionObject, int,
243
+ or float.
231
244
232
245
Examples
233
246
--------
@@ -253,12 +266,14 @@ def __sub__(self, other):
253
266
"""Subtract scalar value or another DiffractionObject to the yarray of
254
267
the DiffractionObject.
255
268
256
- This method behaves similarly to the `__add__` method, but performs subtraction instead of addition.
257
- For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
269
+ This method behaves similarly to the `__add__` method, but performs
270
+ subtraction instead of addition.For details on parameters, returns, and
271
+ exceptions, refer to the documentation for `__add__`.
258
272
259
273
Examples
260
274
--------
261
- Subtract a scalar value from the yarray of a DiffractionObject instance:
275
+ Subtract a scalar value from the yarray of a DiffractionObject
276
+ instance:
262
277
>>> new_do = my_do - 10.1
263
278
264
279
Subtract the yarrays of two DiffractionObject instances:
@@ -279,12 +294,14 @@ def __mul__(self, other):
279
294
"""Multiply a scalar value or another DiffractionObject with the yarray
280
295
of this DiffractionObject.
281
296
282
- This method behaves similarly to the `__add__` method, but performs multiplication instead of addition.
283
- For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
297
+ This method behaves similarly to the `__add__` method, but performs
298
+ multiplication instead of addition. For details on parameters, returns,
299
+ and exceptions, refer to the documentation for `__add__`.
284
300
285
301
Examples
286
302
--------
287
- Multiply a scalar value with the yarray of a DiffractionObject instance:
303
+ Multiply a scalar value with the yarray of a DiffractionObject
304
+ instance:
288
305
>>> new_do = my_do * 3.5
289
306
290
307
Multiply the yarrays of two DiffractionObject instances:
@@ -305,8 +322,9 @@ def __truediv__(self, other):
305
322
"""Divide the yarray of this DiffractionObject by a scalar value or
306
323
another DiffractionObject.
307
324
308
- This method behaves similarly to the `__add__` method, but performs division instead of addition.
309
- For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
325
+ This method behaves similarly to the `__add__` method, but performs
326
+ division instead of addition.For details on parameters, returns, and
327
+ exceptions, refer to the documentation for `__add__`.
310
328
311
329
Examples
312
330
--------
@@ -344,7 +362,8 @@ def all_arrays(self):
344
362
Returns
345
363
-------
346
364
ndarray
347
- The shape (len(data), 4) 2D array with columns containing the `yarray` (intensity)
365
+ The shape (len(data), 4) 2D array with columns containing the
366
+ `yarray` (intensity)
348
367
and the `xarray` values in q, tth, and d.
349
368
350
369
Examples
@@ -399,21 +418,26 @@ def get_array_index(self, xtype, xvalue):
399
418
Parameters
400
419
----------
401
420
xtype : str
402
- The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
421
+ The type of the independent variable in `xarray`. Must be one of
422
+ {*XQUANTITIES}.
403
423
xvalue : float
404
424
The value of the xtype to find the closest index for.
405
425
406
426
Returns
407
427
-------
408
428
index : int
409
- The index of the closest value in the array associated with the specified xtype and the value provided.
429
+ The index of the closest value in the array associated with the
430
+ specified xtype and the value provided.
410
431
"""
411
432
412
433
xtype = self ._input_xtype
413
434
xarray = self .on_xtype (xtype )[0 ]
414
435
if len (xarray ) == 0 :
415
436
raise ValueError (
416
- f"The '{ xtype } ' array is empty. Please ensure it is initialized."
437
+ (
438
+ f"The '{ xtype } ' array is empty. "
439
+ f"Please ensure it is initialized."
440
+ )
417
441
)
418
442
index = (np .abs (xarray - xvalue )).argmin ()
419
443
return index
@@ -486,19 +510,22 @@ def scale_to(
486
510
"""Return a new diffraction object which is the current object but
487
511
rescaled in y to the target.
488
512
489
- By default, if `q`, `tth`, or `d` are not provided, scaling is based on the max intensity from each object.
490
- Otherwise, y-value in the target at the closest specified x-value will be used as the factor to scale to.
491
- The entire array is scaled by this factor so that one object places on top of the other at that point.
492
- If multiple values of `q`, `tth`, or `d` are provided, an error will be raised.
513
+ By default, if `q`, `tth`, or `d` are not provided, scaling is based on
514
+ the max intensity from each object. Otherwise, y-value in the target at
515
+ the closest specified x-value will be used as the factor to scale to.
516
+ The entire array is scaled by this factor so that one object places on
517
+ top of the other at that point.If multiple values of `q`, `tth`, or `d`
518
+ are provided, an error will be raised.
493
519
494
520
Parameters
495
521
----------
496
522
target_diff_object: DiffractionObject
497
523
The diffraction object you want to scale the current one onto.
498
524
499
525
q, tth, d : float, optional, default is None
500
- The value of the x-array where you want the curves to line up vertically.
501
- Specify a value on one of the allowed grids, q, tth, or d), e.g., q=10.
526
+ The value of the x-array where you want the curves to line up
527
+ vertically. Specify a value on one of the allowed grids, q, tth,
528
+ or d), e.g., q=10.
502
529
503
530
offset : float, optional, default is None
504
531
The offset to add to the scaled y-values.
@@ -546,7 +573,8 @@ def on_xtype(self, xtype):
546
573
Parameters
547
574
----------
548
575
xtype : str
549
- The type of quantity for the independent variable chosen from {*XQUANTITIES, }
576
+ The type of quantity for the independent variable chosen from
577
+ {*XQUANTITIES, }
550
578
551
579
Raises
552
580
------
@@ -556,7 +584,8 @@ def on_xtype(self, xtype):
556
584
Returns
557
585
-------
558
586
(xarray, yarray) : tuple of ndarray
559
- The tuple containing two 1D numpy arrays with x and y data for the specified xtype.
587
+ The tuple containing two 1D numpy arrays with x and y data for the
588
+ specified xtype.
560
589
"""
561
590
if xtype .lower () in ANGLEQUANTITIES :
562
591
return self .on_tth ()
@@ -576,12 +605,13 @@ def dump(self, filepath, xtype=None):
576
605
filepath : str
577
606
The filepath where the diffraction object will be dumped
578
607
xtype : str, optional, default is q
579
- The type of quantity for the independent variable chosen from {*XQUANTITIES, }
608
+ The type of quantity for the independent variable chosen from
609
+ {*XQUANTITIES, }
580
610
581
611
Examples
582
612
--------
583
- To save a diffraction object to a file named "diffraction_data.chi" in the current directory
584
- with the independent variable 'q':
613
+ To save a diffraction object to a file named "diffraction_data.chi" in
614
+ the current directory with the independent variable 'q':
585
615
586
616
>>> file = "diffraction_data.chi"
587
617
>>> do.dump(file, xtype="q")
@@ -591,7 +621,8 @@ def dump(self, filepath, xtype=None):
591
621
>>> file = "./output/diffraction_data.chi"
592
622
>>> do.dump(file, xtype="q")
593
623
594
- To save the diffraction data with a different independent variable, such as 'tth':
624
+ To save the diffraction data with a different independent variable,
625
+ such as 'tth':
595
626
596
627
>>> file = "diffraction_data_tth.chi"
597
628
>>> do.dump(file, xtype="tth")
@@ -615,7 +646,8 @@ def dump(self, filepath, xtype=None):
615
646
616
647
with open (filepath , "w" ) as f :
617
648
f .write (
618
- f"[DiffractionObject]\n name = { self .name } \n wavelength = { self .wavelength } \n "
649
+ f"[DiffractionObject]\n name = { self .name } \n "
650
+ f"wavelength = { self .wavelength } \n "
619
651
f"scat_quantity = { self .scat_quantity } \n "
620
652
)
621
653
for key , value in self .metadata .items ():
@@ -629,6 +661,7 @@ def copy(self):
629
661
Returns
630
662
-------
631
663
DiffractionObject
632
- The new instance of DiffractionObject, which is a deep copy of the current instance.
664
+ The new instance of DiffractionObject, which is a deep copy of the
665
+ current instance.
633
666
"""
634
667
return deepcopy (self )
0 commit comments