From 115e3dd4c73043b2c01c65a0797e8d4af09f9234 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 5 Apr 2021 16:32:28 +0200 Subject: [PATCH] simplified --- python/damask/_grid.py | 28 +++++++++++++++++----------- python/damask/_result.py | 2 +- python/damask/util.py | 24 ++---------------------- python/tests/test_Grid.py | 7 +++---- 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/python/damask/_grid.py b/python/damask/_grid.py index 200541cf5..5457643ee 100644 --- a/python/damask/_grid.py +++ b/python/damask/_grid.py @@ -81,26 +81,32 @@ 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 ")}')) - message.append(util.emph( f'size x y z: {util.srepr( self.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 ")}')) if not np.allclose(other.origin,self.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.deemph(f'origin x y z: {util.srepr(other.origin," ")}')) + message.append(util.emph( f'origin x y z: {util.srepr( self.origin," ")}')) if other.N_materials != self.N_materials: - message.append(util.deemph(f'# materials: {other.N_materials}')) - message.append(util.emph( f'# materials: { self.N_materials}')) + 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)}')) + 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 diff --git a/python/damask/_result.py b/python/damask/_result.py index 07b66f139..7cfe66c0b 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -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, diff --git a/python/damask/util.py b/python/damask/util.py index 904277852..3fe30320a 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -22,7 +22,6 @@ __all__=[ 'scale_to_coprime', 'project_stereographic', 'hybrid_IA', - 'return_message', 'execution_stamp', 'shapeshifter', 'shapeblender', 'extend_docstring', 'extended_docstring', @@ -64,7 +63,8 @@ def srepr(arg,glue = '\n'): (hasattr(arg, '__getitem__') or hasattr(arg, '__iter__'))): 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): @@ -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. diff --git a/python/tests/test_Grid.py b/python/tests/test_Grid.py index 24d48bd56..6ccd100fc 100644 --- a/python/tests/test_Grid.py +++ b/python/tests/test_Grid.py @@ -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)