Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ffe5fc7

Browse files
authoredJul 30, 2024··
lint check, remove unused import modules & remove too many "#". (#27)
1 parent 8772a95 commit ffe5fc7

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed
 

‎diffpy/srmise/baselines/arbitrary.py

+2-4
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.baselines import Polynomial
2119
from diffpy.srmise.baselines.base import BaselineFunction
2220
from diffpy.srmise.srmiseerrors import SrMiseEstimationError
@@ -97,7 +95,7 @@ def __init__(self, npars, valuef, jacobianf=None, estimatef=None, Cache=None):
9795
metadict["estimatef"] = (estimatef, repr)
9896
BaselineFunction.__init__(self, parameterdict, formats, default_formats, metadict, None, Cache)
9997

100-
#### Methods required by BaselineFunction ####
98+
# Methods required by BaselineFunction ####
10199

102100
def estimate_parameters(self, r, y):
103101
"""Estimate parameters for data baseline.
@@ -133,7 +131,7 @@ def _jacobianraw(self, pars, r, free):
133131
needed. True for evaluation, False for no evaluation."""
134132
nfree = None
135133
if self.jacobianf is None:
136-
nfree = (pars == True).sum()
134+
nfree = (pars is True).sum()
137135
if nfree != 0:
138136
emsg = "No jacobian routine provided to Arbitrary."
139137
raise NotImplementedError(emsg)

‎diffpy/srmise/baselines/base.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515

1616
import numpy as np
1717

18-
import diffpy.srmise.srmiselog
1918
from diffpy.srmise.basefunction import BaseFunction
2019
from diffpy.srmise.modelparts import ModelPart
21-
from diffpy.srmise.srmiseerrors import *
20+
from diffpy.srmise.srmiseerrors import SrMiseDataFormatError
2221

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

@@ -85,9 +84,9 @@ def __init__(
8584
evaluations."""
8685
BaseFunction.__init__(self, parameterdict, parformats, default_formats, metadict, base, Cache)
8786

88-
#### "Virtual" class methods ####
87+
# "Virtual" class methods ####
8988

90-
#### Methods required by BaseFunction ####
89+
# Methods required by BaseFunction ####
9190

9291
def actualize(
9392
self,
@@ -136,17 +135,16 @@ def factory(baselinestr, ownerlist):
136135
baselinestr: string representing Baseline
137136
ownerlist: List of BaseFunctions that owner is in
138137
"""
139-
from numpy import array
140138

141139
data = baselinestr.strip().splitlines()
142140

143141
# dictionary of parameters
144142
pdict = {}
145143
for d in data:
146-
l = d.split("=", 1)
147-
if len(l) == 2:
144+
result = d.split("=", 1)
145+
if len(result) == 2:
148146
try:
149-
pdict[l[0]] = eval(l[1])
147+
pdict[result[0]] = eval(result[1])
150148
except Exception:
151149
emsg = "Invalid parameter: %s" % d
152150
raise SrMiseDataFormatError(emsg)
@@ -169,10 +167,8 @@ def factory(baselinestr, ownerlist):
169167
# simple test code
170168
if __name__ == "__main__":
171169

172-
import matplotlib.pyplot as plt
173170
from numpy.random import randn
174171

175-
from diffpy.srmise.modelcluster import ModelCluster
176172
from diffpy.srmise.modelevaluators import AICc
177173
from diffpy.srmise.peaks import GaussianOverR, Peaks
178174

‎diffpy/srmise/baselines/fromsequence.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
import logging
1515

16-
import matplotlib.pyplot as plt
1716
import numpy as np
1817
import scipy.interpolate as spi
1918

20-
import diffpy.srmise.srmiselog
2119
from diffpy.srmise.baselines.base import BaselineFunction
2220

2321
logger = logging.getLogger("diffpy.srmise")
@@ -80,7 +78,7 @@ def __init__(self, *args, **kwds):
8078
metadict["y"] = (y, self.xyrepr)
8179
BaselineFunction.__init__(self, parameterdict, formats, default_formats, metadict, None, Cache=None)
8280

83-
#### Methods required by BaselineFunction ####
81+
# Methods required by BaselineFunction ####
8482

8583
def estimate_parameters(self, r, y):
8684
"""Return empty numpy array.
@@ -151,7 +149,7 @@ def _valueraw(self, pars, r):
151149
[r[0], r[-1]],
152150
[self.minx, self.maxx],
153151
)
154-
except (IndexError, TypeError) as e:
152+
except (IndexError, TypeError):
155153
if r < self.minx or r > self.maxx:
156154
logger.warn(
157155
"Warning: Evaluating interpolating function at %s, outside safe range of %s.",
@@ -169,7 +167,7 @@ def xyrepr(self, var):
169167

170168
def readxy(self, filename):
171169
""" """
172-
from diffpy.srmise.srmiseerrors import SrMiseDataFormatError, SrMiseFileError
170+
from diffpy.srmise.srmiseerrors import SrMiseDataFormatError
173171

174172
# TODO: Make this safer
175173
try:

‎diffpy/srmise/baselines/nanospherical.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
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.baselines.base import BaselineFunction
21-
from diffpy.srmise.srmiseerrors import SrMiseEstimationError
2219

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

@@ -54,7 +51,7 @@ def __init__(self, Cache=None):
5451
metadict = {}
5552
BaselineFunction.__init__(self, parameterdict, formats, default_formats, metadict, None, Cache)
5653

57-
#### Methods required by BaselineFunction ####
54+
# Methods required by BaselineFunction ####
5855

5956
# def estimate_parameters(self, r, y):
6057
# """Estimate parameters for spherical baseline. (Not implemented!)
@@ -90,7 +87,7 @@ def _jacobianraw(self, pars, r, free):
9087
emsg = "Argument free must have " + str(self.npars) + " elements."
9188
raise ValueError(emsg)
9289
jacobian = [None for p in range(self.npars)]
93-
if (free == False).sum() == self.npars:
90+
if (free is False).sum() == self.npars:
9491
return jacobian
9592

9693
if np.isscalar(r):
@@ -123,7 +120,7 @@ def _jacobianrawscale(self, pars, r):
123120
pars[1] = radius
124121
r - sequence or scalar over which pars is evaluated.
125122
"""
126-
s = np.abs(pars[0])
123+
np.abs(pars[0])
127124
R = np.abs(pars[1])
128125
rdivR = r / R
129126
# From abs'(s) in derivative, which is equivalent to sign(s) except at 0 where it

0 commit comments

Comments
 (0)
Please sign in to comment.