import numpy as np
import pytest
from ..tasks import xeoltasks
from .data import resource_path
[docs]
@pytest.mark.parametrize(
"config_file",
["configuration_for_h5_Linux.cfg", "configuration_for_h5_Windows.cfg"],
)
@pytest.mark.parametrize(
"output, mask_index",
[
(851.3708, 0),
(851.3708, 1),
(0.0, 2),
],
)
def test_xeol_workflow(config_file, output, mask_index):
with resource_path(config_file) as config_path:
task = xeoltasks.ReadCorrectConfig(inputs={"config_path": str(config_path)})
task.execute()
config = task.outputs.config
y = (
np.array(
[
[[0, 1, 5, 2, 0], [0, 2, 7, 3, 0], [0, 0, 1, 0, 0]],
[[0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]],
[[0, 0, 1, 0, 0], [0, 1, 3, 1, 0], [0, 0, 1, 0, 0]],
]
)
* 10**4
)
x = np.array([830, 840, 850, 860, 870])
# spc = y.sum(axis=-1)
# masks = [
# [np.where(spc > 0)],
# [np.where(spc > 10**4)],
# [np.where(spc > 10**10)],
# ]
expected_masks = [
np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]),
np.array([[1, 1, 0], [0, 0, 0], [0, 1, 0]]),
np.array([[0, 1, 0], [0, 0, 0], [0, 0, 0]]),
]
mask = expected_masks[mask_index]
inputs = dict(config=config, x=x, y=y, mask=mask)
task = xeoltasks.XeolStackFit(inputs=inputs)
task.execute()
labels, parameters = task.outputs.parameters
assert labels == [
"Constant",
"s(Constant)",
"Area_1",
"s(Area_1)",
"Position_1",
"s(Position_1)",
"Fwhm_1",
"s(Fwhm_1)",
"chisq",
]
assert np.round(float(parameters[4][0][0]), 1) == np.round(output, 1)