added missing string import in marc_addUserOutput (introduced with rev 3718) and removed unwanted imports and introduce use of damask.extendableParser in some other scripts

This commit is contained in:
Martin Diehl 2014-11-18 08:00:45 +00:00
parent f5b4bbe32a
commit b656113b11
17 changed files with 65 additions and 134 deletions

View File

@ -2,37 +2,19 @@
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import string,os,sys import string,os,sys
from optparse import OptionParser, Option from optparse import OptionParser
import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1][:-3] scriptName = scriptID.split()[1][:-3]
#-------------------------------------------------------------------------------------------------
class extendableOption(Option):
#-------------------------------------------------------------------------------------------------
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
# taken from online tutorial http://docs.python.org/library/optparse.html
ACTIONS = Option.ACTIONS + ("extend",)
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
lvalue = value.split(",")
values.ensure_value(dest, []).extend(lvalue)
else:
Option.take_action(self, action, dest, opt, value, values, parser)
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
# MAIN # MAIN
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
Converts ang files (EBSD Data) from hexagonal grid to a pixel grid Converts ang files (EBSD Data) from hexagonal grid to a pixel grid
""" + string.replace(scriptID,'\n','\\n')
) """, version = scriptID)
parser.add_option('-x', dest='columnX', type='int', metavar='int', \ parser.add_option('-x', dest='columnX', type='int', metavar='int', \
help='column containing x coordinates [%default]') help='column containing x coordinates [%default]')

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,math,random import os,sys,string,math
import numpy as np import numpy as np
from optparse import OptionParser from optparse import OptionParser
import damask import damask

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,math import os,sys,string,math
import numpy as np import numpy as np
from optparse import OptionParser from optparse import OptionParser
import damask import damask

View File

@ -1,11 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,math,itertools import os,sys,string,math
import numpy as np import numpy as np
from optparse import OptionParser from optparse import OptionParser
from scipy import ndimage from scipy import ndimage
from multiprocessing import Pool
import damask import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,math import os,sys,string,math
import numpy as np import numpy as np
from optparse import OptionParser from optparse import OptionParser
import damask import damask

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,math import os,sys,string,math
import numpy as np import numpy as np
from optparse import OptionParser from optparse import OptionParser
import damask import damask

View File

@ -1,33 +1,15 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,vtk import os,sys,string,vtk
import numpy as np import numpy as np
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP from optparse import OptionParser
import damask import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1][:-3] scriptName = scriptID.split()[1][:-3]
#--------------------------------------------------------------------------------------------------
class extendedOption(Option):
#--------------------------------------------------------------------------------------------------
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
# taken from online tutorial http://docs.python.org/library/optparse.html
ACTIONS = Option.ACTIONS + ("extend",)
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
lvalue = value.split(",")
values.ensure_value(dest, []).extend(lvalue)
else:
Option.take_action(self, action, dest, opt, value, values, parser)
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
# MAIN # MAIN
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
@ -48,11 +30,10 @@ mappings = {
'microstructures': lambda x: int(x), 'microstructures': lambda x: int(x),
} }
parser = OptionParser(option_class=extendedOption, usage='%prog [geomfile[s]]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile[s]]', description = """
Produce ASCIItable of structure data from geom description Produce ASCIItable of structure data from geom description
""" + string.replace(scriptID,'\n','\\n') """, version = scriptID)
)
(options, filenames) = parser.parse_args() (options, filenames) = parser.parse_args()

View File

@ -1,31 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,math,numpy import os,sys,string,math
import numpy as np
import damask import damask
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP from optparse import OptionParser
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1][:-3] scriptName = scriptID.split()[1][:-3]
#--------------------------------------------------------------------------------------------------
class extendedOption(Option):
#--------------------------------------------------------------------------------------------------
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
# taken from online tutorial http://docs.python.org/library/optparse.html
ACTIONS = Option.ACTIONS + ("extend",)
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
lvalue = value.split(",")
values.ensure_value(dest, []).extend(lvalue)
else:
Option.take_action(self, action, dest, opt, value, values, parser)
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
# MAIN # MAIN
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
@ -46,10 +29,10 @@ mappings = {
'microstructures': lambda x: int(x), 'microstructures': lambda x: int(x),
} }
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
translate microstructure indices (shift or substitute) and/or geometry origin. translate microstructure indices (shift or substitute) and/or geometry origin.
""" + string.replace(scriptID,'\n','\\n')
) """, version=scriptID)
parser.add_option('-o', '--origin', dest='origin', type='float', nargs = 3, \ parser.add_option('-o', '--origin', dest='origin', type='float', nargs = 3, \
help='offset from old to new origin of grid', metavar='float float float') help='offset from old to new origin of grid', metavar='float float float')
@ -96,14 +79,14 @@ for file in files:
#--- interpret header ---------------------------------------------------------------------------- #--- interpret header ----------------------------------------------------------------------------
info = { info = {
'grid': numpy.zeros(3,'i'), 'grid': np.zeros(3,'i'),
'size': numpy.zeros(3,'d'), 'size': np.zeros(3,'d'),
'origin': numpy.zeros(3,'d'), 'origin': np.zeros(3,'d'),
'homogenization': 0, 'homogenization': 0,
'microstructures': 0, 'microstructures': 0,
} }
newInfo = { newInfo = {
'origin': numpy.zeros(3,'d'), 'origin': np.zeros(3,'d'),
'microstructures': 0, 'microstructures': 0,
} }
extra_header = [] extra_header = []
@ -129,15 +112,15 @@ for file in files:
'homogenization: %i\n'%info['homogenization'] + \ 'homogenization: %i\n'%info['homogenization'] + \
'microstructures: %i\n'%info['microstructures']) 'microstructures: %i\n'%info['microstructures'])
if numpy.any(info['grid'] < 1): if np.any(info['grid'] < 1):
file['croak'].write('invalid grid a b c.\n') file['croak'].write('invalid grid a b c.\n')
continue continue
if numpy.any(info['size'] <= 0.0): if np.any(info['size'] <= 0.0):
file['croak'].write('invalid size x y z.\n') file['croak'].write('invalid size x y z.\n')
continue continue
#--- read data ------------------------------------------------------------------------------------ #--- read data ------------------------------------------------------------------------------------
microstructure = numpy.zeros(info['grid'].prod(),'i') microstructure = np.zeros(info['grid'].prod(),'i')
i = 0 i = 0
theTable.data_rewind() theTable.data_rewind()
while theTable.data_read(): while theTable.data_read():
@ -153,7 +136,7 @@ for file in files:
i += s i += s
#--- do work ------------------------------------------------------------------------------------ #--- do work ------------------------------------------------------------------------------------
substituted = numpy.copy(microstructure) substituted = np.copy(microstructure)
for k, v in sub.iteritems(): substituted[microstructure==k] = v # substitute microstructure indices for k, v in sub.iteritems(): substituted[microstructure==k] = v # substitute microstructure indices
substituted += options.microstructure # shift microstructure indices substituted += options.microstructure # shift microstructure indices

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,math import os,sys,string,math
import numpy as np import numpy as np
from optparse import OptionParser from optparse import OptionParser
import damask import damask

View File

@ -1,9 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,math,numpy, damask import os,sys,string,math
import numpy as np
from scipy import ndimage from scipy import ndimage
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP from optparse import OptionParser
import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1][:-3] scriptName = scriptID.split()[1][:-3]
@ -48,11 +50,11 @@ mappings = {
'microstructures': lambda x: int(x), 'microstructures': lambda x: int(x),
} }
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
Offset microstructure index for points which see a microstructure different from themselves within a given (cubic) vicinity, Offset microstructure index for points which see a microstructure different from themselves within a given (cubic) vicinity,
i.e. within the region close to a grain/phase boundary. i.e. within the region close to a grain/phase boundary.
""" + string.replace(scriptID,'\n','\\n')
) """, version = scriptID)
parser.add_option('-v', '--vicinity', dest='vicinity', type='int', metavar='int', \ parser.add_option('-v', '--vicinity', dest='vicinity', type='int', metavar='int', \
help='voxel distance checked for presence of other microstructure [%default]') help='voxel distance checked for presence of other microstructure [%default]')

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string import os,sys,string,re
import damask
import re
from optparse import OptionParser from optparse import OptionParser
import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1][:-3] scriptName = scriptID.split()[1][:-3]

View File

@ -7,8 +7,9 @@ based on the files
<modelname_jobname>.output<Homogenization/Crystallite/Constitutive> <modelname_jobname>.output<Homogenization/Crystallite/Constitutive>
that are written during the first run of the model. that are written during the first run of the model.
''' '''
import sys,os,re import sys,os,re,string
from optparse import OptionParser from optparse import OptionParser
import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1][:-3] scriptName = scriptID.split()[1][:-3]
@ -54,8 +55,7 @@ def ParseOutputFormat(filename,what,me):
format['outputs'].append([output,length]) format['outputs'].append([output,length])
return format return format
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options] Marc.inputfile(s)', description="""
parser = OptionParser(usage='%prog [options] Marc.inputfile(s)', description="""
Transfer the output variables requested in the material.config to Transfer the output variables requested in the material.config to
properly labelled user defined variables within the Marc input file (*.dat). properly labelled user defined variables within the Marc input file (*.dat).
@ -65,7 +65,10 @@ that are written during the first run of the model.
Specify which user block format you want to apply by stating the homogenization, crystallite, and phase identifiers. Specify which user block format you want to apply by stating the homogenization, crystallite, and phase identifiers.
Or have an existing set of user variables copied over from another *.dat file. Or have an existing set of user variables copied over from another *.dat file.
""")
""", version = scriptID)
parser.add_option('-n','--number', dest='number', type='int', \ parser.add_option('-n','--number', dest='number', type='int', \
help='maximum requested User Defined Variable [%default]') help='maximum requested User Defined Variable [%default]')
parser.add_option('--homogenization', dest='homog', \ parser.add_option('--homogenization', dest='homog', \

View File

@ -1,8 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import sys,os,pwd,math,re,string,numpy, damask import sys,os,pwd,math,string
import numpy as np
from optparse import OptionParser from optparse import OptionParser
import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1][:-3] scriptName = scriptID.split()[1][:-3]
@ -54,12 +56,12 @@ def servoLink():
cmds = [] cmds = []
base = ['x','y','z'] base = ['x','y','z']
box = {'min': numpy.zeros(3,dtype='d'), box = {'min': np.zeros(3,dtype='d'),
'max': numpy.zeros(3,dtype='d'), 'max': np.zeros(3,dtype='d'),
'delta': numpy.zeros(3,dtype='d'), 'delta': np.zeros(3,dtype='d'),
} }
Nnodes = py_get_int("nnodes()") Nnodes = py_get_int("nnodes()")
NodeCoords = numpy.zeros((Nnodes,3),dtype='d') NodeCoords = np.zeros((Nnodes,3),dtype='d')
for node in xrange(Nnodes): for node in xrange(Nnodes):
NodeCoords[node,0] = py_get_float("node_x(%i)"%(node+1)) NodeCoords[node,0] = py_get_float("node_x(%i)"%(node+1))
NodeCoords[node,1] = py_get_float("node_y(%i)"%(node+1)) NodeCoords[node,1] = py_get_float("node_y(%i)"%(node+1))
@ -120,7 +122,7 @@ def servoLink():
for dir in xrange(3): # check for each direction for dir in xrange(3): # check for each direction
if node['faceMember'][dir]: # me on this front face if node['faceMember'][dir]: # me on this front face
linkCoord[0][dir] = box['min'][dir] # project me onto rear face along dir linkCoord[0][dir] = box['min'][dir] # project me onto rear face along dir
linkCoord.append(numpy.array(box['min'])) # append base corner linkCoord.append(np.array(box['min'])) # append base corner
linkCoord[-1][dir] = box['max'][dir] # stretch it to corresponding control leg of "dir" linkCoord[-1][dir] = box['max'][dir] # stretch it to corresponding control leg of "dir"
@ -156,10 +158,10 @@ def servoLink():
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
# MAIN # MAIN
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
parser = OptionParser(usage='%prog [options]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage = '%prog [options]', description = """
Set up servo linking to achieve periodic boundary conditions for a regular hexahedral mesh presently opened in MSC.Mentat Set up servo linking to achieve periodic boundary conditions for a regular hexahedral mesh presently opened in MSC.Mentat
""" + string.replace(scriptID,'\n','\\n')
) """, version = scriptID)
parser.add_option("-p", "--port", type="int",\ parser.add_option("-p", "--port", type="int",\
dest="port",\ dest="port",\

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os, sys, math, re, threading, time, string import os, sys, string
from optparse import OptionParser from optparse import OptionParser
import damask import damask

View File

@ -1,8 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import sys,os,math,re,string, damask import sys,os,math,re,string
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP from optparse import OptionParser
import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1][:-3] scriptName = scriptID.split()[1][:-3]
@ -23,26 +24,6 @@ except:
MentatCapability = False MentatCapability = False
# -----------------------------
class extendedOption(Option):
# -----------------------------
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
# taken from online tutorial http://docs.python.org/library/optparse.html
ACTIONS = Option.ACTIONS + ("extend",)
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
lvalue = value.split(",")
values.ensure_value(dest, []).extend(lvalue)
else:
Option.take_action(self, action, dest, opt, value, values, parser)
def outMentat(cmd,locals): def outMentat(cmd,locals):
if cmd[0:3] == '(!)': if cmd[0:3] == '(!)':
exec(cmd[3:]) exec(cmd[3:])
@ -800,12 +781,11 @@ def fftbuild(rcData,height,xframe,yframe,resolution,extrusion): # bui
# ----------------------- MAIN ------------------------------- # ----------------------- MAIN -------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options] datafile[s]', description = """
parser = OptionParser(option_class=extendedOption, usage='%prog [options] datafile[s]', description = """
Produce image, spectral geometry description, and (auto) Mentat procedure from TSL/OIM Produce image, spectral geometry description, and (auto) Mentat procedure from TSL/OIM
reconstructed boundary file reconstructed boundary file
""" + string.replace(scriptID,'\n','\\n')
) """, version = scriptID)
parser.add_option("-o", "--output", action='extend', dest='output', \ parser.add_option("-o", "--output", action='extend', dest='output', \
help="types of output [image, mentat, procedure, spectral]") help="types of output [image, mentat, procedure, spectral]")

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,vtk import os,sys,string,vtk
import numpy as np import numpy as np
import damask import damask
from optparse import OptionParser from optparse import OptionParser

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,math,random import os,sys,string,math,random
import numpy as np import numpy as np
from optparse import OptionParser from optparse import OptionParser
import damask import damask