You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow negation of representations with differentials #10987
Currently, negation of representations that include differentials leads to an error, even though it is quite clearly defined for any derivative. This is a bit annoying since it does not easily allow a position offset with a velocity offset to be negated leading to unnecessary logic to calculate either the offset from the sun to the barycentre or its reverse (see #10970)
While I believe that the negation of a Cartesian representation/differential is uncontroversial, I suspect that it may be controversial for other representations, e.g., cylindrical:
>>>importastropy.coordinates.representationasr>>>importastropy.unitsasu>>>pos=r.CartesianRepresentation(1, 0, 0)*u.m>>>vel=r.CartesianDifferential(0, 1, 0)*u.m/u.s# The velocity converted to cylindrical components>>>vel.represent_as(r.CylindricalDifferential, pos)
<CylindricalDifferential (d_rho, d_phi, d_z) in (m/s, rad/s, m/s)
(0., 1., 0.)># If cylindrical velocity is directly negated, it negates the cylindrical components# The sign for `d_phi` has changed ==> the circulation is reversed>>>-vel.represent_as(r.CylindricalDifferential, pos)
<CylindricalDifferential (d_rho, d_phi, d_z) in (m/s, deg/s, m/s)
(-0., -1., -0.)># The natural negation of the Cartesian representation/differential is {-pos, -vel}# We then convert the new velocity to cylindrical components# Note that the sign for `d_phi` has not changed ==> the circulation is preserved>>> (-vel).represent_as(r.CylindricalDifferential, -pos)
<CylindricalDifferential (d_rho, d_phi, d_z) in (m/s, rad/s, m/s)
(1.2246468e-16, 1., -0.)>
That is, the "right" answer for a cylindrical representation/differential depends on whether you think that the circulation should be preserved/reversed. Note that expecting the circulation to be reversed when working in cylindrical could be weird because walking through Cartesian would always preserve the circulation.
@ayshih - agreed one has to be a bit careful, but I think one can make things clear and consistent by insisting that for any operation, the answer does not matter in what representation it is done, i.e., there is a default that converts to cartesian, applies the operation, and the converts back, and there are also shortcuts that give the same result. Indeed, this is how all the operations are implemented right now on representations without differentials. I think the problem with differentials is that for higher order ones, it might be less clear on how to proceed - but that is basically because we cannot yet transform them properly to cartesian in the first place.
Activity
ayshih commentedon Nov 5, 2020
While I believe that the negation of a Cartesian representation/differential is uncontroversial, I suspect that it may be controversial for other representations, e.g., cylindrical:
That is, the "right" answer for a cylindrical representation/differential depends on whether you think that the circulation should be preserved/reversed. Note that expecting the circulation to be reversed when working in cylindrical could be weird because walking through Cartesian would always preserve the circulation.
mhvk commentedon Nov 5, 2020
@ayshih - agreed one has to be a bit careful, but I think one can make things clear and consistent by insisting that for any operation, the answer does not matter in what representation it is done, i.e., there is a default that converts to cartesian, applies the operation, and the converts back, and there are also shortcuts that give the same result. Indeed, this is how all the operations are implemented right now on representations without differentials. I think the problem with differentials is that for higher order ones, it might be less clear on how to proceed - but that is basically because we cannot yet transform them properly to cartesian in the first place.