From e7b8ae08d0e5f95680d902aef8069adbeece9fe1 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 26 May 2019 12:11:30 +0200 Subject: [PATCH] polishing --- processing/pre/geom_clean.py | 20 ++++++++++---------- processing/pre/geom_renumber.py | 24 ++++++++++++------------ processing/pre/geom_rotate.py | 9 +++++---- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/processing/pre/geom_clean.py b/processing/pre/geom_clean.py index a4027efa0..4d7b0a0e5 100755 --- a/processing/pre/geom_clean.py +++ b/processing/pre/geom_clean.py @@ -1,17 +1,20 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np -import damask from io import StringIO -from scipy import ndimage from optparse import OptionParser +from scipy import ndimage +import numpy as np + +import damask + + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + def mostFrequent(arr): unique, inverse = np.unique(arr, return_inverse=True) 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 = """ -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) - parser.add_option('-s','--stencil', dest = 'stencil', type = 'int', metavar = 'int', @@ -37,8 +39,6 @@ parser.set_defaults(stencil = 3) (options, filenames) = parser.parse_args() -# --- loop over input files ------------------------------------------------------------------------- - if filenames == []: filenames = [None] for name in filenames: @@ -49,12 +49,12 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - microstructure = geom.microstructure + microstructure = geom.get_microstructure() microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent, size=(options.stencil,)*3).astype(microstructure.dtype) - geom.microstructure = microstructure + geom.set_microstructure(microstructure) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) damask.util.croak(geom) diff --git a/processing/pre/geom_renumber.py b/processing/pre/geom_renumber.py index f4570d08c..e46296555 100755 --- a/processing/pre/geom_renumber.py +++ b/processing/pre/geom_renumber.py @@ -1,28 +1,30 @@ #!/usr/bin/env python3 -# -*- coding: UTF-8 no BOM -*- import os import sys -import numpy as np -from optparse import OptionParser from io import StringIO +from optparse import OptionParser + +import numpy as np + import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- -parser = OptionParser(option_class=damask.extendableOption, usage='%prog [file[s]]', description = """ -renumber sorted microstructure indices to 1,...,N. +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ +Renumber sorted microstructure indices to 1,...,N. """, version=scriptID) (options, filenames) = parser.parse_args() -# --- loop over input files ---------------------------------------------------------------------- if filenames == []: filenames = [None] @@ -34,15 +36,13 @@ for name in filenames: geom = damask.Geom.from_file(virt_file) else: geom = damask.Geom.from_file(name) - microstructure = geom.microstructure - - grainIDs = np.unique(microstructure) - renumbered = np.copy(microstructure) + microstructure = geom.get_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) - geom.microstructure = renumbered + geom.set_microstructure(renumbered) geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:])) damask.util.croak(geom) diff --git a/processing/pre/geom_rotate.py b/processing/pre/geom_rotate.py index c3308b8f8..eae36a842 100755 --- a/processing/pre/geom_rotate.py +++ b/processing/pre/geom_rotate.py @@ -10,15 +10,17 @@ import numpy as np import damask + scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) + #-------------------------------------------------------------------------------------------------- # MAIN #-------------------------------------------------------------------------------------------------- parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """ -Rotates spectral geometry description. +Rotates and embeddeds. """, version=scriptID) @@ -33,7 +35,7 @@ parser.add_option('-e', '--eulers', parser.add_option('-d', '--degrees', dest = 'degrees', 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', dest = 'matrix', type = 'float', nargs = 9, metavar = ' '.join(['float']*9), @@ -47,8 +49,7 @@ parser.add_option('-f', '--fill', type = 'int', metavar = 'int', help = 'background grain index, defaults to max + 1') -parser.set_defaults(degrees = False, - ) +parser.set_defaults(degrees = False) (options, filenames) = parser.parse_args()