Merge branch 'normalize-to_pole' into 'development'

normalize to_pole output by default

See merge request damask/DAMASK!578
This commit is contained in:
Martin Diehl 2022-05-15 21:46:27 +00:00
commit 6c7f2344da
3 changed files with 27 additions and 12 deletions

View File

@ -786,7 +786,8 @@ class Orientation(Rotation,Crystal):
def to_pole(self, *,
uvw: FloatSequence = None,
hkl: FloatSequence = None,
with_symmetry: bool = False) -> np.ndarray:
with_symmetry: bool = False,
normalize: bool = True) -> np.ndarray:
"""
Calculate lab frame vector along lattice direction [uvw] or plane normal (hkl).
@ -795,18 +796,26 @@ class Orientation(Rotation,Crystal):
uvw|hkl : numpy.ndarray, shape (...,3)
Miller indices of crystallographic direction or plane normal.
Shape of vector blends with shape of own rotation array.
For example, a rotation array, shape (3,2) and a vector array of shape (2,4) result in (3,2,4) outputs.
For example, a rotation array of shape (3,2) and a vector
array of shape (2,4) result in (3,2,4) outputs.
with_symmetry : bool, optional
Calculate all N symmetrically equivalent vectors.
Defaults to False.
normalize : bool, optional
Normalize output vector.
Defaults to True.
Returns
-------
vector : numpy.ndarray, shape (...,3) or (...,N,3)
Lab frame vector (or vectors if with_symmetry) along [uvw] direction or (hkl) plane normal.
Lab frame vector (or vectors if with_symmetry) along
[uvw] direction or (hkl) plane normal.
"""
v = self.to_frame(uvw=uvw,hkl=hkl)
blend = util.shapeblender(self.shape,v.shape[:-1])
if normalize:
v /= np.linalg.norm(v,axis=-1,keepdims=len(v.shape)>1)
if with_symmetry:
sym_ops = self.symmetry_operations
shape = v.shape[:-1]+sym_ops.shape

View File

@ -1023,26 +1023,26 @@ class Result:
@staticmethod
def _add_pole(q,uvw,hkl,with_symmetry):
def _add_pole(q,uvw,hkl,with_symmetry,normalize):
c = q['meta']['c/a'] if 'c/a' in q['meta'] else 1
brackets = ['[]','()','⟨⟩','{}'][(uvw is None)*1+with_symmetry*2]
label = 'p^' + '{}{} {} {}{}'.format(brackets[0],
*(uvw if uvw else hkl),
brackets[-1],)
pole = Orientation(q['data'],lattice=q['meta']['lattice'],a=1,c=c).to_pole(uvw=uvw,hkl=hkl,with_symmetry=with_symmetry)
ori = Orientation(q['data'],lattice=q['meta']['lattice'],a=1,c=c)
return {
'data': pole,
'data': ori.to_pole(uvw=uvw,hkl=hkl,with_symmetry=with_symmetry,normalize=normalize),
'label': label,
'meta' : {
'unit': '1',
'description': 'lab frame vector along lattice ' \
+ ('direction' if uvw else 'plane') \
'description': f'{"normalized " if normalize else ""}lab frame vector along lattice ' \
+ ('direction' if uvw is not None else 'plane') \
+ ('s' if with_symmetry else ''),
'creator': 'add_pole'
}
}
def add_pole(self,q='O',*,uvw=None,hkl=None,with_symmetry=False):
def add_pole(self,q='O',*,uvw=None,hkl=None,with_symmetry=False,normalize=True):
"""
Add lab frame vector along lattice direction [uvw] or plane normal (hkl).
@ -1055,9 +1055,15 @@ class Result:
Miller indices of crystallographic direction or plane normal.
with_symmetry : bool, optional
Calculate all N symmetrically equivalent vectors.
Defaults to True.
normalize : bool, optional
Normalize output vector.
Defaults to True.
"""
self._add_generic_pointwise(self._add_pole,{'q':q},{'uvw':uvw,'hkl':hkl,'with_symmetry':with_symmetry})
self._add_generic_pointwise(self._add_pole,
{'q':q},
{'uvw':uvw,'hkl':hkl,'with_symmetry':with_symmetry,'normalize':normalize})
@staticmethod

View File

@ -180,8 +180,8 @@ class TestOrientation:
o = Orientation.from_directions(uvw=a,hkl=c,**kwargs)
x = o.to_pole(uvw=a)
z = o.to_pole(hkl=c)
assert np.isclose(np.dot(x/np.linalg.norm(x),np.array([1,0,0])),1) \
and np.isclose(np.dot(z/np.linalg.norm(z),np.array([0,0,1])),1)
assert np.isclose(np.dot(x,np.array([1,0,0])),1) \
and np.isclose(np.dot(z,np.array([0,0,1])),1)
@pytest.mark.parametrize('function',[Orientation.from_random,
Orientation.from_quaternion,