clarified colormap default; accept string as colormap name

This commit is contained in:
Philip Eisenlohr 2022-03-08 09:31:08 -05:00
parent fe8e55e470
commit 73f01c07d0
5 changed files with 18 additions and 13 deletions

View File

@ -688,14 +688,14 @@ class Grid:
def show(self,
colormap: Colormap = None) -> None:
colormap: Union[Colormap, str] = None) -> None:
"""
Show on screen.
Parameters
----------
colormap : damask.Colormap, optional
Colors used to map material IDs. Defaults to 'cividis'.
colormap : damask.Colormap or str, optional
Colormap for visualization of material IDs. Defaults to 'cividis'.
"""
VTK.from_image_data(self.cells,self.size,self.origin) \

View File

@ -503,7 +503,7 @@ class VTK:
def show(self,
label: str = None,
colormap: Colormap = None):
colormap: Union[Colormap, str] = None):
"""
Render.
@ -511,8 +511,8 @@ class VTK:
----------
label : str, optional
Label of the dataset to show.
colormap : damask.Colormap, optional
Colormap for visualization of dataset.
colormap : damask.Colormap or str, optional
Colormap for visualization of dataset. Defaults to 'cividis'.
Notes
-----
@ -535,7 +535,9 @@ class VTK:
height = 768
lut = vtk.vtkLookupTable()
colormap_ = Colormap.from_predefined('cividis') if colormap is None else colormap
colormap_ = Colormap.from_predefined('cividis') if colormap is None \
else Colormap.from_predefined(colormap) if isinstance(colormap,str) \
else colormap
lut.SetNumberOfTableValues(len(colormap_.colors))
for i,c in enumerate(colormap_.colors):
lut.SetTableValue(i,c if len(c)==4 else np.append(c,1.0))

View File

@ -6,6 +6,7 @@ from damask import VTK
from damask import Grid
from damask import Table
from damask import Rotation
from damask import Colormap
from damask import util
from damask import seeds
from damask import grid_filters
@ -42,9 +43,10 @@ class TestGrid:
print('patched datetime.datetime.now')
def test_show(sef,default,monkeypatch):
@pytest.mark.parametrize('cmap',[Colormap.from_predefined('cividis'),'cividis',None])
def test_show(sef,default,cmap,monkeypatch):
monkeypatch.delenv('DISPLAY',raising=False)
default.show()
default.show(cmap)
def test_equal(self,default):
assert default == default

View File

@ -10,6 +10,7 @@ import vtk
from damask import VTK
from damask import Table
from damask import Colormap
@pytest.fixture
def ref_path(ref_path_base):
@ -29,10 +30,10 @@ class TestVTK:
def _patch_execution_stamp(self, patch_execution_stamp):
print('patched damask.util.execution_stamp')
def test_show(sef,default,monkeypatch):
@pytest.mark.parametrize('cmap',[Colormap.from_predefined('cividis'),'cividis',None])
def test_show(sef,default,cmap,monkeypatch):
monkeypatch.delenv('DISPLAY',raising=False)
default.show()
default.show(colormap=cmap)
def test_imageData(self,tmp_path):
cells = np.random.randint(5,10,3)

View File

@ -81,7 +81,7 @@ subroutine discretization_grid_init(restart)
if (any(materialAt_global < 1)) &
call IO_error(180,ext_msg='material ID < 1')
if (size(materialAt_global) /= product(cells)) &
call IO_error(180,ext_msg='mismatch of material IDs and # cells')
call IO_error(180,ext_msg='mismatch in # of material IDs and cells')
fname = interface_geomFile
if (scan(fname,'/') /= 0) fname = fname(scan(fname,'/',.true.)+1:)
call results_openJobFile(parallel=.false.)