diff --git a/environment.yml b/environment.yml index 53ea4d1..b555612 100644 --- a/environment.yml +++ b/environment.yml @@ -12,9 +12,9 @@ dependencies: - conda-build - conda-verify - coverage - - numpy >= 1.20.3,< 2.0 - - scipy >= 1.9.0,< 1.14.0 - - python + - numpy == 1.26.4 + - scipy == 1.14.1 + - python >=3.10 - pyre == 0.8.3 - mantid - matplotlib @@ -33,5 +33,4 @@ dependencies: - ipywidgets # used in one test - pip - pip: - - ipywe == 0.1.3a1 - git+https://github.com/neutrons/histogram-dev.git@next#egg=histogram-dev diff --git a/pyproject.toml b/pyproject.toml index 538b3cc..94c74c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,10 +2,10 @@ name = "multiphonon" description="Multiphonon scattering and multiple scattering correction for powder data" dynamic = ["version"] -requires-python = ">=3.8" +requires-python = ">=3.10" dependencies = [ - "numpy >= 1.20.3, <2.0", - "scipy >= 1.9.0, < 1.14.0", + "numpy == 1.26.4", + "scipy == 1.14.1", "mantid", ] license = { text = "BSD" } diff --git a/src/multiphonon/sqe/__init__.py b/src/multiphonon/sqe/__init__.py index 4630af4..99a77de 100644 --- a/src/multiphonon/sqe/__init__.py +++ b/src/multiphonon/sqe/__init__.py @@ -3,10 +3,24 @@ # Jiao Lin +import importlib.machinery +import importlib.util + import histogram as H import numpy as np +def load_source(modname, filename): + loader = importlib.machinery.SourceFileLoader(modname, filename) + spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) + module = importlib.util.module_from_spec(spec) + # The module is always executed and not cached in sys.modules. + # Uncomment the following line to cache the module. + # sys.modules[module.__name__] = module + loader.exec_module(module) + return module + + def _conv_unit_label(un): """Helper function for plotting""" unstr = str(un) @@ -92,14 +106,14 @@ def get_boundary_indexes(a): iqehist.I[mask] = 0 iqehist.E2[mask] = 0 Q = iqehist.Q - f = interpolate.interp2d(E, Q, iqehist.I, kind="linear") - E2f = interpolate.interp2d(E, Q, iqehist.E2, kind="linear") + f = interpolate.RectBivariateSpline(E, Q, iqehist.I.T, kx=1, ky=1) + E2f = interpolate.RectBivariateSpline(E, Q, iqehist.E2.T, kx=1, ky=1) dE = E[1] - E[0] Emin = E[0] // dE * dE Emax = E[-1] // dE * dE # Enew = np.arange(Emin, Emax+dE/2, dE) - newS = f(newE, Q) - newS_E2 = E2f(newE, Q) + newS = f(newE, Q).T + newS_E2 = E2f(newE, Q).T # create new histogram Eaxis = H.axis("E", newE, unit="meV") Qaxis = H.axis("Q", Q, unit="1./angstrom") diff --git a/src/multiphonon/ui/getdos.py b/src/multiphonon/ui/getdos_deprecated.py similarity index 97% rename from src/multiphonon/ui/getdos.py rename to src/multiphonon/ui/getdos_deprecated.py index ade2dbc..9021bfd 100644 --- a/src/multiphonon/ui/getdos.py +++ b/src/multiphonon/ui/getdos_deprecated.py @@ -1,4 +1,8 @@ # -*- python -*- +# This algorithm should be deprecated with the deletion of ipywe. This algorithm is not covered in tests. +# Just in case users are using old jupyternotebooks that calls this algorithm it's renamed +# with *_depracated keyword at the moment. +# For this algorithm to work properly, ipywe needs to be installed. # import os diff --git a/tests/getdos_TestCase.py b/tests/getdos_TestCase.py index a3bcc4d..c17e6fc 100755 --- a/tests/getdos_TestCase.py +++ b/tests/getdos_TestCase.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -import imp + import os import tempfile import unittest @@ -10,6 +10,7 @@ import numpy as np import pytest from multiphonon.getdos import getDOS +from multiphonon.sqe import load_source # pytestmark = pytest.mark.skipif(False, reason="only run mannually") pytestmark = pytest.mark.needs_mantid @@ -18,7 +19,8 @@ here = os.path.dirname(__file__) datadir = os.path.join(here, "data") -dataurls = imp.load_source("dataurls", os.path.join(datadir, "dataurls.py")) + +dataurls = load_source("dataurls", os.path.join(datadir, "dataurls.py")) class TestCase(unittest.TestCase): diff --git a/tests/getdos_TestCase2.py b/tests/getdos_TestCase2.py index 9d9e4c6..223a9e4 100644 --- a/tests/getdos_TestCase2.py +++ b/tests/getdos_TestCase2.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -import imp import os import tempfile import unittest @@ -9,6 +8,7 @@ import pytest from multiphonon.getdos import getDOS +from multiphonon.sqe import load_source # pytestmark = pytest.mark.skipif(False, reason="only run mannually") pytestmark = pytest.mark.needs_mantid @@ -16,7 +16,9 @@ interactive = False datadir = os.path.join(os.path.dirname(__file__), "data") -dataurls = imp.load_source("dataurls", os.path.join(datadir, "dataurls.py")) + + +dataurls = load_source("dataurls", os.path.join(datadir, "dataurls.py")) class TestCase(unittest.TestCase): diff --git a/tests/redutils_TestCase.py b/tests/redutils_TestCase.py index 69c6ce5..0ed5c85 100755 --- a/tests/redutils_TestCase.py +++ b/tests/redutils_TestCase.py @@ -1,12 +1,12 @@ #!/usr/bin/env python # -import imp import os import tempfile import unittest import pytest +from multiphonon.sqe import load_source # pytestmark = pytest.mark.skipif(False, reason="only run mannually") pytestmark = pytest.mark.needs_mantid @@ -16,7 +16,7 @@ here = os.path.dirname(__file__) datadir = os.path.join(here, "data") -dataurls = imp.load_source("dataurls", os.path.join(datadir, "dataurls.py")) +dataurls = load_source("dataurls", os.path.join(datadir, "dataurls.py")) class TestCase(unittest.TestCase): diff --git a/tests/ui/batch_TestCase.py b/tests/ui/batch_TestCase.py index dad3027..129d58e 100755 --- a/tests/ui/batch_TestCase.py +++ b/tests/ui/batch_TestCase.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -import imp import os import tempfile import unittest @@ -9,6 +8,7 @@ import histogram.hdf as hh import numpy as np import pytest +from multiphonon.sqe import load_source from multiphonon.ui import batch # pytestmark = pytest.mark.skipif(False, reason="only run mannually") @@ -19,7 +19,7 @@ here = os.path.abspath(os.path.dirname(__file__)) datadir = os.path.join(here, "..", "data") -dataurls = imp.load_source("dataurls", os.path.join(datadir, "dataurls.py")) +dataurls = load_source("dataurls", os.path.join(datadir, "dataurls.py")) class TestCase(unittest.TestCase): diff --git a/tests/ui/getdos_TestCase.py b/tests/ui/getdos_TestCase.py index 20b1aa3..1e40f73 100644 --- a/tests/ui/getdos_TestCase.py +++ b/tests/ui/getdos_TestCase.py @@ -27,64 +27,6 @@ def test_contextload(self): cntxt2.from_yaml(context_filepath) return - def test1(self): - """multiphonon.ui.getdos""" - from multiphonon.ui import Context, getdos - - with tempfile.TemporaryDirectory() as tmpdirname: - context_filepath = os.path.join(tmpdirname, "context.yaml") - - context = Context() - context.to_yaml(context_filepath) - context2 = Context() - context2.from_yaml(context_filepath) - s = str(context) - - context.sample_nxs = "sample.nxs" - wiz = getdos.NxsWizardStart(context) - wiz.show() - wiz.sample_nxs = context.sample_nxs - wiz.validate() - wiz.nextStep() - - wiz = getdos.GetMTNxs(context) - wiz.show() - wiz.mt_nxs = "mt.nxs" - wiz.validate() - wiz.nextStep() - - wiz = getdos.GetEiT(context) - wiz.show() - wiz.validate() - wiz.nextStep() - - wiz = getdos.GetEAxis(context) - wiz.show() - wiz.validate() - context.Emin, context.Emax, context.dE = -50.0, 50.0, 1.0 - wiz.nextStep() - - wiz = getdos.GetQAxis(context) - wiz.show() - wiz.validate() - context.Qmin, context.Qmax, context.dQ = 0.0, 15.0, 0.1 - # wiz.nextStep() - - context.initdos = "initdos.h5" - wiz = getdos.GetInitDOS(context) - wiz.show() - wiz.initdos = "initdos.h5" - wiz.validate() - wiz.nextStep() - - wiz = getdos.GetParameters(context) - wiz.show() - wiz.validate() - # wiz.nextStep() - return - - pass # end of TestCase - def exec_cmd(cmd): if os.system(cmd):