Skip to content

Commit e2f789c

Browse files
committed
style: apply black and flake8 to all files in the project
1 parent 62525fd commit e2f789c

14 files changed

+585
-143
lines changed

Diff for: doc/source/conf.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,13 @@
221221
# (source start file, target name, title,
222222
# author, documentclass [howto, manual, or own class]).
223223
latex_documents = [
224-
("index", "diffpy.utils.tex", "diffpy.utils Documentation", ab_authors, "manual"),
224+
(
225+
"index",
226+
"diffpy.utils.tex",
227+
"diffpy.utils Documentation",
228+
ab_authors,
229+
"manual",
230+
),
225231
]
226232

227233
# The name of an image file (relative to this directory) to place at the top of
@@ -249,7 +255,9 @@
249255

250256
# One entry per manual page. List of tuples
251257
# (source start file, name, description, authors, manual section).
252-
man_pages = [("index", "diffpy.utils", "diffpy.utils Documentation", ab_authors, 1)]
258+
man_pages = [
259+
("index", "diffpy.utils", "diffpy.utils Documentation", ab_authors, 1)
260+
]
253261

254262
# If true, show URL addresses after external links.
255263
# man_show_urls = False

Diff for: src/diffpy/utils/diffraction_objects.py

+59-15
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,29 @@
66
import numpy as np
77

88
from diffpy.utils.tools import get_package_info
9-
from diffpy.utils.transforms import d_to_q, d_to_tth, q_to_d, q_to_tth, tth_to_d, tth_to_q
9+
from diffpy.utils.transforms import (
10+
d_to_q,
11+
d_to_tth,
12+
q_to_d,
13+
q_to_tth,
14+
tth_to_d,
15+
tth_to_q,
16+
)
1017

1118
QQUANTITIES = ["q"]
1219
ANGLEQUANTITIES = ["angle", "tth", "twotheta", "2theta"]
1320
DQUANTITIES = ["d", "dspace"]
1421
XQUANTITIES = ANGLEQUANTITIES + DQUANTITIES + QQUANTITIES
15-
XUNITS = ["degrees", "radians", "rad", "deg", "inv_angs", "inv_nm", "nm-1", "A-1"]
22+
XUNITS = [
23+
"degrees",
24+
"radians",
25+
"rad",
26+
"deg",
27+
"inv_angs",
28+
"inv_nm",
29+
"nm-1",
30+
"A-1",
31+
]
1632

1733
x_values_not_equal_emsg = (
1834
"The two objects have different values in x arrays (my_do.all_arrays[:, [1, 2, 3]]). "
@@ -129,9 +145,13 @@ def __init__(
129145
"""
130146

131147
self._uuid = uuid.uuid4()
132-
self._input_data(xarray, yarray, xtype, wavelength, scat_quantity, name, metadata)
148+
self._input_data(
149+
xarray, yarray, xtype, wavelength, scat_quantity, name, metadata
150+
)
133151

134-
def _input_data(self, xarray, yarray, xtype, wavelength, scat_quantity, name, metadata):
152+
def _input_data(
153+
self, xarray, yarray, xtype, wavelength, scat_quantity, name, metadata
154+
):
135155
if xtype not in XQUANTITIES:
136156
raise ValueError(_xtype_wmsg(xtype))
137157
if len(xarray) != len(yarray):
@@ -152,8 +172,12 @@ def _input_data(self, xarray, yarray, xtype, wavelength, scat_quantity, name, me
152172
def __eq__(self, other):
153173
if not isinstance(other, DiffractionObject):
154174
return NotImplemented
155-
self_attributes = [key for key in self.__dict__ if not key.startswith("_")]
156-
other_attributes = [key for key in other.__dict__ if not key.startswith("_")]
175+
self_attributes = [
176+
key for key in self.__dict__ if not key.startswith("_")
177+
]
178+
other_attributes = [
179+
key for key in other.__dict__ if not key.startswith("_")
180+
]
157181
if not sorted(self_attributes) == sorted(other_attributes):
158182
return False
159183
for key in self_attributes:
@@ -167,8 +191,13 @@ def __eq__(self, other):
167191
or not np.isclose(value, other_value, rtol=1e-5)
168192
):
169193
return False
170-
elif isinstance(value, list) and all(isinstance(i, np.ndarray) for i in value):
171-
if not all(np.allclose(i, j, rtol=1e-5) for i, j in zip(value, other_value)):
194+
elif isinstance(value, list) and all(
195+
isinstance(i, np.ndarray) for i in value
196+
):
197+
if not all(
198+
np.allclose(i, j, rtol=1e-5)
199+
for i, j in zip(value, other_value)
200+
):
172201
return False
173202
else:
174203
if value != other_value:
@@ -303,7 +332,9 @@ def _check_operation_compatibility(self, other):
303332
if isinstance(other, DiffractionObject):
304333
if self.all_arrays.shape != other.all_arrays.shape:
305334
raise ValueError(x_values_not_equal_emsg)
306-
if not np.allclose(self.all_arrays[:, [1, 2, 3]], other.all_arrays[:, [1, 2, 3]]):
335+
if not np.allclose(
336+
self.all_arrays[:, [1, 2, 3]], other.all_arrays[:, [1, 2, 3]]
337+
):
307338
raise ValueError(x_values_not_equal_emsg)
308339

309340
@property
@@ -381,7 +412,9 @@ def get_array_index(self, xtype, xvalue):
381412
xtype = self._input_xtype
382413
xarray = self.on_xtype(xtype)[0]
383414
if len(xarray) == 0:
384-
raise ValueError(f"The '{xtype}' array is empty. Please ensure it is initialized.")
415+
raise ValueError(
416+
f"The '{xtype}' array is empty. Please ensure it is initialized."
417+
)
385418
index = (np.abs(xarray - xvalue)).argmin()
386419
return index
387420

@@ -447,7 +480,9 @@ def on_d(self):
447480
"""
448481
return [self.all_arrays[:, 3], self.all_arrays[:, 0]]
449482

450-
def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
483+
def scale_to(
484+
self, target_diff_object, q=None, tth=None, d=None, offset=None
485+
):
451486
"""Return a new diffraction object which is the current object but
452487
rescaled in y to the target.
453488
@@ -486,7 +521,10 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
486521
if count == 0:
487522
q_target_max = max(target_diff_object.on_q()[1])
488523
q_self_max = max(self.on_q()[1])
489-
scaled_do._all_arrays[:, 0] = scaled_do._all_arrays[:, 0] * q_target_max / q_self_max + offset
524+
scaled_do._all_arrays[:, 0] = (
525+
scaled_do._all_arrays[:, 0] * q_target_max / q_self_max
526+
+ offset
527+
)
490528
return scaled_do
491529

492530
xtype = "q" if q is not None else "tth" if tth is not None else "d"
@@ -497,7 +535,9 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
497535

498536
xindex_data = (np.abs(data[0] - xvalue)).argmin()
499537
xindex_target = (np.abs(target[0] - xvalue)).argmin()
500-
scaled_do._all_arrays[:, 0] = data[1] * target[1][xindex_target] / data[1][xindex_data] + offset
538+
scaled_do._all_arrays[:, 0] = (
539+
data[1] * target[1][xindex_target] / data[1][xindex_data] + offset
540+
)
501541
return scaled_do
502542

503543
def on_xtype(self, xtype):
@@ -561,12 +601,16 @@ def dump(self, filepath, xtype=None):
561601
if xtype in QQUANTITIES:
562602
data_to_save = np.column_stack((self.on_q()[0], self.on_q()[1]))
563603
elif xtype in ANGLEQUANTITIES:
564-
data_to_save = np.column_stack((self.on_tth()[0], self.on_tth()[1]))
604+
data_to_save = np.column_stack(
605+
(self.on_tth()[0], self.on_tth()[1])
606+
)
565607
elif xtype in DQUANTITIES:
566608
data_to_save = np.column_stack((self.on_d()[0], self.on_d()[1]))
567609
else:
568610
warnings.warn(_xtype_wmsg(xtype))
569-
self.metadata.update(get_package_info("diffpy.utils", metadata=self.metadata))
611+
self.metadata.update(
612+
get_package_info("diffpy.utils", metadata=self.metadata)
613+
)
570614
self.metadata["creation_time"] = datetime.datetime.now()
571615

572616
with open(filepath, "w") as f:

Diff for: src/diffpy/utils/parsers/custom_exceptions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,7 @@ class ImproperSizeError(Exception):
5151

5252
def __init__(self, bad_object, message=None):
5353
if message is None:
54-
self.message = f"The size of {bad_object} is different than expected."
54+
self.message = (
55+
f"The size of {bad_object} is different than expected."
56+
)
5557
super().__init__(self.message)

Diff for: src/diffpy/utils/parsers/loaddata.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
from diffpy.utils import validators
2121

2222

23-
def loadData(filename, minrows=10, headers=False, hdel="=", hignore=None, **kwargs):
23+
def loadData(
24+
filename, minrows=10, headers=False, hdel="=", hignore=None, **kwargs
25+
):
2426
"""Find and load data from a text file.
2527
2628
The data block is identified as the first matrix block of at least minrows rows and constant number of columns.
@@ -105,7 +107,9 @@ def countcolumnsvalues(line):
105107

106108
# Check if file exists before trying to open
107109
if not os.path.exists(filename):
108-
raise IOError(f"File {filename} cannot be found. Please rerun the program specifying a valid filename.")
110+
raise IOError(
111+
f"File {filename} cannot be found. Please rerun the program specifying a valid filename."
112+
)
109113

110114
# make sure fid gets cleaned up
111115
with open(filename, "rb") as fid:
@@ -134,7 +138,10 @@ def countcolumnsvalues(line):
134138
if hignore is not None:
135139
for tag in hignore:
136140
taglen = len(tag)
137-
if len(hpair[0]) >= taglen and hpair[0][:taglen] == tag:
141+
if (
142+
len(hpair[0]) >= taglen
143+
and hpair[0][:taglen] == tag
144+
):
138145
flag = False
139146
# add header data
140147
if flag:
@@ -258,7 +265,13 @@ def _findDataBlocks(self):
258265
# nf - number of words, ok - has data
259266
self._linerecs = numpy.recarray(
260267
(nlines,),
261-
dtype=[("idx", int), ("nw0", int), ("nw1", int), ("nf", int), ("ok", bool)],
268+
dtype=[
269+
("idx", int),
270+
("nw0", int),
271+
("nw1", int),
272+
("nf", int),
273+
("ok", bool),
274+
],
262275
)
263276
lr = self._linerecs
264277
lr.idx = numpy.arange(nlines)
@@ -319,7 +332,9 @@ def _findDataBlocks(self):
319332
if self.usecols is None:
320333
data = numpy.reshape(lw.value[bb1.nw0 : ee1.nw1], (-1, bb1.nf))
321334
else:
322-
tdata = numpy.empty((len(self.usecols), dend - dbeg), dtype=float)
335+
tdata = numpy.empty(
336+
(len(self.usecols), dend - dbeg), dtype=float
337+
)
323338
for j, trow in zip(self.usecols, tdata):
324339
j %= bb1.nf
325340
trow[:] = lw.value[bb1.nw0 + j : ee1.nw1 : bb1.nf]

Diff for: src/diffpy/utils/parsers/serialization.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ def serialize_data(
8686
num_columns = [len(row) for row in data_table]
8787
max_columns = max(num_columns)
8888
num_col_names = len(dt_colnames)
89-
if max_columns < num_col_names: # assume numpy.loadtxt gives non-irregular array
90-
raise ImproperSizeError("More entries in dt_colnames than columns in data_table.")
89+
if (
90+
max_columns < num_col_names
91+
): # assume numpy.loadtxt gives non-irregular array
92+
raise ImproperSizeError(
93+
"More entries in dt_colnames than columns in data_table."
94+
)
9195
named_columns = 0
9296
for idx in range(num_col_names):
9397
colname = dt_colnames[idx]

0 commit comments

Comments
 (0)