Skip to content

Commit 5980b00

Browse files
committed
style: line lengths in src
1 parent 09a11ee commit 5980b00

File tree

15 files changed

+89
-75
lines changed

15 files changed

+89
-75
lines changed

src/diffpy/srfit/fitbase/fithook.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,17 @@ def postcall(self, recipe, chiv):
144144
print("Variables")
145145
vnames = recipe.getNames()
146146
vals = recipe.getValues()
147-
byname = lambda nv: sortKeyForNumericString(nv[0])
148-
items = sorted(zip(vnames, vals), key=byname)
147+
# byname = _byname()
148+
items = sorted(zip(vnames, vals), key=_byname)
149149
for name, val in items:
150150
print(" %s = %f" % (name, val))
151151
return
152152

153153

154+
def _byname(nv):
155+
return sortKeyForNumericString(nv[0])
156+
157+
154158
# End class PrintFitHook
155159

156160

src/diffpy/srfit/fitbase/fitresults.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def __init__(self, recipe, update=True, showfixed=True, showcon=False):
108108

109109
def update(self):
110110
"""Update the results according to the current state of the recipe."""
111-
## Note that the order of these operations are chosen to reduce
112-
## computation time.
111+
# Note that the order of these operations are chosen to reduce
112+
# computation time.
113113

114114
recipe = self.recipe
115115

@@ -173,8 +173,8 @@ def _calculateCovariance(self):
173173
self.cov = numpy.dot(vh.T.conj() / s**2, vh)
174174
except numpy.linalg.LinAlgError:
175175
self.messages.append("Cannot compute covariance matrix.")
176-
l = len(self.varvals)
177-
self.cov = numpy.zeros((l, l), dtype=float)
176+
lvarvals = len(self.varvals)
177+
self.cov = numpy.zeros((lvarvals, lvarvals), dtype=float)
178178
return
179179

180180
def _calculateJacobian(self):
@@ -324,17 +324,19 @@ def formatResults(self, header="", footer="", update=False):
324324
lines.append(header)
325325

326326
if not certain:
327-
l = "Some quantities invalid due to missing profile uncertainty"
328-
if not l in self.messages:
329-
self.messages.append(l)
327+
err_msg = (
328+
"Some quantities invalid due to missing profile uncertainty"
329+
)
330+
if err_msg not in self.messages:
331+
self.messages.append(err_msg)
330332

331333
lines.extend(self.messages)
332334

333-
## Overall results
334-
l = "Overall"
335+
# Overall results
336+
err_msg = "Overall"
335337
if not certain:
336-
l += " (Chi2 and Reduced Chi2 invalid)"
337-
lines.append(l)
338+
err_msg += " (Chi2 and Reduced Chi2 invalid)"
339+
lines.append(err_msg)
338340
lines.append(_DASHEDLINE)
339341
formatstr = "%-14s %.8f"
340342
lines.append(formatstr % ("Residual", self.residual))
@@ -346,16 +348,16 @@ def formatResults(self, header="", footer="", update=False):
346348
lines.append(formatstr % ("Reduced Chi2", self.rchi2))
347349
lines.append(formatstr % ("Rw", self.rw))
348350

349-
## Per-FitContribution results
351+
# Per-FitContribution results
350352
if len(self.conresults) > 1:
351353
keys = list(self.conresults.keys())
352354
keys.sort(key=numstr)
353355

354356
lines.append("")
355-
l = "Contributions"
357+
err_msg = "Contributions"
356358
if not certain:
357-
l += " (Chi2 and Reduced Chi2 invalid)"
358-
lines.append(l)
359+
err_msg += " (Chi2 and Reduced Chi2 invalid)"
360+
lines.append(err_msg)
359361
lines.append(_DASHEDLINE)
360362
formatstr = "%-10s %-42.8f"
361363
for name in keys:
@@ -368,14 +370,14 @@ def formatResults(self, header="", footer="", update=False):
368370
lines.append(formatstr % ("Chi2", res.chi2))
369371
lines.append(formatstr % ("Rw", res.rw))
370372

371-
## The variables
373+
# The variables
372374
if self.varnames:
373375
lines.append("")
374-
l = "Variables"
376+
err_msg = "Variables"
375377
if not certain:
376-
m = "Uncertainties invalid"
377-
l += " (%s)" % m
378-
lines.append(l)
378+
err_msg2 = "Uncertainties invalid"
379+
err_msg += " (%s)" % err_msg2
380+
lines.append(err_msg)
379381
lines.append(_DASHEDLINE)
380382

381383
varnames = self.varnames
@@ -407,13 +409,13 @@ def formatResults(self, header="", footer="", update=False):
407409
varlines.sort()
408410
lines.extend(varlines)
409411

410-
## The constraints
412+
# The constraints
411413
if self.connames and self.showcon:
412414
lines.append("")
413-
l = "Constrained Parameters"
415+
err_msg = "Constrained Parameters"
414416
if not certain:
415-
l += " (Uncertainties invalid)"
416-
lines.append(l)
417+
err_msg += " (Uncertainties invalid)"
418+
lines.append(err_msg)
417419
lines.append(_DASHEDLINE)
418420

419421
w = 0
@@ -436,13 +438,13 @@ def formatResults(self, header="", footer="", update=False):
436438
val, unc = vals[name]
437439
lines.append(formatstr % (name, val, unc))
438440

439-
## Variable correlations
441+
# Variable correlations
440442
lines.append("")
441443
corint = int(corrmin * 100)
442-
l = "Variable Correlations greater than %i%%" % corint
444+
err_msg = "Variable Correlations greater than %i%%" % corint
443445
if not certain:
444-
l += " (Correlations invalid)"
445-
lines.append(l)
446+
err_msg += " (Correlations invalid)"
447+
lines.append(err_msg)
446448
lines.append(_DASHEDLINE)
447449
tup = []
448450
cornames = []
@@ -563,8 +565,8 @@ def __init__(self, con, weight, fitres):
563565

564566
def _init(self, con, weight, fitres):
565567
"""Initialize the attributes, for real."""
566-
## Note that the order of these operations is chosen to reduce
567-
## computation time.
568+
# Note that the order of these operations is chosen to reduce
569+
# computation time.
568570

569571
if con.profile is None:
570572
return

src/diffpy/srfit/fitbase/parameter.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,18 @@ def __init__(self, name, obj, getter=None, setter=None, attr=None):
253253
name -- The name of this Parameter.
254254
obj -- The object to be wrapped.
255255
getter -- The unbound function that can be used to access the
256-
attribute containing the parameter value. getter(obj) should
257-
return the Parameter value. If getter is None (default),
258-
it is assumed that an attribute is accessed via attr. If
259-
attr is also specified, then the Parameter value will be
260-
accessed via getter(obj, attr).
261-
setter -- The unbound function that can be used to modify the
262-
attribute containing the parameter value. setter(obj, value)
263-
should set the attribute to the passed value. If setter is
264-
None (default), it is assumed that an attribute is accessed
256+
attribute containing the parameter value. getter(obj)
257+
should return the Parameter value. If getter is None
258+
(default), it is assumed that an attribute is accessed
265259
via attr. If attr is also specified, then the Parameter
266-
value will be set via setter(obj, attr, value).
260+
value will be accessed via getter(obj, attr).
261+
setter -- The unbound function that can be used to modify the
262+
attribute containing the parameter value.
263+
setter(obj, value) should set the attribute to the
264+
passed value. If setter is None (default), it is assumed
265+
that an attribute is accessed via attr. If attr is also
266+
specified, then the Parameter value will be set via
267+
setter(obj, attr, value).
267268
attr -- The name of the attribute that contains the value of the
268269
parameter. If attr is None (default), then both getter and
269270
setter must be specified.

src/diffpy/srfit/fitbase/profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class Profile(Observable, Validatable):
4747
xobs -- Read-only property of _xobs.
4848
_yobs -- A numpy array of the observed signal (default None)
4949
yobs -- Read-only property of _yobs.
50-
_dyobs -- A numpy array of the uncertainty of the observed signal (default
51-
None, optional).
50+
_dyobs -- A numpy array of the uncertainty of the observed signal
51+
(default None, optional).
5252
dyobs -- Read-only property of _dyobs.
5353
x -- A numpy array of the calculated independent variable (default
5454
None, property for xpar accessors).

src/diffpy/srfit/fitbase/profilegenerator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __call__(self, x):
111111
"""
112112
return x
113113

114-
## No need to overload anything below here
114+
# No need to overload anything below here
115115

116116
def operation(self):
117117
"""Evaluate the profile.

src/diffpy/srfit/fitbase/profileparser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class ProfileParser(object):
3434
_format -- Name of the data format that this parses (string, default
3535
""). The format string is a unique identifier for the data
3636
format handled by the parser.
37-
_banks -- The data from each bank. Each bank contains a (x, y, dx, dy)
37+
_banks -- The data from each bank. Each bank contains a (x, y, dx,
38+
dy)
3839
tuple:
3940
x -- A numpy array containing the independent
4041
variable read from the file.

src/diffpy/srfit/fitbase/recipeorganizer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def registerFunction(self, f, name=None, argnames=None):
510510
self._eqfactory.registerOperator(name, f)
511511
return f
512512

513-
#### Introspection code
513+
# Introspection code
514514
if name is None or argnames is None:
515515

516516
import inspect
@@ -547,7 +547,7 @@ def registerFunction(self, f, name=None, argnames=None):
547547
argnames = list(fncode.co_varnames)
548548
argnames = argnames[offset : fncode.co_argcount]
549549

550-
#### End introspection code
550+
# End introspection code
551551

552552
# Make missing Parameters
553553
for pname in argnames:
@@ -741,7 +741,7 @@ def clearConstraints(self, recurse=False):
741741
self.unconstrain(*self._constraints)
742742

743743
if recurse:
744-
f = lambda m: hasattr(m, "clearConstraints")
744+
_constraint_clearer = lambda m: hasattr(m, "clearConstraints")
745745
for m in filter(f, self._iterManaged()):
746746
m.clearConstraints(recurse)
747747
return
@@ -1057,3 +1057,7 @@ def equationFromString(
10571057
factory.deRegisterBuilder(name)
10581058

10591059
return eq
1060+
1061+
1062+
def _constraint_clearer(msg):
1063+
return hasattr(msg, "clearConstraints")

src/diffpy/srfit/interface/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@
2020
"""
2121

2222

23-
from diffpy.srfit.interface.interface import ParameterInterface
23+
from diffpy.srfit.interface.interface import (
24+
FitRecipeInterface,
25+
ParameterInterface,
26+
RecipeOrganizerInterface,
27+
)
2428

2529
_parameter_interface = ParameterInterface
26-
27-
from diffpy.srfit.interface.interface import RecipeOrganizerInterface
28-
2930
_recipeorganizer_interface = RecipeOrganizerInterface
30-
31-
from diffpy.srfit.interface.interface import FitRecipeInterface
32-
3331
_fitrecipe_interface = FitRecipeInterface
3432

3533
# End of file

src/diffpy/srfit/pdf/pdfparser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ class PDFParser(ProfileParser):
3838
_format -- Name of the data format that this parses (string, default
3939
""). The format string is a unique identifier for the data
4040
format handled by the parser.
41-
_banks -- The data from each bank. Each bank contains a (x, y, dx, dy)
42-
tuple:
41+
_banks -- The data from each bank. Each bank contains a
42+
(x, y, dx, dy) tuple:
4343
x -- A numpy array containing the independent
4444
variable read from the file.
4545
y -- A numpy array containing the profile
4646
from the file.
4747
dx -- A numpy array containing the uncertainty in x
48-
read from the file. This is 0 if the uncertainty
49-
cannot be read.
48+
read from the file. This is 0 if the
49+
uncertainty cannot be read.
5050
dy -- A numpy array containing the uncertainty read
5151
from the file. This is 0 if the uncertainty
5252
cannot be read.

src/diffpy/srfit/sas/sasparser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ class SASParser(ProfileParser):
3636
_format -- Name of the data format that this parses (string, default
3737
""). The format string is a unique identifier for the data
3838
format handled by the parser.
39-
_banks -- The data from each bank. Each bank contains a (x, y, dx, dy)
40-
tuple:
39+
_banks -- The data from each bank. Each bank contains a
40+
(x, y, dx, dy) tuple:
4141
x -- A numpy array containing the independent
4242
variable read from the file.
4343
y -- A numpy array containing the profile
4444
from the file.
4545
dx -- A numpy array containing the uncertainty in x
46-
read from the file. This is 0 if the uncertainty
47-
cannot be read.
46+
read from the file. This is 0 if the
47+
uncertainty cannot be read.
4848
dy -- A numpy array containing the uncertainty read
4949
from the file. This is 0 if the uncertainty
5050
cannot be read.

0 commit comments

Comments
 (0)