Commit 90eeb4ba authored by payno's avatar payno

[orange-add-on] Add possibility to load configuration from .hdf5 in the input widget

parent 54086b4f
Pipeline #12151 passed with stage
in 10 minutes and 7 seconds
......@@ -34,6 +34,7 @@ from silx.gui import qt
from xas.core.types import XASBase, PyMcaXAS
from Orange.widgets.settings import Setting
from silx.io.url import DataUrl
import h5py
import os
import logging
import xas.core.process.io
......@@ -98,6 +99,8 @@ class XASInputOW(OWWidget):
old = self.blockSignals(True)
dialog = qt.QFileDialog(self)
dialog.setFileMode(qt.QFileDialog.ExistingFile)
dialog.setNameFilters(["spectrum (*.dat)",
"spectrum and configruation (*.h5 *.hdf *.hdf5)"])
if not dialog.exec_():
dialog.close()
......@@ -123,9 +126,23 @@ class XASInputOW(OWWidget):
return
else:
try:
xas_obj = xas.core.process.io.read_pymca_xas(DataUrl(file_path=self._input_file_setting,
scheme='PyMca'))
xas_obj = self._interpreteInput(file_path=self._input_file_setting)
except ... as e:
_logger.error(e)
else:
self.send("spectrum", xas_obj)
def _interpreteInput(self, file_path):
if file_path.endswith('.dat'):
return xas.core.process.io.read_pymca_xas(DataUrl(file_path=self._input_file_setting,
scheme='PyMca'))
elif h5py.is_hdf5(file_path):
return xas.core.process.io.read_pymca_xas(
spectrum_url=DataUrl(file_path=file_path,
scheme='PyMca',
data_path='spectrum'),
config_url=DataUrl(file_path=file_path,
scheme='silx',
data_path='configuration'))
else:
raise ValueError('file type not managed, unable to load')
......@@ -59,7 +59,10 @@ def read_pymca_xas(spectrum_url, config_url=None):
# deal with .dat file
config = {}
if config_url is not None:
config = utils.get_data(config_url)
if config_url.is_valid():
config = utils.get_data(config_url)
else:
_logger.warning('invalid url for configuration, will not load it')
spectrum = {}
if spectrum_url.scheme() in ('PyMca', 'PyMca5'):
......
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