Skip to content

Commit 7c77b11

Browse files
fix too many leading #, import modules, and unused var (#29)
1 parent ff0fc58 commit 7c77b11

File tree

5 files changed

+26
-33
lines changed

5 files changed

+26
-33
lines changed

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313

1414
import logging
1515

16-
import matplotlib.pyplot as plt
1716
import numpy as np
1817

19-
import diffpy.srmise.srmiselog
2018
from diffpy.srmise.peaks.base import PeakFunction
2119
from diffpy.srmise.srmiseerrors import SrMiseEstimationError, SrMiseScalingError, SrMiseTransformationError
2220

@@ -59,7 +57,7 @@ def __init__(self, maxwidth, Cache=None):
5957
raise ValueError(emsg)
6058
self.maxwidth = maxwidth
6159

62-
### Useful constants ###
60+
# Useful constants ###
6361
# c1 and c2 help with function values
6462
self.c1 = self.maxwidth * np.sqrt(np.pi / (8 * np.log(2)))
6563
self.c2 = self.maxwidth**2 / (8 * np.log(2))
@@ -73,7 +71,7 @@ def __init__(self, maxwidth, Cache=None):
7371

7472
return
7573

76-
#### Methods required by PeakFunction ####
74+
# Methods required by PeakFunction ####
7775

7876
def estimate_parameters(self, r, y):
7977
"""Estimate parameters for single peak from data provided.
@@ -102,11 +100,10 @@ def estimate_parameters(self, r, y):
102100
emsg = "Not enough data for successful estimation."
103101
raise SrMiseEstimationError(emsg)
104102

105-
#### Estimation ####
103+
# Estimation ####
106104
guesspars = np.array([0.0, 0.0, 0.0], dtype=float)
107105
min_y = use_y.min()
108106
max_y = use_y.max()
109-
center = use_r[use_y.argmax()]
110107

111108
if min_y != max_y:
112109
weights = (use_y - min_y) ** 2
@@ -204,7 +201,7 @@ def _jacobianraw(self, pars, r, free):
204201
needed. True for evaluation, False for no evaluation.
205202
"""
206203
jacobian = [None, None, None]
207-
if (free == False).sum() == self.npars:
204+
if (free is False).sum() == self.npars:
208205
return jacobian
209206

210207
# Optimization
@@ -228,8 +225,8 @@ def _jacobianraw(self, pars, r, free):
228225
# derivative with respect to peak area
229226
# abs'(x)=sign(x) for real x except at 0 where it is undetermined. Since any real peak necessarily has
230227
# non-zero area and the function is paramaterized such that values of either sign represent equivalent
231-
# curves I arbitrarily choose positive sign for pars[2]==0 in order to push the system back into a realistic
232-
# parameter space should this improbable scenario occur.
228+
# curves I arbitrarily choose positive sign for pars[2]==0 in order to
229+
# push the system back into a realistic parameter space should this improbable scenario occur.
233230
# jacobian[2] = sign(pars[2])*exp_p
234231
if pars[2] >= 0:
235232
jacobian[2] = exp_p
@@ -321,7 +318,7 @@ def _valueraw(self, pars, r):
321318
def getmodule(self):
322319
return __name__
323320

324-
#### Other methods ####
321+
# Other methods ####
325322

326323
def max(self, pars):
327324
"""Return position and height of the peak maximum."""

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313

1414
import logging
1515

16-
import matplotlib.pyplot as plt
1716
import numpy as np
1817

19-
import diffpy.srmise.srmiselog
2018
from diffpy.srmise.peaks.base import PeakFunction
2119
from diffpy.srmise.srmiseerrors import SrMiseEstimationError, SrMiseScalingError, SrMiseTransformationError
2220

@@ -59,7 +57,7 @@ def __init__(self, maxwidth, Cache=None):
5957
raise ValueError(emsg)
6058
self.maxwidth = maxwidth
6159

62-
### Useful constants ###
60+
# Useful constants ###
6361
# c1 and c2 help with function values
6462
self.c1 = self.maxwidth * np.sqrt(np.pi / (8 * np.log(2)))
6563
self.c2 = self.maxwidth**2 / (8 * np.log(2))
@@ -73,7 +71,7 @@ def __init__(self, maxwidth, Cache=None):
7371

7472
return
7573

76-
#### Methods required by PeakFunction ####
74+
# Methods required by PeakFunction ####
7775

7876
def estimate_parameters(self, r, y):
7977
"""Estimate parameters for single peak from data provided.
@@ -102,11 +100,10 @@ def estimate_parameters(self, r, y):
102100
emsg = "Not enough data for successful estimation."
103101
raise SrMiseEstimationError(emsg)
104102

105-
#### Estimation ####
103+
# Estimation ####
106104
guesspars = np.array([0.0, 0.0, 0.0], dtype=float)
107105
min_y = use_y.min()
108106
max_y = use_y.max()
109-
center = use_r[use_y.argmax()]
110107

111108
if min_y != max_y:
112109
weights = (use_y - min_y) ** 2
@@ -218,7 +215,7 @@ def _jacobianraw(self, pars, r, free):
218215
needed. True for evaluation, False for no evaluation.
219216
"""
220217
jacobian = [None, None, None]
221-
if (free == False).sum() == self.npars:
218+
if (free is False).sum() == self.npars:
222219
return jacobian
223220

224221
# Optimization
@@ -242,8 +239,8 @@ def _jacobianraw(self, pars, r, free):
242239
# derivative with respect to peak area
243240
# abs'(x)=sign(x) for real x except at 0 where it is undetermined. Since any real peak necessarily has
244241
# non-zero area and the function is paramaterized such that values of either sign represent equivalent
245-
# curves I arbitrarily choose positive sign for pars[2]==0 in order to push the system back into a realistic
246-
# parameter space should this improbable scenario occur.
242+
# curves I arbitrarily choose positive sign for pars[2]==0 in order to
243+
# push the system back into a realistic parameter space should this improbable scenario occur.
247244
# jacobian[2] = sign(pars[2])*exp_p
248245
if pars[2] >= 0:
249246
jacobian[2] = exp_p
@@ -387,7 +384,7 @@ def _valueraw(self, pars, r):
387384
def getmodule(self):
388385
return __name__
389386

390-
#### Other methods ####
387+
# Other methods ####
391388

392389
def max(self, pars):
393390
"""Return position and height of the peak maximum."""

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import numpy as np
1717
import scipy.fftpack as fp
1818

19-
import diffpy.srmise.srmiselog
2019
from diffpy.srmise.peaks.base import PeakFunction
2120

2221
logger = logging.getLogger("diffpy.srmise")
@@ -55,7 +54,7 @@ def __init__(self, base, qmax, extension=4.0, supersample=5.0, Cache=None):
5554
PeakFunction.__init__(self, parameterdict, formats, default_formats, metadict, base, Cache)
5655
return
5756

58-
#### Methods required by PeakFunction ####
57+
# Methods required by PeakFunction ####
5958

6059
# TODO: A smart way to convert from the basefunctions estimate to an
6160
# appropriate one when ripples are considered. This may not be necessary,
@@ -122,7 +121,7 @@ def _valueraw(self, pars, r):
122121
r: sequence or scalar over which pars is evaluated"""
123122
return self.base._valueraw(pars, r)
124123

125-
#### Overridden PeakFunction functions ####
124+
# Overridden PeakFunction functions ####
126125
# jacobian() and value() are not normally overridden by PeakFunction
127126
# subclasses, but are here to minimize the effect of edge-effects while
128127
# introducing termination ripples.
@@ -236,7 +235,7 @@ def value(self, peak, r, rng=None):
236235
def getmodule(self):
237236
return __name__
238237

239-
#### Other methods ####
238+
# Other methods ####
240239

241240
def cut_freq(self, sequence, delta):
242241
"""Remove high-frequency components from sequence.
@@ -278,10 +277,10 @@ def extend_grid(self, r, dr):
278277
from numpy.random import randn
279278

280279
from diffpy.srmise.modelcluster import ModelCluster
281-
from diffpy.srmise.modelevaluator import AICc
282-
from diffpy.srmise.peakfunctions.gaussianoverr import GaussianOverR
283-
from diffpy.srmise.peakfunctions.peaks import Peaks
284-
from diffpy.srmise.peakfunctions.terminationripples import TerminationRipples
280+
from diffpy.srmise.modelevaluators import AICc
281+
from diffpy.srmise.peaks import Peaks
282+
from diffpy.srmise.peaks.gaussianoverr import GaussianOverR
283+
from diffpy.srmise.peaks.terminationripples import TerminationRipples
285284

286285
res = 0.01
287286
r = np.arange(2, 4, res)

Diff for: diffpy/srmise/peakstability.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def setppe(self, ppe):
4040
def load(self, filename):
4141
try:
4242
import cPickle as pickle
43-
except:
43+
except ImportError:
4444
import pickle
4545

4646
in_s = open(filename, "rb")
@@ -68,7 +68,7 @@ def load(self, filename):
6868
def save(self, filename):
6969
try:
7070
import cPickle as pickle
71-
except:
71+
except ImportError:
7272
import pickle
7373
out_s = open(filename, "wb")
7474
try:
@@ -150,7 +150,7 @@ def animate(self, results=None, step=False, **kwds):
150150
self.setcurrent(0)
151151
plt.ion()
152152
plt.plot(*self.ppe.extracted.plottable())
153-
a = plt.axis()
153+
plt.axis()
154154
for i in results:
155155
self.setcurrent(i)
156156
plt.ioff()

Diff for: diffpy/srmise/srmiseerrors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"""
2929

3030

31-
### Superclass class for diffpy.srmise.mise
31+
# Superclass class for diffpy.srmise.mise
3232
class SrMiseError(Exception):
3333
"""Superclass of all diffpy.srmise exceptions."""
3434

@@ -43,7 +43,7 @@ def __str__(self):
4343
return self.info
4444

4545

46-
### SrMiseError subclasses ###
46+
# SrMiseError subclasses ###
4747

4848

4949
class SrMiseDataFormatError(SrMiseError):

0 commit comments

Comments
 (0)