Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] SoftiMax HDF5 reader #779

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion orangecontrib/spectroscopy/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 22 additions & 1 deletion orangecontrib/spectroscopy/io/maxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
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")
20 changes: 10 additions & 10 deletions orangecontrib/spectroscopy/io/soleil.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ 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_ROCK(FileFormat, SpectralFileFormat):
Expand Down
Loading