simplified

This commit is contained in:
Martin Diehl 2020-03-17 10:49:30 +01:00
parent ba8eab646b
commit f46d79ec87
1 changed files with 8 additions and 17 deletions

View File

@ -18,7 +18,7 @@ def kdtree_search(cloud, queryPoints):
n = queryPoints.shape[0] n = queryPoints.shape[0]
distances = np.zeros(n,dtype=float) distances = np.zeros(n,dtype=float)
tree = spatial.cKDTree(cloud) tree = spatial.cKDTree(cloud)
for i in range(n): for i in range(n):
distances[i], index = tree.query(queryPoints[i]) distances[i], index = tree.query(queryPoints[i])
@ -58,9 +58,6 @@ parser.add_option('-r',
'--rnd', '--rnd',
dest = 'randomSeed', type = 'int', metavar = 'int', dest = 'randomSeed', type = 'int', metavar = 'int',
help = 'seed of random number generator [%default]') help = 'seed of random number generator [%default]')
parser.add_option('--format',
dest = 'format', type = 'string', metavar = 'string',
help = 'output number format [auto]')
group = OptionGroup(parser, "Laguerre Tessellation", group = OptionGroup(parser, "Laguerre Tessellation",
"Parameters determining shape of weight distribution of seed points" "Parameters determining shape of weight distribution of seed points"
@ -99,7 +96,7 @@ group.add_option( '--distance',
group.add_option( '--numCandidates', group.add_option( '--numCandidates',
dest = 'numCandidates', dest = 'numCandidates',
type = 'int', metavar = 'int', type = 'int', metavar = 'int',
help = 'size of point group to select best distance from [%default]') help = 'size of point group to select best distance from [%default]')
parser.add_option_group(group) parser.add_option_group(group)
parser.set_defaults(randomSeed = None, parser.set_defaults(randomSeed = None,
@ -114,10 +111,10 @@ parser.set_defaults(randomSeed = None,
selective = False, selective = False,
distance = 0.2, distance = 0.2,
numCandidates = 10, numCandidates = 10,
format = None,
) )
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
if filenames == []: filenames = [None]
options.fraction = np.array(options.fraction) options.fraction = np.array(options.fraction)
options.grid = np.array(options.grid) options.grid = np.array(options.grid)
@ -127,11 +124,6 @@ if options.randomSeed is None: options.randomSeed = int(os.urandom(4).hex(), 16)
np.random.seed(options.randomSeed) # init random generators np.random.seed(options.randomSeed) # init random generators
random.seed(options.randomSeed) random.seed(options.randomSeed)
# --- loop over output files -------------------------------------------------------------------------
if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
try: try:
table = damask.ASCIItable(outname = name) table = damask.ASCIItable(outname = name)
@ -157,7 +149,7 @@ for name in filenames:
sys.exit() sys.exit()
# --- do work ------------------------------------------------------------------------------------ # --- do work ------------------------------------------------------------------------------------
grainEuler = np.random.rand(3,options.N) # create random Euler triplets grainEuler = np.random.rand(3,options.N) # create random Euler triplets
grainEuler[0,:] *= 360.0 # phi_1 is uniformly distributed grainEuler[0,:] *= 360.0 # phi_1 is uniformly distributed
grainEuler[1,:] = np.degrees(np.arccos(2*grainEuler[1,:]-1)) # cos(Phi) is uniformly distributed grainEuler[1,:] = np.degrees(np.arccos(2*grainEuler[1,:]-1)) # cos(Phi) is uniformly distributed
@ -208,22 +200,21 @@ for name in filenames:
table.info_append([ table.info_append([
scriptID + ' ' + ' '.join(sys.argv[1:]), scriptID + ' ' + ' '.join(sys.argv[1:]),
"grid\ta {}\tb {}\tc {}".format(*options.grid), "grid\ta {}\tb {}\tc {}".format(*options.grid),
"microstructures\t{}".format(options.N),
"randomSeed\t{}".format(options.randomSeed), "randomSeed\t{}".format(options.randomSeed),
]) ])
table.labels_clear() table.labels_clear()
table.labels_append( ['{dim}_{label}'.format(dim = 1+k,label = 'pos') for k in range(3)] + table.labels_append( ['{dim}_{label}'.format(dim = 1+k,label = 'pos') for k in range(3)] +
['{dim}_{label}'.format(dim = 1+k,label = 'euler') for k in range(3)] + ['{dim}_{label}'.format(dim = 1+k,label = 'euler') for k in range(3)] +
['microstructure'] + ['microstructure'] +
(['weight'] if options.weights else [])) (['weight'] if options.weights else []))
table.head_write() table.head_write()
table.output_flush() table.output_flush()
# --- write seeds information ------------------------------------------------------------ # --- write seeds information ------------------------------------------------------------
table.data = seeds table.data = seeds
table.data_writeArray(fmt = options.format) table.data_writeArray()
# --- output finalization -------------------------------------------------------------------------- # --- output finalization --------------------------------------------------------------------------
table.close() # close ASCII table table.close() # close ASCII table