DAMASK_EICMD/processing/pre/geom_toTable.py

47 lines
1.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2019-05-27 01:37:50 +05:30
import os
import sys
from io import StringIO
2019-12-09 03:05:39 +05:30
from optparse import OptionParser
2019-05-27 01:37:50 +05:30
import damask
2019-05-27 01:37:50 +05:30
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 = """
2016-05-17 14:35:50 +05:30
Translate geom description into ASCIItable containing position and microstructure.
""", version = scriptID)
(options, filenames) = parser.parse_args()
if filenames == []: filenames = [None]
for name in filenames:
2019-12-09 03:05:39 +05:30
damask.util.report(scriptName,name)
2019-12-09 03:05:39 +05:30
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
damask.util.croak(geom)
2019-05-30 17:37:49 +05:30
coord0 = damask.grid_filters.cell_coord0(geom.grid,geom.size,geom.origin).reshape((-1,3))
2019-12-09 03:05:39 +05:30
comments = geom.comments \
+ [scriptID + ' ' + ' '.join(sys.argv[1:]),
"grid\ta {}\tb {}\tc {}".format(*geom.grid),
"size\tx {}\ty {}\tz {}".format(*geom.size),
"origin\tx {}\ty {}\tz {}".format(*geom.origin),
"homogenization\t{}".format(geom.homogenization)]
2019-12-09 03:05:39 +05:30
table = damask.Table(coord0,{'pos':(3,)},comments)
2020-01-02 22:16:14 +05:30
table.add('microstructure',geom.microstructure.reshape((-1,1),order='F'))
2019-05-28 01:30:26 +05:30
2019-12-09 03:05:39 +05:30
table.to_ASCII(sys.stdout if name is None else \
os.path.splitext(name)[0]+'.txt')