iteritems does not exist in python3 anymore

items also works for python2 (might be slower though)
This commit is contained in:
Martin Diehl 2018-07-19 16:16:10 +02:00
parent d138993c1d
commit 9821654aae
9 changed files with 16 additions and 16 deletions

View File

@ -58,7 +58,7 @@ for name in filenames:
errors = [] errors = []
remarks = [] remarks = []
for type, data in items.iteritems(): for type, data in items.items():
for what in data['labels']: for what in data['labels']:
dim = table.label_dimension(what) dim = table.label_dimension(what)
if dim != data['dim']: remarks.append('column {} is not a {}...'.format(what,type)) if dim != data['dim']: remarks.append('column {} is not a {}...'.format(what,type))
@ -81,7 +81,7 @@ for name in filenames:
outputAlive = True outputAlive = True
while outputAlive and table.data_read(): # read next data line of ASCII table while outputAlive and table.data_read(): # read next data line of ASCII table
for type, data in items.iteritems(): for type, data in items.items():
for column in data['column']: for column in data['column']:
table.data_append(determinant(map(float,table.data[column: table.data_append(determinant(map(float,table.data[column:
column+data['dim']]))) column+data['dim']])))

View File

@ -66,7 +66,7 @@ for name in filenames:
remarks = [] remarks = []
column = {} column = {}
for type, data in items.iteritems(): for type, data in items.items():
for what in data['labels']: for what in data['labels']:
dim = table.label_dimension(what) dim = table.label_dimension(what)
if dim != data['dim']: remarks.append('column {} is not a {}.'.format(what,type)) if dim != data['dim']: remarks.append('column {} is not a {}.'.format(what,type))
@ -83,7 +83,7 @@ for name in filenames:
# ------------------------------------------ assemble header -------------------------------------- # ------------------------------------------ assemble header --------------------------------------
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:])) table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
for type, data in items.iteritems(): for type, data in items.items():
for label in data['active']: for label in data['active']:
table.labels_append(['{}_dev({})'.format(i+1,label) for i in range(data['dim'])] + \ table.labels_append(['{}_dev({})'.format(i+1,label) for i in range(data['dim'])] + \
(['sph({})'.format(label)] if options.spherical else [])) # extend ASCII header with new labels (['sph({})'.format(label)] if options.spherical else [])) # extend ASCII header with new labels
@ -93,7 +93,7 @@ for name in filenames:
outputAlive = True outputAlive = True
while outputAlive and table.data_read(): # read next data line of ASCII table while outputAlive and table.data_read(): # read next data line of ASCII table
for type, data in items.iteritems(): for type, data in items.items():
for column in data['column']: for column in data['column']:
table.data_append(deviator(map(float,table.data[column: table.data_append(deviator(map(float,table.data[column:
column+data['dim']]),options.spherical)) column+data['dim']]),options.spherical))

View File

@ -83,7 +83,7 @@ for name in filenames:
if table.label_dimension(options.pos) != 3: errors.append('coordinates {} are not a vector.'.format(options.pos)) if table.label_dimension(options.pos) != 3: errors.append('coordinates {} are not a vector.'.format(options.pos))
else: colCoord = table.label_index(options.pos) else: colCoord = table.label_index(options.pos)
for type, data in items.iteritems(): for type, data in items.items():
for what in (data['labels'] if data['labels'] is not None else []): for what in (data['labels'] if data['labels'] is not None else []):
dim = table.label_dimension(what) dim = table.label_dimension(what)
if dim != data['dim']: remarks.append('column {} is not a {}.'.format(what,type)) if dim != data['dim']: remarks.append('column {} is not a {}.'.format(what,type))
@ -100,7 +100,7 @@ for name in filenames:
# ------------------------------------------ assemble header -------------------------------------- # ------------------------------------------ assemble header --------------------------------------
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:])) table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
for type, data in items.iteritems(): for type, data in items.items():
for label in data['active']: for label in data['active']:
table.labels_append(['Gauss{}({})'.format(options.sigma,label)]) # extend ASCII header with new labels table.labels_append(['Gauss{}({})'.format(options.sigma,label)]) # extend ASCII header with new labels
table.head_write() table.head_write()
@ -114,7 +114,7 @@ for name in filenames:
# ------------------------------------------ process value field ----------------------------------- # ------------------------------------------ process value field -----------------------------------
stack = [table.data] stack = [table.data]
for type, data in items.iteritems(): for type, data in items.items():
for i,label in enumerate(data['active']): for i,label in enumerate(data['active']):
stack.append(ndimage.filters.gaussian_filter(table.data[:,data['column'][i]], stack.append(ndimage.filters.gaussian_filter(table.data[:,data['column'][i]],
options.sigma,options.order, options.sigma,options.order,

View File

@ -70,7 +70,7 @@ for name in filenames:
errors = [] errors = []
remarks = [] remarks = []
for type, data in items.iteritems(): for type, data in items.items():
for what in data['labels']: for what in data['labels']:
dim = table.label_dimension(what) dim = table.label_dimension(what)
if dim != data['dim']: remarks.append('column {} is not a {}...'.format(what,type)) if dim != data['dim']: remarks.append('column {} is not a {}...'.format(what,type))
@ -94,7 +94,7 @@ for name in filenames:
outputAlive = True outputAlive = True
while outputAlive and table.data_read(): # read next data line of ASCII table while outputAlive and table.data_read(): # read next data line of ASCII table
for type, data in items.iteritems(): for type, data in items.items():
for column in data['column']: for column in data['column']:
table.data_append(Mises(type, table.data_append(Mises(type,
np.array(table.data[column:column+data['dim']],'d').reshape(data['shape']))) np.array(table.data[column:column+data['dim']],'d').reshape(data['shape'])))

View File

@ -58,7 +58,7 @@ for name in filenames:
errors = [] errors = []
remarks = [] remarks = []
for type, data in items.iteritems(): for type, data in items.items():
for what in data['labels']: for what in data['labels']:
dim = table.label_dimension(what) dim = table.label_dimension(what)
if dim != data['dim']: remarks.append('column {} is not a {}...'.format(what,type)) if dim != data['dim']: remarks.append('column {} is not a {}...'.format(what,type))
@ -84,7 +84,7 @@ for name in filenames:
outputAlive = True outputAlive = True
while outputAlive and table.data_read(): # read next data line of ASCII table while outputAlive and table.data_read(): # read next data line of ASCII table
for type, data in items.iteritems(): for type, data in items.items():
for column in data['column']: for column in data['column']:
(u,v) = np.linalg.eigh(np.array(map(float,table.data[column:column+data['dim']])).reshape(data['shape'])) (u,v) = np.linalg.eigh(np.array(map(float,table.data[column:column+data['dim']])).reshape(data['shape']))
if options.rh and np.dot(np.cross(v[:,0], v[:,1]), v[:,2]) < 0.0 : v[:, 2] *= -1.0 # ensure right-handed eigenvector basis if options.rh and np.dot(np.cross(v[:,0], v[:,1]), v[:,2]) < 0.0 : v[:, 2] *= -1.0 # ensure right-handed eigenvector basis

View File

@ -101,7 +101,7 @@ for name in filenames:
errors = [] errors = []
remarks = [] remarks = []
for type, data in items.iteritems(): for type, data in items.items():
for what in data['labels']: for what in data['labels']:
dim = table.label_dimension(what) dim = table.label_dimension(what)
if dim != data['dim']: remarks.append('column {} is not a {}...'.format(what,type)) if dim != data['dim']: remarks.append('column {} is not a {}...'.format(what,type))

View File

@ -73,7 +73,7 @@ for name in filenames:
remarks = [] remarks = []
column = {} column = {}
for type, data in items.iteritems(): for type, data in items.items():
for what in data['labels']: for what in data['labels']:
dim = table.label_dimension(what) dim = table.label_dimension(what)
if dim != data['dim']: remarks.append('column {} is not a {}.'.format(what,type)) if dim != data['dim']: remarks.append('column {} is not a {}.'.format(what,type))

View File

@ -92,7 +92,7 @@ for name in filenames:
} }
substituted = np.copy(microstructure) substituted = np.copy(microstructure)
for k, v in sub.iteritems(): substituted[microstructure==k] = v # substitute microstructure indices for k, v in sub.items(): substituted[microstructure==k] = v # substitute microstructure indices
substituted += options.microstructure # shift microstructure indices substituted += options.microstructure # shift microstructure indices

View File

@ -344,7 +344,7 @@ def rcbParser(content,M,size,tolerance,idcolumn,segmentcolumn):
else: else:
myNeighbors[grainNeighbors[leg][side]] = 1 myNeighbors[grainNeighbors[leg][side]] = 1
if myNeighbors: # do I have any neighbors (i.e., non-bounding box segment) if myNeighbors: # do I have any neighbors (i.e., non-bounding box segment)
candidateGrains = sorted(myNeighbors.iteritems(), key=lambda p: (p[1],p[0]), reverse=True) # sort grain counting candidateGrains = sorted(myNeighbors.items(), key=lambda p: (p[1],p[0]), reverse=True) # sort grain counting
# most frequent one not yet seen? # most frequent one not yet seen?
rcData['grainMapping'].append(candidateGrains[0 if candidateGrains[0][0] not in rcData['grainMapping'] else 1][0]) # must be me then rcData['grainMapping'].append(candidateGrains[0 if candidateGrains[0][0] not in rcData['grainMapping'] else 1][0]) # must be me then
# special case of bi-crystal situation... # special case of bi-crystal situation...