fix for scalar datasets

This commit is contained in:
Martin Diehl 2019-05-16 09:31:13 +02:00
parent 4599d1c34e
commit 9f7fa5393a
2 changed files with 18 additions and 5 deletions

View File

@ -73,7 +73,10 @@ for filename in options.filenames:
array = np.reshape(array,[np.product(results.grid),d]) array = np.reshape(array,[np.product(results.grid),d])
data = np.concatenate((data,array),1) data = np.concatenate((data,array),1)
if d>1:
header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)]) header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)])
else:
header+=' '+label
for label in options.mat: for label in options.mat:
for o in results.m_output_types: for o in results.m_output_types:
@ -89,7 +92,10 @@ for filename in options.filenames:
array = np.reshape(array,[np.product(results.grid),d]) array = np.reshape(array,[np.product(results.grid),d])
data = np.concatenate((data,array),1) data = np.concatenate((data,array),1)
if d>1:
header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)]) header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)])
else:
header+=' '+label
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir)) dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
try: try:

View File

@ -126,19 +126,26 @@ class DADF5():
""" """
with h5py.File(self.filename,'r') as f: with h5py.File(self.filename,'r') as f:
shape = (self.Nmaterialpoints,) + np.shape(f[path[0]])[1:] shape = (self.Nmaterialpoints,) + np.shape(f[path[0]])[1:]
if len(shape) == 1: shape = shape +(1,)
dataset = np.full(shape,np.nan) dataset = np.full(shape,np.nan)
for pa in path: for pa in path:
label = pa.split('/')[2] label = pa.split('/')[2]
try: try:
p = np.where(f['mapping/cellResults/constituent'][:,c]['Name'] == str.encode(label))[0] p = np.where(f['mapping/cellResults/constituent'][:,c]['Name'] == str.encode(label))[0]
u = (f['mapping/cellResults/constituent'][p,c]['Position']) u = (f['mapping/cellResults/constituent'][p,c]['Position'])
dataset[p,:] = f[pa][u,:] # does not work for scalar datasets a = np.array(f[pa])
if len(a.shape) == 1:
a=a.reshape([a.shape[0],1])
dataset
except: except:
pass pass
try: try:
p = np.where(f['mapping/cellResults/materialpoint']['Name'] == str.encode(label))[0] p = np.where(f['mapping/cellResults/materialpoint']['Name'] == str.encode(label))[0]
u = (f['mapping/cellResults/materialpoint'][p.tolist()]['Position']) u = (f['mapping/cellResults/materialpoint'][p.tolist()]['Position'])
dataset[p,:] = f[pa][u,:] # does not work for scalar datasets a = np.array(f[pa])
if len(a.shape) == 1:
a=a.reshape([a.shape[0],1])
dataset[p,:] = a[u,:]
except: except:
pass pass