save some memory (avoid copies if not needed)
This commit is contained in:
parent
9f68923038
commit
bb6f54963a
|
@ -45,12 +45,10 @@ for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
microstructure = geom.get_microstructure()
|
|
||||||
|
|
||||||
microstructure = ndimage.filters.generic_filter(microstructure,mostFrequent,
|
damask.util.croak(geom.update(ndimage.filters.generic_filter(
|
||||||
size=(options.stencil,)*3).astype(microstructure.dtype)
|
geom.microstructure,mostFrequent,
|
||||||
|
size=(options.stencil,)*3).astype(geom.microstructure.dtype)))
|
||||||
damask.util.croak(geom.update(microstructure))
|
|
||||||
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
if name is None:
|
if name is None:
|
||||||
|
|
|
@ -60,11 +60,10 @@ for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
microstructure = geom.get_microstructure()
|
grid_original = geom.get_grid()
|
||||||
damask.util.croak(geom)
|
damask.util.croak(geom)
|
||||||
|
|
||||||
grid_original = geom.get_grid()
|
microstructure = np.tile(geom.microstructure,np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1
|
||||||
microstructure = np.tile(geom.get_microstructure(),np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1
|
|
||||||
grid = np.array(microstructure.shape)
|
grid = np.array(microstructure.shape)
|
||||||
|
|
||||||
# --- initialize support data ---------------------------------------------------------------------
|
# --- initialize support data ---------------------------------------------------------------------
|
||||||
|
|
|
@ -30,7 +30,6 @@ for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
microstructure = geom.get_microstructure().flatten('F')
|
|
||||||
damask.util.croak(geom)
|
damask.util.croak(geom)
|
||||||
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
|
@ -38,7 +37,12 @@ for name in filenames:
|
||||||
former = start = -1
|
former = start = -1
|
||||||
reps = 0
|
reps = 0
|
||||||
|
|
||||||
for current in microstructure:
|
if name is None:
|
||||||
|
f = sys.stdout
|
||||||
|
else:
|
||||||
|
f= open(name,'w')
|
||||||
|
|
||||||
|
for current in geom.microstructure.flatten('F'):
|
||||||
if abs(current - former) == 1 and (start - current) == reps*(former - current):
|
if abs(current - former) == 1 and (start - current) == reps*(former - current):
|
||||||
compressType = 'to'
|
compressType = 'to'
|
||||||
reps += 1
|
reps += 1
|
||||||
|
@ -47,13 +51,13 @@ for name in filenames:
|
||||||
reps += 1
|
reps += 1
|
||||||
else:
|
else:
|
||||||
if compressType is None:
|
if compressType is None:
|
||||||
out = geom.get_header()
|
f.write('\n'.join(geom.get_header())+'\n')
|
||||||
elif compressType == '.':
|
elif compressType == '.':
|
||||||
out.append('{}'.format(former))
|
f.write('{}\n'.format(former))
|
||||||
elif compressType == 'to':
|
elif compressType == 'to':
|
||||||
out.append('{} to {}'.format(start,former))
|
f.write('{} to {}\n'.format(start,former))
|
||||||
elif compressType == 'of':
|
elif compressType == 'of':
|
||||||
out.append('{} of {}'.format(reps,former))
|
f.write('{} of {}\n'.format(reps,former))
|
||||||
|
|
||||||
compressType = '.'
|
compressType = '.'
|
||||||
start = current
|
start = current
|
||||||
|
@ -62,15 +66,8 @@ for name in filenames:
|
||||||
former = current
|
former = current
|
||||||
|
|
||||||
if compressType == '.':
|
if compressType == '.':
|
||||||
out.append('{}'.format(former))
|
f.write('{}\n'.format(former))
|
||||||
elif compressType == 'to':
|
elif compressType == 'to':
|
||||||
out.append('{} to {}'.format(start,former))
|
f.write('{} to {}\n'.format(start,former))
|
||||||
elif compressType == 'of':
|
elif compressType == 'of':
|
||||||
out.append('{} of {}'.format(reps,former))
|
f.write('{} of {}\n'.format(reps,former))
|
||||||
|
|
||||||
|
|
||||||
if name is None:
|
|
||||||
sys.stdout.write('\n'.join(out)+'\n')
|
|
||||||
else:
|
|
||||||
with open(name,'w') as f:
|
|
||||||
f.write('\n'.join(out)+'\n')
|
|
||||||
|
|
|
@ -32,11 +32,10 @@ for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
microstructure = geom.get_microstructure()
|
|
||||||
|
|
||||||
renumbered = np.copy(microstructure)
|
renumbered = np.empty(geom.get_grid(),dtype=geom.microstructure.dtype)
|
||||||
for i, oldID in enumerate(np.unique(microstructure)):
|
for i, oldID in enumerate(np.unique(geom.microstructure)):
|
||||||
renumbered = np.where(microstructure == oldID, i+1, renumbered)
|
renumbered = np.where(geom.microstructure == oldID, i+1, renumbered)
|
||||||
|
|
||||||
damask.util.croak(geom.update(renumbered))
|
damask.util.croak(geom.update(renumbered))
|
||||||
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
|
@ -43,7 +43,6 @@ for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
microstructure = geom.get_microstructure()
|
|
||||||
grid = geom.get_grid()
|
grid = geom.get_grid()
|
||||||
size = geom.get_size()
|
size = geom.get_size()
|
||||||
|
|
||||||
|
@ -55,11 +54,14 @@ for name in filenames:
|
||||||
np.array([o*float(n.lower().replace('x','')) if n.lower().endswith('x') \
|
np.array([o*float(n.lower().replace('x','')) if n.lower().endswith('x') \
|
||||||
else float(n) for o,n in zip(size,options.size)],dtype=float)
|
else float(n) for o,n in zip(size,options.size)],dtype=float)
|
||||||
|
|
||||||
if np.any(new_grid != grid):
|
damask.util.croak(geom.update(microstructure =
|
||||||
microstructure = ndimage.interpolation.zoom(microstructure, new_grid/grid,output=microstructure.dtype,
|
ndimage.interpolation.zoom(
|
||||||
order=0,mode='nearest', prefilter=False)
|
geom.microstructure,
|
||||||
|
new_grid/grid,output=geom.microstructure.dtype,
|
||||||
damask.util.croak(geom.update(microstructure,new_size))
|
order=0,mode='nearest', prefilter=False\
|
||||||
|
) \
|
||||||
|
if np.any(new_grid != grid) else None,
|
||||||
|
size = new_size))
|
||||||
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
if name is None:
|
if name is None:
|
||||||
|
|
|
@ -88,7 +88,6 @@ for name in filenames:
|
||||||
microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0,
|
microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0,
|
||||||
prefilter=False,output=dtype,cval=fill) # rotation around z
|
prefilter=False,output=dtype,cval=fill) # rotation around z
|
||||||
|
|
||||||
|
|
||||||
damask.util.croak(geom.update(microstructure,rescale=True))
|
damask.util.croak(geom.update(microstructure,rescale=True))
|
||||||
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,7 @@ for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
damask.util.croak(geom)
|
damask.util.croak(geom)
|
||||||
microstructure = geom.get_microstructure().flatten('F')
|
|
||||||
grid = geom.get_grid()
|
grid = geom.get_grid()
|
||||||
size = geom.get_size()
|
size = geom.get_size()
|
||||||
origin = geom.get_origin()
|
origin = geom.get_origin()
|
||||||
|
@ -55,6 +54,6 @@ for name in filenames:
|
||||||
table.labels_append(['{}_{}'.format(1+i,'pos') for i in range(3)]+['microstructure'])
|
table.labels_append(['{}_{}'.format(1+i,'pos') for i in range(3)]+['microstructure'])
|
||||||
table.head_write()
|
table.head_write()
|
||||||
table.output_flush()
|
table.output_flush()
|
||||||
table.data = np.squeeze(np.dstack((xx,yy,zz,microstructure)),axis=0)
|
table.data = np.squeeze(np.dstack((xx,yy,zz,geom.microstructure.flatten('F'))),axis=0)
|
||||||
table.data_writeArray()
|
table.data_writeArray()
|
||||||
table.close()
|
table.close()
|
||||||
|
|
|
@ -51,10 +51,9 @@ for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
microstructure = geom.get_microstructure()
|
substituted = geom.get_microstructure()
|
||||||
substituted = np.copy(microstructure)
|
|
||||||
|
|
||||||
for old,new in zip(sub[0::2],sub[1::2]): substituted[microstructure==old] = new # substitute microstructure indices
|
for old,new in zip(sub[0::2],sub[1::2]): substituted[substituted==old] = new # substitute microstructure indices
|
||||||
substituted += options.microstructure # constant shift
|
substituted += options.microstructure # constant shift
|
||||||
|
|
||||||
damask.util.croak(geom.update(substituted,origin=geom.get_origin()+options.origin))
|
damask.util.croak(geom.update(substituted,origin=geom.get_origin()+options.origin))
|
||||||
|
|
|
@ -70,18 +70,16 @@ for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
microstructure = geom.get_microstructure()
|
|
||||||
|
|
||||||
offset = np.nanmax(microstructure) if options.offset is None else options.offset
|
offset = np.nanmax(geom.microstructure) if options.offset is None else options.offset
|
||||||
|
|
||||||
microstructure = np.where(ndimage.filters.generic_filter(microstructure,
|
damask.util.croak(geom.update(np.where(ndimage.filters.generic_filter(
|
||||||
taintedNeighborhood,
|
geom.microstructure,
|
||||||
size=1+2*options.vicinity,mode=options.mode,
|
taintedNeighborhood,
|
||||||
extra_arguments=(),
|
size=1+2*options.vicinity,mode=options.mode,
|
||||||
extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}),
|
extra_arguments=(),
|
||||||
microstructure + offset,microstructure)
|
extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}),
|
||||||
|
geom.microstructure + offset,geom.microstructure)))
|
||||||
damask.util.croak(geom.update(microstructure))
|
|
||||||
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
if name is None:
|
if name is None:
|
||||||
|
|
Loading…
Reference in New Issue