3131]
3232
3333x_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."
3738)
3839
3940invalid_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. "
4244 "e.g., my_do_1 + my_do_2 or my_do + 10 or 10 + my_do"
4345)
4446
@@ -70,11 +72,14 @@ class DiffractionObject:
7072 Attributes
7173 ----------
7274 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 "".
7477 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.
7680 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 "".
7883 qmin : float
7984 The minimum q value.
8085 qmax : float
@@ -104,11 +109,13 @@ def __init__(
104109 Parameters
105110 ----------
106111 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.
108114 yarray : ndarray
109115 The dependent variable array corresponding to intensity values.
110116 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}.
112119 wavelength : float, optional, default is None.
113120 The wavelength of the incoming beam, specified in angstroms (Å)
114121 scat_quantity : str, optional, default is an empty string "".
@@ -124,7 +131,8 @@ def __init__(
124131 >>> import numpy as np
125132 >>> from diffpy.utils.diffraction_objects import DiffractionObject
126133 ...
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])
128136 >>> y = np.array([10, 20, 40, 60]) # intensity values
129137 >>> metadata = {
130138 ... "sample": "rock salt from the beach",
@@ -211,23 +219,28 @@ def __add__(self, other):
211219 Parameters
212220 ----------
213221 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.
218228
219229 Returns
220230 -------
221231 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.
224235
225236 Raises
226237 ------
227238 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.
229241 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.
231244
232245 Examples
233246 --------
@@ -253,12 +266,14 @@ def __sub__(self, other):
253266 """Subtract scalar value or another DiffractionObject to the yarray of
254267 the DiffractionObject.
255268
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__`.
258272
259273 Examples
260274 --------
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:
262277 >>> new_do = my_do - 10.1
263278
264279 Subtract the yarrays of two DiffractionObject instances:
@@ -279,12 +294,14 @@ def __mul__(self, other):
279294 """Multiply a scalar value or another DiffractionObject with the yarray
280295 of this DiffractionObject.
281296
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__`.
284300
285301 Examples
286302 --------
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:
288305 >>> new_do = my_do * 3.5
289306
290307 Multiply the yarrays of two DiffractionObject instances:
@@ -305,8 +322,9 @@ def __truediv__(self, other):
305322 """Divide the yarray of this DiffractionObject by a scalar value or
306323 another DiffractionObject.
307324
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__`.
310328
311329 Examples
312330 --------
@@ -344,7 +362,8 @@ def all_arrays(self):
344362 Returns
345363 -------
346364 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)
348367 and the `xarray` values in q, tth, and d.
349368
350369 Examples
@@ -399,21 +418,26 @@ def get_array_index(self, xtype, xvalue):
399418 Parameters
400419 ----------
401420 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}.
403423 xvalue : float
404424 The value of the xtype to find the closest index for.
405425
406426 Returns
407427 -------
408428 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.
410431 """
411432
412433 xtype = self ._input_xtype
413434 xarray = self .on_xtype (xtype )[0 ]
414435 if len (xarray ) == 0 :
415436 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+ )
417441 )
418442 index = (np .abs (xarray - xvalue )).argmin ()
419443 return index
@@ -486,19 +510,22 @@ def scale_to(
486510 """Return a new diffraction object which is the current object but
487511 rescaled in y to the target.
488512
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.
493519
494520 Parameters
495521 ----------
496522 target_diff_object: DiffractionObject
497523 The diffraction object you want to scale the current one onto.
498524
499525 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.
502529
503530 offset : float, optional, default is None
504531 The offset to add to the scaled y-values.
@@ -546,7 +573,8 @@ def on_xtype(self, xtype):
546573 Parameters
547574 ----------
548575 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, }
550578
551579 Raises
552580 ------
@@ -556,7 +584,8 @@ def on_xtype(self, xtype):
556584 Returns
557585 -------
558586 (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.
560589 """
561590 if xtype .lower () in ANGLEQUANTITIES :
562591 return self .on_tth ()
@@ -576,12 +605,13 @@ def dump(self, filepath, xtype=None):
576605 filepath : str
577606 The filepath where the diffraction object will be dumped
578607 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, }
580610
581611 Examples
582612 --------
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':
585615
586616 >>> file = "diffraction_data.chi"
587617 >>> do.dump(file, xtype="q")
@@ -591,7 +621,8 @@ def dump(self, filepath, xtype=None):
591621 >>> file = "./output/diffraction_data.chi"
592622 >>> do.dump(file, xtype="q")
593623
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':
595626
596627 >>> file = "diffraction_data_tth.chi"
597628 >>> do.dump(file, xtype="tth")
@@ -615,7 +646,8 @@ def dump(self, filepath, xtype=None):
615646
616647 with open (filepath , "w" ) as f :
617648 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 "
619651 f"scat_quantity = { self .scat_quantity } \n "
620652 )
621653 for key , value in self .metadata .items ():
@@ -629,6 +661,7 @@ def copy(self):
629661 Returns
630662 -------
631663 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.
633666 """
634667 return deepcopy (self )
0 commit comments