Skip to content

Commit c0d43e6

Browse files
clean out inits (#38)
* clean out inits * [pre-commit.ci] auto fixes from pre-commit hooks * dataclusters.py, modelevaluators/aicc and modelparts.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 978dca1 commit c0d43e6

File tree

6 files changed

+25
-41
lines changed

6 files changed

+25
-41
lines changed

Diff for: diffpy/srmise/baselines/__init__.py

-8
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,3 @@
1111
# See LICENSE.txt for license information.
1212
#
1313
##############################################################################
14-
15-
__all__ = ["base", "arbitrary", "fromsequence", "nanospherical", "polynomial"]
16-
17-
from arbitrary import Arbitrary
18-
from base import Baseline
19-
from fromsequence import FromSequence
20-
from nanospherical import NanoSpherical
21-
from polynomial import Polynomial

Diff for: diffpy/srmise/dataclusters.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ def cut(self, idx):
365365
def cluster_boundaries(self):
366366
"""Return sequence with (x,y) of all cluster boundaries."""
367367
boundaries = []
368-
for l in self.clusters:
369-
xlo = np.mean(self.x[l[0] - 1 : l[0] + 1])
370-
ylo = np.mean(self.y[l[0] - 1 : l[0] + 1])
371-
xhi = np.mean(self.x[l[1] : l[1] + 2])
372-
yhi = np.mean(self.y[l[1] : l[1] + 2])
368+
for cluster in self.clusters:
369+
xlo = np.mean(self.x[cluster[0] - 1 : cluster[0] + 1])
370+
ylo = np.mean(self.y[cluster[0] - 1 : cluster[0] + 1])
371+
xhi = np.mean(self.x[cluster[1] : cluster[1] + 2])
372+
yhi = np.mean(self.y[cluster[1] : cluster[1] + 2])
373373
boundaries.append((xlo, ylo))
374374
boundaries.append((xhi, yhi))
375375
return np.unique(boundaries)
@@ -416,9 +416,9 @@ def animate(self):
416416
all_lines[i].set_ydata([0, height])
417417
ax.draw_artist(all_lines[i])
418418
else:
419-
l = plt.axvline(b[0], 0, height, color="k", animated=True)
420-
ax.draw_artist(l)
421-
all_lines.append(l)
419+
line = plt.axvline(b[0], 0, height, color="k", animated=True)
420+
ax.draw_artist(line)
421+
all_lines.append(line)
422422
canvas.blit(ax.bbox)
423423

424424
self.clusters = clusters

Diff for: diffpy/srmise/modelevaluators/__init__.py

-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,3 @@
1111
# See LICENSE.txt for license information.
1212
#
1313
##############################################################################
14-
15-
__all__ = ["base", "aic", "aicc"]
16-
17-
from aic import AIC
18-
from aicc import AICc

Diff for: diffpy/srmise/modelevaluators/aicc.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import numpy as np
1818

19-
import diffpy.srmise.srmiselog
2019
from diffpy.srmise.modelevaluators.base import ModelEvaluator
2120
from diffpy.srmise.srmiseerrors import SrMiseModelEvaluatorError
2221

@@ -72,7 +71,7 @@ def evaluate(self, fit, count_fixed=False, kshift=0):
7271
logger.warn("AICc.evaluate(): too few data to evaluate quality reliably.")
7372
n = self.minpoints(k)
7473

75-
if self.chisq == None:
74+
if self.chisq is None:
7675
self.chisq = self.chi_squared(fit.value(), fit.y_cluster, fit.error_cluster)
7776

7877
self.stat = self.chisq + self.parpenalty(k, n)
@@ -96,10 +95,12 @@ def parpenalty(self, k, n):
9695
return (2 * k + float(2 * k * (k + 1)) / (n - k - 1)) * fudgefactor
9796

9897
def growth_justified(self, fit, k_prime):
99-
"""Returns whether adding k_prime parameters to the given model (ModelCluster) is justified given the current quality of the fit.
100-
The assumption is that adding k_prime parameters will result in "effectively 0" chiSquared cost, and so adding it is justified
101-
if the cost of adding these parameters is less than the current chiSquared cost. The validity of this assumption (which
102-
depends on an unknown chiSquared value) and the impact of the errors used should be examined more thoroughly in the future.
98+
"""Is adding k_prime parameters to ModelCluster justified given the current quality of the fit.
99+
100+
The assumption is that adding k_prime parameters will result in "effectively 0" chiSquared cost,
101+
and so adding it is justified if the cost of adding these parameters is less than the current
102+
chiSquared cost. The validity of this assumption (which depends on an unknown chiSquared value)
103+
and the impact of the errors used should be examined more thoroughly in the future.
103104
"""
104105

105106
if self.chisq is None:

Diff for: diffpy/srmise/modelparts.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@
2121

2222
import logging
2323

24-
import numpy as np
25-
from scipy.optimize import leastsq
26-
27-
from diffpy.srmise import srmiselog
28-
from diffpy.srmise.srmiseerrors import *
29-
30-
logger = logging.getLogger("diffpy.srmise")
31-
3224
import matplotlib.pyplot as plt
25+
import numpy as np
3326

3427
# Output of scipy.optimize.leastsq for a single parameter changed in scipy 0.8.0
3528
# Before it returned a scalar, later it returned an array of length 1.
3629
import pkg_resources as pr
30+
from scipy.optimize import leastsq
3731

32+
from diffpy.srmise import srmiselog
33+
from diffpy.srmise.srmiseerrors import SrMiseFitError, SrMiseStaticOwnerError, SrMiseUndefinedCovarianceError
34+
35+
logger = logging.getLogger("diffpy.srmise")
3836
__spv__ = pr.get_distribution("scipy").version
3937
__oldleastsqbehavior__ = pr.parse_version(__spv__) < pr.parse_version("0.8.0")
4038

@@ -98,7 +96,7 @@ def fit(
9896
# raise SrMiseFitError(emsg)
9997
return
10098

101-
if range == None:
99+
if range is None:
102100
range = slice(None)
103101

104102
args = (r, y, y_error, range)
@@ -203,7 +201,7 @@ def fit(
203201
cov.setcovariance(self, pcov * np.sum(fvec**2) / dof)
204202
try:
205203
cov.transform(in_format="internal", out_format=cov_format)
206-
except SrMiseUndefinedCovarianceError as e:
204+
except SrMiseUndefinedCovarianceError:
207205
logger.warn("Covariance not defined. Fit may not have converged.")
208206

209207
return
@@ -332,7 +330,7 @@ def covariance(self, format="internal", **kwds):
332330

333331
for k, v in kwds.items():
334332
try:
335-
idx = int(k[1:])
333+
int(k[1:])
336334
except ValueError:
337335
emsg = "Invalid format keyword '%s'. They must be specified as 'f0', 'f1', etc." % k
338336
raise ValueError(emsg)
@@ -559,7 +557,7 @@ def npars(self, count_fixed=True):
559557
if count_fixed:
560558
return self._owner.npars
561559
else:
562-
return (self.free == True).sum()
560+
return (self.free is True).sum()
563561

564562
def __str__(self):
565563
"""Return string representation of ModelPart parameters."""

Diff for: diffpy/srmise/peaks/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@
1111
# See LICENSE.txt for license information.
1212
#
1313
##############################################################################
14-
15-
__all__ = ["base", "gaussian", "gaussianoverr", "terminationripples"]

0 commit comments

Comments
 (0)