From 32c34457c28a558a6afefa3b3d8d87e6e07fd78c Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 7 Mar 2018 17:45:22 -0500 Subject: [PATCH] direct selection of valid seed coordinates within subfraction of unit cube instead of check and repeat --- processing/pre/seeds_fromRandom.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/processing/pre/seeds_fromRandom.py b/processing/pre/seeds_fromRandom.py index 0df292ed2..3045359ef 100755 --- a/processing/pre/seeds_fromRandom.py +++ b/processing/pre/seeds_fromRandom.py @@ -166,25 +166,11 @@ for name in filenames: grainEuler[2,:] *= 360.0 # phi_2 is uniformly distributed if not options.selective: - seeds = np.array([]) + n = np.array(options.grid * options.fraction,dtype=int) # find valid grid indices within fraction + meshgrid = np.meshgrid(*map(np.arange,n),indexing='ij') # create a meshgrid within fraction - while len(seeds) < options.N: - - theSeeds = np.zeros((options.N,3),dtype=float) # seed positions array - gridpoints = random.sample(range(gridSize),options.N) # choose first N from random permutation of grid positions - - theSeeds[:,0] = (np.mod(gridpoints ,options.grid[0])\ - +np.random.random(options.N)) /options.grid[0] - theSeeds[:,1] = (np.mod(gridpoints// options.grid[0] ,options.grid[1])\ - +np.random.random(options.N)) /options.grid[1] - theSeeds[:,2] = (np.mod(gridpoints//(options.grid[1]*options.grid[0]),options.grid[2])\ - +np.random.random(options.N)) /options.grid[2] - - goodSeeds = theSeeds[np.all(theSeeds<=options.fraction,axis=1)] # pick seeds within threshold fraction - seeds = goodSeeds if len(seeds) == 0 else np.vstack((seeds,goodSeeds)) - if len(seeds) > options.N: seeds = seeds[:min(options.N,len(seeds))] - - seeds = seeds.T # switch layout to point index as last index + coords = np.vstack((meshgrid[0],meshgrid[1],meshgrid[2])).reshape(3,n.prod()).T # assemble list of 3D coordinates + seeds = ((random.sample(coords,options.N)+np.random.random(options.N*3).reshape(options.N,3))/options.grid).T # pick options.N of those and rattle position else: