whitespace cleaning and other polishing
This commit is contained in:
parent
38b755740b
commit
b4679fabfc
|
@ -1,6 +1,6 @@
|
|||
import numpy as np
|
||||
|
||||
class Color():
|
||||
class Color:
|
||||
"""Color representation in and conversion between different color-spaces."""
|
||||
|
||||
__slots__ = [
|
||||
|
@ -97,7 +97,6 @@ class Color():
|
|||
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).
|
||||
|
@ -202,7 +201,6 @@ class Color():
|
|||
self.color = converted.color
|
||||
|
||||
|
||||
|
||||
def _RGB2XYZ(self):
|
||||
"""
|
||||
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
|
||||
XYZ = np.dot(convert,RGB_lin)
|
||||
for i in range(3):
|
||||
|
||||
XYZ[i] = max(XYZ[i],0.0)
|
||||
|
||||
converted = Color('XYZ', XYZ)
|
||||
|
@ -231,7 +228,6 @@ class Color():
|
|||
self.color = converted.color
|
||||
|
||||
|
||||
|
||||
def _XYZ2RGB(self):
|
||||
"""
|
||||
Convert CIE XYZ to R(ed) G(reen) B(lue).
|
||||
|
@ -239,8 +235,7 @@ class Color():
|
|||
All values are in the range [0,1]
|
||||
from http://www.cs.rit.edu/~ncs/color/t_convert.html
|
||||
"""
|
||||
if self.model != 'XYZ':
|
||||
return
|
||||
if self.model != 'XYZ': return
|
||||
|
||||
convert = np.array([[ 3.240479,-1.537150,-0.498535],
|
||||
[-0.969256, 1.875992, 0.041556],
|
||||
|
@ -263,7 +258,6 @@ class Color():
|
|||
self.color = converted.color
|
||||
|
||||
|
||||
|
||||
def _CIELAB2XYZ(self):
|
||||
"""
|
||||
Convert CIE Lab to CIE XYZ.
|
||||
|
@ -352,7 +346,7 @@ class Color():
|
|||
self.color = converted.color
|
||||
|
||||
|
||||
class Colormap():
|
||||
class Colormap:
|
||||
"""Perceptually uniform diverging or sequential colormap."""
|
||||
|
||||
__slots__ = [
|
||||
|
@ -403,7 +397,7 @@ class Colormap():
|
|||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------
|
||||
def __init__(self,
|
||||
left = Color('RGB',[1,1,1]),
|
||||
right = Color('RGB',[0,0,0]),
|
||||
|
@ -440,32 +434,32 @@ class Colormap():
|
|||
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])
|
||||
# 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):
|
||||
if Msh_sat[0] >= Msh_unsat[0]:
|
||||
return Msh_sat[2]
|
||||
|
@ -507,7 +501,7 @@ class Colormap():
|
|||
else:
|
||||
raise NameError('unknown color interpolation method')
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------
|
||||
def export(self,name = 'uniformPerceptualColorMap',\
|
||||
format = 'paraview',\
|
||||
steps = 2,\
|
||||
|
|
|
@ -49,6 +49,7 @@ class Geom():
|
|||
'max microstructure: {}'.format(np.nanmax(self.microstructure)),
|
||||
])
|
||||
|
||||
|
||||
def update(self,microstructure=None,size=None,origin=None,rescale=False):
|
||||
"""
|
||||
Updates microstructure and size.
|
||||
|
@ -111,6 +112,7 @@ class Geom():
|
|||
|
||||
return util.return_message(message)
|
||||
|
||||
|
||||
def set_comments(self,comments):
|
||||
"""
|
||||
Replaces all existing comments.
|
||||
|
@ -124,6 +126,7 @@ class Geom():
|
|||
self.comments = []
|
||||
self.add_comments(comments)
|
||||
|
||||
|
||||
def add_comments(self,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)]
|
||||
|
||||
|
||||
def set_microstructure(self,microstructure):
|
||||
"""
|
||||
Replaces the existing microstructure representation.
|
||||
|
@ -154,6 +158,7 @@ class Geom():
|
|||
else:
|
||||
self.microstructure = np.copy(microstructure)
|
||||
|
||||
|
||||
def set_size(self,size):
|
||||
"""
|
||||
Replaces the existing size information.
|
||||
|
@ -173,6 +178,7 @@ class Geom():
|
|||
else:
|
||||
self.size = np.array(size)
|
||||
|
||||
|
||||
def set_origin(self,origin):
|
||||
"""
|
||||
Replaces the existing origin information.
|
||||
|
@ -189,6 +195,7 @@ class Geom():
|
|||
else:
|
||||
self.origin = np.array(origin)
|
||||
|
||||
|
||||
def set_homogenization(self,homogenization):
|
||||
"""
|
||||
Replaces the existing homogenization index.
|
||||
|
@ -205,34 +212,42 @@ class Geom():
|
|||
else:
|
||||
self.homogenization = homogenization
|
||||
|
||||
|
||||
@property
|
||||
def grid(self):
|
||||
return self.get_grid()
|
||||
|
||||
|
||||
def get_microstructure(self):
|
||||
"""Return the microstructure representation."""
|
||||
return np.copy(self.microstructure)
|
||||
|
||||
|
||||
def get_size(self):
|
||||
"""Return the physical size in meter."""
|
||||
return np.copy(self.size)
|
||||
|
||||
|
||||
def get_origin(self):
|
||||
"""Return the origin in meter."""
|
||||
return np.copy(self.origin)
|
||||
|
||||
|
||||
def get_grid(self):
|
||||
"""Return the grid discretization."""
|
||||
return np.array(self.microstructure.shape)
|
||||
|
||||
|
||||
def get_homogenization(self):
|
||||
"""Return the homogenization index."""
|
||||
return self.homogenization
|
||||
|
||||
|
||||
def get_comments(self):
|
||||
"""Return the comments."""
|
||||
return self.comments[:]
|
||||
|
||||
|
||||
def get_header(self):
|
||||
"""Return the full header (grid, size, origin, homogenization, comments)."""
|
||||
header = ['{} header'.format(len(self.comments)+4)] + self.comments
|
||||
|
@ -242,6 +257,7 @@ class Geom():
|
|||
header.append('homogenization {}'.format(self.get_homogenization()))
|
||||
return header
|
||||
|
||||
|
||||
@staticmethod
|
||||
def from_file(fname):
|
||||
"""
|
||||
|
@ -470,8 +486,8 @@ class Geom():
|
|||
if 'x' in directions:
|
||||
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)
|
||||
#self.add_comments('tbd')
|
||||
|
||||
|
||||
def scale(self,grid):
|
||||
|
@ -484,6 +500,7 @@ class Geom():
|
|||
new grid dimension
|
||||
|
||||
"""
|
||||
#self.add_comments('geom.py:scale v{}'.format(version)
|
||||
return self.update(
|
||||
ndimage.interpolation.zoom(
|
||||
self.microstructure,
|
||||
|
@ -494,7 +511,6 @@ class Geom():
|
|||
prefilter=False
|
||||
)
|
||||
)
|
||||
#self.add_comments('tbd')
|
||||
|
||||
|
||||
def clean(self,stencil=3):
|
||||
|
@ -511,13 +527,13 @@ class Geom():
|
|||
unique, inverse = np.unique(arr, return_inverse=True)
|
||||
return unique[np.argmax(np.bincount(inverse))]
|
||||
|
||||
#self.add_comments('geom.py:clean v{}'.format(version)
|
||||
return self.update(ndimage.filters.generic_filter(
|
||||
self.microstructure,
|
||||
mostFrequent,
|
||||
size=(stencil,)*3
|
||||
).astype(self.microstructure.dtype)
|
||||
)
|
||||
#self.add_comments('tbd')
|
||||
|
||||
|
||||
def renumber(self):
|
||||
|
@ -526,5 +542,5 @@ class Geom():
|
|||
for i, oldID in enumerate(np.unique(self.microstructure)):
|
||||
renumbered = np.where(self.microstructure == oldID, i+1, renumbered)
|
||||
|
||||
#self.add_comments('geom.py:renumber v{}'.format(version)
|
||||
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)
|
||||
Deformation gradient.
|
||||
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):
|
||||
|
@ -136,7 +136,7 @@ def PK2(P,F):
|
|||
Parameters
|
||||
----------
|
||||
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)
|
||||
Deformation gradient.
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ class Table:
|
|||
Parameters
|
||||
----------
|
||||
other : Table
|
||||
Table to append
|
||||
Table to append.
|
||||
|
||||
"""
|
||||
if self.shapes != other.shapes or not self.data.columns.equals(other.data.columns):
|
||||
|
@ -305,7 +305,7 @@ class Table:
|
|||
Parameters
|
||||
----------
|
||||
other : Table
|
||||
Table to join
|
||||
Table to join.
|
||||
|
||||
"""
|
||||
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
|
||||
----------
|
||||
what : str or iterable
|
||||
Content to be displayed
|
||||
Content to be displayed.
|
||||
newline : bool, optional
|
||||
Separate items of what by newline. Defaults to True.
|
||||
|
||||
|
@ -122,8 +122,8 @@ def execute(cmd,
|
|||
Input (via pipe) for executed process.
|
||||
wd : str, optional
|
||||
Working directory of process. Defaults to ./ .
|
||||
env :
|
||||
Environment
|
||||
env : dict, optional
|
||||
Environment for execution.
|
||||
|
||||
"""
|
||||
initialPath = os.getcwd()
|
||||
|
|
Loading…
Reference in New Issue