polishing

This commit is contained in:
Martin Diehl 2019-05-26 12:11:30 +02:00
parent 974f67ffdc
commit e7b8ae08d0
3 changed files with 27 additions and 26 deletions

View File

@ -1,17 +1,20 @@
#!/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
import damask
from io import StringIO from io import StringIO
from scipy import ndimage
from optparse import OptionParser from optparse import OptionParser
from scipy import ndimage
import numpy as np
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])
def mostFrequent(arr): def mostFrequent(arr):
unique, inverse = np.unique(arr, return_inverse=True) unique, inverse = np.unique(arr, return_inverse=True)
return unique[np.argmax(np.bincount(inverse))] return unique[np.argmax(np.bincount(inverse))]
@ -22,11 +25,10 @@ def mostFrequent(arr):
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
Smooth geometry by selecting most frequent microstructure index within given stencil at each location. Smooth microstructure by selecting most frequent index within given stencil at each location.
""", version=scriptID) """, version=scriptID)
parser.add_option('-s','--stencil', parser.add_option('-s','--stencil',
dest = 'stencil', dest = 'stencil',
type = 'int', metavar = 'int', type = 'int', metavar = 'int',
@ -37,8 +39,6 @@ parser.set_defaults(stencil = 3)
(options, filenames) = parser.parse_args() (options, filenames) = parser.parse_args()
# --- loop over input files -------------------------------------------------------------------------
if filenames == []: filenames = [None] if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
@ -49,12 +49,12 @@ 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)
microstructure = geom.microstructure microstructure = geom.get_microstructure()
microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent, microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent,
size=(options.stencil,)*3).astype(microstructure.dtype) size=(options.stencil,)*3).astype(microstructure.dtype)
geom.microstructure = microstructure geom.set_microstructure(microstructure)
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
damask.util.croak(geom) damask.util.croak(geom)

View File

@ -1,28 +1,30 @@
#!/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
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [file[s]]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
renumber sorted microstructure indices to 1,...,N. Renumber sorted microstructure indices to 1,...,N.
""", version=scriptID) """, version=scriptID)
(options, filenames) = parser.parse_args() (options, filenames) = parser.parse_args()
# --- loop over input files ----------------------------------------------------------------------
if filenames == []: filenames = [None] if filenames == []: filenames = [None]
@ -34,15 +36,13 @@ 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)
microstructure = geom.microstructure microstructure = geom.get_microstructure()
grainIDs = np.unique(microstructure)
renumbered = np.copy(microstructure)
for i, oldID in enumerate(grainIDs): renumbered = np.copy(microstructure)
for i, oldID in enumerate(np.unique(microstructure)):
renumbered = np.where(microstructure == oldID, i+1, renumbered) renumbered = np.where(microstructure == oldID, i+1, renumbered)
geom.microstructure = renumbered geom.set_microstructure(renumbered)
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
damask.util.croak(geom) damask.util.croak(geom)

View File

@ -10,15 +10,17 @@ 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
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
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 spectral geometry description. Rotates and embeddeds.
""", version=scriptID) """, version=scriptID)
@ -33,7 +35,7 @@ parser.add_option('-e', '--eulers',
parser.add_option('-d', '--degrees', parser.add_option('-d', '--degrees',
dest = 'degrees', dest = 'degrees',
action = 'store_true', action = 'store_true',
help = 'Euler angles are given in degrees [%default]') help = 'Angles (Euler angles/axis angle) are given in degrees [%default]')
parser.add_option('-m', '--matrix', parser.add_option('-m', '--matrix',
dest = 'matrix', dest = 'matrix',
type = 'float', nargs = 9, metavar = ' '.join(['float']*9), type = 'float', nargs = 9, metavar = ' '.join(['float']*9),
@ -47,8 +49,7 @@ parser.add_option('-f', '--fill',
type = 'int', metavar = 'int', type = 'int', metavar = 'int',
help = 'background grain index, defaults to max + 1') help = 'background grain index, defaults to max + 1')
parser.set_defaults(degrees = False, parser.set_defaults(degrees = False)
)
(options, filenames) = parser.parse_args() (options, filenames) = parser.parse_args()