some suggestions from prospector/pylint
This commit is contained in:
parent
ce4591fa29
commit
df96110733
|
@ -267,7 +267,7 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
(bounds[0],bounds[1])
|
||||
|
||||
if abs(delta := r-l) * 1e8 <= (avg := 0.5*abs(r+l)): # delta is similar to numerical noise
|
||||
l,r = l-0.5*avg*np.sign(delta),r+0.5*avg*np.sign(delta), # extend range to have actual data centered within
|
||||
l,r = (l-0.5*avg*np.sign(delta),r+0.5*avg*np.sign(delta)) # extend range to have actual data centered within
|
||||
|
||||
return Image.fromarray(
|
||||
(np.dstack((
|
||||
|
@ -301,7 +301,7 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
>>> damask.Colormap.from_predefined('stress').reversed()
|
||||
|
||||
"""
|
||||
rev = super(Colormap,self).reversed(name)
|
||||
rev = super().reversed(name)
|
||||
return Colormap(np.array(rev.colors),rev.name[:-4] if rev.name.endswith('_r_r') else rev.name)
|
||||
|
||||
|
||||
|
@ -436,11 +436,11 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
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
|
||||
return msh_sat[2]
|
||||
|
||||
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)
|
||||
|
@ -453,9 +453,9 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
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:
|
||||
if lo[1] < 0.05 < hi[1]:
|
||||
lo[2] = adjust_hue(hi,lo)
|
||||
elif lo[1] > 0.05 and hi[1] < 0.05:
|
||||
elif hi[1] < 0.05 < lo[1]:
|
||||
hi[2] = adjust_hue(lo,hi)
|
||||
|
||||
return (1.0 - frac) * lo + frac * hi
|
||||
|
|
|
@ -33,7 +33,7 @@ class Grid:
|
|||
material: np.ndarray,
|
||||
size: FloatSequence,
|
||||
origin: FloatSequence = np.zeros(3),
|
||||
comments: Union[str, Sequence[str]] = []):
|
||||
comments: Union[str, Sequence[str]] = None):
|
||||
"""
|
||||
New geometry definition for grid solvers.
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Grid:
|
|||
self.material = material
|
||||
self.size = size # type: ignore
|
||||
self.origin = origin # type: ignore
|
||||
self.comments = comments # type: ignore
|
||||
self.comments = [] if comments is None else comments # type: ignore
|
||||
|
||||
|
||||
def __repr__(self) -> str:
|
||||
|
@ -106,14 +106,14 @@ class Grid:
|
|||
material: np.ndarray):
|
||||
if len(material.shape) != 3:
|
||||
raise ValueError(f'invalid material shape {material.shape}')
|
||||
elif material.dtype not in np.sctypes['float'] and material.dtype not in np.sctypes['int']:
|
||||
if material.dtype not in np.sctypes['float'] and material.dtype not in np.sctypes['int']:
|
||||
raise TypeError(f'invalid material data type {material.dtype}')
|
||||
else:
|
||||
self._material = np.copy(material)
|
||||
|
||||
if self.material.dtype in np.sctypes['float'] and \
|
||||
np.all(self.material == self.material.astype(int).astype(float)):
|
||||
self._material = self.material.astype(int)
|
||||
self._material = np.copy(material)
|
||||
|
||||
if self.material.dtype in np.sctypes['float'] and \
|
||||
np.all(self.material == self.material.astype(int).astype(float)):
|
||||
self._material = self.material.astype(int)
|
||||
|
||||
|
||||
@property
|
||||
|
@ -126,8 +126,8 @@ class Grid:
|
|||
size: FloatSequence):
|
||||
if len(size) != 3 or any(np.array(size) < 0):
|
||||
raise ValueError(f'invalid size {size}')
|
||||
else:
|
||||
self._size = np.array(size)
|
||||
|
||||
self._size = np.array(size)
|
||||
|
||||
@property
|
||||
def origin(self) -> np.ndarray:
|
||||
|
@ -139,8 +139,8 @@ class Grid:
|
|||
origin: FloatSequence):
|
||||
if len(origin) != 3:
|
||||
raise ValueError(f'invalid origin {origin}')
|
||||
else:
|
||||
self._origin = np.array(origin)
|
||||
|
||||
self._origin = np.array(origin)
|
||||
|
||||
@property
|
||||
def comments(self) -> List[str]:
|
||||
|
|
|
@ -14,7 +14,7 @@ class Table:
|
|||
|
||||
def __init__(self,
|
||||
data: np.ndarray,
|
||||
shapes: dict,
|
||||
shapes: dict,
|
||||
comments: Union[str, list] = None):
|
||||
"""
|
||||
New spreadsheet.
|
||||
|
@ -526,10 +526,10 @@ class Table:
|
|||
"""
|
||||
if self.shapes != other.shapes or not self.data.columns.equals(other.data.columns):
|
||||
raise KeyError('Labels or shapes or order do not match')
|
||||
else:
|
||||
dup = self.copy()
|
||||
dup.data = dup.data.append(other.data,ignore_index=True)
|
||||
return dup
|
||||
|
||||
dup = self.copy()
|
||||
dup.data = dup.data.append(other.data,ignore_index=True)
|
||||
return dup
|
||||
|
||||
|
||||
def join(self,
|
||||
|
@ -552,12 +552,12 @@ class Table:
|
|||
"""
|
||||
if set(self.shapes) & set(other.shapes) or self.data.shape[0] != other.data.shape[0]:
|
||||
raise KeyError('Duplicated keys or row count mismatch')
|
||||
else:
|
||||
dup = self.copy()
|
||||
dup.data = dup.data.join(other.data)
|
||||
for key in other.shapes:
|
||||
dup.shapes[key] = other.shapes[key]
|
||||
return dup
|
||||
|
||||
dup = self.copy()
|
||||
dup.data = dup.data.join(other.data)
|
||||
for key in other.shapes:
|
||||
dup.shapes[key] = other.shapes[key]
|
||||
return dup
|
||||
|
||||
|
||||
def save(self,
|
||||
|
|
|
@ -64,7 +64,7 @@ def eigenvectors(T_sym: _np.ndarray,
|
|||
associated eigenvalues.
|
||||
|
||||
"""
|
||||
(u,v) = _np.linalg.eigh(symmetric(T_sym))
|
||||
_,v = _np.linalg.eigh(symmetric(T_sym))
|
||||
|
||||
if RHS: v[_np.linalg.det(v) < 0.0,:,2] *= -1.0
|
||||
return v
|
||||
|
|
|
@ -7,7 +7,7 @@ import subprocess
|
|||
import shlex
|
||||
import re
|
||||
import fractions
|
||||
import collections.abc as abc
|
||||
from collections import abc
|
||||
from functools import reduce
|
||||
from typing import Union, Tuple, Iterable, Callable, Dict, List, Any, Literal, Optional
|
||||
from pathlib import Path
|
||||
|
@ -77,7 +77,7 @@ def srepr(msg,
|
|||
hasattr(msg, '__iter__'))):
|
||||
return glue.join(str(x) for x in msg)
|
||||
else:
|
||||
return msg if isinstance(msg,str) else repr(msg)
|
||||
return msg if isinstance(msg,str) else repr(msg)
|
||||
|
||||
|
||||
def emph(msg) -> str:
|
||||
|
@ -230,15 +230,15 @@ def show_progress(iterable: Iterable,
|
|||
|
||||
"""
|
||||
if isinstance(iterable,abc.Sequence):
|
||||
if N_iter is None:
|
||||
N = len(iterable)
|
||||
else:
|
||||
raise ValueError('N_iter given for sequence')
|
||||
if N_iter is None:
|
||||
N = len(iterable)
|
||||
else:
|
||||
raise ValueError('N_iter given for sequence')
|
||||
else:
|
||||
if N_iter is None:
|
||||
raise ValueError('N_iter not given')
|
||||
else:
|
||||
N = N_iter
|
||||
if N_iter is None:
|
||||
raise ValueError('N_iter not given')
|
||||
|
||||
N = N_iter
|
||||
|
||||
if N <= 1:
|
||||
for item in iterable:
|
||||
|
@ -454,7 +454,7 @@ def shapeshifter(fro: Tuple[int, ...],
|
|||
|
||||
|
||||
"""
|
||||
if not len(fro) and not len(to): return ()
|
||||
if len(fro) == 0 and len(to) == 0: return ()
|
||||
|
||||
beg = dict(left ='(^.*\\b)',
|
||||
right='(^.*?\\b)')
|
||||
|
@ -462,8 +462,8 @@ def shapeshifter(fro: Tuple[int, ...],
|
|||
right='(.*?\\b)')
|
||||
end = dict(left ='(.*?$)',
|
||||
right='(.*$)')
|
||||
fro = (1,) if not len(fro) else fro
|
||||
to = (1,) if not len(to) else to
|
||||
fro = (1,) if len(fro) == 0 else fro
|
||||
to = (1,) if len(to) == 0 else to
|
||||
try:
|
||||
match = re.match(beg[mode]
|
||||
+f',{sep[mode]}'.join(map(lambda x: f'{x}'
|
||||
|
|
Loading…
Reference in New Issue