Skip to content

fix py2 -> py3, fix broken import, remove deprecation warning #47

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 2 commits into from
Aug 2, 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
5 changes: 3 additions & 2 deletions devutils/makesdist
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python

'''Create source distribution tar.gz archive, where each file belongs
"""Create source distribution tar.gz archive, where each file belongs
to a root user and modification time is set to the git commit time.
'''
"""

import sys
import os
Expand All @@ -28,6 +28,7 @@ tarname = max(glob.glob(BASEDIR + '/dist/*.tar'), key=os.path.getmtime)
tfin = tarfile.open(tarname)
tfout = tarfile.open(tarname + '.gz', 'w:gz')


def fixtarinfo(tinfo):
tinfo.uid = tinfo.gid = 0
tinfo.uname = tinfo.gname = 'root'
Expand Down
12 changes: 6 additions & 6 deletions src/diffpy/srmise/applications/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def main():
return

if options.bcrystal is not None:
from diffpy.srmise.baselines import Polynomial
from diffpy.srmise.baselines.polynomial import Polynomial

bl = Polynomial(degree=1)
options.baseline = parsepars(bl, [options.bcrystal, "0c"])
Expand All @@ -445,27 +445,27 @@ def main():
blext.read(options.bsrmise)
options.baseline = blext.extracted.baseline
elif options.bpoly0 is not None:
from diffpy.srmise.baselines import Polynomial
from diffpy.srmise.baselines.polynomial import Polynomial

bl = Polynomial(degree=0)
options.baseline = parsepars(bl, [options.bpoly0])
elif options.bpoly1 is not None:
from diffpy.srmise.baselines import Polynomial
from diffpy.srmise.baselines.polynomial import Polynomial

bl = Polynomial(degree=1)
options.baseline = parsepars(bl, options.bpoly1)
elif options.bpoly2 is not None:
from diffpy.srmise.baselines import Polynomial
from diffpy.srmise.baselines.polynomial import Polynomial

bl = Polynomial(degree=2)
options.baseline = parsepars(bl, options.bpoly2)
elif options.bseq is not None:
from diffpy.srmise.baselines import FromSequence
from diffpy.srmise.baselines.fromsequence import FromSequence

bl = FromSequence(options.bseq)
options.baseline = bl.actualize([], "internal")
elif options.bspherical is not None:
from diffpy.srmise.baselines import NanoSpherical
from diffpy.srmise.baselines.nanospherical import NanoSpherical

bl = NanoSpherical()
options.baseline = parsepars(bl, options.bspherical)
Expand Down
10 changes: 5 additions & 5 deletions src/diffpy/srmise/applications/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from matplotlib.ticker import MultipleLocator
from mpl_toolkits.axes_grid1.inset_locator import inset_axes

from diffpy.srmise import PDFPeakExtraction, PeakStability
from diffpy.srmise.pdfpeakextraction import resample
from diffpy.srmise.pdfpeakextraction import PDFPeakExtraction, resample
from diffpy.srmise.peakstability import PeakStability

# For a given figure, returns a label of interest
labeldict = {}
Expand Down Expand Up @@ -92,14 +92,14 @@ def comparepositions(ppe, ip=None, **kwds):
ep = [p for p in ep if p >= pmin and p <= pmax]

if ip is not None:
xi = np.NaN + np.zeros(3 * len(ip))
xi = np.nan + np.zeros(3 * len(ip))
xi[0::3] = ip
xi[1::3] = ip
yi = np.zeros_like(xi) + base
yi[1::3] += yideal
plt.plot(xi, yi, "b", lw=1.5, **ip_style)

xe = np.NaN + np.zeros(3 * len(ep))
xe = np.nan + np.zeros(3 * len(ep))
xe[0::3] = ep
xe[1::3] = ep
ye = np.zeros_like(xe) + base
Expand Down Expand Up @@ -185,7 +185,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):

if ppe.extracted is None:
# Makeplot requires a ModelCluster, so whip one up.
from diffpy.srmise import ModelCluster
from diffpy.srmise.modelcluster import ModelCluster

ppe.defaultvars() # Make sure everything has some setting. This
# shouldn't have harmful side effects.
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/srmise/baselines/arbitrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import numpy as np

from diffpy.srmise.baselines import Polynomial
from diffpy.srmise.baselines.base import BaselineFunction
from diffpy.srmise.baselines.polynomial import Polynomial
from diffpy.srmise.srmiseerrors import SrMiseEstimationError

logger = logging.getLogger("diffpy.srmise")
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, npars, valuef, jacobianf=None, estimatef=None, Cache=None):
# Define parameterdict
# e.g. {"a_0":0, "a_1":1, "a_2":2, "a_3":3} if npars is 4.
parameterdict = {}
for d in range(self.testnpars + 1):
for d in range(testnpars + 1):
parameterdict["a_" + str(d)] = d
formats = ["internal"]
default_formats = {"default_input": "internal", "default_output": "internal"}
Expand Down
5 changes: 3 additions & 2 deletions src/diffpy/srmise/baselines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ def factory(baselinestr, ownerlist):

from numpy.random import randn

from diffpy.srmise.modelevaluators import AICc
from diffpy.srmise.peaks import GaussianOverR, Peaks
from diffpy.srmise.modelevaluators.aicc import AICc
from diffpy.srmise.peaks.base import Peaks
from diffpy.srmise.peaks.gaussianoverr import GaussianOverR

res = 0.01
r = np.arange(2, 4, res)
Expand Down
8 changes: 4 additions & 4 deletions src/diffpy/srmise/baselines/fromsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ def _valueraw(self, pars, r):
raise ValueError(emsg)
try:
if r[0] < self.minx or r[-1] > self.maxx:
logger.warn(
logger.warning(
"Warning: Evaluating interpolating function over %s, outside safe range of %s.",
[r[0], r[-1]],
[self.minx, self.maxx],
)
except (IndexError, TypeError):
if r < self.minx or r > self.maxx:
logger.warn(
logger.warning(
"Warning: Evaluating interpolating function at %s, outside safe range of %s.",
r,
[self.minx, self.maxx],
Expand All @@ -178,15 +178,15 @@ def readxy(self, filename):

import re

res = re.search(r"^[^#]", datastring, re.M)
res = re.search(rb"^[^#]", datastring, re.M)
if res:
datastring = datastring[res.end() :].strip()

x = []
y = []

try:
for line in datastring.split("\n"):
for line in datastring.split(b"\n"):
v = line.split()
x.append(float(v[0]))
y.append(float(v[1]))
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/srmise/modelevaluators/aic.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def evaluate(self, fit, count_fixed=False, kshift=0):
n = fit.size

if n < self.minpoints(k):
logger.warn("AIC.evaluate(): too few data to evaluate quality reliably.")
logger.warning("AIC.evaluate(): too few data to evaluate quality reliably.")
n = self.minpoints(k)

if self.chisq is None:
Expand Down Expand Up @@ -115,7 +115,7 @@ def growth_justified(self, fit, k_prime):

# assert n >= self.minPoints(kActual) #check that AIC is defined for the actual fit
if n < self.minpoints(k_actual):
logger.warn("AIC.growth_justified(): too few data to evaluate quality reliably.")
logger.warning("AIC.growth_justified(): too few data to evaluate quality reliably.")
n = self.minpoints(k_actual)

penalty = self.parpenalty(k_test, n) - self.parpenalty(k_actual, n)
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/srmise/modelevaluators/aicc.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def evaluate(self, fit, count_fixed=False, kshift=0):
n = fit.size

if n < self.minpoints(k):
logger.warn("AICc.evaluate(): too few data to evaluate quality reliably.")
logger.warning("AICc.evaluate(): too few data to evaluate quality reliably.")
n = self.minpoints(k)

if self.chisq is None:
Expand Down Expand Up @@ -117,7 +117,7 @@ def growth_justified(self, fit, k_prime):

# assert n >= self.minPoints(kActual) #check that AICc is defined for the actual fit
if n < self.minpoints(k_actual):
logger.warn("AICc.growth_justified(): too few data to evaluate quality reliably.")
logger.warning("AICc.growth_justified(): too few data to evaluate quality reliably.")
n = self.minpoints(k_actual)

penalty = self.parpenalty(k_test, n) - self.parpenalty(k_actual, n)
Expand Down
Loading