Skip to content

Commit f8b741c

Browse files
authored
Merge pull request #99 from sbillinge/black
black
2 parents d037f66 + 9e7e63a commit f8b741c

40 files changed

+493
-359
lines changed

pyproject.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,28 @@ where = ["src"] # list of folders that contain the packages (["."] by default)
5252
include = ["diffpy*"] # package names should match these glob patterns (["*"] by default)
5353
exclude = ["diffpy.pdfmorph.tests*"] # exclude packages matching these glob patterns (empty by default)
5454
namespaces = false # to disable scanning PEP 420 namespaces (true by default)
55+
56+
[tool.black]
57+
line-length = 115
58+
include = '\.pyi?$'
59+
exclude = '''
60+
/(
61+
\.git
62+
| \.hg
63+
| \.mypy_cache
64+
| \.tox
65+
| \.venv
66+
| _build
67+
| buck-out
68+
| build
69+
| dist
70+
71+
# The following are specific to Black, you probably don't want those.
72+
| blib2to3
73+
| tests/data
74+
)/
75+
'''
76+
77+
[tool.flake8]
78+
max-line-length = 115
79+
per-file-ignores="__init__.py:F401"

src/diffpy/pdfmorph/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
"""Tools for manipulating and comparing PDFs.
1717
"""
1818

19+
# top-level import
20+
from diffpy.pdfmorph.pdfmorph_api import (morph_default_config, pdfmorph,
21+
plot_morph)
1922
# obtain version information
2023
from diffpy.pdfmorph.version import __version__
2124

22-
# top-level import
23-
from diffpy.pdfmorph.pdfmorph_api import pdfmorph, morph_default_config, plot_morph
24-
2525
# key used when saving multiple morphs
2626
__save_morph_as__ = "save_morph_as"
2727

src/diffpy/pdfmorph/log.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
import logging
2424

2525
# logging configuration
26-
plog = logging.getLogger('diffpy.pdfmorph')
26+
plog = logging.getLogger("diffpy.pdfmorph")
2727

2828

2929
def set_verbosity(vb):
30-
'''Set verbosity of the pdfmorph logger.
30+
"""Set verbosity of the pdfmorph logger.
3131
3232
Parameters
3333
----------
@@ -37,7 +37,7 @@ def set_verbosity(vb):
3737
Returns
3838
-------
3939
No return value.
40-
'''
40+
"""
4141
try:
4242
if type(vb) is str:
4343
level = int(getattr(logging, vb.upper(), vb))

src/diffpy/pdfmorph/morph_helpers/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
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+
from diffpy.pdfmorph.morph_helpers.transformrdftopdf import \
19+
TransformXtalRDFtoPDF
1820

1921
# List of helpers
2022
morph_helpers = [
2123
TransformXtalPDFtoRDF,
2224
TransformXtalRDFtoPDF,
2325
]
24-
25-

src/diffpy/pdfmorph/morph_helpers/transformpdftordf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
class TransformXtalPDFtoRDF(Morph):
25-
'''Transform crystal PDFs to RDFs.
25+
"""Transform crystal PDFs to RDFs.
2626
2727
Converts both morph data and target data PDFs to RDFs.
2828
@@ -35,10 +35,10 @@ class TransformXtalPDFtoRDF(Morph):
3535
With s = baselineslope,
3636
R(r) = r * (G(r) - r * s)
3737
38-
'''
38+
"""
3939

4040
# Define input output types
41-
summary = 'Turn the PDF into the RDF for both the morph and target'
41+
summary = "Turn the PDF into the RDF for both the morph and target"
4242
xinlabel = LABEL_RA
4343
yinlabel = LABEL_GR
4444
xoutlabel = LABEL_RA

src/diffpy/pdfmorph/morph_helpers/transformrdftopdf.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020

2121
import numpy
22+
2223
from diffpy.pdfmorph.morphs.morph import *
2324

2425

2526
class TransformXtalRDFtoPDF(Morph):
26-
'''Transform crystal RDFs to PDFs.
27+
"""Transform crystal RDFs to PDFs.
2728
2829
Converts both morph data and target data RDFs to PDFs.
2930
@@ -36,10 +37,10 @@ class TransformXtalRDFtoPDF(Morph):
3637
With s = baselineslope,
3738
G(r) = R(r) / r + r * s
3839
39-
'''
40+
"""
4041

4142
# Define input output types
42-
summary = 'Turn the PDF into the RDF for both the morph and target'
43+
summary = "Turn the PDF into the RDF for both the morph and target"
4344
xinlabel = LABEL_RA
4445
yinlabel = LABEL_RR
4546
xoutlabel = LABEL_RA
@@ -51,10 +52,10 @@ def morph(self, x_morph, y_morph, x_target, y_target):
5152
Morph.morph(self, x_morph, y_morph, x_target, y_target)
5253
morph_baseline = self.baselineslope * self.x_morph_in
5354
target_baseline = self.baselineslope * self.x_target_in
54-
with numpy.errstate(divide='ignore', invalid='ignore'):
55+
with numpy.errstate(divide="ignore", invalid="ignore"):
5556
self.y_target_out = self.y_target_in / self.x_target_in + target_baseline
5657
self.y_target_out[self.x_target_in == 0] = 0
57-
with numpy.errstate(divide='ignore', invalid='ignore'):
58+
with numpy.errstate(divide="ignore", invalid="ignore"):
5859
self.y_morph_out = self.y_morph_in / self.x_morph_in + morph_baseline
5960
self.y_morph_out[self.x_target_in == 0] = 0
6061
return self.xyallout

src/diffpy/pdfmorph/morphs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
from diffpy.pdfmorph.morphs.morph import Morph
2121
from diffpy.pdfmorph.morphs.morphchain import MorphChain
22+
from diffpy.pdfmorph.morphs.morphishape import MorphISphere, MorphISpheroid
2223
from diffpy.pdfmorph.morphs.morphresolution import MorphResolutionDamping
2324
from diffpy.pdfmorph.morphs.morphrgrid import MorphRGrid
2425
from diffpy.pdfmorph.morphs.morphscale import MorphScale
2526
from diffpy.pdfmorph.morphs.morphshape import MorphSphere, MorphSpheroid
26-
from diffpy.pdfmorph.morphs.morphishape import MorphISphere, MorphISpheroid
2727
from diffpy.pdfmorph.morphs.morphshift import MorphShift
2828
from diffpy.pdfmorph.morphs.morphsmear import MorphSmear
2929
from diffpy.pdfmorph.morphs.morphstretch import MorphStretch

src/diffpy/pdfmorph/morphs/morph.py

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
"""
1919

2020

21-
LABEL_RA = 'r (A)' # r-grid
22-
LABEL_GR = 'G (1/A^2)' # PDF G(r)
23-
LABEL_RR = 'R (1/A)' # RDF R(r)
21+
LABEL_RA = "r (A)" # r-grid
22+
LABEL_GR = "G (1/A^2)" # PDF G(r)
23+
LABEL_RR = "R (1/A)" # RDF R(r)
2424

2525

2626
class Morph(object):
27-
'''Base class for implementing a morph given a target.
27+
"""Base class for implementing a morph given a target.
2828
2929
Adapted from diffpy.pdfgetx to include two sets of arrays that get passed through.
3030
@@ -79,46 +79,51 @@ class Morph(object):
7979
Tuple of (x_target_out, y_target_out).
8080
xyallout
8181
Tuple of (x_morph_out, y_morph_out, x_target_out, y_target_out).
82-
'''
82+
"""
8383

8484
# Class variables
8585
# default array types are empty
86-
summary = 'identity transformation'
87-
xinlabel = 'x'
88-
yinlabel = 'y'
89-
xoutlabel = 'x'
90-
youtlabel = 'y'
86+
summary = "identity transformation"
87+
xinlabel = "x"
88+
yinlabel = "y"
89+
xoutlabel = "x"
90+
youtlabel = "y"
9191
parnames = []
9292

9393
# Properties
9494

9595
xy_morph_in = property(
9696
lambda self: (self.x_morph_in, self.y_morph_in),
97-
doc='Return a tuple of morph input arrays',
97+
doc="Return a tuple of morph input arrays",
9898
)
9999
xy_morph_out = property(
100100
lambda self: (self.x_morph_out, self.y_morph_out),
101-
doc='Return a tuple of morph output arrays',
101+
doc="Return a tuple of morph output arrays",
102102
)
103103
xy_target_in = property(
104104
lambda self: (self.x_target_in, self.y_target_in),
105-
doc='Return a tuple of target input arrays',
105+
doc="Return a tuple of target input arrays",
106106
)
107107
xy_target_out = property(
108108
lambda self: (self.x_target_out, self.y_target_out),
109-
doc='Return a tuple of target output arrays',
109+
doc="Return a tuple of target output arrays",
110110
)
111111
xyallout = property(
112-
lambda self: (self.x_morph_out, self.y_morph_out, self.x_target_out, self.y_target_out),
113-
doc='Return a tuple of all output arrays',
112+
lambda self: (
113+
self.x_morph_out,
114+
self.y_morph_out,
115+
self.x_target_out,
116+
self.y_target_out,
117+
),
118+
doc="Return a tuple of all output arrays",
114119
)
115120

116121
def __init__(self, config=None):
117-
'''Create a default Morph instance.
122+
"""Create a default Morph instance.
118123
119124
config: dict
120125
All configuration variables.
121-
'''
126+
"""
122127
# declare empty attributes
123128
if config is None:
124129
config = {}
@@ -135,7 +140,7 @@ def __init__(self, config=None):
135140
return
136141

137142
def morph(self, x_morph, y_morph, x_target, y_target):
138-
'''Morph arrays morphed or target.
143+
"""Morph arrays morphed or target.
139144
140145
Identity operation. This method should be overloaded in a derived class.
141146
@@ -150,7 +155,7 @@ def morph(self, x_morph, y_morph, x_target, y_target):
150155
-------
151156
tuple
152157
A tuple of numpy arrays (x_morph_out, y_morph_out, x_target_out, y_target_out)
153-
'''
158+
"""
154159
self.x_morph_in = x_morph
155160
self.y_morph_in = y_morph
156161
self.x_target_in = x_target
@@ -163,11 +168,11 @@ def morph(self, x_morph, y_morph, x_target, y_target):
163168
return self.xyallout
164169

165170
def __call__(self, x_morph, y_morph, x_target, y_target):
166-
'''Alias for morph.'''
171+
"""Alias for morph."""
167172
return self.morph(x_morph, y_morph, x_target, y_target)
168173

169174
def applyConfig(self, config):
170-
'''Process any configuration data from a dictionary.
175+
"""Process any configuration data from a dictionary.
171176
172177
Parameters
173178
----------
@@ -177,19 +182,19 @@ def applyConfig(self, config):
177182
Returns
178183
-------
179184
No return value.
180-
'''
185+
"""
181186
self.config = config
182187
return
183188

184189
def checkConfig(self):
185-
'''Verify data in self.config. No action by default.
190+
"""Verify data in self.config. No action by default.
186191
187192
To be overridden in a derived class.
188-
'''
193+
"""
189194
return
190195

191196
def plotInputs(self, xylabels=True):
192-
'''Plot input arrays using matplotlib.pyplot
197+
"""Plot input arrays using matplotlib.pyplot
193198
194199
Parameters
195200
----------
@@ -200,7 +205,7 @@ def plotInputs(self, xylabels=True):
200205
-------
201206
list:
202207
A list of matplotlib line objects.
203-
'''
208+
"""
204209
from matplotlib.pyplot import plot, xlabel, ylabel
205210

206211
rv = plot(self.x_target_in, self.y_target_in, label="target")
@@ -211,7 +216,7 @@ def plotInputs(self, xylabels=True):
211216
return rv
212217

213218
def plotOutputs(self, xylabels=True, **plotargs):
214-
'''Plot output arrays using matplotlib.pyplot
219+
"""Plot output arrays using matplotlib.pyplot
215220
216221
Parameters
217222
----------
@@ -224,7 +229,7 @@ def plotOutputs(self, xylabels=True, **plotargs):
224229
-------
225230
list
226231
A list of matplotlib line objects.
227-
'''
232+
"""
228233
from matplotlib.pyplot import plot, xlabel, ylabel
229234

230235
pargs = dict(plotargs)
@@ -237,7 +242,7 @@ def plotOutputs(self, xylabels=True, **plotargs):
237242
return rv
238243

239244
def __getattr__(self, name):
240-
'''Obtain the value from self.config, when normal lookup fails.
245+
"""Obtain the value from self.config, when normal lookup fails.
241246
242247
Parameters
243248
----------
@@ -252,23 +257,23 @@ def __getattr__(self, name):
252257
------
253258
AttributeError
254259
Name is not available from self.config.
255-
'''
260+
"""
256261
if name in self.config:
257262
return self.config[name]
258263
else:
259-
emsg = 'Object has no attribute %r' % name
264+
emsg = "Object has no attribute %r" % name
260265
raise AttributeError(emsg)
261266

262267
def __setattr__(self, name, val):
263-
'''Set configuration variables to config.
268+
"""Set configuration variables to config.
264269
265270
Parameters
266271
----------
267272
name
268273
Name of the attribute.
269274
val
270275
Value of the attribute.
271-
'''
276+
"""
272277
if name in self.parnames:
273278
self.config[name] = val
274279
else:

0 commit comments

Comments
 (0)