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