From 9f7fa5393a8af1d784433262dfbbe8bebded5ab0 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 16 May 2019 09:31:13 +0200 Subject: [PATCH] fix for scalar datasets --- processing/post/DADF5_postResults.py | 12 +++++++++--- python/damask/dadf5.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/processing/post/DADF5_postResults.py b/processing/post/DADF5_postResults.py index b918388d9..1af8c2aa9 100755 --- a/processing/post/DADF5_postResults.py +++ b/processing/post/DADF5_postResults.py @@ -73,8 +73,11 @@ for filename in options.filenames: array = np.reshape(array,[np.product(results.grid),d]) data = np.concatenate((data,array),1) - header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)]) - + if d>1: + header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)]) + else: + header+=' '+label + for label in options.mat: for o in results.m_output_types: results.active['m_output_types'] = [o] @@ -89,7 +92,10 @@ for filename in options.filenames: array = np.reshape(array,[np.product(results.grid),d]) data = np.concatenate((data,array),1) - header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)]) + if d>1: + 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)) try: diff --git a/python/damask/dadf5.py b/python/damask/dadf5.py index 56082a1f4..0abde662b 100644 --- a/python/damask/dadf5.py +++ b/python/damask/dadf5.py @@ -126,19 +126,26 @@ class DADF5(): """ with h5py.File(self.filename,'r') as f: shape = (self.Nmaterialpoints,) + np.shape(f[path[0]])[1:] + if len(shape) == 1: shape = shape +(1,) dataset = np.full(shape,np.nan) for pa in path: label = pa.split('/')[2] try: p = np.where(f['mapping/cellResults/constituent'][:,c]['Name'] == str.encode(label))[0] 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: pass try: p = np.where(f['mapping/cellResults/materialpoint']['Name'] == str.encode(label))[0] 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: pass