Skip to content

Commit

Permalink
lint check, remove unused import modules & remove too many "#". (diff…
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhua0320 authored Jul 30, 2024
1 parent 8772a95 commit ffe5fc7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
6 changes: 2 additions & 4 deletions diffpy/srmise/baselines/arbitrary.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.baselines import Polynomial
from diffpy.srmise.baselines.base import BaselineFunction
from diffpy.srmise.srmiseerrors import SrMiseEstimationError
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 6 additions & 10 deletions diffpy/srmise/baselines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
8 changes: 3 additions & 5 deletions diffpy/srmise/baselines/fromsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.",
Expand All @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions diffpy/srmise/baselines/nanospherical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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!)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ffe5fc7

Please sign in to comment.