accept variables that will be used
**kwargs allowed the use of extraneous arguments
This commit is contained in:
parent
d5c98bbf62
commit
f1b8978e21
|
@ -1,3 +1,5 @@
|
||||||
|
import inspect
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from . import Rotation
|
from . import Rotation
|
||||||
|
@ -107,8 +109,7 @@ class Orientation(Rotation):
|
||||||
lattice = None,
|
lattice = None,
|
||||||
a = None,b = None,c = None,
|
a = None,b = None,c = None,
|
||||||
alpha = None,beta = None,gamma = None,
|
alpha = None,beta = None,gamma = None,
|
||||||
degrees = False,
|
degrees = False):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Initialize orientation object.
|
Initialize orientation object.
|
||||||
|
|
||||||
|
@ -263,70 +264,110 @@ class Orientation(Rotation):
|
||||||
raise TypeError('Use "O@b", i.e. matmul, to apply Orientation "O" to object "b"')
|
raise TypeError('Use "O@b", i.e. matmul, to apply Orientation "O" to object "b"')
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _separate_arguments(parent_dict,function):
|
||||||
|
"""
|
||||||
|
Separate arguments required by Rotation and Orientation objects respectively.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
parent_dict : Dictionary
|
||||||
|
Contains all **kwargs
|
||||||
|
function: Method
|
||||||
|
Function whose signature list is required
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
ori_dict: dictionary
|
||||||
|
Dictionary consisting of valid keys accepted by Orientation class
|
||||||
|
rot_dict: dictionary
|
||||||
|
Dictionary consisting of valid keys accepted by 'function' in Rotation class
|
||||||
|
|
||||||
|
"""
|
||||||
|
set_ori = set(inspect.signature(Orientation.__init__).parameters.keys()) & set(parent_dict.keys())
|
||||||
|
set_rot = set(inspect.signature(function).parameters.keys()) & set(parent_dict.keys())
|
||||||
|
ori_dict = {key: parent_dict[key] for key in set_ori}
|
||||||
|
rot_dict = {key: parent_dict[key] for key in set_rot}
|
||||||
|
if(set(parent_dict.keys())-(set_ori|set_rot)):
|
||||||
|
raise KeyError(f'Unknown key {set(parent_dict.keys())-(set_ori|set_rot)} present')
|
||||||
|
return rot_dict,ori_dict
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_random,_parameter_doc)
|
@util.extended_docstring(Rotation.from_random,_parameter_doc)
|
||||||
def from_random(cls,**kwargs):
|
def from_random(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_random(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_random)
|
||||||
|
return cls(rotation=Rotation.from_random(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_quaternion,_parameter_doc)
|
@util.extended_docstring(Rotation.from_quaternion,_parameter_doc)
|
||||||
def from_quaternion(cls,**kwargs):
|
def from_quaternion(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_quaternion(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_quaternion)
|
||||||
|
return cls(rotation=Rotation.from_quaternion(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_Euler_angles,_parameter_doc)
|
@util.extended_docstring(Rotation.from_Euler_angles,_parameter_doc)
|
||||||
def from_Euler_angles(cls,**kwargs):
|
def from_Euler_angles(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_Euler_angles(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_Euler_angles)
|
||||||
|
return cls(rotation=Rotation.from_Euler_angles(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_axis_angle,_parameter_doc)
|
@util.extended_docstring(Rotation.from_axis_angle,_parameter_doc)
|
||||||
def from_axis_angle(cls,**kwargs):
|
def from_axis_angle(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_axis_angle(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_axis_angle)
|
||||||
|
return cls(rotation=Rotation.from_axis_angle(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_basis,_parameter_doc)
|
@util.extended_docstring(Rotation.from_basis,_parameter_doc)
|
||||||
def from_basis(cls,**kwargs):
|
def from_basis(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_basis(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_basis)
|
||||||
|
return cls(rotation=Rotation.from_basis(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_matrix,_parameter_doc)
|
@util.extended_docstring(Rotation.from_matrix,_parameter_doc)
|
||||||
def from_matrix(cls,**kwargs):
|
def from_matrix(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_matrix(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_matrix)
|
||||||
|
return cls(rotation=Rotation.from_matrix(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_Rodrigues_vector,_parameter_doc)
|
@util.extended_docstring(Rotation.from_Rodrigues_vector,_parameter_doc)
|
||||||
def from_Rodrigues_vector(cls,**kwargs):
|
def from_Rodrigues_vector(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_Rodrigues_vector(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_Rodrigues_vector)
|
||||||
|
return cls(rotation=Rotation.from_Rodrigues_vector(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_homochoric,_parameter_doc)
|
@util.extended_docstring(Rotation.from_homochoric,_parameter_doc)
|
||||||
def from_homochoric(cls,**kwargs):
|
def from_homochoric(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_homochoric(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_homochoric)
|
||||||
|
return cls(rotation=Rotation.from_homochoric(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_cubochoric,_parameter_doc)
|
@util.extended_docstring(Rotation.from_cubochoric,_parameter_doc)
|
||||||
def from_cubochoric(cls,**kwargs):
|
def from_cubochoric(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_cubochoric(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_cubochoric)
|
||||||
|
return cls(rotation=Rotation.from_cubochoric(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_spherical_component,_parameter_doc)
|
@util.extended_docstring(Rotation.from_spherical_component,_parameter_doc)
|
||||||
def from_spherical_component(cls,**kwargs):
|
def from_spherical_component(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_spherical_component(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_spherical_component)
|
||||||
|
return cls(rotation=Rotation.from_spherical_component(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@util.extended_docstring(Rotation.from_fiber_component,_parameter_doc)
|
@util.extended_docstring(Rotation.from_fiber_component,_parameter_doc)
|
||||||
def from_fiber_component(cls,**kwargs):
|
def from_fiber_component(cls,**kwargs):
|
||||||
return cls(rotation=Rotation.from_fiber_component(**kwargs),**kwargs)
|
kwargs_rot,kwargs_ori = Orientation._separate_arguments(kwargs,Rotation.from_fiber_component)
|
||||||
|
return cls(rotation=Rotation.from_fiber_component(**kwargs_rot),**kwargs_ori)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -514,8 +514,7 @@ class Rotation:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_quaternion(q,
|
def from_quaternion(q,
|
||||||
accept_homomorph = False,
|
accept_homomorph = False,
|
||||||
P = -1,
|
P = -1):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Initialize from quaternion.
|
Initialize from quaternion.
|
||||||
|
|
||||||
|
@ -550,8 +549,7 @@ class Rotation:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_Euler_angles(phi,
|
def from_Euler_angles(phi,
|
||||||
degrees = False,
|
degrees = False):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Initialize from Bunge-Euler angles.
|
Initialize from Bunge-Euler angles.
|
||||||
|
|
||||||
|
@ -578,8 +576,7 @@ class Rotation:
|
||||||
def from_axis_angle(axis_angle,
|
def from_axis_angle(axis_angle,
|
||||||
degrees = False,
|
degrees = False,
|
||||||
normalize = False,
|
normalize = False,
|
||||||
P = -1,
|
P = -1):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Initialize from Axis angle pair.
|
Initialize from Axis angle pair.
|
||||||
|
|
||||||
|
@ -616,8 +613,7 @@ class Rotation:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_basis(basis,
|
def from_basis(basis,
|
||||||
orthonormal = True,
|
orthonormal = True,
|
||||||
reciprocal = False,
|
reciprocal = False):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Initialize from lattice basis vectors.
|
Initialize from lattice basis vectors.
|
||||||
|
|
||||||
|
@ -651,7 +647,7 @@ class Rotation:
|
||||||
return Rotation(Rotation._om2qu(om))
|
return Rotation(Rotation._om2qu(om))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_matrix(R,**kwargs):
|
def from_matrix(R):
|
||||||
"""
|
"""
|
||||||
Initialize from rotation matrix.
|
Initialize from rotation matrix.
|
||||||
|
|
||||||
|
@ -695,8 +691,7 @@ class Rotation:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_Rodrigues_vector(rho,
|
def from_Rodrigues_vector(rho,
|
||||||
normalize = False,
|
normalize = False,
|
||||||
P = -1,
|
P = -1):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Initialize from Rodrigues-Frank vector (angle separated from axis).
|
Initialize from Rodrigues-Frank vector (angle separated from axis).
|
||||||
|
|
||||||
|
@ -727,8 +722,7 @@ class Rotation:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_homochoric(h,
|
def from_homochoric(h,
|
||||||
P = -1,
|
P = -1):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Initialize from homochoric vector.
|
Initialize from homochoric vector.
|
||||||
|
|
||||||
|
@ -755,8 +749,7 @@ class Rotation:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_cubochoric(c,
|
def from_cubochoric(c,
|
||||||
P = -1,
|
P = -1):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Initialize from cubochoric vector.
|
Initialize from cubochoric vector.
|
||||||
|
|
||||||
|
@ -784,8 +777,7 @@ class Rotation:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_random(shape = None,
|
def from_random(shape = None,
|
||||||
rng_seed = None,
|
rng_seed = None):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Draw random rotation.
|
Draw random rotation.
|
||||||
|
|
||||||
|
@ -878,8 +870,7 @@ class Rotation:
|
||||||
sigma,
|
sigma,
|
||||||
N = 500,
|
N = 500,
|
||||||
degrees = True,
|
degrees = True,
|
||||||
rng_seed = None,
|
rng_seed = None):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Calculate set of rotations with Gaussian distribution around center.
|
Calculate set of rotations with Gaussian distribution around center.
|
||||||
|
|
||||||
|
@ -915,8 +906,7 @@ class Rotation:
|
||||||
sigma = 0.0,
|
sigma = 0.0,
|
||||||
N = 500,
|
N = 500,
|
||||||
degrees = True,
|
degrees = True,
|
||||||
rng_seed = None,
|
rng_seed = None):
|
||||||
**kwargs):
|
|
||||||
"""
|
"""
|
||||||
Calculate set of rotations with Gaussian distribution around direction.
|
Calculate set of rotations with Gaussian distribution around direction.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue