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, def show(self,
colormap: Colormap = None) -> None: colormap: Union[Colormap, str] = None) -> None:
""" """
Show on screen. Show on screen.
Parameters Parameters
---------- ----------
colormap : damask.Colormap, optional colormap : damask.Colormap or str, optional
Colors used to map material IDs. Defaults to 'cividis'. Colormap for visualization of material IDs. Defaults to 'cividis'.
""" """
VTK.from_image_data(self.cells,self.size,self.origin) \ VTK.from_image_data(self.cells,self.size,self.origin) \

View File

@ -503,7 +503,7 @@ class VTK:
def show(self, def show(self,
label: str = None, label: str = None,
colormap: Colormap = None): colormap: Union[Colormap, str] = None):
""" """
Render. Render.
@ -511,8 +511,8 @@ class VTK:
---------- ----------
label : str, optional label : str, optional
Label of the dataset to show. Label of the dataset to show.
colormap : damask.Colormap, optional colormap : damask.Colormap or str, optional
Colormap for visualization of dataset. Colormap for visualization of dataset. Defaults to 'cividis'.
Notes Notes
----- -----
@ -535,7 +535,9 @@ class VTK:
height = 768 height = 768
lut = vtk.vtkLookupTable() 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)) lut.SetNumberOfTableValues(len(colormap_.colors))
for i,c in enumerate(colormap_.colors): for i,c in enumerate(colormap_.colors):
lut.SetTableValue(i,c if len(c)==4 else np.append(c,1.0)) 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 Grid
from damask import Table from damask import Table
from damask import Rotation from damask import Rotation
from damask import Colormap
from damask import util from damask import util
from damask import seeds from damask import seeds
from damask import grid_filters from damask import grid_filters
@ -42,9 +43,10 @@ class TestGrid:
print('patched datetime.datetime.now') 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) monkeypatch.delenv('DISPLAY',raising=False)
default.show() default.show(cmap)
def test_equal(self,default): def test_equal(self,default):
assert default == default assert default == default

View File

@ -10,6 +10,7 @@ import vtk
from damask import VTK from damask import VTK
from damask import Table from damask import Table
from damask import Colormap
@pytest.fixture @pytest.fixture
def ref_path(ref_path_base): def ref_path(ref_path_base):
@ -29,10 +30,10 @@ class TestVTK:
def _patch_execution_stamp(self, patch_execution_stamp): def _patch_execution_stamp(self, patch_execution_stamp):
print('patched damask.util.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) monkeypatch.delenv('DISPLAY',raising=False)
default.show() default.show(colormap=cmap)
def test_imageData(self,tmp_path): def test_imageData(self,tmp_path):
cells = np.random.randint(5,10,3) cells = np.random.randint(5,10,3)

View File

@ -81,7 +81,7 @@ subroutine discretization_grid_init(restart)
if (any(materialAt_global < 1)) & if (any(materialAt_global < 1)) &
call IO_error(180,ext_msg='material ID < 1') call IO_error(180,ext_msg='material ID < 1')
if (size(materialAt_global) /= product(cells)) & 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 fname = interface_geomFile
if (scan(fname,'/') /= 0) fname = fname(scan(fname,'/',.true.)+1:) if (scan(fname,'/') /= 0) fname = fname(scan(fname,'/',.true.)+1:)
call results_openJobFile(parallel=.false.) call results_openJobFile(parallel=.false.)