added some warnings if Mentat or PIL cabability missing

This commit is contained in:
Philip Eisenlohr 2011-08-18 07:52:07 +00:00
parent ff3bac2496
commit 164da22730
1 changed files with 56 additions and 46 deletions

View File

@ -3,14 +3,14 @@
import sys,os,math,re import sys,os,math,re
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
try:
try: # check for Python Image Lib
import Image,ImageDraw import Image,ImageDraw
ImageCapability = True ImageCapability = True
except: except:
ImageCapability = False ImageCapability = False
try: # check for MSC.Mentat installation location
try:
file = open('%s/../MSCpath'%os.path.dirname(os.path.realpath(sys.argv[0]))) file = open('%s/../MSCpath'%os.path.dirname(os.path.realpath(sys.argv[0])))
MSCpath = os.path.normpath(file.readline().strip()) MSCpath = os.path.normpath(file.readline().strip())
file.close() file.close()
@ -32,7 +32,7 @@ for release,subdirs in sorted(releases.items(),reverse=True):
continue continue
break break
try: try: # check for MSC.Mentat Python interface
from py_mentat import * from py_mentat import *
MentatCapability = True MentatCapability = True
except: except:
@ -309,11 +309,11 @@ def rcbParser(content,M,size,tolerance): # parser for TSL-O
for point in points: for point in points:
rcData['point'].append(point['coords']) rcData['point'].append(point['coords'])
print "\nfound %i points"%(len(rcData['point'])) print " found %i points"%(len(rcData['point']))
for segment in segments: for segment in segments:
rcData['segment'].append(segment) rcData['segment'].append(segment)
print "built %i segments"%(len(rcData['segment'])) print " built %i segments"%(len(rcData['segment']))
for grain in grains['legs']: for grain in grains['legs']:
rcData['grain'].append(grain) rcData['grain'].append(grain)
@ -327,7 +327,7 @@ def rcbParser(content,M,size,tolerance): # parser for TSL-O
myNeighbors[grainNeighbors[leg][side]] = 1 myNeighbors[grainNeighbors[leg][side]] = 1
if myNeighbors: # do I have any neighbors if myNeighbors: # do I have any neighbors
rcData['grainMapping'].append(sorted(myNeighbors.iteritems(), key=lambda (k,v): (v,k), reverse=True)[0][0]) # most frequent grain is me rcData['grainMapping'].append(sorted(myNeighbors.iteritems(), key=lambda (k,v): (v,k), reverse=True)[0][0]) # most frequent grain is me
print "found %i grains\n"%(len(rcData['grain'])) print " found %i grains\n"%(len(rcData['grain']))
rcData['box'] = grains['box'] rcData['box'] = grains['box']
@ -791,11 +791,14 @@ def fftbuild(rcData, height,xframe,yframe,resolution,extrusion): # bu
# ----------------------- MAIN ------------------------------- # ----------------------- MAIN -------------------------------
parser = OptionParser(option_class=extendedOption, usage='%prog [options] datafile[s]', description = """ parser = OptionParser(option_class=extendedOption, usage='%prog [options] datafile[s]', description = """
what I do... Produce image, spectral geometry description, and (auto) Mentat procedure from TSL/OIM
""") reconstructed boundary file
""" + string.replace('$Id: spectral_iterationCount 919 2011-06-15 18:14:05Z MPIE\p.eisenlohr $','\n','\\n')
)
parser.add_option("-o", "--output", action='extend', dest='output', type='string', \ parser.add_option("-o", "--output", action='extend', dest='output', type='string', \
help="type of output [image,mentat,procedure,spectral]") help="types of output [image,mentat,procedure,spectral]")
parser.add_option("-p", "--port", type="int",\ parser.add_option("-p", "--port", type="int",\
dest="port",\ dest="port",\
help="Mentat connection port") help="Mentat connection port")
@ -859,6 +862,7 @@ parser.set_defaults(mesh = 'dt_planar_trimesh')
parser.set_defaults(twoD = False) parser.set_defaults(twoD = False)
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if not len(args): if not len(args):
parser.error('no boundary file specified') parser.error('no boundary file specified')
@ -873,15 +877,18 @@ except:
options.output = [s.lower() for s in options.output] # lower case options.output = [s.lower() for s in options.output] # lower case
myName = os.path.splitext(args[0])[0] myName = os.path.splitext(args[0])[0]
print "\n",myName print "\n%s\n"%myName
orientationData = rcbOrientationParser(boundarySegments) orientationData = rcbOrientationParser(boundarySegments)
rcData = rcbParser(boundarySegments,options.M,options.size,options.tolerance) rcData = rcbParser(boundarySegments,options.M,options.size,options.tolerance)
# ----- write image ----- # ----- write image -----
if ImageCapability and 'image' in options.output and options.imgsize > 0: if 'image' in options.output and options.imgsize > 0:
if ImageCapability:
image(myName,options.imgsize,options.xmargin,options.ymargin,rcData) image(myName,options.imgsize,options.xmargin,options.ymargin,rcData)
else:
print '...no image drawing possible (PIL missing)...'
# ----- write spectral geom ----- # ----- write spectral geom -----
@ -895,12 +902,13 @@ if 'spectral' in options.output:
geomFile.write('\n'.join(map(str,fftdata['fftpoints']))+'\n') # write grain indexes, one per line geomFile.write('\n'.join(map(str,fftdata['fftpoints']))+'\n') # write grain indexes, one per line
geomFile.close() # close geom file geomFile.close() # close geom file
print('assigned %i out of %i Fourier points'%(len(fftdata['fftpoints']), int(fftdata['resolution'][0])*int(fftdata['resolution'][1]))) print('assigned %i out of %i Fourier points.'%(len(fftdata['fftpoints']), int(fftdata['resolution'][0])*int(fftdata['resolution'][1])))
# ----- write Mentat procedure ----- # ----- write Mentat procedure -----
if MentatCapability and 'mentat' in options.output: if 'mentat' in options.output:
if MentatCapability:
rcData['offsetPoints'] = 1+4 # gage definition generates 4 points rcData['offsetPoints'] = 1+4 # gage definition generates 4 points
rcData['offsetSegments'] = 1+4 # gage definition generates 4 segments rcData['offsetSegments'] = 1+4 # gage definition generates 4 segments
@ -933,6 +941,8 @@ if MentatCapability and 'mentat' in options.output:
py_disconnect() py_disconnect()
if 'procedure' in options.output: if 'procedure' in options.output:
output(outputLocals['log'],outputLocals,'Stdout') output(outputLocals['log'],outputLocals,'Stdout')
else:
print '...no interaction with Mentat possible...'
# ----- write config data to file ----- # ----- write config data to file -----