import numpy as np
from IPython.core.interactiveshell import InteractiveShell
from matplotlib import pyplot as plt
%config InlineBackend.figure_format = 'retina'
# %matplotlib notebook
InteractiveShell.ast_node_interactivity = 'last_expr'
# We need to do it in a separate cell. See:
# https://github.com/jupyter/notebook/issues/3385
plt.style.use('default')
plt.rcParams.update({
'font.family': 'latin modern math', 'font.size':12, 'mathtext.fontset':'stix',
'axes.formatter.use_mathtext': True, 'axes.formatter.limits': (-4, 4),
'axes.grid': True, 'grid.color': 'gray', 'grid.linewidth': 0.5,
'xtick.top': True, 'ytick.right': True,
'xtick.direction': 'inout', 'ytick.direction': 'inout',
'xtick.minor.size': 2.0, 'ytick.minor.size': 2.0, # default 2.0
'xtick.major.size': 4.0, 'ytick.major.size': 4.0, # default 3.5
'xtick.minor.visible': True, 'ytick.minor.visible': True
})
# Example schematic epochs (days, arbitrary zero point)
t_fov = np.array([-0.5, -0.2, 0.3, 0.55]) # FOV (observation) epochs
fov_colors = ["b", "g", "orange", "r"]
t_sso = np.random.RandomState(12345).uniform(2., 3.55, 17) # orbital-element epochs
dt_limit = 0.35 # kete_ipac (v1.x) only
def draw(ax, jd0, title, jd0_note, dt_limit=None):
"""Draw `propagate_n_body` to `jd0`, then `fov_state_check`."""
# Time axis
ax.annotate("", xy=(3.8, 0), xytext=(-0.8, 0),
arrowprops=dict(arrowstyle="->", lw=2, color="black"))
ax.text(3.85, 0, r"time $t$", va="center", ha="left", fontsize=14)
ax.text(-0.8, 1.3, title, ha="left", va="center", fontsize=16)
# fov_state_check: from JD0 to each FOV epoch
if dt_limit is not None:
ax.fill_between([jd0 - dt_limit, jd0 + dt_limit], 0, 0.95,
color="gold", alpha=0.25, lw=0)
ax.text(jd0, 0.9, "JD0 ± `dt_limit`", ha="center", va="top", fontsize=11)
for t, c in zip(t_fov, fov_colors):
ax.plot(t, 0, "o", ms=9, color=c, zorder=3)
if abs(t - jd0) < 1e-9:
continue
two_body = dt_limit is not None and abs(t - jd0) <= dt_limit
ax.annotate("", xy=(t, 0.06), xytext=(jd0, 0.06),
arrowprops=dict(arrowstyle="->", lw=1.3, color=c,
ls="--" if two_body else "-",
connectionstyle=f"arc3,rad={-0.5 * np.sign(t - jd0)}"))
ax.text(0.95, 0.8,
"`fov_state_check`\nsolid: N-body\ndashed: 2-body (yellow span)"
if dt_limit is not None
else "`fov_state_check`\nN-body to every FOV epoch\n(exact, no `dt_limit`)",
ha="left", va="center", fontsize=12)
ax.text(t_fov.max() + 0.1, -0.08, "FOV epochs", ha="left", va="top", fontsize=12)
# propagate_n_body: from each orbital-element epoch to JD0
y_arrows = -0.5 - 0.045 * np.arange(len(t_sso))
for t, y in zip(t_sso, y_arrows):
ax.plot(t, 0, "s", ms=7, color="gray", zorder=3)
ax.plot([t, t], [0, y], "-", lw=0.5, color="gray")
ax.annotate("", xy=(jd0, y), xytext=(t, y),
arrowprops=dict(arrowstyle="->", lw=0.5, color="gray"))
ax.text(t_sso.mean(), 0.12, "orbital-element epochs\n(arbitrary, may be far away)",
ha="center", va="bottom", fontsize=12, color="dimgray")
ax.text(0.5 * (jd0 + t_sso.min()), y_arrows[-1] - 0.08,
"`propagate_n_body`: N-body to JD0", ha="center", va="top", fontsize=12)
# JD0
ax.plot([jd0, jd0], [y_arrows[-1] - 0.05, 0.0], lw=2, color="b")
ax.text(jd0, y_arrows[-1] - 0.1, "JD0", ha="center", va="top",
fontsize=14, color="b", fontfamily="monospace")
ax.text(jd0, y_arrows[-1] - 0.32, jd0_note, ha="center", va="top", fontsize=11)
ax.set_xlim(-0.85, 4.2)
ax.set_ylim(-1.75, 1.45)
ax.axis("off")
fig, axs = plt.subplots(2, 1, figsize=(10, 7.6))
draw(axs[0], 0.5 * (t_fov.min() + t_fov.max()), "kete_ipac (v1.x)",
"default: middle of the FOV epochs", dt_limit=dt_limit)
draw(axs[1], t_fov.min(), "kete (>= 3.3)", "default: earliest FOV epoch")
plt.tight_layout()
plt.show()