47 lines
1.3 KiB
Python
Executable File
47 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import sys
|
|
from io import StringIO
|
|
from optparse import OptionParser
|
|
|
|
import numpy as np
|
|
|
|
import damask
|
|
|
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
scriptID = ' '.join([scriptName,damask.version])
|
|
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
# MAIN
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile(s)]', description = """
|
|
Renumber sorted microstructure indices to 1,...,N.
|
|
|
|
""", version=scriptID)
|
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
for name in filenames:
|
|
damask.util.report(scriptName,name)
|
|
|
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
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)
|
|
|
|
damask.util.croak(geom.update(renumbered))
|
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
|
|
|
if name is None:
|
|
sys.stdout.write(str(geom.show()))
|
|
else:
|
|
geom.to_file(name)
|