Open
Description
For Quantity
and Time
, an implicit conversion can be made during initialization:
In [1]: from astropy import units as u
In [2]: q = 3 * u.m
In [3]: u.Quantity(q, u.km)
Out[3]: <Quantity 0.003 km>
In [8]: from astropy.time import Time
In [9]: t = Time.now()
In [10]: t
Out[10]: <Time object: scale='utc' format='datetime' value=2018-07-29 10:19:22.232158>
In [11]: Time(t, scale='tai')
Out[11]: <Time object: scale='tai' format='datetime' value=2018-07-29 10:19:59.232158>
However, this is not the case for SkyCoord:
In [4]: from astropy.coordinates import SkyCoord
In [5]: c = SkyCoord.from_name('m31')
In [6]: c
Out[6]:
<SkyCoord (ICRS): (ra, dec) in deg
(10.6847083, 41.26875)>
In [7]: SkyCoord(c, frame='galactic')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-785076b7254e> in <module>()
----> 1 SkyCoord(c, frame='galactic')
~/Dropbox/Code/Astropy/astropy/astropy/coordinates/sky_coordinate.py in __init__(self, copy, *args, **kwargs)
223 # creating the internal self._sky_coord_frame object
224 args = list(args) # Make it mutable
--> 225 kwargs = self._parse_inputs(args, kwargs)
226
227 frame = kwargs['frame']
~/Dropbox/Code/Astropy/astropy/astropy/coordinates/sky_coordinate.py in _parse_inputs(self, args, kwargs)
358 # by keyword args or else get a None default. Pop them off of kwargs
359 # in the process.
--> 360 frame = valid_kwargs['frame'] = _get_frame(args, kwargs)
361
362 # TODO: possibly remove the below. The representation/differential
~/Dropbox/Code/Astropy/astropy/astropy/coordinates/sky_coordinate.py in _get_frame(args, kwargs)
1823 raise ValueError("Cannot override frame='{0}' of input coordinate with "
1824 "new frame='{1}'. Instead transform the coordinate."
-> 1825 .format(coord_frame_cls.__name__, frame_cls.__name__))
1826
1827 frame_cls_kwargs = {}
ValueError: Cannot override frame='ICRS' of input coordinate with new frame='Galactic'. Instead transform the coordinate.
Is there any reason not to allow this? It would be nice if this worked for consistency with Quantity and Time, and would avoid special-casing SkyCoord in the APE14 implementation of celestial coordinates.