diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index fcf497ae..8e78c674 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -42,18 +42,20 @@ jobs: - name: Windows - Python 3.11 with all optional dependencies os: windows-latest - python: 3.11 + python: '3.11' toxenv: py11-test-alldeps + toxargs: -v - name: Python 3.11 with remote data, all dependencies, and coverage os: ubuntu-latest - python: 3.11 + python: '3.11' toxenv: py11-test-alldeps-cov - toxposargs: --remote-data + toxargs: -v + posargs: --remote-data=any - name: Python 3.11 with latest dev versions of key dependencies os: ubuntu-latest - python: 3.11 + python: '3.11' toxenv: py11-test-devdeps - name: Test building of Sphinx docs @@ -79,4 +81,4 @@ jobs: run: sudo apt-get -y install graphviz - name: Test with tox run: | - tox -e ${{ matrix.toxenv }} + python -m tox -e ${{ matrix.toxenv }} ${{ matrix.toxargs }} -- ${{ matrix.posargs }} diff --git a/astroplan/constraints.py b/astroplan/constraints.py index b9f4b12a..3de8351f 100644 --- a/astroplan/constraints.py +++ b/astroplan/constraints.py @@ -728,12 +728,9 @@ def __init__(self, min=None, max=None): Constrain the observations to targets that are observable between 23:50 and 04:08 local time: - >>> from astroplan import Observer - >>> from astroplan.constraints import LocalTimeConstraint >>> import datetime as dt - >>> subaru = Observer.at_site("Subaru", timezone="US/Hawaii") - >>> # bound times between 23:50 and 04:08 local Hawaiian time - >>> constraint = LocalTimeConstraint(min=dt.time(23,50), max=dt.time(4,8)) + >>> from astroplan.constraints import LocalTimeConstraint + >>> constraint = LocalTimeConstraint(min=dt.time(23, 50), max=dt.time(4, 8)) """ self.min = min @@ -816,12 +813,11 @@ def __init__(self, min=None, max=None): Constrain the observations to targets that are observable between 2016-03-28 and 2016-03-30: - >>> from astroplan import Observer >>> from astropy.time import Time - >>> subaru = Observer.at_site("Subaru") + >>> from astroplan.constraints import TimeConstraint >>> t1 = Time("2016-03-28T12:00:00") >>> t2 = Time("2016-03-30T12:00:00") - >>> constraint = TimeConstraint(t1,t2) + >>> constraint = TimeConstraint(t1, t2) """ self.min = min self.max = max @@ -907,7 +903,8 @@ def __init__(self, periodic_event, min=None, max=None): Examples -------- - To constrain observations on orbital phases between 0.4 and 0.6, + To constrain observations on orbital phases between 0.4 and 0.6: + >>> from astroplan import PeriodicEvent >>> from astropy.time import Time >>> import astropy.units as u @@ -917,6 +914,7 @@ def __init__(self, periodic_event, min=None, max=None): The minimum and maximum phase must be described on the interval [0, 1). To constrain observations on orbital phases between 0.6 and 1.2, for example, you should subtract one from the second number: + >>> constraint = PhaseConstraint(binary, min=0.6, max=0.2) """ self.periodic_event = periodic_event diff --git a/astroplan/plots/tests/test_sky.py b/astroplan/plots/tests/test_sky.py index d7123e1e..a70a7dd8 100644 --- a/astroplan/plots/tests/test_sky.py +++ b/astroplan/plots/tests/test_sky.py @@ -22,6 +22,7 @@ def test_image_example(): return fig +@pytest.mark.remote_data @pytest.mark.skipif('not HAS_MATPLOTLIB') @pytest.mark.mpl_image_compare def test_timezone(): diff --git a/astroplan/target.py b/astroplan/target.py index e42fedb9..c98bc860 100644 --- a/astroplan/target.py +++ b/astroplan/target.py @@ -83,7 +83,7 @@ class FixedTarget(Target): for the coordinates of Sirius by name: >>> from astroplan import FixedTarget - >>> sirius = FixedTarget.from_name("Sirius") + >>> sirius = FixedTarget.from_name("Sirius") # doctest: +REMOTE_DATA """ def __init__(self, coord, name=None, **kwargs): @@ -125,8 +125,8 @@ def from_name(cls, query_name, name=None, **kwargs): Examples -------- >>> from astroplan import FixedTarget - >>> sirius = FixedTarget.from_name("Sirius") - >>> sirius.coord # doctest: +FLOAT_CMP + >>> sirius = FixedTarget.from_name("Sirius") # doctest: +REMOTE_DATA + >>> sirius.coord # doctest: +FLOAT_CMP +REMOTE_DATA """ diff --git a/astroplan/tests/test_constraints.py b/astroplan/tests/test_constraints.py index 5343c6fa..f63fd8ac 100644 --- a/astroplan/tests/test_constraints.py +++ b/astroplan/tests/test_constraints.py @@ -33,6 +33,7 @@ dec=89.26410897*u.deg), name="Polaris") +@pytest.mark.remote_data def test_at_night_basic(): subaru = Observer.at_site("Subaru") time_ranges = [Time(['2001-02-03 04:05:06', '2001-02-04 04:05:06']), # 1 day @@ -53,6 +54,7 @@ def test_at_night_basic(): len(targets)*[observer_is_night_all]) +@pytest.mark.remote_data def test_observability_table(): subaru = Observer.at_site("Subaru") # time_ranges = [Time(['2001-02-03 04:05:06', '2001-02-04 04:05:06']), # 1 day @@ -96,6 +98,7 @@ def test_observability_table(): assert 'time observable' in stab.colnames +@pytest.mark.remote_data def test_altitude_constraint(): subaru = Observer.at_site("Subaru") time = Time('2001-02-03 15:35:00') @@ -107,6 +110,7 @@ def test_altitude_constraint(): assert np.all([results != 0][0] == [False, False, True, True, False, False]) +@pytest.mark.remote_data def test_compare_altitude_constraint_and_observer(): time = Time('2001-02-03 04:05:06') time_ranges = [Time([time, time+1*u.hour]) + offset @@ -128,6 +132,7 @@ def test_compare_altitude_constraint_and_observer(): assert all(always_from_observer == always_from_constraint) +@pytest.mark.remote_data def test_compare_airmass_constraint_and_observer(): time = Time('2001-02-03 04:05:06') time_ranges = [Time([time, time+1*u.hour]) + offset @@ -149,6 +154,7 @@ def test_compare_airmass_constraint_and_observer(): assert all(always_from_observer == always_from_constraint) +@pytest.mark.remote_data def test_galactic_plane_separation(): time = Time('2003-04-05 06:07:08') apo = Observer.at_site("APO") @@ -174,6 +180,7 @@ def test_galactic_plane_separation(): # in astropy before v1.0.4, a recursion error is triggered by this test @pytest.mark.skipif('APY_LT104') +@pytest.mark.remote_data # astropy.coordinates.errors.NonRotationTransformationWarning @pytest.mark.filterwarnings("ignore") def test_sun_separation(): @@ -200,6 +207,7 @@ def test_sun_separation(): assert np.all(is_constraint_met == [False, True, True]) +@pytest.mark.remote_data # astropy.coordinates.errors.NonRotationTransformationWarning @pytest.mark.filterwarnings("ignore") def test_moon_separation(): @@ -230,6 +238,7 @@ def test_moon_separation(): assert np.all(is_constraint_met == [False, True, True]) +@pytest.mark.remote_data def test_moon_illumination(): times = Time(["2015-08-28 03:30", "2015-08-28 12:00", "2015-09-05 10:30", "2015-09-15 18:35"]) @@ -268,6 +277,7 @@ def test_moon_illumination(): assert np.all(is_constraint_met == [True, False, False, False]) +@pytest.mark.remote_data def test_local_time_constraint_utc(): time = Time('2001-02-03 04:05:06') subaru = Observer.at_site("Subaru") @@ -284,6 +294,7 @@ def test_local_time_constraint_utc(): assert is_constraint_met is np.bool_(True) +@pytest.mark.remote_data def test_local_time_constraint_hawaii_tz(): # Define timezone in Observer.timezone time = Time('2001-02-03 04:05:06') @@ -301,6 +312,7 @@ def test_local_time_constraint_hawaii_tz(): assert is_constraint_met is np.bool_(True) +@pytest.mark.remote_data def test_docs_example(): # Test the example in astroplan/docs/tutorials/constraints.rst target_table_string = """# name ra_degrees dec_degrees @@ -364,6 +376,7 @@ def compute_constraint(self, times, observer, targets): assert all(observability == [False, False, True, False, False, False]) +@pytest.mark.remote_data def test_regression_airmass_141(): subaru = Observer.at_site("Subaru") time = Time('2001-1-1 12:00') @@ -426,6 +439,7 @@ def test_rescale_minmax(): ] +@pytest.mark.remote_data @pytest.mark.parametrize('constraint', constraint_tests) # astropy.coordinates.errors.NonRotationTransformationWarning @pytest.mark.filterwarnings("ignore") @@ -443,6 +457,7 @@ def test_regression_shapes(constraint): constraint(lapalma, targets, times) +@pytest.mark.remote_data def test_caches_shapes(): times = Time([2457884.43350526, 2457884.5029497, 2457884.57239415], format='jd') m31 = SkyCoord(10.6847929*u.deg, 41.269065*u.deg) @@ -455,6 +470,7 @@ def test_caches_shapes(): assert ac(observer, targets, times, grid_times_targets=False).shape == (3,) +@pytest.mark.remote_data def test_eclipses(): subaru = Observer.at_site("Subaru") @@ -476,6 +492,7 @@ def test_eclipses(): assert np.all(np.array([False, True, False]) == pc(subaru, None, times)) +@pytest.mark.remote_data def test_event_observable(): epoch = Time(2452826.628514, format='jd') diff --git a/astroplan/tests/test_observer.py b/astroplan/tests/test_observer.py index 3c2e87a7..2ee8f928 100644 --- a/astroplan/tests/test_observer.py +++ b/astroplan/tests/test_observer.py @@ -1092,6 +1092,7 @@ def test_timezone_convenience_methods(): assert all(naive_dts == times_dt_ndarray - datetime.timedelta(hours=4)) +@pytest.mark.remote_data def test_is_night(): lco = Observer(location=EarthLocation.of_site('lco')) # Las Campanas aao = Observer(location=EarthLocation.of_site('aao')) # Sydney, Australia @@ -1222,6 +1223,7 @@ def test_hour_angle(): assert_quantity_allclose(hour_angle, lst, atol=0.001*u.deg) +@pytest.mark.remote_data def test_tonight(): obs = Observer.at_site('Subaru') obs.height = 0 * u.m @@ -1349,6 +1351,7 @@ def test_sun_set_vs_mmto_almanac(mmto_sunset): assert abs(mmto_sunset - astroplan_sunset) < 1 * u.min +@pytest.mark.remote_data def test_observer_lon_lat_el(): """Test that astropy.EarthLocation conversion to longitude, latitude, and elevation works correctly. @@ -1358,6 +1361,7 @@ def test_observer_lon_lat_el(): assert hasattr(obs, attr) +@pytest.mark.remote_data def test_hash_observer(): """Test that Observer objects are hashable.""" obs1 = Observer.at_site('Subaru') @@ -1371,6 +1375,7 @@ def test_hash_observer(): assert hash(obs3) == hash(obs4) +@pytest.mark.remote_data def test_eq_observer(): """Test that Observer objects are comparable.""" obs1 = Observer.at_site('Subaru') diff --git a/astroplan/tests/test_scheduling.py b/astroplan/tests/test_scheduling.py index ff09cb7a..191c066b 100644 --- a/astroplan/tests/test_scheduling.py +++ b/astroplan/tests/test_scheduling.py @@ -4,6 +4,7 @@ from astropy.time import Time import astropy.units as u from astropy.coordinates import SkyCoord, EarthLocation +import pytest from ..utils import time_grid_from_range from ..observer import Observer @@ -21,7 +22,8 @@ polaris = FixedTarget(coord=SkyCoord(ra=37.95456067 * u.deg, dec=89.26410897 * u.deg), name="Polaris") -apo = Observer(EarthLocation.of_site('apo'), name='APO') +apo = Observer(EarthLocation(-1463969.30185172, -5166673.34223433, 3434985.71204565, unit='m'), + name='APO') targets = [vega, polaris, rigel] default_time = Time('2016-02-06 03:00:00') only_at_night = [AtNightConstraint()] @@ -205,6 +207,7 @@ def test_sequential_scheduler(): scheduler(blocks, schedule) +@pytest.mark.remote_data def test_scheduling_target_down(): lco = Observer.at_site('lco') block = [ObservingBlock(FixedTarget.from_name('polaris'), 1 * u.min, 0)] @@ -222,6 +225,7 @@ def test_scheduling_target_down(): assert len(schedule2.observing_blocks) == 0 +@pytest.mark.remote_data def test_scheduling_during_day(): block = [ObservingBlock(FixedTarget.from_name('polaris'), 1 * u.min, 0)] day = Time('2016-02-06 03:00:00') @@ -240,6 +244,7 @@ def test_scheduling_during_day(): # bring this back when MoonIlluminationConstraint is working properly +@pytest.mark.remote_data def test_scheduling_moon_up(): block = [ObservingBlock(FixedTarget.from_name('polaris'), 30 * u.min, 0)] # on february 23 the moon was up between the start/end times defined below diff --git a/astroplan/tests/test_target.py b/astroplan/tests/test_target.py index 582edebd..c6a53b24 100644 --- a/astroplan/tests/test_target.py +++ b/astroplan/tests/test_target.py @@ -12,6 +12,7 @@ from ..observer import Observer +@pytest.mark.remote_data def test_FixedTarget_from_name(): """ Check that resolving target names with the `SkyCoord.from_name` constructor @@ -28,6 +29,7 @@ def test_FixedTarget_from_name(): assert polaris_from_name.coord.separation(polaris_from_SIMBAD) < 1*u.arcsec +@pytest.mark.remote_data def test_FixedTarget_ra_dec(): """ Confirm that FixedTarget.ra and FixedTarget.dec are the same as the @@ -44,6 +46,7 @@ def test_FixedTarget_ra_dec(): 'SkyCoord') +@pytest.mark.remote_data def test_get_skycoord(): m31 = SkyCoord(10.6847083*u.deg, 41.26875*u.deg) m31_with_distance = SkyCoord(10.6847083*u.deg, 41.26875*u.deg, 780*u.kpc) diff --git a/tox.ini b/tox.ini index dcff8165..a3d93881 100644 --- a/tox.ini +++ b/tox.ini @@ -6,19 +6,16 @@ envlist = build_docs linkcheck codestyle -requires = - setuptools >= 30.3.0 - pip >= 19.3.1 -isolated_build = true -indexserver = - NIGHTLY = https://pypi.anaconda.org/scientific-python-nightly-wheels/simple [testenv] + # Suppress display of matplotlib plots generated during docs build -setenv = MPLBACKEND=agg +setenv = + MPLBACKEND=agg + devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/simple # Pass through the following environment variables which may be needed for the CI -passenv = HOME, WINDIR, LC_ALL, LC_CTYPE, CC, CI, TRAVIS +passenv = HOME,WINDIR,LC_ALL,LC_CTYPE,CC,CI # Run the tests in a temporary directory to make sure that we don't import # this package from the source tree @@ -63,7 +60,7 @@ deps = astropy42: astropy==4.2.* devdeps: numpy>=0.0.dev0 - devdeps: git+https://github.com/astropy/astropy.git#egg=astropy + devdeps: astropy>=0.0.dev0 # The following indicates which extras_require from setup.cfg will be installed extras =