Skip to content
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

Package upgrades #159

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 3 additions & 4 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
22 changes: 18 additions & 4 deletions src/multiphonon/sqe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# -*- python -*-
# This algorithm should be deprecated with the deletion of ipywe. This algorithm is not covered in tests.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include in your PR summary how to import this to have it as a reference, please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is an added instructions now

# 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

Expand Down
6 changes: 4 additions & 2 deletions tests/getdos_TestCase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#

import imp

import os
import tempfile
import unittest
Expand All @@ -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
Expand All @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions tests/getdos_TestCase2.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#!/usr/bin/env python
#

import imp
import os
import tempfile
import unittest
import warnings

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

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):
Expand Down
4 changes: 2 additions & 2 deletions tests/redutils_TestCase.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/batch_TestCase.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python
#

import imp
import os
import tempfile
import unittest

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")
Expand All @@ -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):
Expand Down
58 changes: 0 additions & 58 deletions tests/ui/getdos_TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down