Skip to content

remove unused modules, ambiguous variable name #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions diffpy/srmise/baselines/polynomial.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.base import BaselineFunction
from diffpy.srmise.srmiseerrors import SrMiseEstimationError

Expand Down Expand Up @@ -54,7 +52,7 @@ def __init__(self, degree, Cache=None):
metadict["degree"] = (degree, 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 polynomial baseline.
Expand Down Expand Up @@ -124,7 +122,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

# The partial derivative with respect to the nth coefficient of a
Expand Down
2 changes: 0 additions & 2 deletions diffpy/srmise/dataclusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import matplotlib.pyplot as plt
import numpy as np

import diffpy.srmise.srmiselog

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


Expand Down
37 changes: 17 additions & 20 deletions diffpy/srmise/modelcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import re
import sys

import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
from scipy.optimize import leastsq

from diffpy.srmise import srmiselog
from diffpy.srmise.baselines import Baseline
from diffpy.srmise.modelparts import ModelParts
from diffpy.srmise.peaks import Peak, Peaks
Expand All @@ -39,8 +37,6 @@

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

from diffpy.srmise import srmiselog


class ModelCovariance(object):
"""Helper class preserves uncertainty info (full covariance matrix) for a fit model.
Expand Down Expand Up @@ -201,8 +197,8 @@ def transform(self, in_format, out_format, **kwds):
subg = np.identity(p.npars(True))
except Exception as e:
logger.warning(
"Transformation gradient failed for part %i: %s. Failed with message %s. Ignoring transformation."
% (i, str(p), str(e))
"Transformation gradient failed for part %i: %s. "
"Failed with message %s. Ignoring transformation." % (i, str(p), str(e))
)
subg = np.identity(p.npars(True))

Expand All @@ -211,8 +207,8 @@ def transform(self, in_format, out_format, **kwds):
p.pars = p.owner().transform_parameters(p.pars, in_format, out_format)
except Exception as e:
logger.warning(
"Parameter transformation failed for part %i: %s. Failed with message %s. Ignoring transformation."
% (i, str(p), str(e))
"Parameter transformation failed for part %i: %s. "
"Failed with message %s. Ignoring transformation." % (i, str(p), str(e))
)
subg = np.identity(p.npars(True))

Expand Down Expand Up @@ -600,21 +596,21 @@ def factory(mcstr, **kwds):
baselinefunctions = header[res.end() :].strip()
header = header[: res.start()]

### Instantiating baseline functions
# Instantiating baseline functions
if readblf:
blfbaselist = []
res = re.split(r"(?m)^#+ BaselineFunction \d+\s*(?:#.*\s+)*", baselinefunctions)
for s in res[1:]:
blfbaselist.append(BaseFunction.factory(s, blfbaselist))

### Instantiating peak functions
# Instantiating peak functions
if readpf:
pfbaselist = []
res = re.split(r"(?m)^#+ PeakFunction \d+\s*(?:#.*\s+)*", peakfunctions)
for s in res[1:]:
pfbaselist.append(BaseFunction.factory(s, pfbaselist))

### Instantiating header data
# Instantiating header data
# peak_funcs
res = re.search(r"^peak_funcs=(.*)$", header, re.M)
peak_funcs = eval(res.groups()[0].strip())
Expand All @@ -631,19 +627,19 @@ def factory(mcstr, **kwds):
res = re.search(r"^slice=(.*)$", header, re.M)
cluster_slice = eval(res.groups()[0].strip())

### Instantiating BaselineObject
# Instantiating BaselineObject
if re.match(r"^None$", baselineobject):
baseline = None
else:
baseline = Baseline.factory(baselineobject, blfbaselist)

### Instantiating model
# Instantiating model
model = Peaks()
res = re.split(r"(?m)^#+ ModelPeak\s*(?:#.*\s+)*", model_peaks)
for s in res[1:]:
model.append(Peak.factory(s, pfbaselist))

### Instantiating start data
# Instantiating start data
# read actual data - r, y, dy
arrays = []
if hasr:
Expand All @@ -664,9 +660,10 @@ def factory(mcstr, **kwds):
# raise SrMiseDataFormatError if something goes wrong
try:
for line in start_data.split("\n"):
l = line.split()
if len(arrays) != len(l):
lines = line.split()
if len(arrays) != len(lines):
emsg = "Number of value fields does not match that given by '%s'" % start_data_info
raise IndexError(emsg)
for a, v in zip(arrays, line.split()):
a.append(float(v))
except (ValueError, IndexError) as err:
Expand Down Expand Up @@ -847,7 +844,7 @@ def deletepeak(self, idx):

def estimatepeak(self):
"""Attempt to add single peak to empty cluster. Return True if successful."""
### STUB!!! ###
# STUB!!! ###
# Currently only a single peak function is supported. Dynamic
# selection from multiple types may require additional support
# within peak functions themselves. The simplest method would
Expand Down Expand Up @@ -901,7 +898,7 @@ def fit(
if estimate:
try:
self.estimatepeak()
except SrMiseEstimationError as e:
except SrMiseEstimationError:
logger.info("Fit: No model to fit, estimation not possible.")
return
else:
Expand Down Expand Up @@ -1278,7 +1275,7 @@ def prune(self):
msg = ["====Pruning fits:====", "Original model:", "%s", "w/ quality: %s"]
logger.info("\n".join(msg), best_model, best_qual.stat)

#### Main prune loop ####
# Main prune loop ####
while check_models.count(None) < len(check_models):

# Cache value of individual peaks for best current model.
Expand Down
4 changes: 2 additions & 2 deletions diffpy/srmise/srmiselog.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ def readstr(self, datastring):

res = re.search(r"^recursion=(.*)$", header, re.M)
if res:
recursion = eval(res.groups()[0].strip())
eval(res.groups()[0].strip())
else:
emsg = "Required field 'recursion' not found."
raise SrMiseDataFormatError(emsg)

res = re.search(r"^counter=(.*)$", header, re.M)
if res:
counter = eval(res.groups()[0].strip())
eval(res.groups()[0].strip())
else:
emsg = "Required field 'counter' not found."
raise SrMiseDataFormatError(emsg)
Expand Down
Loading