Vectorized checking of neighbourhood for unique microstructure
(faster) M addEuclideanDistance.py
This commit is contained in:
parent
98d02dcffb
commit
eaf7072bc1
|
@ -180,6 +180,9 @@ for file in files:
|
||||||
convoluted = numpy.empty([len(neighborhood)]+list(resolution+2),'i')
|
convoluted = numpy.empty([len(neighborhood)]+list(resolution+2),'i')
|
||||||
microstructure = periodic_3Dpad(numpy.array(structure[:,3].reshape(resolution),'i'))
|
microstructure = periodic_3Dpad(numpy.array(structure[:,3].reshape(resolution),'i'))
|
||||||
|
|
||||||
|
print 'setup | time = '+repr(time.clock()-cputime)
|
||||||
|
cputime = time.clock()
|
||||||
|
|
||||||
for i,p in enumerate(neighborhood):
|
for i,p in enumerate(neighborhood):
|
||||||
stencil = numpy.zeros((3,3,3),'i')
|
stencil = numpy.zeros((3,3,3),'i')
|
||||||
stencil[1,1,1] = -1
|
stencil[1,1,1] = -1
|
||||||
|
@ -190,13 +193,13 @@ for file in files:
|
||||||
convoluted[i,:,:,:] = ndimage.convolve(microstructure,stencil)
|
convoluted[i,:,:,:] = ndimage.convolve(microstructure,stencil)
|
||||||
|
|
||||||
distance = numpy.ones((len(feature_list),resolution[0],resolution[1],resolution[2]),'d')
|
distance = numpy.ones((len(feature_list),resolution[0],resolution[1],resolution[2]),'d')
|
||||||
for x in xrange(resolution[0]):
|
|
||||||
for y in xrange(resolution[1]):
|
uniques = numpy.ones(resolution)
|
||||||
for z in xrange(resolution[2]):
|
for i in xrange(len(neighborhood)):
|
||||||
uniques = len(numpy.unique(convoluted[:,x+1,y+1,z+1]))
|
for j in xrange(len(neighborhood)):
|
||||||
|
uniques += numpy.where(convoluted[i,1:-1,1:-1,1:-1] == convoluted[j,1:-1,1:-1,1:-1],1,0)
|
||||||
for i,feature_id in enumerate(feature_list):
|
for i,feature_id in enumerate(feature_list):
|
||||||
if uniques > features[feature_id]['aliens']:
|
distance[i,:,:,:] = numpy.where(uniques > features[feature_id]['aliens'],0.0,1.0)
|
||||||
distance[i,x,y,z] = 0.0 # found a starting point
|
|
||||||
|
|
||||||
for i in xrange(len(feature_list)):
|
for i in xrange(len(feature_list)):
|
||||||
distance[i,:,:,:] = skfmm.distance(distance[i,:,:,:], dx=[unitlength]*3)
|
distance[i,:,:,:] = skfmm.distance(distance[i,:,:,:], dx=[unitlength]*3)
|
||||||
|
|
Loading…
Reference in New Issue