Skip to content

Modify file sky.py to add labels for the hours corresponding to the points plotted in the skychart #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.o
*.so
__pycache__
.eggs

# Ignore .c files by default to avoid including generated code. If you want to
# add a non-generated .c extension, use `git add -f filename.c`.
Expand Down
38 changes: 35 additions & 3 deletions astroplan/plots/sky.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@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):
warn_below_horizon=False, style_sheet=None, hours_value=np.array([])):
"""
Plots target positions in the sky with respect to the observer's location.

Expand Down Expand Up @@ -81,6 +81,11 @@ def plot_sky(target, observer, time, ax=None, style_kwargs=None,
astroplan, print *astroplan.plots.available_style_sheets*. Defaults
to the light theme.

hours_value : `numpy.ndarray`
Array with the labels of the hours to be plotted. The length of
this array must be equal to the length of the time array. If
passed, the hours will be plotted on the sky map.

Returns
-------
An `~matplotlib.axes.Axes` object (ax) with a map of the sky.
Expand Down Expand Up @@ -171,8 +176,35 @@ def plot_sky(target, observer, time, ax=None, style_kwargs=None,
if north_to_east_ccw is False:
ax.set_theta_direction(-1)

# Plot target coordinates.
ax.scatter(az_plot, alt_plot, **style_kwargs)
# Hours added to map by F. Herpich 2025-05-19
if isinstance(hours_value, (list, tuple)):
hours_value = np.array(hours_value)
if not isinstance(hours_value, np.ndarray):
raise TypeError("hours_value must be a numpy array, list or tuple")

if len(hours_value) != len(time):
raise ValueError("hours_value must have the same length as the time array")

if hours_value.size > 0:
hoursvalue = hours_value[altitude <= 91.0]
if len(hoursvalue) > 1:
hoursname = ["%.1f" % i for i in hoursvalue]
for i, txt in enumerate(hoursname):
ax.annotate(txt, (az_plot[i], alt_plot[i]),
fontsize=8)
elif len(hoursvalue) == 1:
hoursname = ["%.1f" % hoursvalue[0]]
ax.annotate(hoursname[0], (az_plot[0], alt_plot[0]),
fontsize=8)
else:
pass

# Plot target coordinates. Modified by F. Herpich 2025-05-19
if 'c' in style_kwargs.keys():
colorformap = style_kwargs.pop('c')[altitude <= 91.0]
ax.scatter(az_plot, alt_plot, c=colorformap, **style_kwargs)
else:
ax.scatter(az_plot, alt_plot, **style_kwargs)

# Set radial limits.
ax.set_rlim(1, 91)
Expand Down
Loading