cleaning
This commit is contained in:
parent
d43dfa569b
commit
130fac21c6
|
@ -135,27 +135,26 @@ class extendableOption(Option):
|
||||||
# Print iterations progress
|
# Print iterations progress
|
||||||
# from https://gist.github.com/aubricus/f91fb55dc6ba5557fbab06119420dd6a
|
# from https://gist.github.com/aubricus/f91fb55dc6ba5557fbab06119420dd6a
|
||||||
def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100):
|
def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100):
|
||||||
"""
|
"""
|
||||||
Call in a loop to create terminal progress bar
|
Call in a loop to create terminal progress bar
|
||||||
|
|
||||||
@params:
|
@params:
|
||||||
iteration - Required : current iteration (Int)
|
iteration - Required : current iteration (Int)
|
||||||
total - Required : total iterations (Int)
|
total - Required : total iterations (Int)
|
||||||
prefix - Optional : prefix string (Str)
|
prefix - Optional : prefix string (Str)
|
||||||
suffix - Optional : suffix string (Str)
|
suffix - Optional : suffix string (Str)
|
||||||
decimals - Optional : positive number of decimals in percent complete (Int)
|
decimals - Optional : positive number of decimals in percent complete (Int)
|
||||||
bar_length - Optional : character length of bar (Int)
|
bar_length - Optional : character length of bar (Int)
|
||||||
"""
|
"""
|
||||||
str_format = "{0:." + str(decimals) + "f}"
|
str_format = "{0:." + str(decimals) + "f}"
|
||||||
percents = str_format.format(100 * (iteration / float(total)))
|
percents = str_format.format(100 * (iteration / float(total)))
|
||||||
filled_length = int(round(bar_length * iteration / float(total)))
|
filled_length = int(round(bar_length * iteration / float(total)))
|
||||||
bar = '█' * filled_length + '-' * (bar_length - filled_length)
|
bar = '█' * filled_length + '-' * (bar_length - filled_length)
|
||||||
|
|
||||||
sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),
|
sys.stderr.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),
|
||||||
|
|
||||||
if iteration == total:
|
if iteration == total: sys.stderr.write('\n\n')
|
||||||
sys.stdout.write('\n')
|
sys.stderr.flush()
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
class backgroundMessage(threading.Thread):
|
class backgroundMessage(threading.Thread):
|
||||||
|
|
|
@ -29,20 +29,25 @@ parser.add_option('-d',
|
||||||
parser.add_option('-s',
|
parser.add_option('-s',
|
||||||
'--symmetry',
|
'--symmetry',
|
||||||
dest = 'symmetry',
|
dest = 'symmetry',
|
||||||
type = 'string', metavar = 'string',
|
metavar = 'string',
|
||||||
help = 'crystal symmetry [%default]')
|
help = 'crystal symmetry [%default]')
|
||||||
parser.add_option('-q',
|
parser.add_option('-q',
|
||||||
'--quaternion',
|
'--quaternion',
|
||||||
dest = 'quaternion',
|
dest = 'quaternion',
|
||||||
type = 'string', metavar = 'string',
|
metavar = 'string',
|
||||||
help = 'label of quaternion')
|
help = 'label of quaternion')
|
||||||
parser.add_option('-p',
|
parser.add_option('-p',
|
||||||
'--pos', '--position',
|
'--pos', '--position',
|
||||||
dest = 'pos',
|
dest = 'pos',
|
||||||
type = 'string', metavar = 'string',
|
metavar = 'string',
|
||||||
help = 'label of coordinates [%default]')
|
help = 'label of coordinates [%default]')
|
||||||
|
parser.add_option('--quiet',
|
||||||
|
dest='verbose',
|
||||||
|
action = 'store_false',
|
||||||
|
help = 'hide status bar (useful when piping to file)')
|
||||||
|
|
||||||
parser.set_defaults(disorientation = 5,
|
parser.set_defaults(disorientation = 5,
|
||||||
|
verbose = True,
|
||||||
quaternion = 'orientation',
|
quaternion = 'orientation',
|
||||||
symmetry = 'cubic',
|
symmetry = 'cubic',
|
||||||
pos = 'pos',
|
pos = 'pos',
|
||||||
|
@ -111,7 +116,7 @@ for name in filenames:
|
||||||
table.data_rewind()
|
table.data_rewind()
|
||||||
while table.data_read(): # read next data line of ASCII table
|
while table.data_read(): # read next data line of ASCII table
|
||||||
|
|
||||||
if Npoints > 100 and p%(Npoints//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
if options.verbose and Npoints > 100 and p%(Npoints//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
||||||
damask.util.print_progress(iteration=p,total=Npoints)
|
damask.util.print_progress(iteration=p,total=Npoints)
|
||||||
|
|
||||||
o = damask.Orientation(quaternion = np.array(list(map(float,table.data[column:column+4]))),
|
o = damask.Orientation(quaternion = np.array(list(map(float,table.data[column:column+4]))),
|
||||||
|
@ -160,6 +165,7 @@ for name in filenames:
|
||||||
|
|
||||||
outputAlive = True
|
outputAlive = True
|
||||||
p = 0
|
p = 0
|
||||||
|
damask.util.print_progress(iteration=1,total=1)
|
||||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||||
table.data_append(1+packingMap[grainID[p]]) # add (condensed) grain ID
|
table.data_append(1+packingMap[grainID[p]]) # add (condensed) grain ID
|
||||||
outputAlive = table.data_write() # output processed line
|
outputAlive = table.data_write() # output processed line
|
||||||
|
|
|
@ -636,7 +636,7 @@ parser.add_option('-p','--type', dest='filetype',
|
||||||
help = 'type of result file [auto]')
|
help = 'type of result file [auto]')
|
||||||
parser.add_option('-q','--quiet', dest='verbose',
|
parser.add_option('-q','--quiet', dest='verbose',
|
||||||
action = 'store_false',
|
action = 'store_false',
|
||||||
help = 'legacy switch, no effect')
|
help = 'hide status bar (useful when piping to file)')
|
||||||
|
|
||||||
group_material = OptionGroup(parser,'Material identifier')
|
group_material = OptionGroup(parser,'Material identifier')
|
||||||
|
|
||||||
|
@ -679,6 +679,7 @@ parser.add_option_group(group_special)
|
||||||
|
|
||||||
parser.set_defaults(info = False,
|
parser.set_defaults(info = False,
|
||||||
nodal = False,
|
nodal = False,
|
||||||
|
verbose = True,
|
||||||
prefix = '',
|
prefix = '',
|
||||||
suffix = '',
|
suffix = '',
|
||||||
dir = 'postProc',
|
dir = 'postProc',
|
||||||
|
@ -705,6 +706,8 @@ if files == []:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
parser.error('no file specified...')
|
parser.error('no file specified...')
|
||||||
|
|
||||||
|
damask.util.report(scriptName,files[0])
|
||||||
|
|
||||||
if not os.path.exists(files[0]):
|
if not os.path.exists(files[0]):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
parser.error('invalid file "%s" specified...'%files[0])
|
parser.error('invalid file "%s" specified...'%files[0])
|
||||||
|
@ -828,7 +831,7 @@ if options.info:
|
||||||
elementsOfNode = {}
|
elementsOfNode = {}
|
||||||
Nelems = stat['NumberOfElements']
|
Nelems = stat['NumberOfElements']
|
||||||
for e in range(Nelems):
|
for e in range(Nelems):
|
||||||
if Nelems > 100 and e%(Nelems//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
if options.verbose and Nelems > 100 and e%(Nelems//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
||||||
damask.util.print_progress(iteration=e,total=Nelems,prefix='1/3: connecting elements')
|
damask.util.print_progress(iteration=e,total=Nelems,prefix='1/3: connecting elements')
|
||||||
for n in map(p.node_sequence,p.element(e).items):
|
for n in map(p.node_sequence,p.element(e).items):
|
||||||
if n not in elementsOfNode:
|
if n not in elementsOfNode:
|
||||||
|
@ -848,11 +851,12 @@ index = {}
|
||||||
groups = []
|
groups = []
|
||||||
groupCount = 0
|
groupCount = 0
|
||||||
memberCount = 0
|
memberCount = 0
|
||||||
print('\n')
|
damask.util.print_progress(iteration=1,total=1,prefix='1/3: connecting elements')
|
||||||
|
|
||||||
if options.nodalScalar:
|
if options.nodalScalar:
|
||||||
Npoints = stat['NumberOfNodes']
|
Npoints = stat['NumberOfNodes']
|
||||||
for n in range(Npoints):
|
for n in range(Npoints):
|
||||||
if Npoints > 100 and e%(Npoints//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
if options.verbose and Npoints > 100 and e%(Npoints//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
||||||
damask.util.print_progress(iteration=n,total=Npoints,prefix='2/3: scanning nodes ')
|
damask.util.print_progress(iteration=n,total=Npoints,prefix='2/3: scanning nodes ')
|
||||||
myNodeID = p.node_id(n)
|
myNodeID = p.node_id(n)
|
||||||
myNodeCoordinates = [p.node(n).x, p.node(n).y, p.node(n).z]
|
myNodeCoordinates = [p.node(n).x, p.node(n).y, p.node(n).z]
|
||||||
|
@ -884,12 +888,12 @@ if options.nodalScalar:
|
||||||
myNodeCoordinates) # incrementally update average location
|
myNodeCoordinates) # incrementally update average location
|
||||||
groups[index[grp]].append([myElemID,myNodeID,myIpID,myGrainID,0]) # append a new list defining each group member
|
groups[index[grp]].append([myElemID,myNodeID,myIpID,myGrainID,0]) # append a new list defining each group member
|
||||||
memberCount += 1
|
memberCount += 1
|
||||||
print('\n')
|
damask.util.print_progress(iteration=1,total=1,prefix='2/3: scanning nodes ')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
Nelems = stat['NumberOfElements']
|
Nelems = stat['NumberOfElements']
|
||||||
for e in range(Nelems):
|
for e in range(Nelems):
|
||||||
if Nelems > 100 and e%(Nelems//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
if options.verbose and Nelems > 100 and e%(Nelems//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
||||||
damask.util.print_progress(iteration=e,total=Nelems,prefix='2/3: scanning elements ')
|
damask.util.print_progress(iteration=e,total=Nelems,prefix='2/3: scanning elements ')
|
||||||
myElemID = p.element_id(e)
|
myElemID = p.element_id(e)
|
||||||
myIpCoordinates = ipCoords(p.element(e).type, list(map(lambda node: [node.x, node.y, node.z],
|
myIpCoordinates = ipCoords(p.element(e).type, list(map(lambda node: [node.x, node.y, node.z],
|
||||||
|
@ -930,7 +934,7 @@ else:
|
||||||
myIpCoordinates[n]) # incrementally update average location
|
myIpCoordinates[n]) # incrementally update average location
|
||||||
groups[index[grp]].append([myElemID,myNodeID,myIpID,myGrainID,n]) # append a new list defining each group member
|
groups[index[grp]].append([myElemID,myNodeID,myIpID,myGrainID,n]) # append a new list defining each group member
|
||||||
memberCount += 1
|
memberCount += 1
|
||||||
print('\n')
|
damask.util.print_progress(iteration=1,total=1,prefix='2/3: scanning elements ')
|
||||||
|
|
||||||
|
|
||||||
# --------------------------- sort groups --------------------------------
|
# --------------------------- sort groups --------------------------------
|
||||||
|
@ -1030,7 +1034,7 @@ for incCount,position in enumerate(locations): # walk through locations
|
||||||
Ngroups = len(groups)
|
Ngroups = len(groups)
|
||||||
for j,group in enumerate(groups):
|
for j,group in enumerate(groups):
|
||||||
f = incCount*Ngroups + j
|
f = incCount*Ngroups + j
|
||||||
if (Ngroups*Nincs) > 100 and f%((Ngroups*Nincs)//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
if options.verbose and (Ngroups*Nincs) > 100 and f%((Ngroups*Nincs)//100) == 0: # report in 1% steps if possible and avoid modulo by zero
|
||||||
damask.util.print_progress(iteration=f,total=Ngroups*Nincs,prefix='3/3: processing points ')
|
damask.util.print_progress(iteration=f,total=Ngroups*Nincs,prefix='3/3: processing points ')
|
||||||
N = 0 # group member counter
|
N = 0 # group member counter
|
||||||
for (e,n,i,g,n_local) in group[1:]: # loop over group members
|
for (e,n,i,g,n_local) in group[1:]: # loop over group members
|
||||||
|
@ -1122,7 +1126,7 @@ for incCount,position in enumerate(locations): # walk through locations
|
||||||
group[0] + \
|
group[0] + \
|
||||||
mappedResult)
|
mappedResult)
|
||||||
)) + '\n')
|
)) + '\n')
|
||||||
print('')
|
damask.util.print_progress(iteration=1,total=1,prefix='3/3: processing points ')
|
||||||
|
|
||||||
if fileOpen:
|
if fileOpen:
|
||||||
file.close()
|
file.close()
|
||||||
|
|
Loading…
Reference in New Issue