Skip to content
Snippets Groups Projects

Build XASObject in GUI via read_from_input_information

Merged Loic Huder requested to merge refactor-input-info into main
2 unresolved threads
Files
2
@@ -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()
@@ -239,6 +208,7 @@ class XASObjectDialog(qt.QWidget):
)
def getMonitorUrl(self):
# TODO" UNUSED
Please register or sign in to reply
if self.getCurrentType() is InputType.hdf5_spectra:
# TODO: case not handled for H5 files ?!!
return None
@@ -250,6 +220,7 @@ class XASObjectDialog(qt.QWidget):
)
def getExtraInfos(self) -> dict:
# TODO: UNUSED
if self.getCurrentType() is InputType.hdf5_spectra:
return {}
else:
Loading