2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2017-08-23 23:38:11 +05:30
|
|
|
|
2019-05-25 13:44:53 +05:30
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from io import StringIO
|
2019-05-26 15:41:30 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2019-05-25 13:44:53 +05:30
|
|
|
import damask
|
2017-08-23 23:38:11 +05:30
|
|
|
|
2019-05-26 15:41:30 +05:30
|
|
|
|
2017-08-23 23:38:11 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
|
|
|
|
2019-05-26 15:41:30 +05:30
|
|
|
|
2017-08-23 23:38:11 +05:30
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
|
2019-05-27 00:06:41 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile(s)]', description = """
|
2019-05-26 15:41:30 +05:30
|
|
|
Renumber sorted microstructure indices to 1,...,N.
|
2017-08-23 23:38:11 +05:30
|
|
|
|
|
|
|
""", version=scriptID)
|
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
|
|
|
for name in filenames:
|
|
|
|
damask.util.report(scriptName,name)
|
2019-05-25 13:44:53 +05:30
|
|
|
|
2019-05-28 06:44:09 +05:30
|
|
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2017-08-23 23:38:11 +05:30
|
|
|
|
2019-05-29 11:19:43 +05:30
|
|
|
renumbered = np.empty(geom.get_grid(),dtype=geom.microstructure.dtype)
|
|
|
|
for i, oldID in enumerate(np.unique(geom.microstructure)):
|
|
|
|
renumbered = np.where(geom.microstructure == oldID, i+1, renumbered)
|
2017-08-23 23:38:11 +05:30
|
|
|
|
2019-05-27 00:06:41 +05:30
|
|
|
damask.util.croak(geom.update(renumbered))
|
2019-05-28 06:44:09 +05:30
|
|
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
2019-05-25 13:44:53 +05:30
|
|
|
|
|
|
|
if name is None:
|
|
|
|
sys.stdout.write(str(geom.show()))
|
|
|
|
else:
|
|
|
|
geom.to_file(name)
|