fixed bug in asciitable when updating labels for readArray, fixed checking for euler angels presence in tessellation, improved help
This commit is contained in:
parent
7ea350b90e
commit
fa1368204d
|
@ -258,12 +258,14 @@ class ASCIItable():
|
||||||
read whole data of all (given) labels as numpy array
|
read whole data of all (given) labels as numpy array
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if labels == []: indices = range(self.__IO__['validReadSize']) # use all columns
|
if labels != []: # read only some labels
|
||||||
else:
|
indices = self.labels_index(labels) # get indices to read
|
||||||
indices = self.labels_index(labels) # use specified columns
|
tempDict = dict(zip(indices, labels)) # column <> label connections
|
||||||
dictionary = dict(zip(indices, labels))
|
self.labels = [tempDict[label] for label in sorted(tempDict)] # sort labels to reflect order from np.readtxt
|
||||||
self.labels_index = range(len(dictionary))
|
self.__IO__['validReadSize'] = len(labels)
|
||||||
self.labels = [dictionary[label] for label in sorted(dictionary)]
|
else:
|
||||||
|
indices = range(self.__IO__['validReadSize']) # use all columns
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.data_rewind() # try to wind back to start of data
|
self.data_rewind() # try to wind back to start of data
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -40,19 +40,11 @@ parser.set_defaults(data = True)
|
||||||
#--- setup file handles --------------------------------------------------------------------------
|
#--- setup file handles --------------------------------------------------------------------------
|
||||||
files = []
|
files = []
|
||||||
if filenames == []:
|
if filenames == []:
|
||||||
files.append({'name':'STDIN',
|
files.append({'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout, 'croak':sys.stderr, })
|
||||||
'input':sys.stdin,
|
|
||||||
'output':sys.stdout,
|
|
||||||
'croak':sys.stderr,
|
|
||||||
})
|
|
||||||
else:
|
else:
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
if os.path.exists(name):
|
if os.path.exists(name):
|
||||||
files.append({'name':name,
|
files.append({'name':name, 'input':open(name), 'output':sys.stdout, 'croak':sys.stdout, })
|
||||||
'input':open(name),
|
|
||||||
'output':sys.stdout,
|
|
||||||
'croak':sys.stdout,
|
|
||||||
})
|
|
||||||
|
|
||||||
#--- loop over input files ------------------------------------------------------------------------
|
#--- loop over input files ------------------------------------------------------------------------
|
||||||
for file in files:
|
for file in files:
|
||||||
|
|
|
@ -31,43 +31,43 @@ def meshgrid2(*arrs):
|
||||||
return tuple(ans)
|
return tuple(ans)
|
||||||
|
|
||||||
def laguerreTessellation(undeformed, coords):
|
def laguerreTessellation(undeformed, coords):
|
||||||
bestdist = np.ones(len(undeformed)) * np.finfo('d').max
|
bestdist = np.ones(len(undeformed)) * np.finfo('d').max
|
||||||
bestseed = np.zeros(len(undeformed))
|
bestseed = np.zeros(len(undeformed))
|
||||||
|
|
||||||
for i,seed in enumerate(coords):
|
for i,seed in enumerate(coords):
|
||||||
for copy in np.array([[1, 0, 0, ],
|
for copy in np.array([[1, 0, 0, ],
|
||||||
[0, 1, 0, ],
|
[0, 1, 0, ],
|
||||||
[0, 0, 1, ],
|
[0, 0, 1, ],
|
||||||
[-1, 0, 0, ],
|
[-1, 0, 0, ],
|
||||||
[0, -1, 0, ],
|
[0, -1, 0, ],
|
||||||
[0, 0, -1, ],
|
[0, 0, -1, ],
|
||||||
[1, 1, 0, ],
|
[1, 1, 0, ],
|
||||||
[1, 0, 1, ],
|
[1, 0, 1, ],
|
||||||
[0, 1, 1, ],
|
[0, 1, 1, ],
|
||||||
[-1, 1, 0, ],
|
[-1, 1, 0, ],
|
||||||
[-1, 0, 1, ],
|
[-1, 0, 1, ],
|
||||||
[0, -1, 1, ],
|
[0, -1, 1, ],
|
||||||
[-1, -1, 0, ],
|
[-1, -1, 0, ],
|
||||||
[-1, 0, -1, ],
|
[-1, 0, -1, ],
|
||||||
[0, -1, -1, ],
|
[0, -1, -1, ],
|
||||||
[1, -1, 0, ],
|
[1, -1, 0, ],
|
||||||
[1, 0, -1, ],
|
[1, 0, -1, ],
|
||||||
[0, 1, -1, ],
|
[0, 1, -1, ],
|
||||||
[1, 1, 1, ],
|
[1, 1, 1, ],
|
||||||
[-1, 1, 1, ],
|
[-1, 1, 1, ],
|
||||||
[1, -1, 1, ],
|
[1, -1, 1, ],
|
||||||
[1, 1, -1, ],
|
[1, 1, -1, ],
|
||||||
[-1, -1, -1, ],
|
[-1, -1, -1, ],
|
||||||
[1, -1, -1, ],
|
[1, -1, -1, ],
|
||||||
[-1, 1, -1, ],
|
[-1, 1, -1, ],
|
||||||
[-1, -1, 1, ]]).astype(float):
|
[-1, -1, 1, ]]).astype(float):
|
||||||
|
|
||||||
diff = undeformed - np.repeat((seed+info['size']*copy).reshape(3,1),len(undeformed),axis=1).T
|
diff = undeformed - np.repeat((seed+info['size']*copy).reshape(3,1),len(undeformed),axis=1).T
|
||||||
dist = np.sum(diff*diff,axis=1) - weights[i]
|
dist = np.sum(diff*diff,axis=1) - weights[i]
|
||||||
|
|
||||||
bestseed = np.where(dist < bestdist, np.ones(len(undeformed))*(i+1),bestseed)
|
bestseed = np.where(dist < bestdist, np.ones(len(undeformed))*(i+1),bestseed)
|
||||||
bestdist = np.where(dist < bestdist, dist,bestdist)
|
bestdist = np.where(dist < bestdist, dist,bestdist)
|
||||||
return bestseed
|
return bestseed
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
@ -109,8 +109,6 @@ parser.add_option('--secondphase', type='float', dest='secondphase', metavar= 'f
|
||||||
help='volume fraction of randomly distribute second phase [%default]')
|
help='volume fraction of randomly distribute second phase [%default]')
|
||||||
parser.add_option('--laguerre', dest='laguerre', action='store_true',
|
parser.add_option('--laguerre', dest='laguerre', action='store_true',
|
||||||
help='for weighted voronoi (Laguerre) tessellation [%default]')
|
help='for weighted voronoi (Laguerre) tessellation [%default]')
|
||||||
|
|
||||||
|
|
||||||
parser.set_defaults(grid = (0,0,0))
|
parser.set_defaults(grid = (0,0,0))
|
||||||
parser.set_defaults(size = (0.0,0.0,0.0))
|
parser.set_defaults(size = (0.0,0.0,0.0))
|
||||||
parser.set_defaults(origin = (0.0,0.0,0.0))
|
parser.set_defaults(origin = (0.0,0.0,0.0))
|
||||||
|
@ -159,7 +157,7 @@ for file in files:
|
||||||
file['croak'].write('no coordinate data (1_coords/x) found ...')
|
file['croak'].write('no coordinate data (1_coords/x) found ...')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
hasEulers = np.any(np.asarray(table.labels_index(['phi1','Phi','phi2'])) == -1)
|
hasEulers = np.all(np.asarray(table.labels_index(['phi1','Phi','phi2'])) != -1)
|
||||||
if hasEulers:
|
if hasEulers:
|
||||||
labels += ['phi1','Phi','phi2']
|
labels += ['phi1','Phi','phi2']
|
||||||
|
|
||||||
|
@ -174,8 +172,8 @@ for file in files:
|
||||||
table.data_readArray(labels)
|
table.data_readArray(labels)
|
||||||
coords = table.data[:,table.labels_index(coords)]
|
coords = table.data[:,table.labels_index(coords)]
|
||||||
eulers = table.data[:,table.labels_index(['phi1','Phi','phi2'])] if hasEulers else np.zeros(3*len(coords))
|
eulers = table.data[:,table.labels_index(['phi1','Phi','phi2'])] if hasEulers else np.zeros(3*len(coords))
|
||||||
grain = table.data[:,table.labels_index('microstructure')] if hasGrains else 1+np.arange(len(coords))
|
grain = table.data[:,table.labels.index('microstructure')] if hasGrains else 1+np.arange(len(coords))
|
||||||
weights = table.data[:,table.labels_index('weight')] if hasWeight else np.zeros(len(coords))
|
weights = table.data[:,table.labels.index('weight')] if hasWeight else np.zeros(len(coords))
|
||||||
grainIDs = np.unique(grain).astype('i')
|
grainIDs = np.unique(grain).astype('i')
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,6 +306,4 @@ for file in files:
|
||||||
if file['name'] != 'STDIN':
|
if file['name'] != 'STDIN':
|
||||||
table.input_close()
|
table.input_close()
|
||||||
table.output_close()
|
table.output_close()
|
||||||
os.rename(file['name']+'_tmp',os.path.splitext(file['name'])[0] + \
|
os.rename(file['name']+'_tmp',os.path.splitext(file['name'])[0] + '_material.config' if options.config else '.geom')
|
||||||
{True: '_material.config',
|
|
||||||
False:'.geom'}[options.config])
|
|
||||||
|
|
|
@ -36,22 +36,18 @@ Examples:
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option('-p', '--positions', dest = 'pos', type = 'string',
|
parser.add_option('-p', '--positions', dest = 'pos', metavar='string',
|
||||||
help = 'coordinate label')
|
help = 'coordinate label')
|
||||||
parser.add_option('--boundingbox', dest = 'box', type = 'float', nargs = 6,
|
parser.add_option('--boundingbox', dest = 'box', type = 'float', nargs = 6,
|
||||||
help = 'min (x,y,z) and max (x,y,z) to specify bounding box [auto]')
|
help = 'min (x,y,z) and max (x,y,z) to specify bounding box [auto]')
|
||||||
parser.add_option('-i', '--index', dest = 'index', type = 'string',
|
parser.add_option('-i', '--index', dest = 'index', type = 'string',
|
||||||
help = 'microstructure index label')
|
help = 'microstructure index label')
|
||||||
parser.add_option('-w','--white', dest = 'whitelist', action = 'extend', type = 'string', \
|
parser.add_option('-w','--white', dest = 'whitelist', action = 'extend',\
|
||||||
help = 'white list of microstructure indices', metavar = '<LIST>')
|
help = 'white list of microstructure indices', metavar = '<LIST>')
|
||||||
parser.add_option('-b','--black', dest = 'blacklist', action = 'extend', type = 'string', \
|
parser.add_option('-b','--black', dest = 'blacklist', action = 'extend',\
|
||||||
help = 'black list of microstructure indices', metavar = '<LIST>')
|
help = 'black list of microstructure indices', metavar = '<LIST>')
|
||||||
|
|
||||||
parser.set_defaults(pos = 'pos')
|
parser.set_defaults(pos = 'pos')
|
||||||
parser.set_defaults(index = 'microstructure')
|
parser.set_defaults(index = 'microstructure')
|
||||||
parser.set_defaults(box = ())
|
|
||||||
parser.set_defaults(whitelist = [])
|
|
||||||
parser.set_defaults(blacklist = [])
|
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
|
||||||
|
@ -62,10 +58,10 @@ datainfo = { # lis
|
||||||
'label':[]},
|
'label':[]},
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.pos != None: datainfo['vector']['label'] += [options.pos]
|
datainfo['vector']['label'] += [options.pos]
|
||||||
if options.index != None: datainfo['scalar']['label'] += [options.index]
|
datainfo['scalar']['label'] += [options.index]
|
||||||
options.whitelist = map(int,options.whitelist)
|
if options.whitelist != None: options.whitelist = map(int,options.whitelist)
|
||||||
options.blacklist = map(int,options.blacklist)
|
if options.blacklist != None: options.blacklist = map(int,options.blacklist)
|
||||||
|
|
||||||
#--- setup file handles --------------------------------------------------------------------------
|
#--- setup file handles --------------------------------------------------------------------------
|
||||||
files = []
|
files = []
|
||||||
|
@ -126,10 +122,10 @@ for file in files:
|
||||||
#--- filtering of grain voxels ------------------------------------------------------------------------------------
|
#--- filtering of grain voxels ------------------------------------------------------------------------------------
|
||||||
mask = np.logical_and(\
|
mask = np.logical_and(\
|
||||||
np.ones_like(table.data[:,3],bool) \
|
np.ones_like(table.data[:,3],bool) \
|
||||||
if options.whitelist == [] \
|
if options.whitelist == None \
|
||||||
else np.in1d(table.data[:,3].ravel(), options.whitelist).reshape(table.data[:,3].shape),
|
else np.in1d(table.data[:,3].ravel(), options.whitelist).reshape(table.data[:,3].shape),
|
||||||
np.ones_like(table.data[:,3],bool) \
|
np.ones_like(table.data[:,3],bool) \
|
||||||
if options.blacklist == [] \
|
if options.blacklist == None \
|
||||||
else np.invert(np.in1d(table.data[:,3].ravel(), options.blacklist).reshape(table.data[:,3].shape))
|
else np.invert(np.in1d(table.data[:,3].ravel(), options.blacklist).reshape(table.data[:,3].shape))
|
||||||
)
|
)
|
||||||
table.data = table.data[mask]
|
table.data = table.data[mask]
|
||||||
|
|
Loading…
Reference in New Issue