Created
June 5, 2015 15:47
-
-
Save jberlanga/543afee14f09443f0941 to your computer and use it in GitHub Desktop.
Observing excercise with Skyfield
This file contains hidden or 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
#!/usr/bin/env python3.4 | |
""" | |
observe_skyfield.py | |
Observing exercise with Skyfield. | |
""" | |
import numpy as np | |
from skyfield.api import JulianDate, earth, venus, jupiter, saturn, Star | |
from datetime import datetime | |
from pytz import timezone | |
################### | |
# Set Dates & Times | |
################### | |
# Central timezone | |
central = timezone('US/Central') | |
# Skyfield can make date/time objects as arrays (for instance, | |
# if want info for multiple times in one night), but | |
# not clear how would handle higher order arrays | |
# (eg., multiple times in multiple nights). | |
# What time to start/end observing in local timezone | |
local_start_hour = 20 # 8:00 pm | |
#local_start_min = 30 | |
local_end_hour = 23 # 11:00 pm | |
#local_end_min = 30 | |
# Observing in | |
year = 2015 | |
month = 5 | |
day = 15 | |
hour = range(local_start_hour, local_end_hour + 1) | |
observe_date = [] | |
for i in range(0, len(hour)): | |
observe_date.append(central.localize(datetime(year, month, day, hour[i]))) | |
jd_1 = JulianDate(observe_date) | |
################### | |
# Find Observer-centered Coords | |
################### | |
# Fayetteville, AR | |
fville = earth.topos('36.0764 N', '94.1608 W') | |
# Define star targets. | |
# This should instead be input as lists or dictionaries. | |
# Because of the tendency to create "shortcut" objects for the planets, | |
# creating observation objects for planets within the same loop | |
# that creates observation objects for stars does not have an | |
# obvious solution for the novice or casual programmer. | |
Sirius = Star(ra_hours=(6, 45, 08.9173), dec_degrees=(-16, 42, 58.017)) | |
Pollux = Star(ra_hours=(7, 45, 19), dec_degrees=(28, 1.584, 0)) | |
Castor = Star(ra_hours=(7, 34, 36), dec_degrees=(31, 53, 18)) | |
Polaris = Star(ra_hours=(2, 31, 48.7), dec_degrees=(89, 15, 51)) | |
Betelgeuse = Star(ra_hours=(5, 55, 10.3053), dec_degrees=(7, 24, 25.426)) | |
Rigel = Star(ra_hours=(5, 14, 32.272), dec_degrees=(-8, 12, 05.91)) | |
Altair = Star(ra_hours=(19, 50, 47), dec_degrees=(8, 52.098, 0)) | |
Deneb = Star(ra_hours=(20, 41, 25.9), dec_degrees=(45, 16, 49)) | |
Vega = Star(ra_hours=(18, 36, 56.3364), dec_degrees=(38, 47, 01.291)) | |
Arcturus = Star(ra_hours=(14, 15, 39.7), dec_degrees=(19, 10, 56)) | |
Spica = Star(ra_hours=(13, 25, 11.5793), dec_degrees=(-11, 9, 40.759)) | |
# Define Messier object targets. | |
M31 = Star(ra_hours=(0, 42, 44.3), dec_degrees=(41, 16, 10)) | |
M33 = Star(ra_hours=(1, 33, 50.9), dec_degrees=(30, 39, 36)) | |
M13 = Star(ra_hours=(16, 5, 15), dec_degrees=(17, 44, 55)) | |
M1 = Star(ra_hours=(5, 34, 32), dec_degrees=(22, 0.870, 0)) | |
M51 = Star(ra_hours=(13, 29, 52.7), dec_degrees=(47, 11, 43)) | |
# List of targets | |
# Clear that target objects need to include a name attribute as well that can be used to refer | |
# to the variables, in order to avoid a situation like this, with separate target & target | |
# name lists. | |
# Also, dictionaries would be more flexible than arrays when putting together varying data | |
# types, as may be necessary when putting together observation tables. | |
targets = [Sirius, Pollux, Castor, Polaris, Betelgeuse, Rigel, Altair, Deneb, Vega, Arcturus, Spica, M31, M33, M13, M1, M51] | |
target_names = ['Sirius', 'Pollux', 'Castor', 'Polaris', 'Betelgeuse', 'Rigel', 'Altair', 'Deneb', 'Vega', 'Arcturus', 'Spica', 'M31', 'M33', 'M13', 'M1', 'M51'] | |
# Get alt/az for all objects from apparent positions. | |
for target in range(0, len(targets)): | |
print(target_names[target]) | |
## Numpy array to hold output data | |
## Date/Time Alt Az | |
#output_array = np.zeros((len(hour), 3), dtype=str) | |
for date in range(0, len(hour)): | |
alt, az = fville(jd_1[date]).observe(targets[target]).apparent().altaz()[:2] | |
#output_array[date:0] = str(jd_1[date].astimezone(central)) | |
print(jd_1[date].astimezone(central)) | |
#output_array[date:1] = str(alt.dstr()) | |
print(alt.dstr()) | |
#output_array[date:2] = str(az.dstr()) | |
print(az.dstr()) | |
#np.savetxt(target_names[target]+'--alt_az.txt', output_array, fmt="%s", delimiter="\t") | |
## This savetxt statement doesn't work. | |
print("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from skyfield.api import JulianDate
throws an error...