output all datasets per default
respect 'field' selection
This commit is contained in:
parent
18afa217fe
commit
e8ff509502
|
@ -25,10 +25,10 @@ from . import util
|
||||||
|
|
||||||
h5py3 = h5py.__version__[0] == '3'
|
h5py3 = h5py.__version__[0] == '3'
|
||||||
|
|
||||||
def _read(handle,path):
|
def _read(dataset):
|
||||||
metadata = {k:(v if h5py3 else v.decode()) for k,v in handle[path].attrs.items()}
|
metadata = {k:(v if h5py3 else v.decode()) for k,v in dataset.attrs.items()}
|
||||||
dtype = np.dtype(handle[path].dtype,metadata=metadata)
|
dtype = np.dtype(dataset.dtype,metadata=metadata)
|
||||||
return np.array(handle[path],dtype=dtype)
|
return np.array(dataset,dtype=dtype)
|
||||||
|
|
||||||
|
|
||||||
class Result:
|
class Result:
|
||||||
|
@ -1274,7 +1274,6 @@ class Result:
|
||||||
|
|
||||||
# compatibility hack
|
# compatibility hack
|
||||||
ln = 3 if self.version_minor < 12 else 10
|
ln = 3 if self.version_minor < 12 else 10
|
||||||
|
|
||||||
N_digits = int(np.floor(np.log10(max(1,int(self.increments[-1][ln:])))))+1
|
N_digits = int(np.floor(np.log10(max(1,int(self.increments[-1][ln:])))))+1
|
||||||
|
|
||||||
for inc in util.show_progress(self.iterate('increments'),len(self.visible['increments'])):
|
for inc in util.show_progress(self.iterate('increments'),len(self.visible['increments'])):
|
||||||
|
@ -1322,7 +1321,7 @@ class Result:
|
||||||
v.save(f'{self.fname.stem}_inc{inc[ln:].zfill(N_digits)}')
|
v.save(f'{self.fname.stem}_inc{inc[ln:].zfill(N_digits)}')
|
||||||
|
|
||||||
|
|
||||||
def read(self,output,flatten=True,prune=True):
|
def read(self,output='*',flatten=True,prune=True):
|
||||||
"""
|
"""
|
||||||
Export data per phase/homogenization.
|
Export data per phase/homogenization.
|
||||||
|
|
||||||
|
@ -1332,12 +1331,12 @@ class Result:
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
output : str or list of str
|
output : str or list of str
|
||||||
Labels of the datasets to read.
|
Labels of the datasets to read. Defaults to '*', in which
|
||||||
|
case all datasets are placed.
|
||||||
flatten : bool
|
flatten : bool
|
||||||
Remove singular levels of the folder hierarchy.
|
Remove singular levels of the folder hierarchy.
|
||||||
This might be beneficial in case of a
|
This might be beneficial in case of single increment,
|
||||||
single constituent, phase, or increment.
|
phase/homogenization, or field. Defaults to True.
|
||||||
Defaults to True.
|
|
||||||
prune : bool
|
prune : bool
|
||||||
Remove branches with no data. Defaults to True.
|
Remove branches with no data. Defaults to True.
|
||||||
|
|
||||||
|
@ -1349,16 +1348,18 @@ class Result:
|
||||||
for inc in util.show_progress(self.visible['increments']):
|
for inc in util.show_progress(self.visible['increments']):
|
||||||
r[inc] = {'phase':{},'homogenization':{},'geometry':{}}
|
r[inc] = {'phase':{},'homogenization':{},'geometry':{}}
|
||||||
|
|
||||||
for out in output_.intersection(f['/'.join((inc,'geometry'))].keys()):
|
for out in f['/'.join((inc,'geometry'))].keys() if '*' in output_ else \
|
||||||
r[inc]['geometry'][out] = _read(f,'/'.join((inc,'geometry',out)))
|
output_.intersection(f['/'.join((inc,'geometry'))].keys()):
|
||||||
|
r[inc]['geometry'][out] = _read(f['/'.join((inc,'geometry',out))])
|
||||||
|
|
||||||
for ty in ['phase','homogenization']:
|
for ty in ['phase','homogenization']:
|
||||||
for label in self.visible[ty+'s']:
|
for label in self.visible[ty+'s']:
|
||||||
r[inc][ty][label] = {}
|
r[inc][ty][label] = {}
|
||||||
for field in f['/'.join((inc,ty,label))].keys():
|
for field in set(self.visible['fields']).union(f['/'.join((inc,ty,label))].keys()):
|
||||||
r[inc][ty][label][field] = {}
|
r[inc][ty][label][field] = {}
|
||||||
for out in output_.intersection(f['/'.join((inc,ty,label,field))].keys()):
|
for out in f['/'.join((inc,ty,label,field))].keys() if '*' in output_ else \
|
||||||
r[inc][ty][label][field][out] = _read(f,'/'.join((inc,ty,label,field,out)))
|
output_.intersection(f['/'.join((inc,ty,label,field))].keys()):
|
||||||
|
r[inc][ty][label][field][out] = _read(f['/'.join((inc,ty,label,field,out))])
|
||||||
|
|
||||||
if prune: r = util.dict_prune(r)
|
if prune: r = util.dict_prune(r)
|
||||||
if flatten: r = util.dict_flatten(r)
|
if flatten: r = util.dict_flatten(r)
|
||||||
|
@ -1366,7 +1367,7 @@ class Result:
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def place(self,output,flatten=True,prune=True,constituents=None,fill_float=0.0,fill_int=0):
|
def place(self,output='*',flatten=True,prune=True,constituents=None,fill_float=0.0,fill_int=0):
|
||||||
"""
|
"""
|
||||||
Export data in spatial order that is compatible with the damask.VTK geometry representation.
|
Export data in spatial order that is compatible with the damask.VTK geometry representation.
|
||||||
|
|
||||||
|
@ -1379,12 +1380,12 @@ class Result:
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
output : str or list of, optional
|
output : str or list of, optional
|
||||||
Labels of the datasets to place.
|
Labels of the datasets to place. Defaults to '*', in which
|
||||||
|
case all datasets are placed.
|
||||||
flatten : bool
|
flatten : bool
|
||||||
Remove singular levels of the folder hierarchy.
|
Remove singular levels of the folder hierarchy.
|
||||||
This might be beneficial in case of a
|
This might be beneficial in case of single increment
|
||||||
single constituent, phase, or increment.
|
or field. Defaults to True.
|
||||||
Defaults to True.
|
|
||||||
prune : bool
|
prune : bool
|
||||||
Remove branches with no data. Defaults to True.
|
Remove branches with no data. Defaults to True.
|
||||||
constituents : int or list of, optional
|
constituents : int or list of, optional
|
||||||
|
@ -1429,21 +1430,23 @@ class Result:
|
||||||
for inc in util.show_progress(self.visible['increments']):
|
for inc in util.show_progress(self.visible['increments']):
|
||||||
r[inc] = {'phase':{},'homogenization':{},'geometry':{}}
|
r[inc] = {'phase':{},'homogenization':{},'geometry':{}}
|
||||||
|
|
||||||
for out in output_.intersection(f['/'.join((inc,'geometry'))].keys()):
|
for out in f['/'.join((inc,'geometry'))].keys() if '*' in output_ else \
|
||||||
r[inc]['geometry'][out] = _read(f,'/'.join((inc,'geometry',out)))
|
output_.intersection(f['/'.join((inc,'geometry'))].keys()):
|
||||||
|
r[inc]['geometry'][out] = _read(f['/'.join((inc,'geometry',out))])
|
||||||
|
|
||||||
for ty in ['phase','homogenization']:
|
for ty in ['phase','homogenization']:
|
||||||
for label in self.visible[ty+'s']:
|
for label in self.visible[ty+'s']:
|
||||||
for field in f['/'.join((inc,ty,label))].keys():
|
for field in set(self.visible['fields']).union(f['/'.join((inc,ty,label))].keys()):
|
||||||
if field not in r[inc][ty].keys():
|
if field not in r[inc][ty].keys():
|
||||||
r[inc][ty][field] = {}
|
r[inc][ty][field] = {}
|
||||||
|
|
||||||
for out in output_.intersection(f['/'.join((inc,ty,label,field))].keys()):
|
for out in f['/'.join((inc,ty,label,field))].keys() if '*' in output_ else \
|
||||||
data = ma.array(_read(f,'/'.join((inc,ty,label,field,out))))
|
output_.intersection(f['/'.join((inc,ty,label,field))].keys()):
|
||||||
|
data = ma.array(_read(f['/'.join((inc,ty,label,field,out))]))
|
||||||
|
|
||||||
if ty == 'phase':
|
if ty == 'phase':
|
||||||
if out+suffixes[0] not in r[inc][ty][field].keys():
|
if out+suffixes[0] not in r[inc][ty][field].keys():
|
||||||
container = np.empty((self.N_materialpoints,)+data.shape[1:],dtype=data.dtype)
|
container = np.empty((self.N_materialpoints,)+data.shape[1:],data.dtype)
|
||||||
fill_value = fill_float if data.dtype in np.sctypes['float'] else \
|
fill_value = fill_float if data.dtype in np.sctypes['float'] else \
|
||||||
fill_int
|
fill_int
|
||||||
for c,suffix in zip(constituents_,suffixes):
|
for c,suffix in zip(constituents_,suffixes):
|
||||||
|
@ -1455,7 +1458,7 @@ class Result:
|
||||||
|
|
||||||
if ty == 'homogenization':
|
if ty == 'homogenization':
|
||||||
if out not in r[inc][ty][field].keys():
|
if out not in r[inc][ty][field].keys():
|
||||||
container = np.empty((self.N_materialpoints,)+data.shape[1:],dtype=data.dtype)
|
container = np.empty((self.N_materialpoints,)+data.shape[1:],data.dtype)
|
||||||
fill_value = fill_float if data.dtype in np.sctypes['float'] else \
|
fill_value = fill_float if data.dtype in np.sctypes['float'] else \
|
||||||
fill_int
|
fill_int
|
||||||
r[inc][ty][field][out] = \
|
r[inc][ty][field][out] = \
|
||||||
|
|
Loading…
Reference in New Issue