Skip to content

BUG: Frame attributes in sky coordinates do not obey Numpy broadcasting rules #8812

Closed

Description

@eteq

Originally prompted by @mhvk in #8805 (comment).

The crux of the issue is this: this doesn't work:

from astropy import units as u
from astropy.coordinates import FK5
from astropy.time import Time

FK5(0*u.deg, 0*u.deg, equinox=time.Time(['J2000', 'J2001']))

whereas this does:

FK5([0]*2*u.deg, [0]*2*u.deg, equinox=Time(['J2000', 'J2001']))

The latter proves that there's nothing in the machinery to prevent this all working the way you'd want, but the fact that the former fails is a sign that the broadcasting is not working the way you'd expect - e.g. 1 + np.random.randn(2) works just fine so it seems like the former example here should.

I consider this a bug because it was always the intent for broadcasting to work naturally in places like this.

cc @adrn

Activity

  1. added this to the v4.0 milestone on Jun 10, 2019
  2. Cadair commented on Jun 11, 2019

    @Cadair
    Member

    👍 this could be super useful for a bunch of SunPy stuff.

  3. mhvk commented on Jun 12, 2019

    @mhvk
    Contributor

    @eteq - now that I look at your examples again, I vaguely recall that at the time we felt that attributes should not have a shape that includes dimensions that the coordinates do not have. Indeed, we specifically test that the attribute can be broadcast to the shape of the representation.

    In principle, we can change this to a test that the attribute and the coordinates can be broadcast together - though for sure that means that we should then actually broadcast the coordinates (otherwise slicing will become strange), i.e., the output of your two examples should be identical (they both have shape (2,). Is this what you envision?

    A question that arises is what to do with setting an attribute after the fact. It may not be crazy to insist that for that case the attribute must still be broadcastable to the instance's shape, so that we can guarantee that the instances shape does not change.

    In fact, just doing it in the initializer might make things cleaner, as it may well be possible to avoid the specific logic for the case that a frame has no data

  4. mhvk commented on Oct 28, 2019

    @mhvk
    Contributor

    Doesn't seem like anybody is getting around to this, so removing milestone.

  5. removed this from the v4.0 milestone on Oct 28, 2019
  6. lpsinger commented on Apr 15, 2021

    @lpsinger
    Contributor

    A question that arises is what to do with setting an attribute after the fact. It may not be crazy to insist that for that case the attribute must still be broadcastable to the instance's shape, so that we can guarantee that the instances shape does not change.

    I agree with that.

  7. mhvk commented on Apr 15, 2021

    @mhvk
    Contributor

    @lpsinger - as I wrote over in #11571, I think your example serves to make clear that really we need to fix this! It should not actually be all that hard....

  8. changed the title [-]Make coordinates broadcast naturally across times[/-] [+]BUG: Frame attributes in sky coordinates do not obey Numpy broadcasting rules[/+] on Apr 15, 2021
  9. added a commit that references this issue on Apr 15, 2021
    fc6f108
  10. mhvk commented on Jul 27, 2022

    @mhvk
    Contributor

    See also discussion following #13398 (comment), which showed that even the person who wrote the initial code continues to think that broadcasting works, when it at present does not.
    EDIT: see in particular some failures described in #13398 (comment)

  11. added 5 commits that reference this issue on Aug 3, 2023
    3797b5b
    ba38c2e
    aa1989c
    1d45f88
    37cfed6
  12. added 5 commits that reference this issue on Aug 18, 2023
    99035b2
    9081d6a
    2f04b20
    7b82928
    5d84c35
  13. added 3 commits that reference this issue on Sep 30, 2023
    b19fb2a
    1f3a2b6
    33cca6f
  14. added a commit that references this issue on Oct 3, 2023
    00e64a9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions