Skip to content

Commit

Permalink
per day
Browse files Browse the repository at this point in the history
  • Loading branch information
wafels committed Aug 23, 2018
1 parent 2fa95a0 commit 7c0f487
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions observer_sees_planets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
#
import json

import numpy as np

from astropy.coordinates import get_body
from astropy.time import Time
import astropy.units as u

from sunpy.coordinates import frames



# Time we are interested in
start_time = Time('2000-05-10 00:00:00')
end_time = Time('2000-05-17 00:00:00')
end_time = Time('2000-05-11 00:00:00')

# Time step
dt = 30*u.minute
Expand All @@ -27,6 +31,7 @@
# Bodies
body_names = ('mercury', 'saturn', 'jupiter', 'venus')


#
def format_time_output(t):
"""
Expand All @@ -35,34 +40,37 @@ def format_time_output(t):
return int(np.rint(t.unix * 1000))


start_time_unix = format_time_output(start_time)

for body_name in body_names:
positions = dict()
positions[body_name] = dict()
positions[body_name][observer_name] = dict()

t = start_time
while t < end_time:
# The location of the observer
observer_location = get_body(observer_name, t)
for nday in range(0, 1):
day_start = start_time + nday*u.day
start_time_unix = format_time_output(day_start)

positions = dict()
positions[body_name] = dict()
positions[body_name][observer_name] = dict()

t = day_start
while t - day_start < 1 * u.day:
# The location of the observer
observer_location = get_body(observer_name, t)

# The location of the body
this_body = get_body(body_name, t)
# The location of the body
this_body = get_body(body_name, t)

# The position of the body as seen from the observer location
position = this_body.transform_to(observer_location).transform_to(frames.Helioprojective)
# The position of the body as seen from the observer location
position = this_body.transform_to(observer_location).transform_to(frames.Helioprojective)

# time index is unix time stamp in milliseconds - cast to ints
t_index = format_time_output(t)
positions[body_name][observer_name][t_index] = dict()
# time index is unix time stamp in milliseconds - cast to ints
t_index = format_time_output(t)
positions[body_name][observer_name][t_index] = dict()

# todo - Positions should be saved as float
positions[body_name][observer_name][t_index]["x"] = position.Tx.value
positions[body_name][observer_name][t_index]["y"] = position.Ty.value
# todo - Positions should be saved as float
positions[body_name][observer_name][t_index]["x"] = position.Tx.value
positions[body_name][observer_name][t_index]["y"] = position.Ty.value

t = t + dt
t = t + dt

f = open('{:s}_as_seen_from_{:s}_{:s}_to_{:s}.json'.format(observer_name, body_name, start_time_unix), 'w')
json.dump(positions, f)
f.close()
f = open('{:s}_{:s}_{:n}.json'.format(observer_name, body_name, start_time_unix), 'w')
json.dump(positions, f)
f.close()

0 comments on commit 7c0f487

Please sign in to comment.