utility function without connection to an object
This commit is contained in:
parent
fc75efa4d0
commit
684016f3e3
|
@ -666,10 +666,10 @@ class Orientation(Rotation):
|
||||||
o = r[ol]
|
o = r[ol]
|
||||||
|
|
||||||
p_,_p = np.zeros(m.shape[:-1]+(3,)),np.zeros(o.shape[:-1]+(3,))
|
p_,_p = np.zeros(m.shape[:-1]+(3,)),np.zeros(o.shape[:-1]+(3,))
|
||||||
p_[...,0,:] = m[...,0,:] if m.shape[-1] == 3 else lattice_.Bravais_to_Miller(uvtw=m[...,0,0:4])
|
p_[...,0,:] = m[...,0,:] if m.shape[-1] == 3 else util.Bravais_to_Miller(uvtw=m[...,0,0:4])
|
||||||
p_[...,1,:] = m[...,1,:] if m.shape[-1] == 3 else lattice_.Bravais_to_Miller(hkil=m[...,1,0:4])
|
p_[...,1,:] = m[...,1,:] if m.shape[-1] == 3 else util.Bravais_to_Miller(hkil=m[...,1,0:4])
|
||||||
_p[...,0,:] = o[...,0,:] if o.shape[-1] == 3 else lattice_.Bravais_to_Miller(uvtw=o[...,0,0:4])
|
_p[...,0,:] = o[...,0,:] if o.shape[-1] == 3 else util.Bravais_to_Miller(uvtw=o[...,0,0:4])
|
||||||
_p[...,1,:] = o[...,1,:] if o.shape[-1] == 3 else lattice_.Bravais_to_Miller(hkil=o[...,1,0:4])
|
_p[...,1,:] = o[...,1,:] if o.shape[-1] == 3 else util.Bravais_to_Miller(hkil=o[...,1,0:4])
|
||||||
|
|
||||||
return (Rotation.from_parallel(p_,_p),ol) \
|
return (Rotation.from_parallel(p_,_p),ol) \
|
||||||
if return_lattice else \
|
if return_lattice else \
|
||||||
|
@ -1254,8 +1254,8 @@ class Orientation(Rotation):
|
||||||
master = lattice_.kinematics[self.lattice][mode]
|
master = lattice_.kinematics[self.lattice][mode]
|
||||||
kinematics = {'direction':master[:,0:3],'plane':master[:,3:6]} \
|
kinematics = {'direction':master[:,0:3],'plane':master[:,3:6]} \
|
||||||
if master.shape[-1] == 6 else \
|
if master.shape[-1] == 6 else \
|
||||||
{'direction':lattice_.Bravais_to_Miller(uvtw=master[:,0:4]),
|
{'direction':util.Bravais_to_Miller(uvtw=master[:,0:4]),
|
||||||
'plane': lattice_.Bravais_to_Miller(hkil=master[:,4:8])}
|
'plane': util.Bravais_to_Miller(hkil=master[:,4:8])}
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise (f'"{mode}" not defined for lattice "{self.lattice}"')
|
raise (f'"{mode}" not defined for lattice "{self.lattice}"')
|
||||||
d = self.to_frame(uvw=kinematics['direction'],with_symmetry=False)
|
d = self.to_frame(uvw=kinematics['direction'],with_symmetry=False)
|
||||||
|
|
|
@ -27,6 +27,7 @@ __all__=[
|
||||||
'execution_stamp',
|
'execution_stamp',
|
||||||
'shapeshifter', 'shapeblender',
|
'shapeshifter', 'shapeblender',
|
||||||
'extend_docstring', 'extended_docstring',
|
'extend_docstring', 'extended_docstring',
|
||||||
|
'Bravais_to_Miller', 'Miller_to_Bravais',
|
||||||
'DREAM3D_base_group', 'DREAM3D_cell_data_group',
|
'DREAM3D_base_group', 'DREAM3D_cell_data_group',
|
||||||
'dict_prune', 'dict_flatten'
|
'dict_prune', 'dict_flatten'
|
||||||
]
|
]
|
||||||
|
@ -499,6 +500,62 @@ def DREAM3D_cell_data_group(fname):
|
||||||
return cell_data_group
|
return cell_data_group
|
||||||
|
|
||||||
|
|
||||||
|
def Bravais_to_Miller(*,uvtw=None,hkil=None):
|
||||||
|
"""
|
||||||
|
Transform 4 Miller–Bravais indices to 3 Miller indices of crystal direction [uvw] or plane normal (hkl).
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
uvtw|hkil : numpy.ndarray of shape (...,4)
|
||||||
|
Miller–Bravais indices of crystallographic direction [uvtw] or plane normal (hkil).
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
uvw|hkl : numpy.ndarray of shape (...,3)
|
||||||
|
Miller indices of [uvw] direction or (hkl) plane normal.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if (uvtw is not None) ^ (hkil is None):
|
||||||
|
raise KeyError('Specify either "uvtw" or "hkil"')
|
||||||
|
axis,basis = (np.array(uvtw),np.array([[1,0,-1,0],
|
||||||
|
[0,1,-1,0],
|
||||||
|
[0,0, 0,1]])) \
|
||||||
|
if hkil is None else \
|
||||||
|
(np.array(hkil),np.array([[1,0,0,0],
|
||||||
|
[0,1,0,0],
|
||||||
|
[0,0,0,1]]))
|
||||||
|
return np.einsum('il,...l',basis,axis)
|
||||||
|
|
||||||
|
|
||||||
|
def Miller_to_Bravais(*,uvw=None,hkl=None):
|
||||||
|
"""
|
||||||
|
Transform 3 Miller indices to 4 Miller–Bravais indices of crystal direction [uvtw] or plane normal (hkil).
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
uvw|hkl : numpy.ndarray of shape (...,3)
|
||||||
|
Miller indices of crystallographic direction [uvw] or plane normal (hkl).
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
uvtw|hkil : numpy.ndarray of shape (...,4)
|
||||||
|
Miller–Bravais indices of [uvtw] direction or (hkil) plane normal.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if (uvw is not None) ^ (hkl is None):
|
||||||
|
raise KeyError('Specify either "uvw" or "hkl"')
|
||||||
|
axis,basis = (np.array(uvw),np.array([[ 2,-1, 0],
|
||||||
|
[-1, 2, 0],
|
||||||
|
[-1,-1, 0],
|
||||||
|
[ 0, 0, 3]])/3) \
|
||||||
|
if hkl is None else \
|
||||||
|
(np.array(hkl),np.array([[ 1, 0, 0],
|
||||||
|
[ 0, 1, 0],
|
||||||
|
[-1,-1, 0],
|
||||||
|
[ 0, 0, 1]]))
|
||||||
|
return np.einsum('il,...l',basis,axis)
|
||||||
|
|
||||||
|
|
||||||
def dict_prune(d):
|
def dict_prune(d):
|
||||||
"""
|
"""
|
||||||
Recursively remove empty dictionaries.
|
Recursively remove empty dictionaries.
|
||||||
|
|
|
@ -484,6 +484,7 @@ class TestOrientation:
|
||||||
assert np.allclose(vector,
|
assert np.allclose(vector,
|
||||||
L.to_frame(**{keyFrame:L.to_lattice(**{keyLattice:vector})}))
|
L.to_frame(**{keyFrame:L.to_lattice(**{keyLattice:vector})}))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('lattice,a,b,c,alpha,beta,gamma',
|
@pytest.mark.parametrize('lattice,a,b,c,alpha,beta,gamma',
|
||||||
[
|
[
|
||||||
('aP',0.5,2.0,3.0,0.8,0.5,1.2),
|
('aP',0.5,2.0,3.0,0.8,0.5,1.2),
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
import pytest
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
from damask import lattice
|
|
||||||
|
|
||||||
class TestLattice:
|
|
||||||
|
|
||||||
def test_double_Bravais_to_Miller(self):
|
|
||||||
with pytest.raises(KeyError):
|
|
||||||
lattice.Bravais_to_Miller(uvtw=np.ones(4),hkil=np.ones(4)) # noqa
|
|
||||||
|
|
||||||
def test_double_Miller_to_Bravais(self):
|
|
||||||
with pytest.raises(KeyError):
|
|
||||||
lattice.Miller_to_Bravais(uvw=np.ones(4),hkl=np.ones(4)) # noqa
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('vector',np.array([
|
|
||||||
[1,0,0],
|
|
||||||
[1,1,0],
|
|
||||||
[1,1,1],
|
|
||||||
[1,0,-2],
|
|
||||||
]))
|
|
||||||
@pytest.mark.parametrize('kw_Miller,kw_Bravais',[('uvw','uvtw'),('hkl','hkil')])
|
|
||||||
def test_Miller_Bravais_Miller(self,vector,kw_Miller,kw_Bravais):
|
|
||||||
assert np.all(vector == lattice.Bravais_to_Miller(**{kw_Bravais:lattice.Miller_to_Bravais(**{kw_Miller:vector})}))
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('vector',np.array([
|
|
||||||
[1,0,-1,2],
|
|
||||||
[1,-1,0,3],
|
|
||||||
[1,1,-2,-3],
|
|
||||||
[0,0,0,1],
|
|
||||||
]))
|
|
||||||
@pytest.mark.parametrize('kw_Miller,kw_Bravais',[('uvw','uvtw'),('hkl','hkil')])
|
|
||||||
def test_Bravais_Miller_Bravais(self,vector,kw_Miller,kw_Bravais):
|
|
||||||
assert np.all(vector == lattice.Miller_to_Bravais(**{kw_Miller:lattice.Bravais_to_Miller(**{kw_Bravais:vector})}))
|
|
|
@ -158,3 +158,33 @@ class TestUtil:
|
||||||
({'A':{'B':{},'C':'D'}}, {'B':{},'C':'D'})])
|
({'A':{'B':{},'C':'D'}}, {'B':{},'C':'D'})])
|
||||||
def test_flatten(self,full,reduced):
|
def test_flatten(self,full,reduced):
|
||||||
assert util.dict_flatten(full) == reduced
|
assert util.dict_flatten(full) == reduced
|
||||||
|
|
||||||
|
|
||||||
|
def test_double_Bravais_to_Miller(self):
|
||||||
|
with pytest.raises(KeyError):
|
||||||
|
util.Bravais_to_Miller(uvtw=np.ones(4),hkil=np.ones(4))
|
||||||
|
|
||||||
|
def test_double_Miller_to_Bravais(self):
|
||||||
|
with pytest.raises(KeyError):
|
||||||
|
util.Miller_to_Bravais(uvw=np.ones(4),hkl=np.ones(4))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('vector',np.array([
|
||||||
|
[1,0,0],
|
||||||
|
[1,1,0],
|
||||||
|
[1,1,1],
|
||||||
|
[1,0,-2],
|
||||||
|
]))
|
||||||
|
@pytest.mark.parametrize('kw_Miller,kw_Bravais',[('uvw','uvtw'),('hkl','hkil')])
|
||||||
|
def test_Miller_Bravais_Miller(self,vector,kw_Miller,kw_Bravais):
|
||||||
|
assert np.all(vector == util.Bravais_to_Miller(**{kw_Bravais:util.Miller_to_Bravais(**{kw_Miller:vector})}))
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('vector',np.array([
|
||||||
|
[1,0,-1,2],
|
||||||
|
[1,-1,0,3],
|
||||||
|
[1,1,-2,-3],
|
||||||
|
[0,0,0,1],
|
||||||
|
]))
|
||||||
|
@pytest.mark.parametrize('kw_Miller,kw_Bravais',[('uvw','uvtw'),('hkl','hkil')])
|
||||||
|
def test_Bravais_Miller_Bravais(self,vector,kw_Miller,kw_Bravais):
|
||||||
|
assert np.all(vector == util.Miller_to_Bravais(**{kw_Miller:util.Bravais_to_Miller(**{kw_Bravais:vector})}))
|
||||||
|
|
Loading…
Reference in New Issue