Skip to content

Commit f4aebe8

Browse files
committedFeb 3, 2025·
style: apply manual line-shortening to files
1 parent e2f789c commit f4aebe8

14 files changed

+482
-269
lines changed
 

‎news/linelength79.rst

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* update isort, flake8 and black to set line limit to 79
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

‎src/diffpy/utils/diffraction_objects.py

+77-46
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@
3131
]
3232

3333
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."
3738
)
3839

3940
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"
4345
)
4446

4547

@@ -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"). Default
76+
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 string
82+
"".
7883
qmin : float
7984
The minimum q value.
8085
qmax : float
@@ -108,7 +113,8 @@ def __init__(
108113
yarray : ndarray
109114
The dependent variable array corresponding to intensity values.
110115
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}.
112118
wavelength : float, optional, default is None.
113119
The wavelength of the incoming beam, specified in angstroms (Å)
114120
scat_quantity : str, optional, default is an empty string "".
@@ -124,7 +130,7 @@ def __init__(
124130
>>> import numpy as np
125131
>>> from diffpy.utils.diffraction_objects import DiffractionObject
126132
...
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
128134
>>> y = np.array([10, 20, 40, 60]) # intensity values
129135
>>> metadata = {
130136
... "sample": "rock salt from the beach",
@@ -211,23 +217,29 @@ def __add__(self, other):
211217
Parameters
212218
----------
213219
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.
218227
219228
Returns
220229
-------
221230
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.
224234
225235
Raises
226236
------
227237
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.
229240
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.
231243
232244
Examples
233245
--------
@@ -253,12 +265,14 @@ def __sub__(self, other):
253265
"""Subtract scalar value or another DiffractionObject to the yarray of
254266
the DiffractionObject.
255267
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__`.
258271
259272
Examples
260273
--------
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:
262276
>>> new_do = my_do - 10.1
263277
264278
Subtract the yarrays of two DiffractionObject instances:
@@ -279,12 +293,14 @@ def __mul__(self, other):
279293
"""Multiply a scalar value or another DiffractionObject with the yarray
280294
of this DiffractionObject.
281295
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__`.
284299
285300
Examples
286301
--------
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:
288304
>>> new_do = my_do * 3.5
289305
290306
Multiply the yarrays of two DiffractionObject instances:
@@ -305,8 +321,9 @@ def __truediv__(self, other):
305321
"""Divide the yarray of this DiffractionObject by a scalar value or
306322
another DiffractionObject.
307323
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__`.
310327
311328
Examples
312329
--------
@@ -344,8 +361,8 @@ def all_arrays(self):
344361
Returns
345362
-------
346363
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.
349366
350367
Examples
351368
--------
@@ -399,21 +416,24 @@ def get_array_index(self, xtype, xvalue):
399416
Parameters
400417
----------
401418
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}.
403421
xvalue : float
404422
The value of the xtype to find the closest index for.
405423
406424
Returns
407425
-------
408426
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.
410429
"""
411430

412431
xtype = self._input_xtype
413432
xarray = self.on_xtype(xtype)[0]
414433
if len(xarray) == 0:
415434
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."
417437
)
418438
index = (np.abs(xarray - xvalue)).argmin()
419439
return index
@@ -486,19 +506,23 @@ def scale_to(
486506
"""Return a new diffraction object which is the current object but
487507
rescaled in y to the target.
488508
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.
493516
494517
Parameters
495518
----------
496519
target_diff_object: DiffractionObject
497520
The diffraction object you want to scale the current one onto.
498521
499522
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.
502526
503527
offset : float, optional, default is None
504528
The offset to add to the scaled y-values.
@@ -546,7 +570,8 @@ def on_xtype(self, xtype):
546570
Parameters
547571
----------
548572
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, }
550575
551576
Raises
552577
------
@@ -556,7 +581,8 @@ def on_xtype(self, xtype):
556581
Returns
557582
-------
558583
(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.
560586
"""
561587
if xtype.lower() in ANGLEQUANTITIES:
562588
return self.on_tth()
@@ -576,12 +602,13 @@ def dump(self, filepath, xtype=None):
576602
filepath : str
577603
The filepath where the diffraction object will be dumped
578604
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, }
580607
581608
Examples
582609
--------
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':
585612
586613
>>> file = "diffraction_data.chi"
587614
>>> do.dump(file, xtype="q")
@@ -591,7 +618,8 @@ def dump(self, filepath, xtype=None):
591618
>>> file = "./output/diffraction_data.chi"
592619
>>> do.dump(file, xtype="q")
593620
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':
595623
596624
>>> file = "diffraction_data_tth.chi"
597625
>>> do.dump(file, xtype="tth")
@@ -615,7 +643,9 @@ def dump(self, filepath, xtype=None):
615643

616644
with open(filepath, "w") as f:
617645
f.write(
618-
f"[DiffractionObject]\nname = {self.name}\nwavelength = {self.wavelength}\n"
646+
f"[DiffractionObject]\n"
647+
f"name = {self.name}\n"
648+
f"wavelength = {self.wavelength}\n"
619649
f"scat_quantity = {self.scat_quantity}\n"
620650
)
621651
for key, value in self.metadata.items():
@@ -629,6 +659,7 @@ def copy(self):
629659
Returns
630660
-------
631661
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.
633664
"""
634665
return deepcopy(self)

0 commit comments

Comments
 (0)
Please sign in to comment.