<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Planning observations with astroplan - Constraints
Step1:  List Comprehensions
List comprehensions provide a concise way to create lists (arrays). Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence.
For example
Step2:  You can do the same thing with
Step3:  You can include if statements
Step4:  You can do the same thing with
Step5:  Now to observations
Let us start with a external list of target objects
Step6:  Observing Night
You are the most junior member of the team, so you get stuck observing on New Years Eve
Step7:  But, you get to observe in Hawaii
Step8:  Plot the objects
Step9:  Observing Constraints
Step10:  Let us add another constraint
Step11:  Additional Constraints
from astroplan import CONSTRAINT
AtNightConstraint() - Constrain the Sun to be below horizon.
MoonIlluminationConstraint(min, max) - Constrain the fractional illumination of the Moon.
MoonSeparationConstraint(min, max) - Constrain the separation between the Moon and some targets.
SunSeparationConstraint(min, max) - Constrain the separation between the Sun and some targets.
<ASSISTANT_TASK:>
Python Code:
import numpy as np
from astropy.table import QTable
import astropy.units as u
from astropy.time import Time
from astropy.coordinates import SkyCoord, EarthLocation
import pytz
from astroplan import Observer, FixedTarget
import warnings
warnings.filterwarnings('ignore', category=Warning)
Explanation: Planning observations with astroplan - Constraints
End of explanation
squares = []                    # create a blank list
for x in range(10):             # foor loop 0 -> 9
    squares.append(x**2)        # calculate x**2 for each x, add to end of list
squares
Explanation: List Comprehensions
List comprehensions provide a concise way to create lists (arrays). Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence.
For example: Create the list: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
End of explanation
squares = [x**2 for x in range(10)]
squares
Explanation: You can do the same thing with:
End of explanation
even_squares = []
for x in range(10):
    
    if (x % 2 == 0):
        even_squares.append(x**2)
even_squares
Explanation: You can include if statements:
End of explanation
even_squares = [x**2 for x in range(10) if (x % 2 == 0)]
even_squares
Explanation: You can do the same thing with:
End of explanation
target_table = QTable.read('ObjectList.csv', format='ascii.csv')
target_table
targets = [FixedTarget(coord=SkyCoord(ra = RA*u.hourangle, dec = DEC*u.deg), name=Name)
           for Name, RA, DEC in target_table]
targets
Explanation: Now to observations
Let us start with a external list of target objects:
End of explanation
observe_date = Time("2018-01-01", format='iso')
Explanation: Observing Night
You are the most junior member of the team, so you get stuck observing on New Years Eve
End of explanation
my_timezone = pytz.timezone('US/Hawaii')
my_location = Observer.at_site('gemini_north')
observe_start = my_location.sun_set_time(observe_date, which='nearest')
observe_end = my_location.sun_rise_time(observe_date, which='next')
print("Observing starts at {0.iso} UTC".format(observe_start))
print("Observing ends at {0.iso} UTC".format(observe_end))
print("Observing starts at {0} local".format(observe_start.to_datetime(my_timezone)))
print("Observing ends at {0} local".format(observe_end.to_datetime(my_timezone)))
# A complete list of built-in observatories can be found by:
#EarthLocation.get_site_names()
observing_length = (observe_end - observe_start).to(u.h)
print("You can observe for {0:.1f} tonight".format(observing_length))
observing_range = [observe_start, observe_end]
Explanation: But, you get to observe in Hawaii
End of explanation
%matplotlib inline
import matplotlib.pyplot as plt
from astroplan import time_grid_from_range
from astroplan.plots import plot_sky, plot_airmass
time_grid = time_grid_from_range(observing_range)
fig,ax = plt.subplots(1,1)
fig.set_size_inches(10,10)
fig.tight_layout()
for my_object in targets:
    ax = plot_sky(my_object, my_location, time_grid)
ax.legend(loc=0,shadow=True);
fig,ax = plt.subplots(1,1)
fig.set_size_inches(10,5)
fig.tight_layout()
for my_object in targets:
    ax = plot_airmass(my_object, my_location, time_grid)
ax.legend(loc=0,shadow=True);
Explanation: Plot the objects
End of explanation
from astroplan import AltitudeConstraint, AirmassConstraint
from astroplan import observability_table
constraints = [AltitudeConstraint(20*u.deg, 80*u.deg)]
observing_table = observability_table(constraints, my_location, targets, time_range=observing_range)
print(observing_table)
Explanation: Observing Constraints
End of explanation
constraints.append(AirmassConstraint(2))
observing_table = observability_table(constraints, my_location, targets, time_range=observing_range)
print(observing_table)
Explanation: Let us add another constraint
End of explanation
from astroplan import moon_illumination
moon_illumination(observe_start)
from astroplan import MoonSeparationConstraint
constraints.append(MoonSeparationConstraint(45*u.deg))
observing_table = observability_table(constraints, my_location, targets, time_range=observing_range)
print(observing_table)
fig,ax = plt.subplots(1,1)
fig.set_size_inches(10,5)
fig.tight_layout()
for i, my_object in enumerate(targets):
    
    if observing_table['ever observable'][i]:
        ax = plot_airmass(my_object, my_location, time_grid)
ax.legend(loc=0,shadow=True);
Explanation: Additional Constraints
from astroplan import CONSTRAINT
AtNightConstraint() - Constrain the Sun to be below horizon.
MoonIlluminationConstraint(min, max) - Constrain the fractional illumination of the Moon.
MoonSeparationConstraint(min, max) - Constrain the separation between the Moon and some targets.
SunSeparationConstraint(min, max) - Constrain the separation between the Sun and some targets.
End of explanation
<END_TASK>