Skip to content

Commit 8ed4d01

Browse files
committed
Remove NoFrame and replace with defaulting to ICRS
1 parent 1684cdb commit 8ed4d01

5 files changed

Lines changed: 40 additions & 57 deletions

File tree

‎astropy/coordinates/builtin_frames.py‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -353,25 +353,6 @@ def __init__(self, *args, **kwargs):
353353
super(AltAz, self).__init__(*args, **kwargs)
354354

355355

356-
class NoFrame(BaseCoordinateFrame):
357-
"""
358-
A "Fake" frame that is not meant to be transformed to/from. Acts like a
359-
standard equatorial coordinate system with no extra attributes.
360-
361-
Used primarily internally in `SkyCoord`, which is why it is not in the
362-
public API.
363-
364-
"""
365-
frame_specific_representation_info = {
366-
'spherical': [RepresentationMapping('lon', 'ra'),
367-
RepresentationMapping('lat', 'dec')]
368-
}
369-
frame_specific_representation_info['unitspherical'] = \
370-
frame_specific_representation_info['spherical']
371-
372-
default_representation = SphericalRepresentation
373-
374-
375356
# <--------------------------------transformations------------------------------>
376357
# Transformations are defined here instead of in the classes themselves, because
377358
# we need references to the various objects to give to the decorators.

‎astropy/coordinates/sky_coordinate.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from .distances import Distance
1414
from .baseframe import BaseCoordinateFrame, frame_transform_graph, GenericFrame, _get_repr_cls
15-
from .builtin_frames import NoFrame
15+
from .builtin_frames import ICRS
1616
from .representation import (BaseRepresentation, SphericalRepresentation,
1717
UnitSphericalRepresentation)
1818

@@ -64,7 +64,7 @@ class SkyCoord(object):
6464
The coordinate values and frame specification can now be provided using
6565
positional and keyword arguments::
6666
67-
>>> c = SkyCoord(10, 20, unit="deg") # No frame (cannot transform to other frames)
67+
>>> c = SkyCoord(10, 20, unit="deg") # defaults to ICRS frame
6868
>>> c = SkyCoord([1, 2, 3], [-30, 45, 8], "icrs", unit="deg") # 3 coords
6969
7070
>>> coords = ["1:12:43.2 +1:12:43", "1 12 43.2 +1 12 43"]
@@ -93,7 +93,8 @@ class or the corresponding string alias. The frame classes that are built in
9393
Parameters
9494
----------
9595
frame : `~astropy.coordinates.BaseCoordinateFrame` class or string, optional
96-
Type of coordinate frame this `SkyCoord` should represent.
96+
Type of coordinate frame this `SkyCoord` should represent. Defaults to
97+
to ICRS if not given or given as None.
9798
unit : `~astropy.units.Unit`, string, or tuple of :class:`~astropy.units.Unit` or str, optional
9899
Units for supplied ``LON`` and ``LAT`` values, respectively. If
99100
only one unit is supplied then it applies to both ``LON`` and
@@ -272,10 +273,6 @@ def transform_to(self, frame):
272273
"""
273274
from astropy.coordinates.errors import ConvertError
274275

275-
if frame is None or isinstance(self.frame, NoFrame):
276-
raise ValueError('Cannot transform to/from this SkyCoord because '
277-
'the frame was not specified at creation.')
278-
279276
frame_kwargs = {}
280277

281278
# Frame name (string) or frame class? Coerce into an instance.
@@ -778,19 +775,22 @@ class like ICRS, but not an instance ICRS() since the latter could have
778775
if frame is not None:
779776
# Frame was provided as kwarg so validate and coerce into corresponding frame.
780777
frame_cls = _get_frame_class(frame)
778+
frame_specified_explicitly = True
781779
else:
782780
# Look for the frame in args
783781
for arg in args:
784782
try:
785783
frame_cls = _get_frame_class(arg)
784+
frame_specified_explicitly = True
786785
except ValueError:
787786
pass
788787
else:
789788
args.remove(arg)
790789
break
791790
else:
792-
# Not in args nor kwargs
793-
frame_cls = NoFrame
791+
# Not in args nor kwargs - default to icrs
792+
frame_cls = ICRS
793+
frame_specified_explicitly = False
794794

795795
# Check that the new frame doesn't conflict with existing coordinate frame
796796
# if a coordinate is supplied in the args list. If the frame still had not
@@ -803,7 +803,7 @@ class like ICRS, but not an instance ICRS() since the latter could have
803803
coord_frame_cls = arg.frame.__class__
804804

805805
if coord_frame_cls is not None:
806-
if frame_cls is NoFrame:
806+
if not frame_specified_explicitly:
807807
frame_cls = coord_frame_cls
808808
elif frame_cls is not coord_frame_cls:
809809
raise ValueError("Cannot override frame='{0}' of input coordinate with "

‎astropy/coordinates/tests/test_sky_coord.py‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ def test_repr():
408408
assert repr(sc3) == ('<SkyCoord (ICRS): (ra, dec) in deg\n'
409409
' [(0.25, 1.0), (0.25, 2.5)]>')
410410

411-
sc_noframe = SkyCoord(0 * u.deg, 1 * u.deg)
412-
assert repr(sc_noframe) == '<SkyCoord (NoFrame): ra=0.0 deg, dec=1.0 deg>'
411+
sc_default = SkyCoord(0 * u.deg, 1 * u.deg)
412+
assert repr(sc_default) == '<SkyCoord (ICRS): ra=0.0 deg, dec=1.0 deg>'
413413

414414

415415
def test_ops():
@@ -441,20 +441,21 @@ def test_ops():
441441

442442
def test_none_transform():
443443
"""
444-
Ensure that transforming from a SkyCoord with no frame provided always fails
444+
Ensure that transforming from a SkyCoord with no frame provided works like
445+
ICRS
445446
"""
446447
sc = SkyCoord(0 * u.deg, 1 * u.deg)
447448
sc_arr = SkyCoord(0 * u.deg, [1, 2] * u.deg)
448449

449-
with pytest.raises(ValueError):
450-
sc.transform_to(ICRS)
451-
with pytest.raises(ValueError):
452-
sc.transform_to('fk5')
450+
sc2 = sc.transform_to(ICRS)
451+
assert sc.ra == sc2.ra and sc.dec == sc2.dec
453452

454-
with pytest.raises(ValueError):
455-
sc_arr.transform_to(ICRS)
456-
with pytest.raises(ValueError):
457-
sc_arr.transform_to('fk5')
453+
sc5 = sc.transform_to('fk5')
454+
assert sc5.ra == sc2.transform_to('fk5').ra
455+
456+
sc_arr2 = sc_arr.transform_to(ICRS)
457+
sc_arr5 = sc_arr.transform_to('fk5')
458+
npt.assert_array_equal(sc_arr5.ra, sc_arr2.transform_to('fk5').ra)
458459

459460

460461
def test_position_angle():

‎docs/coordinates/index.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ because it will be *much* faster than applying the operation to each
119119
|skycoord| in a for loop.
120120

121121
>>> SkyCoord(ra=[10, 11]*u.degree, dec=[41, -5]*u.degree)
122-
<SkyCoord (NoFrame): (ra, dec) in deg
122+
<SkyCoord (ICRS): (ra, dec) in deg
123123
[(10.0, 41.0), (11.0, -5.0)]>
124124

125125
So far we have been using a spherical coordinate representation in the all the

‎docs/coordinates/skycoord.rst‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ The coordinate values and frame specification can now be provided using
7070
positional and keyword arguments. First we show positional arguments for
7171
RA and Dec::
7272

73-
>>> SkyCoord(10, 20, unit="deg") # No frame (no transform to other frames)
74-
<SkyCoord (NoFrame): ra=10.0 deg, dec=20.0 deg>
73+
>>> SkyCoord(10, 20, unit="deg") # Defaults to ICRS
74+
<SkyCoord (ICRS): ra=10.0 deg, dec=20.0 deg>
7575

7676
>>> SkyCoord([1, 2, 3], [-30, 45, 8], "icrs", unit="deg")
7777
<SkyCoord (ICRS): (ra, dec) in deg
7878
[(1.0, -30.0), (2.0, 45.0), (3.0, 8.0)]>
7979

80-
Notice that the first example above does not specify a frame. This object
81-
can be used for displaying the coordinates in different formats but cannot
82-
be used in transformations, matching catalogs, nor in computing coordinate
83-
separations.
80+
Notice that the first example above does not explicitly give a frame. In
81+
this case, the default is taken to be the ICRS system (approximately
82+
correct for "J2000" equatorial coordinates). It is always better to
83+
explicitly specify the frame when it is known to be ICRS, however, as
84+
anyone reading the code will be better able to understand the intent.
8485

8586
String inputs in common formats are acceptable, and the frame can be supplied
8687
as either a class type like `~astropy.coordinates.FK4` or the lower-case
@@ -199,7 +200,7 @@ to astropy are `~astropy.coordinates.ICRS`, `~astropy.coordinates.FK5`,
199200
`~astropy.coordinates.Galactic`, and `~astropy.coordinates.AltAz`.
200201
The string aliases are simply lower-case versions of the class name.
201202

202-
If the frame is not supplied then you will see a special ``NoFrame``
203+
If the frame is not supplied then you will see a special ``ICRS``
203204
identifer. This indicates that the frame is unspecified and operations
204205
that require comparing coordinates (even within that object) are not allowed.
205206

@@ -468,23 +469,23 @@ supplying the corresponding components for that representation::
468469

469470
>>> c = SkyCoord(x=1, y=2, z=3, unit='kpc', representation='cartesian')
470471
>>> c
471-
<SkyCoord (NoFrame): x=1.0 kpc, y=2.0 kpc, z=3.0 kpc>
472+
<SkyCoord (ICRS): x=1.0 kpc, y=2.0 kpc, z=3.0 kpc>
472473
>>> c.x, c.y, c.z
473474
(<Quantity 1.0 kpc>, <Quantity 2.0 kpc>, <Quantity 3.0 kpc>)
474475

475476
Other variations include::
476477

477478
>>> SkyCoord(1, 2*u.deg, 3, representation='cylindrical')
478-
<SkyCoord (NoFrame): rho=1.0 , phi=2.0 deg, z=3.0 >
479+
<SkyCoord (ICRS): rho=1.0 , phi=2.0 deg, z=3.0 >
479480

480481
>>> SkyCoord(rho=1*u.km, phi=2*u.deg, z=3*u.m, representation='cylindrical')
481-
<SkyCoord (NoFrame): rho=1.0 km, phi=2.0 deg, z=3.0 m>
482+
<SkyCoord (ICRS): rho=1.0 km, phi=2.0 deg, z=3.0 m>
482483

483484
>>> SkyCoord(rho=1, phi=2, z=3, unit=(u.km, u.deg, u.m), representation='cylindrical')
484-
<SkyCoord (NoFrame): rho=1.0 km, phi=2.0 deg, z=3.0 m>
485+
<SkyCoord (ICRS): rho=1.0 km, phi=2.0 deg, z=3.0 m>
485486

486487
>>> SkyCoord(1, 2, 3, unit=(None, u.deg, None), representation='cylindrical')
487-
<SkyCoord (NoFrame): rho=1.0 , phi=2.0 deg, z=3.0 >
488+
<SkyCoord (ICRS): rho=1.0 , phi=2.0 deg, z=3.0 >
488489

489490
In general terms, the allowed syntax is as follows::
490491

@@ -628,11 +629,11 @@ in 3d space.
628629

629630
>>> c = SkyCoord(x=1, y=2, z=3, unit='kpc', representation='cartesian')
630631
>>> c
631-
<SkyCoord (NoFrame): x=1.0 kpc, y=2.0 kpc, z=3.0 kpc>
632+
<SkyCoord (ICRS): x=1.0 kpc, y=2.0 kpc, z=3.0 kpc>
632633

633634
>>> c.representation = 'cylindrical'
634635
>>> c
635-
<SkyCoord (NoFrame): rho=2.236067... kpc, phi=63.434948... deg, z=3.0 kpc>
636+
<SkyCoord (ICRS): rho=2.236067... kpc, phi=63.434948... deg, z=3.0 kpc>
636637
>>> c.phi.to(u.deg)
637638
<Angle 63.434948... deg>
638639
>>> c.x # doctest: +SKIP
@@ -641,11 +642,11 @@ in 3d space.
641642

642643
>>> c.representation = 'spherical'
643644
>>> c
644-
<SkyCoord (NoFrame): ra=63.434948... deg, dec=53.300774... deg, distance=3.741657... kpc>
645+
<SkyCoord (ICRS): ra=63.434948... deg, dec=53.300774... deg, distance=3.741657... kpc>
645646

646647
>>> c.representation = 'unitspherical'
647648
>>> c
648-
<SkyCoord (NoFrame): ra=63.434948... deg, dec=53.300774... deg>
649+
<SkyCoord (ICRS): ra=63.434948... deg, dec=53.300774... deg>
649650

650651
You can also use any representation class to set the representation::
651652

0 commit comments

Comments
 (0)