From 6604d0f8e86b491ad9da05c957b9542b7549c7c7 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 18 Dec 2014 19:26:52 +0000 Subject: [PATCH] polishing --- processing/post/3Dvisualize.py | 2 +- processing/post/addCalculation.py | 2 +- processing/post/addCauchy.py | 2 +- processing/post/addCompatibilityMismatch.py | 2 +- processing/post/addCurl.py | 2 +- processing/post/addDeformedConfiguration.py | 2 +- processing/post/addDeterminant.py | 2 +- processing/post/addDeviator.py | 2 +- processing/post/addDivergence.py | 2 +- processing/post/addEhkl.py | 2 +- processing/post/addEuclideanDistance.py | 2 +- processing/post/addMapped.py | 2 +- processing/post/addMises.py | 2 +- processing/post/addNorm.py | 2 +- processing/post/addOrientations.py | 2 +- processing/post/addPK2.py | 2 +- processing/post/addSchmidfactors.py | 2 +- processing/post/addSpectralDecomposition.py | 2 +- processing/post/addStrainTensors.py | 2 +- processing/post/averageDown.py | 2 +- processing/post/binXY.py | 2 +- processing/post/blowUp.py | 2 +- processing/post/deleteColumn.py | 2 +- processing/post/deleteInfo.py | 2 +- processing/post/filterTable.py | 2 +- processing/post/marc_deformedGeometry.py | 7 +- processing/post/marc_extractData.py | 40 +++------- processing/post/mentat_colorMap.py | 9 ++- processing/post/perceptualUniformColorMap.py | 30 ++----- processing/post/permuteData.py | 2 +- processing/post/postResults.py | 8 +- processing/post/rotateData.py | 2 +- processing/post/scaleData.py | 2 +- processing/post/shiftData.py | 2 +- processing/post/showTable.py | 2 +- processing/post/sortTable.py | 2 +- processing/post/stddevDown.py | 83 +++++++------------- processing/post/tagLabel.py | 31 ++------ processing/post/vtk2ang.py | 41 +++++----- processing/post/vtk_addData.py | 7 +- processing/post/vtk_addPointcloudData.py | 35 +++------ processing/post/vtk_addVoxelcloudData.py | 35 +++------ processing/post/vtk_addVoxelgridData.py | 33 +++----- processing/post/vtk_pointcloud.py | 35 +++------ processing/post/vtk_scalars2vectors.py | 15 ++-- processing/post/vtk_voxelcloud.py | 56 +++++-------- 46 files changed, 184 insertions(+), 343 deletions(-) diff --git a/processing/post/3Dvisualize.py b/processing/post/3Dvisualize.py index 9475827fb..c625b4fc8 100755 --- a/processing/post/3Dvisualize.py +++ b/processing/post/3Dvisualize.py @@ -8,7 +8,7 @@ from vtk.util import numpy_support import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # ----------------------------- class backgroundMessage(threading.Thread): diff --git a/processing/post/addCalculation.py b/processing/post/addCalculation.py index f01a6c473..6d629a33a 100755 --- a/processing/post/addCalculation.py +++ b/processing/post/addCalculation.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] def unravel(item): if hasattr(item,'__contains__'): return ' '.join(map(unravel,item)) diff --git a/processing/post/addCauchy.py b/processing/post/addCauchy.py index f3e574ce9..7d3d52111 100755 --- a/processing/post/addCauchy.py +++ b/processing/post/addCauchy.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/addCompatibilityMismatch.py b/processing/post/addCompatibilityMismatch.py index 050845929..6a6d41107 100755 --- a/processing/post/addCompatibilityMismatch.py +++ b/processing/post/addCompatibilityMismatch.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/addCurl.py b/processing/post/addCurl.py index 3b502fad2..8b8ca4f7f 100755 --- a/processing/post/addCurl.py +++ b/processing/post/addCurl.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/addDeformedConfiguration.py b/processing/post/addDeformedConfiguration.py index 696779de8..e66ab8ba5 100755 --- a/processing/post/addDeformedConfiguration.py +++ b/processing/post/addDeformedConfiguration.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/addDeterminant.py b/processing/post/addDeterminant.py index c889f442a..85283f8a8 100755 --- a/processing/post/addDeterminant.py +++ b/processing/post/addDeterminant.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] def determinant(m): return +m[0]*m[4]*m[8] \ diff --git a/processing/post/addDeviator.py b/processing/post/addDeviator.py index 337319741..e8ef39ae0 100755 --- a/processing/post/addDeviator.py +++ b/processing/post/addDeviator.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] oneThird = 1.0/3.0 diff --git a/processing/post/addDivergence.py b/processing/post/addDivergence.py index 25a22310c..9b547bf9b 100755 --- a/processing/post/addDivergence.py +++ b/processing/post/addDivergence.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/addEhkl.py b/processing/post/addEhkl.py index fdc9ed4f2..341204e9f 100755 --- a/processing/post/addEhkl.py +++ b/processing/post/addEhkl.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] def normalize(vec): return vec/np.sqrt(np.inner(vec,vec)) diff --git a/processing/post/addEuclideanDistance.py b/processing/post/addEuclideanDistance.py index 47b7aabd5..8854b05d7 100755 --- a/processing/post/addEuclideanDistance.py +++ b/processing/post/addEuclideanDistance.py @@ -8,7 +8,7 @@ from scipy import ndimage import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] def periodic_3Dpad(array, rimdim=(1,1,1)): diff --git a/processing/post/addMapped.py b/processing/post/addMapped.py index 58ef2aa23..bc21201c3 100755 --- a/processing/post/addMapped.py +++ b/processing/post/addMapped.py @@ -6,7 +6,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/addMises.py b/processing/post/addMises.py index f552010af..eab88a320 100755 --- a/processing/post/addMises.py +++ b/processing/post/addMises.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] def Mises(what,tensor): diff --git a/processing/post/addNorm.py b/processing/post/addNorm.py index e55d944ce..2b42f2336 100755 --- a/processing/post/addNorm.py +++ b/processing/post/addNorm.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # definition of element-wise p-norms for matrices def normAbs(object): # p = 1 diff --git a/processing/post/addOrientations.py b/processing/post/addOrientations.py index 9c6c88894..d077cf055 100755 --- a/processing/post/addOrientations.py +++ b/processing/post/addOrientations.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/addPK2.py b/processing/post/addPK2.py index 32b199dc4..144fe357a 100755 --- a/processing/post/addPK2.py +++ b/processing/post/addPK2.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/addSchmidfactors.py b/processing/post/addSchmidfactors.py index 82f241c71..bf54e82a0 100755 --- a/processing/post/addSchmidfactors.py +++ b/processing/post/addSchmidfactors.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] slipnormal_temp = [ [0,0,0,1], diff --git a/processing/post/addSpectralDecomposition.py b/processing/post/addSpectralDecomposition.py index caf1c5827..e3c0f3c5b 100755 --- a/processing/post/addSpectralDecomposition.py +++ b/processing/post/addSpectralDecomposition.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/addStrainTensors.py b/processing/post/addStrainTensors.py index 6223d4671..0dcb44be7 100755 --- a/processing/post/addStrainTensors.py +++ b/processing/post/addStrainTensors.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] def operator(stretch,strain,eigenvalues): return { diff --git a/processing/post/averageDown.py b/processing/post/averageDown.py index 22ed7e8d3..2ea80791d 100755 --- a/processing/post/averageDown.py +++ b/processing/post/averageDown.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/binXY.py b/processing/post/binXY.py index 3da90e04e..73c73d37b 100755 --- a/processing/post/binXY.py +++ b/processing/post/binXY.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/blowUp.py b/processing/post/blowUp.py index 93c89acf8..aedd1e756 100755 --- a/processing/post/blowUp.py +++ b/processing/post/blowUp.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/deleteColumn.py b/processing/post/deleteColumn.py index a968cbdaf..06a0040ce 100755 --- a/processing/post/deleteColumn.py +++ b/processing/post/deleteColumn.py @@ -6,7 +6,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/deleteInfo.py b/processing/post/deleteInfo.py index 7628cd539..08c170f64 100755 --- a/processing/post/deleteInfo.py +++ b/processing/post/deleteInfo.py @@ -6,7 +6,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/filterTable.py b/processing/post/filterTable.py index d884faaa0..91552954d 100755 --- a/processing/post/filterTable.py +++ b/processing/post/filterTable.py @@ -6,7 +6,7 @@ from optparse import OptionParser import damask scriptID = '$Id$' -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/marc_deformedGeometry.py b/processing/post/marc_deformedGeometry.py index d74bbee41..4030230c9 100755 --- a/processing/post/marc_deformedGeometry.py +++ b/processing/post/marc_deformedGeometry.py @@ -5,7 +5,8 @@ import os, sys, math, string, numpy, shutil import damask from optparse import OptionParser - +scriptID = '$Id$' +scriptName = os.path.splitext(scriptID.split()[1])[0] # ----------------------------- # MAIN FUNCTION STARTS HERE @@ -15,8 +16,8 @@ from optparse import OptionParser parser = OptionParser(usage='%prog [options] resultfile', description = """ Create vtk files for the (deformed) geometry that belongs to a .t16 (MSC.Marc) results file. -""" + string.replace('$Id$','\n','\\n') -) + +""", version = scriptID) parser.add_option('-d','--dir', dest='dir', \ help='name of subdirectory to hold output [%default]') diff --git a/processing/post/marc_extractData.py b/processing/post/marc_extractData.py index 5be8530ac..2dee3dbab 100755 --- a/processing/post/marc_extractData.py +++ b/processing/post/marc_extractData.py @@ -2,30 +2,11 @@ # -*- coding: UTF-8 no BOM -*- import os, sys, math, string, re, time +from optparse import OptionParser, OptionGroup import damask -from optparse import OptionParser, OptionGroup, Option - - -# ----------------------------- -class MyOption(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) - - +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] # ----------------------------- def ParseOutputFormat(filename,homogID,crystID,phaseID): @@ -278,17 +259,14 @@ def writeHeader(myfile,stat,geomtype): return True +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- -# ----------------------------- -# MAIN FUNCTION STARTS HERE -# ----------------------------- - -# --- input parsing - -parser = OptionParser(option_class=MyOption, usage='%prog [options] resultfile', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ Extract data from a .t16 (MSC.Marc) results file. -""" + string.replace('$Id$','\n','\\n') -) + +""", version = scriptID) parser.add_option('-i','--info', action='store_true', dest='info', \ help='list contents of resultfile [%default]') diff --git a/processing/post/mentat_colorMap.py b/processing/post/mentat_colorMap.py index 011d48947..a0e96d94c 100755 --- a/processing/post/mentat_colorMap.py +++ b/processing/post/mentat_colorMap.py @@ -1,10 +1,12 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import sys, string +import os, sys, string import damask from optparse import OptionParser +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] # ----------------------------- def outMentat(cmd,locals): @@ -57,13 +59,12 @@ def colorMap(colors,baseIdx=32): # MAIN FUNCTION STARTS HERE # ----------------------------- -parser = OptionParser(usage="%prog [options] predefinedScheme | (lower_h,s,l upper_h,s,l)", description = """ +parser = OptionParser(option_class=damask.extendableOption, usage="%prog [options] predefinedScheme | (lower_h,s,l upper_h,s,l)", description = """ Changes the color map in MSC.Mentat. Interpolates colors between "lower_hsl" and "upper_hsl". -""" + string.replace('$Id$','\n','\\n') -) +""", version = scriptID) parser.add_option("-i","--inverse", action = "store_true", dest = "inverse", \ diff --git a/processing/post/perceptualUniformColorMap.py b/processing/post/perceptualUniformColorMap.py index b09acaead..4d5a35dd1 100755 --- a/processing/post/perceptualUniformColorMap.py +++ b/processing/post/perceptualUniformColorMap.py @@ -2,38 +2,20 @@ # -*- coding: UTF-8 no BOM -*- import math, string, sys, os -from damask import Color,Colormap -from optparse import OptionParser, Option - -# ----------------------------- -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) - +import damask +from optparse import OptionParser +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ Produces perceptually linear diverging and sequential colormaps in formats suitable for visualization software or simply as a list of interpolated colors. -""" + string.replace('$Id$','\n','\\n') -) +""", version = scriptID) parser.add_option('-l','--left', dest='left', type='float', nargs=3, \ help='left color %default') diff --git a/processing/post/permuteData.py b/processing/post/permuteData.py index 33033569c..2fa009317 100755 --- a/processing/post/permuteData.py +++ b/processing/post/permuteData.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/postResults.py b/processing/post/postResults.py index 36c96c5d0..cd12fe2eb 100755 --- a/processing/post/postResults.py +++ b/processing/post/postResults.py @@ -5,6 +5,9 @@ import pdb, os, sys, gc, math, re, threading, time, struct, string import damask from optparse import OptionParser, OptionGroup +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] + fileExtensions = { \ 'marc': ['.t16',], @@ -623,7 +626,7 @@ def SummarizePostfile(stat,where=sys.stdout,format='marc'): # --- input parsing -parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options] resultfile', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ Extract data from a .t16 (MSC.Marc) or .spectralOut results file. List of output variables is given by options '--ns','--es','--et','--ho','--cr','--co'. @@ -640,8 +643,7 @@ User mappings need to be formulated in an incremental fashion for each new data and may use the current (incremental) result, b(ase), as well as the number, n(umber), of already processed data points for evaluation. -""", version = string.replace('$Id$','\n','\\n') -) +""", version = scriptID) parser.add_option('-i','--info', action='store_true', dest='info', \ help='list contents of resultfile [%default]') diff --git a/processing/post/rotateData.py b/processing/post/rotateData.py index 15c900840..5313af7c9 100755 --- a/processing/post/rotateData.py +++ b/processing/post/rotateData.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/scaleData.py b/processing/post/scaleData.py index fbc10352c..f2d7c513e 100755 --- a/processing/post/scaleData.py +++ b/processing/post/scaleData.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = '$Id$' -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/shiftData.py b/processing/post/shiftData.py index 66b2e1f4e..9e8bf5b37 100755 --- a/processing/post/shiftData.py +++ b/processing/post/shiftData.py @@ -8,7 +8,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/showTable.py b/processing/post/showTable.py index 8a9d77b3c..0319cd167 100755 --- a/processing/post/showTable.py +++ b/processing/post/showTable.py @@ -6,7 +6,7 @@ from optparse import OptionParser import damask scriptID = '$Id$' -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/sortTable.py b/processing/post/sortTable.py index 9f0952e2f..379411698 100755 --- a/processing/post/sortTable.py +++ b/processing/post/sortTable.py @@ -7,7 +7,7 @@ from optparse import OptionParser import damask scriptID = string.replace('$Id$','\n','\\n') -scriptName = scriptID.split()[1][:-3] +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN diff --git a/processing/post/stddevDown.py b/processing/post/stddevDown.py index 39fc45843..1f8431c9c 100755 --- a/processing/post/stddevDown.py +++ b/processing/post/stddevDown.py @@ -1,52 +1,23 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,re,sys,math,string,numpy,damask,time -from optparse import OptionParser, Option - -# ----------------------------- -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) - - - -def location(idx,res): - - return numpy.array([ idx % res[0], \ - (idx // res[0]) % res[1], \ - (idx // res[0] // res[1]) % res[2] ]) - -def index(location,res): - - return ( location[0] % res[0] + \ - (location[1] % res[1]) * res[0] + \ - (location[2] % res[2]) * res[0] * res[1] ) +import os,re,sys,math,string,time +import numpy as np +import damask +from optparse import OptionParser +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=extendableOption, usage='%prog [options] [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options] datafile[s]', description = """ Calculates the standard deviation of data in blocks of size 'packing' thus reducing the former resolution -to resolution/packing. (Requires numpy.) +to resolution/packing. (Requires np.) -""" + string.replace('$Id$','\n','\\n') -) +""", version = scriptID) parser.add_option('-c','--coordinates', dest='coords', type='string',\ help='column heading for coordinates [%default]') @@ -71,11 +42,11 @@ if len(options.packing) < 3: if len(options.shift) < 3: parser.error('shift needs three parameters...') -options.packing = numpy.array(options.packing) -options.shift = numpy.array(options.shift) +options.packing = np.array(options.packing) +options.shift = np.array(options.shift) prefix = 'stddevDown%ix%ix%i_'%(options.packing[0],options.packing[1],options.packing[2]) -if numpy.any(options.shift != 0): +if np.any(options.shift != 0): prefix += 'shift%+i%+i%+i_'%(options.shift[0],options.shift[1],options.shift[2]) # ------------------------------------------ setup file handles --------------------------------------- @@ -114,27 +85,27 @@ for file in files: while table.data_read(): # read next data line of ASCII table for j in xrange(3): grid[j][str(table.data[locationCol+j])] = True # remember coordinate along x,y,z - resolution = numpy.array([len(grid[0]),\ + resolution = np.array([len(grid[0]),\ len(grid[1]),\ len(grid[2]),],'i') # resolution is number of distinct coordinates found - dimension = resolution/numpy.maximum(numpy.ones(3,'d'),resolution-1.0)* \ - numpy.array([max(map(float,grid[0].keys()))-min(map(float,grid[0].keys())),\ + dimension = resolution/np.maximum(np.ones(3,'d'),resolution-1.0)* \ + np.array([max(map(float,grid[0].keys()))-min(map(float,grid[0].keys())),\ max(map(float,grid[1].keys()))-min(map(float,grid[1].keys())),\ max(map(float,grid[2].keys()))-min(map(float,grid[2].keys())),\ ],'d') # dimension from bounding box, corrected for cell-centeredness else: - resolution = numpy.array(options.resolution,'i') - dimension = numpy.array(options.dimension,'d') + resolution = np.array(options.resolution,'i') + dimension = np.array(options.dimension,'d') if resolution[2] == 1: options.packing[2] = 1 options.shift[2] = 0 dimension[2] = min(dimension[:2]/resolution[:2]) # z spacing equal to smaller of x or y spacing - packing = numpy.array(options.packing,'i') - shift = numpy.array(options.shift,'i') - downSized = numpy.maximum(numpy.ones(3,'i'),resolution//packing) - outSize = numpy.ceil(numpy.array(resolution,'d')/numpy.array(packing,'d')) + packing = np.array(options.packing,'i') + shift = np.array(options.shift,'i') + downSized = np.maximum(np.ones(3,'i'),resolution//packing) + outSize = np.ceil(np.array(resolution,'d')/np.array(packing,'d')) print '\t%s @ %s --> %s'%(dimension,resolution,downSized) @@ -144,9 +115,9 @@ for file in files: # ------------------------------------------ process data --------------------------------------- - dataavg = numpy.zeros(outSize.tolist()+[len(table.labels)]) - datavar = numpy.zeros(outSize.tolist()+[len(table.labels)]) - p = numpy.zeros(3,'i') + dataavg = np.zeros(outSize.tolist()+[len(table.labels)]) + datavar = np.zeros(outSize.tolist()+[len(table.labels)]) + p = np.zeros(3,'i') table.data_rewind() for p[2] in xrange(resolution[2]): @@ -154,7 +125,7 @@ for file in files: for p[0] in xrange(resolution[0]): d = ((p-shift)%resolution)//packing table.data_read() - dataavg[d[0],d[1],d[2],:] += numpy.array(table.data_asFloat(),'d') # convert to numpy array + dataavg[d[0],d[1],d[2],:] += np.array(table.data_asFloat(),'d') # convert to np array dataavg /= packing.prod() @@ -164,9 +135,9 @@ for file in files: for p[0] in xrange(resolution[0]): d = ((p-shift)%resolution)//packing table.data_read() - datavar[d[0],d[1],d[2],:] += (numpy.array(table.data_asFloat(),'d') - dataavg[d[0],d[1],d[2],:])**2 + datavar[d[0],d[1],d[2],:] += (np.array(table.data_asFloat(),'d') - dataavg[d[0],d[1],d[2],:])**2 - datavar = numpy.sqrt(datavar/packing.prod()) + datavar = np.sqrt(datavar/packing.prod()) posOffset = (shift+[0.5,0.5,0.5])*dimension/resolution elementSize = dimension/resolution*packing diff --git a/processing/post/tagLabel.py b/processing/post/tagLabel.py index 508863974..0c7cbb591 100755 --- a/processing/post/tagLabel.py +++ b/processing/post/tagLabel.py @@ -1,38 +1,21 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,re,sys,math,string,damask -from optparse import OptionParser, Option - -# ----------------------------- -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) - +import os,re,sys,math,string +import damask +from optparse import OptionParser +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options] dfile[s]', description = """ Tag scalar, vectorial, and/or tensorial data header labels by specified suffix. -""" + string.replace('$Id$','\n','\\n') -) +""", version = scriptID) parser.add_option('-l','--tag', dest='tag', \ help='tag to use as suffix for labels') diff --git a/processing/post/vtk2ang.py b/processing/post/vtk2ang.py index c991d1baa..6d9b6b57a 100755 --- a/processing/post/vtk2ang.py +++ b/processing/post/vtk2ang.py @@ -1,11 +1,13 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- - -import os,numpy,string,math,sys -from optparse import OptionParser, Option +import os,string,math,sys +import numpy as np +from optparse import OptionParser from vtk import * +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] # ----------------------------- def getHeader(filename,sizeFastIndex,sizeSlowIndex,stepsize): @@ -79,8 +81,7 @@ def getDataLine(angles,x,y,validData=True): parser = OptionParser(usage='%prog options [file[s]]', description = """ Builds a ang files from a vtk file. -""" + string.replace('$Id$','\n','\\n') -) +""", version = scriptID) parser.add_option('--disp','--displacement',dest='dispLabel', \ @@ -137,7 +138,7 @@ for filename in filenames: # check for othogonality of normal and up vector -if numpy.dot(numpy.array(options.normal),numpy.array(options.up)) > 1e-3: +if np.dot(np.array(options.normal),np.array(options.up)) > 1e-3: parser.error('normal vector and up vector have to be orthogonal') @@ -221,12 +222,12 @@ for filename in filenames: # "R" rotates coordinates from the mesh system into the TSL system if options.verbose: sys.stdout.write("\nGETTING COORDINATE SYSTEM FOR ANG FILES\n") - z = numpy.array(options.normal,dtype='float') - z = z / numpy.linalg.norm(z) - x = numpy.array(options.up,dtype='float') - x = x / numpy.linalg.norm(x) - y = numpy.cross(z,x) - R = numpy.array([x,y,z]) + z = np.array(options.normal,dtype='float') + z = z / np.linalg.norm(z) + x = np.array(options.up,dtype='float') + x = x / np.linalg.norm(x) + y = np.cross(z,x) + R = np.array([x,y,z]) if options.verbose: sys.stdout.write(" axis (x: up direction, z: slice normal)\n") sys.stdout.write(" x (% .8f % .8f % .8f)\n"%tuple(x)) @@ -237,12 +238,12 @@ for filename in filenames: # Get bounding box in rotated system (x,y,z) if options.verbose: sys.stdout.write("\nGETTING BOUNDING BOX IN ROTATED SYSTEM\n") - rotatedbox = [[numpy.inf,-numpy.inf] for i in range(3)] # bounding box in rotated TSL system + rotatedbox = [[np.inf,-np.inf] for i in range(3)] # bounding box in rotated TSL system for n in range(8): # loop over eight vertices of mesh bounding box - vert = numpy.array([box[0+(n/1)%2], + vert = np.array([box[0+(n/1)%2], box[2+(n/2)%2], box[4+(n/4)%2]]) # vertex in mesh system - rotatedvert = numpy.dot(R,vert) # vertex in rotated system + rotatedvert = np.dot(R,vert) # vertex in rotated system for i in range(3): rotatedbox[i][0] = min(rotatedbox[i][0],rotatedvert[i]) rotatedbox[i][1] = max(rotatedbox[i][1],rotatedvert[i]) @@ -292,10 +293,10 @@ for filename in filenames: for k in xrange(Npoints[2]): for j in xrange(Npoints[0]): for i in xrange(Npoints[1]): # y is fastest index - rotatedpoint = numpy.array([rotatedbox[0][0] + (float(j) + 0.5) * options.resolution, + rotatedpoint = np.array([rotatedbox[0][0] + (float(j) + 0.5) * options.resolution, rotatedbox[1][0] + (float(i) + 0.5) * options.resolution, rotatedbox[2][0] + (float(k) + 0.5) * options.distance ]) # point in rotated system - point = numpy.dot(R.T,rotatedpoint) # point in mesh system + point = np.dot(R.T,rotatedpoint) # point in mesh system points.InsertNextPoint(list(point)) if options.verbose: sys.stdout.write("\rGENERATING POINTS FOR POINT GRID %d%%" %(100*(Npoints[1]*(k*Npoints[0]+j)+i+1)/totalNpoints)) @@ -363,7 +364,7 @@ for filename in filenames: if options.verbose: sys.stdout.write("\nWRITING OUT ANG FILES\n") sys.stdout.write(" scaling all length with %f\n"%options.scale) - x0,y0,z0 = numpy.dot(R,pointgrid.GetPoint(0)) # first point on slice defines origin + x0,y0,z0 = np.dot(R,pointgrid.GetPoint(0)) # first point on slice defines origin for sliceN in range(Npoints[2]): # Open file and write header @@ -396,7 +397,7 @@ for filename in filenames: # write data to ang file - x,y,z = numpy.dot(R,pointgrid.GetPoint(i)) # point in rotated TSL system + x,y,z = np.dot(R,pointgrid.GetPoint(i)) # point in rotated TSL system x -= x0 # first point on slice defines origin y -= y0 # first point on slice defines origin x *= options.scale @@ -423,7 +424,7 @@ for filename in filenames: P = [rotatedbox[0][(n/1)%2], rotatedbox[1][(n/2)%2], rotatedbox[2][(n/4)%2]] - boxpoints.InsertNextPoint(list(numpy.dot(R.T,numpy.array(P)))) + boxpoints.InsertNextPoint(list(np.dot(R.T,np.array(P)))) box = vtkHexahedron() for n,i in enumerate([0,1,3,2,4,5,7,6]): box.GetPointIds().SetId(n,i) diff --git a/processing/post/vtk_addData.py b/processing/post/vtk_addData.py index 9c30944ef..dfd016777 100755 --- a/processing/post/vtk_addData.py +++ b/processing/post/vtk_addData.py @@ -5,7 +5,8 @@ import os, sys, string, glob, re import damask from optparse import OptionParser - +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] # ----------------------------- def findTag(filename,tag): @@ -27,8 +28,8 @@ def findTag(filename,tag): parser = OptionParser(usage='%prog [options] directory', description = """ Add data from an ASCII table to a VTK geometry file. -""" + string.replace('$Id$','\n','\\n') -) + +""", version = scriptID) parser.add_option('-s','--sub', action='store_true', dest='subdir', \ help='include files in subdirectories [%default]') diff --git a/processing/post/vtk_addPointcloudData.py b/processing/post/vtk_addPointcloudData.py index f986dbbaf..a7686df5b 100755 --- a/processing/post/vtk_addPointcloudData.py +++ b/processing/post/vtk_addPointcloudData.py @@ -1,36 +1,21 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,sys,string,re,numpy,vtk +import os,sys,string,re,vtk import damask -from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP +from optparse import OptionParser -scriptID = '$Id$' -scriptName = scriptID.split()[1] +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] -#-------------------------------------------------------------------------------------------------- -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",) +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- - 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) - - -parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ Add scalar and RGB tuples from ASCIItable to existing VTK point cloud (.vtp). -""" + string.replace(scriptID,'\n','\\n') -) + +""", version = scriptID) parser.add_option('-v', '--vtk', dest='vtk', \ help = 'VTK file name') diff --git a/processing/post/vtk_addVoxelcloudData.py b/processing/post/vtk_addVoxelcloudData.py index 053353227..7bad544ab 100755 --- a/processing/post/vtk_addVoxelcloudData.py +++ b/processing/post/vtk_addVoxelcloudData.py @@ -1,36 +1,21 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,sys,string,re,numpy,vtk +import os,sys,string,re,vtk import damask -from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP +from optparse import OptionParser -scriptID = '$Id$' -scriptName = scriptID.split()[1] +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] -#-------------------------------------------------------------------------------------------------- -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",) +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- - 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) - - -parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ Add scalar and RGB tuples from ASCIItable to existing VTK voxel cloud (.vtu). -""" + string.replace(scriptID,'\n','\\n') -) + +""", version = scriptID) parser.add_option('-v', '--vtk', dest='vtk', \ help = 'VTK file name') diff --git a/processing/post/vtk_addVoxelgridData.py b/processing/post/vtk_addVoxelgridData.py index 3693e5c4f..989a9bcc0 100755 --- a/processing/post/vtk_addVoxelgridData.py +++ b/processing/post/vtk_addVoxelgridData.py @@ -1,37 +1,22 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,sys,string,re,numpy,vtk +import os,sys,string,re,vtk import damask from collections import defaultdict -from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP +from optparse import OptionParser -scriptID = '$Id: vtk_addVoxelgridData.py 3064 2014-04-03 01:00:00Z p.eisenlohr $' +scriptID = string.replace('$Id: addCalculation.py 3465 2014-09-12 14:14:55Z MPIE\m.diehl $','\n','\\n') scriptName = os.path.splitext(scriptID.split()[1])[0] -#-------------------------------------------------------------------------------------------------- -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",) +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- - 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) - - -parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ Add scalar and RGB tuples from ASCIItable to existing VTK voxel grid (.vtr). -""" + string.replace(scriptID,'\n','\\n') -) + +""", version = scriptID) parser.add_option('-v', '--vtk', dest='vtk', type='string', help = 'VTK file name') diff --git a/processing/post/vtk_pointcloud.py b/processing/post/vtk_pointcloud.py index b1fb854d8..ef1a9f75c 100755 --- a/processing/post/vtk_pointcloud.py +++ b/processing/post/vtk_pointcloud.py @@ -1,36 +1,21 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,sys,string,re,numpy,vtk +import os,sys,string,re,vtk import damask -from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP +from optparse import OptionParser -scriptID = '$Id$' -scriptName = scriptID.split()[1] +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] -#-------------------------------------------------------------------------------------------------- -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",) +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- - 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) - - -parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ Add grain index based on similitude of crystal lattice orientation. -""" + string.replace(scriptID,'\n','\\n') -) + +""", version = scriptID) parser.add_option('-p', '--positions', dest='pos', \ help = 'coordinate label') diff --git a/processing/post/vtk_scalars2vectors.py b/processing/post/vtk_scalars2vectors.py index 266b5066b..e1a015bb9 100755 --- a/processing/post/vtk_scalars2vectors.py +++ b/processing/post/vtk_scalars2vectors.py @@ -2,19 +2,20 @@ # -*- coding: UTF-8 no BOM -*- import os, sys, string, re, shutil +import damask from optparse import OptionParser from vtk import * +scriptID = string.replace('$Id$','\n','\\n') +scriptName = os.path.splitext(scriptID.split()[1])[0] -# ----------------------------- -# MAIN FUNCTION STARTS HERE -# ----------------------------- +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- -# --- input parsing +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ -parser = OptionParser(usage='%prog [options] vtkfile', description = """ -""" + string.replace('$Id$','\n','\\n') -) +""", version = scriptID) parser.add_option('-v','--vector', nargs=3, dest='vector', \ help='suffices indicating vector components [%default]') diff --git a/processing/post/vtk_voxelcloud.py b/processing/post/vtk_voxelcloud.py index bea6cced1..2e116fc2b 100755 --- a/processing/post/vtk_voxelcloud.py +++ b/processing/post/vtk_voxelcloud.py @@ -1,35 +1,14 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,sys,string,re,numpy,vtk +import os,sys,string,re,vtk +import numpy as np +from optparse import OptionParser import damask -from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP scriptID = '$Id$' scriptName = os.path.splitext(scriptID.split()[1])[0] -#-------------------------------------------------------------------------------------------------- -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 -#-------------------------------------------------------------------------------------------------- synonyms = { 'grid': ['resolution'], 'size': ['dimension'], @@ -46,11 +25,14 @@ mappings = { 'microstructures': lambda x: int(x), } +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- -parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ Create hexahedral voxels around points in an ASCIItable. -""" + string.replace(scriptID,'\n','\\n') -) + +""", version = scriptID) parser.add_option('-p', '--positions', dest='pos', type='string', help = 'coordinate label') @@ -91,12 +73,11 @@ for file in files: table = damask.ASCIItable(file['input'],file['croak'],False) # make unbuffered ASCII_table table.head_read() # read ASCII header info - #--- interpret header ---------------------------------------------------------------------------- info = { - 'grid': numpy.zeros(3,'i'), - 'size': numpy.zeros(3,'d'), - 'origin': numpy.zeros(3,'d'), + 'grid': np.zeros(3,'i'), + 'size': np.zeros(3,'d'), + 'origin': np.zeros(3,'d'), 'homogenization': 0, 'microstructures': 0, } @@ -121,18 +102,17 @@ for file in files: 'homogenization: %i\n'%info['homogenization'] + \ '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') continue - if numpy.any(info['size'] <= 0.0): + if np.any(info['size'] <= 0.0): file['croak'].write('invalid size x y z.\n') continue else: - info['size'] = numpy.ones(3) + info['size'] = np.ones(3) info['grid'] = info['size'] / options.size info['origin'] = options.origin - # --------------- figure out columns to process active = {} @@ -156,7 +136,7 @@ for file in files: # ------------------------------------------ process data --------------------------------------- - hexPoints = numpy.array([[-1,-1,-1], + hexPoints = np.array([[-1,-1,-1], [ 1,-1,-1], [ 1, 1,-1], [-1, 1,-1], @@ -175,9 +155,9 @@ for file in files: table.data[:,0:3] *= info['size'] table.data[:,0:3] += info['origin'] -# minD = numpy.array(options.size,dtype=float) +# minD = np.array(options.size,dtype=float) # for i in xrange(3): -# coords = numpy.unique(table.data[:,i]) +# coords = np.unique(table.data[:,i]) # minD[i] = coords[-1]-coords[0] # for j in xrange(len(coords)-1): # d = coords[j+1]-coords[j]