2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2014-01-10 03:05:21 +05:30
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
try:
|
|
|
|
import h5py
|
2015-04-01 20:13:34 +05:30
|
|
|
except (ImportError) as e:
|
2016-05-11 19:34:01 +05:30
|
|
|
pass # sys.stderr.write('\nREMARK: h5py module not available \n\n')
|
2014-01-10 03:05:21 +05:30
|
|
|
|
|
|
|
class Result():
|
2016-03-04 23:20:13 +05:30
|
|
|
"""
|
|
|
|
General class for result parsing.
|
|
|
|
|
|
|
|
Needs h5py to be installed
|
|
|
|
"""
|
2014-01-10 03:05:21 +05:30
|
|
|
|
|
|
|
def __init__(self,resultsFile):
|
2014-01-16 03:47:32 +05:30
|
|
|
self.data=h5py.File(resultsFile,"r")
|
|
|
|
self.Npoints=self.data.attrs['Number of Materialpoints']
|
2016-07-03 15:14:12 +05:30
|
|
|
print("Opened {} with {} points".format(resultsFile,self.Npoints))
|
2014-01-10 03:05:21 +05:30
|
|
|
|
2014-01-16 03:47:32 +05:30
|
|
|
def getCrystallite(self,labels,inc,constituent=1,points=None):
|
2016-07-03 15:14:12 +05:30
|
|
|
if points is None: points = np.array(np.array(range(self.Npoints)))
|
2014-01-16 03:47:32 +05:30
|
|
|
results = {}
|
|
|
|
mapping=self.data['mapping/crystallite']
|
|
|
|
for instance in self.data['increments/%s/crystallite/'%inc]:
|
2016-07-03 15:14:12 +05:30
|
|
|
dsets = list(self.data['increments/%s/crystallite/%s'%(inc,instance)].keys())
|
2014-01-16 03:47:32 +05:30
|
|
|
for label in labels:
|
|
|
|
if label in dsets and label not in results:
|
|
|
|
shape = np.shape(self.data['increments/%s/crystallite/%s/%s'%(inc,instance,label)])[1:]
|
|
|
|
results[label] = np.nan*np.ones(np.array((self.Npoints,)+shape))
|
2016-07-03 15:14:12 +05:30
|
|
|
for myPoint in range(len(points)):
|
2014-01-16 03:47:32 +05:30
|
|
|
matPoint = points[myPoint]
|
|
|
|
pos = mapping[matPoint,constituent-1]
|
|
|
|
if pos[0] != 0:
|
|
|
|
try:
|
|
|
|
for label in labels:
|
|
|
|
results[label][matPoint,...] = self.data['increments/%s/crystallite/%s/%s'%(inc,pos[0],label)][pos[1],...]
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
return results
|