now also using numpy
This commit is contained in:
parent
7ae786e802
commit
563e74c832
|
@ -39,7 +39,6 @@ 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=extendedOption, usage='%prog options [file[s]]', description = """
|
||||||
compress geometry files with ranges "a to b" and/or multiples "n of x".
|
compress geometry files with ranges "a to b" and/or multiples "n of x".
|
||||||
""" + string.replace('$Id$','\n','\\n')
|
""" + string.replace('$Id$','\n','\\n')
|
||||||
|
@ -80,12 +79,13 @@ for file in files:
|
||||||
content = file['input'].readlines()
|
content = file['input'].readlines()
|
||||||
file['input'].close()
|
file['input'].close()
|
||||||
|
|
||||||
#--- interpretate header --------------------------------------------------------------------------
|
#--- interprete header ----------------------------------------------------------------------------
|
||||||
info = {'grid': [0,0,0],
|
info = {
|
||||||
'size': [0.0,0.0,0.0],
|
'grid': numpy.zeros(3,'i'),
|
||||||
'origin': [0.0,0.0,0.0],
|
'size': numpy.zeros(3,'d'),
|
||||||
'homogenization': 1,
|
'origin': numpy.zeros(3,'d'),
|
||||||
'microstructures': 0,
|
'microstructures': 0,
|
||||||
|
'homogenization': 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
new_header = []
|
new_header = []
|
||||||
|
@ -102,10 +102,10 @@ for file in files:
|
||||||
info[headitems[0]] = mappings[headitems[0]](headitems[1])
|
info[headitems[0]] = mappings[headitems[0]](headitems[1])
|
||||||
new_header.append(header)
|
new_header.append(header)
|
||||||
|
|
||||||
if info['grid'] == [0,0,0]:
|
if numpy.all(info['grid'] == 0):
|
||||||
file['croak'].write('no grid info found.\n')
|
file['croak'].write('no grid info found.\n')
|
||||||
continue
|
continue
|
||||||
if info['size'] == [0.0,0.0,0.0]:
|
if numpy.all(info['size'] == 0.0):
|
||||||
file['croak'].write('no size info found.\n')
|
file['croak'].write('no size info found.\n')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
import os,sys,string,re,math,numpy
|
import os,sys,string,re,math,numpy
|
||||||
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
class extendedOption(Option):
|
class extendedOption(Option):
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
@ -32,7 +31,6 @@ identifiers = {
|
||||||
'size': ['x','y','z'],
|
'size': ['x','y','z'],
|
||||||
'origin': ['x','y','z'],
|
'origin': ['x','y','z'],
|
||||||
}
|
}
|
||||||
|
|
||||||
mappings = {
|
mappings = {
|
||||||
'grid': lambda x: int(x),
|
'grid': lambda x: int(x),
|
||||||
'size': lambda x: float(x),
|
'size': lambda x: float(x),
|
||||||
|
@ -41,7 +39,6 @@ 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=extendedOption, usage='%prog options [file[s]]', description = """
|
||||||
Unpack geometry files containing ranges "a to b" and/or "n of x" multiples (exclusively in one line).
|
Unpack geometry files containing ranges "a to b" and/or "n of x" multiples (exclusively in one line).
|
||||||
""" + string.replace('$Id$','\n','\\n')
|
""" + string.replace('$Id$','\n','\\n')
|
||||||
|
@ -87,12 +84,13 @@ for file in files:
|
||||||
content = file['input'].readlines()
|
content = file['input'].readlines()
|
||||||
file['input'].close()
|
file['input'].close()
|
||||||
|
|
||||||
#--- interpretate header --------------------------------------------------------------------------
|
#--- interprete header ----------------------------------------------------------------------------
|
||||||
info = {'grid': [0,0,0],
|
info = {
|
||||||
'size': [0.0,0.0,0.0],
|
'grid': numpy.zeros(3,'i'),
|
||||||
'origin': [0.0,0.0,0.0],
|
'size': numpy.zeros(3,'d'),
|
||||||
'homogenization': 1,
|
'origin': numpy.zeros(3,'d'),
|
||||||
'microstructures': 0,
|
'microstructures': 0,
|
||||||
|
'homogenization': 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
new_header = []
|
new_header = []
|
||||||
|
@ -109,10 +107,10 @@ for file in files:
|
||||||
info[headitems[0]] = mappings[headitems[0]](headitems[1])
|
info[headitems[0]] = mappings[headitems[0]](headitems[1])
|
||||||
new_header.append(header)
|
new_header.append(header)
|
||||||
|
|
||||||
if info['grid'] == [0,0,0]:
|
if numpy.all(info['grid'] == 0):
|
||||||
file['croak'].write('no grid info found.\n')
|
file['croak'].write('no grid info found.\n')
|
||||||
continue
|
continue
|
||||||
if info['size'] == [0.0,0.0,0.0]:
|
if numpy.all(info['size'] == 0.0):
|
||||||
file['croak'].write('no size info found.\n')
|
file['croak'].write('no size info found.\n')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -124,13 +122,13 @@ for file in files:
|
||||||
'origin x y z: %s\n'%(' : '.join(map(str,info['origin']))) + \
|
'origin x y z: %s\n'%(' : '.join(map(str,info['origin']))) + \
|
||||||
'homogenization: %i\n'%info['homogenization'] + \
|
'homogenization: %i\n'%info['homogenization'] + \
|
||||||
'microstructures: %i\n'%info['microstructures'])
|
'microstructures: %i\n'%info['microstructures'])
|
||||||
|
file['output'].write('%i\theader\n'%(len(new_header))+''.join(new_header))
|
||||||
|
|
||||||
if info['microstructures'] > 0:
|
if info['microstructures'] > 0:
|
||||||
digits = 1+int(math.log10(int(info['microstructures'])))
|
digits = 1+int(math.log10(int(info['microstructures'])))
|
||||||
else:
|
else:
|
||||||
digits = 1+int(math.log10(int(info['grid'][0]*info['grid'][1]*info['grid'][2])))
|
digits = 1+int(math.log10(int(info['grid'][0]*info['grid'][1]*info['grid'][2])))
|
||||||
|
|
||||||
file['output'].write('%i\theader\n'%(len(new_header))+''.join(new_header))
|
|
||||||
|
|
||||||
#--- unpack input ---------------------------------------------------------------------------------
|
#--- unpack input ---------------------------------------------------------------------------------
|
||||||
wordsWritten = 0
|
wordsWritten = 0
|
||||||
|
|
Loading…
Reference in New Issue