Commit efbd5d2b authored by payno's avatar payno

[unittest][test_types] replace local file for some random data

parent a2010048
Pipeline #12283 passed with stage
in 9 minutes and 59 seconds
......@@ -30,8 +30,11 @@ __date__ = "06/26/2019"
import numpy
import os
import unittest
import tempfile
import h5py
from xas.core.types import Spectrum, XASObject
from xas.core.utils.pymca import read_spectrum
from xas.core.utils import spectra as spectra_utils
from xas.io import read_pymca_xas
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from silx.io.url import DataUrl
......@@ -79,21 +82,30 @@ class TestXASObject(unittest.TestCase):
self.assertEqual(obj2, obj)
def test_create_from_several_spectrums(self):
data_file = '/nobackup/linazimov/payno/dev/esrf/xas/S5_nuit1_merge_new_crop.h5'
url_spectra = DataUrl(file_path=data_file,
data_path='/data/NXdata/data',
self.spectra = spectra_utils.create_dataset(shape=(256, 20, 10))
self.energy = numpy.linspace(start=3.26, stop=3.96, num=256)
self.output_dir = tempfile.mkdtemp()
spectra_path = '/data/NXdata/data'
channel_path = '/data/NXdata/Channel'
filename = os.path.join(self.output_dir, 'myfile.h5')
with h5py.File(filename) as f:
f[spectra_path] = self.spectra
f[channel_path] = self.energy
url_spectra = DataUrl(file_path=filename,
data_path=spectra_path,
scheme='silx')
self.xas_obj = read_pymca_xas(spectra_url=url_spectra,
channel_url=DataUrl(file_path=data_file,
data_path='/data/NXdata/Channel',
channel_url=DataUrl(file_path=filename,
data_path=channel_path,
scheme='silx')
)
self.assertEqual(self.xas_obj.dim1, 299)
self.assertEqual(self.xas_obj.dim2, 350)
self.assertEqual(self.xas_obj.n_spectrum, 299*350)
self.assertEqual(self.xas_obj.dim1, 20)
self.assertEqual(self.xas_obj.dim2, 10)
self.assertEqual(self.xas_obj.n_spectrum, 20*10)
ddict = self.xas_obj.to_dict()
original_spectra = silx.io.utils.get_data(DataUrl(file_path=data_file,
data_path='/data/NXdata/data',
original_spectra = silx.io.utils.get_data(DataUrl(file_path=filename,
data_path=spectra_path,
scheme='silx'))
numpy.testing.assert_array_equal(original_spectra, ddict['spectra'])
obj2 = XASObject.from_dict(ddict)
......
Markdown is supported
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