not specific to Orientation class

This commit is contained in:
Martin Diehl 2020-11-14 19:51:15 +01:00
parent 149fce0a7e
commit 1eb9d494c7
2 changed files with 32 additions and 32 deletions

View File

@ -4,7 +4,7 @@ from . import Rotation
from . import util
from . import mechanics
__parameter_doc__ = \
_parameter_doc = \
"""lattice : str
Either a crystal family out of [triclinic, monoclinic, orthorhombic, tetragonal, hexagonal, cubic]
or a Bravais lattice out of [aP, mP, mS, oP, oS, oI, oF, tP, tI, hP, cP, cI, cF].
@ -27,22 +27,6 @@ __parameter_doc__ = \
"""
def extend_docstring():
"""Decorator: Append Orientation parameter documentation to function's docstring."""
def _decorator(func):
func.__doc__ += __parameter_doc__
return func
return _decorator
def extended_docstring(f):
"""Decorator: Combine Orientation parameter documentation with another function's docstring."""
def _decorator(func):
func.__doc__ = f.__doc__ + __parameter_doc__
return func
return _decorator
class Orientation(Rotation):
"""
Representation of crystallographic orientation as combination of rotation and either crystal family or Bravais lattice.
@ -128,7 +112,7 @@ class Orientation(Rotation):
}
@extend_docstring()
@util.extend_docstring(_parameter_doc)
def __init__(self,
rotation = None,
lattice = None,
@ -279,73 +263,73 @@ class Orientation(Rotation):
@classmethod
@extended_docstring(Rotation.from_random)
@util.extended_docstring(Rotation.from_random,_parameter_doc)
def from_random(cls,**kwargs):
return cls(rotation=Rotation.from_random(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_quaternion)
@util.extended_docstring(Rotation.from_quaternion,_parameter_doc)
def from_quaternion(cls,**kwargs):
return cls(rotation=Rotation.from_quaternion(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_Eulers)
@util.extended_docstring(Rotation.from_Eulers,_parameter_doc)
def from_Eulers(cls,**kwargs):
return cls(rotation=Rotation.from_Eulers(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_axis_angle)
@util.extended_docstring(Rotation.from_axis_angle,_parameter_doc)
def from_axis_angle(cls,**kwargs):
return cls(rotation=Rotation.from_axis_angle(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_basis)
@util.extended_docstring(Rotation.from_basis,_parameter_doc)
def from_basis(cls,**kwargs):
return cls(rotation=Rotation.from_basis(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_matrix)
@util.extended_docstring(Rotation.from_matrix,_parameter_doc)
def from_matrix(cls,**kwargs):
return cls(rotation=Rotation.from_matrix(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_Rodrigues)
@util.extended_docstring(Rotation.from_Rodrigues,_parameter_doc)
def from_Rodrigues(cls,**kwargs):
return cls(rotation=Rotation.from_Rodrigues(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_homochoric)
@util.extended_docstring(Rotation.from_homochoric,_parameter_doc)
def from_homochoric(cls,**kwargs):
return cls(rotation=Rotation.from_homochoric(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_cubochoric)
@util.extended_docstring(Rotation.from_cubochoric,_parameter_doc)
def from_cubochoric(cls,**kwargs):
return cls(rotation=Rotation.from_cubochoric(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_spherical_component)
@util.extended_docstring(Rotation.from_spherical_component,_parameter_doc)
def from_spherical_component(cls,**kwargs):
return cls(rotation=Rotation.from_spherical_component(**kwargs),**kwargs)
@classmethod
@extended_docstring(Rotation.from_fiber_component)
@util.extended_docstring(Rotation.from_fiber_component,_parameter_doc)
def from_fiber_component(cls,**kwargs):
return cls(rotation=Rotation.from_fiber_component(**kwargs),**kwargs)
@classmethod
@extend_docstring()
@util.extend_docstring(_parameter_doc)
def from_directions(cls,uvw,hkl,**kwargs):
"""
Initialize orientation object from two crystallographic directions.

View File

@ -26,8 +26,8 @@ __all__=[
'return_message',
'extendableOption',
'execution_stamp',
'shapeshifter',
'shapeblender',
'shapeshifter', 'shapeblender',
'extend_docstring', 'extended_docstring'
]
####################################################################################################
@ -302,6 +302,22 @@ def shapeblender(a,b):
return a + b[i:]
def extend_docstring(general):
"""Decorator: Append Orientation parameter documentation to function's docstring."""
def _decorator(func):
func.__doc__ += general
return func
return _decorator
def extended_docstring(f,general):
"""Decorator: Combine Orientation parameter documentation with another function's docstring."""
def _decorator(func):
func.__doc__ = f.__doc__ + general
return func
return _decorator
####################################################################################################
# Classes
####################################################################################################