some more syntax improvements

This commit is contained in:
Martin Diehl 2016-03-01 22:12:04 +01:00
parent 043f2faeb3
commit 974b8cde41
10 changed files with 25 additions and 41 deletions

View File

@ -1,16 +1,7 @@
#!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*-
'''
Writes meaningful labels to the Abaqus input file (*.inp)
based on the files
<modelname_jobname>.output<Homogenization/Crystallite/Constitutive>
that are written during the first run of the model.
See Abaqus Keyword Reference Manual (AKRM) *DEPVAR for details.
Original script: marc_addUserOutput.py modified by Benjamin Bode
'''
import sys,os,re,string
import sys,os,re
from optparse import OptionParser
import damask
@ -19,7 +10,6 @@ scriptID = ' '.join([scriptName,damask.version])
# -----------------------------
def ParseOutputFormat(filename,what,me):
# -----------------------------
format = {'outputs':{},'specials':{'brothers':[]}}
outputmetafile = filename+'.output'+what
@ -120,7 +110,7 @@ for file in files:
for what in me:
outputFormat[what] = ParseOutputFormat(formatFile,what,me[what])
if not '_id' in outputFormat[what]['specials']:
if '_id' not in outputFormat[what]['specials']:
print "'%s' not found in <%s>"%(me[what],what)
print '\n'.join(map(lambda x:' '+x,outputFormat[what]['specials']['brothers']))
sys.exit(1)
@ -164,19 +154,14 @@ for file in files:
if m:
lastSection = thisSection
thisSection = m.group(1)
#Abaqus keyword can be upper or lower case
if (lastSection.upper() == '*DEPVAR' and thisSection.upper() == '*USER'):
#Abaqus SDVs are named SDV1...SDVn if no specific name is given
#Abaqus needs total number of SDVs in the line after *Depvar keyword
if (lastSection.upper() == '*DEPVAR' and thisSection.upper() == '*USER'): #Abaqus keyword can be upper or lower case
if options.number > 0:
#number of SDVs
output.write('%i\n'%options.number)
output.write('%i\n'%options.number) #Abaqus needs total number of SDVs in the line after *Depvar keyword
else:
#number of SDVs
output.write('%i\n'%len(UserVars))
#index,output variable key,output variable description
for i in range(len(UserVars)):
output.write('%i,"%i%s","%i%s"\n'%(i+1,0,UserVars[i],0,UserVars[i]))
output.write('%i,"%i%s","%i%s"\n'%(i+1,0,UserVars[i],0,UserVars[i])) #index,output variable key,output variable description
if (thisSection.upper() != '*DEPVAR' or not re.match('\s*\d',line)):
output.write(line)
output.close()

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*-
import os,sys,math,string
import os,sys,math
import numpy as np
from optparse import OptionParser
import damask
@ -114,7 +114,7 @@ for name in filenames:
microstructure = microstructure.reshape(info['grid'],order='F')
if options.dimension != None:
if options.dimension is not None:
mask = (np.array(options.dimension) < 0).astype(float) # zero where positive dimension, otherwise one
dim = abs(np.array(options.dimension)) # dimensions of primitive body
pos = np.zeros(3,dtype='float')
@ -134,10 +134,9 @@ for name in filenames:
# --- report ---------------------------------------------------------------------------------------
if ( newInfo['microstructures'] != info['microstructures']):
damask.util.croak('--> microstructures: %i'%newInfo['microstructures'])
remarks = []
if ( newInfo['microstructures'] != info['microstructures']): remarks.append('--> microstructures: %i'%newInfo['microstructures'])
if remarks != []: damask.util.croak(remarks)
#--- write header ---------------------------------------------------------------------------------

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*-
import os,sys,math,string
import os,sys,math
import numpy as np
from optparse import OptionParser
import damask
@ -81,7 +81,8 @@ for name in filenames:
'microstructures': 0,
}
newInfo['grid'] = np.array([int(o*float(n.translate(None,'xX'))) if n[-1].lower() == 'x' else int(n) for o,n in zip(info['grid'],options.grid)],'i')
newInfo['grid'] = np.array([int(o*float(n.translate(None,'xX'))) if n[-1].lower() == 'x'\
else int(n) for o,n in zip(info['grid'],options.grid)],'i')
newInfo['grid'] = np.where(newInfo['grid'] > 0, newInfo['grid'],info['grid'])
microstructure_cropped = np.zeros(newInfo['grid'],'i')
@ -143,7 +144,7 @@ for name in filenames:
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=newInfo['origin']),
"homogenization\t{homog}".format(homog=info['homogenization']),
"microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']),
extra_header
extra_header
])
table.labels_clear()
table.head_write()

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*-
import os,sys,string,vtk
import os,sys,vtk
import numpy as np
from optparse import OptionParser
import damask
@ -91,8 +91,7 @@ for name in filenames:
(directory,filename) = os.path.split(name)
writer.SetDataModeToBinary()
writer.SetCompressorTypeToZLib()
writer.SetFileName(os.path.join(directory,os.path.splitext(filename)[0]
+'.'+writer.GetDefaultFileExtension()))
writer.SetFileName(os.path.join(directory,os.path.splitext(filename)[0]+'.'+writer.GetDefaultFileExtension()))
else:
writer = vtk.vtkDataSetWriter()
writer.WriteToOutputStringOn()
@ -101,6 +100,6 @@ for name in filenames:
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
else: writer.SetInputData(grid)
writer.Write()
if name == None: sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
if name is None: sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
table.close()

View File

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

View File

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

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*-
import os,sys,math,string
import os,sys,math
import numpy as np
from optparse import OptionParser
from PIL import Image,ImageOps
from PIL import Image
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
@ -51,7 +51,7 @@ for name in filenames:
try:
img.seek(slice) # advance to slice
layer = np.expand_dims(1+np.array(img,dtype = 'uint16'),axis = 0) # read image layer
microstructure = layer if slice == 0 else np.vstack((microstructure,layer)) # add to microstructure data
microstructure = layer if slice == 0 else np.vstack((microstructure,layer)) # noqa
slice += 1 # advance to next slice
except EOFError:
break

View File

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

View File

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

View File

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