-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
Adding telescope constraints to the time_dependent plots #548
Open
SunilSimha
wants to merge
4
commits into
astropy:main
Choose a base branch
from
SunilSimha:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6c47a8b
add telescope limits to plot
SunilSimha 67816e2
Merge pull request #1 from SunilSimha/constraints_plot
SunilSimha 5c6b952
add telescope limits to plot
SunilSimha 346fb21
Merge branch 'master' of https://github.com/SunilSimha/astroplan
SunilSimha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
import copy | ||
from xmlrpc.client import boolean | ||
import numpy as np | ||
import operator | ||
import astropy.units as u | ||
|
@@ -12,6 +13,7 @@ | |
|
||
from ..exceptions import PlotWarning | ||
from ..utils import _set_mpl_style_sheet | ||
from ..constraints import Constraint | ||
|
||
__all__ = ['plot_airmass', 'plot_schedule_airmass', 'plot_parallactic', | ||
'plot_altitude'] | ||
|
@@ -51,7 +53,8 @@ def _has_twin(ax): | |
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): | ||
max_airmass=3.0, max_region=None, use_local_tz=False, | ||
constraints=None): | ||
r""" | ||
Plots airmass as a function of time for a given target. | ||
|
||
|
@@ -126,6 +129,10 @@ def plot_airmass(targets, observer, time, ax=None, style_kwargs=None, | |
use_local_tz : bool | ||
If the time is specified in a local timezone, the time will be plotted | ||
in that timezone. | ||
|
||
constraints : Constraint or list of Constraint objects (optional) | ||
If a list of boolean constraints is provided, the objects will have | ||
blackened curves outside the constraints. | ||
|
||
Returns | ||
------- | ||
|
@@ -176,6 +183,23 @@ def plot_airmass(targets, observer, time, ax=None, style_kwargs=None, | |
|
||
if not isinstance(targets, Sequence): | ||
targets = [targets] | ||
|
||
# Firstly, check that the constraints are valid if any. | ||
if constraints is not None: | ||
if isinstance(constraints, Constraint): | ||
constraints = [constraints] | ||
|
||
assert isinstance(constraints, (list, tuple, np.ndarray)), "constraints must be an array-like object or a single Constraint instance." | ||
for cons in constraints: | ||
assert isinstance(cons, Constraint), "All constraint objects must be Constraints" | ||
|
||
# Make sure they're boolean | ||
assert hasattr(cons, 'boolean_constraint'), "Each constraints element must have the 'boolean_constraint attribute." | ||
assert cons.boolean_constraint, "Cannot work with non-boolean constraints." | ||
# Then make sure they're not some weird user-generated constraint. | ||
assert hasattr(cons, 'compute_constraint'), "Constraints must have a 'compute_constraint' method." | ||
|
||
|
||
Comment on lines
+186
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than including |
||
|
||
for target in targets: | ||
# Calculate airmass | ||
|
@@ -192,6 +216,17 @@ def plot_airmass(targets, observer, time, ax=None, style_kwargs=None, | |
# Plot data (against timezone-offset time) | ||
ax.plot_date(timetoplot.plot_date, masked_airmass, label=target_name, **style_kwargs) | ||
|
||
# Plot black curves for where the target is outside constraints | ||
if constraints: | ||
cons_mask = np.ones(len(airmass), dtype=bool) | ||
for cons in constraints: | ||
cons_mask &= cons(observer, target, time_ut) | ||
|
||
# Handle discontinuous curves: | ||
time_vals = np.where((~cons_mask)&(airmass>1),timetoplot.plot_date, np.nan) | ||
am_vals = np.where((~cons_mask)&(airmass>1), airmass, np.nan) | ||
ax.plot_date(time_vals, am_vals, "k", lw=3) | ||
|
||
# Format the time axis | ||
xlo, xhi = (timetoplot[0]), (timetoplot[-1]) | ||
ax.set_xlim([xlo.plot_date, xhi.plot_date]) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere?