Created
August 27, 2012 21:20
-
-
Save aezell/3492343 to your computer and use it in GitHub Desktop.
Sunset and Altitude for Shakespeare's Plays
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
# Caveat, the dates included are Julian but PyEphem and Python only really know about Gregorian. | |
# Additionally, not all of these performances were at The Globe so we should be moving the Observer | |
# accordingly. It still largely proves the hypothesis. | |
import argparse | |
from datetime import datetime | |
import ephem | |
from prettytable import PrettyTable | |
def shakespeare_had_candles(args): | |
time_of_day = args.time_of_day | |
show_altitude = args.show_altitude | |
hour, minute, second = map(int, time_of_day.split(':')) | |
plays = [ | |
{'name': 'Henry VI, Part I', 'performance_date': datetime(1592, 03, 03)}, | |
{'name': 'Titus Andronicus', 'performance_date': datetime(1594, 1, 23)}, | |
{'name': 'Taming of the Shrew', 'performance_date': datetime(1594, 6, 13)}, | |
{'name': 'The Comedy of Errors', 'performance_date': datetime(1594, 12, 28)}, | |
{'name': "Love's Labours Lost", 'performance_date': datetime(1597, 12, 26)}, | |
{'name': 'Julius Caesar', 'performance_date': datetime(1599, 10, 21)}, | |
{'name': 'Henry IV, Part I', 'performance_date': datetime(1600, 3, 6)}, | |
{'name': 'Richard II', 'performance_date': datetime(1601, 2, 7)}, | |
{'name': 'Twelfth Night', 'performance_date': datetime(1602, 2, 2)}, | |
{'name': 'Othello', 'performance_date': datetime(1604, 11, 1)}, | |
{'name': 'Troilus and Cressida', 'performance_date': datetime(1604, 2, 7)}, | |
{'name': 'Merry Wives of Windsor', 'performance_date': datetime(1604, 11, 4)}, | |
{'name': 'Measure for Measure', 'performance_date': datetime(1604, 12, 26)}, | |
{'name': 'Henry V', 'performance_date': datetime(1605, 1, 7)}, | |
{'name': 'Merchant of Venice', 'performance_date': datetime(1605, 2, 10)}, | |
{'name': 'King Lear', 'performance_date': datetime(1606, 12, 26)}, | |
{'name': 'The Tempest', 'performance_date': datetime(1611, 11, 1)}, | |
{'name': 'Henry VIII', 'performance_date': datetime(1613, 6, 29)} | |
] | |
globe = ephem.Observer() | |
globe.lat = '51.5069841' | |
globe.lon = '-0.0944368' | |
globe.elevation = 14 | |
sun = ephem.Sun() | |
table_headers = ['Play', | |
#'Curtain Up', | |
'Sunset', | |
'Time Difference', | |
'Light', | |
'Twilight Date', | |
'T Light'] | |
if show_altitude: | |
table_headers.append("Sun's Altitude") | |
x = PrettyTable(table_headers) | |
x.align['Play'] = 'l' | |
#x.align['Curtain Up'] = 'r' | |
x.align['Sunset'] = 'r' | |
x.align['Time Difference'] = 'l' | |
x.align['Candles'] = 'l' | |
x.align['Twilight Date'] = 'r' | |
x.align['Twilight Candles'] = 'l' | |
if show_altitude: | |
x.align["Sun's Altitude"] = 'l' | |
x.padding_width = 2 | |
candle_plays = 0 | |
twilight_plays = 0 | |
for play in plays: | |
# set horizon for London/Southwark/The Globe | |
globe.horizon = '-0:34' | |
globe.date = play['performance_date'].replace(hour=hour, minute=minute, second=second).\ | |
isoformat().replace('T', ' ') | |
start_date = globe.date | |
# compute sun's origin position | |
sun.compute(globe) | |
# get sun's altitude at highest point in our time range | |
if show_altitude: | |
most_light = str(sun.alt) | |
# get the datetime of the next setting | |
setting_date = globe.next_setting(sun) | |
# change horizon so we can calculate twilight (civil) | |
globe.horizon = '-6' | |
twilight_date = globe.next_setting(sun, use_center=True) | |
# determine of time interval means we'll need candles | |
diff = setting_date.datetime() - start_date.datetime() | |
if diff.total_seconds() > 10800: | |
candles = 'N' | |
else: | |
candles = 'Y' | |
candle_plays += 1 | |
# given the dying light of twilight will we still need candles | |
t_diff = twilight_date.datetime() - start_date.datetime() | |
if t_diff.total_seconds() > 10800: | |
twilight_candles = 'N' | |
else: | |
twilight_candles = 'Y' | |
twilight_plays += 1 | |
# add this data to output rows | |
word_diff = '%d hours, %d minutes' % (diff.seconds // 3600, (diff.seconds // 60) % 60) | |
row_items = [play['name'], | |
#start_date, | |
setting_date, | |
word_diff, | |
candles, | |
twilight_date, | |
twilight_candles] | |
if show_altitude: | |
row_items.append(most_light) | |
x.add_row(row_items) | |
print "Total Performances: %d" % len(plays) | |
print "Candle Performances: %d" % candle_plays | |
print "Twilight Candle Performances: %d" % twilight_plays | |
print x | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description="Did Shakespeare need candles?.") | |
parser.add_argument('-t', action="store", dest='time_of_day', type=str, | |
help="What time of day in (HH:MM:SS) format?") | |
parser.add_argument('-a', dest='show_altitude', help="Want to see the altitude?", | |
action="store_true", default=False) | |
args = parser.parse_args() | |
shakespeare_had_candles(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment