pyxem / orix

Analysing crystal orientations and symmetry in Python
https://orix.readthedocs.io
GNU General Public License v3.0
78 stars 45 forks source link

Mathematical notation, more convenient random(), inv() equal to "~" #464

Closed hakonanes closed 7 months ago

hakonanes commented 7 months ago

Description of the change

This PR contains several improvements, most notably adding a consistent mathematical notation. I realize that capitalized variable names, especially just O (for orientations), are frowned upon. Just see the PEP 8 style guide which we follow closely... I'm open to changing the notation. The notation is listed in the contributing guide.

Other additions:

Changes:

Progress of the PR

Minimal example of the bug fix or new feature

>>> import numpy as np
>>> from orix.crystal_map import Phase
>>> from orix.quaternion import Misorientation, Orientation, symmetry
>>> from orix.vector import Miller, Vector3d

>>> v = Vector3d.random(100)
>>> np.isclose(v.norm, 1).all()
True
>>> _ = v.reshape((10, 10)).reshape(4, 5, 5)

>>> cubic = Phase(point_group="m-3m")
>>> g = Miller.random(cubic, (2, 3), "hkl")
>>> g
Miller (2, 3), point group m-3m, hkl
[[[ 0.6439 -0.2434 -0.7253]
  [-0.5368  0.7654 -0.3549]
  [-0.3677  0.925  -0.0951]]
 [[-0.2624 -0.2891 -0.9206]
  [ 0.8905 -0.3044 -0.3382]
  [-0.2024 -0.8396 -0.504 ]]]

>>> O = Orientation.random(5, symmetry.Oh)
>>> M1 = Misorientation(O * O.inv())
>>> M1
Misorientation (5,) 1
[[ 1.  0.  0.  0.]
 [ 1.  0. -0.  0.]
 [ 1.  0.  0.  0.]
 [ 1.  0.  0.  0.]
 [ 1.  0.  0.  0.]]

>>> M2 = Misorientation.random(5, (symmetry.Oh, symmetry.D6h))
>>> M2
Misorientation (5,) m-3m, 6/mmm
[[ 0.9342  0.356   0.0032  0.0242]
 [-0.724   0.5373  0.2002  0.3835]
 [ 0.108   0.7762  0.1533 -0.6019]
 [ 0.3663 -0.2224  0.5108  0.7452]
 [-0.4543 -0.7006 -0.4017  0.376 ]]

>>> M2.inv()
Misorientation (5,) 6/mmm, m-3m
[[ 0.9342 -0.356  -0.0032 -0.0242]
 [-0.724  -0.5373 -0.2002 -0.3835]
 [ 0.108  -0.7762 -0.1533  0.6019]
 [ 0.3663  0.2224 -0.5108 -0.7452]
 [-0.4543  0.7006  0.4017 -0.376 ]]

For reviewers

review-notebook-app[bot] commented 7 months ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

hakonanes commented 7 months ago

I'm sorry for the size of this PR. If necessary, I can split it into several smaller ones.

Nonetheless, everything is detailed in the top comment. And notebook changes can easily be reviewed at ReviewNB.

pc494 commented 7 months ago

I am happy to review this over the weekend.

hakonanes commented 7 months ago

Thank you for having a look, Phillip, really appreciate it. Yes, I'll make coming PRs much more manageable.