Commit b0587814 authored by Thomas Vincent's avatar Thomas Vincent

use str_to_hdf5_utf8 and _get_array_str

parent 7eb6822c
......@@ -156,10 +156,8 @@ class QSpaceH5(XsocsH5Base):
def selected_entries(self):
"""Returns the input entries used for the conversion."""
path = self._ENTRIES_PATH + '/selected'
entries = self._get_array_data(path)
if entries is not None:
return [entry.decode() for entry in entries]
return []
entries = self._get_array_str(path)
return entries if entries is not None else []
@property
def shifts(self):
......@@ -207,10 +205,8 @@ class QSpaceH5(XsocsH5Base):
Returns the input entries that were not used for the conversion.
"""
path = self._ENTRIES_PATH + '/discarded'
entries = self._get_array_data(path)
if entries is not None:
return [entry.decode() for entry in entries]
return []
entries = self._get_array_str(path)
return entries if entries is not None else []
@property
def image_mask(self):
......@@ -434,11 +430,10 @@ class QSpaceH5Writer(QSpaceH5):
number of selected entries. The shift is in grid coordinates.
"""
path = self._ENTRIES_PATH + '/selected'
selected = _np.array(selected, dtype=_np.string_)
selected = str_to_h5_utf8(selected)
self._set_array_data(path, selected)
path = self._ENTRIES_PATH + '/discarded'
discarded = _np.array((discarded is not None and discarded) or [],
dtype=_np.string_)
discarded = str_to_h5_utf8(discarded if discarded is not None or [])
self._set_array_data(path, discarded)
if sample_shifts is not None:
......
......@@ -160,6 +160,18 @@ class XsocsH5Base(object):
except KeyError:
return None
def _get_array_str(self, path):
"""Returns the array of string contained in the dataset.
:param str path: The path of the dataset in the HDF5 file
:rtype: List[str]
"""
strings = self._get_array_data(path=path)
if strings is None:
return None
else:
return [s.decode() if hasattr(s, 'decode') else s for s in strings]
def _set_scalar_data(self, path, value):
with self._get_file() as h5_f:
value_np = _np.array(value)
......
Markdown is supported
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