simplified
This commit is contained in:
parent
0039ac9551
commit
f251cdb746
|
@ -1,11 +1,15 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
|
||||||
|
|
||||||
import os,sys
|
import os
|
||||||
import numpy as np
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
|
|
||||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
scriptID = ' '.join([scriptName,damask.version])
|
scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
|
@ -19,70 +23,44 @@ Translate geom description into ASCIItable containing position and microstructur
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option('--float',
|
|
||||||
dest = 'float',
|
|
||||||
action = 'store_true',
|
|
||||||
help = 'use float input')
|
|
||||||
|
|
||||||
parser.set_defaults(float = False,
|
|
||||||
)
|
|
||||||
(options, filenames) = parser.parse_args()
|
(options, filenames) = parser.parse_args()
|
||||||
|
|
||||||
datatype = 'f' if options.float else 'i'
|
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try: table = damask.ASCIItable(name = name,
|
|
||||||
outname = os.path.splitext(name)[0]+'.txt' if name else name,
|
|
||||||
buffered = False,
|
|
||||||
labeled = False,
|
|
||||||
)
|
|
||||||
except: continue
|
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# --- interpret header ----------------------------------------------------------------------------
|
if name is None:
|
||||||
|
virt_file = StringIO(''.join(sys.stdin.read()))
|
||||||
|
geom = damask.Geom.from_file(virt_file)
|
||||||
|
else:
|
||||||
|
geom = damask.Geom.from_file(name)
|
||||||
|
damask.util.croak(geom)
|
||||||
|
microstructure = geom.get_microstructure().flatten('F')
|
||||||
|
grid = geom.get_grid()
|
||||||
|
size = geom.get_size()
|
||||||
|
|
||||||
table.head_read()
|
for i,line in enumerate(geom.get_comments()):
|
||||||
info,extra_header = table.head_getGeom()
|
if line.lower().strip().startswith('origin'):
|
||||||
damask.util.report_geom(info)
|
origin= np.array([float(line.split()[j]) for j in [2,4,6]]) # assume correct order (x,y,z)
|
||||||
|
|
||||||
errors = []
|
|
||||||
if np.any(info['grid'] < 1): errors.append('invalid grid a b c.')
|
|
||||||
if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.')
|
|
||||||
if errors != []:
|
|
||||||
damask.util.croak(errors)
|
|
||||||
table.close(dismiss = True)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# --- read data ------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
microstructure = table.microstructure_read(info['grid'],datatype)
|
|
||||||
|
|
||||||
# ------------------------------------------ assemble header ---------------------------------------
|
|
||||||
|
|
||||||
table.info_clear()
|
|
||||||
table.info_append(extra_header + [scriptID + '\t' + ' '.join(sys.argv[1:])])
|
|
||||||
table.labels_clear()
|
|
||||||
table.labels_append(['{}_{}'.format(1+i,'pos') for i in range(3)]+['microstructure'])
|
|
||||||
table.head_write()
|
|
||||||
table.output_flush()
|
|
||||||
|
|
||||||
#--- generate grid --------------------------------------------------------------------------------
|
#--- generate grid --------------------------------------------------------------------------------
|
||||||
|
|
||||||
x = (0.5 + np.arange(info['grid'][0],dtype=float))/info['grid'][0]*info['size'][0]+info['origin'][0]
|
x = (0.5 + np.arange(grid[0],dtype=float))/grid[0]*size[0]+origin[0]
|
||||||
y = (0.5 + np.arange(info['grid'][1],dtype=float))/info['grid'][1]*info['size'][1]+info['origin'][1]
|
y = (0.5 + np.arange(grid[1],dtype=float))/grid[1]*size[1]+origin[1]
|
||||||
z = (0.5 + np.arange(info['grid'][2],dtype=float))/info['grid'][2]*info['size'][2]+info['origin'][2]
|
z = (0.5 + np.arange(grid[2],dtype=float))/grid[2]*size[2]+origin[2]
|
||||||
|
|
||||||
xx = np.tile( x, info['grid'][1]* info['grid'][2])
|
xx = np.tile( x, grid[1]* grid[2])
|
||||||
yy = np.tile(np.repeat(y,info['grid'][0] ),info['grid'][2])
|
yy = np.tile(np.repeat(y,grid[0] ),grid[2])
|
||||||
zz = np.repeat(z,info['grid'][0]*info['grid'][1])
|
zz = np.repeat(z,grid[0]*grid[1])
|
||||||
|
|
||||||
table.data = np.squeeze(np.dstack((xx,yy,zz,microstructure)),axis=0)
|
|
||||||
table.data_writeArray()
|
|
||||||
|
|
||||||
# ------------------------------------------ finalize output ---------------------------------------
|
# ------------------------------------------ finalize output ---------------------------------------
|
||||||
|
table = damask.ASCIItable(outname = os.path.splitext(name)[0]+'.txt' if name else name)
|
||||||
|
table.info_append([scriptID + '\t' + ' '.join(sys.argv[1:])] + geom.get_comments())
|
||||||
|
table.labels_append(['{}_{}'.format(1+i,'pos') for i in range(3)]+['microstructure'])
|
||||||
|
table.head_write()
|
||||||
|
table.output_flush()
|
||||||
|
table.data = np.squeeze(np.dstack((xx,yy,zz,microstructure)),axis=0)
|
||||||
|
table.data_writeArray()
|
||||||
table.close()
|
table.close()
|
||||||
|
|
Loading…
Reference in New Issue