From dc527d4116e938043c1ef0e3598e7f9d2251f226 Mon Sep 17 00:00:00 2001 From: "borondics.accounts@gmail.com" Date: Mon, 9 Dec 2024 16:16:08 +0100 Subject: [PATCH 1/3] SoftiMax HDF5 reader --- orangecontrib/spectroscopy/io/soleil.py | 40 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/orangecontrib/spectroscopy/io/soleil.py b/orangecontrib/spectroscopy/io/soleil.py index 7ede84081..93d8bf4c0 100644 --- a/orangecontrib/spectroscopy/io/soleil.py +++ b/orangecontrib/spectroscopy/io/soleil.py @@ -43,16 +43,36 @@ class HDF5Reader_HERMES(FileFormat, SpectralFileFormat): def read_spectra(self): import h5py - hdf5_file = h5py.File(self.filename) - if 'entry1/collection/beamline' in hdf5_file and \ - hdf5_file['entry1/collection/beamline'][()].astype('str') == 'Hermes': - x_locs = np.array(hdf5_file['entry1/Counter0/sample_x']) - y_locs = np.array(hdf5_file['entry1/Counter0/sample_y']) - energy = np.array(hdf5_file['entry1/Counter0/energy']) - intensities = np.array(hdf5_file['entry1/Counter0/data']).T - return _spectra_from_image(intensities, energy, x_locs, y_locs) - else: - raise IOError("Not an HDF5 HERMES file") + with h5py.File(self.filename, 'r') as hdf5_file: + if 'entry1/collection/beamline' in hdf5_file and \ + hdf5_file['entry1/collection/beamline'][()].astype('str') == 'Hermes': + x_locs = np.array(hdf5_file['entry1/Counter0/sample_x']) + y_locs = np.array(hdf5_file['entry1/Counter0/sample_y']) + energy = np.array(hdf5_file['entry1/Counter0/energy']) + intensities = np.array(hdf5_file['entry1/Counter0/data']).T + return _spectra_from_image(intensities, energy, x_locs, y_locs) + else: + raise IOError("Not an HDF5 HERMES file") + + +class HDF5Reader_SoftiMAX(FileFormat, SpectralFileFormat): + """ A very case specific reader for HDF5 files from the SoftiMAX beamline in MAX-IV""" + EXTENSIONS = ('.hdf5',) + DESCRIPTION = 'HDF5 file @SoftiMAX/MAX-IV' + + def read_spectra(self): + print("SoftiMax") + import h5py + with h5py.File(self.filename, 'r') as hdf5_file: + if 'entry1/collection/beamline' in hdf5_file and \ + hdf5_file['entry1/collection/beamline'][()].astype('str') == ['SLS Sophie at Softimax MAXIV']: + x_locs = np.array(hdf5_file['entry1/counter0/sample_x']) + y_locs = np.array(hdf5_file['entry1/counter0/sample_y']) + energy = np.array(hdf5_file['entry1/counter0/energy']) + intensities = np.array(hdf5_file['entry1/counter0/data']).T + return _spectra_from_image(intensities, energy, y_locs, x_locs) + else: + raise IOError("Not a SoftiMAX file") class HDF5Reader_ROCK(FileFormat, SpectralFileFormat): From 38be6ec3151d7c123caffadce51e07eb3dcd1ac6 Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Wed, 18 Dec 2024 10:23:05 +0100 Subject: [PATCH 2/3] ensure old workflow compatibility by preferring HERMES over SoftiMax reader --- orangecontrib/spectroscopy/io/soleil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orangecontrib/spectroscopy/io/soleil.py b/orangecontrib/spectroscopy/io/soleil.py index 93d8bf4c0..93f58f0de 100644 --- a/orangecontrib/spectroscopy/io/soleil.py +++ b/orangecontrib/spectroscopy/io/soleil.py @@ -59,9 +59,9 @@ class HDF5Reader_SoftiMAX(FileFormat, SpectralFileFormat): """ A very case specific reader for HDF5 files from the SoftiMAX beamline in MAX-IV""" EXTENSIONS = ('.hdf5',) DESCRIPTION = 'HDF5 file @SoftiMAX/MAX-IV' + PRIORITY = HDF5Reader_HERMES.PRIORITY + 1 def read_spectra(self): - print("SoftiMax") import h5py with h5py.File(self.filename, 'r') as hdf5_file: if 'entry1/collection/beamline' in hdf5_file and \ From fbf168aeda39a9fe16da72c3f1f0372b4070991c Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Wed, 18 Dec 2024 10:49:35 +0100 Subject: [PATCH 3/3] Move SoftiMax reader to io/maxiv.py --- orangecontrib/spectroscopy/io/__init__.py | 2 +- orangecontrib/spectroscopy/io/maxiv.py | 23 ++++++++++++++++++++++- orangecontrib/spectroscopy/io/soleil.py | 20 -------------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/orangecontrib/spectroscopy/io/__init__.py b/orangecontrib/spectroscopy/io/__init__.py index 9f33338d6..a7a97e54a 100644 --- a/orangecontrib/spectroscopy/io/__init__.py +++ b/orangecontrib/spectroscopy/io/__init__.py @@ -21,6 +21,6 @@ # Facility-specific readers from .diamond import NXS_STXM_Diamond_I08 -from .maxiv import HDRReader_STXM +from .maxiv import HDRReader_STXM, HDF5Reader_SoftiMAX from .soleil import SelectColumnReader, HDF5Reader_HERMES, HDF5Reader_ROCK from .cls import HDF5Reader_SGM diff --git a/orangecontrib/spectroscopy/io/maxiv.py b/orangecontrib/spectroscopy/io/maxiv.py index 7f8e4115a..5eb7a3849 100644 --- a/orangecontrib/spectroscopy/io/maxiv.py +++ b/orangecontrib/spectroscopy/io/maxiv.py @@ -4,6 +4,7 @@ from Orange.data import FileFormat from orangecontrib.spectroscopy.io.util import SpectralFileFormat, _spectra_from_image +from orangecontrib.spectroscopy.io.soleil import HDF5Reader_HERMES class HDRReader_STXM(FileFormat, SpectralFileFormat): @@ -105,4 +106,24 @@ def read_spectra(self): x_loc = axes[1]['Points'] y_loc = axes[0]['Points'] features = np.asarray(axes[2]['Points']) - return _spectra_from_image(spectra, features, x_loc, y_loc) \ No newline at end of file + return _spectra_from_image(spectra, features, x_loc, y_loc) + + +class HDF5Reader_SoftiMAX(FileFormat, SpectralFileFormat): + """ A very case specific reader for HDF5 files from the SoftiMAX beamline in MAX-IV""" + EXTENSIONS = ('.hdf5',) + DESCRIPTION = 'HDF5 file @SoftiMAX/MAX-IV' + PRIORITY = HDF5Reader_HERMES.PRIORITY + 1 + + def read_spectra(self): + import h5py + with h5py.File(self.filename, 'r') as hdf5_file: + if 'entry1/collection/beamline' in hdf5_file and \ + hdf5_file['entry1/collection/beamline'][()].astype('str') == ['SLS Sophie at Softimax MAXIV']: + x_locs = np.array(hdf5_file['entry1/counter0/sample_x']) + y_locs = np.array(hdf5_file['entry1/counter0/sample_y']) + energy = np.array(hdf5_file['entry1/counter0/energy']) + intensities = np.array(hdf5_file['entry1/counter0/data']).T + return _spectra_from_image(intensities, energy, y_locs, x_locs) + else: + raise IOError("Not a SoftiMAX file") diff --git a/orangecontrib/spectroscopy/io/soleil.py b/orangecontrib/spectroscopy/io/soleil.py index 93f58f0de..0d7805ff2 100644 --- a/orangecontrib/spectroscopy/io/soleil.py +++ b/orangecontrib/spectroscopy/io/soleil.py @@ -55,26 +55,6 @@ def read_spectra(self): raise IOError("Not an HDF5 HERMES file") -class HDF5Reader_SoftiMAX(FileFormat, SpectralFileFormat): - """ A very case specific reader for HDF5 files from the SoftiMAX beamline in MAX-IV""" - EXTENSIONS = ('.hdf5',) - DESCRIPTION = 'HDF5 file @SoftiMAX/MAX-IV' - PRIORITY = HDF5Reader_HERMES.PRIORITY + 1 - - def read_spectra(self): - import h5py - with h5py.File(self.filename, 'r') as hdf5_file: - if 'entry1/collection/beamline' in hdf5_file and \ - hdf5_file['entry1/collection/beamline'][()].astype('str') == ['SLS Sophie at Softimax MAXIV']: - x_locs = np.array(hdf5_file['entry1/counter0/sample_x']) - y_locs = np.array(hdf5_file['entry1/counter0/sample_y']) - energy = np.array(hdf5_file['entry1/counter0/energy']) - intensities = np.array(hdf5_file['entry1/counter0/data']).T - return _spectra_from_image(intensities, energy, y_locs, x_locs) - else: - raise IOError("Not a SoftiMAX file") - - class HDF5Reader_ROCK(FileFormat, SpectralFileFormat): """ A very case specific reader for hyperspectral imaging HDF5 files from the ROCK beamline in SOLEIL"""