Merge pull request #585 from acq4/metaarray-appendable-keys
MetaArray: make it possible to append multiple axis values
This commit is contained in:
commit
97c35e6bb4
@ -748,7 +748,6 @@ class MetaArray(object):
|
|||||||
else:
|
else:
|
||||||
fd.seek(0)
|
fd.seek(0)
|
||||||
meta = MetaArray._readMeta(fd)
|
meta = MetaArray._readMeta(fd)
|
||||||
|
|
||||||
if not kwargs.get("readAllData", True):
|
if not kwargs.get("readAllData", True):
|
||||||
self._data = np.empty(meta['shape'], dtype=meta['type'])
|
self._data = np.empty(meta['shape'], dtype=meta['type'])
|
||||||
if 'version' in meta:
|
if 'version' in meta:
|
||||||
@ -1031,6 +1030,7 @@ class MetaArray(object):
|
|||||||
"""Write this object to a file. The object can be restored by calling MetaArray(file=fileName)
|
"""Write this object to a file. The object can be restored by calling MetaArray(file=fileName)
|
||||||
opts:
|
opts:
|
||||||
appendAxis: the name (or index) of the appendable axis. Allows the array to grow.
|
appendAxis: the name (or index) of the appendable axis. Allows the array to grow.
|
||||||
|
appendKeys: a list of keys (other than "values") for metadata to append to on the appendable axis.
|
||||||
compression: None, 'gzip' (good compression), 'lzf' (fast compression), etc.
|
compression: None, 'gzip' (good compression), 'lzf' (fast compression), etc.
|
||||||
chunks: bool or tuple specifying chunk shape
|
chunks: bool or tuple specifying chunk shape
|
||||||
"""
|
"""
|
||||||
@ -1097,7 +1097,6 @@ class MetaArray(object):
|
|||||||
'compression': None
|
'compression': None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## set maximum shape to allow expansion along appendAxis
|
## set maximum shape to allow expansion along appendAxis
|
||||||
append = False
|
append = False
|
||||||
if appAxis is not None:
|
if appAxis is not None:
|
||||||
@ -1125,14 +1124,19 @@ class MetaArray(object):
|
|||||||
data[tuple(sl)] = self.view(np.ndarray)
|
data[tuple(sl)] = self.view(np.ndarray)
|
||||||
|
|
||||||
## add axis values if they are present.
|
## add axis values if they are present.
|
||||||
|
axKeys = ["values"]
|
||||||
|
axKeys.extend(opts.get("appendKeys", []))
|
||||||
axInfo = f['info'][str(ax)]
|
axInfo = f['info'][str(ax)]
|
||||||
if 'values' in axInfo:
|
for key in axKeys:
|
||||||
v = axInfo['values']
|
if key in axInfo:
|
||||||
v2 = self._info[ax]['values']
|
v = axInfo[key]
|
||||||
|
v2 = self._info[ax][key]
|
||||||
shape = list(v.shape)
|
shape = list(v.shape)
|
||||||
shape[0] += v2.shape[0]
|
shape[0] += v2.shape[0]
|
||||||
v.resize(shape)
|
v.resize(shape)
|
||||||
v[-v2.shape[0]:] = v2
|
v[-v2.shape[0]:] = v2
|
||||||
|
else:
|
||||||
|
raise TypeError('Cannot append to axis info key "%s"; this key is not present in the target file.' % key)
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
f = h5py.File(fileName, 'w')
|
f = h5py.File(fileName, 'w')
|
||||||
|
Loading…
Reference in New Issue
Block a user