In [2]:
import ephem
from IPython.display import HTML
In [3]:
# Set observation location - select key from list below
location = 'hilo'
# Add more locations as needed
observer_locations = {
'hilo': {
'lon': '-155:05:23:99',
'lat': '19:42:00:00',
'elevation': 88 , # meters
'temp': 23, # celsius
'pressure': 1010 # This is default but also a guess
},
'vis': {
'lon': '-155:27:52:35',
'lat': '19:45:42:96',
'elevation': 2848.5, # meters
'temp': 15, # celsius - this is a guess
'pressure': 700 #this is a guess
},
}
In [10]:
# Building an Observer to watch the moon. Shouldn't need to change anything here. Move along.
# Phases to watch
min_phase = 0.08
max_phase = 0.58
# Time to watch (UTC)
min_hour = 5 # 7pm HST
max_hour = 15 # 5am HST
midnight = 10
# Get the settings for our location
location_settings = observer_locations[location]
# Setup our observer from our given location
observer = ephem.Observer()
observer.lat = location_settings['lat']
observer.lon = location_settings['lon']
observer.elevation = location_settings['elevation']
observer.temp = location_settings['temp']
observer.pressure = location_settings['pressure']
print(observer.next_rising(ephem.Moon()))
print(observer.next_setting(ephem.Moon()))
In [6]:
# Dates to check, starting from today
observer.date = ephem.Date('2013/09/27 10:00:00')
stop_date = ephem.Date('2014/01/01')
# Create our Moon and look at it from our observer location
moon = ephem.Moon(observer)
# Get next rise time
next_rise_time = observer.next_rising(ephem.Moon())
next_set_time = observer.next_setting(ephem.Moon())
while next_rise_time < stop_date:
# Get info about moon for the night
phase = moon.moon_phase
hour = next_rise_time.tuple()[3]
# Check for good conditions
#if (phase > min_phase) & (phase < max_phase) & (hour > min_hour) & (hour < max_hour):
# Get local time
#local_rise_time = ephem.localtime(next_rise_time).strftime('%a %m/%d %H:%M')
local_rise_time = ephem.localtime(next_rise_time).strftime('%H:%M')
local_set_time = ephem.localtime(next_set_time).strftime('%H:%M')
print(local_rise_time, local_set_time)
# Get next rising time
observer.date += 1
next_rise_time = observer.next_rising(ephem.Moon())
next_set_time = observer.next_setting(ephem.Moon())
moon.compute(observer)
In [4]:
# Here we are getting a list of all the known magnitude stars and then creating
# a function which will return the nearest star to the moon for our given observer.
from ephem import stars
# First we go through the stars and compute their position for our observer
# There are not that many stars in the list (122) so this is not a big deal
for name, star in stars.stars.items():
star.compute(observer)
def find_nearest_star(obj):
"""
Finds the star that appears closest to the moon for the observer. The star list
comes from ephems list of stars of known magnitudes.
"""
# Get the dict of all separations for object
star_sep = {name:ephem.separation(obj,star) for name,star in stars.stars.items()}
# Get the star with minimum separation
min_star_name = min(star_sep, key = lambda k: star_sep[k])
return stars.star(min_star_name)
In [8]:
# Create our Moon and look at it from our observer location
moon = ephem.Moon(observer)
observer.date = ephem.now()
show_break = False
header = "|{4:s}\n| {0:s}| {1:s}| {2:s}| {3:}\n|{4:s}".format('Date'.ljust(18),'Phase'.ljust(10),'Moon'.ljust(30),'Mag Star','-' * 80)
print(header)
while observer.date.triple()[0] < 2014:
p = moon.moon_phase
hour = observer.date.tuple()[3]
near_star = find_nearest_star(moon)
display_date = ephem.localtime(observer.date).strftime('%a %m/%d %H:%M')
if (p > 0.08) & (p < 0.58) & (moon.alt > ephem.degrees('20:00:00')) & (hour > 5) &(hour < 15):
show_break = True
print("| {}".format(display_date.ljust(18)), end='')
print("| {:.2f}\t".format(p), end='')
print("| {} x {}\t".format(moon.az,moon.alt), end='')
print("| {} {}".format(near_star.name,ephem.separation(near_star,moon)))
else:
if show_break:
print("{}\n".format('-'*71))
print(header)
show_break = False
observer.date += ephem.hour
moon.compute(observer)
In [8]:
def get_good_obs_dates(start_date=ephem.now(),end_date=ephem.Date('2014-01-01')):
"""
Given a start_date and an end_date, loop
through and find every (night) hour when
moon is above 20°. Defaults to remainder
of year.
"""