-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making Orientations a child class of Rotations, not Misorientations #345
Comments
Hi @argerlt, I've seen your hackathon fork, and think it's great that you're reaching out to us now, even during the hackathon! As far as I know, the choice of orix/orix/quaternion/orientation.py Lines 473 to 474 in 14639a1
With the initial functionality, this made sense and made for a slightly simpler implementation. The functionality and use cases of mainly @pc494, who've been part of the project from the beginning might have some additional corrections to my "historical review". |
Thanks, I'll give it a try. And yeah, as a general FYI, we are trying to recreate a very specific piece of software that exists in MTEX but not in python, and Orix was agreed upon as the best starting point for a pythonic equivalent. As such, most of those forks and subforks contains a LOT of things you won't find useful, but the ideal goal is after this finishes up, myself and Steve Niezgoda will take the parts that might be useful to the greater Orix crowd and start adding those as pull requests. |
This sounds excellent! Looking forward to it! |
Thank you. I'd wait a couple days though, until @pc494 has gotten the possibility to give his opinion. If he agrees that this is the best way forward, feel free to open a PR early so that we can give pointers early on! |
Sorry to jump in late with an opinion against the flow, but the choice of inheritance of The idea was that While I'm committed to that as a way of understanding the situation, I've yet to work over any programming problems it causes and so it may make sense to change things internally. @argerlt would you be able to scope out the programming problems in a little more detail? |
I saw your issue mesoOSU#48, @argerlt. Don't know whether you've moved on beyond what's in that issue, but a misorientation >>> import numpy as np
>>> from orix.quaternion import Misorientation, Orientation, symmetry
>>> o1 = Orientation.from_axes_angles((0, 0, -1), np.pi / 2, symmetry.Oh)
>>> o1
Orientation (1,) m-3m
[[ 0.7071 0. 0. -0.7071]]
>>> np.rad2deg(o1.to_euler())
array([[90., 0., 0.]])
>>> o2 = Orientation.from_axes_angles((0, 0, -1), np.pi, symmetry.Oh)
>>> o2
Orientation (1,) m-3m
[[ 0. 0. 0. -1.]]
>>> np.rad2deg(o2.to_euler())
array([[180., 0., 0.]])
>>> o12 = o2 * ~o1 # ~ inverts the orientation, equivalent to inv() in MTEX
>>> m12 = Misorientation(o12, (o1.symmetry, o2.symmetry))
>>> m12
Misorientation (1,) m-3m, m-3m
[[ 0.7071 0. 0. -0.7071]]
>>> np.rad2deg(m12.to_euler())
array([[90., 0., 0.]]) I agree that this approach is not well explained in the documentation. To tackle this we should add a "Misorientation" topic similar to the "Orientation" topic, and start to add at least some basic handling of misorientations there. When it comes to the operation
|
Sorry for the radio silence. @pc494, my logic for switching the class inheritance is three-fold. First is philosophical, second is practical, third is very specific to my needs:
Also, in reference to your point:
I agree making redundant docstrings should be avoided, 100% with you on that point. However, the facts that "symmetry" has to be overwritten between the functions, that they have different possible symmetries, and that m(o1,o2) has meaning but o(m1,m2) does not suggests they are not equivalent and should not have equivalent documentation. I think its fair to be against the "misorientation.from_orientations" suggestion, but "Misorientation.from_orientations" would for sure be a useful function, and that would definitely violate LSP with the current structure. Trying to add that function while avoiding an infinite recursion issue is what originally made me want to suggest change in inheritance. One way to fix all this without writing a lot of redundant code or function inheritance would be if both Orientation and Misorientation inherited from some middle class that contained shared functions which don't belong in Rotation, but not sure what you would call that. BaseOrientation maybe? seems like there should be a better name, but I'm coming up blank. |
Okay, I think I've been won around here. For the original purpose of orix, it certainly made sense to highlight the similarity between these two objects. But now, especially if the package moves in the MDF, ODF direction this is no longer the case. I think/agree there is some merit to a class (potentially an abstract and/or private one) that sits above |
Hey, sorry for the long radio silence, but quick update/question for the experts: After spending a few weeks poking around on this, it seemed to me the best solution was to move all the symmetry aware functions out of However, Symmetry is a subclass of Rotation, so doing what was described above would cause circular imports. @hakonanes and @pc494, Is there some reason it wouldn't make sense to make symmetry instead inherit from Quaternion, then just moves the to/from and angle functions that Symmetry uses down into Quaternion as well? this way, Rotation could contain ALL the symmetry-aware functions, which Ori and Misori would inherit, and we could reduce the number of overwritten and repeated code. Other option is to create a function called Thoughts? |
For There are a lot of caveats and gotchas in orix, and I'm happy for any contributions trying to remove some of those. |
|
Continuing discussion from #373 (comment) and #373 (comment) (keeping that issue focused on Is it enough to add a special case in We should warn the user when they don't multiply an orientation with an inverted one, and for this we need an |
Coming back to this after a long break. Quick recap:
Current SetupThis is the current class inheritance layout: Proposed AlternateAt one point, we agreed it made sense to make the I like this a lot, it avoids long vertical overwrites of functions like "flatten", and allows users to write Rot/Mis/Ori specific functions. I'm over half done with a pull request that would implement this. However, it does mean giving I have some other alternatives I thought of if an improper 'Quaternion` is a deal breaker, but wanted feedback on this first. |
Hi @argerlt, its great that you have found time to look at class inheritance in orix! If you can, I suggest you open a PR as soon as you have something you want discussed. As @pc494 always says, this ensures we know what others are doing so that we pull in the same direction. I have a conference next week, but will get back to this discussion after that.
We can avoid this by importing within the method instead of at the top of a file. The reason why this works, I think, is that when the method is called, the first class (of the method) has already been imported, so importing the second class (which imports the first class) doesn't error. Have you tried this? If this is the real show stopper, we might look into this before restructuring everything. Just a thought. |
I'd like to write some class method constructors for Misorientations which generates them from paired lists or arrays of orientations, as well as some other misorientation-specific functions.
Right now, Orientations use Misorientations as a base class, which violates Liskov substitution principle and leads to odd edge cases such as calling Orientation.equivalent(ori) and getting a doc string referencing misorientations. It would really make more sense to make both use rotations as a base class, as opposed to overwriting their shared functions. For my specific case, this would make writing the classmethods a lot more straight forward.
I was about to reorganize this for my own use anyway, but before i did, I wanted to check if there was a bigger reason I didn't understand/appreciate for misorientations being a base class for orientations.
Thanks, I'm a big fan of orix.
The text was updated successfully, but these errors were encountered: