I am currently facing a problem which ask me to plot the Earth's location over a very long time (over 10000 days).
I am using astroquery to get the location of Earth. I have decided to plot the location of Earth every day and making them into a graph. Is this possible or should I plot the location every 10-days or more to decrease the number of computations?
from astroquery.jplhorizons import Horizons
from astropy.time import Time
tau = Time("1986-08-06 11:08:00").jd # for not confusing with the previous tau
Earth_location = 3 # code for Earth barycentre
origin = "500@0" # code for solar system barycentre
real_earth_position = []
np.set_printoptions(threshold=sys.maxsize)
D=1000
for i in range(0,D,1):
t = tau + i
query_earth = Horizons(id=Earth_location,location=origin, epochs=t)
vec_earth = query_earth.vectors()
x_e = vec_earth["x"][0] #For Earth
y_e = vec_earth["y"][0]
z_e = vec_earth["z"][0]
real_earth_position.append([x_e, y_e, z_e])
ax.scatter(x_e,y_e,z_e,label=f"Position at {t}")
real_earth_position = np.array(real_earth_position)
this is the code I have tried, but I notice that this takes about a second to create a new vector, so if D is 1000 it takes minutes to produce all vectors that I need. Is it possible to make it generate faster?
your Problem:
Querying the Earth's position for each day individually with astroquery
is slow.
Solution:
To speed things up, use the epochs
parameter in astroquery
to request data for multiple days at once.
Optimized code:
from astroquery.jplhorizons import Horizons
from astropy.time import Time
import matplotlib.pyplot as plt
# Query and plot in one go
vec = Horizons(id=3, location="500@0", epochs={'start': Time("1986-08-06 11:08:00").isot,
'stop': (Time("1986-08-06 11:08:00") + 10000).isot,
'step': '1d'}).vectors()
plt.figure().add_subplot(111, projection='3d').scatter(vec['x'], vec['y'], vec['z'], s=10, c='blue', alpha=0.6)
plt.xlabel("X (AU)"), plt.ylabel("Y (AU)"), plt.zlabel("Z (AU)"), plt.show()
good luck mate...