Commit 3808be89 authored by payno's avatar payno
Browse files

fix CI

parent 4ff7654a
Pipeline #39018 failed with stages
in 6 minutes and 8 seconds
......@@ -46,7 +46,7 @@ DEFAULT_CHANNEL_PATH = "/data/NXdata/Channel"
DEFAULT_CONF_PATH = "/configuration"
def read(spectra_url, channel_url, config_url=None, dimensions=None, energy_unit=ur.eV):
def read(spectra_url, channel_url, dimensions, config_url=None, energy_unit=ur.eV):
"""
:param DataUrl spectra_url: data url to the spectra
......@@ -76,7 +76,7 @@ def read(spectra_url, channel_url, config_url=None, dimensions=None, energy_unit
def read_frm_file(
file_path,
energy_unit=ur.eV,
dimensions: tuple = (Dim.CHANNEL_ENERGY_DIM, Dim.X_DIM, Dim.Y_DIM),
dimensions: tuple = (Dim.CHANNEL_ENERGY_DIM, Dim.Y_DIM, Dim.X_DIM),
):
"""
......@@ -116,7 +116,7 @@ class XASReader(object):
def read_from_file(
file_path,
energy_unit=ur.eV,
dimensions=(Dim.CHANNEL_ENERGY_DIM, Dim.X_DIM, Dim.Y_DIM),
dimensions=(Dim.CHANNEL_ENERGY_DIM, Dim.Y_DIM, Dim.X_DIM),
):
"""
......
......@@ -37,6 +37,7 @@ from est.core.io import read as read_xas
from est.core.utils import spectra as spectra_utils
from est.core.types import XASObject
from silx.io.url import DataUrl
from est.core.types import Dim
try:
import PyMca5
......@@ -63,6 +64,7 @@ class TestReadWrite(unittest.TestCase):
res = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca"),
dimensions=(Dim.CHANNEL_ENERGY_DIM, Dim.X_DIM, Dim.Y_DIM),
)
self.assertTrue(isinstance(res, XASObject))
self.assertEqual(res.n_spectrum, 1)
......
......@@ -44,6 +44,7 @@ from est.core.io import XASWriter
from est.core.io import read as read_xas
from est.core.types import XASObject
from est.core.utils import spectra as spectra_utils
from est.core.types import Dim
try:
import PyMca5
......@@ -75,6 +76,7 @@ class TestStreamSingleSpectrum(unittest.TestCase):
out = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca"),
dimensions=(Dim.CHANNEL_ENERGY_DIM, Dim.X_DIM, Dim.Y_DIM),
)
out.configuration = {"EXAFS": self.exafs_configuration, "SET_KWEIGHT": 0}
out = pymca_normalization(xas_obj=out)
......@@ -88,6 +90,7 @@ class TestStreamSingleSpectrum(unittest.TestCase):
out = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca"),
dimensions=(Dim.CHANNEL_ENERGY_DIM, Dim.X_DIM, Dim.Y_DIM),
)
out.configuration = {"EXAFS": self.exafs_configuration, "SET_KWEIGHT": 0}
out = pymca_normalization(xas_obj=out.to_dict())
......@@ -101,6 +104,7 @@ class TestStreamSingleSpectrum(unittest.TestCase):
out = read_xas(
spectra_url=DataUrl(file_path=data_file, scheme="PyMca"),
channel_url=DataUrl(file_path=data_file, scheme="PyMca"),
dimensions=(Dim.CHANNEL_ENERGY_DIM, Dim.X_DIM, Dim.Y_DIM),
)
out = PyMca_normalization()(xas_obj=out)
exafs_process = PyMca_exafs()
......
......@@ -31,14 +31,13 @@ import os
import shutil
import tempfile
import unittest
import h5py
import numpy
from silx.io.url import DataUrl
from est.core.io import read as read_xas
from est.core.process.roi import xas_roi
from est.core.utils import spectra as spectra_utils
from est.core.types import Dim
class TestRoi(unittest.TestCase):
......@@ -59,6 +58,7 @@ class TestRoi(unittest.TestCase):
channel_url=DataUrl(
file_path=filename, data_path=channel_path, scheme="silx"
),
dimensions=(Dim.CHANNEL_ENERGY_DIM, Dim.Y_DIM, Dim.X_DIM),
)
def tearDown(self):
......
......@@ -41,6 +41,7 @@ from est.units import ur
import json
import pint
import silx.io.utils
from est.core.types import Dim
try:
import PyMca5
......@@ -122,6 +123,7 @@ class TestXASObject(unittest.TestCase):
channel_url=DataUrl(
file_path=filename, data_path=channel_path, scheme="silx"
),
dimensions=(Dim.CHANNEL_ENERGY_DIM, Dim.Y_DIM, Dim.X_DIM),
)
self.assertEqual(self.xas_obj.dim1, 20)
self.assertEqual(self.xas_obj.dim2, 10)
......
......@@ -467,6 +467,8 @@ class XASObject(object):
def load_frm_dict(self, ddict: dict):
"""load XAS values from a dict"""
dimensions = (Dim.CHANNEL_ENERGY_DIM, Dim.Y_DIM, Dim.X_DIM)
# default yay of storing data
from est.io import load_data # avoid cyclic import
contains_config_spectrum = "configuration" in ddict or "spectra" in ddict
......@@ -479,7 +481,11 @@ class XASObject(object):
spectra = ddict["spectra"]
# if spectra is given from an url
if isinstance(spectra, str):
spectra = load_data(data_url=DataUrl(path=spectra), name="spectra")
spectra = load_data(
data_url=DataUrl(path=spectra),
name="spectra",
dimensions=dimensions,
)
# if come from a list of spectrum
elif not isinstance(spectra, (numpy.ndarray, pint.Quantity)):
new_spectra = []
......@@ -493,7 +499,9 @@ class XASObject(object):
energy = ddict["energy"]
if isinstance(energy, str):
energy_url = DataUrl(path=energy)
energy = load_data(data_url=energy_url, name="energy")
energy = load_data(
data_url=energy_url, name="energy", dimensions=dimensions
)
else:
energy = None
if "dim1" in ddict:
......
......@@ -36,7 +36,6 @@ from silx.io.dictdump import dicttoh5, h5todict
from silx.io.url import DataUrl
from silx.utils.enum import Enum
from est.units import ur
from est.core.types import Dim
try:
from est.io.utils.pymca import read_spectrum as pymca_read_spectrum
......@@ -75,6 +74,8 @@ def load_data(data_url, name, dimensions):
"""
if data_url is None:
return None
from est.core.types import Dim # avoid cyclic import
dimensions = tuple([Dim.from_value(dim) for dim in dimensions])
assert isinstance(data_url, DataUrl)
if data_url.scheme() in ("PyMca", "PyMca5"):
......@@ -219,7 +220,7 @@ def read_xas(
dimensions_.index(Dim.X_DIM),
)
dst_axis = (0, 1, 2)
_logger.warning(
_logger.info(
"move axis for spectra %s, from %s to %s" % (spectra_url, src_axis, dst_axis)
)
spectra = numpy.moveaxis(spectra, src_axis, dst_axis)
......
......@@ -29,16 +29,18 @@ __date__ = "06/11/2019"
from PyMca5.PyMcaIO import specfilewrapper as specfile
from est.units import ur
from est.core.types import Dim
def read_spectrum(spec_file, dimensions, energy_unit=ur.eV):
"""
:param spec_file: path to the spec file containing the spectra definition
:param str spec_file: path to the spec file containing the spectra definition
:param tuple dimensions:
:return: (energy, mu)
:rtype: tuple
"""
from est.core.types import Dim # avoid cyclic import
scan = specfile.Specfile(spec_file)[0]
data = scan.data()
......
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