Skip to content
Snippets Groups Projects
Commit f4b8ea69 authored by Loic Huder's avatar Loic Huder
Browse files

Merge branch 'refactor-input-info' into 'main'

Build XASObject in GUI via read_from_input_information

Closes #88

See merge request workflow/ewoksapps/est!149
parents 81e026bb ab93406a
No related branches found
No related tags found
No related merge requests found
......@@ -3,24 +3,15 @@ from typing import Optional
from silx.gui import qt
from silx.io.url import DataUrl
from est.core.types.xasobject import XASObject
from est.io import InputType
from est.core.io import read_from_url
from est.core.io import read_from_ascii
from est.core.io import read_from_input_information
from est.io.information import InputInformation
from est.io.utils.ascii import build_ascii_data_url
from .ascii import XASObjectFromAscii
from .hdf5 import XASObjectFromH5
def _check_url(url_path, name):
if isinstance(url_path, DataUrl):
url = url_path
else:
url = DataUrl(path=url_path)
if not url.is_valid():
raise ValueError(f"{name} url is invalid. Does the file / path still exists ?")
class _InputTypeWidget(qt.QWidget):
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
......@@ -96,38 +87,16 @@ class XASObjectDialog(qt.QWidget):
self._inputType.getInputType() == InputType.hdf5_spectra
)
def buildXASObject(self):
if self.getCurrentType() == InputType.ascii_spectrum:
return read_from_ascii(
file_path=self._asciiDialog.getFileSelected(),
energy_unit=self._asciiDialog.getEnergyUnit(),
columns_names=self._asciiDialog.getColumnSelected(),
scan_title=self._asciiDialog.getScanTitle(),
)
elif self.getCurrentType() == InputType.hdf5_spectra:
spectra_url = self._h5Dialog.getSpectraUrl()
energy_url = self._h5Dialog.getEnergyUrl()
energy_unit = self._h5Dialog.getEnergyUnit()
# if we are not able to build a XASObj
if spectra_url in (None, "") or energy_url in (None, ""):
return None
_check_url(spectra_url, "spectra")
_check_url(energy_url, "energy/channel")
return read_from_url(
spectra_url=self._h5Dialog.getSpectraUrl(),
channel_url=self._h5Dialog.getEnergyUrl(),
energy_unit=energy_unit,
config_url=self._h5Dialog.getConfigurationUrl(),
dimensions=self._h5Dialog.getDimensions(),
I0_url=self._h5Dialog.advanceInfo.getI0Url(),
I1_url=self._h5Dialog.advanceInfo.getI1Url(),
I2_url=self._h5Dialog.advanceInfo.getI2Url(),
mu_ref_url=self._h5Dialog.advanceInfo.getMuRefUrl(),
)
else:
raise ValueError("unmanaged input type")
def buildXASObject(self) -> Optional[XASObject]:
input_information = self.getInputInformation()
spectra_url = input_information.spectra_url
energy_url = input_information.channel_url
# if we are not able to build a XASObj
if spectra_url in (None, "") or energy_url in (None, ""):
return None
return read_from_input_information(input_information)
def _editingIsFinished(self, *args, **kwargs):
self.editingFinished.emit()
......@@ -237,22 +206,3 @@ class XASObjectDialog(qt.QWidget):
col_name=self.getEnergyColName(),
scan_title=self.getScanTitle(),
)
def getMonitorUrl(self):
if self.getCurrentType() is InputType.hdf5_spectra:
# TODO: case not handled for H5 files ?!!
return None
else:
return build_ascii_data_url(
file_path=self.getAsciiFile(),
col_name=self.getMonitorColName(),
scan_title=self.getScanTitle(),
)
def getExtraInfos(self) -> dict:
if self.getCurrentType() is InputType.hdf5_spectra:
return {}
else:
return {
"scan_title": self.getScanTitle(),
}
......@@ -15,7 +15,7 @@ from orangecontrib.est.widgets.utils.xas_input import XASInputOW
def test_xas_input_no_dataset(qtapp):
"Check behavior if no settings exists"
"""Check behavior if no settings exists"""
widget = XASInputOW()
assert widget.buildXASObj() is None
widget.loadSettings(input_information=MISSING_DATA)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment