Skip to content

Instantly share code, notes, and snippets.

@boada
Last active November 8, 2016 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boada/12584fa0b7046aedf27aebb0616892a5 to your computer and use it in GitHub Desktop.
Save boada/12584fa0b7046aedf27aebb0616892a5 to your computer and use it in GitHub Desktop.
import astroplan
from astroplan import Observer, FixedTarget
from astropy.coordinates import SkyCoord
from astropy.time import Time, TimeDelta
from astroplan.constraints import AtNightConstraint, AirmassConstraint
import pandas as pd
import numpy as np
def mst2utc(time):
''' Converts from MST to UTC '''
dt = TimeDelta(7*3600, format='sec')
return time + dt
def utc2mts(time):
''' Converts from UTC to MST '''
dt = TimeDelta(7*3600, format='sec')
return time - dt
# make telescope location
kpno = Observer.at_site('KPNO', timezone='MST')
# make target coordinates
coords = SkyCoord(131.1331774, 62.41165761, unit='deg', frame='icrs')
# make all the targets
target = [FixedTarget(name='test', coord=coords)]
# make the observing time - Local time.
start_time_mst = Time('2016-11-11 18:53')
end_time_mst = Time('2016-11-12 05:29')
night_time = end_time_mst - start_time_mst
observable_time_mst = start_time_mst + night_time * np.linspace(0,1,75)
# convert everything to UTC
start_time_utc = mst2utc(start_time_mst)
end_time_utc = mst2utc(end_time_mst)
observable_time_utc = mst2utc(observable_time_mst)
print(kpno.target_is_up(start_time_utc, target))
# expect to print True
# now we try to do all the fancy scheduling
# set our only constraint to be at night
constraint = [AtNightConstraint.twilight_civil(), AirmassConstraint(max=5)]
print(astroplan.is_observable(constraint, kpno, target[:1],
time_range=observable_time_utc))
# expect to print True.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment