From 8797282d37df5fdedef07bd17581fec28ecc09cf Mon Sep 17 00:00:00 2001 From: Daniel Otto de Mentock Date: Mon, 22 Nov 2021 17:15:22 +0100 Subject: [PATCH 1/7] added typehints for colormap module --- python/damask/_colormap.py | 94 +++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 8c897e6ab..b1970997c 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -14,6 +14,10 @@ from PIL import Image from . import util from . import Table +from typing import Sequence, Union, Optional, List, TextIO +from io import TextIOWrapper +import pathlib + _eps = 216./24389. _kappa = 24389./27. _ref_white = np.array([.95047, 1.00000, 1.08883]) # Observer = 2, Illuminant = D65 @@ -39,20 +43,20 @@ class Colormap(mpl.colors.ListedColormap): """ - def __add__(self,other): + def __add__(self, other: "Colormap") -> "Colormap": """Concatenate.""" return Colormap(np.vstack((self.colors,other.colors)), f'{self.name}+{other.name}') - def __iadd__(self,other): + def __iadd__(self, other: "Colormap") -> "Colormap": """Concatenate (in-place).""" return self.__add__(other) - def __invert__(self): + def __invert__(self) -> "Colormap": """Reverse.""" return self.reversed() - def __repr__(self): + def __repr__(self) -> "Colormap": """Show as matplotlib figure.""" fig = plt.figure(self.name,figsize=(5,.5)) ax1 = fig.add_axes([0, 0, 1, 1]) @@ -64,7 +68,11 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod - def from_range(low,high,name='DAMASK colormap',N=256,model='rgb'): + def from_range(low: Sequence[float], + high: Sequence[float], + name: str = 'DAMASK colormap', + N: int = 256, + model: str = 'rgb') -> "Colormap": """ Create a perceptually uniform colormap between given (inclusive) bounds. @@ -145,7 +153,7 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod - def from_predefined(name,N=256): + def from_predefined(name: str, N: int = 256) -> "Colormap": """ Select from a set of predefined colormaps. @@ -185,7 +193,10 @@ class Colormap(mpl.colors.ListedColormap): return Colormap.from_range(definition['low'],definition['high'],name,N) - def shade(self,field,bounds=None,gap=None): + def shade(self, + field: np.ndarray, + bounds: Optional[Sequence[float]] = None, + gap: Optional[np.ndarray] = None) -> Image: """ Generate PIL image of 2D field using colormap. @@ -226,7 +237,7 @@ class Colormap(mpl.colors.ListedColormap): mode='RGBA') - def reversed(self,name=None): + def reversed(self, name: str = None) -> "Colormap": """ Reverse. @@ -251,7 +262,7 @@ class Colormap(mpl.colors.ListedColormap): return Colormap(np.array(rev.colors),rev.name[:-4] if rev.name.endswith('_r_r') else rev.name) - def _get_file_handle(self,fname,extension): + def _get_file_handle(self, fname: Union[TextIOWrapper, str, pathlib.Path, None], ext: str) -> TextIO: """ Provide file handle. @@ -260,7 +271,7 @@ class Colormap(mpl.colors.ListedColormap): fname : file, str, pathlib.Path, or None Filename or filehandle, will be name of the colormap+extension if None. - extension: str + ext: str Extension of the filename. Returns @@ -269,18 +280,17 @@ class Colormap(mpl.colors.ListedColormap): File handle with write access. """ - if fname is None: - fhandle = open(self.name.replace(' ','_')+'.'+extension,'w',newline='\n') - else: - try: - fhandle = open(fname,'w',newline='\n') - except TypeError: - fhandle = fname + fname = pathlib.Path(self.name.replace(' ','_'))\ + .with_suffix(('' if ext is None or ext.startswith('.') else '.')+ext) if fname is None else fname + if isinstance(fname, (str,pathlib.Path)): + return open(fname, 'w', newline='\n') + if isinstance(fname, TextIOWrapper): + return fname - return fhandle + raise TypeError - def save_paraview(self,fname=None): + def save_paraview(self, fname: Optional[Union[TextIOWrapper, str, pathlib.Path]] = None): """ Save as JSON file for use in Paraview. @@ -291,7 +301,7 @@ class Colormap(mpl.colors.ListedColormap): consist of the name of the colormap and extension '.json'. """ - colors = [] + colors: List = [] for i,c in enumerate(np.round(self.colors,6).tolist()): colors+=[i]+c @@ -306,7 +316,7 @@ class Colormap(mpl.colors.ListedColormap): json.dump(out,self._get_file_handle(fname,'json'),indent=4) - def save_ASCII(self,fname=None): + def save_ASCII(self, fname: Union[TextIOWrapper, str, pathlib.Path] = None): """ Save as ASCII file. @@ -322,7 +332,7 @@ class Colormap(mpl.colors.ListedColormap): t.save(self._get_file_handle(fname,'txt')) - def save_GOM(self,fname=None): + def save_GOM(self, fname: Union[TextIOWrapper, str, pathlib.Path] = None): """ Save as ASCII file for use in GOM Aramis. @@ -343,7 +353,7 @@ class Colormap(mpl.colors.ListedColormap): self._get_file_handle(fname,'legend').write(GOM_str) - def save_gmsh(self,fname=None): + def save_gmsh(self, fname: Optional[Union[TextIOWrapper, str, pathlib.Path]] = None): """ Save as ASCII file for use in gmsh. @@ -362,7 +372,9 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod - def _interpolate_msh(frac,low,high): + def _interpolate_msh(frac, + low: Sequence[float], + high: Sequence[float]) -> np.ndarray: """ Interpolate in Msh color space. @@ -439,31 +451,31 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod - def _hsv2rgb(hsv): + def _hsv2rgb(hsv: Sequence[float]) -> np.ndarray: """H(ue) S(aturation) V(alue) to R(red) G(reen) B(lue).""" return np.array(colorsys.hsv_to_rgb(hsv[0]/360.,hsv[1],hsv[2])) @staticmethod - def _rgb2hsv(rgb): + def _rgb2hsv(rgb: Sequence[float]) -> np.ndarray: """R(ed) G(reen) B(lue) to H(ue) S(aturation) V(alue).""" h,s,v = colorsys.rgb_to_hsv(rgb[0],rgb[1],rgb[2]) return np.array([h*360,s,v]) @staticmethod - def _hsl2rgb(hsl): + def _hsl2rgb(hsl: Sequence[float]) -> np.ndarray: """H(ue) S(aturation) L(uminance) to R(red) G(reen) B(lue).""" return np.array(colorsys.hls_to_rgb(hsl[0]/360.,hsl[2],hsl[1])) @staticmethod - def _rgb2hsl(rgb): + def _rgb2hsl(rgb: Sequence[float]) -> np.ndarray: """R(ed) G(reen) B(lue) to H(ue) S(aturation) L(uminance).""" h,l,s = colorsys.rgb_to_hls(rgb[0],rgb[1],rgb[2]) return np.array([h*360,s,l]) @staticmethod - def _xyz2rgb(xyz): + def _xyz2rgb(xyz: np.ndarray) -> np.ndarray: """ CIE Xyz to R(ed) G(reen) B(lue). @@ -483,7 +495,7 @@ class Colormap(mpl.colors.ListedColormap): return np.clip(rgb,0.,1.) @staticmethod - def _rgb2xyz(rgb): + def _rgb2xyz(rgb: np.ndarray) -> np.ndarray: """ R(ed) G(reen) B(lue) to CIE Xyz. @@ -501,7 +513,7 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod - def _lab2xyz(lab,ref_white=None): + def _lab2xyz(lab: np.ndarray, ref_white: np.ndarray = None) -> np.ndarray: """ CIE Lab to CIE Xyz. @@ -520,7 +532,7 @@ class Colormap(mpl.colors.ListedColormap): ])*(ref_white if ref_white is not None else _ref_white) @staticmethod - def _xyz2lab(xyz,ref_white=None): + def _xyz2lab(xyz: np.ndarray, ref_white: Optional[np.ndarray] = None) -> np.ndarray: """ CIE Xyz to CIE Lab. @@ -540,7 +552,7 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod - def _lab2msh(lab): + def _lab2msh(lab: np.ndarray) -> np.ndarray: """ CIE Lab to Msh. @@ -558,7 +570,7 @@ class Colormap(mpl.colors.ListedColormap): ]) @staticmethod - def _msh2lab(msh): + def _msh2lab(msh: np.ndarray) -> np.ndarray: """ Msh to CIE Lab. @@ -575,29 +587,29 @@ class Colormap(mpl.colors.ListedColormap): ]) @staticmethod - def _lab2rgb(lab): + def _lab2rgb(lab: np.ndarray) -> np.ndarray: return Colormap._xyz2rgb(Colormap._lab2xyz(lab)) @staticmethod - def _rgb2lab(rgb): + def _rgb2lab(rgb: np.ndarray) -> np.ndarray: return Colormap._xyz2lab(Colormap._rgb2xyz(rgb)) @staticmethod - def _msh2rgb(msh): + def _msh2rgb(msh: np.ndarray) -> np.ndarray: return Colormap._lab2rgb(Colormap._msh2lab(msh)) @staticmethod - def _rgb2msh(rgb): + def _rgb2msh(rgb: np.ndarray) -> np.ndarray: return Colormap._lab2msh(Colormap._rgb2lab(rgb)) @staticmethod - def _hsv2msh(hsv): + def _hsv2msh(hsv: np.ndarray) -> np.ndarray: return Colormap._rgb2msh(Colormap._hsv2rgb(hsv)) @staticmethod - def _hsl2msh(hsl): + def _hsl2msh(hsl: np.ndarray) -> np.ndarray: return Colormap._rgb2msh(Colormap._hsl2rgb(hsl)) @staticmethod - def _xyz2msh(xyz): + def _xyz2msh(xyz: np.ndarray) -> np.ndarray: return Colormap._lab2msh(Colormap._xyz2lab(xyz)) From 3410a8d4cba00b678e55ab697717ea656be839ef Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 23 Nov 2021 16:34:50 +0100 Subject: [PATCH 2/7] follow order of imports - python standard library - third party - DAMASK internal --- python/damask/_colormap.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index b1970997c..0db6cb2c1 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -2,6 +2,10 @@ import os import json import functools import colorsys +from pathlib import Path +from typing import Sequence, Union, Optional, List, TextIO +from io import TextIOWrapper + import numpy as np import matplotlib as mpl @@ -14,10 +18,6 @@ from PIL import Image from . import util from . import Table -from typing import Sequence, Union, Optional, List, TextIO -from io import TextIOWrapper -import pathlib - _eps = 216./24389. _kappa = 24389./27. _ref_white = np.array([.95047, 1.00000, 1.08883]) # Observer = 2, Illuminant = D65 From 889ab8791468a746590d91c55436d6bb00e4fc98 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 23 Nov 2021 17:59:56 +0100 Subject: [PATCH 3/7] simplified and corrected - Optional not needed for 'None' argument - Use TextIO for typehints, TextIOWrapper seems to cause problems - Test for tuple/list input for public functions - internal functions that are always called with np.ndarray don't need to offer flexibility. They might work, but we don't guarantee anything. --- python/damask/_colormap.py | 44 ++++++++++++++++------------------- python/tests/test_Colormap.py | 5 ++++ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 0db6cb2c1..5032d6b18 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -3,8 +3,7 @@ import json import functools import colorsys from pathlib import Path -from typing import Sequence, Union, Optional, List, TextIO -from io import TextIOWrapper +from typing import Sequence, Union, List, TextIO import numpy as np @@ -56,7 +55,7 @@ class Colormap(mpl.colors.ListedColormap): """Reverse.""" return self.reversed() - def __repr__(self) -> "Colormap": + def __repr__(self) -> str: """Show as matplotlib figure.""" fig = plt.figure(self.name,figsize=(5,.5)) ax1 = fig.add_axes([0, 0, 1, 1]) @@ -195,8 +194,8 @@ class Colormap(mpl.colors.ListedColormap): def shade(self, field: np.ndarray, - bounds: Optional[Sequence[float]] = None, - gap: Optional[np.ndarray] = None) -> Image: + bounds: Sequence[float] = None, + gap: float = None) -> Image: """ Generate PIL image of 2D field using colormap. @@ -262,7 +261,7 @@ class Colormap(mpl.colors.ListedColormap): return Colormap(np.array(rev.colors),rev.name[:-4] if rev.name.endswith('_r_r') else rev.name) - def _get_file_handle(self, fname: Union[TextIOWrapper, str, pathlib.Path, None], ext: str) -> TextIO: + def _get_file_handle(self, fname: Union[TextIO, str, Path, None], ext: str) -> TextIO: """ Provide file handle. @@ -270,7 +269,6 @@ class Colormap(mpl.colors.ListedColormap): ---------- fname : file, str, pathlib.Path, or None Filename or filehandle, will be name of the colormap+extension if None. - ext: str Extension of the filename. @@ -280,17 +278,15 @@ class Colormap(mpl.colors.ListedColormap): File handle with write access. """ - fname = pathlib.Path(self.name.replace(' ','_'))\ - .with_suffix(('' if ext is None or ext.startswith('.') else '.')+ext) if fname is None else fname - if isinstance(fname, (str,pathlib.Path)): + if fname is None: + return open(self.name.replace(' ','_')+'.'+ext, 'w', newline='\n') + elif isinstance(fname, (str, Path)): return open(fname, 'w', newline='\n') - if isinstance(fname, TextIOWrapper): + else: return fname - raise TypeError - - def save_paraview(self, fname: Optional[Union[TextIOWrapper, str, pathlib.Path]] = None): + def save_paraview(self, fname: Union[TextIO, str, Path] = None): """ Save as JSON file for use in Paraview. @@ -316,7 +312,7 @@ class Colormap(mpl.colors.ListedColormap): json.dump(out,self._get_file_handle(fname,'json'),indent=4) - def save_ASCII(self, fname: Union[TextIOWrapper, str, pathlib.Path] = None): + def save_ASCII(self, fname: Union[TextIO, str, Path] = None): """ Save as ASCII file. @@ -332,7 +328,7 @@ class Colormap(mpl.colors.ListedColormap): t.save(self._get_file_handle(fname,'txt')) - def save_GOM(self, fname: Union[TextIOWrapper, str, pathlib.Path] = None): + def save_GOM(self, fname: Union[TextIO, str, Path] = None): """ Save as ASCII file for use in GOM Aramis. @@ -353,7 +349,7 @@ class Colormap(mpl.colors.ListedColormap): self._get_file_handle(fname,'legend').write(GOM_str) - def save_gmsh(self, fname: Optional[Union[TextIOWrapper, str, pathlib.Path]] = None): + def save_gmsh(self, fname: Union[TextIO, str, Path] = None): """ Save as ASCII file for use in gmsh. @@ -373,8 +369,8 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod def _interpolate_msh(frac, - low: Sequence[float], - high: Sequence[float]) -> np.ndarray: + low: np.ndarray, + high: np.ndarray) -> np.ndarray: """ Interpolate in Msh color space. @@ -451,24 +447,24 @@ class Colormap(mpl.colors.ListedColormap): @staticmethod - def _hsv2rgb(hsv: Sequence[float]) -> np.ndarray: + def _hsv2rgb(hsv: np.ndarray) -> np.ndarray: """H(ue) S(aturation) V(alue) to R(red) G(reen) B(lue).""" return np.array(colorsys.hsv_to_rgb(hsv[0]/360.,hsv[1],hsv[2])) @staticmethod - def _rgb2hsv(rgb: Sequence[float]) -> np.ndarray: + def _rgb2hsv(rgb: np.ndarray) -> np.ndarray: """R(ed) G(reen) B(lue) to H(ue) S(aturation) V(alue).""" h,s,v = colorsys.rgb_to_hsv(rgb[0],rgb[1],rgb[2]) return np.array([h*360,s,v]) @staticmethod - def _hsl2rgb(hsl: Sequence[float]) -> np.ndarray: + def _hsl2rgb(hsl: np.ndarray) -> np.ndarray: """H(ue) S(aturation) L(uminance) to R(red) G(reen) B(lue).""" return np.array(colorsys.hls_to_rgb(hsl[0]/360.,hsl[2],hsl[1])) @staticmethod - def _rgb2hsl(rgb: Sequence[float]) -> np.ndarray: + def _rgb2hsl(rgb: np.ndarray) -> np.ndarray: """R(ed) G(reen) B(lue) to H(ue) S(aturation) L(uminance).""" h,l,s = colorsys.rgb_to_hls(rgb[0],rgb[1],rgb[2]) return np.array([h*360,s,l]) @@ -532,7 +528,7 @@ class Colormap(mpl.colors.ListedColormap): ])*(ref_white if ref_white is not None else _ref_white) @staticmethod - def _xyz2lab(xyz: np.ndarray, ref_white: Optional[np.ndarray] = None) -> np.ndarray: + def _xyz2lab(xyz: np.ndarray, ref_white: np.ndarray = None) -> np.ndarray: """ CIE Xyz to CIE Lab. diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index 81bf8d2f6..46b096d19 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -77,6 +77,11 @@ class TestColormap: # xyz2msh assert np.allclose(Colormap._xyz2msh(xyz),msh,atol=1.e-6,rtol=0) + @pytest.mark.parametrize('low,high',[((0,0,0),(1,1,1)), + ([0,0,0],[1,1,1]), + (np.array([0,0,0]),np.array([1,1,1]))]) + def test_from_range_types(self,low,high): + c = Colormap.from_range(low,high) # noqa @pytest.mark.parametrize('format',['ASCII','paraview','GOM','gmsh']) @pytest.mark.parametrize('model',['rgb','hsv','hsl','xyz','lab','msh']) From 3393d32d9faee4f1ce549387155d2e83b7d499b3 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 23 Nov 2021 19:42:10 +0100 Subject: [PATCH 4/7] more sensible test vor sequence arguments --- python/tests/test_Colormap.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index 46b096d19..45f2cbc91 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -78,10 +78,9 @@ class TestColormap: assert np.allclose(Colormap._xyz2msh(xyz),msh,atol=1.e-6,rtol=0) @pytest.mark.parametrize('low,high',[((0,0,0),(1,1,1)), - ([0,0,0],[1,1,1]), - (np.array([0,0,0]),np.array([1,1,1]))]) + ([0,0,0],[1,1,1])]) def test_from_range_types(self,low,high): - c = Colormap.from_range(low,high) # noqa + assert Colormap.from_range(low,high) == Colormap.from_range(np.array(low),np.array(high)) @pytest.mark.parametrize('format',['ASCII','paraview','GOM','gmsh']) @pytest.mark.parametrize('model',['rgb','hsv','hsl','xyz','lab','msh']) From c23e9fb126269859b442bb50445dc0af8412305f Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 23 Nov 2021 20:34:19 +0100 Subject: [PATCH 5/7] __eq__ not implemented probably also not very much used outside tests --- python/tests/test_Colormap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/tests/test_Colormap.py b/python/tests/test_Colormap.py index 45f2cbc91..342165134 100644 --- a/python/tests/test_Colormap.py +++ b/python/tests/test_Colormap.py @@ -80,7 +80,9 @@ class TestColormap: @pytest.mark.parametrize('low,high',[((0,0,0),(1,1,1)), ([0,0,0],[1,1,1])]) def test_from_range_types(self,low,high): - assert Colormap.from_range(low,high) == Colormap.from_range(np.array(low),np.array(high)) + a = Colormap.from_range(low,high) + b = Colormap.from_range(np.array(low),np.array(high)) + assert np.all(a.colors == b.colors) @pytest.mark.parametrize('format',['ASCII','paraview','GOM','gmsh']) @pytest.mark.parametrize('model',['rgb','hsv','hsl','xyz','lab','msh']) From 757ba4dba298dd6239cbba44b34da161feb50011 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 24 Nov 2021 17:26:58 +0100 Subject: [PATCH 6/7] in-line with pathlib.Path --- 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 5032d6b18..22e44a43c 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -261,7 +261,7 @@ class Colormap(mpl.colors.ListedColormap): return Colormap(np.array(rev.colors),rev.name[:-4] if rev.name.endswith('_r_r') else rev.name) - def _get_file_handle(self, fname: Union[TextIO, str, Path, None], ext: str) -> TextIO: + def _get_file_handle(self, fname: Union[TextIO, str, Path, None], suffix: str) -> TextIO: """ Provide file handle. @@ -269,7 +269,7 @@ class Colormap(mpl.colors.ListedColormap): ---------- fname : file, str, pathlib.Path, or None Filename or filehandle, will be name of the colormap+extension if None. - ext: str + suffix: str Extension of the filename. Returns @@ -279,7 +279,7 @@ class Colormap(mpl.colors.ListedColormap): """ if fname is None: - return open(self.name.replace(' ','_')+'.'+ext, 'w', newline='\n') + return open(self.name.replace(' ','_')+suffix, 'w', newline='\n') elif isinstance(fname, (str, Path)): return open(fname, 'w', newline='\n') else: @@ -309,7 +309,7 @@ class Colormap(mpl.colors.ListedColormap): 'RGBPoints':colors }] - json.dump(out,self._get_file_handle(fname,'json'),indent=4) + json.dump(out,self._get_file_handle(fname,'.json'),indent=4) def save_ASCII(self, fname: Union[TextIO, str, Path] = None): @@ -325,7 +325,7 @@ class Colormap(mpl.colors.ListedColormap): """ labels = {'RGBA':4} if self.colors.shape[1] == 4 else {'RGB': 3} t = Table(self.colors,labels,f'Creator: {util.execution_stamp("Colormap")}') - t.save(self._get_file_handle(fname,'txt')) + t.save(self._get_file_handle(fname,'.txt')) def save_GOM(self, fname: Union[TextIO, str, Path] = None): @@ -346,7 +346,7 @@ class Colormap(mpl.colors.ListedColormap): + ' '.join([f' 0 {c[0]} {c[1]} {c[2]} 255 1' for c in reversed((self.colors*255).astype(int))]) \ + '\n' - self._get_file_handle(fname,'legend').write(GOM_str) + self._get_file_handle(fname,'.legend').write(GOM_str) def save_gmsh(self, fname: Union[TextIO, str, Path] = None): @@ -364,7 +364,7 @@ class Colormap(mpl.colors.ListedColormap): gmsh_str = 'View.ColorTable = {\n' \ +'\n'.join([f'{c[0]},{c[1]},{c[2]},' for c in self.colors[:,:3]*255]) \ +'\n}\n' - self._get_file_handle(fname,'msh').write(gmsh_str) + self._get_file_handle(fname,'.msh').write(gmsh_str) @staticmethod From 3cae915e4744d32497dfc559738e7f08d8a1b434 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 24 Nov 2021 21:12:13 +0100 Subject: [PATCH 7/7] not needed a = [] is already a list --- 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 22e44a43c..40aab652c 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -3,7 +3,7 @@ import json import functools import colorsys from pathlib import Path -from typing import Sequence, Union, List, TextIO +from typing import Sequence, Union, TextIO import numpy as np @@ -297,7 +297,7 @@ class Colormap(mpl.colors.ListedColormap): consist of the name of the colormap and extension '.json'. """ - colors: List = [] + colors = [] for i,c in enumerate(np.round(self.colors,6).tolist()): colors+=[i]+c