Skip to content

Commit

Permalink
Merge 3c5a082 into 389ada4
Browse files Browse the repository at this point in the history
  • Loading branch information
yxqd committed Sep 18, 2020
2 parents 389ada4 + 3c5a082 commit 14519ab
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ install:
# - pip install codecov

script:
- travis_wait 60 py.test --cov=multiphonon tests
- py.test -s --cov=multiphonon tests
- python examples/getdos-Al.py
- python examples/getdos-Al-from-nparrs.py
# the following were run standalone but now all included in the cmd above.
Expand Down
18 changes: 9 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@
master_doc = 'index'

# General information about the project.
project = u'multiphonon'
copyright = u'2017, ORNL Neutron Data Sciences Group'
author = u'Jiao Lin and Fahima Islam'
project = 'multiphonon'
copyright = '2017, ORNL Neutron Data Sciences Group'
author = 'Jiao Lin and Fahima Islam'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'0.1'
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = u'0.1.1'
release = '0.1.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -227,8 +227,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'multiphonon.tex', u'multiphonon Documentation',
u'Jiao Lin', 'manual'),
(master_doc, 'multiphonon.tex', 'multiphonon Documentation',
'Jiao Lin', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -257,7 +257,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'multiphonon', u'multiphonon Documentation',
(master_doc, 'multiphonon', 'multiphonon Documentation',
[author], 1)
]

Expand All @@ -271,7 +271,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'multiphonon', u'multiphonon Documentation',
(master_doc, 'multiphonon', 'multiphonon Documentation',
author, 'multiphonon', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
4 changes: 2 additions & 2 deletions examples/getdos-Al-from-nparrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
C_ms=0.2, Ei=80., workdir=workdir)
# process and plot
for i, dos in enumerate(iterdos):
print "* Iteration", i
print("* Iteration", i)
if not headless:
plt.plot(dos.E, dos.I, label='%d' % i)
continue
Expand All @@ -52,4 +52,4 @@
plt.legend()
plt.show()

print "Intermediate and final results are stored in directory %r" % workdir
print("Intermediate and final results are stored in directory %r" % workdir)
4 changes: 2 additions & 2 deletions examples/getdos-Al.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# process
for i, dos in enumerate(iterdos):
print "* Iteration", i
print("* Iteration", i)
if not headless:
plt.plot(dos.E, dos.I, label='%d' % i)
continue
Expand All @@ -44,4 +44,4 @@
plt.legend()
plt.show()

print "Intermediate and final results are stored in directory %r" % workdir
print("Intermediate and final results are stored in directory %r" % workdir)
14 changes: 7 additions & 7 deletions examples/getdos2-graphite_Ei130meV-noUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
from multiphonon.sqe import plot as plot_sqe


print "* Reading DOS from $E_i=300$..."
print("* Reading DOS from $E_i=300$...")
dos_300 = hh.load('./data/graphite-Ei_300-dos.h5')
#
if not headless:
print "* Plotting DOS from $E_i=300$..."
print("* Plotting DOS from $E_i=300$...")
plt.figure()
plt.plot(dos_300.E, dos_300.I)
plt.show()

print "* Reading S(Q,E) from $E_i=130$..."
print("* Reading S(Q,E) from $E_i=130$...")
iqe_130 = hh.load('data/graphite-Ei_130-iqe.h5')
if not headless:
print "* Plotting S(Q,E) from $E_i=130$..."
print("* Plotting S(Q,E) from $E_i=130$...")
plt.figure()
plot_sqe(iqe_130)
plt.xlim(0, 18)
Expand All @@ -40,7 +40,7 @@
# It is clear here only phonons with $E<120meV$ were measured in this dataset.


print "* Processing and stitching..."
print("* Processing and stitching...")
iterdos = sqe2dos.sqe2dos(
iqe_130, T=300, Ecutoff=100.,
elastic_E_cutoff=(-30., 15), M=12.,
Expand All @@ -52,13 +52,13 @@
# plot the partial DOS
partial_dos = lastdos[(None, 100)]
if not headless:
print "* Plotting the partial DOS from Ei=130 ..."
print("* Plotting the partial DOS from Ei=130 ...")
plt.figure()
plt.plot(partial_dos.E, partial_dos.I)
plt.show()
# plot the final DOS
if not headless:
print "* Plotting the stitched DOS..."
print("* Plotting the stitched DOS...")
plt.figure()
plt.plot(lastdos.E, lastdos.I)
plt.show()
2 changes: 1 addition & 1 deletion multiphonon/backward/sqe2dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def normalizeExpSQE_inelonly(sqe, dos, M, beta, elastic_E_cutoff):
"""

#
from singlephonon_sqe2dos import sqe2dos as singlephonon_sqe2dos
from .singlephonon_sqe2dos import sqe2dos as singlephonon_sqe2dos
from ._sqe2dos_script_templates import \
plot_intermediate_result_sqe_code,plot_intermediate_result_se_code, \
plot_dos_iteration_code, plot_residual_code
Expand Down
2 changes: 1 addition & 1 deletion multiphonon/dos/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def fromascii(datapath, x_unit=None):
continue
tokens = line.split()
try:
numbers = map(float, tokens)
numbers = list(map(float, tokens))
except Exception as e:
msg = 'Skip line %s' % line
warnings.warn(msg)
Expand Down
8 changes: 4 additions & 4 deletions multiphonon/dos/nice.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def fit(N):
if badfit:
# import pylab; pylab.plot(E, g); pylab.show()
raise ParabolicFittingError("Unable to fit DOS to parabolic")
print "DOS: fit first %s points to parbolic" % N
print("DOS: fit first %s points to parbolic" % N)
E1 = E[:N]
g[:N] = c * E1*E1
return E,g
Expand Down Expand Up @@ -100,18 +100,18 @@ def smooth(x,window_len=11,window='hanning'):
import numpy

if x.ndim != 1:
raise ValueError, "smooth only accepts 1 dimension arrays."
raise ValueError("smooth only accepts 1 dimension arrays.")

if x.size < window_len:
raise ValueError, "Input vector needs to be bigger than window size."
raise ValueError("Input vector needs to be bigger than window size.")


if window_len<3:
return x


if not window in ['flat', 'hanning', 'hamming', 'bartlett', 'blackman']:
raise ValueError, "Window is on of 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'"
raise ValueError("Window is on of 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'")


s=numpy.r_[x[window_len-1:0:-1],x,x[-1:-window_len:-1]]
Expand Down
6 changes: 3 additions & 3 deletions multiphonon/getdos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import histogram.hdf as hh, numpy as np
import os
import os, sys

# hide the warnings on divide by zero etc
np.seterr(divide='ignore', invalid='ignore')
Expand Down Expand Up @@ -256,9 +256,9 @@ def raw2iqe(eventnxs, iqe_h5, Eaxis, Qaxis, type):
if not os.path.exists(iqe_h5):
qaxis = Qmin, dQ, Qmax
eaxis = Emin, dE, Emax
if isinstance(eventnxs, unicode):
if sys.version_info < (3,0) and isinstance(eventnxs, unicode):
eventnxs = eventnxs.encode()
if isinstance(iqe_h5, unicode):
if sys.version_info < (3,0) and isinstance(iqe_h5, unicode):
iqe_h5 = iqe_h5.encode()
reduce(eventnxs, qaxis, iqe_h5, eaxis=eaxis, tof2E='guess', ibnorm='ByCurrent')
else:
Expand Down
4 changes: 2 additions & 2 deletions multiphonon/redutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ def _createDefaultMantidUserConfig(facility='SNS'):

mantid_checked = False
def _checkMantid():
print "* Checking Mantid ..."
print("* Checking Mantid ...")
import subprocess as sp, shlex
sp.call(shlex.split("python -c 'import matplotlib, mantid'"), stdout=sp.PIPE, stderr=sp.PIPE) # sometimes mantid import for the first time may fail
if sp.call(shlex.split("python -c 'import matplotlib, mantid'")):
raise RuntimeError("Please install mantid")
global mantid_checked
mantid_checked = True
print " - Done."
print(" - Done.")
return
if not mantid_checked:
_checkMantid()
Expand Down
2 changes: 1 addition & 1 deletion multiphonon/ui/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def process(sample_nxs_list, mt_nxs_list, parameter_yaml):
os.makedirs(workdir)
log = open(os.path.join(workdir, 'log.getdos'), 'wt')
kargs['workdir'] = workdir
print "* Processing %s, %s" % (sample_nxs, mt_nxs)
print("* Processing %s, %s" % (sample_nxs, mt_nxs))
for msg in getDOS(**kargs):
log.write('%s\n' % (msg,))
continue
Expand Down
6 changes: 3 additions & 3 deletions multiphonon/ui/getdos.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def validate(self):
return True

def nextStep(self):
print "Done."
print("Done.")

def round2(a, digits = 1):
d = 10**(np.floor(np.log10(a)) - digits+1)
Expand Down Expand Up @@ -201,9 +201,9 @@ def nextStep(self):
mt_nxs=context.mt_nxs,
workdir=context.workdir,
)
for msg in r2i:print msg
for msg in r2i:print(msg)
context.iqe_h5, context.mtiqe_h5, context.Qaxis, context.Eaxis = msg
print "Done."
print("Done.")


# Wizard: GetDOS
Expand Down
4 changes: 2 additions & 2 deletions multiphonon/ui/getdos0.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def submit(b):
open(os.path.join(workdir, 'getdos-opts.yaml'), 'wt'))
maxiter = 10
close = lambda w: w.close()
map(close, w_all)
list(map(close, w_all))
from ..getdos import getDOS
log_progress(getDOS(samplenxs, mt_nxs=mtnxs, maxiter=maxiter, **kargs), every=1, size=maxiter+2)
return
Expand Down Expand Up @@ -139,7 +139,7 @@ def log_progress(sequence, every=None, size=None):
label.value = 'Running: {index} / ?: {msg}...'.format(index=index, msg=msg)
else:
progress.value = index
label.value = u'Running: {index} / {size}: {msg}...'.format(
label.value = 'Running: {index} / {size}: {msg}...'.format(
index=index,
size=size,
msg=msg
Expand Down
18 changes: 9 additions & 9 deletions tests/backward/singlephonon_sqe2dos_TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test1a(self):
# compare to the original dos data
E1, g1 = loadDOS()
ginterp = np.interp(E1, E, g)
self.assert_(np.allclose(g1, ginterp))
self.assertTrue(np.allclose(g1, ginterp))
# plot
if interactive:
import pylab
Expand All @@ -52,8 +52,8 @@ def test1b(self):
newiqe, T=300, Ecutoff=65., elastic_E_cutoff=(-20., 6.7), M=50.94)
path = os.path.join(here, 'expected_results', 'test1b-dos.h5')
expected = hh.load(path)
self.assert_(np.allclose(DOS.I, expected.I))
self.assert_(np.allclose(DOS.E2, expected.E2))
self.assertTrue(np.allclose(DOS.I, expected.I))
self.assertTrue(np.allclose(DOS.E2, expected.E2))
# plot
if interactive:
H.plot(DOS)
Expand Down Expand Up @@ -95,9 +95,9 @@ def test1c1(self):
path = os.path.join(here, 'expected_results', 'test1c1-dos.h5')
# hh.dump(newdos, path)
expected = hh.load(path)
self.assert_(np.allclose(newdos.I, expected.I))
self.assert_(np.allclose(newdos.E, expected.E))
self.assert_(np.allclose(newdos.E2, expected.E2))
self.assertTrue(np.allclose(newdos.I, expected.I))
self.assertTrue(np.allclose(newdos.E, expected.E))
self.assertTrue(np.allclose(newdos.E2, expected.E2))
# plot
if interactive:
pylab.errorbar(initdos.E, initdos.I, initdos.E2**.5, label='init')
Expand All @@ -117,8 +117,8 @@ def test1c2(self):
path = os.path.join(here, 'expected_results', 'test1c2-dos.h5')
# hh.dump(newdos, path)
expected = hh.load(path)
self.assert_(np.allclose(newdos.I, expected.I))
self.assert_(np.allclose(newdos.E, expected.E))
self.assertTrue(np.allclose(newdos.I, expected.I))
self.assertTrue(np.allclose(newdos.E, expected.E))
# self.assert_(np.allclose(newdos.E2, expected.E2))
# plot
if interactive:
Expand All @@ -142,7 +142,7 @@ def test1d(self):
for w in ws:
has_scaling_factor_warning = has_scaling_factor_warning or ('Scaling factor' in str(w))
continue
self.assert_(has_scaling_factor_warning)
self.assertTrue(has_scaling_factor_warning)
# plot
if interactive:
pylab.plot(initdos.E, initdos.I)
Expand Down
10 changes: 5 additions & 5 deletions tests/backward/sqe2dos_TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def test2a(self):
path = os.path.join(here, 'expected_results', 'sqe2dos-test2a-final-dos.h5')
# hh.dump(dos, path)
expected = hh.load(path)
self.assert_(np.allclose(dos.I, expected.I))
self.assert_(np.allclose(dos.E2, expected.E2))
self.assertTrue(np.allclose(dos.I, expected.I))
self.assertTrue(np.allclose(dos.E2, expected.E2))
if interactive:
pylab.figure()
pylab.errorbar(dos.E, dos.I+dos.I.max()/5., dos.E2**.5, label='new')
Expand Down Expand Up @@ -92,8 +92,8 @@ def test2b(self):
path = os.path.join(here, 'expected_results', 'sqe2dos-test2b-final-dos.h5')
# hh.dump(dos, path)
expected = hh.load(path)
self.assert_(np.allclose(dos.I, expected.I))
self.assert_(np.allclose(dos.E2, expected.E2))
self.assertTrue(np.allclose(dos.I, expected.I))
self.assertTrue(np.allclose(dos.E2, expected.E2))
if interactive:
pylab.figure()
pylab.errorbar(dos.E, dos.I + dos.I.max()/5, dos.E2**.5, label='new')
Expand Down Expand Up @@ -121,7 +121,7 @@ def test2c(self):
path = os.path.join(here, 'expected_results', 'sqe2dos-test2c-final-dos.h5')
# hh.dump(dos, path)
expected = hh.load(path)
self.assert_(np.allclose(dos.I, expected.I))
self.assertTrue(np.allclose(dos.I, expected.I))
# self.assert_(np.allclose(dos.E2, expected.E2))
if interactive:
pylab.figure()
Expand Down
2 changes: 1 addition & 1 deletion tests/forward/phonon_TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test3(self):


def _check(self, a1, a2):
self.assert_(np.allclose(a1, a2))
self.assertTrue(np.allclose(a1, a2))

pass # end of TestCase

Expand Down
2 changes: 1 addition & 1 deletion tests/forward/phonon_TestCase2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test1(self):
T = 300
beta = 1./(T*kelvin2mev)
dwexp = DWExp(Q, M, E,g, beta, dE)
print dwexp
print(dwexp)
return


Expand Down

0 comments on commit 14519ab

Please sign in to comment.