Skip to content

Commit

Permalink
Merge branch 'main' into remove-deprecated-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim authored Dec 4, 2024
2 parents 82f4dcc + ecac608 commit 1f99580
Show file tree
Hide file tree
Showing 37 changed files with 370 additions and 210 deletions.
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: ".github/workflows" # Location of package manifests
schedule:
interval: "monthly"
groups:
actions:
patterns:
- "*"

4 changes: 2 additions & 2 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Set up python ${{ matrix.python }} on ${{ matrix.os }}
uses: actions/setup-python@v4
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ matrix.python }}
- name: Install base dependencies
Expand Down
23 changes: 22 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
0.9 (unreleased)
0.11 (unreleased)
-----------------

0.10.1 (2024-08-13)
-------------------

- Compatibility with numpy 2.0. [#587]

0.10 (2024-04-04)
-----------------

- Fix compatibility with astropy v6.0.

0.9.1 (2023-09-20)
------------------

- Fix bug when ``FixedTarget`` objects are passed to methods that calculate
lunar coordinates. [#568]

0.9 (2023-07-27)
----------------

- Fix time range in ``months_observable`` to not be only in 2014. Function now
Expand All @@ -7,6 +26,8 @@
- Fix ``Observer`` not having longtitude, latitude, and elevation parameters
as class attributes. They are now properties calculated from the ``location``.

- Documentation revisions and theme update [#563]

0.8 (2021-01-26)
----------------

Expand Down
16 changes: 10 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ Observation planning package for astronomers
* Docs: https://astroplan.readthedocs.io/
* License: BSD-3

.. image:: http://img.shields.io/badge/powered%20by-AstroPy-orange.svg?style=flat
:target: http://www.astropy.org/
.. image:: https://readthedocs.org/projects/astroplan/badge/?version=latest
:target: https://astroplan.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: http://img.shields.io/pypi/v/astroplan.svg?text=version
:target: https://pypi.python.org/pypi/astroplan/
:alt: Latest release

.. image:: http://img.shields.io/badge/arXiv-1709.03913-red.svg?style=flat
:target: https://arxiv.org/abs/1712.09631
:alt: arXiv paper

.. image:: https://github.com/astropy/astroplan/workflows/CI%20Tests/badge.svg
:target: https://github.com/astropy/astroplan/actions

.. image:: http://img.shields.io/badge/powered%20by-AstroPy-orange.svg?style=flat
:target: http://www.astropy.org/

.. image:: http://img.shields.io/pypi/v/astroplan.svg?text=version
:target: https://pypi.python.org/pypi/astroplan/
:alt: Latest release

Attribution
+++++++++++

Expand Down
29 changes: 13 additions & 16 deletions astroplan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
* Docs: https://astroplan.readthedocs.io/
"""

# Affiliated packages may add whatever they like to this file, but
# should keep this content at the top.
# ----------------------------------------------------------------------------
from ._astropy_init import *
# ----------------------------------------------------------------------------
try:
from .version import version as __version__
except ImportError:
__version__ = ''

# For egg_info test builds to pass, put package imports here.
if not _ASTROPY_SETUP_:
from .utils import *
from .observer import *
from .target import *
from .exceptions import *
from .moon import *
from .constraints import *
from .scheduling import *
from .periodic import *
from .utils import *
from .observer import *
from .target import *
from .exceptions import *
from .moon import *
from .constraints import *
from .scheduling import *
from .periodic import *

download_IERS_A()
download_IERS_A()
25 changes: 0 additions & 25 deletions astroplan/_astropy_init.py

This file was deleted.

11 changes: 5 additions & 6 deletions astroplan/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
an observer.
"""

from __future__ import (absolute_import, division, print_function,
unicode_literals)

# Standard library
from abc import ABCMeta, abstractmethod
import datetime
Expand All @@ -16,7 +13,7 @@
# Third-party
from astropy.time import Time
import astropy.units as u
from astropy.coordinates import get_body, get_sun, get_moon, Galactic, SkyCoord
from astropy.coordinates import get_body, get_sun, Galactic, SkyCoord
from astropy import table

import numpy as np
Expand Down Expand Up @@ -354,7 +351,7 @@ def compute_constraint(self, times, observer, targets):
uppermask = alt <= self.max
return lowermask & uppermask
else:
return max_best_rescale(alt, self.min, self.max)
return max_best_rescale(alt, self.min, self.max, greater_than_max=0)


class AirmassConstraint(AltitudeConstraint):
Expand Down Expand Up @@ -550,6 +547,7 @@ def compute_constraint(self, times, observer, targets):
# by the observer.
# 'get_sun' returns ICRS coords.
sun = get_body('sun', times, location=observer.location)
targets = get_skycoord(targets)
solar_separation = sun.separation(targets)

if self.min is None and self.max is not None:
Expand Down Expand Up @@ -590,11 +588,12 @@ def __init__(self, min=None, max=None, ephemeris=None):
self.ephemeris = ephemeris

def compute_constraint(self, times, observer, targets):
moon = get_moon(times, location=observer.location, ephemeris=self.ephemeris)
moon = get_body("moon", times, location=observer.location, ephemeris=self.ephemeris)
# note to future editors - the order matters here
# moon.separation(targets) is NOT the same as targets.separation(moon)
# the former calculates the separation in the frame of the moon coord
# which is GCRS, and that is what we want.
targets = get_skycoord(targets)
moon_separation = moon.separation(targets)

if self.min is None and self.max is not None:
Expand Down
2 changes: 0 additions & 2 deletions astroplan/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from astropy.utils.exceptions import AstropyWarning

Expand Down
7 changes: 2 additions & 5 deletions astroplan/moon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
This version of the `moon` module calculates lunar phase angle for a geocentric
"""

from __future__ import (absolute_import, division, print_function,
unicode_literals)

# Third-party
import numpy as np
from astropy.coordinates import get_moon, get_sun
from astropy.coordinates import get_sun, get_body

__all__ = ["moon_phase_angle", "moon_illumination"]

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

sun = get_sun(time)
moon = get_moon(time, ephemeris=ephemeris)
moon = get_body("moon", time, ephemeris=ephemeris)
elongation = sun.separation(moon)
return np.arctan2(sun.distance*np.sin(elongation),
moon.distance - sun.distance*np.cos(elongation))
Expand Down
90 changes: 83 additions & 7 deletions astroplan/observer.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from six import string_types

# Standard library
import sys
import datetime
import warnings
# Third-party
from astropy.coordinates import (EarthLocation, SkyCoord, AltAz, get_sun,
get_moon, Angle, Longitude)
get_body, Angle, Longitude)
import astropy.units as u
from astropy.time import Time
from astropy.utils.exceptions import AstropyDeprecationWarning
Expand Down Expand Up @@ -216,7 +213,7 @@ def __init__(self, location=None, timezone='UTC', name=None, latitude=None,
# Accept various timezone inputs, default to UTC
if isinstance(timezone, datetime.tzinfo):
self.timezone = timezone
elif isinstance(timezone, string_types):
elif isinstance(timezone, str):
self.timezone = pytz.timezone(timezone)
else:
raise TypeError('timezone keyword should be a string, or an '
Expand Down Expand Up @@ -273,6 +270,85 @@ def __repr__(self):
attributes_strings.append("{}={}".format(name, value))
return "<{}: {}>".format(class_name, ",\n ".join(attributes_strings))

def _key(self):
"""
Generate a tuple of the attributes that determine uniqueness of
`~astroplan.Observer` objects.
Returns
-------
key : tuple
Examples
--------
>>> from astroplan import Observer
>>> keck = Observer.at_site("Keck", timezone="US/Hawaii")
>>> keck._key()
('Keck', None, None, None, <Longitude -155.47833333 deg>,
<Latitude 19.82833333 deg>, <Quantity 4160. m>,
<DstTzInfo 'US/Hawaii' LMT-1 day, 13:29:00 STD>)
"""

return (self.name,
self.pressure,
self.temperature,
self.relative_humidity,
self.longitude,
self.latitude,
self.elevation,
self.timezone,)

def __hash__(self):
"""
Hash the `~astroplan.Observer` object.
Examples
--------
>>> from astroplan import Observer
>>> keck = Observer.at_site("Keck", timezone="US/Hawaii")
>>> hash(keck)
-3872382927731250571
"""

return hash(self._key())

def __eq__(self, other):
"""
Equality check for `~astroplan.Observer` objects.
Examples
--------
>>> from astroplan import Observer
>>> keck = Observer.at_site("Keck", timezone="US/Hawaii")
>>> keck2 = Observer.at_site("Keck", timezone="US/Hawaii")
>>> keck == keck2
True
"""

if isinstance(other, Observer):
return self._key() == other._key()
else:
return NotImplemented

def __ne__(self, other):
"""
Inequality check for `~astroplan.Observer` objects.
Examples
--------
>>> from astroplan import Observer
>>> keck = Observer.at_site("Keck", timezone="US/Hawaii")
>>> kpno = Observer.at_site("KPNO", timezone="US/Arizona")
>>> keck != kpno
True
"""

return not self.__eq__(other)

@classmethod
def at_site(cls, site_name, **kwargs):
"""
Expand Down Expand Up @@ -513,7 +589,7 @@ def altaz(self, time, target=None, obswl=None, grid_times_targets=False):
"""
if target is not None:
if target is MoonFlag:
target = get_moon(time, location=self.location)
target = get_body("moon", time, location=self.location)
elif target is SunFlag:
target = get_sun(time)

Expand Down Expand Up @@ -1734,7 +1810,7 @@ def moon_altaz(self, time, ephemeris=None):
if not isinstance(time, Time):
time = Time(time)

moon = get_moon(time, location=self.location, ephemeris=ephemeris)
moon = get_body("moon", time, location=self.location, ephemeris=ephemeris)
return self.altaz(time, moon)

def sun_altaz(self, time):
Expand Down
2 changes: 0 additions & 2 deletions astroplan/periodic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import numpy as np
import astropy.units as u
from astropy.time import Time
Expand Down
2 changes: 0 additions & 2 deletions astroplan/plots/finder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import numpy as np

Expand Down
3 changes: 0 additions & 3 deletions astroplan/plots/mplstyles.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import copy

from astropy.visualization import astropy_mpl_style
Expand Down
Loading

0 comments on commit 1f99580

Please sign in to comment.