2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2017-05-29 14:02:22 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-12-21 23:34:29 +05:30
|
|
|
from io import StringIO
|
2017-05-29 14:02:22 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2017-05-29 14:02:22 +05:30
|
|
|
from scipy import ndimage
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2017-05-29 14:02:22 +05:30
|
|
|
import damask
|
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2017-05-29 14:02:22 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog option [ASCIItable(s)]', description = """
|
2017-06-01 13:30:21 +05:30
|
|
|
Add column(s) containing Gaussian filtered values of requested column(s).
|
|
|
|
Operates on periodic and non-periodic ordered three-dimensional data sets.
|
2018-01-30 19:50:47 +05:30
|
|
|
For details see scipy.ndimage documentation.
|
2017-05-29 14:02:22 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
|
|
|
parser.add_option('-p','--pos','--periodiccellcenter',
|
|
|
|
dest = 'pos',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'label of coordinates [%default]')
|
|
|
|
parser.add_option('-s','--scalar',
|
2019-12-21 23:33:36 +05:30
|
|
|
dest = 'labels',
|
2017-05-29 14:02:22 +05:30
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'label(s) of scalar field values')
|
|
|
|
parser.add_option('-o','--order',
|
|
|
|
dest = 'order',
|
|
|
|
type = int,
|
|
|
|
metavar = 'int',
|
2019-02-16 19:23:56 +05:30
|
|
|
help = 'order of the filter [%default]')
|
2017-05-29 14:02:22 +05:30
|
|
|
parser.add_option('--sigma',
|
|
|
|
dest = 'sigma',
|
|
|
|
type = float,
|
|
|
|
metavar = 'float',
|
2019-02-16 19:23:56 +05:30
|
|
|
help = 'standard deviation [%default]')
|
2017-05-29 14:02:22 +05:30
|
|
|
parser.add_option('--periodic',
|
|
|
|
dest = 'periodic',
|
|
|
|
action = 'store_true',
|
2018-01-30 19:50:47 +05:30
|
|
|
help = 'assume periodic grain structure')
|
2017-05-29 14:02:22 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.set_defaults(pos = 'pos',
|
|
|
|
order = 0,
|
|
|
|
sigma = 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
2019-12-21 23:33:36 +05:30
|
|
|
if options.labels is None: parser.error('no data column specified.')
|
|
|
|
|
2017-05-29 14:02:22 +05:30
|
|
|
for name in filenames:
|
2019-12-21 23:33:36 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2017-05-29 14:02:22 +05:30
|
|
|
|
2019-12-21 23:33:36 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
damask.grid_filters.coord0_check(table.get(options.pos))
|
2017-05-29 14:02:22 +05:30
|
|
|
|
2019-12-21 23:33:36 +05:30
|
|
|
for label in options.labels:
|
|
|
|
table.add('Gauss{}({})'.format(options.sigma,label),
|
|
|
|
ndimage.filters.gaussian_filter(table.get(label).reshape((-1)),
|
|
|
|
options.sigma,options.order,
|
|
|
|
mode = 'wrap' if options.periodic else 'nearest'),
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
2017-05-29 14:02:22 +05:30
|
|
|
|
2019-12-21 23:33:36 +05:30
|
|
|
table.to_ASCII(sys.stdout if name is None else name)
|