From e779e190ea42ecbb05b55adc4f3dc3dd60e8c291 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 27 Jun 2020 16:01:16 +0200 Subject: [PATCH 01/28] new colormap class for use in python - based on matplotlib "ListedColormap" - constructors - Array of RGB values (inherited), - 'from_bounds': perceptual uniform colormap within given bounds - 'from_predefined': from matplotlib or DAMASK templates - export to files (WIP) - preview on screen --- processing/post/perceptualUniformColorMap.py | 75 --- python/damask/__init__.py | 2 +- python/damask/_colormap.py | 482 +++++++++++++++++ python/damask/_colormaps.py | 541 ------------------- python/tests/test_Colormap.py | 40 ++ 5 files changed, 523 insertions(+), 617 deletions(-) delete mode 100755 processing/post/perceptualUniformColorMap.py create mode 100644 python/damask/_colormap.py delete mode 100644 python/damask/_colormaps.py create mode 100644 python/tests/test_Colormap.py diff --git a/processing/post/perceptualUniformColorMap.py b/processing/post/perceptualUniformColorMap.py deleted file mode 100755 index 8e432536d..000000000 --- a/processing/post/perceptualUniformColorMap.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys -from optparse import OptionParser - -import damask - - -scriptName = os.path.splitext(os.path.basename(__file__))[0] -scriptID = ' '.join([scriptName,damask.version]) - - -# -------------------------------------------------------------------- -# MAIN -# -------------------------------------------------------------------- -#Borland, D., & Taylor, R. M. (2007). Rainbow Color Map (Still) Considered Harmful. Computer Graphics and Applications, IEEE, 27(2), 14--17. -#Moreland, K. (2009). Diverging Color Maps for Scientific Visualization. In Proc. 5th Int. Symp. Visual Computing (pp. 92--103). -outtypes = ['paraview','gmsh','raw','GOM'] -extensions = ['.json','.msh','.txt','.legend'] -colormodels = ['RGB','HSL','XYZ','CIELAB','MSH'] - -parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ -Produces perceptually linear diverging and sequential colormaps in formats suitable for visualization software -or simply as a list of interpolated colors. - -""", version = scriptID) - -parser.add_option('-N','--steps', dest='N', type='int', nargs=1, metavar='int', - help='number of interpolation steps [%default]') -parser.add_option('-t','--trim', dest='trim', type='float', nargs=2, metavar='float float', - help='relative trim of colormap range [%default]') -parser.add_option('-l','--left', dest='left', type='float', nargs=3, metavar='float float float', - help='left color [%default]') -parser.add_option('-r','--right', dest='right', type='float', nargs=3, metavar='float float float', - help='right color [%default]') -parser.add_option('-c','--colormodel', dest='colormodel', metavar='string', - help='colormodel: '+', '.join(colormodels)+' [%default]') -parser.add_option('-p','--predefined', dest='predefined', metavar='string', - help='predefined colormap') -parser.add_option('-f','--format', dest='format', metavar='string', - help='output format: '+', '.join(outtypes)+' [%default]') -parser.set_defaults(colormodel = 'RGB') -parser.set_defaults(predefined = None) -parser.set_defaults(basename = None) -parser.set_defaults(format = 'paraview') -parser.set_defaults(N = 10) -parser.set_defaults(trim = (-1.0,1.0)) -parser.set_defaults(left = (1.0,1.0,1.0)) -parser.set_defaults(right = (0.0,0.0,0.0)) - -(options,filename) = parser.parse_args() - -if options.format not in outtypes: - parser.error('invalid format: "{}" (choices: {}).'.format(options.format,', '.join(outtypes))) - -if options.N < 2: - parser.error('too few steps (need at least 2).') - -if options.trim[0] < -1.0 or \ - options.trim[1] > 1.0 or \ - options.trim[0] >= options.trim[1]: - parser.error('invalid trim range (-1 +1).') - -name = options.format if filename == [] \ - else filename[0] -output = sys.stdout if filename == [] \ - else open(os.path.basename(filename[0])+extensions[outtypes.index(options.format)],'w') - -colorLeft = damask.Color(options.colormodel.upper(), list(options.left)) -colorRight = damask.Color(options.colormodel.upper(), list(options.right)) -colormap = damask.Colormap(colorLeft, colorRight, predefined=options.predefined) - -output.write(colormap.export(name,options.format,options.N,list(options.trim))) -output.close() diff --git a/python/damask/__init__.py b/python/damask/__init__.py index 6d65f7cd1..b2b94b6a5 100644 --- a/python/damask/__init__.py +++ b/python/damask/__init__.py @@ -10,7 +10,7 @@ with open(_Path(__file__).parent/_Path('VERSION')) as _f: from ._environment import Environment # noqa from ._table import Table # noqa from ._vtk import VTK # noqa -from ._colormaps import Colormap, Color # noqa +from ._colormap import Colormap # noqa from ._rotation import Rotation # noqa from ._lattice import Symmetry, Lattice# noqa from ._orientation import Orientation # noqa diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py new file mode 100644 index 000000000..20b1a015f --- /dev/null +++ b/python/damask/_colormap.py @@ -0,0 +1,482 @@ +import json +import functools + +import numpy as np +import matplotlib as mpl +import matplotlib.pyplot as plt +from matplotlib import cm + +from damask import Table + +_eps = 216./24389. +_kappa = 24389./27. +_ref_white = np.array([.95047, 1.00000, 1.08883]) # Observer = 2, Illuminant = D65 + + +class Colormap(mpl.colors.ListedColormap): + + + @staticmethod + def from_bounds(low,high,N=256,name='DAMASK colormap',model='rgb'): + """ + Create a perceptually uniform colormap. + + Parameters + ---------- + low : numpy.ndarray of shape (3) + high : numpy.ndarray of shape (3) + N : integer, optional + Number of discrete color values. Defaults to 256. + model : str + Colormodel used for low and high. + + """ + low_,high_ = map(np.array,[low,high]) + if model.lower() == 'rgb': + # ToDo: Sanity check + low_,high_ = map(Colormap._rgb2msh,[low_,high_]) + elif model.lower() == 'hsv': + # ToDo: Sanity check + low_,high_ = map(Colormap._hsv2msh,[low_,high_]) + elif model.lower() == 'hsl': + # ToDo: Sanity check + low_,high_ = map(Colormap._hsl2msh,[low_,high_]) + elif model.lower() == 'xyz': + # ToDo: Sanity check + low_,high_ = map(Colormap._xyz2msh,[low_,high_]) + elif model.lower() == 'lab': + # ToDo: Sanity check + low_,high_ = map(Colormap._lab2msh,[low_,high_]) + elif model.lower() == 'msh': + # ToDo: Sanity check + pass + else: + raise ValueError(f'Invalid color model: {model}.') + + msh = map(functools.partial(Colormap._interpolate_msh,low=low_,high=high_),np.linspace(0,1,N)) + rgb = np.array(list(map(Colormap._msh2rgb,msh))) + + return Colormap(rgb,name=name) + + + @staticmethod + def from_predefined(name,N=256): + """ + Select from set of predefined colormaps. + + Predefined colormaps include matplotlib-native colormaps + and common DAMASK colormaps. + + Parameters + ---------- + name : str + N : int, optional + Number of discrete color values. Defaults to 256. + This parameter is not used for matplotlib colormaps + that are of type `ListedColormap`. + + """ + # matplotlib presets + for cat in Colormap._predefined_mpl: + for n in cat[1]: + if n == name: + colormap = cm.__dict__[name] + if isinstance(colormap,mpl.colors.LinearSegmentedColormap): + return Colormap(np.array(list(map(colormap,np.linspace(0,1,N)))),name=name) + else: + return Colormap(colormap.colors,name=name) + + # DAMASK presets + definition = Colormap._predefined_DAMASK[name] + return Colormap.from_bounds(definition['left'],definition['right'],N,name) + + + @staticmethod + def list_predefined(): + """List predefined colormaps by category.""" + print('DAMASK colormaps') + print(' '+', '.join(Colormap._predefined_DAMASK.keys())) + for cat in Colormap._predefined_mpl: + print(f'{cat[0]}') + print(' '+', '.join(cat[1])) + + + def show(self): + fig, ax = plt.subplots(figsize=(10,1)) + ax.set_axis_off() + im = ax.imshow(np.broadcast_to(np.linspace(0,1,640).reshape(1,-1),(64,640)),cmap=self) # noqa + fig.canvas.set_window_title(self.name) + plt.show() + + + def to_file(self,fname=None,format='paraview'): + if fname is not None: + try: + f = open(fname,'w') + except TypeError: + f = fname + else: + f = None + + if format.lower() == 'paraview': + Colormap._export_paraview(self,f) + elif format.lower() == 'ascii': + Colormap._export_ASCII(self,f) + + + @staticmethod + def _export_paraview(colormap,fhandle=None): + colors = [] + for i,c in enumerate(np.round(colormap.colors,6).tolist()): + colors+=[i]+c + + out = [{ + 'ColorSpace':'RGB', + 'Name':colormap.name, + 'DefaultMap':True, + 'RGBPoints':colors + }] + if fhandle is None: + with open(colormap.name.replace(' ','_')+'.json', 'w') as f: + json.dump(out, f,indent=4) + else: + json.dump(out,fhandle,indent=4) + + @staticmethod + def _export_ASCII(colormap,fhandle=None): + labels = {'R':(1,),'G':(1,),'B':(1,)} + if colormap.colors.shape[1] == 4: labels['alpha']=(1,) + + t = Table(colormap.colors,labels) + if fhandle is None: + with open(colormap.name.replace(' ','_')+'.txt', 'w') as f: + t.to_ASCII(f) + else: + t.to_ASCII(fhandle) + + @staticmethod + def _export_GOM(colormap,fhandle=None): + pass + # a = f'1 1 {name.replace(" ","_"} 9 {name.replace(" ","_"} ' + # f' 0 1 0 3 0 0 -1 9 \\ 0 0 0 255 255 255 0 0 255 ' + # f'30 NO_UNIT 1 1 64 64 64 255 1 0 0 0 0 0 0 3 0 ' + str(len(colors)) + # f' '.join([' 0 %s 255 1'%(' '.join([str(int(x*255.0)) for x in color])) for color in reversed(colors)])] + + @staticmethod + def _export_gmsh(colormap,fname=None): + colors = colormap.colors + colormap = ['View.ColorTable = {'] \ + + [',\n'.join(['{%s}'%(','.join([str(x*255.0) for x in color])) for color in colors])] \ + + ['}'] + + @staticmethod + def _interpolate_msh(frac,low, high): + + def rad_diff(a,b): + return abs(a[2]-b[2]) + + def adjust_hue(msh_sat, msh_unsat): + """If saturation of one of the two colors is much less than the other, hue of the less.""" + if msh_sat[0] >= msh_unsat[0]: + return msh_sat[2] + else: + hSpin = msh_sat[1]/np.sin(msh_sat[1])*np.sqrt(msh_unsat[0]**2.0-msh_sat[0]**2)/msh_sat[0] + if msh_sat[2] < - np.pi/3.0: hSpin *= -1.0 + return msh_sat[2] + hSpin + + + lo = np.array(low) + hi = np.array(high) + + if (lo[1] > 0.05 and hi[1] > 0.05 and rad_diff(lo,hi) > np.pi/3.0): + M_mid = max(lo[0],hi[0],88.0) + if frac < 0.5: + hi = np.array([M_mid,0.0,0.0]) + frac *= 2.0 + else: + lo = np.array([M_mid,0.0,0.0]) + frac = 2.0*frac - 1.0 + if lo[1] < 0.05 and hi[1] > 0.05: + lo[2] = adjust_hue(hi,lo) + elif lo[1] > 0.05 and hi[1] < 0.05: + hi[2] = adjust_hue(lo,hi) + + return (1.0 - frac) * lo + frac * hi + + + _predefined_mpl= [('Perceptually Uniform Sequential', [ + 'viridis', 'plasma', 'inferno', 'magma', 'cividis']), + ('Sequential', [ + 'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', + 'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', + 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']), + ('Sequential (2)', [ + 'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink', + 'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia', + 'hot', 'afmhot', 'gist_heat', 'copper']), + ('Diverging', [ + 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', + 'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']), + ('Cyclic', ['twilight', 'twilight_shifted', 'hsv']), + ('Qualitative', [ + 'Pastel1', 'Pastel2', 'Paired', 'Accent', + 'Dark2', 'Set1', 'Set2', 'Set3', + 'tab10', 'tab20', 'tab20b', 'tab20c']), + ('Miscellaneous', [ + 'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern', + 'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', + 'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])] + + _predefined_DAMASK = {'orientation': {'low': [0.933334,0.878432,0.878431], + 'right': [0.250980,0.007843,0.000000]}, + 'strain': {'left': [0.941177,0.941177,0.870588], + 'right': [0.266667,0.266667,0.000000]}, + 'stress': {'left': [0.878432,0.874511,0.949019], + 'right': [0.000002,0.000000,0.286275]}} + + @staticmethod + def _hsv2rgb(hsv): + """ + H(ue) S(aturation) V(alue) to R(red) G(reen) B(lue). + + References + ---------- + https://www.rapidtables.com/convert/color/hsv-to-rgb.html + + """ + sextant = np.clip(int(hsv[0]/60.),0,5) + c = hsv[1]*hsv[2] + x = c*(1.0 - abs((hsv[0]/60.)%2 - 1.)) + + return np.array([ + [c, x, 0], + [x, c, 0], + [0, c, x], + [0, x, c], + [x, 0, c], + [c, 0, x], + ])[sextant] + hsv[2] - c + + @staticmethod + def _rgb2hsv(rgb): + """ + R(ed) G(reen) B(lue) to H(ue) S(aturation) V(alue). + + References + ---------- + https://www.rapidtables.com/convert/color/rgb-to-hsv.html + + """ + C_max = rgb.max() + C_min = rgb.min() + Delta = C_max - C_min + + v = C_max + s = 0. if np.isclose(C_max,0.) else Delta/C_max + if np.isclose(Delta,0.): + h = 0. + elif rgb.argmax() == 0: + h = (rgb[1]-rgb[2])/Delta%6 + elif rgb.argmax() == 1: + h = (rgb[2]-rgb[0])/Delta + 2. + elif rgb.argmax() == 2: + h = (rgb[0]-rgb[1])/Delta + 4. + + h = np.clip(h,0.,6.) * 60. + + return np.array([h,s,v]) + + + @staticmethod + def _hsl2rgb(hsl): + """ + H(ue) S(aturation) L(uminance) to R(red) G(reen) B(lue). + + References + ---------- + https://www.rapidtables.com/convert/color/hsl-to-rgb.html + + """ + sextant = np.clip(int(hsl[0]/60.),0,5) + c = (1.0 - abs(2.0 * hsl[2] - 1.))*hsl[1] + x = c*(1.0 - abs((hsl[0]/60.)%2 - 1.)) + m = hsl[2] - 0.5*c + + return np.array([ + [c+m, x+m, m], + [x+m, c+m, m], + [m, c+m, x+m], + [m, x+m, c+m], + [x+m, m, c+m], + [c+m, m, x+m], + ])[sextant] + + @staticmethod + def _rgb2hsl(rgb): + """ + R(ed) G(reen) B(lue) to H(ue) S(aturation) L(uminance). + + References + ---------- + https://www.rapidtables.com/convert/color/rgb-to-hsl.html + + """ + C_max = rgb.max() + C_min = rgb.min() + Delta = C_max - C_min + + l = np.clip((C_max + C_min)*.5,0.,1.) # noqa + s = 0. if np.isclose(C_max,C_min) else Delta/(1.-np.abs(2*l-1.)) + if np.isclose(Delta,0.): + h = 0. + elif rgb.argmax() == 0: + h = (rgb[1]-rgb[2])/Delta%6 + elif rgb.argmax() == 1: + h = (rgb[2]-rgb[0])/Delta + 2. + elif rgb.argmax() == 2: + h = (rgb[0]-rgb[1])/Delta + 4. + + h = np.clip(h,0.,6.) * 60. + + return np.array([h,s,l]) + + + @staticmethod + def _xyz2rgb(xyz): + """ + CIE Xyz to R(ed) G(reen) B(lue). + + References + ---------- + http://www.ryanjuckett.com/programming/rgb-color-space-conversion + + """ + rgb_lin = np.dot(np.array([ + [ 3.240969942,-1.537383178,-0.498610760], + [-0.969243636, 1.875967502, 0.041555057], + [ 0.055630080,-0.203976959, 1.056971514] + ]),xyz) + with np.errstate(invalid='ignore'): + rgb = np.where(rgb_lin>0.0031308,rgb_lin**(1.0/2.4)*1.0555-0.0555,rgb_lin*12.92) + + return np.clip(rgb,0.,1.) + + @staticmethod + def _rgb2xyz(rgb): + """ + R(ed) G(reen) B(lue) to CIE Xyz. + + References + ---------- + http://www.ryanjuckett.com/programming/rgb-color-space-conversion + + """ + rgb_lin = np.where(rgb>0.04045,((rgb+0.0555)/1.0555)**2.4,rgb/12.92) + return np.dot(np.array([ + [0.412390799,0.357584339,0.180480788], + [0.212639006,0.715168679,0.072192315], + [0.019330819,0.119194780,0.950532152] + ]),rgb_lin) + + + @staticmethod + def _lab2xyz(lab,ref_white=None): + """ + CIE Lab to CIE Xyz. + + References + ---------- + http://www.brucelindbloom.com/index.html?Eqn_Lab_to_XYZ.html + + """ + f_x = (lab[0]+16.)/116. + lab[1]/500. + f_z = (lab[0]+16.)/116. - lab[2]/200. + + return np.array([ + f_x**3. if f_x**3. > _eps else (116.*f_x-16.)/_kappa, + ((lab[0]+16.)/116.)**3 if lab[0]>_kappa*_eps else lab[0]/_kappa, + f_z**3. if f_z**3. > _eps else (116.*f_z-16.)/_kappa + ])*(ref_white if ref_white is not None else _ref_white) + + @staticmethod + def _xyz2lab(xyz,ref_white=None): + """ + CIE Xyz to CIE Lab. + + References + ---------- + http://www.brucelindbloom.com/index.html?Eqn_Lab_to_XYZ.html + + """ + ref_white = ref_white if ref_white is not None else _ref_white + f = np.where(xyz/ref_white > _eps,(xyz/ref_white)**(1./3.),(_kappa*xyz/ref_white+16.)/116.) + + return np.array([ + 116.0 * f[1] - 16.0, + 500.0 * (f[0] - f[1]), + 200.0 * (f[1] - f[2]) + ]) + + + @staticmethod + def _lab2msh(lab): + """ + CIE Lab to Msh. + + References + ---------- + https://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf + https://www.kennethmoreland.com/color-maps/diverging_map.py + + """ + M = np.linalg.norm(lab) + return np.array([ + M, + np.arccos(lab[0]/M) if M>1e-8 else 0., + np.arctan2(lab[2],lab[1]) if M>1e-8 else 0., + ]) + + @staticmethod + def _msh2lab(msh): + """ + Msh to CIE Lab. + + References + ---------- + https://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf + https://www.kennethmoreland.com/color-maps/diverging_map.py + + """ + return np.array([ + msh[0] * np.cos(msh[1]), + msh[0] * np.sin(msh[1]) * np.cos(msh[2]), + msh[0] * np.sin(msh[1]) * np.sin(msh[2]) + ]) + + @staticmethod + def _lab2rgb(lab): + return Colormap._xyz2rgb(Colormap._lab2xyz(lab)) + + @staticmethod + def _rgb2lab(rgb): + return Colormap._xyz2lab(Colormap._rgb2xyz(rgb)) + + @staticmethod + def _msh2rgb(msh): + return Colormap._lab2rgb(Colormap._msh2lab(msh)) + + @staticmethod + def _rgb2msh(rgb): + return Colormap._lab2msh(Colormap._rgb2lab(rgb)) + + @staticmethod + def _hsv2msh(hsv): + return Colormap._rgb2msh(Colormap._hsv2rgb(hsv)) + + @staticmethod + def _hsl2msh(hsl): + return Colormap._rgb2msh(Colormap._hsl2rgb(hsl)) + + @staticmethod + def _xyz2msh(xyz): + return Colormap._lab2msh(Colormap._xyz2lab(xyz)) diff --git a/python/damask/_colormaps.py b/python/damask/_colormaps.py deleted file mode 100644 index 6c6f82604..000000000 --- a/python/damask/_colormaps.py +++ /dev/null @@ -1,541 +0,0 @@ -import numpy as np -from . import util - -class Color: - """Color representation in and conversion between different color-spaces.""" - - __slots__ = [ - 'model', - 'color', - '__dict__', - ] - - - def __init__(self, - model = 'RGB', - color = np.zeros(3)): - """ - Create a Color object. - - Parameters - ---------- - model : string - color model - color : numpy.ndarray - vector representing the color according to the selected model - - """ - self.__transforms__ = \ - {'HSV': {'index': 0, 'next': self._HSV2HSL}, - 'HSL': {'index': 1, 'next': self._HSL2RGB, 'prev': self._HSL2HSV}, - 'RGB': {'index': 2, 'next': self._RGB2XYZ, 'prev': self._RGB2HSL}, - 'XYZ': {'index': 3, 'next': self._XYZ2CIELAB, 'prev': self._XYZ2RGB}, - 'CIELAB': {'index': 4, 'next': self._CIELAB2MSH, 'prev': self._CIELAB2XYZ}, - 'MSH': {'index': 5, 'prev': self._MSH2CIELAB}, - } - - model = model.upper() - if model not in list(self.__transforms__.keys()): model = 'RGB' - if model == 'RGB' and max(color) > 1.0: # are we RGB255 ? - for i in range(3): - color[i] /= 255.0 # rescale to RGB - - if model == 'HSL': # are we HSL ? - if abs(color[0]) > 1.0: color[0] /= 360.0 # with angular hue? - while color[0] >= 1.0: color[0] -= 1.0 # rewind to proper range - while color[0] < 0.0: color[0] += 1.0 # rewind to proper range - - self.model = model - self.color = np.array(color,'d') - - - def __repr__(self): - """Color model and values.""" - return 'Model: %s Color: %s'%(self.model,str(self.color)) - - - def __str__(self): - """Color model and values.""" - return self.__repr__() - - - def convert_to(self,toModel = 'RGB'): - """ - Change the color model permanently. - - Parameters - ---------- - toModel : string - color model - - """ - toModel = toModel.upper() - if toModel not in list(self.__transforms__.keys()): return - - sourcePos = self.__transforms__[self.model]['index'] - targetPos = self.__transforms__[toModel]['index'] - - while sourcePos < targetPos: - self.__transforms__[self.model]['next']() - sourcePos += 1 - - while sourcePos > targetPos: - self.__transforms__[self.model]['prev']() - sourcePos -= 1 - return self - - - def express_as(self,asModel = 'RGB'): - """ - Return the color in a different model. - - Parameters - ---------- - asModel : string - color model - - """ - return self.__class__(self.model,self.color).convert_to(asModel) - - - def _HSV2HSL(self): - """ - Convert H(ue) S(aturation) V(alue or brightness) to H(ue) S(aturation) L(uminance). - - All values are in the range [0,1] - http://codeitdown.com/hsl-hsb-hsv-color - """ - if self.model != 'HSV': return - - converted = Color('HSL',np.array([ - self.color[0], - 1. if self.color[2] == 0.0 or (self.color[1] == 0.0 and self.color[2] == 1.0) \ - else self.color[1]*self.color[2]/(1.-abs(self.color[2]*(2.-self.color[1])-1.)), - 0.5*self.color[2]*(2.-self.color[1]), - ])) - - self.model = converted.model - self.color = converted.color - - - def _HSL2HSV(self): - """ - Convert H(ue) S(aturation) L(uminance) to H(ue) S(aturation) V(alue or brightness). - - All values are in the range [0,1] - http://codeitdown.com/hsl-hsb-hsv-color - """ - if self.model != 'HSL': return - - h = self.color[0] - b = self.color[2]+0.5*(self.color[1]*(1.-abs(2*self.color[2]-1))) - s = 1.0 if b == 0.0 else 2.*(b-self.color[2])/b - - converted = Color('HSV',np.array([h,s,b])) - - self.model = converted.model - self.color = converted.color - - - def _HSL2RGB(self): - """ - Convert H(ue) S(aturation) L(uminance) to R(red) G(reen) B(lue). - - All values are in the range [0,1] - from http://en.wikipedia.org/wiki/HSL_and_HSV - """ - if self.model != 'HSL': return - - sextant = self.color[0]*6.0 - c = (1.0 - abs(2.0 * self.color[2] - 1.0))*self.color[1] - x = c*(1.0 - abs(sextant%2 - 1.0)) - m = self.color[2] - 0.5*c - - converted = Color('RGB',np.array([ - [c+m, x+m, m], - [x+m, c+m, m], - [m, c+m, x+m], - [m, x+m, c+m], - [x+m, m, c+m], - [c+m, m, x+m], - ][int(sextant)])) - self.model = converted.model - self.color = converted.color - - - def _RGB2HSL(self): - """ - Convert R(ed) G(reen) B(lue) to H(ue) S(aturation) L(uminance). - - All values are in the range [0,1] - from http://130.113.54.154/~monger/hsl-rgb.html - """ - if self.model != 'RGB': return - - HSL = np.zeros(3) - maxcolor = self.color.max() - mincolor = self.color.min() - HSL[2] = (maxcolor + mincolor)/2.0 - if(mincolor == maxcolor): - HSL[0] = 0.0 - HSL[1] = 0.0 - else: - if (HSL[2]<0.5): - HSL[1] = (maxcolor - mincolor)/(maxcolor + mincolor) - else: - HSL[1] = (maxcolor - mincolor)/(2.0 - maxcolor - mincolor) - if (maxcolor == self.color[0]): - HSL[0] = 0.0 + (self.color[1] - self.color[2])/(maxcolor - mincolor) - elif (maxcolor == self.color[1]): - HSL[0] = 2.0 + (self.color[2] - self.color[0])/(maxcolor - mincolor) - elif (maxcolor == self.color[2]): - HSL[0] = 4.0 + (self.color[0] - self.color[1])/(maxcolor - mincolor) - HSL[0] = HSL[0]*60.0 # scaling to 360 might be dangerous for small values - if (HSL[0] < 0.0): - HSL[0] = HSL[0] + 360.0 - HSL[1:] = np.clip(HSL[1:],0.0,1.0) - - converted = Color('HSL', HSL) - self.model = converted.model - self.color = converted.color - - - def _RGB2XYZ(self): - """ - Convert R(ed) G(reen) B(lue) to CIE XYZ. - - All values are in the range [0,1] - from http://www.cs.rit.edu/~ncs/color/t_convert.html - """ - if self.model != 'RGB': return - - XYZ = np.zeros(3) - RGB_lin = np.zeros(3) - convert = np.array([[0.412453,0.357580,0.180423], - [0.212671,0.715160,0.072169], - [0.019334,0.119193,0.950227]]) - - for i in range(3): - if (self.color[i] > 0.04045): RGB_lin[i] = ((self.color[i]+0.0555)/1.0555)**2.4 - else: RGB_lin[i] = self.color[i] /12.92 - XYZ = np.dot(convert,RGB_lin) - XYZ = np.clip(XYZ,0.0,None) - - converted = Color('XYZ', XYZ) - self.model = converted.model - self.color = converted.color - - - def _XYZ2RGB(self): - """ - Convert CIE XYZ to R(ed) G(reen) B(lue). - - All values are in the range [0,1] - from http://www.cs.rit.edu/~ncs/color/t_convert.html - """ - if self.model != 'XYZ': return - - convert = np.array([[ 3.240479,-1.537150,-0.498535], - [-0.969256, 1.875992, 0.041556], - [ 0.055648,-0.204043, 1.057311]]) - RGB_lin = np.dot(convert,self.color) - RGB = np.zeros(3) - - for i in range(3): - if (RGB_lin[i] > 0.0031308): RGB[i] = ((RGB_lin[i])**(1.0/2.4))*1.0555-0.0555 - else: RGB[i] = RGB_lin[i] *12.92 - - RGB = np.clip(RGB,0.0,1.0) - - maxVal = max(RGB) # clipping colors according to the display gamut - if (maxVal > 1.0): RGB /= maxVal - - converted = Color('RGB', RGB) - self.model = converted.model - self.color = converted.color - - - def _CIELAB2XYZ(self): - """ - Convert CIE Lab to CIE XYZ. - - All values are in the range [0,1] - from http://www.easyrgb.com/index.php?X=MATH&H=07#text7 - """ - if self.model != 'CIELAB': return - - ref_white = np.array([.95047, 1.00000, 1.08883]) # Observer = 2, Illuminant = D65 - XYZ = np.zeros(3) - - XYZ[1] = (self.color[0] + 16.0 ) / 116.0 - XYZ[0] = XYZ[1] + self.color[1]/ 500.0 - XYZ[2] = XYZ[1] - self.color[2]/ 200.0 - - for i in range(len(XYZ)): - if (XYZ[i] > 6./29. ): XYZ[i] = XYZ[i]**3. - else: XYZ[i] = 108./841. * (XYZ[i] - 4./29.) - - converted = Color('XYZ', XYZ*ref_white) - self.model = converted.model - self.color = converted.color - - - def _XYZ2CIELAB(self): - """ - Convert CIE XYZ to CIE Lab. - - All values are in the range [0,1] - from http://en.wikipedia.org/wiki/Lab_color_space, - http://www.cs.rit.edu/~ncs/color/t_convert.html - """ - if self.model != 'XYZ': return - - ref_white = np.array([.95047, 1.00000, 1.08883]) # Observer = 2, Illuminant = D65 - XYZ = self.color/ref_white - - for i in range(len(XYZ)): - if (XYZ[i] > 216./24389 ): XYZ[i] = XYZ[i]**(1.0/3.0) - else: XYZ[i] = (841./108. * XYZ[i]) + 16.0/116.0 - - converted = Color('CIELAB', np.array([ 116.0 * XYZ[1] - 16.0, - 500.0 * (XYZ[0] - XYZ[1]), - 200.0 * (XYZ[1] - XYZ[2]) ])) - self.model = converted.model - self.color = converted.color - - - def _CIELAB2MSH(self): - """ - Convert CIE Lab to Msh colorspace. - - from http://www.cs.unm.edu/~kmorel/documents/ColorMaps/DivergingColorMapWorkshop.xls - """ - if self.model != 'CIELAB': return - - Msh = np.zeros(3) - Msh[0] = np.sqrt(np.dot(self.color,self.color)) - if (Msh[0] > 0.001): - Msh[1] = np.arccos(self.color[0]/Msh[0]) - if (self.color[1] != 0.0): - Msh[2] = np.arctan2(self.color[2],self.color[1]) - - converted = Color('MSH', Msh) - self.model = converted.model - self.color = converted.color - - - def _MSH2CIELAB(self): - """ - Convert Msh colorspace to CIE Lab. - - with s,h in radians - from http://www.cs.unm.edu/~kmorel/documents/ColorMaps/DivergingColorMapWorkshop.xls - """ - if self.model != 'MSH': return - - Lab = np.zeros(3) - Lab[0] = self.color[0] * np.cos(self.color[1]) - Lab[1] = self.color[0] * np.sin(self.color[1]) * np.cos(self.color[2]) - Lab[2] = self.color[0] * np.sin(self.color[1]) * np.sin(self.color[2]) - - converted = Color('CIELAB', Lab) - self.model = converted.model - self.color = converted.color - - -class Colormap: - """Perceptually uniform diverging or sequential colormap.""" - - __slots__ = [ - 'left', - 'right', - 'interpolate', - ] - __predefined__ = { - 'gray': {'left': Color('HSL',[0,1,1]), - 'right': Color('HSL',[0,0,0.15]), - 'interpolate': 'perceptualuniform'}, - 'grey': {'left': Color('HSL',[0,1,1]), - 'right': Color('HSL',[0,0,0.15]), - 'interpolate': 'perceptualuniform'}, - 'red': {'left': Color('HSL',[0,1,0.14]), - 'right': Color('HSL',[0,0.35,0.91]), - 'interpolate': 'perceptualuniform'}, - 'green': {'left': Color('HSL',[0.33333,1,0.14]), - 'right': Color('HSL',[0.33333,0.35,0.91]), - 'interpolate': 'perceptualuniform'}, - 'blue': {'left': Color('HSL',[0.66,1,0.14]), - 'right': Color('HSL',[0.66,0.35,0.91]), - 'interpolate': 'perceptualuniform'}, - 'seaweed': {'left': Color('HSL',[0.78,1.0,0.1]), - 'right': Color('HSL',[0.40000,0.1,0.9]), - 'interpolate': 'perceptualuniform'}, - 'bluebrown': {'left': Color('HSL',[0.65,0.53,0.49]), - 'right': Color('HSL',[0.11,0.75,0.38]), - 'interpolate': 'perceptualuniform'}, - 'redgreen': {'left': Color('HSL',[0.97,0.96,0.36]), - 'right': Color('HSL',[0.33333,1.0,0.14]), - 'interpolate': 'perceptualuniform'}, - 'bluered': {'left': Color('HSL',[0.65,0.53,0.49]), - 'right': Color('HSL',[0.97,0.96,0.36]), - 'interpolate': 'perceptualuniform'}, - 'blueredrainbow':{'left': Color('HSL',[2.0/3.0,1,0.5]), - 'right': Color('HSL',[0,1,0.5]), - 'interpolate': 'linear' }, - 'orientation': {'left': Color('RGB',[0.933334,0.878432,0.878431]), - 'right': Color('RGB',[0.250980,0.007843,0.000000]), - 'interpolate': 'perceptualuniform'}, - 'strain': {'left': Color('RGB',[0.941177,0.941177,0.870588]), - 'right': Color('RGB',[0.266667,0.266667,0.000000]), - 'interpolate': 'perceptualuniform'}, - 'stress': {'left': Color('RGB',[0.878432,0.874511,0.949019]), - 'right': Color('RGB',[0.000002,0.000000,0.286275]), - 'interpolate': 'perceptualuniform'}, - } - - - def __init__(self, - left = Color('RGB',[1,1,1]), - right = Color('RGB',[0,0,0]), - interpolate = 'perceptualuniform', - predefined = None - ): - """ - Create a Colormap object. - - Parameters - ---------- - left : Color - left color (minimum value) - right : Color - right color (maximum value) - interpolate : str - interpolation scheme (either 'perceptualuniform' or 'linear') - predefined : bool - ignore other arguments and use predefined definition - - """ - if predefined is not None: - left = self.__predefined__[predefined.lower()]['left'] - right= self.__predefined__[predefined.lower()]['right'] - interpolate = self.__predefined__[predefined.lower()]['interpolate'] - - if left.__class__.__name__ != 'Color': - left = Color() - if right.__class__.__name__ != 'Color': - right = Color() - - self.left = left - self.right = right - self.interpolate = interpolate - - - def __repr__(self): - """Left and right value of colormap.""" - return 'Left: %s Right: %s'%(self.left,self.right) - - - def invert(self): - """Switch left/minimum with right/maximum.""" - (self.left, self.right) = (self.right, self.left) - return self - - - def show_predefined(self): - """Show the labels of the predefined colormaps.""" - print('\n'.join(self.__predefined__.keys())) - - def color(self,fraction = 0.5): - - def interpolate_Msh(lo, hi, frac): - - def rad_diff(a,b): - return abs(a[2]-b[2]) - - def adjust_hue(Msh_sat, Msh_unsat): - """If saturation of one of the two colors is too less than the other, hue of the less.""" - if Msh_sat[0] >= Msh_unsat[0]: - return Msh_sat[2] - else: - hSpin = Msh_sat[1]/np.sin(Msh_sat[1])*np.sqrt(Msh_unsat[0]**2.0-Msh_sat[0]**2)/Msh_sat[0] - if Msh_sat[2] < - np.pi/3.0: hSpin *= -1.0 - return Msh_sat[2] + hSpin - - Msh1 = np.array(lo[:]) - Msh2 = np.array(hi[:]) - - if (Msh1[1] > 0.05 and Msh2[1] > 0.05 and rad_diff(Msh1,Msh2) > np.pi/3.0): - M_mid = max(Msh1[0],Msh2[0],88.0) - if frac < 0.5: - Msh2 = np.array([M_mid,0.0,0.0]) - frac *= 2.0 - else: - Msh1 = np.array([M_mid,0.0,0.0]) - frac = 2.0*frac - 1.0 - if Msh1[1] < 0.05 and Msh2[1] > 0.05: Msh1[2] = adjust_hue(Msh2,Msh1) - elif Msh1[1] > 0.05 and Msh2[1] < 0.05: Msh2[2] = adjust_hue(Msh1,Msh2) - Msh = (1.0 - frac) * Msh1 + frac * Msh2 - - return Color('MSH',Msh) - - def interpolate_linear(lo, hi, frac): - """Linear interpolation between lo and hi color at given fraction; output in model of lo color.""" - interpolation = (1.0 - frac) * np.array(lo.color[:]) \ - + frac * np.array(hi.express_as(lo.model).color[:]) - - return Color(lo.model,interpolation) - - if self.interpolate == 'perceptualuniform': - return interpolate_Msh(self.left.express_as('MSH').color, - self.right.express_as('MSH').color,fraction) - elif self.interpolate == 'linear': - return interpolate_linear(self.left,self.right,fraction) - else: - raise NameError('unknown color interpolation method') - - - def export(self,name = 'uniformPerceptualColorMap',\ - format = 'paraview',\ - steps = 2,\ - crop = [-1.0,1.0], - model = 'RGB'): - """ - [RGB] colormap for use in paraview or gmsh, or as raw string, or array. - - Arguments: name, format, steps, crop. - Format is one of (paraview, gmsh, gom, raw, list). - Crop selects a (sub)range in [-1.0,1.0]. - Generates sequential map if one limiting color is either white or black, - diverging map otherwise. - """ - format = format.lower() # consistent comparison basis - frac = 0.5*(np.array(crop) + 1.0) # rescale crop range to fractions - colors = [self.color(float(i)/(steps-1)*(frac[1]-frac[0])+frac[0]).express_as(model).color for i in range(steps)] - if format == 'paraview': - colormap = [f'[\n {{\n "ColorSpace": "RGB", "Name": "{name}", "DefaultMap": true,\n "RGBPoints" : ['] \ - + [f' {i:4d},{color[0]:8.6f},{color[1]:8.6f},{color[2]:8.6f}{"," if i+1 Date: Sat, 27 Jun 2020 16:25:10 +0200 Subject: [PATCH 02/28] reverse should return DAMASK colormap --- python/damask/_colormap.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 20b1a015f..ded6a32a0 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -123,6 +123,11 @@ class Colormap(mpl.colors.ListedColormap): elif format.lower() == 'ascii': Colormap._export_ASCII(self,f) + def reversed(self): + rev = super(Colormap,self).reversed() + return Colormap(rev.colors,rev.name) + + @staticmethod def _export_paraview(colormap,fhandle=None): From cf6322672147580f3923d60a95134189664a4f89 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 27 Jun 2020 18:55:27 +0200 Subject: [PATCH 03/28] testing all conversions --- python/tests/test_Colormap.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index daeeaf775..d3cbcaacd 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -21,10 +21,14 @@ class TestColormap: print('rgb',rgb) # rgb2hsv2rgb - assert np.allclose(Colormap._hsv2rgb(Colormap._rgb2hsv(rgb)),rgb) + hsv = Colormap._rgb2hsv(rgb) + print('hsv',hsv) + assert np.allclose(Colormap._hsv2rgb(hsv),rgb) # rgb2hsl2rgb - assert np.allclose(Colormap._hsl2rgb(Colormap._rgb2hsl(rgb)),rgb) + hsl = Colormap._rgb2hsl(rgb) + print('hsl',hsl) + assert np.allclose(Colormap._hsl2rgb(hsl),rgb) # rgb2xyz2rgb xyz = Colormap._rgb2xyz(rgb) @@ -37,4 +41,21 @@ class TestColormap: assert np.allclose(Colormap._lab2xyz(lab),xyz) # lab2msh2lab - assert np.allclose(Colormap._msh2lab(Colormap._lab2msh(lab)),lab) + msh = Colormap._lab2msh(lab) + print('msh',msh) + assert np.allclose(Colormap._msh2lab(msh),lab) + + # lab2rgb2lab + assert np.allclose(Colormap._rgb2lab(Colormap._lab2rgb(lab)),lab,atol=1.e-6,rtol=0) + + # rgb2msh2rgb + assert np.allclose(Colormap._msh2rgb(Colormap._rgb2msh(rgb)),rgb,atol=1.e-6,rtol=0) + + # hsv2msh + assert np.allclose(Colormap._hsv2msh(hsv),msh,atol=1.e-6,rtol=0) + + # hsl2msh + assert np.allclose(Colormap._hsv2msh(hsv),msh,atol=1.e-6,rtol=0) + + # xyz2msh + assert np.allclose(Colormap._xyz2msh(xyz),msh,atol=1.e-6,rtol=0) From c929af12c0e33b25fa6b60fb7fd3ecee7002d6dc Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 27 Jun 2020 19:43:35 +0200 Subject: [PATCH 04/28] testing/polishing --- python/damask/_colormap.py | 93 +++++++++++++++++++++++++---------- python/tests/test_Colormap.py | 53 +++++++++++++++++++- 2 files changed, 119 insertions(+), 27 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index ded6a32a0..9b707d00a 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -17,7 +17,7 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod - def from_bounds(low,high,N=256,name='DAMASK colormap',model='rgb'): + def from_bounds(low,high,name='DAMASK colormap',N=256,model='rgb'): """ Create a perceptually uniform colormap. @@ -26,30 +26,46 @@ class Colormap(mpl.colors.ListedColormap): low : numpy.ndarray of shape (3) high : numpy.ndarray of shape (3) N : integer, optional - Number of discrete color values. Defaults to 256. + The number of color quantization levels. + name : str, optional + The name of the colormap. Defaults to `DAMASK colormap`. model : str Colormodel used for low and high. """ low_,high_ = map(np.array,[low,high]) + low_high = np.vstack((low_,high)) if model.lower() == 'rgb': - # ToDo: Sanity check + if np.any(low_high<0) or np.any(low_high>1): + raise ValueError(f'RGB color out of range {low} {high}.') + low_,high_ = map(Colormap._rgb2msh,[low_,high_]) + elif model.lower() == 'hsv': - # ToDo: Sanity check + if np.any(low_high<0) or np.any(low_high[:,1:3]>1) or np.any(low_high[:,0]>360): + raise ValueError(f'HSV color out of range {low} {high}.') + low_,high_ = map(Colormap._hsv2msh,[low_,high_]) + elif model.lower() == 'hsl': - # ToDo: Sanity check + if np.any(low_high<0) or np.any(low_high[:,1:3]>1) or np.any(low_high[:,0]>360): + raise ValueError(f'HSL color out of range {low} {high}.') + low_,high_ = map(Colormap._hsl2msh,[low_,high_]) + elif model.lower() == 'xyz': - # ToDo: Sanity check + low_,high_ = map(Colormap._xyz2msh,[low_,high_]) + elif model.lower() == 'lab': - # ToDo: Sanity check + if np.any(low_high[:,0]<0): + raise ValueError(f'CIE Lab color out of range {low} {high}.') + low_,high_ = map(Colormap._lab2msh,[low_,high_]) + elif model.lower() == 'msh': - # ToDo: Sanity check pass + else: raise ValueError(f'Invalid color model: {model}.') @@ -64,14 +80,15 @@ class Colormap(mpl.colors.ListedColormap): """ Select from set of predefined colormaps. - Predefined colormaps include matplotlib-native colormaps + Predefined colormaps include native matplotlib colormaps and common DAMASK colormaps. Parameters ---------- name : str + The name of the colormap. N : int, optional - Number of discrete color values. Defaults to 256. + The number of color quantization levels. Defaults to 256. This parameter is not used for matplotlib colormaps that are of type `ListedColormap`. @@ -84,11 +101,11 @@ class Colormap(mpl.colors.ListedColormap): if isinstance(colormap,mpl.colors.LinearSegmentedColormap): return Colormap(np.array(list(map(colormap,np.linspace(0,1,N)))),name=name) else: - return Colormap(colormap.colors,name=name) + return Colormap(np.array(colormap.colors),name=name) # DAMASK presets definition = Colormap._predefined_DAMASK[name] - return Colormap.from_bounds(definition['left'],definition['right'],N,name) + return Colormap.from_bounds(definition['left'],definition['right'],name,N) @staticmethod @@ -102,6 +119,7 @@ class Colormap(mpl.colors.ListedColormap): def show(self): + """Show colormap in window.""" fig, ax = plt.subplots(figsize=(10,1)) ax.set_axis_off() im = ax.imshow(np.broadcast_to(np.linspace(0,1,640).reshape(1,-1),(64,640)),cmap=self) # noqa @@ -109,6 +127,26 @@ class Colormap(mpl.colors.ListedColormap): plt.show() + def reversed(self,name=None): + """ + Make a reversed instance of the Colormap. + + Parameters + ---------- + name : str, optional + The name for the reversed colormap. If it's None + the name will be the name of the parent colormap + "_r". + + Returns + ------- + damask.Colormap + The reversed colormap. + + """ + rev = super(Colormap,self).reversed(name) + return Colormap(rev.colors,rev.name) + + def to_file(self,fname=None,format='paraview'): if fname is not None: try: @@ -122,15 +160,16 @@ class Colormap(mpl.colors.ListedColormap): Colormap._export_paraview(self,f) elif format.lower() == 'ascii': Colormap._export_ASCII(self,f) - - def reversed(self): - rev = super(Colormap,self).reversed() - return Colormap(rev.colors,rev.name) - - + elif format.lower() == 'gom': + Colormap._export_GOM(self,f) + elif format.lower() == 'gmsh': + Colormap._export_gmsh(self,f) + else: + raise ValueError('Unknown output format: {format}.') @staticmethod def _export_paraview(colormap,fhandle=None): + """Write colormap to JSON file for Paraview.""" colors = [] for i,c in enumerate(np.round(colormap.colors,6).tolist()): colors+=[i]+c @@ -149,10 +188,11 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def _export_ASCII(colormap,fhandle=None): + """Write colormap to ASCII table.""" labels = {'R':(1,),'G':(1,),'B':(1,)} if colormap.colors.shape[1] == 4: labels['alpha']=(1,) - t = Table(colormap.colors,labels) + if fhandle is None: with open(colormap.name.replace(' ','_')+'.txt', 'w') as f: t.to_ASCII(f) @@ -162,17 +202,18 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def _export_GOM(colormap,fhandle=None): pass - # a = f'1 1 {name.replace(" ","_"} 9 {name.replace(" ","_"} ' - # f' 0 1 0 3 0 0 -1 9 \\ 0 0 0 255 255 255 0 0 255 ' - # f'30 NO_UNIT 1 1 64 64 64 255 1 0 0 0 0 0 0 3 0 ' + str(len(colors)) - # f' '.join([' 0 %s 255 1'%(' '.join([str(int(x*255.0)) for x in color])) for color in reversed(colors)])] + s =(f'1 1 {colormap.name.replace(" ","_")} 9 {colormap.name.replace(" ","_")} ' + f' 0 1 0 3 0 0 -1 9 \\ 0 0 0 255 255 255 0 0 255 ' + f'30 NO_UNIT 1 1 64 64 64 255 1 0 0 0 0 0 0 3 0 {str(len(colormap.colors))}' + ' '.join([' 0 %s 255 1'%(' '.join([str(int(x*255.0)) for x in color])) for color in reversed(colormap.colors)])) + print(s) @staticmethod def _export_gmsh(colormap,fname=None): colors = colormap.colors - colormap = ['View.ColorTable = {'] \ - + [',\n'.join(['{%s}'%(','.join([str(x*255.0) for x in color])) for color in colors])] \ - + ['}'] + colormap =('View.ColorTable = {' + ',\n'.join(['{%s}'%(','.join([str(x*255.0) for x in color])) for color in colors])+\ + '}') @staticmethod def _interpolate_msh(frac,low, high): diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index d3cbcaacd..e00367452 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -1,4 +1,7 @@ +import os + import numpy as np +import pytest from damask import Colormap @@ -15,7 +18,7 @@ class TestColormap: [1.,0.,1.], [1.,1.,1.] ]) - rgbs = np.vstack((specials,np.random.rand(10000,3))) + rgbs = np.vstack((specials,np.random.rand(100,3))) pass # class not integrated for rgb in rgbs: print('rgb',rgb) @@ -59,3 +62,51 @@ class TestColormap: # xyz2msh assert np.allclose(Colormap._xyz2msh(xyz),msh,atol=1.e-6,rtol=0) + + + @pytest.mark.parametrize('format',['ASCII','paraview','GOM','gmsh']) + @pytest.mark.parametrize('model',['rgb','hsv','hsl','xyz','lab','msh']) + def test_from_bounds(self,model,format,tmpdir): + N = np.random.randint(2,256) + c = Colormap.from_bounds(np.random.rand(3),np.random.rand(3),model=model,N=N) + c.to_file(tmpdir/'color_out',format=format) + + @pytest.mark.parametrize('format',['ASCII','paraview','GOM','gmsh']) + @pytest.mark.parametrize('name',['strain','gnuplot','Greys','PRGn','viridis']) + def test_from_predefined(self,name,format,tmpdir): + N = np.random.randint(2,256) + c = Colormap.from_predefined(name,N) + os.chdir(tmpdir) + c.to_file(format=format) + + @pytest.mark.parametrize('format,name',[('ASCII','test.txt'), + ('paraview','test.json'), + ('GOM','test.legend'), + ('gmsh','test.xxx') + ]) + def test_write_filehandle(self,format,name,tmpdir): + c = Colormap.from_predefined('Dark2') + with open(tmpdir/name,'w') as f: + c.to_file(f,format=format) + + def test_invalid_format(self): + c = Colormap.from_predefined('Dark2') + with pytest.raises(ValueError): + c.to_file(format='invalid') + + @pytest.mark.parametrize('model',['rgb','hsv','hsl','lab','invalid']) + def test_invalid_color(self,model): + with pytest.raises(ValueError): + c = Colormap.from_bounds(-2.+np.random.rand(3),np.random.rand(3),N=10,model=model) # noqa + + def test_reversed(self): + c_1 = Colormap.from_predefined('stress') + c_2 = c_1.reversed() + assert (not np.allclose(c_1.colors,c_2.colors)) and \ + np.allclose(c_1.colors,c_2.reversed().colors) + + def test_list(self): + c = Colormap.from_predefined('afmhot').reversed() + c.list_predefined() + + From d965d663195c57824e298e33f1f5fabc29d9494c Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 28 Jun 2020 09:32:10 +0200 Subject: [PATCH 05/28] [skip ci] documenting --- python/damask/_colormap.py | 57 +++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 9b707d00a..a0c976516 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -12,6 +12,9 @@ _eps = 216./24389. _kappa = 24389./27. _ref_white = np.array([.95047, 1.00000, 1.08883]) # Observer = 2, Illuminant = D65 +# ToDo (if needed) +# - support alpha channel (paraview/ASCII/input) +# - support NaN color (paraview) class Colormap(mpl.colors.ListedColormap): @@ -19,18 +22,31 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def from_bounds(low,high,name='DAMASK colormap',N=256,model='rgb'): """ - Create a perceptually uniform colormap. + Create a perceptually uniform colormap from given bounds. + + Colors are internally stored as R(ed) G(green) B(lue) values. + The colormap can be used in matplotlib/seaborn or exported to + file for external use. Parameters ---------- low : numpy.ndarray of shape (3) + Color definition for minimum value. high : numpy.ndarray of shape (3) + Color definition for maximum value. N : integer, optional - The number of color quantization levels. + The number of color quantization levels. Defaults to 256. name : str, optional The name of the colormap. Defaults to `DAMASK colormap`. - model : str - Colormodel used for low and high. + model : {'rgb', 'hsv', 'hsl', 'xyz', 'lab', 'msh'} + Colormodel used for input color definitions. Defaults to `rgb`. + The available color models are: + - 'rgb': R(ed) G(green) B(lue). + - 'hsv': H(ue) S(aturation) V(alue). + - 'hsl': H(ue) S(aturation) L(uminance). + - 'xyz': CIE Xyz. + - 'lab': CIE Lab. + - 'msh': Msh (for perceptual uniform interpolation). """ low_,high_ = map(np.array,[low,high]) @@ -78,7 +94,7 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def from_predefined(name,N=256): """ - Select from set of predefined colormaps. + Select from a set of predefined colormaps. Predefined colormaps include native matplotlib colormaps and common DAMASK colormaps. @@ -147,7 +163,24 @@ class Colormap(mpl.colors.ListedColormap): return Colormap(rev.colors,rev.name) - def to_file(self,fname=None,format='paraview'): + def to_file(self,fname=None,format='ParaView'): + """ + Export colormap to file for use in external programs. + + Parameters + ---------- + fname : file, str, or pathlib.Path, optional. + Filename to store results. If not given, the filename will + consist of the name of the colormap and an extension that + depends on the file format. + format : {'ParaView', 'ASCII', 'GOM', 'gmsh'}, optional + File format, defaults to 'ParaView'. Available formats are: + - ParaView: JSON file, extension '.json'. + - ASCII: Plain text file, extension '.txt'. + - GOM: Aramis GOM (DIC), extension '.legend'. + - Gmsh: Gmsh FEM mesh-generator, extension '.msh'. + + """ if fname is not None: try: f = open(fname,'w') @@ -216,8 +249,18 @@ class Colormap(mpl.colors.ListedColormap): '}') @staticmethod - def _interpolate_msh(frac,low, high): + def _interpolate_msh(frac,low,high): + """ + Interpolate in Msh color space. + This interpolation gives a perceptually uniform colormap. + + References + ---------- + https://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf + https://www.kennethmoreland.com/color-maps/diverging_map.py + + """ def rad_diff(a,b): return abs(a[2]-b[2]) From 3513754647b2a2de2ef1f11413dd859c58719508 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 27 Jun 2020 20:17:48 +0200 Subject: [PATCH 06/28] low/high instead of left/right --- python/damask/_colormap.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index a0c976516..39a86cc8f 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -121,7 +121,7 @@ class Colormap(mpl.colors.ListedColormap): # DAMASK presets definition = Colormap._predefined_DAMASK[name] - return Colormap.from_bounds(definition['left'],definition['right'],name,N) + return Colormap.from_bounds(definition['low'],definition['high'],name,N) @staticmethod @@ -316,12 +316,12 @@ class Colormap(mpl.colors.ListedColormap): 'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])] - _predefined_DAMASK = {'orientation': {'low': [0.933334,0.878432,0.878431], - 'right': [0.250980,0.007843,0.000000]}, - 'strain': {'left': [0.941177,0.941177,0.870588], - 'right': [0.266667,0.266667,0.000000]}, - 'stress': {'left': [0.878432,0.874511,0.949019], - 'right': [0.000002,0.000000,0.286275]}} + _predefined_DAMASK = {'orientation': {'low': [0.933334,0.878432,0.878431], + 'high': [0.250980,0.007843,0.000000]}, + 'strain': {'low': [0.941177,0.941177,0.870588], + 'high': [0.266667,0.266667,0.000000]}, + 'stress': {'low': [0.878432,0.874511,0.949019], + 'high': [0.000002,0.000000,0.286275]}} @staticmethod def _hsv2rgb(hsv): From b78c8093756d790dfadc2aac5cddb3dc893db4cb Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 27 Jun 2020 20:36:18 +0200 Subject: [PATCH 07/28] real output --- python/damask/_colormap.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 39a86cc8f..0d04c44b7 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -242,11 +242,16 @@ class Colormap(mpl.colors.ListedColormap): print(s) @staticmethod - def _export_gmsh(colormap,fname=None): - colors = colormap.colors - colormap =('View.ColorTable = {' - ',\n'.join(['{%s}'%(','.join([str(x*255.0) for x in color])) for color in colors])+\ - '}') + def _export_gmsh(colormap,fhandle=None): + colormap = 'View.ColorTable = {\n'\ + +'\n'.join([f'{c[0]},{c[1]},{c[2]},' for c in reversed(colormap.colors)])\ + +'}' + if fhandle is None: + with open(colormap.name.replace(' ','_')+'.txt', 'w') as f: + t.to_ASCII(f) + else: + t.to_ASCII(fhandle) + @staticmethod def _interpolate_msh(frac,low,high): From 1c03bd157f65175c4815a89277486dc97afe56a9 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 27 Jun 2020 21:26:25 +0200 Subject: [PATCH 08/28] more testing --- python/damask/_colormap.py | 31 +++++++++++++++++++------------ python/tests/test_Colormap.py | 9 +++++++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 0d04c44b7..f6e6b62e7 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -234,23 +234,30 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def _export_GOM(colormap,fhandle=None): - pass - s =(f'1 1 {colormap.name.replace(" ","_")} 9 {colormap.name.replace(" ","_")} ' - f' 0 1 0 3 0 0 -1 9 \\ 0 0 0 255 255 255 0 0 255 ' - f'30 NO_UNIT 1 1 64 64 64 255 1 0 0 0 0 0 0 3 0 {str(len(colormap.colors))}' - ' '.join([' 0 %s 255 1'%(' '.join([str(int(x*255.0)) for x in color])) for color in reversed(colormap.colors)])) - print(s) + # ToDo: test in GOM + GOM_str = f'1 1 {colormap.name.replace(" ","_")} 9 {colormap.name.replace(" ","_")} ' \ + + '0 1 0 3 0 0 -1 9 \\ 0 0 0 255 255 255 0 0 255 ' \ + + f'30 NO_UNIT 1 1 64 64 64 255 1 0 0 0 0 0 0 3 0 {len(colormap.colors)}' \ + + ' '.join([f' 0 {c[0]} {c[1]} {c[2]} 255 1' for c in reversed((colormap.colors*255).astype(int))]) \ + + '\n' + if fhandle is None: + with open(colormap.name.replace(' ','_')+'.legend', 'w') as f: + f.write(GOM_str) + else: + fhandle.write(GOM_str) + @staticmethod def _export_gmsh(colormap,fhandle=None): - colormap = 'View.ColorTable = {\n'\ - +'\n'.join([f'{c[0]},{c[1]},{c[2]},' for c in reversed(colormap.colors)])\ - +'}' + # ToDo: test in gmsh + gmsh_str = 'View.ColorTable = {\n' \ + +'\n'.join([f'{c[0]},{c[1]},{c[2]},' for c in colormap.colors[:,:3]*255]) \ + +'\n}\n' if fhandle is None: - with open(colormap.name.replace(' ','_')+'.txt', 'w') as f: - t.to_ASCII(f) + with open(colormap.name.replace(' ','_')+'.msh', 'w') as f: + f.write(gmsh_str) else: - t.to_ASCII(fhandle) + fhandle.write(gmsh_str) @staticmethod diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index e00367452..dde14dcf3 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -86,10 +86,15 @@ class TestColormap: ]) def test_write_filehandle(self,format,name,tmpdir): c = Colormap.from_predefined('Dark2') - with open(tmpdir/name,'w') as f: + fname = tmpdir/name + with open(fname,'w') as f: c.to_file(f,format=format) + for i in range(10): + if fname.exists(): return + time.sleep(.5) + assert False - def test_invalid_format(self): + def test_write_invalid_format(self): c = Colormap.from_predefined('Dark2') with pytest.raises(ValueError): c.to_file(format='invalid') From e81b67e96408ad432012b803209df8d1fa2b4c56 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 28 Jun 2020 10:32:59 +0200 Subject: [PATCH 09/28] polishing --- python/damask/_colormap.py | 2 ++ python/tests/test_Colormap.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index f6e6b62e7..9377ca277 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -234,6 +234,7 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def _export_GOM(colormap,fhandle=None): + """Write colormap to GOM Aramis compatible format.""" # ToDo: test in GOM GOM_str = f'1 1 {colormap.name.replace(" ","_")} 9 {colormap.name.replace(" ","_")} ' \ + '0 1 0 3 0 0 -1 9 \\ 0 0 0 255 255 255 0 0 255 ' \ @@ -249,6 +250,7 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def _export_gmsh(colormap,fhandle=None): + """Write colormap to Gmsh compatible format.""" # ToDo: test in gmsh gmsh_str = 'View.ColorTable = {\n' \ +'\n'.join([f'{c[0]},{c[1]},{c[2]},' for c in colormap.colors[:,:3]*255]) \ diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index dde14dcf3..f124c704e 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -82,7 +82,7 @@ class TestColormap: @pytest.mark.parametrize('format,name',[('ASCII','test.txt'), ('paraview','test.json'), ('GOM','test.legend'), - ('gmsh','test.xxx') + ('gmsh','test.msh') ]) def test_write_filehandle(self,format,name,tmpdir): c = Colormap.from_predefined('Dark2') @@ -111,7 +111,6 @@ class TestColormap: np.allclose(c_1.colors,c_2.reversed().colors) def test_list(self): - c = Colormap.from_predefined('afmhot').reversed() - c.list_predefined() + Colormap.list_predefined() From ae4146f1c6a3a5e8e1c69c9ab94600819f5d2614 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 28 Jun 2020 11:18:22 +0200 Subject: [PATCH 10/28] report version, write out 'modern' ASCII table style --- python/damask/_colormap.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 9377ca277..d3ed4b12e 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -6,6 +6,7 @@ import matplotlib as mpl import matplotlib.pyplot as plt from matplotlib import cm +import damask from damask import Table _eps = 216./24389. @@ -208,6 +209,7 @@ class Colormap(mpl.colors.ListedColormap): colors+=[i]+c out = [{ + 'Creator':f'damask.Colormap {damask.version}', 'ColorSpace':'RGB', 'Name':colormap.name, 'DefaultMap':True, @@ -224,13 +226,13 @@ class Colormap(mpl.colors.ListedColormap): """Write colormap to ASCII table.""" labels = {'R':(1,),'G':(1,),'B':(1,)} if colormap.colors.shape[1] == 4: labels['alpha']=(1,) - t = Table(colormap.colors,labels) + t = Table(colormap.colors,labels,f'Creator: damask.Colormap {damask.version}') if fhandle is None: with open(colormap.name.replace(' ','_')+'.txt', 'w') as f: - t.to_ASCII(f) + t.to_ASCII(f,True) else: - t.to_ASCII(fhandle) + t.to_ASCII(fhandle,True) @staticmethod def _export_GOM(colormap,fhandle=None): From 6a748d2edf8f3ffd7b4bdf8a618605c08dfa7557 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 28 Jun 2020 11:19:18 +0200 Subject: [PATCH 11/28] do not expand single strings into characters --- python/damask/_table.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/damask/_table.py b/python/damask/_table.py index 435b7afa9..e8d35c545 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -19,11 +19,12 @@ class Table: Data. Column labels from a pandas.DataFrame will be replaced. shapes : dict with str:tuple pairs Shapes of the columns. Example 'F':(3,3) for a deformation gradient. - comments : iterable of str, optional + comments : str or iterable of str, optional Additional, human-readable information. """ - self.comments = [] if comments is None else [c for c in comments] + comments_ = [comments] if isinstance(comments,str) else comments + self.comments = [] if comments_ is None else [c for c in comments_] self.data = pd.DataFrame(data=data) self.shapes = { k:(v,) if isinstance(v,(np.int,int)) else v for k,v in shapes.items() } self._label_condensed() From e6a87da37c8d7562aa351c2c156d830c4a08bfc3 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 28 Jun 2020 11:20:09 +0200 Subject: [PATCH 12/28] compare to reference results need to patch damask.version to be independent of version strings (in json and ASCII table) --- python/tests/reference/Colormap/binary.json | 1290 +++++++++++++++++ python/tests/reference/Colormap/binary.legend | 1 + python/tests/reference/Colormap/binary.msh | 258 ++++ python/tests/reference/Colormap/binary.txt | 258 ++++ python/tests/test_Colormap.py | 31 +- 5 files changed, 1835 insertions(+), 3 deletions(-) create mode 100644 python/tests/reference/Colormap/binary.json create mode 100644 python/tests/reference/Colormap/binary.legend create mode 100644 python/tests/reference/Colormap/binary.msh create mode 100644 python/tests/reference/Colormap/binary.txt diff --git a/python/tests/reference/Colormap/binary.json b/python/tests/reference/Colormap/binary.json new file mode 100644 index 000000000..d56f1232e --- /dev/null +++ b/python/tests/reference/Colormap/binary.json @@ -0,0 +1,1290 @@ +[ + { + "Creator": "damask.Colormap 99.99.99-9999-pytest", + "ColorSpace": "RGB", + "Name": "binary", + "DefaultMap": true, + "RGBPoints": [ + 0, + 1.0, + 1.0, + 1.0, + 1.0, + 1, + 0.996078, + 0.996078, + 0.996078, + 1.0, + 2, + 0.992157, + 0.992157, + 0.992157, + 1.0, + 3, + 0.988235, + 0.988235, + 0.988235, + 1.0, + 4, + 0.984314, + 0.984314, + 0.984314, + 1.0, + 5, + 0.980392, + 0.980392, + 0.980392, + 1.0, + 6, + 0.976471, + 0.976471, + 0.976471, + 1.0, + 7, + 0.972549, + 0.972549, + 0.972549, + 1.0, + 8, + 0.968627, + 0.968627, + 0.968627, + 1.0, + 9, + 0.964706, + 0.964706, + 0.964706, + 1.0, + 10, + 0.960784, + 0.960784, + 0.960784, + 1.0, + 11, + 0.956863, + 0.956863, + 0.956863, + 1.0, + 12, + 0.952941, + 0.952941, + 0.952941, + 1.0, + 13, + 0.94902, + 0.94902, + 0.94902, + 1.0, + 14, + 0.945098, + 0.945098, + 0.945098, + 1.0, + 15, + 0.941176, + 0.941176, + 0.941176, + 1.0, + 16, + 0.937255, + 0.937255, + 0.937255, + 1.0, + 17, + 0.933333, + 0.933333, + 0.933333, + 1.0, + 18, + 0.929412, + 0.929412, + 0.929412, + 1.0, + 19, + 0.92549, + 0.92549, + 0.92549, + 1.0, + 20, + 0.921569, + 0.921569, + 0.921569, + 1.0, + 21, + 0.917647, + 0.917647, + 0.917647, + 1.0, + 22, + 0.913725, + 0.913725, + 0.913725, + 1.0, + 23, + 0.909804, + 0.909804, + 0.909804, + 1.0, + 24, + 0.905882, + 0.905882, + 0.905882, + 1.0, + 25, + 0.901961, + 0.901961, + 0.901961, + 1.0, + 26, + 0.898039, + 0.898039, + 0.898039, + 1.0, + 27, + 0.894118, + 0.894118, + 0.894118, + 1.0, + 28, + 0.890196, + 0.890196, + 0.890196, + 1.0, + 29, + 0.886275, + 0.886275, + 0.886275, + 1.0, + 30, + 0.882353, + 0.882353, + 0.882353, + 1.0, + 31, + 0.878431, + 0.878431, + 0.878431, + 1.0, + 32, + 0.87451, + 0.87451, + 0.87451, + 1.0, + 33, + 0.870588, + 0.870588, + 0.870588, + 1.0, + 34, + 0.866667, + 0.866667, + 0.866667, + 1.0, + 35, + 0.862745, + 0.862745, + 0.862745, + 1.0, + 36, + 0.858824, + 0.858824, + 0.858824, + 1.0, + 37, + 0.854902, + 0.854902, + 0.854902, + 1.0, + 38, + 0.85098, + 0.85098, + 0.85098, + 1.0, + 39, + 0.847059, + 0.847059, + 0.847059, + 1.0, + 40, + 0.843137, + 0.843137, + 0.843137, + 1.0, + 41, + 0.839216, + 0.839216, + 0.839216, + 1.0, + 42, + 0.835294, + 0.835294, + 0.835294, + 1.0, + 43, + 0.831373, + 0.831373, + 0.831373, + 1.0, + 44, + 0.827451, + 0.827451, + 0.827451, + 1.0, + 45, + 0.823529, + 0.823529, + 0.823529, + 1.0, + 46, + 0.819608, + 0.819608, + 0.819608, + 1.0, + 47, + 0.815686, + 0.815686, + 0.815686, + 1.0, + 48, + 0.811765, + 0.811765, + 0.811765, + 1.0, + 49, + 0.807843, + 0.807843, + 0.807843, + 1.0, + 50, + 0.803922, + 0.803922, + 0.803922, + 1.0, + 51, + 0.8, + 0.8, + 0.8, + 1.0, + 52, + 0.796078, + 0.796078, + 0.796078, + 1.0, + 53, + 0.792157, + 0.792157, + 0.792157, + 1.0, + 54, + 0.788235, + 0.788235, + 0.788235, + 1.0, + 55, + 0.784314, + 0.784314, + 0.784314, + 1.0, + 56, + 0.780392, + 0.780392, + 0.780392, + 1.0, + 57, + 0.776471, + 0.776471, + 0.776471, + 1.0, + 58, + 0.772549, + 0.772549, + 0.772549, + 1.0, + 59, + 0.768627, + 0.768627, + 0.768627, + 1.0, + 60, + 0.764706, + 0.764706, + 0.764706, + 1.0, + 61, + 0.760784, + 0.760784, + 0.760784, + 1.0, + 62, + 0.756863, + 0.756863, + 0.756863, + 1.0, + 63, + 0.752941, + 0.752941, + 0.752941, + 1.0, + 64, + 0.74902, + 0.74902, + 0.74902, + 1.0, + 65, + 0.745098, + 0.745098, + 0.745098, + 1.0, + 66, + 0.741176, + 0.741176, + 0.741176, + 1.0, + 67, + 0.737255, + 0.737255, + 0.737255, + 1.0, + 68, + 0.733333, + 0.733333, + 0.733333, + 1.0, + 69, + 0.729412, + 0.729412, + 0.729412, + 1.0, + 70, + 0.72549, + 0.72549, + 0.72549, + 1.0, + 71, + 0.721569, + 0.721569, + 0.721569, + 1.0, + 72, + 0.717647, + 0.717647, + 0.717647, + 1.0, + 73, + 0.713725, + 0.713725, + 0.713725, + 1.0, + 74, + 0.709804, + 0.709804, + 0.709804, + 1.0, + 75, + 0.705882, + 0.705882, + 0.705882, + 1.0, + 76, + 0.701961, + 0.701961, + 0.701961, + 1.0, + 77, + 0.698039, + 0.698039, + 0.698039, + 1.0, + 78, + 0.694118, + 0.694118, + 0.694118, + 1.0, + 79, + 0.690196, + 0.690196, + 0.690196, + 1.0, + 80, + 0.686275, + 0.686275, + 0.686275, + 1.0, + 81, + 0.682353, + 0.682353, + 0.682353, + 1.0, + 82, + 0.678431, + 0.678431, + 0.678431, + 1.0, + 83, + 0.67451, + 0.67451, + 0.67451, + 1.0, + 84, + 0.670588, + 0.670588, + 0.670588, + 1.0, + 85, + 0.666667, + 0.666667, + 0.666667, + 1.0, + 86, + 0.662745, + 0.662745, + 0.662745, + 1.0, + 87, + 0.658824, + 0.658824, + 0.658824, + 1.0, + 88, + 0.654902, + 0.654902, + 0.654902, + 1.0, + 89, + 0.65098, + 0.65098, + 0.65098, + 1.0, + 90, + 0.647059, + 0.647059, + 0.647059, + 1.0, + 91, + 0.643137, + 0.643137, + 0.643137, + 1.0, + 92, + 0.639216, + 0.639216, + 0.639216, + 1.0, + 93, + 0.635294, + 0.635294, + 0.635294, + 1.0, + 94, + 0.631373, + 0.631373, + 0.631373, + 1.0, + 95, + 0.627451, + 0.627451, + 0.627451, + 1.0, + 96, + 0.623529, + 0.623529, + 0.623529, + 1.0, + 97, + 0.619608, + 0.619608, + 0.619608, + 1.0, + 98, + 0.615686, + 0.615686, + 0.615686, + 1.0, + 99, + 0.611765, + 0.611765, + 0.611765, + 1.0, + 100, + 0.607843, + 0.607843, + 0.607843, + 1.0, + 101, + 0.603922, + 0.603922, + 0.603922, + 1.0, + 102, + 0.6, + 0.6, + 0.6, + 1.0, + 103, + 0.596078, + 0.596078, + 0.596078, + 1.0, + 104, + 0.592157, + 0.592157, + 0.592157, + 1.0, + 105, + 0.588235, + 0.588235, + 0.588235, + 1.0, + 106, + 0.584314, + 0.584314, + 0.584314, + 1.0, + 107, + 0.580392, + 0.580392, + 0.580392, + 1.0, + 108, + 0.576471, + 0.576471, + 0.576471, + 1.0, + 109, + 0.572549, + 0.572549, + 0.572549, + 1.0, + 110, + 0.568627, + 0.568627, + 0.568627, + 1.0, + 111, + 0.564706, + 0.564706, + 0.564706, + 1.0, + 112, + 0.560784, + 0.560784, + 0.560784, + 1.0, + 113, + 0.556863, + 0.556863, + 0.556863, + 1.0, + 114, + 0.552941, + 0.552941, + 0.552941, + 1.0, + 115, + 0.54902, + 0.54902, + 0.54902, + 1.0, + 116, + 0.545098, + 0.545098, + 0.545098, + 1.0, + 117, + 0.541176, + 0.541176, + 0.541176, + 1.0, + 118, + 0.537255, + 0.537255, + 0.537255, + 1.0, + 119, + 0.533333, + 0.533333, + 0.533333, + 1.0, + 120, + 0.529412, + 0.529412, + 0.529412, + 1.0, + 121, + 0.52549, + 0.52549, + 0.52549, + 1.0, + 122, + 0.521569, + 0.521569, + 0.521569, + 1.0, + 123, + 0.517647, + 0.517647, + 0.517647, + 1.0, + 124, + 0.513725, + 0.513725, + 0.513725, + 1.0, + 125, + 0.509804, + 0.509804, + 0.509804, + 1.0, + 126, + 0.505882, + 0.505882, + 0.505882, + 1.0, + 127, + 0.501961, + 0.501961, + 0.501961, + 1.0, + 128, + 0.498039, + 0.498039, + 0.498039, + 1.0, + 129, + 0.494118, + 0.494118, + 0.494118, + 1.0, + 130, + 0.490196, + 0.490196, + 0.490196, + 1.0, + 131, + 0.486275, + 0.486275, + 0.486275, + 1.0, + 132, + 0.482353, + 0.482353, + 0.482353, + 1.0, + 133, + 0.478431, + 0.478431, + 0.478431, + 1.0, + 134, + 0.47451, + 0.47451, + 0.47451, + 1.0, + 135, + 0.470588, + 0.470588, + 0.470588, + 1.0, + 136, + 0.466667, + 0.466667, + 0.466667, + 1.0, + 137, + 0.462745, + 0.462745, + 0.462745, + 1.0, + 138, + 0.458824, + 0.458824, + 0.458824, + 1.0, + 139, + 0.454902, + 0.454902, + 0.454902, + 1.0, + 140, + 0.45098, + 0.45098, + 0.45098, + 1.0, + 141, + 0.447059, + 0.447059, + 0.447059, + 1.0, + 142, + 0.443137, + 0.443137, + 0.443137, + 1.0, + 143, + 0.439216, + 0.439216, + 0.439216, + 1.0, + 144, + 0.435294, + 0.435294, + 0.435294, + 1.0, + 145, + 0.431373, + 0.431373, + 0.431373, + 1.0, + 146, + 0.427451, + 0.427451, + 0.427451, + 1.0, + 147, + 0.423529, + 0.423529, + 0.423529, + 1.0, + 148, + 0.419608, + 0.419608, + 0.419608, + 1.0, + 149, + 0.415686, + 0.415686, + 0.415686, + 1.0, + 150, + 0.411765, + 0.411765, + 0.411765, + 1.0, + 151, + 0.407843, + 0.407843, + 0.407843, + 1.0, + 152, + 0.403922, + 0.403922, + 0.403922, + 1.0, + 153, + 0.4, + 0.4, + 0.4, + 1.0, + 154, + 0.396078, + 0.396078, + 0.396078, + 1.0, + 155, + 0.392157, + 0.392157, + 0.392157, + 1.0, + 156, + 0.388235, + 0.388235, + 0.388235, + 1.0, + 157, + 0.384314, + 0.384314, + 0.384314, + 1.0, + 158, + 0.380392, + 0.380392, + 0.380392, + 1.0, + 159, + 0.376471, + 0.376471, + 0.376471, + 1.0, + 160, + 0.372549, + 0.372549, + 0.372549, + 1.0, + 161, + 0.368627, + 0.368627, + 0.368627, + 1.0, + 162, + 0.364706, + 0.364706, + 0.364706, + 1.0, + 163, + 0.360784, + 0.360784, + 0.360784, + 1.0, + 164, + 0.356863, + 0.356863, + 0.356863, + 1.0, + 165, + 0.352941, + 0.352941, + 0.352941, + 1.0, + 166, + 0.34902, + 0.34902, + 0.34902, + 1.0, + 167, + 0.345098, + 0.345098, + 0.345098, + 1.0, + 168, + 0.341176, + 0.341176, + 0.341176, + 1.0, + 169, + 0.337255, + 0.337255, + 0.337255, + 1.0, + 170, + 0.333333, + 0.333333, + 0.333333, + 1.0, + 171, + 0.329412, + 0.329412, + 0.329412, + 1.0, + 172, + 0.32549, + 0.32549, + 0.32549, + 1.0, + 173, + 0.321569, + 0.321569, + 0.321569, + 1.0, + 174, + 0.317647, + 0.317647, + 0.317647, + 1.0, + 175, + 0.313725, + 0.313725, + 0.313725, + 1.0, + 176, + 0.309804, + 0.309804, + 0.309804, + 1.0, + 177, + 0.305882, + 0.305882, + 0.305882, + 1.0, + 178, + 0.301961, + 0.301961, + 0.301961, + 1.0, + 179, + 0.298039, + 0.298039, + 0.298039, + 1.0, + 180, + 0.294118, + 0.294118, + 0.294118, + 1.0, + 181, + 0.290196, + 0.290196, + 0.290196, + 1.0, + 182, + 0.286275, + 0.286275, + 0.286275, + 1.0, + 183, + 0.282353, + 0.282353, + 0.282353, + 1.0, + 184, + 0.278431, + 0.278431, + 0.278431, + 1.0, + 185, + 0.27451, + 0.27451, + 0.27451, + 1.0, + 186, + 0.270588, + 0.270588, + 0.270588, + 1.0, + 187, + 0.266667, + 0.266667, + 0.266667, + 1.0, + 188, + 0.262745, + 0.262745, + 0.262745, + 1.0, + 189, + 0.258824, + 0.258824, + 0.258824, + 1.0, + 190, + 0.254902, + 0.254902, + 0.254902, + 1.0, + 191, + 0.25098, + 0.25098, + 0.25098, + 1.0, + 192, + 0.247059, + 0.247059, + 0.247059, + 1.0, + 193, + 0.243137, + 0.243137, + 0.243137, + 1.0, + 194, + 0.239216, + 0.239216, + 0.239216, + 1.0, + 195, + 0.235294, + 0.235294, + 0.235294, + 1.0, + 196, + 0.231373, + 0.231373, + 0.231373, + 1.0, + 197, + 0.227451, + 0.227451, + 0.227451, + 1.0, + 198, + 0.223529, + 0.223529, + 0.223529, + 1.0, + 199, + 0.219608, + 0.219608, + 0.219608, + 1.0, + 200, + 0.215686, + 0.215686, + 0.215686, + 1.0, + 201, + 0.211765, + 0.211765, + 0.211765, + 1.0, + 202, + 0.207843, + 0.207843, + 0.207843, + 1.0, + 203, + 0.203922, + 0.203922, + 0.203922, + 1.0, + 204, + 0.2, + 0.2, + 0.2, + 1.0, + 205, + 0.196078, + 0.196078, + 0.196078, + 1.0, + 206, + 0.192157, + 0.192157, + 0.192157, + 1.0, + 207, + 0.188235, + 0.188235, + 0.188235, + 1.0, + 208, + 0.184314, + 0.184314, + 0.184314, + 1.0, + 209, + 0.180392, + 0.180392, + 0.180392, + 1.0, + 210, + 0.176471, + 0.176471, + 0.176471, + 1.0, + 211, + 0.172549, + 0.172549, + 0.172549, + 1.0, + 212, + 0.168627, + 0.168627, + 0.168627, + 1.0, + 213, + 0.164706, + 0.164706, + 0.164706, + 1.0, + 214, + 0.160784, + 0.160784, + 0.160784, + 1.0, + 215, + 0.156863, + 0.156863, + 0.156863, + 1.0, + 216, + 0.152941, + 0.152941, + 0.152941, + 1.0, + 217, + 0.14902, + 0.14902, + 0.14902, + 1.0, + 218, + 0.145098, + 0.145098, + 0.145098, + 1.0, + 219, + 0.141176, + 0.141176, + 0.141176, + 1.0, + 220, + 0.137255, + 0.137255, + 0.137255, + 1.0, + 221, + 0.133333, + 0.133333, + 0.133333, + 1.0, + 222, + 0.129412, + 0.129412, + 0.129412, + 1.0, + 223, + 0.12549, + 0.12549, + 0.12549, + 1.0, + 224, + 0.121569, + 0.121569, + 0.121569, + 1.0, + 225, + 0.117647, + 0.117647, + 0.117647, + 1.0, + 226, + 0.113725, + 0.113725, + 0.113725, + 1.0, + 227, + 0.109804, + 0.109804, + 0.109804, + 1.0, + 228, + 0.105882, + 0.105882, + 0.105882, + 1.0, + 229, + 0.101961, + 0.101961, + 0.101961, + 1.0, + 230, + 0.098039, + 0.098039, + 0.098039, + 1.0, + 231, + 0.094118, + 0.094118, + 0.094118, + 1.0, + 232, + 0.090196, + 0.090196, + 0.090196, + 1.0, + 233, + 0.086275, + 0.086275, + 0.086275, + 1.0, + 234, + 0.082353, + 0.082353, + 0.082353, + 1.0, + 235, + 0.078431, + 0.078431, + 0.078431, + 1.0, + 236, + 0.07451, + 0.07451, + 0.07451, + 1.0, + 237, + 0.070588, + 0.070588, + 0.070588, + 1.0, + 238, + 0.066667, + 0.066667, + 0.066667, + 1.0, + 239, + 0.062745, + 0.062745, + 0.062745, + 1.0, + 240, + 0.058824, + 0.058824, + 0.058824, + 1.0, + 241, + 0.054902, + 0.054902, + 0.054902, + 1.0, + 242, + 0.05098, + 0.05098, + 0.05098, + 1.0, + 243, + 0.047059, + 0.047059, + 0.047059, + 1.0, + 244, + 0.043137, + 0.043137, + 0.043137, + 1.0, + 245, + 0.039216, + 0.039216, + 0.039216, + 1.0, + 246, + 0.035294, + 0.035294, + 0.035294, + 1.0, + 247, + 0.031373, + 0.031373, + 0.031373, + 1.0, + 248, + 0.027451, + 0.027451, + 0.027451, + 1.0, + 249, + 0.023529, + 0.023529, + 0.023529, + 1.0, + 250, + 0.019608, + 0.019608, + 0.019608, + 1.0, + 251, + 0.015686, + 0.015686, + 0.015686, + 1.0, + 252, + 0.011765, + 0.011765, + 0.011765, + 1.0, + 253, + 0.007843, + 0.007843, + 0.007843, + 1.0, + 254, + 0.003922, + 0.003922, + 0.003922, + 1.0, + 255, + 0.0, + 0.0, + 0.0, + 1.0 + ] + } +] \ No newline at end of file diff --git a/python/tests/reference/Colormap/binary.legend b/python/tests/reference/Colormap/binary.legend new file mode 100644 index 000000000..ba417facc --- /dev/null +++ b/python/tests/reference/Colormap/binary.legend @@ -0,0 +1 @@ +1 1 binary 9 binary 0 1 0 3 0 0 -1 9 \ 0 0 0 255 255 255 0 0 255 30 NO_UNIT 1 1 64 64 64 255 1 0 0 0 0 0 0 3 0 256 0 0 0 0 255 1 0 0 0 0 255 1 0 1 1 1 255 1 0 2 2 2 255 1 0 4 4 4 255 1 0 5 5 5 255 1 0 6 6 6 255 1 0 7 7 7 255 1 0 8 8 8 255 1 0 8 8 8 255 1 0 9 9 9 255 1 0 11 11 11 255 1 0 12 12 12 255 1 0 13 13 13 255 1 0 14 14 14 255 1 0 15 15 15 255 1 0 16 16 16 255 1 0 16 16 16 255 1 0 17 17 17 255 1 0 18 18 18 255 1 0 20 20 20 255 1 0 21 21 21 255 1 0 22 22 22 255 1 0 23 23 23 255 1 0 24 24 24 255 1 0 24 24 24 255 1 0 25 25 25 255 1 0 27 27 27 255 1 0 28 28 28 255 1 0 29 29 29 255 1 0 30 30 30 255 1 0 31 31 31 255 1 0 32 32 32 255 1 0 32 32 32 255 1 0 33 33 33 255 1 0 34 34 34 255 1 0 36 36 36 255 1 0 37 37 37 255 1 0 38 38 38 255 1 0 39 39 39 255 1 0 40 40 40 255 1 0 40 40 40 255 1 0 41 41 41 255 1 0 43 43 43 255 1 0 44 44 44 255 1 0 45 45 45 255 1 0 46 46 46 255 1 0 47 47 47 255 1 0 48 48 48 255 1 0 48 48 48 255 1 0 49 49 49 255 1 0 50 50 50 255 1 0 52 52 52 255 1 0 53 53 53 255 1 0 54 54 54 255 1 0 55 55 55 255 1 0 56 56 56 255 1 0 56 56 56 255 1 0 57 57 57 255 1 0 59 59 59 255 1 0 60 60 60 255 1 0 61 61 61 255 1 0 62 62 62 255 1 0 63 63 63 255 1 0 64 64 64 255 1 0 65 65 65 255 1 0 65 65 65 255 1 0 66 66 66 255 1 0 68 68 68 255 1 0 69 69 69 255 1 0 70 70 70 255 1 0 71 71 71 255 1 0 72 72 72 255 1 0 73 73 73 255 1 0 73 73 73 255 1 0 75 75 75 255 1 0 76 76 76 255 1 0 77 77 77 255 1 0 78 78 78 255 1 0 79 79 79 255 1 0 80 80 80 255 1 0 81 81 81 255 1 0 81 81 81 255 1 0 82 82 82 255 1 0 84 84 84 255 1 0 85 85 85 255 1 0 86 86 86 255 1 0 87 87 87 255 1 0 88 88 88 255 1 0 89 89 89 255 1 0 89 89 89 255 1 0 91 91 91 255 1 0 92 92 92 255 1 0 93 93 93 255 1 0 94 94 94 255 1 0 95 95 95 255 1 0 96 96 96 255 1 0 97 97 97 255 1 0 97 97 97 255 1 0 98 98 98 255 1 0 100 100 100 255 1 0 101 101 101 255 1 0 102 102 102 255 1 0 103 103 103 255 1 0 104 104 104 255 1 0 105 105 105 255 1 0 105 105 105 255 1 0 107 107 107 255 1 0 108 108 108 255 1 0 109 109 109 255 1 0 110 110 110 255 1 0 111 111 111 255 1 0 112 112 112 255 1 0 113 113 113 255 1 0 113 113 113 255 1 0 114 114 114 255 1 0 116 116 116 255 1 0 117 117 117 255 1 0 118 118 118 255 1 0 119 119 119 255 1 0 120 120 120 255 1 0 121 121 121 255 1 0 121 121 121 255 1 0 123 123 123 255 1 0 124 124 124 255 1 0 125 125 125 255 1 0 126 126 126 255 1 0 127 127 127 255 1 0 128 128 128 255 1 0 129 129 129 255 1 0 130 130 130 255 1 0 131 131 131 255 1 0 131 131 131 255 1 0 133 133 133 255 1 0 134 134 134 255 1 0 135 135 135 255 1 0 136 136 136 255 1 0 137 137 137 255 1 0 138 138 138 255 1 0 139 139 139 255 1 0 140 140 140 255 1 0 141 141 141 255 1 0 142 142 142 255 1 0 143 143 143 255 1 0 144 144 144 255 1 0 145 145 145 255 1 0 146 146 146 255 1 0 147 147 147 255 1 0 147 147 147 255 1 0 149 149 149 255 1 0 150 150 150 255 1 0 151 151 151 255 1 0 152 152 152 255 1 0 153 153 153 255 1 0 154 154 154 255 1 0 155 155 155 255 1 0 156 156 156 255 1 0 157 157 157 255 1 0 158 158 158 255 1 0 159 159 159 255 1 0 160 160 160 255 1 0 161 161 161 255 1 0 162 162 162 255 1 0 163 163 163 255 1 0 163 163 163 255 1 0 165 165 165 255 1 0 166 166 166 255 1 0 167 167 167 255 1 0 168 168 168 255 1 0 169 169 169 255 1 0 170 170 170 255 1 0 171 171 171 255 1 0 172 172 172 255 1 0 173 173 173 255 1 0 174 174 174 255 1 0 175 175 175 255 1 0 176 176 176 255 1 0 177 177 177 255 1 0 178 178 178 255 1 0 179 179 179 255 1 0 179 179 179 255 1 0 181 181 181 255 1 0 182 182 182 255 1 0 183 183 183 255 1 0 184 184 184 255 1 0 185 185 185 255 1 0 186 186 186 255 1 0 187 187 187 255 1 0 188 188 188 255 1 0 189 189 189 255 1 0 190 190 190 255 1 0 191 191 191 255 1 0 192 192 192 255 1 0 193 193 193 255 1 0 194 194 194 255 1 0 195 195 195 255 1 0 195 195 195 255 1 0 197 197 197 255 1 0 198 198 198 255 1 0 199 199 199 255 1 0 200 200 200 255 1 0 201 201 201 255 1 0 202 202 202 255 1 0 203 203 203 255 1 0 204 204 204 255 1 0 205 205 205 255 1 0 206 206 206 255 1 0 207 207 207 255 1 0 208 208 208 255 1 0 209 209 209 255 1 0 210 210 210 255 1 0 211 211 211 255 1 0 211 211 211 255 1 0 213 213 213 255 1 0 214 214 214 255 1 0 215 215 215 255 1 0 216 216 216 255 1 0 217 217 217 255 1 0 218 218 218 255 1 0 219 219 219 255 1 0 220 220 220 255 1 0 221 221 221 255 1 0 222 222 222 255 1 0 223 223 223 255 1 0 224 224 224 255 1 0 225 225 225 255 1 0 226 226 226 255 1 0 227 227 227 255 1 0 228 228 228 255 1 0 229 229 229 255 1 0 230 230 230 255 1 0 231 231 231 255 1 0 232 232 232 255 1 0 233 233 233 255 1 0 234 234 234 255 1 0 235 235 235 255 1 0 236 236 236 255 1 0 237 237 237 255 1 0 238 238 238 255 1 0 239 239 239 255 1 0 240 240 240 255 1 0 241 241 241 255 1 0 242 242 242 255 1 0 243 243 243 255 1 0 244 244 244 255 1 0 245 245 245 255 1 0 246 246 246 255 1 0 247 247 247 255 1 0 248 248 248 255 1 0 249 249 249 255 1 0 250 250 250 255 1 0 251 251 251 255 1 0 252 252 252 255 1 0 253 253 253 255 1 0 254 254 254 255 1 0 255 255 255 255 1 diff --git a/python/tests/reference/Colormap/binary.msh b/python/tests/reference/Colormap/binary.msh new file mode 100644 index 000000000..66b1cf863 --- /dev/null +++ b/python/tests/reference/Colormap/binary.msh @@ -0,0 +1,258 @@ +View.ColorTable = { +255.0,255.0,255.0, +254.0,254.0,254.0, +253.0,253.0,253.0, +252.0,252.0,252.0, +251.0,251.0,251.0, +250.0,250.0,250.0, +249.0,249.0,249.0, +248.0,248.0,248.0, +247.0,247.0,247.0, +246.0,246.0,246.0, +245.0,245.0,245.0, +244.0,244.0,244.0, +243.0,243.0,243.0, +242.0,242.0,242.0, +241.0,241.0,241.0, +240.0,240.0,240.0, +239.0,239.0,239.0, +238.0,238.0,238.0, +237.0,237.0,237.0, +236.0,236.0,236.0, +235.00000000000003,235.00000000000003,235.00000000000003, +234.0,234.0,234.0, +233.0,233.0,233.0, +232.0,232.0,232.0, +231.0,231.0,231.0, +230.0,230.0,230.0, +229.0,229.0,229.0, +228.0,228.0,228.0, +227.0,227.0,227.0, +226.0,226.0,226.0, +225.0,225.0,225.0, +224.0,224.0,224.0, +223.0,223.0,223.0, +222.0,222.0,222.0, +221.0,221.0,221.0, +220.0,220.0,220.0, +219.00000000000003,219.00000000000003,219.00000000000003, +218.00000000000003,218.00000000000003,218.00000000000003, +217.0,217.0,217.0, +216.0,216.0,216.0, +215.0,215.0,215.0, +214.0,214.0,214.0, +213.0,213.0,213.0, +211.99999999999997,211.99999999999997,211.99999999999997, +211.0,211.0,211.0, +210.0,210.0,210.0, +209.0,209.0,209.0, +208.0,208.0,208.0, +207.0,207.0,207.0, +206.0,206.0,206.0, +205.0,205.0,205.0, +204.0,204.0,204.0, +203.00000000000003,203.00000000000003,203.00000000000003, +202.00000000000003,202.00000000000003,202.00000000000003, +201.0,201.0,201.0, +200.0,200.0,200.0, +199.0,199.0,199.0, +198.0,198.0,198.0, +197.0,197.0,197.0, +195.99999999999997,195.99999999999997,195.99999999999997, +195.0,195.0,195.0, +194.0,194.0,194.0, +193.0,193.0,193.0, +192.0,192.0,192.0, +191.0,191.0,191.0, +190.0,190.0,190.0, +189.0,189.0,189.0, +188.0,188.0,188.0, +187.00000000000003,187.00000000000003,187.00000000000003, +186.00000000000003,186.00000000000003,186.00000000000003, +185.0,185.0,185.0, +184.0,184.0,184.0, +183.0,183.0,183.0, +182.0,182.0,182.0, +181.0,181.0,181.0, +179.99999999999997,179.99999999999997,179.99999999999997, +179.0,179.0,179.0, +178.0,178.0,178.0, +177.0,177.0,177.0, +176.0,176.0,176.0, +175.0,175.0,175.0, +174.0,174.0,174.0, +173.0,173.0,173.0, +172.0,172.0,172.0, +171.00000000000003,171.00000000000003,171.00000000000003, +170.00000000000003,170.00000000000003,170.00000000000003, +169.0,169.0,169.0, +168.0,168.0,168.0, +167.0,167.0,167.0, +166.0,166.0,166.0, +165.0,165.0,165.0, +163.99999999999997,163.99999999999997,163.99999999999997, +163.0,163.0,163.0, +162.0,162.0,162.0, +161.0,161.0,161.0, +160.0,160.0,160.0, +159.0,159.0,159.0, +158.0,158.0,158.0, +157.0,157.0,157.0, +156.0,156.0,156.0, +155.00000000000003,155.00000000000003,155.00000000000003, +154.00000000000003,154.00000000000003,154.00000000000003, +153.0,153.0,153.0, +152.0,152.0,152.0, +151.0,151.0,151.0, +150.0,150.0,150.0, +149.0,149.0,149.0, +147.99999999999997,147.99999999999997,147.99999999999997, +147.0,147.0,147.0, +146.0,146.0,146.0, +145.0,145.0,145.0, +144.0,144.0,144.0, +143.0,143.0,143.0, +142.0,142.0,142.0, +141.0,141.0,141.0, +140.0,140.0,140.0, +139.00000000000003,139.00000000000003,139.00000000000003, +138.00000000000003,138.00000000000003,138.00000000000003, +137.0,137.0,137.0, +136.0,136.0,136.0, +135.0,135.0,135.0, +134.0,134.0,134.0, +133.0,133.0,133.0, +131.99999999999997,131.99999999999997,131.99999999999997, +131.0,131.0,131.0, +130.0,130.0,130.0, +129.0,129.0,129.0, +128.0,128.0,128.0, +127.0,127.0,127.0, +126.0,126.0,126.0, +125.00000000000001,125.00000000000001,125.00000000000001, +124.00000000000001,124.00000000000001,124.00000000000001, +123.00000000000001,123.00000000000001,123.00000000000001, +121.99999999999999,121.99999999999999,121.99999999999999, +121.0,121.0,121.0, +120.0,120.0,120.0, +119.0,119.0,119.0, +118.0,118.0,118.0, +117.00000000000001,117.00000000000001,117.00000000000001, +116.00000000000001,116.00000000000001,116.00000000000001, +114.99999999999999,114.99999999999999,114.99999999999999, +113.99999999999999,113.99999999999999,113.99999999999999, +113.0,113.0,113.0, +112.0,112.0,112.0, +111.0,111.0,111.0, +110.0,110.0,110.0, +109.00000000000001,109.00000000000001,109.00000000000001, +108.00000000000001,108.00000000000001,108.00000000000001, +107.00000000000001,107.00000000000001,107.00000000000001, +105.99999999999999,105.99999999999999,105.99999999999999, +105.0,105.0,105.0, +104.0,104.0,104.0, +103.0,103.0,103.0, +102.0,102.0,102.0, +101.00000000000001,101.00000000000001,101.00000000000001, +100.00000000000001,100.00000000000001,100.00000000000001, +98.99999999999999,98.99999999999999,98.99999999999999, +97.99999999999999,97.99999999999999,97.99999999999999, +97.0,97.0,97.0, +96.0,96.0,96.0, +95.0,95.0,95.0, +94.0,94.0,94.0, +93.00000000000001,93.00000000000001,93.00000000000001, +92.00000000000001,92.00000000000001,92.00000000000001, +91.00000000000001,91.00000000000001,91.00000000000001, +89.99999999999999,89.99999999999999,89.99999999999999, +89.0,89.0,89.0, +88.0,88.0,88.0, +87.0,87.0,87.0, +86.0,86.0,86.0, +85.00000000000001,85.00000000000001,85.00000000000001, +84.00000000000001,84.00000000000001,84.00000000000001, +82.99999999999999,82.99999999999999,82.99999999999999, +81.99999999999999,81.99999999999999,81.99999999999999, +81.0,81.0,81.0, +80.0,80.0,80.0, +79.0,79.0,79.0, +78.0,78.0,78.0, +77.00000000000001,77.00000000000001,77.00000000000001, +76.00000000000001,76.00000000000001,76.00000000000001, +75.00000000000001,75.00000000000001,75.00000000000001, +73.99999999999999,73.99999999999999,73.99999999999999, +73.0,73.0,73.0, +72.0,72.0,72.0, +71.0,71.0,71.0, +70.0,70.0,70.0, +69.00000000000001,69.00000000000001,69.00000000000001, +68.00000000000001,68.00000000000001,68.00000000000001, +66.99999999999999,66.99999999999999,66.99999999999999, +65.99999999999999,65.99999999999999,65.99999999999999, +65.0,65.0,65.0, +64.0,64.0,64.0, +63.0,63.0,63.0, +62.00000000000001,62.00000000000001,62.00000000000001, +61.00000000000001,61.00000000000001,61.00000000000001, +60.000000000000014,60.000000000000014,60.000000000000014, +59.000000000000014,59.000000000000014,59.000000000000014, +57.99999999999999,57.99999999999999,57.99999999999999, +56.99999999999999,56.99999999999999,56.99999999999999, +56.0,56.0,56.0, +55.0,55.0,55.0, +54.00000000000001,54.00000000000001,54.00000000000001, +53.00000000000001,53.00000000000001,53.00000000000001, +52.000000000000014,52.000000000000014,52.000000000000014, +50.999999999999986,50.999999999999986,50.999999999999986, +49.99999999999999,49.99999999999999,49.99999999999999, +48.99999999999999,48.99999999999999,48.99999999999999, +48.0,48.0,48.0, +47.0,47.0,47.0, +46.00000000000001,46.00000000000001,46.00000000000001, +45.00000000000001,45.00000000000001,45.00000000000001, +44.000000000000014,44.000000000000014,44.000000000000014, +43.000000000000014,43.000000000000014,43.000000000000014, +41.99999999999999,41.99999999999999,41.99999999999999, +40.99999999999999,40.99999999999999,40.99999999999999, +40.0,40.0,40.0, +39.0,39.0,39.0, +38.00000000000001,38.00000000000001,38.00000000000001, +37.00000000000001,37.00000000000001,37.00000000000001, +36.000000000000014,36.000000000000014,36.000000000000014, +34.999999999999986,34.999999999999986,34.999999999999986, +33.99999999999999,33.99999999999999,33.99999999999999, +32.99999999999999,32.99999999999999,32.99999999999999, +32.0,32.0,32.0, +31.000000000000004,31.000000000000004,31.000000000000004, +30.000000000000007,30.000000000000007,30.000000000000007, +29.00000000000001,29.00000000000001,29.00000000000001, +28.000000000000014,28.000000000000014,28.000000000000014, +27.000000000000018,27.000000000000018,27.000000000000018, +25.999999999999993,25.999999999999993,25.999999999999993, +24.999999999999996,24.999999999999996,24.999999999999996, +24.0,24.0,24.0, +23.000000000000004,23.000000000000004,23.000000000000004, +22.000000000000007,22.000000000000007,22.000000000000007, +21.00000000000001,21.00000000000001,21.00000000000001, +20.000000000000014,20.000000000000014,20.000000000000014, +18.99999999999999,18.99999999999999,18.99999999999999, +17.999999999999993,17.999999999999993,17.999999999999993, +16.999999999999996,16.999999999999996,16.999999999999996, +16.0,16.0,16.0, +15.000000000000004,15.000000000000004,15.000000000000004, +14.000000000000007,14.000000000000007,14.000000000000007, +13.00000000000001,13.00000000000001,13.00000000000001, +12.000000000000014,12.000000000000014,12.000000000000014, +11.000000000000018,11.000000000000018,11.000000000000018, +9.999999999999993,9.999999999999993,9.999999999999993, +8.999999999999996,8.999999999999996,8.999999999999996, +8.0,8.0,8.0, +7.0000000000000036,7.0000000000000036,7.0000000000000036, +6.000000000000007,6.000000000000007,6.000000000000007, +5.000000000000011,5.000000000000011,5.000000000000011, +4.000000000000014,4.000000000000014,4.000000000000014, +2.9999999999999893,2.9999999999999893,2.9999999999999893, +1.999999999999993,1.999999999999993,1.999999999999993, +0.9999999999999964,0.9999999999999964,0.9999999999999964, +0.0,0.0,0.0, +} diff --git a/python/tests/reference/Colormap/binary.txt b/python/tests/reference/Colormap/binary.txt new file mode 100644 index 000000000..65e5e3d58 --- /dev/null +++ b/python/tests/reference/Colormap/binary.txt @@ -0,0 +1,258 @@ +# Creator: damask.Colormap 99.99.99-9999-pytest +R G B alpha +1.0 1.0 1.0 1.0 +0.996078431372549 0.996078431372549 0.996078431372549 1.0 +0.9921568627450981 0.9921568627450981 0.9921568627450981 1.0 +0.9882352941176471 0.9882352941176471 0.9882352941176471 1.0 +0.9843137254901961 0.9843137254901961 0.9843137254901961 1.0 +0.9803921568627451 0.9803921568627451 0.9803921568627451 1.0 +0.9764705882352941 0.9764705882352941 0.9764705882352941 1.0 +0.9725490196078431 0.9725490196078431 0.9725490196078431 1.0 +0.9686274509803922 0.9686274509803922 0.9686274509803922 1.0 +0.9647058823529412 0.9647058823529412 0.9647058823529412 1.0 +0.9607843137254902 0.9607843137254902 0.9607843137254902 1.0 +0.9568627450980393 0.9568627450980393 0.9568627450980393 1.0 +0.9529411764705882 0.9529411764705882 0.9529411764705882 1.0 +0.9490196078431372 0.9490196078431372 0.9490196078431372 1.0 +0.9450980392156862 0.9450980392156862 0.9450980392156862 1.0 +0.9411764705882353 0.9411764705882353 0.9411764705882353 1.0 +0.9372549019607843 0.9372549019607843 0.9372549019607843 1.0 +0.9333333333333333 0.9333333333333333 0.9333333333333333 1.0 +0.9294117647058824 0.9294117647058824 0.9294117647058824 1.0 +0.9254901960784314 0.9254901960784314 0.9254901960784314 1.0 +0.9215686274509804 0.9215686274509804 0.9215686274509804 1.0 +0.9176470588235294 0.9176470588235294 0.9176470588235294 1.0 +0.9137254901960784 0.9137254901960784 0.9137254901960784 1.0 +0.9098039215686274 0.9098039215686274 0.9098039215686274 1.0 +0.9058823529411765 0.9058823529411765 0.9058823529411765 1.0 +0.9019607843137255 0.9019607843137255 0.9019607843137255 1.0 +0.8980392156862745 0.8980392156862745 0.8980392156862745 1.0 +0.8941176470588236 0.8941176470588236 0.8941176470588236 1.0 +0.8901960784313725 0.8901960784313725 0.8901960784313725 1.0 +0.8862745098039215 0.8862745098039215 0.8862745098039215 1.0 +0.8823529411764706 0.8823529411764706 0.8823529411764706 1.0 +0.8784313725490196 0.8784313725490196 0.8784313725490196 1.0 +0.8745098039215686 0.8745098039215686 0.8745098039215686 1.0 +0.8705882352941177 0.8705882352941177 0.8705882352941177 1.0 +0.8666666666666667 0.8666666666666667 0.8666666666666667 1.0 +0.8627450980392157 0.8627450980392157 0.8627450980392157 1.0 +0.8588235294117648 0.8588235294117648 0.8588235294117648 1.0 +0.8549019607843138 0.8549019607843138 0.8549019607843138 1.0 +0.8509803921568627 0.8509803921568627 0.8509803921568627 1.0 +0.8470588235294118 0.8470588235294118 0.8470588235294118 1.0 +0.8431372549019608 0.8431372549019608 0.8431372549019608 1.0 +0.8392156862745098 0.8392156862745098 0.8392156862745098 1.0 +0.8352941176470589 0.8352941176470589 0.8352941176470589 1.0 +0.8313725490196078 0.8313725490196078 0.8313725490196078 1.0 +0.8274509803921568 0.8274509803921568 0.8274509803921568 1.0 +0.8235294117647058 0.8235294117647058 0.8235294117647058 1.0 +0.8196078431372549 0.8196078431372549 0.8196078431372549 1.0 +0.8156862745098039 0.8156862745098039 0.8156862745098039 1.0 +0.8117647058823529 0.8117647058823529 0.8117647058823529 1.0 +0.807843137254902 0.807843137254902 0.807843137254902 1.0 +0.803921568627451 0.803921568627451 0.803921568627451 1.0 +0.8 0.8 0.8 1.0 +0.7960784313725491 0.7960784313725491 0.7960784313725491 1.0 +0.7921568627450981 0.7921568627450981 0.7921568627450981 1.0 +0.788235294117647 0.788235294117647 0.788235294117647 1.0 +0.7843137254901961 0.7843137254901961 0.7843137254901961 1.0 +0.7803921568627451 0.7803921568627451 0.7803921568627451 1.0 +0.7764705882352941 0.7764705882352941 0.7764705882352941 1.0 +0.7725490196078432 0.7725490196078432 0.7725490196078432 1.0 +0.7686274509803921 0.7686274509803921 0.7686274509803921 1.0 +0.7647058823529411 0.7647058823529411 0.7647058823529411 1.0 +0.7607843137254902 0.7607843137254902 0.7607843137254902 1.0 +0.7568627450980392 0.7568627450980392 0.7568627450980392 1.0 +0.7529411764705882 0.7529411764705882 0.7529411764705882 1.0 +0.7490196078431373 0.7490196078431373 0.7490196078431373 1.0 +0.7450980392156863 0.7450980392156863 0.7450980392156863 1.0 +0.7411764705882353 0.7411764705882353 0.7411764705882353 1.0 +0.7372549019607844 0.7372549019607844 0.7372549019607844 1.0 +0.7333333333333334 0.7333333333333334 0.7333333333333334 1.0 +0.7294117647058824 0.7294117647058824 0.7294117647058824 1.0 +0.7254901960784313 0.7254901960784313 0.7254901960784313 1.0 +0.7215686274509804 0.7215686274509804 0.7215686274509804 1.0 +0.7176470588235294 0.7176470588235294 0.7176470588235294 1.0 +0.7137254901960784 0.7137254901960784 0.7137254901960784 1.0 +0.7098039215686275 0.7098039215686275 0.7098039215686275 1.0 +0.7058823529411764 0.7058823529411764 0.7058823529411764 1.0 +0.7019607843137254 0.7019607843137254 0.7019607843137254 1.0 +0.6980392156862745 0.6980392156862745 0.6980392156862745 1.0 +0.6941176470588235 0.6941176470588235 0.6941176470588235 1.0 +0.6901960784313725 0.6901960784313725 0.6901960784313725 1.0 +0.6862745098039216 0.6862745098039216 0.6862745098039216 1.0 +0.6823529411764706 0.6823529411764706 0.6823529411764706 1.0 +0.6784313725490196 0.6784313725490196 0.6784313725490196 1.0 +0.6745098039215687 0.6745098039215687 0.6745098039215687 1.0 +0.6705882352941177 0.6705882352941177 0.6705882352941177 1.0 +0.6666666666666667 0.6666666666666667 0.6666666666666667 1.0 +0.6627450980392157 0.6627450980392157 0.6627450980392157 1.0 +0.6588235294117647 0.6588235294117647 0.6588235294117647 1.0 +0.6549019607843137 0.6549019607843137 0.6549019607843137 1.0 +0.6509803921568628 0.6509803921568628 0.6509803921568628 1.0 +0.6470588235294118 0.6470588235294118 0.6470588235294118 1.0 +0.6431372549019607 0.6431372549019607 0.6431372549019607 1.0 +0.6392156862745098 0.6392156862745098 0.6392156862745098 1.0 +0.6352941176470588 0.6352941176470588 0.6352941176470588 1.0 +0.6313725490196078 0.6313725490196078 0.6313725490196078 1.0 +0.6274509803921569 0.6274509803921569 0.6274509803921569 1.0 +0.6235294117647059 0.6235294117647059 0.6235294117647059 1.0 +0.6196078431372549 0.6196078431372549 0.6196078431372549 1.0 +0.615686274509804 0.615686274509804 0.615686274509804 1.0 +0.611764705882353 0.611764705882353 0.611764705882353 1.0 +0.607843137254902 0.607843137254902 0.607843137254902 1.0 +0.603921568627451 0.603921568627451 0.603921568627451 1.0 +0.6 0.6 0.6 1.0 +0.596078431372549 0.596078431372549 0.596078431372549 1.0 +0.592156862745098 0.592156862745098 0.592156862745098 1.0 +0.5882352941176471 0.5882352941176471 0.5882352941176471 1.0 +0.5843137254901961 0.5843137254901961 0.5843137254901961 1.0 +0.580392156862745 0.580392156862745 0.580392156862745 1.0 +0.5764705882352941 0.5764705882352941 0.5764705882352941 1.0 +0.5725490196078431 0.5725490196078431 0.5725490196078431 1.0 +0.5686274509803921 0.5686274509803921 0.5686274509803921 1.0 +0.5647058823529412 0.5647058823529412 0.5647058823529412 1.0 +0.5607843137254902 0.5607843137254902 0.5607843137254902 1.0 +0.5568627450980392 0.5568627450980392 0.5568627450980392 1.0 +0.5529411764705883 0.5529411764705883 0.5529411764705883 1.0 +0.5490196078431373 0.5490196078431373 0.5490196078431373 1.0 +0.5450980392156863 0.5450980392156863 0.5450980392156863 1.0 +0.5411764705882354 0.5411764705882354 0.5411764705882354 1.0 +0.5372549019607843 0.5372549019607843 0.5372549019607843 1.0 +0.5333333333333333 0.5333333333333333 0.5333333333333333 1.0 +0.5294117647058824 0.5294117647058824 0.5294117647058824 1.0 +0.5254901960784314 0.5254901960784314 0.5254901960784314 1.0 +0.5215686274509804 0.5215686274509804 0.5215686274509804 1.0 +0.5176470588235293 0.5176470588235293 0.5176470588235293 1.0 +0.5137254901960784 0.5137254901960784 0.5137254901960784 1.0 +0.5098039215686274 0.5098039215686274 0.5098039215686274 1.0 +0.5058823529411764 0.5058823529411764 0.5058823529411764 1.0 +0.5019607843137255 0.5019607843137255 0.5019607843137255 1.0 +0.4980392156862745 0.4980392156862745 0.4980392156862745 1.0 +0.49411764705882355 0.49411764705882355 0.49411764705882355 1.0 +0.4901960784313726 0.4901960784313726 0.4901960784313726 1.0 +0.4862745098039216 0.4862745098039216 0.4862745098039216 1.0 +0.48235294117647065 0.48235294117647065 0.48235294117647065 1.0 +0.4784313725490196 0.4784313725490196 0.4784313725490196 1.0 +0.4745098039215686 0.4745098039215686 0.4745098039215686 1.0 +0.47058823529411764 0.47058823529411764 0.47058823529411764 1.0 +0.4666666666666667 0.4666666666666667 0.4666666666666667 1.0 +0.4627450980392157 0.4627450980392157 0.4627450980392157 1.0 +0.45882352941176474 0.45882352941176474 0.45882352941176474 1.0 +0.4549019607843138 0.4549019607843138 0.4549019607843138 1.0 +0.4509803921568627 0.4509803921568627 0.4509803921568627 1.0 +0.44705882352941173 0.44705882352941173 0.44705882352941173 1.0 +0.44313725490196076 0.44313725490196076 0.44313725490196076 1.0 +0.4392156862745098 0.4392156862745098 0.4392156862745098 1.0 +0.43529411764705883 0.43529411764705883 0.43529411764705883 1.0 +0.43137254901960786 0.43137254901960786 0.43137254901960786 1.0 +0.4274509803921569 0.4274509803921569 0.4274509803921569 1.0 +0.42352941176470593 0.42352941176470593 0.42352941176470593 1.0 +0.41960784313725497 0.41960784313725497 0.41960784313725497 1.0 +0.4156862745098039 0.4156862745098039 0.4156862745098039 1.0 +0.4117647058823529 0.4117647058823529 0.4117647058823529 1.0 +0.40784313725490196 0.40784313725490196 0.40784313725490196 1.0 +0.403921568627451 0.403921568627451 0.403921568627451 1.0 +0.4 0.4 0.4 1.0 +0.39607843137254906 0.39607843137254906 0.39607843137254906 1.0 +0.3921568627450981 0.3921568627450981 0.3921568627450981 1.0 +0.388235294117647 0.388235294117647 0.388235294117647 1.0 +0.38431372549019605 0.38431372549019605 0.38431372549019605 1.0 +0.3803921568627451 0.3803921568627451 0.3803921568627451 1.0 +0.3764705882352941 0.3764705882352941 0.3764705882352941 1.0 +0.37254901960784315 0.37254901960784315 0.37254901960784315 1.0 +0.3686274509803922 0.3686274509803922 0.3686274509803922 1.0 +0.3647058823529412 0.3647058823529412 0.3647058823529412 1.0 +0.36078431372549025 0.36078431372549025 0.36078431372549025 1.0 +0.3568627450980393 0.3568627450980393 0.3568627450980393 1.0 +0.3529411764705882 0.3529411764705882 0.3529411764705882 1.0 +0.34901960784313724 0.34901960784313724 0.34901960784313724 1.0 +0.34509803921568627 0.34509803921568627 0.34509803921568627 1.0 +0.3411764705882353 0.3411764705882353 0.3411764705882353 1.0 +0.33725490196078434 0.33725490196078434 0.33725490196078434 1.0 +0.33333333333333337 0.33333333333333337 0.33333333333333337 1.0 +0.3294117647058824 0.3294117647058824 0.3294117647058824 1.0 +0.3254901960784313 0.3254901960784313 0.3254901960784313 1.0 +0.32156862745098036 0.32156862745098036 0.32156862745098036 1.0 +0.3176470588235294 0.3176470588235294 0.3176470588235294 1.0 +0.3137254901960784 0.3137254901960784 0.3137254901960784 1.0 +0.30980392156862746 0.30980392156862746 0.30980392156862746 1.0 +0.3058823529411765 0.3058823529411765 0.3058823529411765 1.0 +0.3019607843137255 0.3019607843137255 0.3019607843137255 1.0 +0.29803921568627456 0.29803921568627456 0.29803921568627456 1.0 +0.2941176470588236 0.2941176470588236 0.2941176470588236 1.0 +0.2901960784313725 0.2901960784313725 0.2901960784313725 1.0 +0.28627450980392155 0.28627450980392155 0.28627450980392155 1.0 +0.2823529411764706 0.2823529411764706 0.2823529411764706 1.0 +0.2784313725490196 0.2784313725490196 0.2784313725490196 1.0 +0.27450980392156865 0.27450980392156865 0.27450980392156865 1.0 +0.2705882352941177 0.2705882352941177 0.2705882352941177 1.0 +0.2666666666666667 0.2666666666666667 0.2666666666666667 1.0 +0.26274509803921564 0.26274509803921564 0.26274509803921564 1.0 +0.2588235294117647 0.2588235294117647 0.2588235294117647 1.0 +0.2549019607843137 0.2549019607843137 0.2549019607843137 1.0 +0.25098039215686274 0.25098039215686274 0.25098039215686274 1.0 +0.24705882352941178 0.24705882352941178 0.24705882352941178 1.0 +0.2431372549019608 0.2431372549019608 0.2431372549019608 1.0 +0.23921568627450984 0.23921568627450984 0.23921568627450984 1.0 +0.23529411764705888 0.23529411764705888 0.23529411764705888 1.0 +0.2313725490196079 0.2313725490196079 0.2313725490196079 1.0 +0.22745098039215683 0.22745098039215683 0.22745098039215683 1.0 +0.22352941176470587 0.22352941176470587 0.22352941176470587 1.0 +0.2196078431372549 0.2196078431372549 0.2196078431372549 1.0 +0.21568627450980393 0.21568627450980393 0.21568627450980393 1.0 +0.21176470588235297 0.21176470588235297 0.21176470588235297 1.0 +0.207843137254902 0.207843137254902 0.207843137254902 1.0 +0.20392156862745103 0.20392156862745103 0.20392156862745103 1.0 +0.19999999999999996 0.19999999999999996 0.19999999999999996 1.0 +0.196078431372549 0.196078431372549 0.196078431372549 1.0 +0.19215686274509802 0.19215686274509802 0.19215686274509802 1.0 +0.18823529411764706 0.18823529411764706 0.18823529411764706 1.0 +0.1843137254901961 0.1843137254901961 0.1843137254901961 1.0 +0.18039215686274512 0.18039215686274512 0.18039215686274512 1.0 +0.17647058823529416 0.17647058823529416 0.17647058823529416 1.0 +0.1725490196078432 0.1725490196078432 0.1725490196078432 1.0 +0.16862745098039222 0.16862745098039222 0.16862745098039222 1.0 +0.16470588235294115 0.16470588235294115 0.16470588235294115 1.0 +0.16078431372549018 0.16078431372549018 0.16078431372549018 1.0 +0.1568627450980392 0.1568627450980392 0.1568627450980392 1.0 +0.15294117647058825 0.15294117647058825 0.15294117647058825 1.0 +0.14901960784313728 0.14901960784313728 0.14901960784313728 1.0 +0.14509803921568631 0.14509803921568631 0.14509803921568631 1.0 +0.14117647058823535 0.14117647058823535 0.14117647058823535 1.0 +0.13725490196078427 0.13725490196078427 0.13725490196078427 1.0 +0.1333333333333333 0.1333333333333333 0.1333333333333333 1.0 +0.12941176470588234 0.12941176470588234 0.12941176470588234 1.0 +0.12549019607843137 0.12549019607843137 0.12549019607843137 1.0 +0.1215686274509804 0.1215686274509804 0.1215686274509804 1.0 +0.11764705882352944 0.11764705882352944 0.11764705882352944 1.0 +0.11372549019607847 0.11372549019607847 0.11372549019607847 1.0 +0.1098039215686275 0.1098039215686275 0.1098039215686275 1.0 +0.10588235294117654 0.10588235294117654 0.10588235294117654 1.0 +0.10196078431372546 0.10196078431372546 0.10196078431372546 1.0 +0.0980392156862745 0.0980392156862745 0.0980392156862745 1.0 +0.09411764705882353 0.09411764705882353 0.09411764705882353 1.0 +0.09019607843137256 0.09019607843137256 0.09019607843137256 1.0 +0.0862745098039216 0.0862745098039216 0.0862745098039216 1.0 +0.08235294117647063 0.08235294117647063 0.08235294117647063 1.0 +0.07843137254901966 0.07843137254901966 0.07843137254901966 1.0 +0.07450980392156858 0.07450980392156858 0.07450980392156858 1.0 +0.07058823529411762 0.07058823529411762 0.07058823529411762 1.0 +0.06666666666666665 0.06666666666666665 0.06666666666666665 1.0 +0.06274509803921569 0.06274509803921569 0.06274509803921569 1.0 +0.05882352941176472 0.05882352941176472 0.05882352941176472 1.0 +0.05490196078431375 0.05490196078431375 0.05490196078431375 1.0 +0.050980392156862786 0.050980392156862786 0.050980392156862786 1.0 +0.04705882352941182 0.04705882352941182 0.04705882352941182 1.0 +0.04313725490196085 0.04313725490196085 0.04313725490196085 1.0 +0.039215686274509776 0.039215686274509776 0.039215686274509776 1.0 +0.03529411764705881 0.03529411764705881 0.03529411764705881 1.0 +0.03137254901960784 0.03137254901960784 0.03137254901960784 1.0 +0.027450980392156876 0.027450980392156876 0.027450980392156876 1.0 +0.02352941176470591 0.02352941176470591 0.02352941176470591 1.0 +0.019607843137254943 0.019607843137254943 0.019607843137254943 1.0 +0.015686274509803977 0.015686274509803977 0.015686274509803977 1.0 +0.0117647058823529 0.0117647058823529 0.0117647058823529 1.0 +0.007843137254901933 0.007843137254901933 0.007843137254901933 1.0 +0.0039215686274509665 0.0039215686274509665 0.0039215686274509665 1.0 +0.0 0.0 0.0 1.0 diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index f124c704e..b95d23a86 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -1,10 +1,18 @@ import os +import filecmp +import time import numpy as np import pytest +import damask from damask import Colormap +@pytest.fixture +def reference_dir(reference_dir_base): + """Directory containing reference results.""" + return reference_dir_base/'Colormap' + class TestColormap: def test_conversion(self): @@ -64,14 +72,14 @@ class TestColormap: assert np.allclose(Colormap._xyz2msh(xyz),msh,atol=1.e-6,rtol=0) - @pytest.mark.parametrize('format',['ASCII','paraview','GOM','gmsh']) + @pytest.mark.parametrize('format',['ASCII','paraview','GOM','Gmsh']) @pytest.mark.parametrize('model',['rgb','hsv','hsl','xyz','lab','msh']) def test_from_bounds(self,model,format,tmpdir): N = np.random.randint(2,256) c = Colormap.from_bounds(np.random.rand(3),np.random.rand(3),model=model,N=N) c.to_file(tmpdir/'color_out',format=format) - @pytest.mark.parametrize('format',['ASCII','paraview','GOM','gmsh']) + @pytest.mark.parametrize('format',['ASCII','paraview','GOM','Gmsh']) @pytest.mark.parametrize('name',['strain','gnuplot','Greys','PRGn','viridis']) def test_from_predefined(self,name,format,tmpdir): N = np.random.randint(2,256) @@ -82,7 +90,7 @@ class TestColormap: @pytest.mark.parametrize('format,name',[('ASCII','test.txt'), ('paraview','test.json'), ('GOM','test.legend'), - ('gmsh','test.msh') + ('Gmsh','test.msh') ]) def test_write_filehandle(self,format,name,tmpdir): c = Colormap.from_predefined('Dark2') @@ -113,4 +121,21 @@ class TestColormap: def test_list(self): Colormap.list_predefined() + @pytest.mark.parametrize('format,ext',[('ASCII','.txt'), + ('paraview','.json'), + ('GOM','.legend'), + ('Gmsh','.msh') + ]) + def test_compare_reference(self,format,ext,tmpdir,reference_dir,update,monkeypatch): + monkeypatch.setattr(damask, 'version', '99.99.99-9999-pytest') + name = 'binary' + c = Colormap.from_predefined(name) + if update: + os.chdir(reference_dir) + c.to_file(format=format) + else: + os.chdir(tmpdir) + c.to_file(format=format) + time.sleep(.5) + assert filecmp.cmp(tmpdir/(name+ext),reference_dir/(name+ext)) From b3f5ee022ace521fde51c1e35104dfafcd10402c Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 28 Jun 2020 11:40:19 +0200 Subject: [PATCH 13/28] unified style --- python/damask/_colormap.py | 6 +++--- python/damask/_result.py | 4 ++-- python/damask/_vtk.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index d3ed4b12e..f354af0a3 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -7,7 +7,7 @@ import matplotlib.pyplot as plt from matplotlib import cm import damask -from damask import Table +from . import Table _eps = 216./24389. _kappa = 24389./27. @@ -209,7 +209,7 @@ class Colormap(mpl.colors.ListedColormap): colors+=[i]+c out = [{ - 'Creator':f'damask.Colormap {damask.version}', + 'Creator':f'damask.Colormap v{damask.version}', 'ColorSpace':'RGB', 'Name':colormap.name, 'DefaultMap':True, @@ -226,7 +226,7 @@ class Colormap(mpl.colors.ListedColormap): """Write colormap to ASCII table.""" labels = {'R':(1,),'G':(1,),'B':(1,)} if colormap.colors.shape[1] == 4: labels['alpha']=(1,) - t = Table(colormap.colors,labels,f'Creator: damask.Colormap {damask.version}') + t = Table(colormap.colors,labels,f'Creator: damask.Colormap v{damask.version}') if fhandle is None: with open(colormap.name.replace(' ','_')+'.txt', 'w') as f: diff --git a/python/damask/_result.py b/python/damask/_result.py index 354c1c3f7..472355ae2 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -12,6 +12,7 @@ from functools import partial import h5py import numpy as np +import damask from . import VTK from . import Table from . import Rotation @@ -20,7 +21,6 @@ from . import Environment from . import grid_filters from . import mechanics from . import util -from . import version class Result: @@ -1090,7 +1090,7 @@ class Result: for l,v in result[1]['meta'].items(): dataset.attrs[l]=v.encode() - creator = f"damask.Result.{dataset.attrs['Creator'].decode()} v{version}" + creator = f"damask.Result.{dataset.attrs['Creator'].decode()} v{damask.version}" dataset.attrs['Creator'] = creator.encode() except (OSError,RuntimeError) as err: diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index f4855820e..0b9fde387 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -6,9 +6,9 @@ import vtk from vtk.util.numpy_support import numpy_to_vtk as np_to_vtk from vtk.util.numpy_support import numpy_to_vtkIdTypeArray as np_to_vtkIdTypeArray +import damask from . import Table from . import Environment -from . import version class VTK: @@ -214,7 +214,7 @@ class VTK: def __repr__(self): """ASCII representation of the VTK data.""" writer = vtk.vtkDataSetWriter() - writer.SetHeader(f'# DAMASK.VTK v{version}') + writer.SetHeader(f'# damask.VTK v{damask.version}') writer.WriteToOutputStringOn() writer.SetInputData(self.geom) writer.Write() From 1cfa6d44d9fb2332de356a32b05b1b9e9a7580d1 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 28 Jun 2020 11:50:28 +0200 Subject: [PATCH 14/28] dummy version could be useful for other tests note that monkey patching requires direct access to damask.version in the respective modules. 'from xx import yy' creates a copy (at least for the version string). --- python/tests/conftest.py | 5 +++++ python/tests/test_Colormap.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 411c07a8c..a7bc59f98 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -2,6 +2,11 @@ import os import pytest +# Use to monkeypatch damask.version (for comparsion to reference files that contain version information) +def pytest_configure(): + pytest.dummy_version = '99.99.99-9999-pytest' + + def pytest_addoption(parser): parser.addoption("--update", action="store_true", diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index b95d23a86..8d3d51018 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -127,7 +127,7 @@ class TestColormap: ('Gmsh','.msh') ]) def test_compare_reference(self,format,ext,tmpdir,reference_dir,update,monkeypatch): - monkeypatch.setattr(damask, 'version', '99.99.99-9999-pytest') + monkeypatch.setattr(damask, 'version', pytest.dummy_version) name = 'binary' c = Colormap.from_predefined(name) if update: From a657125840cb63c0f8e7614f04332dc5d7515c11 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 28 Jun 2020 19:30:23 +0200 Subject: [PATCH 15/28] standard version string --- python/tests/reference/Colormap/binary.json | 2 +- python/tests/reference/Colormap/binary.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tests/reference/Colormap/binary.json b/python/tests/reference/Colormap/binary.json index d56f1232e..c71d3649b 100644 --- a/python/tests/reference/Colormap/binary.json +++ b/python/tests/reference/Colormap/binary.json @@ -1,6 +1,6 @@ [ { - "Creator": "damask.Colormap 99.99.99-9999-pytest", + "Creator": "damask.Colormap v99.99.99-9999-pytest", "ColorSpace": "RGB", "Name": "binary", "DefaultMap": true, diff --git a/python/tests/reference/Colormap/binary.txt b/python/tests/reference/Colormap/binary.txt index 65e5e3d58..817350aee 100644 --- a/python/tests/reference/Colormap/binary.txt +++ b/python/tests/reference/Colormap/binary.txt @@ -1,4 +1,4 @@ -# Creator: damask.Colormap 99.99.99-9999-pytest +# Creator: damask.Colormap v99.99.99-9999-pytest R G B alpha 1.0 1.0 1.0 1.0 0.996078431372549 0.996078431372549 0.996078431372549 1.0 From 2d0c680dafb4a1f131e2c885f86c2a91ab00eea3 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 29 Jun 2020 07:30:42 +0200 Subject: [PATCH 16/28] useful information --- python/damask/_colormap.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index f354af0a3..d60f7f6c6 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -127,7 +127,19 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def list_predefined(): - """List predefined colormaps by category.""" + """ + List predefined colormaps by category. + + References + ---------- + .. [1] DAMASK colormap theory + https://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf + .. [2] DAMASK colormaps first use + https://doi.org/10.1016/j.ijplas.2012.09.012 + .. [3] Matplotlib colormaps overview + https://matplotlib.org/tutorials/colors/colormaps.html + + """ print('DAMASK colormaps') print(' '+', '.join(Colormap._predefined_DAMASK.keys())) for cat in Colormap._predefined_mpl: From 97ca1b1a9bc6b58a3994052caf85e72ea901fd70 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 29 Jun 2020 21:50:33 -0400 Subject: [PATCH 17/28] try wxPython before tkinter, recent macOS otherwise fails --- python/damask/_environment.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/python/damask/_environment.py b/python/damask/_environment.py index 7d12050aa..73fe6c035 100644 --- a/python/damask/_environment.py +++ b/python/damask/_environment.py @@ -1,19 +1,25 @@ import os from pathlib import Path -import tkinter class Environment: def __init__(self): """Read and provide values of DAMASK configuration.""" + self.screen_width = 1024 + self.screen_height = 768 try: - tk = tkinter.Tk() - self.screen_width = tk.winfo_screenwidth() - self.screen_height = tk.winfo_screenheight() - tk.destroy() - except tkinter.TclError: - self.screen_width = 1024 - self.screen_height = 768 + import wx + app = wx.App(False) + self.screenwidth, self.screenheight = wx.GetDisplaySize() + except ImportError: + try: + import tkinter + tk = tkinter.Tk() + self.screen_width = tk.winfo_screenwidth() + self.screen_height = tk.winfo_screenheight() + tk.destroy() + except: + pass @property def options(self): From 39aac76859a39bcbf11e5a626cdd01c58c0fb155 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 29 Jun 2020 21:58:41 -0400 Subject: [PATCH 18/28] __add__, from_range, fixed missing np.array(colors), show peppered... --- python/damask/_colormap.py | 57 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index d60f7f6c6..442ee1b63 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -19,11 +19,15 @@ _ref_white = np.array([.95047, 1.00000, 1.08883]) class Colormap(mpl.colors.ListedColormap): + def __add__(self,other): + """Concatenate colormaps.""" + return Colormap(np.vstack((self.colors,other.colors)), + f'{self.name}+{other.name}') @staticmethod - def from_bounds(low,high,name='DAMASK colormap',N=256,model='rgb'): + def from_range(low,high,name='DAMASK colormap',N=256,model='rgb'): """ - Create a perceptually uniform colormap from given bounds. + Create a perceptually uniform colormap between given (inclusive) bounds. Colors are internally stored as R(ed) G(green) B(lue) values. The colormap can be used in matplotlib/seaborn or exported to @@ -50,35 +54,34 @@ class Colormap(mpl.colors.ListedColormap): - 'msh': Msh (for perceptual uniform interpolation). """ - low_,high_ = map(np.array,[low,high]) - low_high = np.vstack((low_,high)) + low_high = np.vstack((low,high)) if model.lower() == 'rgb': if np.any(low_high<0) or np.any(low_high>1): - raise ValueError(f'RGB color out of range {low} {high}.') + raise ValueError(f'RGB color {low} | {high} are out of range.') - low_,high_ = map(Colormap._rgb2msh,[low_,high_]) + low_,high_ = map(Colormap._rgb2msh,low_high) elif model.lower() == 'hsv': if np.any(low_high<0) or np.any(low_high[:,1:3]>1) or np.any(low_high[:,0]>360): - raise ValueError(f'HSV color out of range {low} {high}.') + raise ValueError(f'HSV color {low} | {high} are out of range.') - low_,high_ = map(Colormap._hsv2msh,[low_,high_]) + low_,high_ = map(Colormap._hsv2msh,low_high) elif model.lower() == 'hsl': if np.any(low_high<0) or np.any(low_high[:,1:3]>1) or np.any(low_high[:,0]>360): - raise ValueError(f'HSL color out of range {low} {high}.') + raise ValueError(f'HSL color {low} | {high} are out of range.') - low_,high_ = map(Colormap._hsl2msh,[low_,high_]) + low_,high_ = map(Colormap._hsl2msh,low_high) elif model.lower() == 'xyz': - low_,high_ = map(Colormap._xyz2msh,[low_,high_]) + low_,high_ = map(Colormap._xyz2msh,low_high) elif model.lower() == 'lab': if np.any(low_high[:,0]<0): - raise ValueError(f'CIE Lab color out of range {low} {high}.') + raise ValueError(f'CIE Lab color {low} | {high} are out of range.') - low_,high_ = map(Colormap._lab2msh,[low_,high_]) + low_,high_ = map(Colormap._lab2msh,low_high) elif model.lower() == 'msh': pass @@ -122,7 +125,7 @@ class Colormap(mpl.colors.ListedColormap): # DAMASK presets definition = Colormap._predefined_DAMASK[name] - return Colormap.from_bounds(definition['low'],definition['high'],name,N) + return Colormap.from_range(definition['low'],definition['high'],name,N) @staticmethod @@ -147,24 +150,27 @@ class Colormap(mpl.colors.ListedColormap): print(' '+', '.join(cat[1])) - def show(self): - """Show colormap in window.""" - fig, ax = plt.subplots(figsize=(10,1)) - ax.set_axis_off() - im = ax.imshow(np.broadcast_to(np.linspace(0,1,640).reshape(1,-1),(64,640)),cmap=self) # noqa - fig.canvas.set_window_title(self.name) + def show(self,aspect=10,vertical=False): + """Show colormap as matplotlib figure.""" + fig = plt.figure(figsize=(5/aspect,5) if vertical else (5,5/aspect)) + ax1 = fig.add_axes([0, 0, 1, 1]) + ax1.set_axis_off() + ax1.imshow(np.linspace(1 if vertical else 0, + 0 if vertical else 1, + self.N).reshape((-1,1) if vertical else (1,-1)), + aspect='auto', cmap=self, interpolation='nearest') plt.show() def reversed(self,name=None): """ - Make a reversed instance of the Colormap. + Make a reversed instance of the colormap. Parameters ---------- name : str, optional - The name for the reversed colormap. If it's None - the name will be the name of the parent colormap + "_r". + The name for the reversed colormap. + A name of None will be replaced by the name of the parent colormap + "_r". Returns ------- @@ -173,7 +179,7 @@ class Colormap(mpl.colors.ListedColormap): """ rev = super(Colormap,self).reversed(name) - return Colormap(rev.colors,rev.name) + return Colormap(np.array(rev.colors),rev.name[:-4] if rev.name.endswith('_r_r') else rev.name) def to_file(self,fname=None,format='ParaView'): @@ -236,8 +242,7 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def _export_ASCII(colormap,fhandle=None): """Write colormap to ASCII table.""" - labels = {'R':(1,),'G':(1,),'B':(1,)} - if colormap.colors.shape[1] == 4: labels['alpha']=(1,) + labels = {'RGBA':4} if colormap.colors.shape[1] == 4 else {'RGB': 3} t = Table(colormap.colors,labels,f'Creator: damask.Colormap v{damask.version}') if fhandle is None: From d3b3d628b290bcd33211146abf4657dbf089496d Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 29 Jun 2020 22:06:40 -0400 Subject: [PATCH 19/28] PEP conformity... --- python/damask/_environment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/damask/_environment.py b/python/damask/_environment.py index 73fe6c035..29c0f45c7 100644 --- a/python/damask/_environment.py +++ b/python/damask/_environment.py @@ -9,7 +9,7 @@ class Environment: self.screen_height = 768 try: import wx - app = wx.App(False) + _ = wx.App(False) # noqa self.screenwidth, self.screenheight = wx.GetDisplaySize() except ImportError: try: @@ -18,7 +18,7 @@ class Environment: self.screen_width = tk.winfo_screenwidth() self.screen_height = tk.winfo_screenheight() tk.destroy() - except: + except Exception as e: pass @property From decbe8074a8eef7c3a86217874ddd8f7c39f68e9 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 29 Jun 2020 22:22:21 -0400 Subject: [PATCH 20/28] not using unassigned variable --- python/damask/_colormap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 442ee1b63..ebfd241d0 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -89,7 +89,7 @@ class Colormap(mpl.colors.ListedColormap): else: raise ValueError(f'Invalid color model: {model}.') - msh = map(functools.partial(Colormap._interpolate_msh,low=low_,high=high_),np.linspace(0,1,N)) + msh = map(functools.partial(Colormap._interpolate_msh,low=low_high[0],high=low_high[1]),np.linspace(0,1,N)) rgb = np.array(list(map(Colormap._msh2rgb,msh))) return Colormap(rgb,name=name) From 8dc87023d11f27818cfe97dbc737ff6cc3d44fff Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 29 Jun 2020 22:23:24 -0400 Subject: [PATCH 21/28] test from_range; update ASCII colormap labels (i_RGBA) --- python/tests/reference/Colormap/binary.txt | 2 +- python/tests/test_Colormap.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/tests/reference/Colormap/binary.txt b/python/tests/reference/Colormap/binary.txt index 817350aee..976c0202a 100644 --- a/python/tests/reference/Colormap/binary.txt +++ b/python/tests/reference/Colormap/binary.txt @@ -1,5 +1,5 @@ # Creator: damask.Colormap v99.99.99-9999-pytest -R G B alpha +1_RGBA 2_RGBA 3_RGBA 4_RGBA 1.0 1.0 1.0 1.0 0.996078431372549 0.996078431372549 0.996078431372549 1.0 0.9921568627450981 0.9921568627450981 0.9921568627450981 1.0 diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index 8d3d51018..fcc2eca81 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -74,9 +74,9 @@ class TestColormap: @pytest.mark.parametrize('format',['ASCII','paraview','GOM','Gmsh']) @pytest.mark.parametrize('model',['rgb','hsv','hsl','xyz','lab','msh']) - def test_from_bounds(self,model,format,tmpdir): + def test_from_range(self,model,format,tmpdir): N = np.random.randint(2,256) - c = Colormap.from_bounds(np.random.rand(3),np.random.rand(3),model=model,N=N) + c = Colormap.from_range(np.random.rand(3),np.random.rand(3),model=model,N=N) c.to_file(tmpdir/'color_out',format=format) @pytest.mark.parametrize('format',['ASCII','paraview','GOM','Gmsh']) @@ -110,7 +110,7 @@ class TestColormap: @pytest.mark.parametrize('model',['rgb','hsv','hsl','lab','invalid']) def test_invalid_color(self,model): with pytest.raises(ValueError): - c = Colormap.from_bounds(-2.+np.random.rand(3),np.random.rand(3),N=10,model=model) # noqa + c = Colormap.from_range(-2.+np.random.rand(3),np.random.rand(3),N=10,model=model) # noqa def test_reversed(self): c_1 = Colormap.from_predefined('stress') From c8adfae0fa20baaff0f009be59530c13c45ae341 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 30 Jun 2020 07:16:49 +0200 Subject: [PATCH 22/28] bugfix: wrong variables used --- python/damask/_colormap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index ebfd241d0..964f22d85 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -84,12 +84,12 @@ class Colormap(mpl.colors.ListedColormap): low_,high_ = map(Colormap._lab2msh,low_high) elif model.lower() == 'msh': - pass + low_,high_ = low_high[0],low_high[1] else: raise ValueError(f'Invalid color model: {model}.') - msh = map(functools.partial(Colormap._interpolate_msh,low=low_high[0],high=low_high[1]),np.linspace(0,1,N)) + msh = map(functools.partial(Colormap._interpolate_msh,low=low_,high=high_),np.linspace(0,1,N)) rgb = np.array(list(map(Colormap._msh2rgb,msh))) return Colormap(rgb,name=name) From b88becb9d089e10f1e7714182fbc291e987f5e1e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 2 Jul 2020 08:25:35 +0200 Subject: [PATCH 23/28] don't go out of focus during initialization --- python/damask/_environment.py | 22 +++++++++++++++------- python/damask/_vtk.py | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/python/damask/_environment.py b/python/damask/_environment.py index 29c0f45c7..7b8b8487e 100644 --- a/python/damask/_environment.py +++ b/python/damask/_environment.py @@ -3,23 +3,30 @@ from pathlib import Path class Environment: + # ToDo: Probably, we don't need a class (just a module with a few functions) def __init__(self): - """Read and provide values of DAMASK configuration.""" - self.screen_width = 1024 - self.screen_height = 768 + """Do Nothing.""" + pass + + @property + def screen_size(self): + width = 1024 + height = 768 try: import wx - _ = wx.App(False) # noqa - self.screenwidth, self.screenheight = wx.GetDisplaySize() + _ = wx.App(False) # noqa + width, height = wx.GetDisplaySize() except ImportError: try: import tkinter tk = tkinter.Tk() - self.screen_width = tk.winfo_screenwidth() - self.screen_height = tk.winfo_screenheight() + width = tk.winfo_screenwidth() + height = tk.winfo_screenheight() tk.destroy() except Exception as e: pass + return (width,height) + @property def options(self): @@ -32,6 +39,7 @@ class Environment: return options + @property def root_dir(self): """Return DAMASK root path.""" diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index 49a4f8958..1e99f83f3 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -242,7 +242,7 @@ class VTK: ren.AddActor(actor) ren.SetBackground(0.2,0.2,0.2) - window.SetSize(Environment().screen_width,Environment().screen_height) + window.SetSize(Environment().screen_size[0],Environment().screen_size[1]) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(window) From 3b72d0ec725450d576a6d2fa3ea310f20d471164 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 2 Jul 2020 10:13:47 -0400 Subject: [PATCH 24/28] added __invert__ method to reverse colormap --- python/damask/_colormap.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 964f22d85..2533d4d36 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -24,6 +24,10 @@ class Colormap(mpl.colors.ListedColormap): return Colormap(np.vstack((self.colors,other.colors)), f'{self.name}+{other.name}') + def __invert__(self): + """Return inverted colormap.""" + return self.reversed() + @staticmethod def from_range(low,high,name='DAMASK colormap',N=256,model='rgb'): """ From f3ff2e741288984d6c4182453f2526eaaab1fbf4 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 2 Jul 2020 10:25:04 -0400 Subject: [PATCH 25/28] added __iadd__ method --- python/damask/_colormap.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 2533d4d36..c15befcfa 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -24,6 +24,11 @@ class Colormap(mpl.colors.ListedColormap): return Colormap(np.vstack((self.colors,other.colors)), f'{self.name}+{other.name}') + def __iadd__(self,other): + """Concatenate colormaps.""" + return Colormap(np.vstack((self.colors,other.colors)), + f'{self.name}+{other.name}') + def __invert__(self): """Return inverted colormap.""" return self.reversed() From 5a96708f4143c07d15e74ca938bc4e648296deb9 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 2 Jul 2020 10:26:04 -0400 Subject: [PATCH 26/28] added __iadd__ method --- python/damask/_colormap.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index c15befcfa..9d57f234b 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -26,8 +26,7 @@ class Colormap(mpl.colors.ListedColormap): def __iadd__(self,other): """Concatenate colormaps.""" - return Colormap(np.vstack((self.colors,other.colors)), - f'{self.name}+{other.name}') + return self.__add__(other) def __invert__(self): """Return inverted colormap.""" From 368a2419312097167bc53c2bd51cce152bf09f1e Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 2 Jul 2020 10:26:28 -0400 Subject: [PATCH 27/28] added testing of __iadd__ and __invert__ --- python/tests/test_Colormap.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index fcc2eca81..f288ffb24 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -118,6 +118,17 @@ class TestColormap: assert (not np.allclose(c_1.colors,c_2.colors)) and \ np.allclose(c_1.colors,c_2.reversed().colors) + def test_invert(self): + c_1 = Colormap.from_predefined('strain') + c_2 = ~c_1 + assert (not np.allclose(c_1.colors,c_2.colors)) and \ + np.allclose(c_1.colors,(~c_2).colors) + + def test_add(self): + c = Colormap.from_predefined('jet') + c += c + assert (np.allclose(c.colors[:len(c.colors)],c.colors[len(c.colors):])) + def test_list(self): Colormap.list_predefined() @@ -138,4 +149,3 @@ class TestColormap: c.to_file(format=format) time.sleep(.5) assert filecmp.cmp(tmpdir/(name+ext),reference_dir/(name+ext)) - From 81b3c103059fdc931623b274de6abf25cae24317 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 2 Jul 2020 10:37:57 -0400 Subject: [PATCH 28/28] removed ambiguous variable "l" --- python/tests/test_Colormap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index f288ffb24..fbe65e2bd 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -127,7 +127,7 @@ class TestColormap: def test_add(self): c = Colormap.from_predefined('jet') c += c - assert (np.allclose(c.colors[:len(c.colors)],c.colors[len(c.colors):])) + assert (np.allclose(c.colors[:len(c.colors)//2],c.colors[len(c.colors)//2:])) def test_list(self): Colormap.list_predefined()