parent
84551c9d1e
commit
e07c00a592
|
@ -8,7 +8,6 @@ if os.name == 'posix' and 'DISPLAY' not in os.environ:
|
|||
mpl.use('Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import cm
|
||||
|
||||
from PIL import Image
|
||||
|
||||
import damask
|
||||
|
@ -169,11 +168,11 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
field : numpy 2D array
|
||||
field : np.array of shape(:,:)
|
||||
Data to be shaded.
|
||||
bounds : array, optional
|
||||
bounds : iterable of len(2), optional
|
||||
Lower and upper bound of value range.
|
||||
gap : scalar, optional
|
||||
gap : field.dtype, optional
|
||||
Transparent value. NaN will always be rendered transparent.
|
||||
|
||||
Returns
|
||||
|
@ -187,9 +186,10 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
np.logical_or (np.isnan(field), field == gap)) # mask gap and NaN (if gap present)
|
||||
|
||||
if bounds is None:
|
||||
bounds = [field[mask].min(),
|
||||
field[mask].max()]
|
||||
hi,lo = max(bounds),min(bounds)
|
||||
hi,lo = field[mask].min(),field[mask].max()
|
||||
else:
|
||||
hi,lo = bounds[::-1]
|
||||
|
||||
delta,avg = hi-lo,0.5*(hi+lo)
|
||||
|
||||
if delta * 1e8 <= avg: # delta around numerical noise
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 143 B |
|
@ -4,6 +4,8 @@ import time
|
|||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from PIL import Image
|
||||
from PIL import ImageChops
|
||||
|
||||
import damask
|
||||
from damask import Colormap
|
||||
|
@ -129,6 +131,16 @@ class TestColormap:
|
|||
c += c
|
||||
assert (np.allclose(c.colors[:len(c.colors)//2],c.colors[len(c.colors)//2:]))
|
||||
|
||||
def test_shade(self,reference_dir,update):
|
||||
data = np.add(*np.indices((10, 11)))
|
||||
img_current = Colormap.from_predefined('orientation').shade(data)
|
||||
if update:
|
||||
img_current.save(reference_dir/'shade.png')
|
||||
else:
|
||||
img_reference = Image.open(reference_dir/'shade.png')
|
||||
diff = ImageChops.difference(img_reference.convert('RGB'),img_current.convert('RGB'))
|
||||
assert not diff.getbbox()
|
||||
|
||||
def test_list(self):
|
||||
Colormap.list_predefined()
|
||||
|
||||
|
|
Loading…
Reference in New Issue