diff --git a/diffpy/srmise/baselines/arbitrary.py b/diffpy/srmise/baselines/arbitrary.py index d2bc487..4e78be4 100644 --- a/diffpy/srmise/baselines/arbitrary.py +++ b/diffpy/srmise/baselines/arbitrary.py @@ -13,10 +13,8 @@ import logging -import matplotlib.pyplot as plt import numpy as np -import diffpy.srmise.srmiselog from diffpy.srmise.baselines import Polynomial from diffpy.srmise.baselines.base import BaselineFunction from diffpy.srmise.srmiseerrors import SrMiseEstimationError @@ -97,7 +95,7 @@ def __init__(self, npars, valuef, jacobianf=None, estimatef=None, Cache=None): metadict["estimatef"] = (estimatef, repr) BaselineFunction.__init__(self, parameterdict, formats, default_formats, metadict, None, Cache) - #### Methods required by BaselineFunction #### + # Methods required by BaselineFunction #### def estimate_parameters(self, r, y): """Estimate parameters for data baseline. @@ -133,7 +131,7 @@ def _jacobianraw(self, pars, r, free): needed. True for evaluation, False for no evaluation.""" nfree = None if self.jacobianf is None: - nfree = (pars == True).sum() + nfree = (pars is True).sum() if nfree != 0: emsg = "No jacobian routine provided to Arbitrary." raise NotImplementedError(emsg) diff --git a/diffpy/srmise/baselines/base.py b/diffpy/srmise/baselines/base.py index 3f3844a..781d617 100644 --- a/diffpy/srmise/baselines/base.py +++ b/diffpy/srmise/baselines/base.py @@ -15,10 +15,9 @@ import numpy as np -import diffpy.srmise.srmiselog from diffpy.srmise.basefunction import BaseFunction from diffpy.srmise.modelparts import ModelPart -from diffpy.srmise.srmiseerrors import * +from diffpy.srmise.srmiseerrors import SrMiseDataFormatError logger = logging.getLogger("diffpy.srmise") @@ -85,9 +84,9 @@ def __init__( evaluations.""" BaseFunction.__init__(self, parameterdict, parformats, default_formats, metadict, base, Cache) - #### "Virtual" class methods #### + # "Virtual" class methods #### - #### Methods required by BaseFunction #### + # Methods required by BaseFunction #### def actualize( self, @@ -136,17 +135,16 @@ def factory(baselinestr, ownerlist): baselinestr: string representing Baseline ownerlist: List of BaseFunctions that owner is in """ - from numpy import array data = baselinestr.strip().splitlines() # dictionary of parameters pdict = {} for d in data: - l = d.split("=", 1) - if len(l) == 2: + result = d.split("=", 1) + if len(result) == 2: try: - pdict[l[0]] = eval(l[1]) + pdict[result[0]] = eval(result[1]) except Exception: emsg = "Invalid parameter: %s" % d raise SrMiseDataFormatError(emsg) @@ -169,10 +167,8 @@ def factory(baselinestr, ownerlist): # simple test code if __name__ == "__main__": - import matplotlib.pyplot as plt from numpy.random import randn - from diffpy.srmise.modelcluster import ModelCluster from diffpy.srmise.modelevaluators import AICc from diffpy.srmise.peaks import GaussianOverR, Peaks diff --git a/diffpy/srmise/baselines/fromsequence.py b/diffpy/srmise/baselines/fromsequence.py index 718051a..5d770a5 100644 --- a/diffpy/srmise/baselines/fromsequence.py +++ b/diffpy/srmise/baselines/fromsequence.py @@ -13,11 +13,9 @@ import logging -import matplotlib.pyplot as plt import numpy as np import scipy.interpolate as spi -import diffpy.srmise.srmiselog from diffpy.srmise.baselines.base import BaselineFunction logger = logging.getLogger("diffpy.srmise") @@ -80,7 +78,7 @@ def __init__(self, *args, **kwds): metadict["y"] = (y, self.xyrepr) BaselineFunction.__init__(self, parameterdict, formats, default_formats, metadict, None, Cache=None) - #### Methods required by BaselineFunction #### + # Methods required by BaselineFunction #### def estimate_parameters(self, r, y): """Return empty numpy array. @@ -151,7 +149,7 @@ def _valueraw(self, pars, r): [r[0], r[-1]], [self.minx, self.maxx], ) - except (IndexError, TypeError) as e: + except (IndexError, TypeError): if r < self.minx or r > self.maxx: logger.warn( "Warning: Evaluating interpolating function at %s, outside safe range of %s.", @@ -169,7 +167,7 @@ def xyrepr(self, var): def readxy(self, filename): """ """ - from diffpy.srmise.srmiseerrors import SrMiseDataFormatError, SrMiseFileError + from diffpy.srmise.srmiseerrors import SrMiseDataFormatError # TODO: Make this safer try: diff --git a/diffpy/srmise/baselines/nanospherical.py b/diffpy/srmise/baselines/nanospherical.py index 88de784..929a66f 100644 --- a/diffpy/srmise/baselines/nanospherical.py +++ b/diffpy/srmise/baselines/nanospherical.py @@ -13,12 +13,9 @@ import logging -import matplotlib.pyplot as plt import numpy as np -import diffpy.srmise.srmiselog from diffpy.srmise.baselines.base import BaselineFunction -from diffpy.srmise.srmiseerrors import SrMiseEstimationError logger = logging.getLogger("diffpy.srmise") @@ -54,7 +51,7 @@ def __init__(self, Cache=None): metadict = {} BaselineFunction.__init__(self, parameterdict, formats, default_formats, metadict, None, Cache) - #### Methods required by BaselineFunction #### + # Methods required by BaselineFunction #### # def estimate_parameters(self, r, y): # """Estimate parameters for spherical baseline. (Not implemented!) @@ -90,7 +87,7 @@ def _jacobianraw(self, pars, r, free): emsg = "Argument free must have " + str(self.npars) + " elements." raise ValueError(emsg) jacobian = [None for p in range(self.npars)] - if (free == False).sum() == self.npars: + if (free is False).sum() == self.npars: return jacobian if np.isscalar(r): @@ -123,7 +120,7 @@ def _jacobianrawscale(self, pars, r): pars[1] = radius r - sequence or scalar over which pars is evaluated. """ - s = np.abs(pars[0]) + np.abs(pars[0]) R = np.abs(pars[1]) rdivR = r / R # From abs'(s) in derivative, which is equivalent to sign(s) except at 0 where it