Skip to content

Commit 3b662ec

Browse files
committed
style: apply black to all files in the project
1 parent 6fe6ef7 commit 3b662ec

29 files changed

+549
-146
lines changed

doc/source/conf.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,13 @@
223223
# (source start file, target name, title,
224224
# author, documentclass [howto, manual, or own class]).
225225
latex_documents = [
226-
("index", "diffpy.pdfmorph.tex", "diffpy.pdfmorph Documentation", ab_authors, "manual"),
226+
(
227+
"index",
228+
"diffpy.pdfmorph.tex",
229+
"diffpy.pdfmorph Documentation",
230+
ab_authors,
231+
"manual",
232+
),
227233
]
228234

229235
# The name of an image file (relative to this directory) to place at the top of
@@ -251,7 +257,15 @@
251257

252258
# One entry per manual page. List of tuples
253259
# (source start file, name, description, authors, manual section).
254-
man_pages = [("index", "diffpy.pdfmorph", "diffpy.pdfmorph Documentation", ab_authors, 1)]
260+
man_pages = [
261+
(
262+
"index",
263+
"diffpy.pdfmorph",
264+
"diffpy.pdfmorph Documentation",
265+
ab_authors,
266+
1,
267+
)
268+
]
255269

256270
# If true, show URL addresses after external links.
257271
# man_show_urls = False

src/diffpy/pdfmorph/morph_helpers/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313

1414
"""List of helpers for certain morphing operations (currently only used for smear)."""
1515

16-
from diffpy.pdfmorph.morph_helpers.transformpdftordf import TransformXtalPDFtoRDF
17-
from diffpy.pdfmorph.morph_helpers.transformrdftopdf import TransformXtalRDFtoPDF
16+
from diffpy.pdfmorph.morph_helpers.transformpdftordf import (
17+
TransformXtalPDFtoRDF,
18+
)
19+
from diffpy.pdfmorph.morph_helpers.transformrdftopdf import (
20+
TransformXtalRDFtoPDF,
21+
)
1822

1923
# List of helpers
2024
morph_helpers = [

src/diffpy/pdfmorph/morph_helpers/transformpdftordf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def morph(self, x_morph, y_morph, x_target, y_target):
5151
morph_baseline = self.baselineslope * self.x_morph_in
5252
self.y_morph_out = self.x_morph_in * (self.y_morph_in - morph_baseline)
5353
target_baseline = self.baselineslope * self.x_target_in
54-
self.y_target_out = self.x_target_in * (self.y_target_in - target_baseline)
54+
self.y_target_out = self.x_target_in * (
55+
self.y_target_in - target_baseline
56+
)
5557
return self.xyallout
5658

5759

src/diffpy/pdfmorph/morph_helpers/transformrdftopdf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ def morph(self, x_morph, y_morph, x_target, y_target):
5353
morph_baseline = self.baselineslope * self.x_morph_in
5454
target_baseline = self.baselineslope * self.x_target_in
5555
with numpy.errstate(divide="ignore", invalid="ignore"):
56-
self.y_target_out = self.y_target_in / self.x_target_in + target_baseline
56+
self.y_target_out = (
57+
self.y_target_in / self.x_target_in + target_baseline
58+
)
5759
self.y_target_out[self.x_target_in == 0] = 0
5860
with numpy.errstate(divide="ignore", invalid="ignore"):
59-
self.y_morph_out = self.y_morph_in / self.x_morph_in + morph_baseline
61+
self.y_morph_out = (
62+
self.y_morph_in / self.x_morph_in + morph_baseline
63+
)
6064
self.y_morph_out[self.x_target_in == 0] = 0
6165
return self.xyallout
6266

src/diffpy/pdfmorph/morphs/morph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ def plotOutputs(self, xylabels=True, **plotargs):
234234

235235
pargs = dict(plotargs)
236236
pargs.pop("label", None)
237-
rv = plot(self.x_target_out, self.y_target_out, label="target", **pargs)
237+
rv = plot(
238+
self.x_target_out, self.y_target_out, label="target", **pargs
239+
)
238240
rv = plot(self.x_morph_out, self.y_morph_out, label="morph", **pargs)
239241
if xylabels:
240242
xlabel(self.xoutlabel)

src/diffpy/pdfmorph/morphs/morphchain.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,47 @@ class MorphChain(list):
6666
The properties return tuples of None if there are no morphs.
6767
"""
6868

69-
x_morph_in = property(lambda self: None if len(self) == 0 else self[0].x_morph_in)
70-
y_morph_in = property(lambda self: None if len(self) == 0 else self[0].y_morph_in)
71-
x_target_in = property(lambda self: None if len(self) == 0 else self[0].x_target_in)
72-
y_target_in = property(lambda self: None if len(self) == 0 else self[0].y_target_in)
73-
x_morph_out = property(lambda self: None if len(self) == 0 else self[-1].x_morph_out)
74-
y_morph_out = property(lambda self: None if len(self) == 0 else self[-1].y_morph_out)
75-
x_target_out = property(lambda self: None if len(self) == 0 else self[-1].x_target_out)
76-
y_target_out = property(lambda self: None if len(self) == 0 else self[-1].y_target_out)
77-
xy_morph_in = property(lambda self: (None, None) if len(self) == 0 else self[0].xy_morph_in)
78-
xy_morph_out = property(lambda self: (None, None) if len(self) == 0 else self[-1].xy_morph_out)
79-
xy_target_in = property(lambda self: (None, None) if len(self) == 0 else self[0].xy_target_in)
80-
xy_target_out = property(lambda self: (None, None) if len(self) == 0 else self[-1].xy_target_out)
81-
xyallout = property(lambda self: (None, None, None, None) if len(self) == 0 else self[-1].xyallout)
69+
x_morph_in = property(
70+
lambda self: None if len(self) == 0 else self[0].x_morph_in
71+
)
72+
y_morph_in = property(
73+
lambda self: None if len(self) == 0 else self[0].y_morph_in
74+
)
75+
x_target_in = property(
76+
lambda self: None if len(self) == 0 else self[0].x_target_in
77+
)
78+
y_target_in = property(
79+
lambda self: None if len(self) == 0 else self[0].y_target_in
80+
)
81+
x_morph_out = property(
82+
lambda self: None if len(self) == 0 else self[-1].x_morph_out
83+
)
84+
y_morph_out = property(
85+
lambda self: None if len(self) == 0 else self[-1].y_morph_out
86+
)
87+
x_target_out = property(
88+
lambda self: None if len(self) == 0 else self[-1].x_target_out
89+
)
90+
y_target_out = property(
91+
lambda self: None if len(self) == 0 else self[-1].y_target_out
92+
)
93+
xy_morph_in = property(
94+
lambda self: (None, None) if len(self) == 0 else self[0].xy_morph_in
95+
)
96+
xy_morph_out = property(
97+
lambda self: (None, None) if len(self) == 0 else self[-1].xy_morph_out
98+
)
99+
xy_target_in = property(
100+
lambda self: (None, None) if len(self) == 0 else self[0].xy_target_in
101+
)
102+
xy_target_out = property(
103+
lambda self: (None, None) if len(self) == 0 else self[-1].xy_target_out
104+
)
105+
xyallout = property(
106+
lambda self: (
107+
(None, None, None, None) if len(self) == 0 else self[-1].xyallout
108+
)
109+
)
82110
parnames = property(lambda self: set(p for m in self for p in m.parnames))
83111

84112
def __init__(self, config, *args):

src/diffpy/pdfmorph/morphs/morphrgrid.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,27 @@ def morph(self, x_morph, y_morph, x_target, y_target):
6363
r_step_target = self.x_target_in[1] - self.x_target_in[0]
6464
r_step_morph = self.x_morph_in[1] - self.x_morph_in[0]
6565
rstepinc = max(r_step_target, r_step_morph)
66-
rmaxinc = min(self.x_target_in[-1] + r_step_target, self.x_morph_in[-1] + r_step_morph)
66+
rmaxinc = min(
67+
self.x_target_in[-1] + r_step_target,
68+
self.x_morph_in[-1] + r_step_morph,
69+
)
6770
if self.rmin is None or self.rmin < rmininc:
6871
self.rmin = rmininc
6972
if self.rmax is None or self.rmax > rmaxinc:
7073
self.rmax = rmaxinc
7174
if self.rstep is None or self.rstep < rstepinc:
7275
self.rstep = rstepinc
7376
# Make sure that rmax is exclusive
74-
self.x_morph_out = numpy.arange(self.rmin, self.rmax - epsilon, self.rstep)
75-
self.y_morph_out = numpy.interp(self.x_morph_out, self.x_morph_in, self.y_morph_in)
77+
self.x_morph_out = numpy.arange(
78+
self.rmin, self.rmax - epsilon, self.rstep
79+
)
80+
self.y_morph_out = numpy.interp(
81+
self.x_morph_out, self.x_morph_in, self.y_morph_in
82+
)
7683
self.x_target_out = self.x_morph_out.copy()
77-
self.y_target_out = numpy.interp(self.x_target_out, self.x_target_in, self.y_target_in)
84+
self.y_target_out = numpy.interp(
85+
self.x_target_out, self.x_target_in, self.y_target_in
86+
)
7887
return self.xyallout
7988

8089

src/diffpy/pdfmorph/morphs/morphshape.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,25 @@ def _spheroidalCF2(r, psize, axrat):
165165
f1 = (
166166
1
167167
- 3 * r / (4 * d * v) * (1 - r2 / (4 * d2) * (1 + 2.0 / (3 * v2)))
168-
- 3 * r / (4 * d) * (1 - r2 / (4 * d2)) * v / sqrt(1 - v2) * atanh(sqrt(1 - v2))
168+
- 3
169+
* r
170+
/ (4 * d)
171+
* (1 - r2 / (4 * d2))
172+
* v
173+
/ sqrt(1 - v2)
174+
* atanh(sqrt(1 - v2))
169175
)
170176

171177
r = rx[numpy.logical_and(rx > v * psize, rx <= psize)]
172178
r2 = r * r
173179
f2 = (
174180
(
175181
3 * d / (8 * r) * (1 + r2 / (2 * d2)) * sqrt(1 - r2 / d2)
176-
- 3 * r / (4 * d) * (1 - r2 / (4 * d2)) * atanh(sqrt(1 - r2 / d2))
182+
- 3
183+
* r
184+
/ (4 * d)
185+
* (1 - r2 / (4 * d2))
186+
* atanh(sqrt(1 - r2 / d2))
177187
)
178188
* v
179189
/ sqrt(1 - v2)
@@ -190,15 +200,26 @@ def _spheroidalCF2(r, psize, axrat):
190200
f1 = (
191201
1
192202
- 3 * r / (4 * d * v) * (1 - r2 / (4 * d2) * (1 + 2.0 / (3 * v2)))
193-
- 3 * r / (4 * d) * (1 - r2 / (4 * d2)) * v / sqrt(v2 - 1) * atan(sqrt(v2 - 1))
203+
- 3
204+
* r
205+
/ (4 * d)
206+
* (1 - r2 / (4 * d2))
207+
* v
208+
/ sqrt(v2 - 1)
209+
* atan(sqrt(v2 - 1))
194210
)
195211

196212
r = rx[numpy.logical_and(rx > psize, rx <= v * psize)]
197213
r2 = r * r
198214
f2 = (
199215
1
200216
- 3 * r / (4 * d * v) * (1 - r2 / (4 * d2) * (1 + 2.0 / (3 * v2)))
201-
- 3.0 / 8 * (1 + r2 / (2 * d2)) * sqrt(1 - d2 / r2) * v / sqrt(v2 - 1)
217+
- 3.0
218+
/ 8
219+
* (1 + r2 / (2 * d2))
220+
* sqrt(1 - d2 / r2)
221+
* v
222+
/ sqrt(v2 - 1)
202223
- 3
203224
* r
204225
/ (4 * d)

src/diffpy/pdfmorph/pdfmorph_api.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
],
4141
qdamp=morphs.MorphResolutionDamping,
4242
)
43-
_default_config = dict(scale=None, stretch=None, smear=None, baselineslope=None, qdamp=None)
43+
_default_config = dict(
44+
scale=None, stretch=None, smear=None, baselineslope=None, qdamp=None
45+
)
4446

4547

4648
def morph_default_config(**kwargs):
@@ -172,7 +174,11 @@ def pdfmorph(
172174
# input config
173175
rv_cfg = dict(kwargs)
174176
# configure morph operations
175-
active_morphs = [k for k, v in rv_cfg.items() if (v is not None) and k in _morph_step_dict]
177+
active_morphs = [
178+
k
179+
for k, v in rv_cfg.items()
180+
if (v is not None) and k in _morph_step_dict
181+
]
176182
rv_cfg["rmin"] = rmin
177183
rv_cfg["rmax"] = rmax
178184
rv_cfg["rstep"] = rstep
@@ -230,7 +236,9 @@ def pdfmorph(
230236
print("== INFO: Following steps are fixed during morphing ==:\n")
231237
print("\n".join(fixed_operations))
232238
print("== INFO: Refined morph parameters ==:\n")
233-
output = "\n".join(["# %s = %f" % (k, v) for k, v in rv_cfg.items() if v is not None])
239+
output = "\n".join(
240+
["# %s = %f" % (k, v) for k, v in rv_cfg.items() if v is not None]
241+
)
234242
output += "\n# Rw = %f" % rw
235243
output += "\n# Pearson = %f" % pcc
236244
print(output)

src/diffpy/pdfmorph/pdfmorph_io.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,17 @@ def single_morph_output(
5858

5959
# Input and output parameters
6060
morphs_in = "\n# Input morphing parameters:\n"
61-
morphs_in += "\n".join(f"# {key} = {morph_inputs[key]}" for key in morph_inputs.keys()) + "\n"
61+
morphs_in += (
62+
"\n".join(
63+
f"# {key} = {morph_inputs[key]}" for key in morph_inputs.keys()
64+
)
65+
+ "\n"
66+
)
6267

6368
morphs_out = "# Optimized morphing parameters:\n"
64-
morphs_out += "\n".join(f"# {key} = {morph_results[key]:.6f}" for key in morph_results.keys())
69+
morphs_out += "\n".join(
70+
f"# {key} = {morph_results[key]:.6f}" for key in morph_results.keys()
71+
)
6572

6673
# Printing to terminal
6774
if stdout_flag:
@@ -158,10 +165,20 @@ def get_multisave_names(target_list: list, save_names_file=None, mm=False):
158165
if target_file.name not in save_names.keys():
159166
if not mm:
160167
save_names.update(
161-
{target_file.name: {__save_morph_as__: f"Morph_with_Target_{target_file.stem}.cgr"}}
168+
{
169+
target_file.name: {
170+
__save_morph_as__: f"Morph_with_Target_{target_file.stem}.cgr"
171+
}
172+
}
162173
)
163174
else:
164-
save_names.update({target_file.name: {__save_morph_as__: f"Morph_of_{target_file.stem}.cgr"}})
175+
save_names.update(
176+
{
177+
target_file.name: {
178+
__save_morph_as__: f"Morph_of_{target_file.stem}.cgr"
179+
}
180+
}
181+
)
165182
return save_names
166183

167184

@@ -211,7 +228,9 @@ def multiple_morph_output(
211228

212229
# Input parameters used for every morph
213230
inputs = "\n# Input morphing parameters:\n"
214-
inputs += "\n".join(f"# {key} = {morph_inputs[key]}" for key in morph_inputs.keys())
231+
inputs += "\n".join(
232+
f"# {key} = {morph_inputs[key]}" for key in morph_inputs.keys()
233+
)
215234

216235
# Verbose to get output for every morph
217236
verbose_outputs = ""
@@ -224,7 +243,8 @@ def multiple_morph_output(
224243
output = f"\n# Morph: {target}\n"
225244
output += "# Optimized morphing parameters:\n"
226245
output += "\n".join(
227-
f"# {param} = {morph_results[target][param]:.6f}" for param in morph_results[target]
246+
f"# {param} = {morph_results[target][param]:.6f}"
247+
for param in morph_results[target]
228248
)
229249
verbose_outputs += f"{output}\n"
230250

@@ -270,13 +290,19 @@ def multiple_morph_output(
270290
else:
271291
header += f"# from morphing directory {target_path_name}\n"
272292
header += f"# with target {morph_path_name}"
273-
reference_table = Path(save_directory).joinpath("Morph_Reference_Table.txt")
293+
reference_table = Path(save_directory).joinpath(
294+
"Morph_Reference_Table.txt"
295+
)
274296
with open(reference_table, "w") as reference:
275-
print(f"{header}\n{inputs}\n{verbose_outputs}{table}", file=reference)
297+
print(
298+
f"{header}\n{inputs}\n{verbose_outputs}{table}", file=reference
299+
)
276300

277301
if stdout_flag:
278302
# Indicate successful save
279-
save_message = f"# Morphs saved in the directory {save_directory}\n"
303+
save_message = (
304+
f"# Morphs saved in the directory {save_directory}\n"
305+
)
280306
print(save_message)
281307

282308

@@ -302,6 +328,10 @@ def tabulate_results(multiple_morph_results):
302328
tabulated_results = {}
303329
for param in relevant_parameters:
304330
tabulated_results.update(
305-
{param: tools.get_values_from_dictionary_collection(multiple_morph_results, param)}
331+
{
332+
param: tools.get_values_from_dictionary_collection(
333+
multiple_morph_results, param
334+
)
335+
}
306336
)
307337
return tabulated_results

0 commit comments

Comments
 (0)