use symmetry-aware Miller brackets in Result.add_pole

This commit is contained in:
Philip Eisenlohr 2022-05-10 15:25:45 -04:00
parent 675e9c911d
commit c9f344758a
2 changed files with 21 additions and 14 deletions

View File

@ -1025,17 +1025,21 @@ class Result:
@staticmethod @staticmethod
def _add_pole(q,uvw,hkl,with_symmetry): def _add_pole(q,uvw,hkl,with_symmetry):
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
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) pole = Orientation(q['data'],lattice=q['meta']['lattice'],a=1,c=c).to_pole(uvw=uvw,hkl=hkl,with_symmetry=with_symmetry)
return { return {
'data': pole, 'data': pole,
'label': 'p^[{} {} {}]'.format(*uvw) if uvw else 'p^({} {} {})'.format(*hkl), 'label': label,
'meta' : { 'meta' : {
'unit': '1', 'unit': '1',
'description': 'lab frame vector along lattice ' \ 'description': 'lab frame vector along lattice ' \
+ ('direction' if uvw else 'plane') \ + ('direction' if uvw else 'plane') \
+ ('s' if with_symmetry else ''), + ('s' if with_symmetry else ''),
'creator': 'add_pole' '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):
@ -1047,7 +1051,7 @@ class Result:
q : str q : str
Name of the dataset containing the crystallographic orientation as quaternions. Name of the dataset containing the crystallographic orientation as quaternions.
Defaults to 'O'. Defaults to 'O'.
uvw|hkl : numpy.ndarray of shape (...,3) uvw|hkl : numpy.ndarray of shape (3)
Miller indices of crystallographic direction or plane normal. Miller indices of crystallographic direction or plane normal.
with_symmetry : bool, optional with_symmetry : bool, optional
Calculate all N symmetrically equivalent vectors. Calculate all N symmetrically equivalent vectors.

View File

@ -24,8 +24,7 @@ def default(tmp_path,ref_path):
"""Small Result file in temp location for modification.""" """Small Result file in temp location for modification."""
fname = '12grains6x7x8_tensionY.hdf5' fname = '12grains6x7x8_tensionY.hdf5'
shutil.copy(ref_path/fname,tmp_path) shutil.copy(ref_path/fname,tmp_path)
f = Result(tmp_path/fname) return Result(tmp_path/fname).view(times=20.0)
return f.view(times=20.0)
@pytest.fixture @pytest.fixture
def single_phase(tmp_path,ref_path): def single_phase(tmp_path,ref_path):
@ -226,15 +225,19 @@ class TestResult:
assert np.allclose(in_memory,in_file) assert np.allclose(in_memory,in_file)
@pytest.mark.parametrize('options',[{'uvw':[1,0,0],'with_symmetry':False}, @pytest.mark.parametrize('options',[{'uvw':[1,0,0],'with_symmetry':False},
{'hkl':[0,1,1],'with_symmetry':True}]) {'uvw':[1,1,0],'with_symmetry':True},
{'hkl':[0,1,1],'with_symmetry':True},
{'hkl':[1,1,1],'with_symmetry':False},
])
def test_add_pole(self,default,options): def test_add_pole(self,default,options):
default.add_pole(**options) default.add_pole(**options)
rot = default.place('O') rot = default.place('O')
in_memory = Orientation(rot,lattice=rot.dtype.metadata['lattice']).to_pole(**options) in_memory = Orientation(rot,lattice=rot.dtype.metadata['lattice']).to_pole(**options)
brackets = ['[[]','[]]'] if 'uvw' in options.keys() else ['(',')'] # escape fnmatch brackets = [['[[]','[]]'],'()','〈〉','{}'][('hkl' in options)*1+(options['with_symmetry'])*2] # escape fnmatch
label = '{}{} {} {}{}'.format(brackets[0],*(list(options.values())[0]),brackets[1]) label = 'p^{}{} {} {}{}'.format(brackets[0],
in_file = default.place(f'p^{label}') *(list(options.values())[0]),
print(in_file - in_memory) brackets[-1])
in_file = default.place(label)
assert np.allclose(in_memory,in_file) assert np.allclose(in_memory,in_file)
def test_add_rotation(self,default): def test_add_rotation(self,default):