Skip to content

Weird bug initialising SkyCoord from list of SkyCoords that have distances set #5209

Closed

Description

@StuartLittlefair

Using astropy 1.2.1 I find the following behaviour

In [13]: from astropy.coordinates import EarthLocation, SkyCoord, GCRS, AltAz
In [13]: from astropy import units as u
In [13]: from astropy.time import Time
In [13]: time = Time("2014-01-20 22:00")
In [13]: location = EarthLocation.from_geodetic(-17.88*u.deg, -28.76*u.deg, 2327*u.m)
In [13]: gcrs_loc = u.Quantity([1712675, 5328049, -3053885], unit=u.m)
In [13]: gcrs_vel = u.Quantity([-388, 125, 0], unit=u.m/u.s)
In [13]: m31 = SkyCoord(10.6847083*u.deg, 41.26875*u.deg)
In [13]: moon = SkyCoord(GCRS(172.4*u.deg, 0.51*u.deg, 0.002671*u.au,
                obstime=time, obsgeoloc=gcrs_loc, obsgeovel=gcrs_vel))

In [13]: SkyCoord(m31)
Out[13]: 
<SkyCoord (ICRS): (ra, dec) in deg
    (10.6847083, 41.26875)>
In [14]: SkyCoord([m31, m31])  # m31 works fine!
Out[14]: 
<SkyCoord (ICRS): (ra, dec) in deg
    [(10.6847083, 41.26875), (10.6847083, 41.26875)]>

This is the behaviour I expect. But if I try and use the moon the same way:

In [4]: SkyCoord(moon)
Out[4]: 
<SkyCoord (GCRS: obstime=2014-01-20 22:00:00.000, obsgeoloc=[ 1712675.  5328049. -3053885.] m, obsgeovel=[-388.  125.    0.] m / s): (ra, dec, distance) in (deg, deg, AU)
    (172.4, 0.51, 0.002671)>

In [5]: SkyCoord([moon])  # ODD! Where has the distance gone?
Out[5]: 
<SkyCoord (ICRS): (ra, dec) in deg
    (172.4, 0.51)>

In [6]: SkyCoord([moon, moon]) 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-d318e9f1252e> in <module>()
----> 1 SkyCoord([moon, moon])

/usr/local/lib/python3.5/site-packages/astropy/coordinates/sky_coordinate.py in __init__(self, *args, **kwargs)
    194         args = list(args)  # Make it mutable
    195         copy = kwargs.pop('copy', True)
--> 196         kwargs = self._parse_inputs(args, kwargs)
    197 
    198         # Set internal versions of object state attributes

/usr/local/lib/python3.5/site-packages/astropy/coordinates/sky_coordinate.py in _parse_inputs(self, args, kwargs)
    294                 # along with any frame attributes like equinox or obstime which
    295                 # were explicitly specified in the coordinate object (i.e. non-default).
--> 296                 coord_kwargs = _parse_coordinate_arg(args[0], frame, units, kwargs)
    297 
    298                 # Copy other 'info' attr only if it has actually been defined.

/usr/local/lib/python3.5/site-packages/astropy/coordinates/sky_coordinate.py in _parse_coordinate_arg(coords, frame, units, init_kwargs)
   1486             allunitsphrepr = True
   1487             for sc in scs[1:]:
-> 1488                 if not sc.is_equivalent_frame(scs[0]):
   1489                     raise ValueError("List of inputs don't have equivalent "
   1490                                      "frames: {0} != {1}".format(sc, scs[0]))

/usr/local/lib/python3.5/site-packages/astropy/coordinates/sky_coordinate.py in is_equivalent_frame(self, other)
    602 
    603             for fattrnm in FRAME_ATTR_NAMES_SET():
--> 604                 if getattr(self, fattrnm) != getattr(other, fattrnm):
    605                     return False
    606             return True

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

And it's not a GCRS thing, since the same occurs if I use an ICRS coordinate...

In [8]: moon.icrs
Out[8]: 
<SkyCoord (ICRS): (ra, dec, distance) in (deg, deg, AU)
    (122.91386538, 19.98343108, 0.98321877)>

In [9]: SkyCoord(moon.icrs)
Out[9]: 
<SkyCoord (ICRS): (ra, dec, distance) in (deg, deg, AU)
    (122.91386538, 19.98343108, 0.98321877)>

In [10]: SkyCoord([moon.icrs])  # ODD! Where has the distance gone?
Out[10]: 
<SkyCoord (ICRS): (ra, dec) in deg
    (122.91386538, 19.98343108)>

In [11]: SkyCoord([moon.icrs, moon.icrs])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-5ca3644d5d2e> in <module>()
----> 1 SkyCoord([moon.icrs, moon.icrs])

/usr/local/lib/python3.5/site-packages/astropy/coordinates/sky_coordinate.py in __init__(self, *args, **kwargs)
    194         args = list(args)  # Make it mutable
    195         copy = kwargs.pop('copy', True)
--> 196         kwargs = self._parse_inputs(args, kwargs)
    197 
    198         # Set internal versions of object state attributes

/usr/local/lib/python3.5/site-packages/astropy/coordinates/sky_coordinate.py in _parse_inputs(self, args, kwargs)
    294                 # along with any frame attributes like equinox or obstime which
    295                 # were explicitly specified in the coordinate object (i.e. non-default).
--> 296                 coord_kwargs = _parse_coordinate_arg(args[0], frame, units, kwargs)
    297 
    298                 # Copy other 'info' attr only if it has actually been defined.

/usr/local/lib/python3.5/site-packages/astropy/coordinates/sky_coordinate.py in _parse_coordinate_arg(coords, frame, units, init_kwargs)
   1486             allunitsphrepr = True
   1487             for sc in scs[1:]:
-> 1488                 if not sc.is_equivalent_frame(scs[0]):
   1489                     raise ValueError("List of inputs don't have equivalent "
   1490                                      "frames: {0} != {1}".format(sc, scs[0]))

/usr/local/lib/python3.5/site-packages/astropy/coordinates/sky_coordinate.py in is_equivalent_frame(self, other)
    602 
    603             for fattrnm in FRAME_ATTR_NAMES_SET():
--> 604                 if getattr(self, fattrnm) != getattr(other, fattrnm):
    605                     return False
    606             return True

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
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