Skip to content

Commit

Permalink
Merge pull request #142 from sns-chops/interp-dos
Browse files Browse the repository at this point in the history
interpolate method for DOS
  • Loading branch information
yxqd authored Aug 18, 2021
2 parents 595ca98 + 19fa76b commit 508ab31
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
build-and-test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
fail-fast: true
matrix:
os: ["ubuntu-latest"]
python-version: ["3.7"]
Expand Down Expand Up @@ -58,6 +58,7 @@ jobs:
- name: build / test
shell: pwsh
run: |
wget --no-check-certificate "https://mcvine.ornl.gov/multiphonon/ARCS_V_annulus.nxs" -O tests/data/ARCS_V_annulus.nxs
echo $PYTHON_VERSION
conda install pip pytest pytest-cov python=$PYTHON_VERSION numpy scipy matplotlib histogram ipywe mantid-framework=5
python setup.py install
Expand Down
27 changes: 26 additions & 1 deletion multiphonon/dos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,29 @@
#
# Jiao Lin

# End of file
def interp(doshist, newE):
"""compute a new DOS histogram from the given DOS using the new energy array by interpolation
Parameters
----------
doshist: histogram
input DOS
newE:numpy array of floats
new energy centers in meV
"""
import numpy as np, histogram as H
try:
E = doshist.energy
except:
E = doshist.E
#
newS = np.interp(newE, E, doshist.I)
newS_E2 = np.interp(newE, E, doshist.E2)
Eaxis = H.axis("E", newE, unit='meV')
newHist = H.histogram("DOS", [Eaxis], data=newS, errors=newS_E2)
return newHist

# End of file
30 changes: 30 additions & 0 deletions tests/dos/dos_interp_TestCase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
#

interactive = False

import os, numpy as np, histogram.hdf as hh
here = os.path.dirname(__file__)

from multiphonon.dos import interp

import unittest
class TestCase(unittest.TestCase):

def test1(self):
"interp"
dos = hh.load(os.path.join(here, 'dos_to_interp.h5'))
newE = np.arange(0, 45, 0.5)
newdos = interp(dos, newE)
expected = hh.load(os.path.join(here, './expected/dos_interped.h5'))
np.testing.assert_allclose(newdos.I, expected.I)
np.testing.assert_allclose(newdos.E2, expected.E2)
return
pass # end of TestCase


if __name__ == "__main__":
interactive = True
unittest.main()

# End of file
Binary file added tests/dos/dos_to_interp.h5
Binary file not shown.
Binary file added tests/dos/expected/dos_interped.h5
Binary file not shown.

0 comments on commit 508ab31

Please sign in to comment.