summaryrefslogtreecommitdiff
path: root/silx/io/dictdump.py
diff options
context:
space:
mode:
authorPicca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>2019-12-23 13:45:09 +0100
committerPicca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>2019-12-23 13:45:09 +0100
commit5d647cf9a6159afd2933da594b9c79ad93d3cd9b (patch)
tree2571025a602f68fc8933b01104dc712d41f84034 /silx/io/dictdump.py
parent654a6ac93513c3cc1ef97cacd782ff674c6f4559 (diff)
New upstream version 0.12.0~b0+dfsg
Diffstat (limited to 'silx/io/dictdump.py')
-rw-r--r--silx/io/dictdump.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/silx/io/dictdump.py b/silx/io/dictdump.py
index e8cabcf..da1bc5c 100644
--- a/silx/io/dictdump.py
+++ b/silx/io/dictdump.py
@@ -1,6 +1,6 @@
# coding: utf-8
# /*##########################################################################
-# Copyright (C) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (C) 2016-2019 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -263,7 +263,7 @@ def _name_contains_string_in_list(name, strlist):
return False
-def h5todict(h5file, path="/", exclude_names=None):
+def h5todict(h5file, path="/", exclude_names=None, asarray=True):
"""Read a HDF5 file and return a nested dictionary with the complete file
structure and all data.
@@ -299,6 +299,8 @@ def h5todict(h5file, path="/", exclude_names=None):
to read only a sub-group in the file
:param List[str] exclude_names: Groups and datasets whose name contains
a string in this list will be ignored. Default is None (ignore nothing)
+ :param bool asarray: True (default) to read scalar as arrays, False to
+ read them as scalar
:return: Nested dictionary
"""
with _SafeH5FileRead(h5file) as h5f:
@@ -309,10 +311,14 @@ def h5todict(h5file, path="/", exclude_names=None):
if is_group(h5f[path + "/" + key]):
ddict[key] = h5todict(h5f,
path + "/" + key,
- exclude_names=exclude_names)
+ exclude_names=exclude_names,
+ asarray=asarray)
else:
- # Convert HDF5 dataset to numpy array
- ddict[key] = h5f[path + "/" + key][...]
+ # Read HDF5 datset
+ data = h5f[path + "/" + key][()]
+ if asarray: # Convert HDF5 dataset to numpy array
+ data = numpy.array(data, copy=False)
+ ddict[key] = data
return ddict