Commit cc07294a authored by Thomas Vincent's avatar Thomas Vincent
Browse files

use h5py_read_dataset where needed

parent 9b4d33b6
...@@ -39,6 +39,11 @@ import numpy as _np ...@@ -39,6 +39,11 @@ import numpy as _np
from .XsocsH5Base import XsocsH5Base from .XsocsH5Base import XsocsH5Base
from ._utils import str_to_h5_utf8, find_NX_class from ._utils import str_to_h5_utf8, find_NX_class
try: # silx >= 0.14
from silx.io.utils import h5py_read_dataset
except ImportError: # Fall back for silx < 0.14
from ..util.silx_io_utils import h5py_read_dataset
class InvalidEntryError(Exception): class InvalidEntryError(Exception):
pass pass
...@@ -80,7 +85,7 @@ class XsocsH5(XsocsH5Base): ...@@ -80,7 +85,7 @@ class XsocsH5(XsocsH5Base):
def title(self, entry): def title(self, entry):
with self._get_file() as h5_file: with self._get_file() as h5_file:
path = entry + '/title' path = entry + '/title'
return h5_file[path][()] return h5py_read_dataset(h5_file[path], decode_ascii=True)
@_process_entry @_process_entry
def entry_filename(self, entry): def entry_filename(self, entry):
......
...@@ -47,6 +47,11 @@ import fabio ...@@ -47,6 +47,11 @@ import fabio
from ...io import XsocsH5 from ...io import XsocsH5
from ... import config from ... import config
try: # silx >= 0.14
from silx.io.utils import h5py_read_dataset
except ImportError: # Fall back for silx < 0.14
from ...util.silx_io_utils import h5py_read_dataset
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
...@@ -397,7 +402,7 @@ class KmapMerger(object): ...@@ -397,7 +402,7 @@ class KmapMerger(object):
except KeyError: except KeyError:
raise ValueError('Scan ID {0} not found.'.format(scan_id)) raise ValueError('Scan ID {0} not found.'.format(scan_id))
command = scan['title'][()] command = h5py_read_dataset(scan['title'], decode_ascii=True)
try: try:
return parse_scan_command(command) return parse_scan_command(command)
...@@ -426,7 +431,8 @@ class KmapMerger(object): ...@@ -426,7 +431,8 @@ class KmapMerger(object):
calibration = {} calibration = {}
# Parse spec header to find calibration # Parse spec header to find calibration
header = scan['instrument/specfile/scan_header'][()] header = h5py_read_dataset(
scan['instrument/specfile/scan_header'], decode_ascii=True)
for line in header: for line in header:
if line.startswith('#UDETCALIB ') or line.startswith('#UMONO '): if line.startswith('#UDETCALIB ') or line.startswith('#UMONO '):
params = line.split(' ')[1].strip().split(',') params = line.split(' ')[1].strip().split(',')
...@@ -746,7 +752,8 @@ def _add_edf_data(scan_id, ...@@ -746,7 +752,8 @@ def _add_edf_data(scan_id,
entry_h5f.copy_group(spec_h5_fn, scan_id, entry) entry_h5f.copy_group(spec_h5_fn, scan_id, entry)
with h5py.File(spec_h5_fn, mode='r') as spec_h5: with h5py.File(spec_h5_fn, mode='r') as spec_h5:
command = spec_h5[scan_id]['title'][()] command = h5py_read_dataset(
spec_h5[scan_id]['title'], decode_ascii=True)
command_params = parse_scan_command(command) command_params = parse_scan_command(command)
entry_h5f.set_scan_params(entry, **command_params) entry_h5f.set_scan_params(entry, **command_params)
......
...@@ -39,6 +39,10 @@ from threading import Thread ...@@ -39,6 +39,10 @@ from threading import Thread
import h5py import h5py
from silx.io import convert from silx.io import convert
try: # silx >= 0.14
from silx.io.utils import h5py_read_dataset
except ImportError: # Fall back for silx < 0.14
from ...util.silx_io_utils import h5py_read_dataset
# regular expression matching the imageFile comment line # regular expression matching the imageFile comment line
...@@ -246,7 +250,8 @@ def _spec_get_img_filenames(spec_h5_filename): ...@@ -246,7 +250,8 @@ def _spec_get_img_filenames(spec_h5_filename):
regx = re.compile(_IMAGEFILE_LINE_PATTERN) regx = re.compile(_IMAGEFILE_LINE_PATTERN)
for k_scan, v_scan in h5_f.items(): for k_scan, v_scan in h5_f.items():
header = v_scan['instrument/specfile/scan_header'][()] header = h5py_read_dataset(
v_scan['instrument/specfile/scan_header'], decode_ascii=True)
imgfile_match = [m for line in header imgfile_match = [m for line in header
if line.startswith('#C imageFile') if line.startswith('#C imageFile')
for m in [regx.match(line.strip())] if m] for m in [regx.match(line.strip())] if m]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment