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,8 +81,8 @@ class Grid:
"""
message = []
if np.any(other.cells != self.cells):
message.append(util.deemph(f'cells a b c: {util.srepr(other.cells," x ")}'))
message.append(util.emph( f'cells a b c: {util.srepr( self.cells," x ")}'))
message.append(util.deemph(f'cells x y z: {util.srepr(other.cells," x ")}'))
message.append(util.emph( f'cells x y z: {util.srepr( self.cells," x ")}'))
if not np.allclose(other.size,self.size):
message.append(util.deemph(f'size x y z: {util.srepr(other.size," x ")}'))
@ -96,11 +96,17 @@ class Grid:
message.append(util.deemph(f'# materials: {other.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):
message.append(util.deemph(f'max material: {np.nanmax(other.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

View File

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

View File

@ -22,7 +22,6 @@ __all__=[
'scale_to_coprime',
'project_stereographic',
'hybrid_IA',
'return_message',
'execution_stamp',
'shapeshifter', 'shapeblender',
'extend_docstring', 'extended_docstring',
@ -64,6 +63,7 @@ def srepr(arg,glue = '\n'):
(hasattr(arg, '__getitem__') or
hasattr(arg, '__iter__'))):
return glue.join(str(x) for x in arg)
else:
return arg if isinstance(arg,str) else repr(arg)
@ -463,26 +463,6 @@ def dict_flatten(d):
####################################################################################################
# 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:
"""
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):
return np.all(a.material == b.material) and \
np.all(a.cells == b.cells) and \
np.allclose(a.size, b.size) and \
str(a.diff(b)) == str(b.diff(a))
np.allclose(a.size, b.size)
@pytest.fixture
def default():
@ -43,12 +42,12 @@ class TestGrid:
print('patched datetime.datetime.now')
def test_diff_equal(self,default):
assert str(default.diff(default)) == ''
assert not default.diff(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'])
assert str(default.diff(new)) != ''
assert default.diff(new)
def test_repr(self,default):
print(default)