store history of geometry modifications

This commit is contained in:
Martin Diehl 2020-08-23 23:23:23 +02:00
parent a1c78b778a
commit 9867830d68
2 changed files with 23 additions and 5 deletions

View File

@ -1,7 +1,8 @@
import sys import sys
import copy import copy
from io import StringIO import inspect
import multiprocessing import multiprocessing
from io import StringIO
from functools import partial from functools import partial
import numpy as np import numpy as np
@ -416,8 +417,8 @@ class Geom:
else: else:
microstructure = microstructure.reshape(grid) microstructure = microstructure.reshape(grid)
#ToDo: comments = 'geom.py:from_Laguerre_tessellation v{}'.format(version) creator = util.edit_info('damask.Result.'+inspect.stack()[0][3])
return Geom(microstructure+1,size,homogenization=1) return Geom(microstructure+1,size,homogenization=1,comments=creator)
@staticmethod @staticmethod
@ -441,8 +442,8 @@ class Geom:
KDTree = spatial.cKDTree(seeds,boxsize=size) if periodic else spatial.cKDTree(seeds) KDTree = spatial.cKDTree(seeds,boxsize=size) if periodic else spatial.cKDTree(seeds)
devNull,microstructure = KDTree.query(coords) devNull,microstructure = KDTree.query(coords)
#ToDo: comments = 'geom.py:from_Voronoi_tessellation v{}'.format(version) creator = util.edit_info('damask.Result.'+inspect.stack()[0][3])
return Geom(microstructure.reshape(grid)+1,size,homogenization=1) return Geom(microstructure.reshape(grid)+1,size,homogenization=1,comments=creator)
def to_file(self,fname,pack=None): def to_file(self,fname,pack=None):
@ -588,6 +589,7 @@ class Geom:
fill_ = np.full_like(self.microstructure,np.nanmax(self.microstructure)+1 if fill is None else fill) fill_ = np.full_like(self.microstructure,np.nanmax(self.microstructure)+1 if fill is None else fill)
ms = np.ma.MaskedArray(fill_,np.logical_not(mask) if inverse else mask) ms = np.ma.MaskedArray(fill_,np.logical_not(mask) if inverse else mask)
self.add_comments(util.edit_info('damask.Result.'+inspect.stack()[0][3]))
return self.update(ms) return self.update(ms)
@ -618,6 +620,7 @@ class Geom:
if 'x' in directions: if 'x' in directions:
ms = np.concatenate([ms,ms[limits[0]:limits[1]:-1,:,:]],0) ms = np.concatenate([ms,ms[limits[0]:limits[1]:-1,:,:]],0)
self.add_comments(util.edit_info('damask.Result.'+inspect.stack()[0][3]))
return self.update(ms,rescale=True) return self.update(ms,rescale=True)
@ -633,6 +636,7 @@ class Geom:
Assume geometry to be periodic. Defaults to True. Assume geometry to be periodic. Defaults to True.
""" """
self.add_comments(util.edit_info('damask.Result.'+inspect.stack()[0][3]))
return self.update( return self.update(
ndimage.interpolation.zoom( ndimage.interpolation.zoom(
self.microstructure, self.microstructure,
@ -667,6 +671,7 @@ class Geom:
else: else:
return me return me
self.add_comments(util.edit_info('damask.Result.'+inspect.stack()[0][3]))
return self.update(ndimage.filters.generic_filter( return self.update(ndimage.filters.generic_filter(
self.microstructure, self.microstructure,
mostFrequent, mostFrequent,
@ -683,6 +688,7 @@ class Geom:
for i, oldID in enumerate(np.unique(self.microstructure)): for i, oldID in enumerate(np.unique(self.microstructure)):
renumbered = np.where(self.microstructure == oldID, i+1, renumbered) renumbered = np.where(self.microstructure == oldID, i+1, renumbered)
self.add_comments(util.edit_info('damask.Result.'+inspect.stack()[0][3]))
return self.update(renumbered) return self.update(renumbered)
@ -717,6 +723,7 @@ class Geom:
origin = self.origin-(np.asarray(microstructure_in.shape)-self.grid)*.5 * self.size/self.grid origin = self.origin-(np.asarray(microstructure_in.shape)-self.grid)*.5 * self.size/self.grid
self.add_comments(util.edit_info('damask.Result.'+inspect.stack()[0][3]))
return self.update(microstructure_in,origin=origin,rescale=True) return self.update(microstructure_in,origin=origin,rescale=True)
@ -749,6 +756,7 @@ class Geom:
canvas[ll[0]:ur[0],ll[1]:ur[1],ll[2]:ur[2]] = self.microstructure[LL[0]:UR[0],LL[1]:UR[1],LL[2]:UR[2]] canvas[ll[0]:ur[0],ll[1]:ur[1],ll[2]:ur[2]] = self.microstructure[LL[0]:UR[0],LL[1]:UR[1],LL[2]:UR[2]]
self.add_comments(util.edit_info('damask.Result.'+inspect.stack()[0][3]))
return self.update(canvas,origin=self.origin+offset*self.size/self.grid,rescale=True) return self.update(canvas,origin=self.origin+offset*self.size/self.grid,rescale=True)
@ -768,6 +776,7 @@ class Geom:
for from_ms,to_ms in zip(from_microstructure,to_microstructure): for from_ms,to_ms in zip(from_microstructure,to_microstructure):
substituted[self.microstructure==from_ms] = to_ms substituted[self.microstructure==from_ms] = to_ms
self.add_comments(util.edit_info('damask.Result.'+inspect.stack()[0][3]))
return self.update(substituted) return self.update(substituted)
@ -813,4 +822,5 @@ class Geom:
extra_keywords={'trigger':trigger}) extra_keywords={'trigger':trigger})
microstructure = np.ma.MaskedArray(self.microstructure + offset_, np.logical_not(mask)) microstructure = np.ma.MaskedArray(self.microstructure + offset_, np.logical_not(mask))
self.add_comments(util.edit_info('damask.Result.'+inspect.stack()[0][3]))
return self.update(microstructure) return self.update(microstructure)

View File

@ -9,6 +9,8 @@ from optparse import Option
import numpy as np import numpy as np
import damask
# limit visibility # limit visibility
__all__=[ __all__=[
'srepr', 'srepr',
@ -20,6 +22,7 @@ __all__=[
'scale_to_coprime', 'scale_to_coprime',
'return_message', 'return_message',
'extendableOption', 'extendableOption',
'edit_info'
] ]
#################################################################################################### ####################################################################################################
@ -175,6 +178,11 @@ def scale_to_coprime(v):
return m return m
def edit_info(who):
now = datetime.datetime.now().astimezone().strftime('%Y-%m-%d %H:%M:%S%z')
return f'{who} v{damask.version} ({now})'
#################################################################################################### ####################################################################################################
# Classes # Classes
#################################################################################################### ####################################################################################################