Skip to content

Commit

Permalink
Merge pull request #779 from borondics/SoftiMax_reader
Browse files Browse the repository at this point in the history
[ENH] SoftiMax HDF5 reader
  • Loading branch information
markotoplak authored Dec 18, 2024
2 parents 0d49e68 + fbf168a commit 2bbb856
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
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

0 comments on commit 2bbb856

Please sign in to comment.