2019-02-15 03:26:39 +05:30
|
|
|
#!/usr/bin/env python3
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2014-08-07 00:36:33 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2019-12-23 22:22:35 +05:30
|
|
|
from scipy import ndimage
|
2019-06-14 16:33:30 +05:30
|
|
|
import numpy as np
|
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
import damask
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2013-01-22 04:45:23 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-17 02:50:10 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2013-01-22 15:26:36 +05:30
|
|
|
Blows up each value to a surrounding data block of size 'packing' thus increasing the former resolution
|
2014-08-07 00:36:33 +05:30
|
|
|
to resolution*packing.
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
""", version = scriptID)
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2016-04-16 03:57:23 +05:30
|
|
|
parser.add_option('-c','--coordinates',
|
2016-04-27 02:19:58 +05:30
|
|
|
dest = 'pos', metavar = 'string',
|
2016-04-16 03:57:23 +05:30
|
|
|
help = 'column label of coordinates [%default]')
|
|
|
|
parser.add_option('-p','--packing',
|
|
|
|
dest = 'packing', type = 'int', nargs = 3, metavar = 'int int int',
|
|
|
|
help = 'dimension of packed group [%default]')
|
|
|
|
parser.add_option('-g','--grid',
|
|
|
|
dest = 'resolution', type = 'int', nargs = 3, metavar = 'int int int',
|
2019-02-16 19:23:56 +05:30
|
|
|
help = 'grid in x,y,z (optional)')
|
2016-04-16 03:57:23 +05:30
|
|
|
parser.add_option('-s','--size',
|
|
|
|
dest = 'dimension', type = 'float', nargs = 3, metavar = 'int int int',
|
2019-02-16 19:23:56 +05:30
|
|
|
help = 'size in x,y,z (optional)')
|
2016-04-27 02:19:58 +05:30
|
|
|
parser.set_defaults(pos = 'pos',
|
2016-04-16 03:57:23 +05:30
|
|
|
packing = (2,2,2),
|
|
|
|
grid = (0,0,0),
|
|
|
|
size = (0.0,0.0,0.0),
|
|
|
|
)
|
2013-01-22 04:45:23 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
2019-12-26 19:04:22 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
options.packing = np.array(options.packing)
|
2016-04-16 03:57:23 +05:30
|
|
|
prefix = 'blowUp{}x{}x{}_'.format(*options.packing)
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
for name in filenames:
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2016-04-16 03:57:23 +05:30
|
|
|
|
2019-12-26 19:04:22 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.get(options.pos))
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
packing = np.array(options.packing,'i')
|
|
|
|
outSize = grid*packing
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2019-12-26 19:04:22 +05:30
|
|
|
data = table.data.values.reshape(tuple(grid)+(-1,))
|
|
|
|
blownUp = ndimage.interpolation.zoom(data,tuple(packing)+(1,),order=0,mode='nearest').reshape((outSize.prod(),-1))
|
2016-04-16 03:57:23 +05:30
|
|
|
|
2019-12-26 19:04:22 +05:30
|
|
|
table = damask.Table(blownUp,table.shapes,table.comments)
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2019-12-23 22:22:35 +05:30
|
|
|
coords = damask.grid_filters.cell_coord0(outSize,size,origin)
|
2019-12-26 19:04:22 +05:30
|
|
|
table.set(options.pos,coords.reshape((-1,3)))
|
|
|
|
table.set('elem',np.arange(1,outSize.prod()+1))
|
|
|
|
|
|
|
|
outname = os.path.join(os.path.dirname(name),prefix+os.path.basename(name))
|
|
|
|
table.to_ASCII(sys.stdout if name is None else outname)
|