Skip to content

Commit 67c0c6b

Browse files
authored
Merge pull request #558 from bmorris3/get-moon-deprecation
Replacing deprecated astropy function: get_moon
2 parents cb9517e + 3b4f162 commit 67c0c6b

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

astroplan/conftest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
PYTEST_HEADER_MODULES = {}
1616
TESTED_VERSIONS = {}
1717

18-
from astropy.tests.helper import enable_deprecations_as_exceptions
19-
2018
# We do this to pick up the test header report even when using LTS astropy
2119
try:
2220
from astropy.tests.pytest_plugins import pytest_report_header # noqa
@@ -36,10 +34,6 @@
3634
TESTED_VERSIONS[packagename] = version
3735

3836

39-
# Comment out this line to avoid deprecation warnings being raised as
40-
# exceptions
41-
enable_deprecations_as_exceptions()
42-
4337
# Define list of packages for which to display version numbers in the test log
4438
try:
4539
PYTEST_HEADER_MODULES['Astropy'] = 'astropy'

astroplan/constraints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Third-party
1717
from astropy.time import Time
1818
import astropy.units as u
19-
from astropy.coordinates import get_body, get_sun, get_moon, Galactic, SkyCoord
19+
from astropy.coordinates import get_body, get_sun, Galactic, SkyCoord
2020
from astropy import table
2121

2222
import numpy as np
@@ -590,7 +590,7 @@ def __init__(self, min=None, max=None, ephemeris=None):
590590
self.ephemeris = ephemeris
591591

592592
def compute_constraint(self, times, observer, targets):
593-
moon = get_moon(times, location=observer.location, ephemeris=self.ephemeris)
593+
moon = get_body("moon", times, location=observer.location, ephemeris=self.ephemeris)
594594
# note to future editors - the order matters here
595595
# moon.separation(targets) is NOT the same as targets.separation(moon)
596596
# the former calculates the separation in the frame of the moon coord

astroplan/moon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# Third-party
1010
import numpy as np
11-
from astropy.coordinates import get_moon, get_sun
11+
from astropy.coordinates import get_sun, get_body
1212

1313
__all__ = ["moon_phase_angle", "moon_illumination"]
1414

@@ -35,7 +35,7 @@ def moon_phase_angle(time, ephemeris=None):
3535
# TODO: cache these sun/moon SkyCoord objects
3636

3737
sun = get_sun(time)
38-
moon = get_moon(time, ephemeris=ephemeris)
38+
moon = get_body("moon", time, ephemeris=ephemeris)
3939
elongation = sun.separation(moon)
4040
return np.arctan2(sun.distance*np.sin(elongation),
4141
moon.distance - sun.distance*np.cos(elongation))

astroplan/observer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import warnings
1010
# Third-party
1111
from astropy.coordinates import (EarthLocation, SkyCoord, AltAz, get_sun,
12-
get_moon, Angle, Longitude)
12+
get_body, Angle, Longitude)
1313
import astropy.units as u
1414
from astropy.time import Time
1515
from astropy.utils.exceptions import AstropyDeprecationWarning
@@ -513,7 +513,7 @@ def altaz(self, time, target=None, obswl=None, grid_times_targets=False):
513513
"""
514514
if target is not None:
515515
if target is MoonFlag:
516-
target = get_moon(time, location=self.location)
516+
target = get_body("moon", time, location=self.location)
517517
elif target is SunFlag:
518518
target = get_sun(time)
519519

@@ -1734,7 +1734,7 @@ def moon_altaz(self, time, ephemeris=None):
17341734
if not isinstance(time, Time):
17351735
time = Time(time)
17361736

1737-
moon = get_moon(time, location=self.location, ephemeris=ephemeris)
1737+
moon = get_body("moon", time, location=self.location, ephemeris=ephemeris)
17381738
return self.altaz(time, moon)
17391739

17401740
def sun_altaz(self, time):

astroplan/tests/test_constraints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
import astropy.units as u
77
from astropy.time import Time
8-
from astropy.coordinates import Galactic, SkyCoord, get_sun, get_moon
8+
from astropy.coordinates import Galactic, SkyCoord, get_sun, get_body
99
from astropy.utils import minversion
1010
import pytest
1111

@@ -193,7 +193,7 @@ def test_moon_separation():
193193
time = Time('2003-04-05 06:07:08')
194194
apo = Observer.at_site("APO")
195195
altaz_frame = apo.altaz(time)
196-
moon = get_moon(time, apo.location).transform_to(altaz_frame)
196+
moon = get_body("moon", time, apo.location).transform_to(altaz_frame)
197197
one_deg_away = SkyCoord(az=moon.az, alt=moon.alt+1*u.deg, frame=altaz_frame)
198198
five_deg_away = SkyCoord(az=moon.az+5*u.deg, alt=moon.alt,
199199
frame=altaz_frame)

astroplan/tests/test_observer.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,27 @@ def test_rise_set_transit_nearest_vector():
159159
time = Time('2022-06-21 00:00:00')
160160

161161
obs = Observer(location=location)
162-
rise_vector = obs.target_rise_time(time, sc_list)
162+
163+
with pytest.warns(TargetAlwaysUpWarning):
164+
rise_vector = obs.target_rise_time(time, sc_list)
165+
polaris_rise = obs.target_rise_time(time, polaris)
166+
163167
vega_rise = obs.target_rise_time(time, vega)
164168
mira_rise = obs.target_rise_time(time, mira)
165169
sirius_rise = obs.target_rise_time(time, sirius)
166-
polaris_rise = obs.target_rise_time(time, polaris)
167170

168171
assert rise_vector[0] == vega_rise
169172
assert rise_vector[1] == mira_rise
170173
assert rise_vector[2] == sirius_rise
171174
assert rise_vector[3].value.mask and polaris_rise.value.mask
172175

173-
set_vector = obs.target_set_time(time, sc_list)
176+
with pytest.warns(TargetAlwaysUpWarning):
177+
set_vector = obs.target_set_time(time, sc_list)
178+
polaris_set = obs.target_set_time(time, polaris)
179+
174180
vega_set = obs.target_set_time(time, vega)
175181
mira_set = obs.target_set_time(time, mira)
176182
sirius_set = obs.target_set_time(time, sirius)
177-
polaris_set = obs.target_set_time(time, polaris)
178183

179184
assert set_vector[0] == vega_set
180185
assert set_vector[1] == mira_set

0 commit comments

Comments
 (0)