speed up (x 5 to 10) identification of most frequent microstructure index

This commit is contained in:
Philip Eisenlohr 2016-04-15 18:54:09 -04:00
parent 81f6530f52
commit 24d029c7ed
1 changed files with 5 additions and 9 deletions

View File

@ -6,15 +6,12 @@ import numpy as np
import damask import damask
from scipy import ndimage from scipy import ndimage
from optparse import OptionParser from optparse import OptionParser
from collections import defaultdict
scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version]) scriptID = ' '.join([scriptName,damask.version])
def mostFrequent(arr): def mostFrequent(arr):
d = defaultdict(int) return np.argmax(np.bincount(arr))
for i in arr: d[i] += 1
return sorted(d.iteritems(), key=lambda x: x[1], reverse=True)[0][0] # return value of most frequent microstructure
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
@ -43,8 +40,7 @@ parser.set_defaults(stencil = 3,
if filenames == []: filenames = [None] if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
try: try: table = damask.ASCIItable(name = name,
table = damask.ASCIItable(name = name,
buffered = False, buffered = False,
labeled = False) labeled = False)
except: continue except: continue