From 7ed2c19d0ff9d605407c5ed4a5a8358d31180d4d Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 16 Jan 2012 09:32:36 +0000 Subject: [PATCH] switched importing from "msc_tools" to "damask" patchFrom... now skips blank lines, has more commenting, treats (artificial) bi-crystal (somewhat) gracefully. --- processing/post/mentat_colorMap.py | 4 +- processing/post/postResults.py | 6 +- processing/pre/mentat_pbcOnBoxMesh.py | 4 +- processing/pre/mentat_spectralBox.py | 4 +- .../pre/patchFromReconstructedBoundaries.py | 152 +++++++++--------- 5 files changed, 89 insertions(+), 81 deletions(-) diff --git a/processing/post/mentat_colorMap.py b/processing/post/mentat_colorMap.py index 033f2aa7f..807114151 100755 --- a/processing/post/mentat_colorMap.py +++ b/processing/post/mentat_colorMap.py @@ -1,10 +1,10 @@ #!/usr/bin/env python -import sys, os, msc_tools, string +import sys, os, string, damask from colorsys import * from optparse import OptionParser -sys.path.append(msc_tools.MSC_TOOLS().libraryPath(sys.argv[0],'../../')) +sys.path.append(damask.solver.Marc().libraryPath('../../')) try: from py_mentat import * diff --git a/processing/post/postResults.py b/processing/post/postResults.py index 0e33478bd..45093da30 100755 --- a/processing/post/postResults.py +++ b/processing/post/postResults.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import pdb, os, sys, gc, math, re, threading, time, struct, string -import msc_tools +import damask from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP @@ -755,7 +755,7 @@ if options.filetype not in ['marc','spectral']: parser.error('file type "%s" not supported...'%options.filetype) if options.filetype == 'marc': - sys.path.append(msc_tools.MSC_TOOLS().libraryPath(sys.argv[0],'../../')) + sys.path.append(damask.solver.Marc().libraryPath('../../')) try: from py_post import * @@ -838,7 +838,7 @@ for opt in ['nodalScalar','elemScalar','elemTensor','homogenizationResult','crys if options.info: if options.filetype == 'marc': - print '\n\nMentat release %s'%msc_tools.MSC_TOOLS().version(sys.argv[0],'../../') + print '\n\nMentat release %s'%damask.solver.Marc().version('../../') if options.filetype == 'spectral': print '\n\n',p diff --git a/processing/pre/mentat_pbcOnBoxMesh.py b/processing/pre/mentat_pbcOnBoxMesh.py index fb329a5bc..1ae4881f7 100755 --- a/processing/pre/mentat_pbcOnBoxMesh.py +++ b/processing/pre/mentat_pbcOnBoxMesh.py @@ -1,9 +1,9 @@ #!/usr/bin/env python -import sys,os,pwd,math,re,string,msc_tools +import sys,os,pwd,math,re,string, damask from optparse import OptionParser -sys.path.append(msc_tools.MSC_TOOLS().libraryPath(sys.argv[0],'../../')) +sys.path.append(damask.solver.Marc().libraryPath('../../')) try: from py_mentat import * diff --git a/processing/pre/mentat_spectralBox.py b/processing/pre/mentat_spectralBox.py index 821420800..b69d39304 100755 --- a/processing/pre/mentat_spectralBox.py +++ b/processing/pre/mentat_spectralBox.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os, sys, math, re, threading, time, string, msc_tools +import os, sys, math, re, threading, time, string, damask from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP @@ -251,7 +251,7 @@ parser.set_defaults(homogenization = 1) (options, args) = parser.parse_args() -sys.path.append(msc_tools.MSC_TOOLS().libraryPath(sys.argv[0],'../../')) +sys.path.append(damask.solver.Marc().libraryPath('../../')) try: from py_mentat import * diff --git a/processing/pre/patchFromReconstructedBoundaries.py b/processing/pre/patchFromReconstructedBoundaries.py index a0131539d..1ba48dabb 100755 --- a/processing/pre/patchFromReconstructedBoundaries.py +++ b/processing/pre/patchFromReconstructedBoundaries.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import sys,os,math,re,string, msc_tools +import sys,os,math,re,string, damask from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP @@ -10,7 +10,7 @@ try: # check for Python Image Lib except: ImageCapability = False -sys.path.append(msc_tools.MSC_TOOLS().libraryPath(sys.argv[0],'../../')) +sys.path.append(damask.solver.Marc().libraryPath('../../')) try: # check for MSC.Mentat Python interface from py_mentat import * @@ -79,15 +79,16 @@ def rcbOrientationParser(content): grains = [] myOrientation = [0.0,0.0,0.0] for line in content: - if line[0] != '#': # skip comments - for grain in range(2): - myID = int(line.split()[12+grain]) # get grain id - myOrientation = map(float,line.split())[3*grain:3+3*grain] # get orientation - if len(grains) < myID: - for i in range(myID-len(grains)): # extend list to necessary length - grains.append([0.0,0.0,0.0]) - grains[myID-1] = myOrientation # store Euler angles - + m = re.match(r'\s*(#|$)',line) + if m: continue # skip comments and blank lines + for grain in range(2): + myID = int(line.split()[12+grain]) # get grain id + myOrientation = map(float,line.split())[3*grain:3+3*grain] # get orientation + if len(grains) < myID: + for i in range(myID-len(grains)): # extend list to necessary length + grains.append([0.0,0.0,0.0]) + grains[myID-1] = myOrientation # store Euler angles + return grains def rcbParser(content,M,size,tolerance): # parser for TSL-OIM reconstructed boundary files @@ -99,14 +100,15 @@ def rcbParser(content,M,size,tolerance): # parser for TSL-O x = [0.,0.] y = [0.,0.] for line in content: - if line[0] != '#': # skip comments - (x[0],y[0],x[1],y[1]) = map(float,line.split())[8:12] # get start and end coordinates of each segment. - (x[0],y[0]) = (M[0]*x[0]+M[1]*y[0],M[2]*x[0]+M[3]*y[0]) # apply transformation to coordinates - (x[1],y[1]) = (M[0]*x[1]+M[1]*y[1],M[2]*x[1]+M[3]*y[1]) # to get rcb --> Euler system - boxX[0] = min(boxX[0],x[0],x[1]) - boxX[1] = max(boxX[1],x[0],x[1]) - boxY[0] = min(boxY[0],y[0],y[1]) - boxY[1] = max(boxY[1],y[0],y[1]) + m = re.match(r'\s*(#|$)',line) + if m: continue # skip comments and blank lines + (x[0],y[0],x[1],y[1]) = map(float,line.split())[8:12] # get start and end coordinates of each segment. + (x[0],y[0]) = (M[0]*x[0]+M[1]*y[0],M[2]*x[0]+M[3]*y[0]) # apply transformation to coordinates + (x[1],y[1]) = (M[0]*x[1]+M[1]*y[1],M[2]*x[1]+M[3]*y[1]) # to get rcb --> Euler system + boxX[0] = min(boxX[0],x[0],x[1]) + boxX[1] = max(boxX[1],x[0],x[1]) + boxY[0] = min(boxY[0],y[0],y[1]) + boxY[1] = max(boxY[1],y[0],y[1]) dX = boxX[1]-boxX[0] dY = boxY[1]-boxY[0] @@ -122,50 +124,51 @@ def rcbParser(content,M,size,tolerance): # parser for TSL-O grainNeighbors = [] for line in content: - if line[0] != '#': # skip comments - (x[0],y[0],x[1],y[1]) = map(float,line.split())[8:12] # get start and end coordinates of each segment - (x[0],y[0]) = (M[0]*x[0]+M[1]*y[0],M[2]*x[0]+M[3]*y[0]) # apply transformation to coordinates - (x[1],y[1]) = (M[0]*x[1]+M[1]*y[1],M[2]*x[1]+M[3]*y[1]) # to get rcb --> Euler system + m = re.match(r'\s*(#|$)',line) + if m: continue # skip comments and blank lines + (x[0],y[0],x[1],y[1]) = map(float,line.split())[8:12] # get start and end coordinates of each segment + (x[0],y[0]) = (M[0]*x[0]+M[1]*y[0],M[2]*x[0]+M[3]*y[0]) # apply transformation to coordinates + (x[1],y[1]) = (M[0]*x[1]+M[1]*y[1],M[2]*x[1]+M[3]*y[1]) # to get rcb --> Euler system - x[0] -= boxX[0] # make relative to origin of bounding box - x[1] -= boxX[0] - y[0] -= boxY[0] - y[1] -= boxY[0] - grainNeighbors.append(map(int,line.split()[12:14])) # remember right and left grain per segment - for i in range(2): # store segment to both points - match = False # check whether point is already known (within a small range) - for posX in connectivityXY.keys(): - if (abs(float(posX)-x[i]) %i'%(grain,origGrain),fill=(128,32,32)) - img.save(name+'.png',"PNG") + img.save(name+'.png',"PNG") # ------------------------- def inside(x,y,points): # tests whether point(x,y) is within polygon described by points