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.
Files changed (56) hide show
  1. orbitsift/__init__.py +2 -0
  2. orbitsift/_native.py +13 -0
  3. orbitsift/ades.py +166 -0
  4. orbitsift/archives/__init__.py +244 -0
  5. orbitsift/archives/cadc.py +97 -0
  6. orbitsift/archives/decam_geom.json +1 -0
  7. orbitsift/archives/eso.py +213 -0
  8. orbitsift/archives/hsc_geom.json +2378 -0
  9. orbitsift/archives/ing.py +70 -0
  10. orbitsift/archives/listing.py +22 -0
  11. orbitsift/archives/noirlab.py +302 -0
  12. orbitsift/archives/ps1.py +59 -0
  13. orbitsift/archives/sdss.py +52 -0
  14. orbitsift/archives/smoka.py +369 -0
  15. orbitsift/blind.py +558 -0
  16. orbitsift/catalog.py +328 -0
  17. orbitsift/cli.py +2200 -0
  18. orbitsift/config.py +85 -0
  19. orbitsift/confirm.py +1030 -0
  20. orbitsift/data/nsc_dr2_k4m_ksb.csv.gz +0 -0
  21. orbitsift/dense.py +788 -0
  22. orbitsift/dynamics.py +235 -0
  23. orbitsift/expindex.py +456 -0
  24. orbitsift/extend.py +690 -0
  25. orbitsift/external.py +204 -0
  26. orbitsift/extract.py +148 -0
  27. orbitsift/growth.py +224 -0
  28. orbitsift/images.py +676 -0
  29. orbitsift/itf.py +154 -0
  30. orbitsift/known.py +716 -0
  31. orbitsift/link.py +509 -0
  32. orbitsift/lov.py +642 -0
  33. orbitsift/mcp_server.py +164 -0
  34. orbitsift/multiyear.py +409 -0
  35. orbitsift/net.py +265 -0
  36. orbitsift/orbit.py +614 -0
  37. orbitsift/plugins.py +97 -0
  38. orbitsift/precovery.py +187 -0
  39. orbitsift/presets/a2.json +85 -0
  40. orbitsift/presets/confirm_v1.json +190 -0
  41. orbitsift/presets/confirm_v2.json +236 -0
  42. orbitsift/presets/lostrec.json +74 -0
  43. orbitsift/recover.py +377 -0
  44. orbitsift/rubin.py +328 -0
  45. orbitsift/survey.py +268 -0
  46. orbitsift/tiles.py +58 -0
  47. orbitsift/unused.py +103 -0
  48. orbitsift/vet.py +304 -0
  49. orbitsift/workflow/__init__.py +5 -0
  50. orbitsift/workflow/models.py +103 -0
  51. orbitsift/workflow/sqlite.py +189 -0
  52. orbitsift-0.1.0.dist-info/METADATA +443 -0
  53. orbitsift-0.1.0.dist-info/RECORD +56 -0
  54. orbitsift-0.1.0.dist-info/WHEEL +4 -0
  55. orbitsift-0.1.0.dist-info/entry_points.txt +3 -0
  56. orbitsift-0.1.0.dist-info/licenses/LICENSE +28 -0
orbitsift/itf.py ADDED
@@ -0,0 +1,154 @@
1
+ """The MPC Isolated Tracklet File as one more archive (``orbitsift itf``).
2
+
3
+ The ITF holds millions of observations that the MPC could not link to any object: one-night tracklets of every
4
+ station. A candidate's orbit can find its own unlinked tracklets there. Download the file yourself
5
+ (https://www.minorplanetcenter.net/iau/ITF/itf.txt.gz, about 1 GB); ``load`` parses it once (80-column MPC format)
6
+ into one-night tracklets of a station (>= 2 observations over >= 0.15 h, slower than 25"/h) and keeps them as an .npz
7
+ next to it.
8
+
9
+ ``search``: tracklets inside the orbit-clone cloud at their time (95% extent + 120", clouds wider than 1800" are not
10
+ searched), moving like the nearest clone (vector rate within 1.5"/h) and fitting jointly with the arc (rms <= 0.2",
11
+ tracklet residuals <= 0.5"). The same test on the ITF shifted by +-0.25 deg gives the chance level. A hit is a night to
12
+ verify on images (or with a second tracklet), not evidence by itself, and a tracklet of another observer never counts
13
+ as a confirmation of your object.
14
+ """
15
+ import gzip
16
+ import math
17
+ from pathlib import Path
18
+
19
+ import numpy as np
20
+
21
+ from . import orbit
22
+
23
+ CAP = 1800.0 # arcsec
24
+ SHIFTS = ((0.0, 0.0), (0.25, 0.25), (-0.25, -0.25))
25
+
26
+
27
+ def _mjd(y, m, d):
28
+ a = (14 - m) // 12
29
+ yy, mm = y + 4800 - a, m + 12 * a - 3
30
+ return d + (153 * mm + 2) // 5 + 365 * yy + yy // 4 - yy // 100 + yy // 400 - 32045 - 2400001
31
+
32
+
33
+ def load(path, exclude=(), since=2003):
34
+ """Tracklets of the ITF file ``path`` (.txt or .txt.gz): dict(trk, stn, t (MJD of the first point), ra, dec, pts (object array of
35
+ (n, 3) mjd, ra, dec), mag). ``exclude``: trkSubs to leave out (your own submissions are not independent)."""
36
+ path = Path(path)
37
+ npz = path.with_name(path.name.split(".")[0] + "_tracklets.npz")
38
+ if npz.exists() and npz.stat().st_mtime >= path.stat().st_mtime and not exclude:
39
+ z = np.load(npz) # never unpickle a file found next to the input
40
+ if "off" in z.files:
41
+ z = {k: z[k] for k in z.files}
42
+ z["pts"] = _ragged(np.split(z.pop("flat"), z.pop("off")[1:-1]))
43
+ return z
44
+ T = {}
45
+ with (gzip.open(path, "rt", errors="replace") if path.suffix == ".gz" else open(path, errors="replace")) as f:
46
+ for ln in f:
47
+ if len(ln) < 80 or ln[14] not in "CcBVSsX":
48
+ continue
49
+ trk = ln[5:12].strip()
50
+ if not trk or trk in exclude:
51
+ continue
52
+ try:
53
+ y, m, d = int(ln[15:19]), int(ln[20:22]), float(ln[23:32])
54
+ ra = 15 * (float(ln[32:34]) + float(ln[35:37]) / 60 + float(ln[38:44]) / 3600)
55
+ de = (-1 if ln[44] == "-" else 1) * (float(ln[45:47]) + float(ln[48:50]) / 60 + float(ln[51:56]) / 3600)
56
+ except ValueError:
57
+ continue
58
+ if y >= since:
59
+ T.setdefault((trk, ln[77:80]), []).append((_mjd(y, m, d), ra, de, ln[65:71].strip()))
60
+ K, P, M = [], [], []
61
+ for (trk, stn), v in T.items():
62
+ v.sort()
63
+ g = [v[0]]
64
+ for p in v[1:] + [None]:
65
+ if p is None or p[0] - g[-1][0] > 0.5: # one group = one night of one station
66
+ h = (g[-1][0] - g[0][0]) * 24
67
+ if len(g) >= 2 and h >= 0.15:
68
+ cd = math.cos(math.radians(g[0][2]))
69
+ if math.hypot((g[-1][1] - g[0][1]) * cd, g[-1][2] - g[0][2]) * 3600 / h < 25:
70
+ K.append((trk, stn))
71
+ P.append(np.array([q[:3] for q in g]))
72
+ M.append(g[0][3])
73
+ g = []
74
+ if p is not None:
75
+ g.append(p)
76
+ z = dict(trk=np.array([k[0] for k in K], str), stn=np.array([k[1] for k in K], str), t=np.array([p[0, 0] for p in P], float),
77
+ ra=np.array([p[0, 1] for p in P], float), dec=np.array([p[0, 2] for p in P], float), mag=np.array(M, str))
78
+ if not exclude: # ragged points as one array + offsets
79
+ np.savez(npz, **z, flat=np.vstack(P) if P else np.empty((0, 3)), off=np.cumsum([0] + [len(p) for p in P]))
80
+ z["pts"] = _ragged(P)
81
+ return z
82
+
83
+
84
+ def _ragged(parts):
85
+ """Object array of the (n_i, 3) point arrays (a plain assignment would stack equal-length tracklets)."""
86
+ pts = np.empty(len(parts), dtype=object)
87
+ for k, p in enumerate(parts):
88
+ pts[k] = p
89
+ return pts
90
+
91
+
92
+ def _site(stn):
93
+ try:
94
+ orbit.site_constants(stn)
95
+ return stn
96
+ except Exception:
97
+ return "500"
98
+
99
+
100
+ def search(arc, Z, samples=2000, r_min=5.0, r_max=200.0):
101
+ """ITF tracklets ``Z`` (from ``load``) that may be the object of ``arc`` (orbit.Arc). -> dict(hits: [dict(trk, stn, mjd, n,
102
+ mag, rms, res_max, clone_sep, ext, dv)], controls: [number of hits on each shifted ITF], in_cloud, searched, fits,
103
+ unconverged: [trk]). A joint fit that fails (no bound orbit, or an error) is unconverged: that tracklet is undecided, not
104
+ a non-hit (survey, 22 Nov 2026: capped fits had been read as no match)."""
105
+ o = orbit.fit(arc, r_min, r_max)
106
+ if o is None or not len(Z["t"]):
107
+ return dict(hits=[], controls=[0] * (len(SHIFTS) - 1), in_cloud=0, searched=0, fits=0, unconverged=[], orbit=o is not None)
108
+ S = orbit.sample(arc, o, samples)
109
+ T = Z["t"]
110
+ tg = np.linspace(T.min(), T.max(), 300)
111
+ Rg, Dg = orbit.predict(S[::10], o.t0, tg, "500")
112
+ e = np.interp(T, tg, np.array([max(orbit.extent(Rg[:, j], Dg[:, j])) for j in range(len(tg))]))
113
+ R0, D0 = (x[0] for x in orbit.predict(S[:1], o.t0, T, "500"))
114
+ tr, own = np.asarray(arc.mjd, float), set(arc.site)
115
+ res, in_cloud, fits, unconv = [], 0, 0, []
116
+ for si, (sa, sd) in enumerate(SHIFTS):
117
+ dec = Z["dec"] + sd
118
+ cd = np.cos(np.radians(dec))
119
+ sep = np.hypot(((Z["ra"] + sa / cd - R0 + 180) % 360 - 180) * cd, dec - D0) * 3600
120
+ cand = np.flatnonzero((e <= CAP) & (sep < e + 120))
121
+ if si == 0:
122
+ in_cloud = len(cand)
123
+ hits = []
124
+ for k in cand:
125
+ p = np.array(Z["pts"][k], float).copy()
126
+ stn = str(Z["stn"][k])
127
+ if stn in own and np.abs(tr - p[0, 0]).min() < 0.6:
128
+ continue # the same station and night: the same data
129
+ p[:, 2] += sd
130
+ p[:, 1] += sa / math.cos(math.radians(p[0, 2]))
131
+ c0, st = math.cos(math.radians(p[0, 2])), _site(stn)
132
+ Rc, Dc = orbit.predict(S, o.t0, p[[0, -1], 0], st)
133
+ d0 = np.hypot((Rc[:, 0] - p[0, 1]) * c0, Dc[:, 0] - p[0, 2]) * 3600
134
+ b, h = int(np.argmin(d0)), (p[-1, 0] - p[0, 0]) * 24
135
+ dv = math.hypot(((Rc[b, 1] - Rc[b, 0]) - (p[-1, 1] - p[0, 1])) * c0, (Dc[b, 1] - Dc[b, 0]) - (p[-1, 2] - p[0, 2])) * 3600 / h
136
+ if dv > 1.5:
137
+ continue
138
+ fits += si == 0
139
+ try:
140
+ o2 = orbit.fit(arc.extend(list(p[:, 0]), list(p[:, 1]), list(p[:, 2]), [0.15] * len(p), [st] * len(p)), r_min, r_max)
141
+ except Exception:
142
+ o2 = None
143
+ if o2 is None:
144
+ if si == 0:
145
+ unconv.append(str(Z["trk"][k]))
146
+ continue
147
+ rr = np.hypot(*o2.residuals.T)
148
+ rms = float(np.sqrt(np.mean(rr ** 2)))
149
+ if rms <= 0.2 and rr[len(tr):].max() <= 0.5:
150
+ hits.append(dict(trk=str(Z["trk"][k]), stn=stn, mjd=float(p[0, 0]), n=len(p), mag=str(Z["mag"][k]), rms=rms,
151
+ res_max=float(rr[len(tr):].max()), clone_sep=float(d0[b]), ext=float(e[k]), dv=dv))
152
+ res.append(hits)
153
+ return dict(hits=res[0], controls=[len(h) for h in res[1:]], in_cloud=in_cloud, searched=int((e <= CAP).sum()), fits=fits,
154
+ unconverged=unconv, orbit=True)