using new functionality
This commit is contained in:
parent
feb2340935
commit
657a30c2f5
|
@ -1,23 +1,25 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import numpy as np
|
|
||||||
from optparse import OptionParser
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
# MAIN
|
# MAIN
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
validDirections = ['x','y','z']
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
|
||||||
Mirrors spectral geometry description along given directions.
|
Mirror along given directions.
|
||||||
|
|
||||||
""", version=scriptID)
|
""", version=scriptID)
|
||||||
|
|
||||||
|
@ -25,17 +27,23 @@ parser.add_option('-d','--direction',
|
||||||
dest = 'directions',
|
dest = 'directions',
|
||||||
action = 'extend', metavar = '<string LIST>',
|
action = 'extend', metavar = '<string LIST>',
|
||||||
help = "directions in which to mirror {'x','y','z'}")
|
help = "directions in which to mirror {'x','y','z'}")
|
||||||
|
parser.add_option( '--double',
|
||||||
|
dest = 'double',
|
||||||
|
action = 'store_true',
|
||||||
|
help = 'double the outer layers in mirror direction')
|
||||||
|
|
||||||
(options, filenames) = parser.parse_args()
|
(options, filenames) = parser.parse_args()
|
||||||
|
|
||||||
if options.directions is None:
|
if options.directions is None:
|
||||||
parser.error('no direction given.')
|
parser.error('no direction given.')
|
||||||
|
|
||||||
|
validDirections = ['x','y','z']
|
||||||
if not set(options.directions).issubset(validDirections):
|
if not set(options.directions).issubset(validDirections):
|
||||||
invalidDirections = [str(e) for e in set(options.directions).difference(validDirections)]
|
invalidDirections = [str(e) for e in set(options.directions).difference(validDirections)]
|
||||||
parser.error('invalid directions {}. '.format(*invalidDirections))
|
parser.error('invalid directions {}. '.format(*invalidDirections))
|
||||||
|
|
||||||
|
limits = [-2,0] if not options.double else [None,None]
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
|
@ -47,22 +55,19 @@ for name in filenames:
|
||||||
geom = damask.Geom.from_file(virt_file)
|
geom = damask.Geom.from_file(virt_file)
|
||||||
else:
|
else:
|
||||||
geom = damask.Geom.from_file(name)
|
geom = damask.Geom.from_file(name)
|
||||||
|
damask.util.croak(geom)
|
||||||
microstructure = geom.microstructure
|
microstructure = geom.microstructure
|
||||||
|
|
||||||
if 'z' in options.directions:
|
if 'z' in options.directions:
|
||||||
microstructure = np.concatenate([microstructure,microstructure[:,:,::-1]],2) # better not double edges
|
microstructure = np.concatenate([microstructure,microstructure[:,:,limits[0]:limits[1]:-1]],2)
|
||||||
geom.set_size(geom.get_size()*np.array([1,1,2]))
|
|
||||||
if 'y' in options.directions:
|
if 'y' in options.directions:
|
||||||
microstructure = np.concatenate([microstructure,microstructure[:,::-1,:]],1) # better not double edges
|
microstructure = np.concatenate([microstructure,microstructure[:,limits[0]:limits[1]:-1,:]],1)
|
||||||
geom.set_size(geom.get_size()*np.array([1,2,1]))
|
|
||||||
if 'x' in options.directions:
|
if 'x' in options.directions:
|
||||||
microstructure = np.concatenate([microstructure,microstructure[::-1,:,:]],0) # better not double edges
|
microstructure = np.concatenate([microstructure,microstructure[limits[0]:limits[1]:-1,:,:]],0)
|
||||||
geom.set_size(geom.get_size()*np.array([2,1,1]))
|
|
||||||
|
|
||||||
geom.microstructure = microstructure
|
damask.util.croak(geom.update(microstructure,rescale=True))
|
||||||
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
damask.util.croak(geom)
|
|
||||||
if name is None:
|
if name is None:
|
||||||
sys.stdout.write(str(geom.show()))
|
sys.stdout.write(str(geom.show()))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -20,7 +20,7 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
|
||||||
Rotates and embeddeds.
|
Rotates original microstructure and embeddeds it into buffer material.
|
||||||
|
|
||||||
""", version=scriptID)
|
""", version=scriptID)
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ parser.add_option('-q', '--quaternion',
|
||||||
help = 'rotation given as quaternion')
|
help = 'rotation given as quaternion')
|
||||||
parser.add_option('-f', '--fill',
|
parser.add_option('-f', '--fill',
|
||||||
dest = 'fill',
|
dest = 'fill',
|
||||||
type = 'int', metavar = 'int',
|
type = 'float', metavar = 'int',
|
||||||
help = 'background grain index, defaults to max + 1')
|
help = 'background microstructure index, defaults to max microstructure index + 1')
|
||||||
|
|
||||||
parser.set_defaults(degrees = False)
|
parser.set_defaults(degrees = False)
|
||||||
|
|
||||||
|
@ -78,9 +78,9 @@ for name in filenames:
|
||||||
geom = damask.Geom.from_file(virt_file)
|
geom = damask.Geom.from_file(virt_file)
|
||||||
else:
|
else:
|
||||||
geom = damask.Geom.from_file(name)
|
geom = damask.Geom.from_file(name)
|
||||||
|
damask.util.croak(geom)
|
||||||
microstructure = geom.get_microstructure()
|
microstructure = geom.get_microstructure()
|
||||||
|
|
||||||
|
|
||||||
fill = options.fill if options.fill is not None else np.nanmax(microstructure)+1
|
fill = options.fill if options.fill is not None else np.nanmax(microstructure)+1
|
||||||
|
|
||||||
# These rotations are always applied in the reference coordinate system, i.e. (z,x,z) not (z,x',z'')
|
# These rotations are always applied in the reference coordinate system, i.e. (z,x,z) not (z,x',z'')
|
||||||
|
@ -92,12 +92,10 @@ for name in filenames:
|
||||||
microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0,
|
microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0,
|
||||||
prefilter=False,output=microstructure.dtype,cval=fill) # rotation around z
|
prefilter=False,output=microstructure.dtype,cval=fill) # rotation around z
|
||||||
|
|
||||||
spacing = geom.get_size()/geom.get_grid()
|
|
||||||
geom.set_size(microstructure.shape*spacing)
|
damask.util.croak(geom.update(microstructure,rescale=True))
|
||||||
geom.set_microstructure(microstructure)
|
|
||||||
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
damask.util.croak(geom)
|
|
||||||
if name is None:
|
if name is None:
|
||||||
sys.stdout.write(str(geom.show()))
|
sys.stdout.write(str(geom.show()))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue