Repository navigation
Add transform method to all representations - #11444
Conversation
|
Hello @nstarman 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2021-04-20 17:16:15 UTC |
9636c57 to
1688671
Compare
|
Now I'm looking at |
|
General comment: I don't think we use a non-cartesian matrix anywhere, and I must admit I have a hard time seeing what the use would be - in fact such a matrix cannot currently be represented properly as a Quantity. I would suggest focussing on just implementing the cartesian variant here, which does have direct use. |
mhvk
left a comment
There was a problem hiding this comment.
My sense would be to use this PR only to change the representations and test those. In particular, I'd make a general transform method on BaseRepresentation, which just goes through Cartesian (i.e., does what is now done inside the transformation mechanism) and then override it on Spherical and UnitSpherical (have to do the latter too, since the general case will no longer have unit distance).
In the transformation machinery, in the first instance we can then simply stop worrying about converting to/from cartesian, and in the second instance we can start to call using the explicit flag for cases where we know a priori it is a rotation matrix.
|
On the spherical matrix for transform, maybe another way to express why I'm not quite sure that is useful is just to think that in the end one if multiplying the longitude and latitude with numbers, which does not seem to be very useful! |
7d7066e to
bfcac33
Compare
|
@mhvk, I reimplemented the representation transformations as you suggested. |
|
I've implemented the flag "is_rotation" for static and dynamic matrix transforms. |
|
@mhvk @adrn , rotation matrix checks now broadcast. All built-in coordinate transforms that use a StaticMatrixTransform and DynamicMatrixTransform now use the flag "is_rotation". #FightTheNaN Edit: I'm having trouble diagnosing the errors. Many seem related to AffineTransform, which should not be impacted by this PR. |
|
@nstarman - while reviewing your new additions, it suddenly struck me that perhaps we are making it too complicated. How about we we do define a general (in principle, to avoid this being slower, one might implement this a bit more explicitly, e.g., using With that, the only other thing needed would be to remove the transformations to Cartesian in the coordinate machinery. What do you think? |
mhvk
left a comment
There was a problem hiding this comment.
Hmm, had some comments, but am now thinking we should just write the transformation such that the distance is done separately anyway - see in main thread... (so, this is not quite complete either...)
astropy#11444 (comment) Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
|
@nstarman - before we go further, what about my larger suggestion, at #11444 (comment)? It avoids even the need of checking/tracking whether something is a rotation matrix. |
|
@mhvk, I really like the idea, and it works wonderfully for representations, but I don't think it works for differentials. Consequentially, if the transformation matrix is not a rotation, setting the radial component to 0 before applying the matrix destroys information. Therefore, only when the radial effect of the matrix is known a priori (eg none for a rotation) can we shortcut in this manner. This can be seen in the following code snippet, which is the transformation for differentials in the SphericalRepresentation.transform, when the matrix is a rotation matrix: for the representation we can multiply by the distance (or assign since it's 1), for the differentials we must add (or assign since it's 0). Edit: as a more detailed demonstration, the radial component of the differential cannot be rescaled and the process is therefore not information-preserving. I haven't looked into speedups using |
|
@nstarman - I think it could still work in principle, if one took care to split out the radial velocity component and treat that separately (for higher order derivatives this becomes quite painful, but we cannot deal with those properly yet anyway). But perhaps it still makes sense to decouple the representations from the differentials? First move |
applied suggested ``. _re_represent_differentials()`` method. Split from astropy#11444 (suggested in comment by @mhvk) Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
|
Note: #11470 will simplify rescaling. Don't need to strip differentials. |
Rotation matrices are routed through UnitSpherical to prevent NaN leakage. unit-spherical transform shortcut spherical transform with differentials override for PhysicsSpherical representations have transformations apply @mhvk suggestion | astropy#11444 (comment) Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
Rotation matrices are routed through UnitSpherical to prevent NaN leakage. unit-spherical transform shortcut spherical transform with differentials override for PhysicsSpherical representations have transformations apply @mhvk suggestion | astropy#11444 (comment) Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
Rotation matrices are routed through UnitSpherical to prevent NaN leakage. unit-spherical transform shortcut spherical transform with differentials override for PhysicsSpherical representations have transformations apply @mhvk suggestion | astropy#11444 (comment) Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
adrn
left a comment
There was a problem hiding this comment.
Overall looks great. Mostly minor nitpicks or questions from me!
|
So, with #11568 the |
representations have transformations tests changelog Co-authored-by: Marten van Kerkwijk (@mhvk) Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
push differentials to a future PR. Co-authored-by: Adrian Price-Whelan <[email protected]> Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
|
🤞 |
mhvk
left a comment
There was a problem hiding this comment.
Looks all OK, but on final review one super nitpicky comment about the tests... If you're fed up, though, I'll merge as is...
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
|
And let's get this in as well! Next, the differentials... (but maybe after #11470?) |
|
Wooh! Thanks for the collab @mhvk @adrn. Good to get this in. It seems the overall plan of action is: #11470 -> |
|
Should this be in the whatsnew? |
|
My sense is to have a what's-new together with the larger overhaul in #11470 - which means perhaps for 5.0 - since the whole makes working with representations as vectors much easier. On its own, there is probably no reason for the average user to know about this, as it will mainly have (nice!) impacts on our internal implementation of coordinate transformations. |




Description (edited)
All representations now have a
transformmethod, which allows them to betransformed by a 3x3 matrix in a Cartesian basis. By default, transformations
are routed through
CartesianRepresentation.SphericalRepresentationandPhysicssphericalRepresentationoverride this for speed and to prevent NaNleakage from the distance to the angular components.
Also, add a utility function in
matrix_utitiesto check whether a matrix isa rotation (proper or improper).
@mhvk @adrn
closes #11423
Blocked by #11568
Signed-off-by: Nathaniel Starkman (@nstarman)