result typehints revision

This commit is contained in:
d.mentock 2022-05-02 11:18:35 +02:00
parent 412884ea82
commit a0f019a0cf
1 changed files with 11 additions and 9 deletions

View File

@ -25,6 +25,8 @@ from . import mechanics
from . import tensor from . import tensor
from . import util from . import util
from ._typehints import FloatSequence
h5py3 = h5py.__version__[0] == '3' h5py3 = h5py.__version__[0] == '3'
chunk_size = 1024**2//8 # for compression in HDF5 chunk_size = 1024**2//8 # for compression in HDF5
@ -588,7 +590,7 @@ class Result:
@staticmethod @staticmethod
def _add_absolute(x: Dict[str, Any]) -> Dict[str, Union[Dict[str, Union[str, int, slice]], str, np.ndarray]]: def _add_absolute(x: Dict[str, Any]) -> Dict[str, Any]:
return { return {
'data': np.abs(x['data']), 'data': np.abs(x['data']),
'label': f'|{x["label"]}|', 'label': f'|{x["label"]}|',
@ -612,7 +614,7 @@ class Result:
@staticmethod @staticmethod
def _add_calculation(**kwargs) -> Dict[str, Union[Dict[str, str], str]]: def _add_calculation(**kwargs):
formula = kwargs['formula'] formula = kwargs['formula']
for d in re.findall(r'#(.*?)#',formula): for d in re.findall(r'#(.*?)#',formula):
formula = formula.replace(f'#{d}#',f"kwargs['{d}']['data']") formula = formula.replace(f'#{d}#',f"kwargs['{d}']['data']")
@ -678,7 +680,7 @@ class Result:
... 'Mises equivalent of the Cauchy stress') ... 'Mises equivalent of the Cauchy stress')
""" """
dataset_mapping: Dict[str, str] = {d:d for d in set(re.findall(r'#(.*?)#',formula))} # datasets used in the formula dataset_mapping = {d:d for d in set(re.findall(r'#(.*?)#',formula))} # datasets used in the formula
args = {'formula':formula,'label':name,'unit':unit,'description':description} args = {'formula':formula,'label':name,'unit':unit,'description':description}
self._add_generic_pointwise(self._add_calculation,dataset_mapping,args) self._add_generic_pointwise(self._add_calculation,dataset_mapping,args)
@ -788,7 +790,7 @@ class Result:
elif eigenvalue == 'min': elif eigenvalue == 'min':
label,p = 'minimum',0 label,p = 'minimum',0
else: else:
raise TypeError raise TypeError("invalid eigenvalue passed to function: {}".format(eigenvalue))
return { return {
'data': tensor.eigenvalues(T_sym['data'])[:,p], 'data': tensor.eigenvalues(T_sym['data'])[:,p],
@ -862,7 +864,7 @@ class Result:
@staticmethod @staticmethod
def _add_IPF_color(l: Sequence[float], def _add_IPF_color(l: FloatSequence,
q: Dict[str, Any]) -> Dict[str, Any]: q: Dict[str, Any]) -> Dict[str, Any]:
m = util.scale_to_coprime(np.array(l)) m = util.scale_to_coprime(np.array(l))
lattice = q['meta']['lattice'] lattice = q['meta']['lattice']
@ -905,7 +907,7 @@ class Result:
@staticmethod @staticmethod
def _add_maximum_shear(T_sym: dict) -> dict: def _add_maximum_shear(T_sym: Dict[str, Any]) -> Dict[str, Any]:
return { return {
'data': mechanics.maximum_shear(T_sym['data']), 'data': mechanics.maximum_shear(T_sym['data']),
'label': f"max_shear({T_sym['label']})", 'label': f"max_shear({T_sym['label']})",
@ -1064,8 +1066,8 @@ class Result:
@staticmethod @staticmethod
def _add_pole(q: Dict[str, Any], def _add_pole(q: Dict[str, Any],
uvw: np.ndarray, uvw: FloatSequence,
hkl: np.ndarray, hkl: FloatSequence,
with_symmetry: bool) -> Dict[str, Any]: with_symmetry: bool) -> Dict[str, Any]:
c = q['meta']['c/a'] if 'c/a' in q['meta'] else 1 c = q['meta']['c/a'] if 'c/a' in q['meta'] else 1
pole = Orientation(q['data'],lattice=q['meta']['lattice'],a=1,c=c).to_pole(uvw=uvw,hkl=hkl,with_symmetry=with_symmetry) pole = Orientation(q['data'],lattice=q['meta']['lattice'],a=1,c=c).to_pole(uvw=uvw,hkl=hkl,with_symmetry=with_symmetry)