Commit 53b44d53 authored by payno's avatar payno
Browse files

[unit test] add unit test for roi in a workflow

parent bf295069
......@@ -36,6 +36,10 @@ from xas.core.process.ft import pymca_ft, PyMca_ft
from xas.io import read_pymca_xas
from xas.core.process.k_weight import pymca_k_weight, PyMca_k_weight
from xas.core.process.normalization import pymca_normalization, PyMca_normalization
from xas.core.process.roi import xas_roi, _ROI as XASROI
from xas.core.utils import spectra as spectra_utils
from xas.core.types import XASObject
import numpy
class TestStreamSingleSpectrum(unittest.TestCase):
......@@ -50,7 +54,7 @@ class TestStreamSingleSpectrum(unittest.TestCase):
out = pymca_exafs(xas_obj=out)
out = pymca_k_weight(xas_obj=out)
out = pymca_ft(xas_obj=out)
assert out is not None
assert isinstance(out, XASObject)
def test_pymca_process_with_dict(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
......@@ -62,7 +66,7 @@ class TestStreamSingleSpectrum(unittest.TestCase):
out = pymca_exafs(xas_obj=out)
out = pymca_k_weight(xas_obj=out)
out = pymca_ft(xas_obj=out)
assert out is not None
assert isinstance(out, XASObject)
def test_pymca_process_with_cls(self):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
......@@ -74,7 +78,24 @@ class TestStreamSingleSpectrum(unittest.TestCase):
out = PyMca_exafs()(xas_obj=out)
out = PyMca_k_weight()(xas_obj=out)
out = PyMca_ft()(xas_obj=out)
assert out is not None
assert isinstance(out, XASObject)
def test_pymca_with_roi(self):
spectra = spectra_utils.create_dataset(shape=(256, 20, 10))
energy = numpy.linspace(start=3.26, stop=3.96, num=256)
roi = XASROI(origin=(0, 2), size=(5, 1))
xas_obj = XASObject(spectra=spectra, energy=energy,
configuration={'roi': roi.to_dict()})
out = xas_roi(xas_obj.to_dict())
out = pymca_normalization(xas_obj=out.to_dict())
out = pymca_exafs(xas_obj=out)
out = pymca_k_weight(xas_obj=out)
out = pymca_ft(xas_obj=out)
assert isinstance(out, XASObject)
self.assertEqual(out.dim1, 1)
self.assertEqual(out.dim2, 5)
self.assertTrue(out.spectra[0].ft is not None)
self.assertTrue(len(out.spectra[0].ft['FTIntensity']) > 0)
def suite():
......
......@@ -36,6 +36,7 @@ from xas.app.process import exec_ as exec_workflow
import xas.core.process.normalization
import xas.core.process.k_weight
import xas.core.process.exafs
import xas.core.process.roi
import xas.core.process.ft
from xas.core.types import XASObject
import xas.io
......@@ -86,17 +87,21 @@ class TestWorkflowCallableClasses(unittest.TestCase):
unittest.TestCase.setUp(self)
read_task = Node(callback=xas.io.read_pymca_xas_from_file)
roi_task = Node(callback=xas.core.process.roi.ROIProcess)
normalization_task = Node(
callback=xas.core.process.normalization.PyMca_normalization)
k_weight_task = Node(callback=xas.core.process.k_weight.PyMca_k_weight)
exafs_task = Node(callback=xas.core.process.exafs.PyMca_exafs)
ft_task = Node(callback=xas.core.process.ft.PyMca_ft)
nodes = (
read_task, normalization_task, k_weight_task, exafs_task, ft_task)
nodes = (read_task, roi_task, normalization_task, k_weight_task,
exafs_task, ft_task)
links = [
Link(source_node=read_task, source_channel='spectra',
sink_node=roi_task, sink_channel='spectra'),
Link(source_node=roi_task, source_channel='spectra',
sink_node=normalization_task, sink_channel='spectra'),
Link(source_node=normalization_task, source_channel='spectra',
sink_node=exafs_task, sink_channel='spectra'),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment