Skip to content

Commit

Permalink
clean out inits (#38)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
sbillinge and pre-commit-ci[bot] authored Jul 31, 2024
1 parent 978dca1 commit c0d43e6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 41 deletions.
8 changes: 0 additions & 8 deletions diffpy/srmise/baselines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,3 @@
# See LICENSE.txt for license information.
#
##############################################################################

__all__ = ["base", "arbitrary", "fromsequence", "nanospherical", "polynomial"]

from arbitrary import Arbitrary
from base import Baseline
from fromsequence import FromSequence
from nanospherical import NanoSpherical
from polynomial import Polynomial
16 changes: 8 additions & 8 deletions diffpy/srmise/dataclusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ def cut(self, idx):
def cluster_boundaries(self):
"""Return sequence with (x,y) of all cluster boundaries."""
boundaries = []
for l in self.clusters:
xlo = np.mean(self.x[l[0] - 1 : l[0] + 1])
ylo = np.mean(self.y[l[0] - 1 : l[0] + 1])
xhi = np.mean(self.x[l[1] : l[1] + 2])
yhi = np.mean(self.y[l[1] : l[1] + 2])
for cluster in self.clusters:
xlo = np.mean(self.x[cluster[0] - 1 : cluster[0] + 1])
ylo = np.mean(self.y[cluster[0] - 1 : cluster[0] + 1])
xhi = np.mean(self.x[cluster[1] : cluster[1] + 2])
yhi = np.mean(self.y[cluster[1] : cluster[1] + 2])
boundaries.append((xlo, ylo))
boundaries.append((xhi, yhi))
return np.unique(boundaries)
Expand Down Expand Up @@ -416,9 +416,9 @@ def animate(self):
all_lines[i].set_ydata([0, height])
ax.draw_artist(all_lines[i])
else:
l = plt.axvline(b[0], 0, height, color="k", animated=True)
ax.draw_artist(l)
all_lines.append(l)
line = plt.axvline(b[0], 0, height, color="k", animated=True)
ax.draw_artist(line)
all_lines.append(line)
canvas.blit(ax.bbox)

self.clusters = clusters
Expand Down
5 changes: 0 additions & 5 deletions diffpy/srmise/modelevaluators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,3 @@
# See LICENSE.txt for license information.
#
##############################################################################

__all__ = ["base", "aic", "aicc"]

from aic import AIC
from aicc import AICc
13 changes: 7 additions & 6 deletions diffpy/srmise/modelevaluators/aicc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import numpy as np

import diffpy.srmise.srmiselog
from diffpy.srmise.modelevaluators.base import ModelEvaluator
from diffpy.srmise.srmiseerrors import SrMiseModelEvaluatorError

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

if self.chisq == None:
if self.chisq is None:
self.chisq = self.chi_squared(fit.value(), fit.y_cluster, fit.error_cluster)

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

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

if self.chisq is None:
Expand Down
22 changes: 10 additions & 12 deletions diffpy/srmise/modelparts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@

import logging

import numpy as np
from scipy.optimize import leastsq

from diffpy.srmise import srmiselog
from diffpy.srmise.srmiseerrors import *

logger = logging.getLogger("diffpy.srmise")

import matplotlib.pyplot as plt
import numpy as np

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

from diffpy.srmise import srmiselog
from diffpy.srmise.srmiseerrors import SrMiseFitError, SrMiseStaticOwnerError, SrMiseUndefinedCovarianceError

logger = logging.getLogger("diffpy.srmise")
__spv__ = pr.get_distribution("scipy").version
__oldleastsqbehavior__ = pr.parse_version(__spv__) < pr.parse_version("0.8.0")

Expand Down Expand Up @@ -98,7 +96,7 @@ def fit(
# raise SrMiseFitError(emsg)
return

if range == None:
if range is None:
range = slice(None)

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

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

for k, v in kwds.items():
try:
idx = int(k[1:])
int(k[1:])
except ValueError:
emsg = "Invalid format keyword '%s'. They must be specified as 'f0', 'f1', etc." % k
raise ValueError(emsg)
Expand Down Expand Up @@ -559,7 +557,7 @@ def npars(self, count_fixed=True):
if count_fixed:
return self._owner.npars
else:
return (self.free == True).sum()
return (self.free is True).sum()

def __str__(self):
"""Return string representation of ModelPart parameters."""
Expand Down
2 changes: 0 additions & 2 deletions diffpy/srmise/peaks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@
# See LICENSE.txt for license information.
#
##############################################################################

__all__ = ["base", "gaussian", "gaussianoverr", "terminationripples"]

0 comments on commit c0d43e6

Please sign in to comment.