orbitsift 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orbitsift/__init__.py +2 -0
- orbitsift/_native.py +13 -0
- orbitsift/ades.py +166 -0
- orbitsift/archives/__init__.py +244 -0
- orbitsift/archives/cadc.py +97 -0
- orbitsift/archives/decam_geom.json +1 -0
- orbitsift/archives/eso.py +213 -0
- orbitsift/archives/hsc_geom.json +2378 -0
- orbitsift/archives/ing.py +70 -0
- orbitsift/archives/listing.py +22 -0
- orbitsift/archives/noirlab.py +302 -0
- orbitsift/archives/ps1.py +59 -0
- orbitsift/archives/sdss.py +52 -0
- orbitsift/archives/smoka.py +369 -0
- orbitsift/blind.py +558 -0
- orbitsift/catalog.py +328 -0
- orbitsift/cli.py +2200 -0
- orbitsift/config.py +85 -0
- orbitsift/confirm.py +1030 -0
- orbitsift/data/nsc_dr2_k4m_ksb.csv.gz +0 -0
- orbitsift/dense.py +788 -0
- orbitsift/dynamics.py +235 -0
- orbitsift/expindex.py +456 -0
- orbitsift/extend.py +690 -0
- orbitsift/external.py +204 -0
- orbitsift/extract.py +148 -0
- orbitsift/growth.py +224 -0
- orbitsift/images.py +676 -0
- orbitsift/itf.py +154 -0
- orbitsift/known.py +716 -0
- orbitsift/link.py +509 -0
- orbitsift/lov.py +642 -0
- orbitsift/mcp_server.py +164 -0
- orbitsift/multiyear.py +409 -0
- orbitsift/net.py +265 -0
- orbitsift/orbit.py +614 -0
- orbitsift/plugins.py +97 -0
- orbitsift/precovery.py +187 -0
- orbitsift/presets/a2.json +85 -0
- orbitsift/presets/confirm_v1.json +190 -0
- orbitsift/presets/confirm_v2.json +236 -0
- orbitsift/presets/lostrec.json +74 -0
- orbitsift/recover.py +377 -0
- orbitsift/rubin.py +328 -0
- orbitsift/survey.py +268 -0
- orbitsift/tiles.py +58 -0
- orbitsift/unused.py +103 -0
- orbitsift/vet.py +304 -0
- orbitsift/workflow/__init__.py +5 -0
- orbitsift/workflow/models.py +103 -0
- orbitsift/workflow/sqlite.py +189 -0
- orbitsift-0.1.0.dist-info/METADATA +443 -0
- orbitsift-0.1.0.dist-info/RECORD +56 -0
- orbitsift-0.1.0.dist-info/WHEEL +4 -0
- orbitsift-0.1.0.dist-info/entry_points.txt +3 -0
- orbitsift-0.1.0.dist-info/licenses/LICENSE +28 -0
orbitsift/dynamics.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"""N-body integration of test particles under the Sun and the four giant planets, and the
|
|
2
|
+
Neptune-Trojan (1:1 resonance) libration test.
|
|
3
|
+
|
|
4
|
+
Planet states at the start epoch come from JPL DE440s through astropy and jplephem (the kernel, ~32 MB, is
|
|
5
|
+
downloaded once into the astropy cache). Astropy's offline 'builtin' ephemeris is not used: its velocities are
|
|
6
|
+
off by 0.1-0.4%, enough to shift Neptune's osculating a by up to 0.03 AU and halve a Trojan's libration
|
|
7
|
+
amplitude. Integration: scipy
|
|
8
|
+
DOP853 in the ecliptic J2000 frame centred on the barycentre of the 5 massive bodies (the inner planets'
|
|
9
|
+
mass is added to the Sun). Libration angle: lambda_rel = mean longitude of the particle minus Neptune's
|
|
10
|
+
(heliocentric osculating elements), sampled every ``dt_out`` years.
|
|
11
|
+
"""
|
|
12
|
+
import math
|
|
13
|
+
import time
|
|
14
|
+
|
|
15
|
+
import numpy as np
|
|
16
|
+
from scipy.integrate import solve_ivp
|
|
17
|
+
|
|
18
|
+
from .orbit import ECL, GM_SUN
|
|
19
|
+
|
|
20
|
+
BODIES = ("sun", "jupiter", "saturn", "uranus", "neptune")
|
|
21
|
+
GMP = GM_SUN * np.array([1 + 6.0e-6, 1 / 1047.3486, 1 / 3497.898, 1 / 22902.98, 1 / 19412.24])
|
|
22
|
+
L4_RANGE = (20.0, 120.0) # deg: an L4 librator stays inside for the whole run
|
|
23
|
+
L5_RANGE = (240.0, 340.0)
|
|
24
|
+
ESCAPE_DA = 1.5 # AU: |a - a_Neptune| above this at any sample = left the 1:1 resonance
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def planets(t0, ephemeris="de440s"):
|
|
28
|
+
"""Ecliptic barycentric positions and velocities (5, 3) of Sun + giants at t0 (JD TDB)."""
|
|
29
|
+
from astropy.coordinates import get_body_barycentric_posvel, solar_system_ephemeris
|
|
30
|
+
from astropy.time import Time
|
|
31
|
+
X, W = [], []
|
|
32
|
+
for b in BODIES:
|
|
33
|
+
with solar_system_ephemeris.set(ephemeris):
|
|
34
|
+
p, w = get_body_barycentric_posvel(b, Time(t0, format="jd", scale="tdb"))
|
|
35
|
+
X.append(ECL @ p.xyz.to("au").value)
|
|
36
|
+
W.append(ECL @ w.xyz.to("au/d").value)
|
|
37
|
+
X, W = np.array(X), np.array(W)
|
|
38
|
+
X -= (GMP[:, None] * X).sum(0) / GMP.sum()
|
|
39
|
+
W -= (GMP[:, None] * W).sum(0) / GMP.sum()
|
|
40
|
+
return X, W
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _rhs(t, y, n):
|
|
44
|
+
s = y.reshape(2, 5 + n, 3)
|
|
45
|
+
x = s[0]
|
|
46
|
+
d = x[:5][None, :, :] - x[:, None, :] # (5 + n, 5, 3): massive body j - body i
|
|
47
|
+
r3 = (d * d).sum(2) ** 1.5
|
|
48
|
+
r3[np.arange(5), np.arange(5)] = np.inf
|
|
49
|
+
return np.concatenate([s[1].ravel(), (GMP[None, :, None] * d / r3[:, :, None]).sum(1).ravel()])
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def integrate(t0, states, years, dt_out=20.0, rtol=1e-10):
|
|
53
|
+
"""Integrate test particles (n, 6) (barycentric ICRS, AU, AU/d, at t0 JD TDB) for ``years``.
|
|
54
|
+
Returns dict(t [yr], x, v: (n_out, 5 + n, 3) ecliptic; rows 0-4 = Sun, Jupiter, Saturn, Uranus, Neptune)."""
|
|
55
|
+
states = np.atleast_2d(states)
|
|
56
|
+
n = len(states)
|
|
57
|
+
Xp, Wp = planets(t0)
|
|
58
|
+
x, v = states[:, :3] @ ECL.T, states[:, 3:] @ ECL.T
|
|
59
|
+
te = t0 + np.arange(0, years * 365.25 + 1e-6, dt_out * 365.25)
|
|
60
|
+
y0 = np.concatenate([np.r_[Xp, x].ravel(), np.r_[Wp, v].ravel()])
|
|
61
|
+
S = solve_ivp(_rhs, (t0, te[-1]), y0, method="DOP853", t_eval=te, rtol=rtol, atol=1e-14, args=(n,))
|
|
62
|
+
if not S.success:
|
|
63
|
+
raise RuntimeError(S.message)
|
|
64
|
+
y = S.y.reshape(2, 5 + n, 3, -1)
|
|
65
|
+
return dict(t=(te - t0) / 365.25, x=y[0].transpose(2, 0, 1), v=y[1].transpose(2, 0, 1), nfev=int(S.nfev))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def mean_longitude(x, v, mu=GMP[0]):
|
|
69
|
+
"""(k, 3) ecliptic states -> a [AU], e, mean longitude [deg]."""
|
|
70
|
+
r = np.linalg.norm(x, axis=1)
|
|
71
|
+
a = 1 / (2 / r - (v * v).sum(1) / mu)
|
|
72
|
+
h = np.cross(x, v)
|
|
73
|
+
ev = np.cross(v, h) / mu - x / r[:, None]
|
|
74
|
+
e = np.linalg.norm(ev, axis=1)
|
|
75
|
+
hn = h / np.linalg.norm(h, axis=1)[:, None]
|
|
76
|
+
nn = np.cross([0, 0, 1.0], hn)
|
|
77
|
+
nn /= np.linalg.norm(nn, axis=1)[:, None]
|
|
78
|
+
node = np.arctan2(nn[:, 1], nn[:, 0])
|
|
79
|
+
peri = np.arctan2((np.cross(nn, ev) * hn).sum(1), (nn * ev).sum(1))
|
|
80
|
+
nu = np.arctan2((np.cross(ev, x) * hn).sum(1), (ev * x).sum(1))
|
|
81
|
+
E = 2 * np.arctan(np.sqrt(np.clip((1 - e) / (1 + e), 0, None)) * np.tan(nu / 2))
|
|
82
|
+
return a, e, np.degrees(node + peri + E - e * np.sin(E)) % 360
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def libration(t0, states, kyr=100.0, dt_out=20.0, rtol=1e-10, backend="internal"):
|
|
86
|
+
"""Integrate particles and classify each as 'L4', 'L5', 'escaped' (left the 1:1) or 'other'
|
|
87
|
+
(horseshoe, circulating, or librating with a larger amplitude than the L4/L5 ranges).
|
|
88
|
+
backend 'rebound': the integration with REBOUND WHFast (``external.rebound_integrate``), same analysis.
|
|
89
|
+
Returns dict(summary, clones=[per particle: cls, centre, amp, lr_min, lr_max], t, lam_rel, a)."""
|
|
90
|
+
t1 = time.time()
|
|
91
|
+
if backend == "rebound":
|
|
92
|
+
from .external import rebound_integrate
|
|
93
|
+
R = rebound_integrate(t0, states, kyr * 1000, dt_out)
|
|
94
|
+
else:
|
|
95
|
+
R = integrate(t0, states, kyr * 1000, dt_out, rtol)
|
|
96
|
+
xs, vs = R["x"] - R["x"][:, :1], R["v"] - R["v"][:, :1] # heliocentric
|
|
97
|
+
aN, _, lN = mean_longitude(xs[:, 4], vs[:, 4])
|
|
98
|
+
out, LR, A = [], [], []
|
|
99
|
+
for j in range(len(np.atleast_2d(states))):
|
|
100
|
+
a, _, lam = mean_longitude(xs[:, 5 + j], vs[:, 5 + j])
|
|
101
|
+
lr = (lam - lN) % 360
|
|
102
|
+
esc = bool((np.abs(a - aN) > ESCAPE_DA).any())
|
|
103
|
+
l4 = not esc and bool(((lr > L4_RANGE[0]) & (lr < L4_RANGE[1])).all())
|
|
104
|
+
l5 = not esc and bool(((lr > L5_RANGE[0]) & (lr < L5_RANGE[1])).all())
|
|
105
|
+
out.append(dict(cls="escaped" if esc else "L4" if l4 else "L5" if l5 else "other",
|
|
106
|
+
centre=float((lr.max() + lr.min()) / 2), amp=float((lr.max() - lr.min()) / 2),
|
|
107
|
+
lr_min=float(lr.min()), lr_max=float(lr.max()),
|
|
108
|
+
t_escape_yr=float(R["t"][np.argmax(np.abs(a - aN) > ESCAPE_DA)]) if esc else None))
|
|
109
|
+
LR.append(lr)
|
|
110
|
+
A.append(a)
|
|
111
|
+
cls = [c["cls"] for c in out]
|
|
112
|
+
lib = [c for c in out if c["cls"] in ("L4", "L5")]
|
|
113
|
+
summary = dict(n=len(out), kyr=kyr, **{f"frac_{k}": cls.count(k) / len(cls) for k in ("L4", "L5", "escaped", "other")},
|
|
114
|
+
centre_median=float(np.median([c["centre"] for c in lib])) if lib else None,
|
|
115
|
+
amp_median=float(np.median([c["amp"] for c in lib])) if lib else None,
|
|
116
|
+
nominal=out[0], seconds=time.time() - t1, backend=backend,
|
|
117
|
+
**({"rebound": R["rebound"]} if "rebound" in R else {}))
|
|
118
|
+
return dict(summary=summary, clones=out, t=R["t"], lam_rel=np.array(LR), a=np.array(A), a_neptune=aN)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def clones(state, n=20, rel=1e-6, seed=5, cov=None):
|
|
122
|
+
"""Nominal state plus n clones: Gaussian draws from ``cov`` if given, else tiny relative
|
|
123
|
+
perturbations (a chaos check only)."""
|
|
124
|
+
rng = np.random.default_rng(seed)
|
|
125
|
+
state = np.asarray(state, float)
|
|
126
|
+
if cov is not None:
|
|
127
|
+
return np.r_[[state], rng.multivariate_normal(state, cov, n)]
|
|
128
|
+
return np.r_[[state], state + rng.normal(0, 1, (n, 6)) * rel * np.r_[np.full(3, np.linalg.norm(state[:3])), np.full(3, np.linalg.norm(state[3:]))]]
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# ---- dynamical classes (Gladman et al. 2008 as applied by OSSOS; DES variant as in Bernardinelli et al. 2022) ----
|
|
132
|
+
A_NEPTUNE = 30.07
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _resonances(abar):
|
|
136
|
+
"""Neptune resonances p:q (q <= 5, p/q <= 12, and 1:1) within 2% of the mean a."""
|
|
137
|
+
out = [(1, 1)] + [(p, q) for q in range(1, 6) for p in range(q + 1, 12 * q + 1) if math.gcd(p, q) == 1]
|
|
138
|
+
return [(p, q) for p, q in out if abs(A_NEPTUNE * (p / q) ** (2 / 3) - abar) < 0.02 * abar]
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _librates(phi):
|
|
142
|
+
"""One window: (librates, circular range [deg], circular mean [deg]). Librates = the angle does not cover the circle
|
|
143
|
+
(range < 340 deg) and oscillates about its mean (>= 6 crossings)."""
|
|
144
|
+
d = np.sort(np.degrees(phi) % 360)
|
|
145
|
+
rng = 360 - np.diff(np.r_[d, d[0] + 360]).max()
|
|
146
|
+
c = math.degrees(math.atan2(np.sin(phi).mean(), np.cos(phi).mean())) % 360
|
|
147
|
+
u = np.unwrap(phi)
|
|
148
|
+
s = np.sign(u - u.mean())
|
|
149
|
+
return bool(rng < 340 and int((s[1:] != s[:-1]).sum()) >= 6), float(rng), c
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _circulates(phi, nb):
|
|
153
|
+
"""True if the unwrapped sequence of the angle's circular means over blocks of nb samples spans a full turn."""
|
|
154
|
+
m = len(phi) // nb
|
|
155
|
+
if m < 2:
|
|
156
|
+
return False
|
|
157
|
+
z = np.exp(1j * phi[:m * nb]).reshape(m, nb).mean(1)
|
|
158
|
+
u = np.unwrap(np.angle(z))
|
|
159
|
+
return bool(u.max() - u.min() >= 2 * np.pi)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _resonance(a, lam, pom, lamN, win, nb):
|
|
163
|
+
ok, best = ~np.isnan(a), None
|
|
164
|
+
for p, q in _resonances(float(np.nanmean(a))):
|
|
165
|
+
phi = p * lam - q * lamN - (p - q) * pom
|
|
166
|
+
W = [_librates(phi[k:k + win]) if ok[k:k + win].all() else (False, 360.0, None) for k in range(0, len(a) - win + 1, win)]
|
|
167
|
+
f = sum(w[0] for w in W) / len(W)
|
|
168
|
+
if best is None or f > best["frac"]:
|
|
169
|
+
L = [w for w in W if w[0]]
|
|
170
|
+
best = dict(res=f"{p}:{q}", frac=f, amp=float(np.median([w[1] for w in L]) / 2) if L else None,
|
|
171
|
+
centre=float(np.median([w[2] for w in L])) if L else None, circ=_circulates(phi[ok], nb) if ok.all() else True)
|
|
172
|
+
return best or dict(res=None, frac=0.0, amp=None, centre=None, circ=True)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _rest(a0, e0, i0):
|
|
176
|
+
if a0 * (1 - e0) < 7.35:
|
|
177
|
+
return "inner (q < 7.35 au)"
|
|
178
|
+
if a0 < A_NEPTUNE:
|
|
179
|
+
return "Centaur"
|
|
180
|
+
if e0 > 0.24:
|
|
181
|
+
return "detached"
|
|
182
|
+
if a0 < 39.4:
|
|
183
|
+
return "inner classical"
|
|
184
|
+
if a0 < 48.4:
|
|
185
|
+
return "main classical " + ("cold" if i0 < 5 else "hot")
|
|
186
|
+
return "outer classical"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _resname(r):
|
|
190
|
+
return ("Neptune Trojan " + ("L4" if r["centre"] < 180 else "L5")) if r["res"] == "1:1" else f"resonant {r['res']}"
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def classify(run, tmax_yr=1e7):
|
|
194
|
+
"""Dynamical class of every clone of a long run (``external.rebound_classes_run``), first match wins:
|
|
195
|
+
resonant p:q if >= 50% of the 1-Myr windows librate, the clone survives and the angle does not circulate (its
|
|
196
|
+
100-kyr means never turn a full circle); Centaur if a0 < a_Neptune (q >= 7.35 AU); scattering if a varies by more
|
|
197
|
+
than 1.5 AU within tmax_yr or the clone is removed; else inner (q < 7.35), detached (e0 > 0.24) or classical (inner
|
|
198
|
+
< 39.4 AU, main to 48.4 AU, cold if i < 5 deg, outer). ``des``: the DES variant (>= 90% of windows librate,
|
|
199
|
+
scattering if da/a0 > 0.0375). -> dict(clones=[per-clone dict(lab, des, da, removed, res, frac, amp, centre, circ)],
|
|
200
|
+
cls, agree (fraction with the majority class), labels, des, des_agree)."""
|
|
201
|
+
st = float(run["step_yr"])
|
|
202
|
+
win, nb = int(round(1e6 / st)), int(round(1e5 / st))
|
|
203
|
+
a, e, inc = (np.asarray(run[k], float) for k in ("a", "e", "i"))
|
|
204
|
+
lam, pom, lamN, trm = (np.asarray(run[k], float) for k in ("lam", "pom", "lamN", "t_rm"))
|
|
205
|
+
n10 = int(tmax_yr / st) + 1
|
|
206
|
+
per = []
|
|
207
|
+
for j in range(a.shape[1]):
|
|
208
|
+
r = _resonance(a[:, j], lam[:, j], pom[:, j], lamN, win, nb)
|
|
209
|
+
rm = not np.isnan(trm[j])
|
|
210
|
+
rm10 = rm and trm[j] <= tmax_yr
|
|
211
|
+
a0, e0, i0 = a[0, j], e[0, j], inc[0, j]
|
|
212
|
+
da = float(np.nanmax(a[:n10, j]) - np.nanmin(a[:n10, j]))
|
|
213
|
+
if r["frac"] >= 0.5 and not rm and not r["circ"]:
|
|
214
|
+
lab = _resname(r)
|
|
215
|
+
elif a0 < A_NEPTUNE and a0 * (1 - e0) >= 7.35:
|
|
216
|
+
lab = "Centaur"
|
|
217
|
+
elif rm10 or da > 1.5:
|
|
218
|
+
lab = "scattering"
|
|
219
|
+
else:
|
|
220
|
+
lab = _rest(a0, e0, i0)
|
|
221
|
+
if r["frac"] >= 0.9 and not rm:
|
|
222
|
+
des = _resname(r)
|
|
223
|
+
elif rm10 or da / a0 > 0.0375:
|
|
224
|
+
des = "scattering"
|
|
225
|
+
else:
|
|
226
|
+
des = _rest(a0, e0, i0)
|
|
227
|
+
per.append(dict(lab=lab, des=des, da=da, removed=float(trm[j]) if rm else None, **r))
|
|
228
|
+
out = dict(clones=per)
|
|
229
|
+
for key, name in (("lab", "cls"), ("des", "des")):
|
|
230
|
+
labs = [p[key] for p in per]
|
|
231
|
+
top = max(set(labs), key=labs.count)
|
|
232
|
+
out[name], out[name + "_agree" if key == "des" else "agree"] = top, labs.count(top) / len(labs)
|
|
233
|
+
if key == "lab":
|
|
234
|
+
out["labels"] = {x: labs.count(x) for x in sorted(set(labs))}
|
|
235
|
+
return out
|