From 0f54e972e67145f1452713f694c60259c10f5209 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Tue, 30 Jul 2024 17:40:20 +0800 Subject: [PATCH] fix too many leading #, import modules, and unused var --- diffpy/srmise/peaks/gaussian.py | 17 +++++++---------- diffpy/srmise/peaks/gaussianoverr.py | 17 +++++++---------- diffpy/srmise/peaks/terminationripples.py | 15 +++++++-------- diffpy/srmise/peakstability.py | 6 +++--- diffpy/srmise/srmiseerrors.py | 4 ++-- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/diffpy/srmise/peaks/gaussian.py b/diffpy/srmise/peaks/gaussian.py index 3913b6c..15ea447 100644 --- a/diffpy/srmise/peaks/gaussian.py +++ b/diffpy/srmise/peaks/gaussian.py @@ -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 @@ -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)) @@ -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. @@ -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 @@ -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 @@ -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 @@ -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.""" diff --git a/diffpy/srmise/peaks/gaussianoverr.py b/diffpy/srmise/peaks/gaussianoverr.py index d11467d..28df1a8 100644 --- a/diffpy/srmise/peaks/gaussianoverr.py +++ b/diffpy/srmise/peaks/gaussianoverr.py @@ -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 @@ -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)) @@ -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. @@ -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 @@ -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 @@ -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 @@ -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.""" diff --git a/diffpy/srmise/peaks/terminationripples.py b/diffpy/srmise/peaks/terminationripples.py index 68f52ba..4706e8f 100644 --- a/diffpy/srmise/peaks/terminationripples.py +++ b/diffpy/srmise/peaks/terminationripples.py @@ -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") @@ -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, @@ -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. @@ -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. @@ -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) diff --git a/diffpy/srmise/peakstability.py b/diffpy/srmise/peakstability.py index d704b41..26952b2 100644 --- a/diffpy/srmise/peakstability.py +++ b/diffpy/srmise/peakstability.py @@ -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") @@ -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: @@ -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() diff --git a/diffpy/srmise/srmiseerrors.py b/diffpy/srmise/srmiseerrors.py index f7ef037..ed5287f 100644 --- a/diffpy/srmise/srmiseerrors.py +++ b/diffpy/srmise/srmiseerrors.py @@ -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.""" @@ -43,7 +43,7 @@ def __str__(self): return self.info -### SrMiseError subclasses ### +# SrMiseError subclasses ### class SrMiseDataFormatError(SrMiseError):