improved handling of string types for HDF5
- convert bytes to string when reading - convert string to bytes when writing
This commit is contained in:
parent
5f0a48fae7
commit
e51f6cee72
|
@ -401,22 +401,16 @@ class DADF5():
|
||||||
"""Adds the equivalent Mises stress or strain of a tensor."""
|
"""Adds the equivalent Mises stress or strain of a tensor."""
|
||||||
def Mises(x):
|
def Mises(x):
|
||||||
|
|
||||||
if x['meta']['Unit'] == b'Pa': #ToDo: Should we use this? Then add_Cauchy and add_strain_tensors also should perform sanity checks
|
if x['meta']['Unit'] == 'Pa': #ToDo: Should we use this? Then add_Cauchy and add_strain_tensors also should perform sanity checks
|
||||||
factor = 3.0/2.0
|
|
||||||
t = 'stress'
|
t = 'stress'
|
||||||
elif x['meta']['Unit'] == b'1':
|
elif x['meta']['Unit'] == '1':
|
||||||
factor = 2.0/3.0
|
|
||||||
t = 'strain'
|
t = 'strain'
|
||||||
else:
|
else:
|
||||||
print(x['meta']['Unit'])
|
print(x['meta']['Unit'])
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
d = x['data']
|
|
||||||
dev = d - np.einsum('ijk,i->ijk',np.broadcast_to(np.eye(3),[d.shape[0],3,3]),np.trace(d,axis1=1,axis2=2)/3.0)
|
|
||||||
#dev_sym = (dev + np.einsum('ikj',dev))*0.5 # ToDo: this is not needed (only if the input is not symmetric, but then the whole concept breaks down)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'data' : np.sqrt(np.einsum('ijk->i',dev**2)*factor),
|
'data' : mechanics.Mises_strain(x['data']) if t=='strain' else mechanics.Mises_stress(x['data']),
|
||||||
'label' : '{}_vM'.format(x['label']),
|
'label' : '{}_vM'.format(x['label']),
|
||||||
'meta' : {
|
'meta' : {
|
||||||
'Unit' : x['meta']['Unit'],
|
'Unit' : x['meta']['Unit'],
|
||||||
|
@ -699,7 +693,7 @@ class DADF5():
|
||||||
for d in datasets_requested:
|
for d in datasets_requested:
|
||||||
loc = f[group+'/'+d['label']]
|
loc = f[group+'/'+d['label']]
|
||||||
data = loc[()]
|
data = loc[()]
|
||||||
meta = {k:loc.attrs[k] for k in loc.attrs.keys()}
|
meta = {k:loc.attrs[k].decode() for k in loc.attrs.keys()}
|
||||||
datasets_in[d['arg']] = {'data': data, 'meta' : meta, 'label' : d['label']}
|
datasets_in[d['arg']] = {'data': data, 'meta' : meta, 'label' : d['label']}
|
||||||
|
|
||||||
todo.append({'in':{**datasets_in,**extra_args},'func':func,'group':group,'results':results})
|
todo.append({'in':{**datasets_in,**extra_args},'func':func,'group':group,'results':results})
|
||||||
|
@ -712,7 +706,7 @@ class DADF5():
|
||||||
with h5py.File(self.filename,'a') as f: # write to file
|
with h5py.File(self.filename,'a') as f: # write to file
|
||||||
dataset_out = f[result['group']].create_dataset(result['label'],data=result['data'])
|
dataset_out = f[result['group']].create_dataset(result['label'],data=result['data'])
|
||||||
for k in result['meta'].keys():
|
for k in result['meta'].keys():
|
||||||
dataset_out.attrs[k] = result['meta'][k]
|
dataset_out.attrs[k] = result['meta'][k].encode()
|
||||||
N_not_calculated-=1
|
N_not_calculated-=1
|
||||||
|
|
||||||
if N_added < len(todo): # add more jobs
|
if N_added < len(todo): # add more jobs
|
||||||
|
|
Loading…
Reference in New Issue