Skip to content

Commit 6526430

Browse files
authored
Merge pull request #164 from ycexiao/line_width
style: set the line width limit to 79
2 parents fa1dd17 + 116fe95 commit 6526430

34 files changed

+835
-314
lines changed

Diff for: .flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exclude =
55
build,
66
dist,
77
doc/source/conf.py
8-
max-line-length = 115
8+
max-line-length = 79
99
# Ignore some style 'errors' produced while formatting by 'black'
1010
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#labels-why-pycodestyle-warnings
1111
extend-ignore = E203

Diff for: .isort.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[settings]
2-
line_length = 115
2+
line_length = 79
33
multi_line_output = 3
44
include_trailing_comma = True

Diff for: doc/source/conf.py

+16-2
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

Diff for: news/line79.rst

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
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+
* reduce the line width limit to 79
20+
21+
**Security:**
22+
23+
* <news item>

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ignore-words = ".codespell/ignore_words.txt"
6060
skip = "*.cif,*.dat,*agr"
6161

6262
[tool.black]
63-
line-length = 115
63+
line-length = 79
6464
include = '\.pyi?$'
6565
exclude = '''
6666
/(

Diff for: src/diffpy/pdfmorph/morph_helpers/__init__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
#
1212
##############################################################################
1313

14-
"""List of helpers for certain morphing operations (currently only used for smear)."""
14+
"""List of helpers for certain morphing operations
15+
(currently only used for smear)."""
1516

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

1924
# List of helpers
2025
morph_helpers = [

Diff for: src/diffpy/pdfmorph/morph_helpers/transformpdftordf.py

+3-1
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

Diff for: src/diffpy/pdfmorph/morph_helpers/transformrdftopdf.py

+6-2
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

Diff for: src/diffpy/pdfmorph/morphs/morph.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
class Morph(object):
2727
"""Base class for implementing a morph given a target.
2828
29-
Adapted from diffpy.pdfgetx to include two sets of arrays that get passed through.
29+
Adapted from diffpy.pdfgetx to include two sets of arrays that get passed
30+
through.
3031
31-
Attributes are taken from config when not found locally. The morph may modify the config dictionary.
32-
This is the means by which to communicate automatically modified attributes.
32+
Attributes are taken from config when not found locally. The morph may
33+
modify the config dictionary. This is the means by which to communicate
34+
automatically modified attributes.
3335
3436
Class Attributes
3537
----------------
@@ -142,7 +144,8 @@ def __init__(self, config=None):
142144
def morph(self, x_morph, y_morph, x_target, y_target):
143145
"""Morph arrays morphed or target.
144146
145-
Identity operation. This method should be overloaded in a derived class.
147+
Identity operation.
148+
This method should be overloaded in a derived class.
146149
147150
Parameters
148151
----------
@@ -154,7 +157,8 @@ def morph(self, x_morph, y_morph, x_target, y_target):
154157
Returns
155158
-------
156159
tuple
157-
A tuple of numpy arrays (x_morph_out, y_morph_out, x_target_out, y_target_out)
160+
A tuple of numpy arrays
161+
(x_morph_out, y_morph_out, x_target_out, y_target_out)
158162
"""
159163
self.x_morph_in = x_morph
160164
self.y_morph_in = y_morph
@@ -223,7 +227,8 @@ def plotOutputs(self, xylabels=True, **plotargs):
223227
xylabels: bool
224228
Flag for updating x and y axes labels.
225229
plotargs
226-
Arguments passed to the pylab plot function. Note that "label" will be ignored.
230+
Arguments passed to the pylab plot function.
231+
Note that "label" will be ignored.
227232
228233
Returns
229234
-------
@@ -234,7 +239,9 @@ def plotOutputs(self, xylabels=True, **plotargs):
234239

235240
pargs = dict(plotargs)
236241
pargs.pop("label", None)
237-
rv = plot(self.x_target_out, self.y_target_out, label="target", **pargs)
242+
rv = plot(
243+
self.x_target_out, self.y_target_out, label="target", **pargs
244+
)
238245
rv = plot(self.x_morph_out, self.y_morph_out, label="morph", **pargs)
239246
if xylabels:
240247
xlabel(self.xoutlabel)

Diff for: src/diffpy/pdfmorph/morphs/morphchain.py

+50-18
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
class MorphChain(list):
2121
"""Class for chaining morphs together.
2222
23-
This class is a queue of morphs that get executed in order via the 'morph' method.
24-
This class derives from the built-in list, and list methods are used to modify the queue.
23+
This class is a queue of morphs that get executed in order via the 'morph'
24+
method. This class derives from the built-in list, and list methods are
25+
used to modify the queue.
2526
2627
This derives from list and relies on its methods where possible.
2728
@@ -57,7 +58,8 @@ class MorphChain(list):
5758
xy_target_out
5859
Tuple of (x_target_out, y_target_out) from last morph.
5960
xyallout
60-
Tuple of (x_morph_out, y_morph_out, x_target_out, y_target_out) from last morph.
61+
Tuple of (x_morph_out, y_morph_out, x_target_out, y_target_out)
62+
from last morph.
6163
parnames
6264
Names of parameters collected from morphs (Read only).
6365
@@ -66,19 +68,47 @@ class MorphChain(list):
6668
The properties return tuples of None if there are no morphs.
6769
"""
6870

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

84114
def __init__(self, config, *args):
@@ -89,7 +119,8 @@ def __init__(self, config, *args):
89119
90120
Notes
91121
-----
92-
Additional arguments are morphs that will extend the queue of morphs.
122+
Additional arguments are morphs that will extend the queue of
123+
morphs.
93124
"""
94125
self.config = config
95126
self.extend(args)
@@ -108,7 +139,8 @@ def morph(self, x_morph, y_morph, x_target, y_target):
108139
Returns
109140
-------
110141
tuple
111-
A tuple of numpy arrays (x_morph_out, y_morph_out, x_target_out, y_target_out).
142+
A tuple of numpy arrays
143+
(x_morph_out, y_morph_out, x_target_out, y_target_out).
112144
113145
Notes
114146
-----

Diff for: src/diffpy/pdfmorph/morphs/morphrgrid.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ class MorphRGrid(Morph):
4343
4444
Notes
4545
-----
46-
If any of these is not defined or outside the bounds of the input arrays,
47-
then it will be taken to be the most inclusive value from the input arrays.
48-
These modified values will be stored as the above attributes.
46+
If any of these is not defined or outside the bounds of the input
47+
arrays, then it will be taken to be the most inclusive value from the
48+
input arrays. These modified values will be stored as the above
49+
attributes.
4950
"""
5051

5152
# Define input output types
@@ -63,18 +64,27 @@ def morph(self, x_morph, y_morph, x_target, y_target):
6364
r_step_target = self.x_target_in[1] - self.x_target_in[0]
6465
r_step_morph = self.x_morph_in[1] - self.x_morph_in[0]
6566
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)
67+
rmaxinc = min(
68+
self.x_target_in[-1] + r_step_target,
69+
self.x_morph_in[-1] + r_step_morph,
70+
)
6771
if self.rmin is None or self.rmin < rmininc:
6872
self.rmin = rmininc
6973
if self.rmax is None or self.rmax > rmaxinc:
7074
self.rmax = rmaxinc
7175
if self.rstep is None or self.rstep < rstepinc:
7276
self.rstep = rstepinc
7377
# 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)
78+
self.x_morph_out = numpy.arange(
79+
self.rmin, self.rmax - epsilon, self.rstep
80+
)
81+
self.y_morph_out = numpy.interp(
82+
self.x_morph_out, self.x_morph_in, self.y_morph_in
83+
)
7684
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)
85+
self.y_target_out = numpy.interp(
86+
self.x_target_out, self.x_target_in, self.y_target_in
87+
)
7888
return self.xyallout
7989

8090

Diff for: src/diffpy/pdfmorph/morphs/morphshape.py

+9-21
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def morph(self, x_morph, y_morph, x_target, y_target):
8989
def _sphericalCF(r, psize):
9090
"""Spherical nanoparticle characteristic function.
9191
92-
From Kodama et al., Acta Cryst. A, 62, 444-453 (converted from radius to diameter).
92+
From Kodama et al., Acta Cryst. A, 62, 444-453
93+
(converted from radius to diameter).
9394
9495
Parameters
9596
----------
@@ -163,21 +164,19 @@ def _spheroidalCF2(r, psize, axrat):
163164
r = rx[rx <= v * psize]
164165
r2 = r * r
165166
f1 = (
166-
1
167-
- 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))
167+
1 - 3*r/(4*d*v)*(1-r2/(4*d2)*(1+2.0/(3*v2))) - 3*r/(4*d)*(1-r2/(4*d2))*v/sqrt(1-v2)*atanh(sqrt(1-v2)) # fmt: skip # noqa: E501
169168
)
170169

171170
r = rx[numpy.logical_and(rx > v * psize, rx <= psize)]
172171
r2 = r * r
172+
# fmt: off
173173
f2 = (
174174
(
175-
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))
175+
3*d/(8*r)*(1+r2/(2*d2))*sqrt(1-r2/d2) - 3*r/(4*d)*(1-r2/(4*d2))*atanh(sqrt(1-r2/d2)) # noqa: E501
177176
)
178-
* v
179-
/ sqrt(1 - v2)
177+
* v / sqrt(1-v2)
180178
)
179+
# fmt: on
181180

182181
r = rx[rx > psize]
183182
f3 = numpy.zeros_like(r)
@@ -188,24 +187,13 @@ def _spheroidalCF2(r, psize, axrat):
188187
r = rx[rx <= psize]
189188
r2 = r * r
190189
f1 = (
191-
1
192-
- 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))
190+
1 - 3*r/(4*d*v)*(1-r2/(4*d2)*(1+2.0/(3*v2))) - 3*r/(4*d)*(1-r2/(4*d2))*v/sqrt(v2-1)*atan(sqrt(v2-1)) # fmt: skip # noqa: E501
194191
)
195192

196193
r = rx[numpy.logical_and(rx > psize, rx <= v * psize)]
197194
r2 = r * r
198195
f2 = (
199-
1
200-
- 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)
202-
- 3
203-
* r
204-
/ (4 * d)
205-
* (1 - r2 / (4 * d2))
206-
* v
207-
/ sqrt(v2 - 1)
208-
* (atan(sqrt(v2 - 1)) - atan(sqrt(r2 / d2 - 1)))
196+
1 - 3*r/(4*d*v)*(1-r2/(4*d2)*(1+2.0/(3*v2))) - 3.0/8*(1+r2/(2*d2))*sqrt(1-d2/r2)*v/sqrt(v2-1) - 3*r/(4*d)*(1-r2/(4*d2))*v/sqrt(v2-1)*(atan(sqrt(v2-1))-atan(sqrt(r2/d2-1))) # fmt: skip # noqa:E501
209197
)
210198

211199
r = rx[rx > v * psize]

0 commit comments

Comments
 (0)