speed up (x 5 to 10) identification of most frequent microstructure index
This commit is contained in:
parent
81f6530f52
commit
24d029c7ed
|
@ -6,15 +6,12 @@ import numpy as np
|
|||
import damask
|
||||
from scipy import ndimage
|
||||
from optparse import OptionParser
|
||||
from collections import defaultdict
|
||||
|
||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||
scriptID = ' '.join([scriptName,damask.version])
|
||||
|
||||
def mostFrequent(arr):
|
||||
d = defaultdict(int)
|
||||
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
|
||||
return np.argmax(np.bincount(arr))
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
|
@ -43,10 +40,9 @@ parser.set_defaults(stencil = 3,
|
|||
if filenames == []: filenames = [None]
|
||||
|
||||
for name in filenames:
|
||||
try:
|
||||
table = damask.ASCIItable(name = name,
|
||||
buffered = False,
|
||||
labeled = False)
|
||||
try: table = damask.ASCIItable(name = name,
|
||||
buffered = False,
|
||||
labeled = False)
|
||||
except: continue
|
||||
damask.util.report(scriptName,name)
|
||||
|
||||
|
@ -72,7 +68,7 @@ for name in filenames:
|
|||
|
||||
# --- read data ------------------------------------------------------------------------------------
|
||||
|
||||
microstructure = table.microstructure_read(info['grid']).reshape(info['grid'],order='F') # read microstructure
|
||||
microstructure = table.microstructure_read(info['grid']).reshape(info['grid'],order='F') # read microstructure
|
||||
|
||||
# --- do work ------------------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue