whitespace cleaning and other polishing
This commit is contained in:
parent
38b755740b
commit
b4679fabfc
|
@ -1,6 +1,6 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
class Color():
|
class Color:
|
||||||
"""Color representation in and conversion between different color-spaces."""
|
"""Color representation in and conversion between different color-spaces."""
|
||||||
|
|
||||||
__slots__ = [
|
__slots__ = [
|
||||||
|
@ -97,7 +97,6 @@ class Color():
|
||||||
return self.__class__(self.model,self.color).convert_to(asModel)
|
return self.__class__(self.model,self.color).convert_to(asModel)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _HSV2HSL(self):
|
def _HSV2HSL(self):
|
||||||
"""
|
"""
|
||||||
Convert H(ue) S(aturation) V(alue or brightness) to H(ue) S(aturation) L(uminance).
|
Convert H(ue) S(aturation) V(alue or brightness) to H(ue) S(aturation) L(uminance).
|
||||||
|
@ -202,7 +201,6 @@ class Color():
|
||||||
self.color = converted.color
|
self.color = converted.color
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _RGB2XYZ(self):
|
def _RGB2XYZ(self):
|
||||||
"""
|
"""
|
||||||
Convert R(ed) G(reen) B(lue) to CIE XYZ.
|
Convert R(ed) G(reen) B(lue) to CIE XYZ.
|
||||||
|
@ -223,7 +221,6 @@ class Color():
|
||||||
else: RGB_lin[i] = self.color[i] /12.92
|
else: RGB_lin[i] = self.color[i] /12.92
|
||||||
XYZ = np.dot(convert,RGB_lin)
|
XYZ = np.dot(convert,RGB_lin)
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
|
|
||||||
XYZ[i] = max(XYZ[i],0.0)
|
XYZ[i] = max(XYZ[i],0.0)
|
||||||
|
|
||||||
converted = Color('XYZ', XYZ)
|
converted = Color('XYZ', XYZ)
|
||||||
|
@ -231,7 +228,6 @@ class Color():
|
||||||
self.color = converted.color
|
self.color = converted.color
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _XYZ2RGB(self):
|
def _XYZ2RGB(self):
|
||||||
"""
|
"""
|
||||||
Convert CIE XYZ to R(ed) G(reen) B(lue).
|
Convert CIE XYZ to R(ed) G(reen) B(lue).
|
||||||
|
@ -239,8 +235,7 @@ class Color():
|
||||||
All values are in the range [0,1]
|
All values are in the range [0,1]
|
||||||
from http://www.cs.rit.edu/~ncs/color/t_convert.html
|
from http://www.cs.rit.edu/~ncs/color/t_convert.html
|
||||||
"""
|
"""
|
||||||
if self.model != 'XYZ':
|
if self.model != 'XYZ': return
|
||||||
return
|
|
||||||
|
|
||||||
convert = np.array([[ 3.240479,-1.537150,-0.498535],
|
convert = np.array([[ 3.240479,-1.537150,-0.498535],
|
||||||
[-0.969256, 1.875992, 0.041556],
|
[-0.969256, 1.875992, 0.041556],
|
||||||
|
@ -263,7 +258,6 @@ class Color():
|
||||||
self.color = converted.color
|
self.color = converted.color
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _CIELAB2XYZ(self):
|
def _CIELAB2XYZ(self):
|
||||||
"""
|
"""
|
||||||
Convert CIE Lab to CIE XYZ.
|
Convert CIE Lab to CIE XYZ.
|
||||||
|
@ -352,7 +346,7 @@ class Color():
|
||||||
self.color = converted.color
|
self.color = converted.color
|
||||||
|
|
||||||
|
|
||||||
class Colormap():
|
class Colormap:
|
||||||
"""Perceptually uniform diverging or sequential colormap."""
|
"""Perceptually uniform diverging or sequential colormap."""
|
||||||
|
|
||||||
__slots__ = [
|
__slots__ = [
|
||||||
|
@ -403,7 +397,7 @@ class Colormap():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
left = Color('RGB',[1,1,1]),
|
left = Color('RGB',[1,1,1]),
|
||||||
right = Color('RGB',[0,0,0]),
|
right = Color('RGB',[0,0,0]),
|
||||||
|
@ -440,32 +434,32 @@ class Colormap():
|
||||||
self.interpolate = interpolate
|
self.interpolate = interpolate
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""Left and right value of colormap."""
|
"""Left and right value of colormap."""
|
||||||
return 'Left: %s Right: %s'%(self.left,self.right)
|
return 'Left: %s Right: %s'%(self.left,self.right)
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def invert(self):
|
def invert(self):
|
||||||
"""Switch left/minimum with right/maximum."""
|
"""Switch left/minimum with right/maximum."""
|
||||||
(self.left, self.right) = (self.right, self.left)
|
(self.left, self.right) = (self.right, self.left)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def show_predefined(self):
|
def show_predefined(self):
|
||||||
"""Show the labels of the predefined colormaps."""
|
"""Show the labels of the predefined colormaps."""
|
||||||
print('\n'.join(self.__predefined__.keys()))
|
print('\n'.join(self.__predefined__.keys()))
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def color(self,fraction = 0.5):
|
def color(self,fraction = 0.5):
|
||||||
|
|
||||||
def interpolate_Msh(lo, hi, frac):
|
def interpolate_Msh(lo, hi, frac):
|
||||||
|
|
||||||
def rad_diff(a,b):
|
def rad_diff(a,b):
|
||||||
return abs(a[2]-b[2])
|
return abs(a[2]-b[2])
|
||||||
# if saturation of one of the two colors is too less than the other, hue of the less
|
# if saturation of one of the two colors is too less than the other, hue of the less
|
||||||
def adjust_hue(Msh_sat, Msh_unsat):
|
def adjust_hue(Msh_sat, Msh_unsat):
|
||||||
if Msh_sat[0] >= Msh_unsat[0]:
|
if Msh_sat[0] >= Msh_unsat[0]:
|
||||||
return Msh_sat[2]
|
return Msh_sat[2]
|
||||||
|
@ -507,7 +501,7 @@ class Colormap():
|
||||||
else:
|
else:
|
||||||
raise NameError('unknown color interpolation method')
|
raise NameError('unknown color interpolation method')
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def export(self,name = 'uniformPerceptualColorMap',\
|
def export(self,name = 'uniformPerceptualColorMap',\
|
||||||
format = 'paraview',\
|
format = 'paraview',\
|
||||||
steps = 2,\
|
steps = 2,\
|
||||||
|
|
|
@ -49,6 +49,7 @@ class Geom():
|
||||||
'max microstructure: {}'.format(np.nanmax(self.microstructure)),
|
'max microstructure: {}'.format(np.nanmax(self.microstructure)),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def update(self,microstructure=None,size=None,origin=None,rescale=False):
|
def update(self,microstructure=None,size=None,origin=None,rescale=False):
|
||||||
"""
|
"""
|
||||||
Updates microstructure and size.
|
Updates microstructure and size.
|
||||||
|
@ -111,6 +112,7 @@ class Geom():
|
||||||
|
|
||||||
return util.return_message(message)
|
return util.return_message(message)
|
||||||
|
|
||||||
|
|
||||||
def set_comments(self,comments):
|
def set_comments(self,comments):
|
||||||
"""
|
"""
|
||||||
Replaces all existing comments.
|
Replaces all existing comments.
|
||||||
|
@ -124,6 +126,7 @@ class Geom():
|
||||||
self.comments = []
|
self.comments = []
|
||||||
self.add_comments(comments)
|
self.add_comments(comments)
|
||||||
|
|
||||||
|
|
||||||
def add_comments(self,comments):
|
def add_comments(self,comments):
|
||||||
"""
|
"""
|
||||||
Appends comments to existing comments.
|
Appends comments to existing comments.
|
||||||
|
@ -136,6 +139,7 @@ class Geom():
|
||||||
"""
|
"""
|
||||||
self.comments += [str(c) for c in comments] if isinstance(comments,list) else [str(comments)]
|
self.comments += [str(c) for c in comments] if isinstance(comments,list) else [str(comments)]
|
||||||
|
|
||||||
|
|
||||||
def set_microstructure(self,microstructure):
|
def set_microstructure(self,microstructure):
|
||||||
"""
|
"""
|
||||||
Replaces the existing microstructure representation.
|
Replaces the existing microstructure representation.
|
||||||
|
@ -154,6 +158,7 @@ class Geom():
|
||||||
else:
|
else:
|
||||||
self.microstructure = np.copy(microstructure)
|
self.microstructure = np.copy(microstructure)
|
||||||
|
|
||||||
|
|
||||||
def set_size(self,size):
|
def set_size(self,size):
|
||||||
"""
|
"""
|
||||||
Replaces the existing size information.
|
Replaces the existing size information.
|
||||||
|
@ -173,6 +178,7 @@ class Geom():
|
||||||
else:
|
else:
|
||||||
self.size = np.array(size)
|
self.size = np.array(size)
|
||||||
|
|
||||||
|
|
||||||
def set_origin(self,origin):
|
def set_origin(self,origin):
|
||||||
"""
|
"""
|
||||||
Replaces the existing origin information.
|
Replaces the existing origin information.
|
||||||
|
@ -189,6 +195,7 @@ class Geom():
|
||||||
else:
|
else:
|
||||||
self.origin = np.array(origin)
|
self.origin = np.array(origin)
|
||||||
|
|
||||||
|
|
||||||
def set_homogenization(self,homogenization):
|
def set_homogenization(self,homogenization):
|
||||||
"""
|
"""
|
||||||
Replaces the existing homogenization index.
|
Replaces the existing homogenization index.
|
||||||
|
@ -205,34 +212,42 @@ class Geom():
|
||||||
else:
|
else:
|
||||||
self.homogenization = homogenization
|
self.homogenization = homogenization
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def grid(self):
|
def grid(self):
|
||||||
return self.get_grid()
|
return self.get_grid()
|
||||||
|
|
||||||
|
|
||||||
def get_microstructure(self):
|
def get_microstructure(self):
|
||||||
"""Return the microstructure representation."""
|
"""Return the microstructure representation."""
|
||||||
return np.copy(self.microstructure)
|
return np.copy(self.microstructure)
|
||||||
|
|
||||||
|
|
||||||
def get_size(self):
|
def get_size(self):
|
||||||
"""Return the physical size in meter."""
|
"""Return the physical size in meter."""
|
||||||
return np.copy(self.size)
|
return np.copy(self.size)
|
||||||
|
|
||||||
|
|
||||||
def get_origin(self):
|
def get_origin(self):
|
||||||
"""Return the origin in meter."""
|
"""Return the origin in meter."""
|
||||||
return np.copy(self.origin)
|
return np.copy(self.origin)
|
||||||
|
|
||||||
|
|
||||||
def get_grid(self):
|
def get_grid(self):
|
||||||
"""Return the grid discretization."""
|
"""Return the grid discretization."""
|
||||||
return np.array(self.microstructure.shape)
|
return np.array(self.microstructure.shape)
|
||||||
|
|
||||||
|
|
||||||
def get_homogenization(self):
|
def get_homogenization(self):
|
||||||
"""Return the homogenization index."""
|
"""Return the homogenization index."""
|
||||||
return self.homogenization
|
return self.homogenization
|
||||||
|
|
||||||
|
|
||||||
def get_comments(self):
|
def get_comments(self):
|
||||||
"""Return the comments."""
|
"""Return the comments."""
|
||||||
return self.comments[:]
|
return self.comments[:]
|
||||||
|
|
||||||
|
|
||||||
def get_header(self):
|
def get_header(self):
|
||||||
"""Return the full header (grid, size, origin, homogenization, comments)."""
|
"""Return the full header (grid, size, origin, homogenization, comments)."""
|
||||||
header = ['{} header'.format(len(self.comments)+4)] + self.comments
|
header = ['{} header'.format(len(self.comments)+4)] + self.comments
|
||||||
|
@ -242,6 +257,7 @@ class Geom():
|
||||||
header.append('homogenization {}'.format(self.get_homogenization()))
|
header.append('homogenization {}'.format(self.get_homogenization()))
|
||||||
return header
|
return header
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_file(fname):
|
def from_file(fname):
|
||||||
"""
|
"""
|
||||||
|
@ -470,8 +486,8 @@ class Geom():
|
||||||
if 'x' in directions:
|
if 'x' in directions:
|
||||||
ms = np.concatenate([ms,ms[limits[0]:limits[1]:-1,:,:]],0)
|
ms = np.concatenate([ms,ms[limits[0]:limits[1]:-1,:,:]],0)
|
||||||
|
|
||||||
|
#self.add_comments('geom.py:mirror v{}'.format(version)
|
||||||
return self.update(ms,rescale=True)
|
return self.update(ms,rescale=True)
|
||||||
#self.add_comments('tbd')
|
|
||||||
|
|
||||||
|
|
||||||
def scale(self,grid):
|
def scale(self,grid):
|
||||||
|
@ -484,6 +500,7 @@ class Geom():
|
||||||
new grid dimension
|
new grid dimension
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
#self.add_comments('geom.py:scale v{}'.format(version)
|
||||||
return self.update(
|
return self.update(
|
||||||
ndimage.interpolation.zoom(
|
ndimage.interpolation.zoom(
|
||||||
self.microstructure,
|
self.microstructure,
|
||||||
|
@ -494,7 +511,6 @@ class Geom():
|
||||||
prefilter=False
|
prefilter=False
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
#self.add_comments('tbd')
|
|
||||||
|
|
||||||
|
|
||||||
def clean(self,stencil=3):
|
def clean(self,stencil=3):
|
||||||
|
@ -511,13 +527,13 @@ class Geom():
|
||||||
unique, inverse = np.unique(arr, return_inverse=True)
|
unique, inverse = np.unique(arr, return_inverse=True)
|
||||||
return unique[np.argmax(np.bincount(inverse))]
|
return unique[np.argmax(np.bincount(inverse))]
|
||||||
|
|
||||||
|
#self.add_comments('geom.py:clean v{}'.format(version)
|
||||||
return self.update(ndimage.filters.generic_filter(
|
return self.update(ndimage.filters.generic_filter(
|
||||||
self.microstructure,
|
self.microstructure,
|
||||||
mostFrequent,
|
mostFrequent,
|
||||||
size=(stencil,)*3
|
size=(stencil,)*3
|
||||||
).astype(self.microstructure.dtype)
|
).astype(self.microstructure.dtype)
|
||||||
)
|
)
|
||||||
#self.add_comments('tbd')
|
|
||||||
|
|
||||||
|
|
||||||
def renumber(self):
|
def renumber(self):
|
||||||
|
@ -526,5 +542,5 @@ class Geom():
|
||||||
for i, oldID in enumerate(np.unique(self.microstructure)):
|
for i, oldID in enumerate(np.unique(self.microstructure)):
|
||||||
renumbered = np.where(self.microstructure == oldID, i+1, renumbered)
|
renumbered = np.where(self.microstructure == oldID, i+1, renumbered)
|
||||||
|
|
||||||
|
#self.add_comments('geom.py:renumber v{}'.format(version)
|
||||||
return self.update(renumbered)
|
return self.update(renumbered)
|
||||||
#self.add_comments('tbd')
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ def Cauchy(P,F):
|
||||||
F : numpy.ndarray of shape (:,3,3) or (3,3)
|
F : numpy.ndarray of shape (:,3,3) or (3,3)
|
||||||
Deformation gradient.
|
Deformation gradient.
|
||||||
P : numpy.ndarray of shape (:,3,3) or (3,3)
|
P : numpy.ndarray of shape (:,3,3) or (3,3)
|
||||||
1. Piola-Kirchhoff stress.
|
First Piola-Kirchhoff stress.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if np.shape(F) == np.shape(P) == (3,3):
|
if np.shape(F) == np.shape(P) == (3,3):
|
||||||
|
@ -136,7 +136,7 @@ def PK2(P,F):
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
P : numpy.ndarray of shape (:,3,3) or (3,3)
|
P : numpy.ndarray of shape (:,3,3) or (3,3)
|
||||||
1. Piola-Kirchhoff stress.
|
First Piola-Kirchhoff stress.
|
||||||
F : numpy.ndarray of shape (:,3,3) or (3,3)
|
F : numpy.ndarray of shape (:,3,3) or (3,3)
|
||||||
Deformation gradient.
|
Deformation gradient.
|
||||||
|
|
||||||
|
|
|
@ -287,7 +287,7 @@ class Table:
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
other : Table
|
other : Table
|
||||||
Table to append
|
Table to append.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.shapes != other.shapes or not self.data.columns.equals(other.data.columns):
|
if self.shapes != other.shapes or not self.data.columns.equals(other.data.columns):
|
||||||
|
@ -305,7 +305,7 @@ class Table:
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
other : Table
|
other : Table
|
||||||
Table to join
|
Table to join.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if set(self.shapes) & set(other.shapes) or self.data.shape[0] != other.data.shape[0]:
|
if set(self.shapes) & set(other.shapes) or self.data.shape[0] != other.data.shape[0]:
|
||||||
|
|
|
@ -66,7 +66,7 @@ def croak(what, newline = True):
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
what : str or iterable
|
what : str or iterable
|
||||||
Content to be displayed
|
Content to be displayed.
|
||||||
newline : bool, optional
|
newline : bool, optional
|
||||||
Separate items of what by newline. Defaults to True.
|
Separate items of what by newline. Defaults to True.
|
||||||
|
|
||||||
|
@ -122,8 +122,8 @@ def execute(cmd,
|
||||||
Input (via pipe) for executed process.
|
Input (via pipe) for executed process.
|
||||||
wd : str, optional
|
wd : str, optional
|
||||||
Working directory of process. Defaults to ./ .
|
Working directory of process. Defaults to ./ .
|
||||||
env :
|
env : dict, optional
|
||||||
Environment
|
Environment for execution.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
initialPath = os.getcwd()
|
initialPath = os.getcwd()
|
||||||
|
|
Loading…
Reference in New Issue