SkyCoord initialization with another SkyCoord
- Dominant language
- Python
- Stars
- 5.3k
- Forks
- 2.2k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 81
Description
For ``Quantity`` and ``Time``, an implicit conversion can be made during initialization:
```python
In [1]: from astropy import units as u
In [2]: q = 3 * u.m
In [3]: u.Quantity(q, u.km)
Out[3]:
```
```python
In [8]: from astropy.time import Time
In [9]: t = Time.now()
In [10]: t
Out[10]:
In [11]: Time(t, scale='tai')
Out[11]:
However, this is not the case for SkyCoord:
```python
In [4]: from astropy.coordinates import SkyCoord
In [5]: c = SkyCoord.from_name('m31')
In [6]: c
Out[6]:
In [7]: SkyCoord(c, frame='galactic')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 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.
Contributor guide
Research direction
Start in astropy/coordinates/sky_coordinate.py, especially SkyCoord.__init__, _parse_inputs, and _get_frame, which are shown in the traceback. Read how Quantity and Time handle initialization from an existing object, then determine how SkyCoord(c, frame='galactic') should behave. Done means the requested initialization is supported consistently and the relevant coordinate tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100