Skip to content

Commit

Permalink
fix too many leading #, import modules, and unused var (diffpy#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhua0320 authored Jul 30, 2024
1 parent ff0fc58 commit 7c77b11
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 33 deletions.
17 changes: 7 additions & 10 deletions diffpy/srmise/peaks/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

import logging

import matplotlib.pyplot as plt
import numpy as np

import diffpy.srmise.srmiselog
from diffpy.srmise.peaks.base import PeakFunction
from diffpy.srmise.srmiseerrors import SrMiseEstimationError, SrMiseScalingError, SrMiseTransformationError

Expand Down Expand Up @@ -59,7 +57,7 @@ def __init__(self, maxwidth, Cache=None):
raise ValueError(emsg)
self.maxwidth = maxwidth

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

return

#### Methods required by PeakFunction ####
# Methods required by PeakFunction ####

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

#### Estimation ####
# Estimation ####
guesspars = np.array([0.0, 0.0, 0.0], dtype=float)
min_y = use_y.min()
max_y = use_y.max()
center = use_r[use_y.argmax()]

if min_y != max_y:
weights = (use_y - min_y) ** 2
Expand Down Expand Up @@ -204,7 +201,7 @@ def _jacobianraw(self, pars, r, free):
needed. True for evaluation, False for no evaluation.
"""
jacobian = [None, None, None]
if (free == False).sum() == self.npars:
if (free is False).sum() == self.npars:
return jacobian

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

#### Other methods ####
# Other methods ####

def max(self, pars):
"""Return position and height of the peak maximum."""
Expand Down
17 changes: 7 additions & 10 deletions diffpy/srmise/peaks/gaussianoverr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

import logging

import matplotlib.pyplot as plt
import numpy as np

import diffpy.srmise.srmiselog
from diffpy.srmise.peaks.base import PeakFunction
from diffpy.srmise.srmiseerrors import SrMiseEstimationError, SrMiseScalingError, SrMiseTransformationError

Expand Down Expand Up @@ -59,7 +57,7 @@ def __init__(self, maxwidth, Cache=None):
raise ValueError(emsg)
self.maxwidth = maxwidth

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

return

#### Methods required by PeakFunction ####
# Methods required by PeakFunction ####

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

#### Estimation ####
# Estimation ####
guesspars = np.array([0.0, 0.0, 0.0], dtype=float)
min_y = use_y.min()
max_y = use_y.max()
center = use_r[use_y.argmax()]

if min_y != max_y:
weights = (use_y - min_y) ** 2
Expand Down Expand Up @@ -218,7 +215,7 @@ def _jacobianraw(self, pars, r, free):
needed. True for evaluation, False for no evaluation.
"""
jacobian = [None, None, None]
if (free == False).sum() == self.npars:
if (free is False).sum() == self.npars:
return jacobian

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

#### Other methods ####
# Other methods ####

def max(self, pars):
"""Return position and height of the peak maximum."""
Expand Down
15 changes: 7 additions & 8 deletions diffpy/srmise/peaks/terminationripples.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import numpy as np
import scipy.fftpack as fp

import diffpy.srmise.srmiselog
from diffpy.srmise.peaks.base import PeakFunction

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

#### Methods required by PeakFunction ####
# Methods required by PeakFunction ####

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

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

#### Other methods ####
# Other methods ####

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

from diffpy.srmise.modelcluster import ModelCluster
from diffpy.srmise.modelevaluator import AICc
from diffpy.srmise.peakfunctions.gaussianoverr import GaussianOverR
from diffpy.srmise.peakfunctions.peaks import Peaks
from diffpy.srmise.peakfunctions.terminationripples import TerminationRipples
from diffpy.srmise.modelevaluators import AICc
from diffpy.srmise.peaks import Peaks
from diffpy.srmise.peaks.gaussianoverr import GaussianOverR
from diffpy.srmise.peaks.terminationripples import TerminationRipples

res = 0.01
r = np.arange(2, 4, res)
Expand Down
6 changes: 3 additions & 3 deletions diffpy/srmise/peakstability.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setppe(self, ppe):
def load(self, filename):
try:
import cPickle as pickle
except:
except ImportError:
import pickle

in_s = open(filename, "rb")
Expand Down Expand Up @@ -68,7 +68,7 @@ def load(self, filename):
def save(self, filename):
try:
import cPickle as pickle
except:
except ImportError:
import pickle
out_s = open(filename, "wb")
try:
Expand Down Expand Up @@ -150,7 +150,7 @@ def animate(self, results=None, step=False, **kwds):
self.setcurrent(0)
plt.ion()
plt.plot(*self.ppe.extracted.plottable())
a = plt.axis()
plt.axis()
for i in results:
self.setcurrent(i)
plt.ioff()
Expand Down
4 changes: 2 additions & 2 deletions diffpy/srmise/srmiseerrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"""


### Superclass class for diffpy.srmise.mise
# Superclass class for diffpy.srmise.mise
class SrMiseError(Exception):
"""Superclass of all diffpy.srmise exceptions."""

Expand All @@ -43,7 +43,7 @@ def __str__(self):
return self.info


### SrMiseError subclasses ###
# SrMiseError subclasses ###


class SrMiseDataFormatError(SrMiseError):
Expand Down

0 comments on commit 7c77b11

Please sign in to comment.