Skip to content

Commit

Permalink
Refs #39. forcing correct energy axis in getdos and warn. added a tes…
Browse files Browse the repository at this point in the history
…t case
  • Loading branch information
yxqd committed Aug 6, 2017
1 parent 896ed85 commit 8a114d8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
19 changes: 18 additions & 1 deletion multiphonon/getdos.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def getDOS(sample_nxs, mt_nxs=None, mt_fraction=0.9, const_bg_fraction=0.,
iqe_h5 = os.path.abspath(os.path.join(workdir, iqe_h5))
# reduce
Eaxis = _normalize_axis_setting(Emin, Emax, dE)
Eaxis = _checkEaxis(*Eaxis)
Qaxis = _normalize_axis_setting(Qmin, Qmax, dQ)
yield "Convert sample data to powder I(Q,E)"
raw2iqe(sample_nxs, iqe_nxs, iqe_h5, Eaxis, Qaxis)
Expand All @@ -46,7 +47,7 @@ def getDOS(sample_nxs, mt_nxs=None, mt_fraction=0.9, const_bg_fraction=0.,
# interpolate data
from .sqe import interp
# probably don't need this line
newiqe = interp(iqehist, newE = np.arange(Emin, Emax, dE))
newiqe = interp(iqehist, newE = np.arange(*Eaxis))
# save interpolated data
hh.dump(newiqe, 'iqe-interped.h5')
# init dos
Expand All @@ -68,6 +69,22 @@ def getDOS(sample_nxs, mt_nxs=None, mt_fraction=0.9, const_bg_fraction=0.,
return


def _checkEaxis(Emin, Emax, dE):
saved = Emin, Emax, dE
centers = np.arange(Emin, Emax, dE)
if np.isclose(centers, 0.).any():
return saved
import warnings
Emin = int(Emin/dE) * dE
Emax = int(Emax/dE) * dE
new = Emin, Emax, dE
warnings.warn(
"Zero has to be one of the ticks in the energy axis.\n"
"Energy axis modified from %s to %s \n" % (saved, new)
)
return new


def _normalize_axis_setting(min, max, delta):
# try to deal with numerical error
nsteps = round( 1.*(max-min)/delta )
Expand Down
16 changes: 13 additions & 3 deletions tests/getdos_TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@
import os
datadir = os.path.join(os.path.dirname(__file__), "data")

from multiphonon.getdos import getDOS

import unittest
class TestCase(unittest.TestCase):

def test1(self):
"multiphonon.getdos"
from multiphonon.getdos import getDOS
list(getDOS(os.path.join(datadir, "ARCS_V_annulus.nxs")))
return

def test1a(self):
"multiphonon.getdos: check energy axis"
import warnings
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
for _ in getDOS(os.path.join(datadir, "ARCS_V_annulus.nxs"), Emin=-50.5, Emax=80, dE=1.):
assert len(w)==1
assert "Energy axis modified" in str(w[-1].message)
break
return

def test2(self):
"multiphonon.getdos: MT can"
from multiphonon.getdos import getDOS
list(getDOS(
os.path.join(datadir, "ARCS_V_annulus.nxs"),
mt_nxs = os.path.join(datadir, "ARCS_V_annulus.nxs"),
Expand All @@ -30,7 +41,6 @@ def test2(self):

def test3(self):
"multiphonon.getdos: low T"
from multiphonon.getdos import getDOS
list(getDOS(os.path.join(datadir, "ARCS_V_annulus.nxs"), T=1.5))
return

Expand Down

0 comments on commit 8a114d8

Please sign in to comment.