diff --git a/multiphonon/getdos.py b/multiphonon/getdos.py index 868cf0d..219a99f 100644 --- a/multiphonon/getdos.py +++ b/multiphonon/getdos.py @@ -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) @@ -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 @@ -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 ) diff --git a/tests/getdos_TestCase.py b/tests/getdos_TestCase.py index 45102fe..579aeb4 100755 --- a/tests/getdos_TestCase.py +++ b/tests/getdos_TestCase.py @@ -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"), @@ -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