Skip to content

Commit

Permalink
Add type hints to plotting modules
Browse files Browse the repository at this point in the history
  • Loading branch information
vandalt committed Sep 16, 2024
1 parent 0f3a7b4 commit 04b1804
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 35 deletions.
19 changes: 12 additions & 7 deletions astroplan/plots/finder.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from __future__ import absolute_import, division, print_function, unicode_literals

import numpy as np
from typing import Optional, Union

import astropy.units as u

from matplotlib.axes import Axes
import numpy as np
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
from astropy.units import Quantity

from ..target import FixedTarget

__all__ = ['plot_finder_image']


@u.quantity_input(fov_radius=u.deg)
def plot_finder_image(target, survey='DSS', fov_radius=10*u.arcmin,
log=False, ax=None, grid=False, reticle=False,
style_kwargs=None, reticle_style_kwargs=None):
def plot_finder_image(target: Union[FixedTarget, SkyCoord], survey: str = 'DSS',
fov_radius: Quantity = 10*u.arcmin, log: bool = False,
ax: Optional[Axes] = None, grid: bool = False, reticle: bool = False,
style_kwargs: Optional[dict] = None,
reticle_style_kwargs: Optional[dict] = None) -> Axes:
"""
Plot survey image centered on ``target``.
Expand Down
25 changes: 17 additions & 8 deletions astroplan/plots/sky.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import numpy as np
import warnings
from typing import Optional

import astropy.units as u
import numpy as np
from astropy.time import Time
import warnings
from astropy.units import Quantity
from matplotlib.axes import Axes

from ..exceptions import PlotBelowHorizonWarning
from ..observer import Observer
from ..target import FixedTarget
from ..utils import _set_mpl_style_sheet

__all__ = ['plot_sky', 'plot_sky_24hr']


@u.quantity_input(az_label_offset=u.deg)
def plot_sky(target, observer, time, ax=None, style_kwargs=None,
north_to_east_ccw=True, grid=True, az_label_offset=0.0*u.deg,
warn_below_horizon=False, style_sheet=None):
def plot_sky(target: FixedTarget, observer: Observer, time: Time, ax: Optional[Axes] = None,
style_kwargs: Optional[dict] = None, north_to_east_ccw: bool = True, grid: bool = True,
az_label_offset: Quantity = 0.0*u.deg,
warn_below_horizon: bool = False, style_sheet: Optional[dict] = None) -> Axes:
"""
Plots target positions in the sky with respect to the observer's location.
Expand Down Expand Up @@ -229,9 +236,11 @@ def plot_sky(target, observer, time, ax=None, style_kwargs=None,


@u.quantity_input(delta=u.hour)
def plot_sky_24hr(target, observer, time, delta=1*u.hour, ax=None,
style_kwargs=None, north_to_east_ccw=True, grid=True,
az_label_offset=0.0*u.deg, center_time_style_kwargs=None):
def plot_sky_24hr(target: FixedTarget, observer: Observer, time: Time, delta: Quantity = 1*u.hour,
ax: Axes = None, style_kwargs: Optional[dict] = None,
north_to_east_ccw: bool = True, grid: bool = True,
az_label_offset: Quantity = 0.0*u.deg,
center_time_style_kwargs: Optional[dict] = None) -> Axes:
"""
Plots target positions in the sky with respect to the observer's location
over a twenty-four hour period centered on ``time``.
Expand Down
48 changes: 28 additions & 20 deletions astroplan/plots/time_dependent.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from __future__ import absolute_import, division, print_function, unicode_literals

import copy
import numpy as np
import operator
import astropy.units as u
from astropy.time import Time
from collections.abc import Sequence
import warnings
from collections.abc import Sequence
from typing import Optional

import astropy.units as u
import numpy as np
import pytz
from astropy.time import Time
from matplotlib.axes import Axes

from ..exceptions import PlotWarning
from ..observer import Observer
from ..scheduling import Schedule
from ..target import FixedTarget
from ..utils import _set_mpl_style_sheet

__all__ = ['plot_airmass', 'plot_schedule_airmass', 'plot_parallactic',
'plot_altitude']


def _secz_to_altitude(secant_z):
def _secz_to_altitude(secant_z: float) -> float:
"""
Convert airmass (approximated as the secant of the zenith angle) to
an altitude (aka elevation) in degrees.
Expand All @@ -35,7 +41,7 @@ def _secz_to_altitude(secant_z):
return np.degrees(np.pi/2 - np.arccos(1./secant_z))


def _has_twin(ax):
def _has_twin(ax: Axes) -> bool:
"""
Solution for detecting twin axes built on `ax`. Courtesy of
Jake Vanderplas http://stackoverflow.com/a/36209590/1340208
Expand All @@ -48,10 +54,12 @@ def _has_twin(ax):
return False


def plot_airmass(targets, observer, time, ax=None, style_kwargs=None,
style_sheet=None, brightness_shading=False,
altitude_yaxis=False, min_airmass=1.0, min_region=None,
max_airmass=3.0, max_region=None, use_local_tz=False):
def plot_airmass(targets: FixedTarget, observer: Observer, time: Time, ax: Optional[Axes] = None,
style_kwargs: Optional[dict] = None, style_sheet: Optional[dict] = None,
brightness_shading: bool = False, altitude_yaxis: bool = False,
min_airmass: float = 1.0, min_region: Optional[float] = None,
max_airmass: float = 3.0, max_region: Optional[float] = None,
use_local_tz: bool = False) -> Axes:
r"""
Plots airmass as a function of time for a given target.
Expand Down Expand Up @@ -276,10 +284,11 @@ def plot_airmass(targets, observer, time, ax=None, style_kwargs=None,
return ax


def plot_altitude(targets, observer, time, ax=None, style_kwargs=None,
style_sheet=None, brightness_shading=False,
airmass_yaxis=False, min_altitude=0, min_region=None,
max_altitude=90, max_region=None):
def plot_altitude(targets: FixedTarget, observer: Observer, time: Time, ax: Optional[Axes] = None,
style_kwargs: Optional[dict] = None, style_sheet: Optional[dict] = None,
brightness_shading: bool = False, airmass_yaxis: bool = False,
min_altitude: float = 0, min_region: Optional[float] = None,
max_altitude: float = 90, max_region: Optional[float] = None) -> Axes:
r"""
Plots altitude as a function of time for a given target.
Expand Down Expand Up @@ -467,7 +476,7 @@ def plot_altitude(targets, observer, time, ax=None, style_kwargs=None,
return ax


def plot_schedule_airmass(schedule, show_night=False):
def plot_schedule_airmass(schedule: Schedule, show_night: bool = False) -> Axes:
"""
Plots when observations of targets are scheduled to occur superimposed
upon plots of the airmasses of the targets.
Expand Down Expand Up @@ -526,8 +535,8 @@ def plot_schedule_airmass(schedule, show_night=False):
# TODO: make this output a `axes` object


def plot_parallactic(target, observer, time, ax=None, style_kwargs=None,
style_sheet=None):
def plot_parallactic(target: FixedTarget, observer: Observer, time: Time, ax: Optional[Axes] = None,
style_kwargs: Optional[dict] = None, style_sheet: Optional[dict] = None) -> Axes:
"""
Plots parallactic angle as a function of time for a given target.
Expand Down Expand Up @@ -586,7 +595,6 @@ def plot_parallactic(target, observer, time, ax=None, style_kwargs=None,
_set_mpl_style_sheet(style_sheet)

import matplotlib.pyplot as plt

from matplotlib import dates

# Set up plot axes and style if needed.
Expand Down

0 comments on commit 04b1804

Please sign in to comment.