better readable and documented

This commit is contained in:
Martin Diehl 2021-05-07 19:42:23 +02:00
parent 9506262235
commit a48fa5d797
4 changed files with 23 additions and 10 deletions

View File

@ -110,13 +110,13 @@ class Colormap(mpl.colors.ListedColormap):
low_,high_ = map(Colormap._rgb2msh,low_high) low_,high_ = map(Colormap._rgb2msh,low_high)
elif model.lower() == 'hsv': 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): if np.any(low_high<0) or np.any(low_high>[360,1,1]):
raise ValueError(f'HSV color {low} | {high} are out of range.') 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': 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): if np.any(low_high<0) or np.any(low_high>[360,1,1]):
raise ValueError(f'HSL color {low} | {high} are out of range.') 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)

View File

@ -150,9 +150,8 @@ class VTK:
---------- ----------
fname : str or pathlib.Path fname : str or pathlib.Path
Filename for reading. Valid extensions are .vtr, .vtu, .vtp, and .vtk. Filename for reading. Valid extensions are .vtr, .vtu, .vtp, and .vtk.
dataset_type : str, optional dataset_type : {'vtkRectilinearGrid', 'vtkUnstructuredGrid', 'vtkPolyData'}, optional
Name of the vtk.vtkDataSet subclass when opening a .vtk file. Name of the vtk.vtkDataSet subclass when opening a .vtk file.
Valid types are vtkRectilinearGrid, vtkUnstructuredGrid, and vtkPolyData.
Returns Returns
------- -------

View File

@ -124,9 +124,6 @@ def strain(F,t,m):
""" """
Calculate strain tensor (SethHill family). Calculate strain tensor (SethHill family).
For details refer to https://en.wikipedia.org/wiki/Finite_strain_theory and
https://de.wikipedia.org/wiki/Verzerrungstensor
Parameters Parameters
---------- ----------
F : numpy.ndarray of shape (...,3,3) F : numpy.ndarray of shape (...,3,3)
@ -142,6 +139,11 @@ def strain(F,t,m):
epsilon : numpy.ndarray of shape (...,3,3) epsilon : numpy.ndarray of shape (...,3,3)
Strain of F. Strain of F.
References
----------
https://en.wikipedia.org/wiki/Finite_strain_theory
https://de.wikipedia.org/wiki/Verzerrungstensor
""" """
if t == 'V': if t == 'V':
w,n = _np.linalg.eigh(deformation_Cauchy_Green_left(F)) w,n = _np.linalg.eigh(deformation_Cauchy_Green_left(F))
@ -150,7 +152,6 @@ def strain(F,t,m):
if m > 0.0: if m > 0.0:
eps = 1.0/(2.0*abs(m)) * (+ _np.einsum('...j,...kj,...lj',w**m,n,n) - _np.eye(3)) eps = 1.0/(2.0*abs(m)) * (+ _np.einsum('...j,...kj,...lj',w**m,n,n) - _np.eye(3))
elif m < 0.0: elif m < 0.0:
eps = 1.0/(2.0*abs(m)) * (- _np.einsum('...j,...kj,...lj',w**m,n,n) + _np.eye(3)) eps = 1.0/(2.0*abs(m)) * (- _np.einsum('...j,...kj,...lj',w**m,n,n) + _np.eye(3))
else: else:

View File

@ -1,3 +1,5 @@
"""Miscellaneous helper functionality."""
import sys import sys
import datetime import datetime
import os import os
@ -177,6 +179,16 @@ def execute(cmd,wd='./',env=None):
def natural_sort(key): def natural_sort(key):
"""
Natural sort.
For use in python's 'sorted'.
References
----------
https://en.wikipedia.org/wiki/Natural_sort_order
"""
convert = lambda text: int(text) if text.isdigit() else text convert = lambda text: int(text) if text.isdigit() else text
return [ convert(c) for c in re.split('([0-9]+)', key) ] return [ convert(c) for c in re.split('([0-9]+)', key) ]
@ -191,9 +203,9 @@ def show_progress(iterable,N_iter=None,prefix='',bar_length=50):
---------- ----------
iterable : iterable/function with yield statement iterable : iterable/function with yield statement
Iterable (or function with yield statement) to be decorated. Iterable (or function with yield statement) to be decorated.
N_iter : int N_iter : int, optional
Total # of iterations. Needed if number of iterations can not be obtained as len(iterable). Total # of iterations. Needed if number of iterations can not be obtained as len(iterable).
prefix : str, optional. prefix : str, optional
Prefix string. Prefix string.
bar_length : int, optional bar_length : int, optional
Character length of bar. Defaults to 50. Character length of bar. Defaults to 50.
@ -509,6 +521,7 @@ def dict_prune(d):
v = dict_prune(v) v = dict_prune(v)
if not isinstance(v,dict) or v != {}: if not isinstance(v,dict) or v != {}:
new[k] = v new[k] = v
return new return new