Skip to content

Commit 33aec1a

Browse files
Move altaz() method to the main position class
But keep the behavior that Astrometric.altaz() returns an exception.
1 parent af982dc commit 33aec1a

File tree

2 files changed

+31
-52
lines changed

2 files changed

+31
-52
lines changed

skyfield/positionlib.py

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def build_position(position_au, velocity_au_per_d=None, t=None,
2323
cls = Barycentric
2424
elif center == 399:
2525
cls = Geocentric
26-
elif hasattr(center, 'rotation_at'): # and thus deserves an altaz() method
27-
cls = Geometric
2826
else:
2927
cls = ICRF
3028
return cls(position_au, velocity_au_per_d, t, center, target)
@@ -310,6 +308,30 @@ def hadec(self):
310308
Angle(radians=dec, signed=True),
311309
Distance(au))
312310

311+
def altaz(self, temperature_C=None, pressure_mbar='standard'):
312+
"""Compute (alt, az, distance) relative to the observer's horizon
313+
314+
The altitude returned is an :class:`~skyfield.units.Angle`
315+
measured in degrees above the horizon, while the azimuth
316+
:class:`~skyfield.units.Angle` measures east along the horizon
317+
from geographic north (so 0 degrees means north, 90 is east, 180
318+
is south, and 270 is west).
319+
320+
By default, Skyfield does not adjust the altitude for
321+
atmospheric refraction. If you want Skyfield to estimate how
322+
high the atmosphere might lift the body's image, give the
323+
argument ``temperature_C`` either the temperature in degrees
324+
centigrade, or the string ``'standard'`` (in which case 10°C is
325+
used).
326+
327+
When calculating refraction, Skyfield uses the observer’s
328+
elevation above sea level to estimate the atmospheric pressure.
329+
If you want to override that value, simply provide a number
330+
through the ``pressure_mbar`` parameter.
331+
332+
"""
333+
return _to_altaz(self, temperature_C, pressure_mbar)
334+
313335
def separation_from(self, another_icrf):
314336
"""Return the angle between this position and another.
315337
@@ -627,7 +649,6 @@ def from_altaz(self, alt=None, az=None, alt_degrees=None, az_degrees=None,
627649
# important enough change to warrant a deprecation error for users, so:
628650
ICRS = ICRF
629651

630-
631652
class Geometric(ICRF):
632653
"""An |xyz| vector between two instantaneous position.
633654
@@ -641,30 +662,6 @@ class Geometric(ICRF):
641662
System (ICRS), the modern replacement for J2000 coordinates.
642663
643664
"""
644-
def altaz(self, temperature_C=None, pressure_mbar='standard'):
645-
"""Compute (alt, az, distance) relative to the observer's horizon
646-
647-
The altitude returned is an :class:`~skyfield.units.Angle`
648-
measured in degrees above the horizon, while the azimuth
649-
:class:`~skyfield.units.Angle` measures east along the horizon
650-
from geographic north (so 0 degrees means north, 90 is east, 180
651-
is south, and 270 is west).
652-
653-
By default, Skyfield does not adjust the altitude for
654-
atmospheric refraction. If you want Skyfield to estimate how
655-
high the atmosphere might lift the body's image, give the
656-
argument ``temperature_C`` either the temperature in degrees
657-
centigrade, or the string ``'standard'`` (in which case 10°C is
658-
used).
659-
660-
When calculating refraction, Skyfield uses the observer’s
661-
elevation above sea level to estimate the atmospheric pressure.
662-
If you want to override that value, simply provide a number
663-
through the ``pressure_mbar`` parameter.
664-
665-
"""
666-
return _to_altaz(self, temperature_C, pressure_mbar)
667-
668665

669666
class Barycentric(ICRF):
670667
"""An |xyz| position measured from the Solar System barycenter.
@@ -730,6 +727,12 @@ class Astrometric(ICRF):
730727
call ``.apparent()`` to generate an :class:`Apparent` position.
731728
732729
"""
730+
def altaz(self):
731+
raise ValueError(
732+
'it is not useful to call .altaz() on an astrometric position;'
733+
' try calling .apparent() first to get an apparent position'
734+
)
735+
733736
def apparent(self):
734737
"""Compute an :class:`Apparent` position for this body.
735738
@@ -824,30 +827,6 @@ class Apparent(ICRF):
824827
equator and equinox of date.
825828
826829
"""
827-
def altaz(self, temperature_C=None, pressure_mbar='standard'):
828-
"""Compute (alt, az, distance) relative to the observer's horizon
829-
830-
The altitude returned is an :class:`~skyfield.units.Angle`
831-
measured in degrees above the horizon, while the azimuth
832-
:class:`~skyfield.units.Angle` measures east along the horizon
833-
from geographic north (so 0 degrees means north, 90 is east, 180
834-
is south, and 270 is west).
835-
836-
By default, Skyfield does not adjust the altitude for
837-
atmospheric refraction. If you want Skyfield to estimate how
838-
high the atmosphere might lift the body's image, give the
839-
argument ``temperature_C`` either the temperature in degrees
840-
centigrade, or the string ``'standard'`` (in which case 10°C is
841-
used).
842-
843-
When calculating refraction, Skyfield uses the observer’s
844-
elevation above sea level to estimate the atmospheric pressure.
845-
If you want to override that value, simply provide a number
846-
through the ``pressure_mbar`` parameter.
847-
848-
"""
849-
return _to_altaz(self, temperature_C, pressure_mbar)
850-
851830

852831
class Geocentric(ICRF):
853832
"""An |xyz| position measured from the center of the Earth.

skyfield/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_astrometric_position_does_not_allow_altaz(ts):
3030
e = api.load('de421.bsp')
3131
o = e['earth'] + api.wgs84.latlon(36.7138, -112.2169)
3232
a = o.at(ts.utc(2014, 2, 9, 14, 50)).observe(e['mars'])
33-
with assert_raises(AttributeError):
33+
with assert_raises(ValueError, 'it is not useful to call .altaz'):
3434
a.altaz()
3535

3636
def test_ephemeris_contains_method(ts):

0 commit comments

Comments
 (0)