Repository navigation
Conversation
|
@ayshih - by way of background, for the I think the lack of auto-transfer of attributes was partially on purpose, since the idea was that frames are quite basic and one should just specify exactly what one wants. That said, it is not obvious to me this has to be this way... cc @eteq, @astropy/bots I guess one question is whether there is any particular reason you want to work with the frames directly instead of with |
|
In the example I provided, I think it can be confusing to users that the Certainly my advice to SunPy users who've encountered undesired behavior with Personally, the behavior that I'd like to fix is in the internals of astropy/astropy/coordinates/attributes.py Line 449 in 2023292 .transform_to() is currently written, it uses all default attribute values for the output frame, rather than preserving anything from the input. On the SunPy side, we want to preserve the input obstime, and we achieve it by having our transformations themselves do the transferring of obstime. However, that falls apart when the overall transformation path has intermediate legs of Astropy transformations.
Admittedly, a custom |
|
@ayshih - I agree it is confusing and I think it might well make more sense to have the frame For the |
|
Hi @mhvk and @ayshih - I totally agree that the example provided is confusing. Also, I think that the behaviour enabled by this PR is slightly less confusing. But the crucial behaviour is still "hidden" and will catch some people out - so it's still a potential area of misuse. I'm not sure I'm keen on introducing a change that will break someones code to move to a situation that's only slightly less bad. I wonder if a more radical change here is actually better, and we should deprecate passing classes to |
In fact, even though
Fair enough!
The more I consider this "radical change", the more I like it! It draws a brighter line between working with |
|
In the larger picture, for Note that I changed my mind twice, since just letting the class stand for the "default instance" seemed harmless. I do think @StuartLittlefair is right that to change the meaning to be "an instance with attributes like that of the original frame where possible", while better than "default instance", is too risky -- or rather, too late to change it. Overall, given my changes of mind, I guess we need to be sure to write this up carefully! |
|
Actually, maybe this situation also points to a way to help make things clearer to the user, that a frame is really mostly meant as a way to describe the orientation of the reference system, with a bit more detail also on how the standard representations look like, but the fact that a frame holds the positional data is at some level an implementation detail [1]. Really, In this respect, might it make sense for p.s. The above is beginning to look awfully like three related but separate issues... [1] APE5 notes about frames: "While it may at first make sense to separate specifying frames from the actual representations in those frames, doing so would result in a large amount of code duplication, as each system would require two very similar classes for specifying a frame and for the objects containing the representations. Hence, here we combine them into a single class that is a pure frame if it does not have position data, but if it does, is actually a coordinate." (see also the discussion of alternatives; I'm not sure I 100% agree, but that obviously is water under the bridge) |
Thanks for pointing to the APE! I've never actually read it, and it's nice to appreciate the context of design choices.
Are these the three issues you have in mind?
|
|
Yes, indeed, those three exactly! For (3), one "solution" might be for input that is a frame to first make it a As for the output, it might be interesting to see if any tests break if we change it to |
|
I've created #10475 for the suggested changes, so all future discussion should go there. I'll go ahead and close this PR. |
The problem
When transforming a coordinate frame (not a
SkyCoord) to a class, the destination frame is instantiated with default values for all of its frame attributes:Note that the coordinate has been transformed to
equinoxandobstimeat the default values ofJ2000.0, rather than preserving the original values. This behavior is particularly annoying when a frame attribute has the default value ofNone. Importantly,SkyCoordbehaves differently with the analogous call because it carries over all frame attributes (with the default setting ofmerge_attributes=True):This PR
This PR changes the behavior of
BaseCoordinateFrame.transform_to()so that if it is provided a class, the target frame is instantiated with the values of any shared frame attributes if they are not default values. All other frame attributes will have default values. With this PR:Still not quite the same as
SkyCoordThe way I have currently implemented it, this new behavior occurs only when transforming to a class.
SkyCoordis even more aggressive than that (with the default setting ofmerge_attributes=True) because it also preserves frame attributes when the target is a frame rather than just a class by overwriting any shared frame attributes that are still at their default values. That is, even with this PR:Of course, this PR may have negative impacts that I'm not aware of. Thoughts?