Source code for est.tests.test_write

import pytest

from ..core.types.xasobject import XASObject

try:
    import larch
except ImportError:
    larch = None
else:
    from ..core.process.larch.pre_edge import Larch_pre_edge

from .hdf5 import assert_hdf5_content


[docs] @pytest.mark.skipif(larch is None, reason="larch is not installed") def test_write(spectrum_cu_from_larch, tmp_path): xas_obj = XASObject( spectra=(spectrum_cu_from_larch,), energy=spectrum_cu_from_larch.energy ) assert spectrum_cu_from_larch.pre_edge is None assert spectrum_cu_from_larch.e0 is None process = Larch_pre_edge(inputs={"xas_obj": xas_obj, "pre_edge_config": {}}) process.run() assert spectrum_cu_from_larch.pre_edge is not None assert spectrum_cu_from_larch.e0 is not None output_file = tmp_path / "output.h5" urls = xas_obj.to_file(output_file) assert output_file.exists() assert urls == [f"{output_file}?/1.1"] expected = { "data": { "data@NX_class": "NXdata", "data@auxiliary_signals": ["pre_edge", "post_edge"], "data@axes": ["energy"], "data@signal": "mu", "energy": { "energy@long_name": "Energy (eV)", "energy@units": "eV", }, "mu": {"mu@long_name": "μ"}, "post_edge": {}, "pre_edge": {}, }, "results": { "results@NX_class": "NXprocess", "date": {}, "program": {}, "normalized": { "energy": { "energy@long_name": "Energy (eV)", "energy@units": "eV", }, "flatten_mu": {"flatten_mu@long_name": "Flat(μ)"}, "normalized@NX_class": "NXdata", "normalized@auxiliary_signals": ["normalized_mu"], "normalized@axes": ["energy"], "normalized@signal": "flatten_mu", "normalized_mu": {"normalized_mu@long_name": "Norm(μ)"}, }, "statistics": { "e0": { "e0@long_name": "Edge Energy (eV)", "e0@units": "eV", }, "edge_step": {}, "statistics@NX_class": "NXparameters", }, }, } assert_hdf5_content(output_file, expected, 1)