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
SkyCoord is_equivalent_frame behaves oddly #5478
Comments
@alexrudy - this is actually intended behavior, if counter-intuitive. If you look in the
The reason for this is a bit subtle:
it would be very surprising to find that To get the behavior I think you're looking for, you could replace your assert instead with:
which checks the frame objections themselves, and they have no knowledge of the extra |
If that makes sense, @alexrudy, I think you can go ahead and close this, as I don't think it's a bug. But if you have some thoughts about how we might make this clearer in the docs or something, feel free to keep this open to remind us to implement those ideas! (or PR youself if you have a firm enough idea) |
@eteq this makes sense if we are just using
and I'm not sure why that pattern shouldn't work or be allowed? Although it is nice to be able to transform back to the same frame with the same attributes, I do think that two coordinates that I have explicitly transformed to ICRS should be in equivalent frames? |
@alexrudy Could you provide some more context for the code in the above example, or ideally a snippet that reproduces the error? Also, I'm curious why you wouldn't just do |
@adrn I get a list of coordinates (from a user's starlist, for e.g. an observing run) which might be in different frames. But I want to use a catalog matching function, so I make them into a single sky coordinate in the same frame, usually 'icrs' because thats a good reference frame. But I can't just turn the list of SkyCoord objects into a single vector SkyCoord without first transforming them to the same frame. |
@eteq can you think of another reason why The conversion case posted by @alexrudy is a clear example of how the "hidden" storage of non relevant attributes leads to odd behaviour. |
@alexrudy - BTW, your use case has other issues. For example, what if some coords in your list have distances and some do not? See https://github.com/astropy/astroplan/pull/215/files for an example of how I addressed this problem. |
@StuartLittlefair Agreed, my method has issues if there are distances attached. Fortunately, my starlist format doesn't permit distances, so I'm fairly certain I'll end up with all-unitspherical coordinates. I'm happy for my method to raise an error in that case anyways. Or even better IMO would be if SkyCoord would accept something like:
and then it could raise an appropriate error if it can't convert everything to the same frame. |
I'm not sure how to proceed here. Although I think holding on to attributes is a nice feature for SkyCoord so that coordinates can round trip, I'm not sure about a few things:
@StuartLittlefair's referenced solution is fine, but really clunky for something that otherwise has a pretty nice high-level API. |
I'd like to poke at this again. If we can agree on how we expect the API to work, I'm happy to write the pull request to do so, but I feel like this discussion is stalling. |
Just adding a note that this and #3182 should probably be combined once we reach consensus. |
I expected that is_equivalent_frame() should return true if I e.g. convert a whole bunch of sky coords to 'icrs', but the following test fails on master.
In this example, note that
which is why
is_equivalent_frame()
fails.This came up when I was trying to turn a list of SkyCoord objects into a single SkyCoord object, using something like
SkyCoord([ c.transform_to('icrs') for c in my_coords])
The text was updated successfully, but these errors were encountered: