simplified

This commit is contained in:
Martin Diehl 2021-04-05 16:32:28 +02:00
parent faa9e6aa6a
commit 115e3dd4c7
4 changed files with 23 additions and 38 deletions

View File

@ -81,26 +81,32 @@ class Grid:
""" """
message = [] message = []
if np.any(other.cells != self.cells): if np.any(other.cells != self.cells):
message.append(util.deemph(f'cells a b c: {util.srepr(other.cells," x ")}')) message.append(util.deemph(f'cells x y z: {util.srepr(other.cells," x ")}'))
message.append(util.emph( f'cells a b c: {util.srepr( self.cells," x ")}')) message.append(util.emph( f'cells x y z: {util.srepr( self.cells," x ")}'))
if not np.allclose(other.size,self.size): if not np.allclose(other.size,self.size):
message.append(util.deemph(f'size x y z: {util.srepr(other.size," x ")}')) message.append(util.deemph(f'size x y z: {util.srepr(other.size," x ")}'))
message.append(util.emph( f'size x y z: {util.srepr( self.size," x ")}')) message.append(util.emph( f'size x y z: {util.srepr( self.size," x ")}'))
if not np.allclose(other.origin,self.origin): if not np.allclose(other.origin,self.origin):
message.append(util.deemph(f'origin x y z: {util.srepr(other.origin," ")}')) message.append(util.deemph(f'origin x y z: {util.srepr(other.origin," ")}'))
message.append(util.emph( f'origin x y z: {util.srepr( self.origin," ")}')) message.append(util.emph( f'origin x y z: {util.srepr( self.origin," ")}'))
if other.N_materials != self.N_materials: if other.N_materials != self.N_materials:
message.append(util.deemph(f'# materials: {other.N_materials}')) message.append(util.deemph(f'# materials: {other.N_materials}'))
message.append(util.emph( f'# materials: { self.N_materials}')) message.append(util.emph( f'# materials: { self.N_materials}'))
if np.nanmin(other.material) != np.nanmin(self.material):
message.append(util.deemph(f'min material: {np.nanmin(other.material)}'))
message.append(util.emph( f'min material: {np.nanmin( self.material)}'))
if np.nanmax(other.material) != np.nanmax(self.material): if np.nanmax(other.material) != np.nanmax(self.material):
message.append(util.deemph(f'max material: {np.nanmax(other.material)}')) message.append(util.deemph(f'max material: {np.nanmax(other.material)}'))
message.append(util.emph( f'max material: {np.nanmax( self.material)}')) message.append(util.emph( f'max material: {np.nanmax( self.material)}'))
return util.return_message(message) print(util.srepr(message))
return True if message != [] or (other.material != self.material).any() else False
@property @property

View File

@ -1234,7 +1234,7 @@ class Result:
---------- ----------
output : str or list of str output : str or list of str
Labels of the datasets to read. Defaults to '*', in which Labels of the datasets to read. Defaults to '*', in which
case all datasets are placed. case all datasets are read.
flatten : bool flatten : bool
Remove singular levels of the folder hierarchy. Remove singular levels of the folder hierarchy.
This might be beneficial in case of single increment, This might be beneficial in case of single increment,

View File

@ -22,7 +22,6 @@ __all__=[
'scale_to_coprime', 'scale_to_coprime',
'project_stereographic', 'project_stereographic',
'hybrid_IA', 'hybrid_IA',
'return_message',
'execution_stamp', 'execution_stamp',
'shapeshifter', 'shapeblender', 'shapeshifter', 'shapeblender',
'extend_docstring', 'extended_docstring', 'extend_docstring', 'extended_docstring',
@ -64,7 +63,8 @@ def srepr(arg,glue = '\n'):
(hasattr(arg, '__getitem__') or (hasattr(arg, '__getitem__') or
hasattr(arg, '__iter__'))): hasattr(arg, '__iter__'))):
return glue.join(str(x) for x in arg) return glue.join(str(x) for x in arg)
return arg if isinstance(arg,str) else repr(arg) else:
return arg if isinstance(arg,str) else repr(arg)
def emph(what): def emph(what):
@ -463,26 +463,6 @@ def dict_flatten(d):
#################################################################################################### ####################################################################################################
# Classes # Classes
#################################################################################################### ####################################################################################################
class return_message:
"""Object with formatted return message."""
def __init__(self,message):
"""
Set return message.
Parameters
----------
message : str or list of str
message for output to screen
"""
self.message = message
def __repr__(self):
"""Return message suitable for interactive shells."""
return srepr(self.message)
class _ProgressBar: class _ProgressBar:
""" """
Report progress of an interation as a status bar. Report progress of an interation as a status bar.

View File

@ -14,8 +14,7 @@ from damask import grid_filters
def grid_equal(a,b): def grid_equal(a,b):
return np.all(a.material == b.material) and \ return np.all(a.material == b.material) and \
np.all(a.cells == b.cells) and \ np.all(a.cells == b.cells) and \
np.allclose(a.size, b.size) and \ np.allclose(a.size, b.size)
str(a.diff(b)) == str(b.diff(a))
@pytest.fixture @pytest.fixture
def default(): def default():
@ -43,12 +42,12 @@ class TestGrid:
print('patched datetime.datetime.now') print('patched datetime.datetime.now')
def test_diff_equal(self,default): def test_diff_equal(self,default):
assert str(default.diff(default)) == '' assert not default.diff(default)
def test_diff_not_equal(self,default): def test_diff_not_equal(self,default):
new = Grid(default.material[1:,1:,1:]+1,default.size*.9,np.ones(3)-default.origin,comments=['modified']) new = Grid(default.material[1:,1:,1:]+1,default.size*.9,np.ones(3)-default.origin,comments=['modified'])
assert str(default.diff(new)) != '' assert default.diff(new)
def test_repr(self,default): def test_repr(self,default):
print(default) print(default)