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/catalog.py
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
"""NOIRLab Source Catalog DR2 (NSC DR2) through the Astro Data Lab TAP service (anonymous access).
|
|
2
|
+
|
|
3
|
+
NSC DR2 merges every public DECam (and Mosaic3 / 90Prime) exposure up to late 2019 into objects. A
|
|
4
|
+
slow mover leaves one *single-night* object per night (all its measurements within ``maxdt`` days);
|
|
5
|
+
those "orphans" are the input of the linker. Queries are cached on disk as gzipped CSV, so a tile is
|
|
6
|
+
downloaded once.
|
|
7
|
+
"""
|
|
8
|
+
import csv
|
|
9
|
+
import gzip
|
|
10
|
+
import io
|
|
11
|
+
import os
|
|
12
|
+
import urllib.parse
|
|
13
|
+
import warnings
|
|
14
|
+
from functools import lru_cache
|
|
15
|
+
|
|
16
|
+
import numpy as np
|
|
17
|
+
|
|
18
|
+
from . import config, net
|
|
19
|
+
|
|
20
|
+
TAP_URL = "https://datalab.noirlab.edu/tap/sync"
|
|
21
|
+
# V minus band for a solar-colour reflector (Willmer 2018 solar colours, Jester+2005 V transformation)
|
|
22
|
+
VCOL = {"g": -0.27, "r": 0.17, "i": 0.28, "z": 0.31, "Y": 0.31, "VR": 0.1, "u": -1.2}
|
|
23
|
+
MAG_COLUMNS = {"g": "gmag", "r": "rmag", "i": "imag", "z": "zmag", "Y": "ymag", "VR": "vrmag"}
|
|
24
|
+
STATIONS = {"c4d": "W84", "k4m": "695", "ksb": "V00"} # NSC instruments: DECam, Mosaic3, 90Prime
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def night(mjd):
|
|
28
|
+
"""Integer night label (CTIO nights run ~23-10 UT)."""
|
|
29
|
+
return np.floor(np.asarray(mjd) - 0.5).astype(int)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def tap(query, timeout=None):
|
|
33
|
+
"""Run an ADQL query, return rows as dicts of strings."""
|
|
34
|
+
data = urllib.parse.urlencode({"REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "csv", "QUERY": query}).encode()
|
|
35
|
+
txt = net.fetch(TAP_URL, data, timeout=timeout).decode()
|
|
36
|
+
if txt.lstrip().startswith("<"):
|
|
37
|
+
raise net.ServiceError("TAP error: " + txt[:600])
|
|
38
|
+
return list(csv.DictReader(io.StringIO(txt)))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def cache_path(name):
|
|
42
|
+
"""Where ``cached(name, ...)`` keeps its rows."""
|
|
43
|
+
return config.cache_dir() / "nsc" / f"{name}.csv.gz"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def cached(name, query):
|
|
47
|
+
"""``tap(query)`` cached as <cache>/nsc/<name>.csv.gz (written atomically)."""
|
|
48
|
+
path = cache_path(name)
|
|
49
|
+
if path.exists():
|
|
50
|
+
with gzip.open(path, "rt") as f:
|
|
51
|
+
return list(csv.DictReader(f))
|
|
52
|
+
rows = tap(query)
|
|
53
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
54
|
+
tmp = path.with_name(f"{path.name}.{os.getpid()}.tmp")
|
|
55
|
+
with gzip.open(tmp, "wt", newline="") as f:
|
|
56
|
+
w = csv.DictWriter(f, list(rows[0].keys()) if rows else ["id"])
|
|
57
|
+
w.writeheader()
|
|
58
|
+
w.writerows(rows)
|
|
59
|
+
os.replace(tmp, path)
|
|
60
|
+
return rows
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@lru_cache(maxsize=32)
|
|
64
|
+
def _tile_rows(name, select, where, ra0, dec0):
|
|
65
|
+
rows = cached(f"{name}_{ra0:03d}{dec0:+03d}", f"{select} WHERE 't' = Q3C_RADIAL_QUERY(ra, dec, {ra0 + 0.5}, {dec0 + 0.5}, 0.75) AND "
|
|
66
|
+
f"ra >= {ra0} AND ra < {ra0 + 1} AND dec >= {dec0} AND dec < {dec0 + 1}{where}")
|
|
67
|
+
return rows, np.array([float(r["ra"]) for r in rows]), np.array([float(r["dec"]) for r in rows])
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def near(name, select, ra, dec, h, where=""):
|
|
71
|
+
"""Rows of ``select`` (ADQL 'SELECT ... FROM table' with ra, dec columns; ``where``: ' AND ...' extra cuts) in
|
|
72
|
+
the box |dRA| <= h / cos(dec), |dDec| <= h around (ra, dec). Fetched once per 1 deg tile cell (cached as
|
|
73
|
+
<name>_<tile id>) and cut here: the query names the tile, never (ra, dec)."""
|
|
74
|
+
from .tiles import tiles_in
|
|
75
|
+
hr = h / np.cos(np.radians(min(89.0, abs(dec) + h))) # ponytail: tiles_in walks RA cells, slow near the poles
|
|
76
|
+
out = []
|
|
77
|
+
for t in {t["id"]: t for t in tiles_in(ra - hr, ra + hr, max(-90.0, dec - h), min(90.0, dec + h))}.values():
|
|
78
|
+
rows, a, d = _tile_rows(name, select, where, t["ra0"], t["dec0"])
|
|
79
|
+
k = np.flatnonzero((np.abs((a - ra + 180) % 360 - 180) <= h / np.cos(np.radians(dec))) & (np.abs(d - dec) <= h))
|
|
80
|
+
out += [rows[i] for i in k]
|
|
81
|
+
return out
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _box_where(ra0, ra1, dec0, dec1, prefix=""):
|
|
85
|
+
"""WHERE clause for an RA/Dec box; RA may run below 0 or above 360 (wrap)."""
|
|
86
|
+
c = f"{prefix}ra"
|
|
87
|
+
if ra0 < 0:
|
|
88
|
+
r = f"({c} >= {ra0 + 360} OR {c} <= {ra1})"
|
|
89
|
+
elif ra1 > 360:
|
|
90
|
+
r = f"({c} >= {ra0} OR {c} <= {ra1 - 360})"
|
|
91
|
+
else:
|
|
92
|
+
r = f"{c} BETWEEN {ra0} AND {ra1}"
|
|
93
|
+
return f"{r} AND {prefix}dec BETWEEN {dec0} AND {dec1}"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _tag(box):
|
|
97
|
+
return "_".join(f"{x:.3f}" for x in box)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def orphans_name(box, maxdt=0.6):
|
|
101
|
+
"""Cache name of ``orphans(box, maxdt)``."""
|
|
102
|
+
return f"orphans_{_tag(box)}_{maxdt:g}"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def orphans(box, maxdt=0.6):
|
|
106
|
+
"""NSC DR2 objects in box (ra0, ra1, dec0, dec1) seen on one night only (deltamjd < maxdt), with
|
|
107
|
+
Gaia DR3 and Legacy Survey DR10 counterpart ids (1.5" crossmatch) for the static-source veto."""
|
|
108
|
+
q = ("SELECT o.id, o.ra, o.dec, o.mjd, o.deltamjd, o.ndet, o.gmag, o.rmag, o.imag, o.zmag, o.ymag, o.vrmag, "
|
|
109
|
+
"o.class_star, o.fwhm, o.flags, g.id2 AS gaia, l.id2 AS ls FROM nsc_dr2.object AS o "
|
|
110
|
+
"LEFT JOIN nsc_dr2.x1p5__object__gaia_dr3__gaia_source AS g ON o.id = g.id1 "
|
|
111
|
+
"LEFT JOIN nsc_dr2.x1p5__object__ls_dr10__tractor AS l ON o.id = l.id1 "
|
|
112
|
+
f"WHERE {_box_where(*box, 'o.')} AND o.deltamjd < {maxdt}")
|
|
113
|
+
return cached(orphans_name(box, maxdt), q)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
ORPHAN_FLOATS = ("ra", "dec", "mjd", "deltamjd", "ndet", "gmag", "rmag", "imag", "zmag", "ymag", "vrmag", "class_star",
|
|
117
|
+
"fwhm", "flags")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def orphan_arrays(box, maxdt=0.6):
|
|
121
|
+
"""``orphans`` as columns: dict(id (str array), static (bool: Gaia or Legacy Survey counterpart), and
|
|
122
|
+
the ORPHAN_FLOATS as float64, nan where empty), in row order. The parsed columns are kept as an .npz
|
|
123
|
+
next to the cached CSV (re-made if the CSV changes), so a tile is parsed once."""
|
|
124
|
+
name = orphans_name(box, maxdt)
|
|
125
|
+
path = cache_path(name)
|
|
126
|
+
if not path.exists():
|
|
127
|
+
orphans(box, maxdt)
|
|
128
|
+
st = path.stat()
|
|
129
|
+
stamp = np.array([st.st_size, st.st_mtime_ns], np.int64)
|
|
130
|
+
npz = path.with_name(f"{name}.npz")
|
|
131
|
+
if npz.exists():
|
|
132
|
+
with np.load(npz) as z:
|
|
133
|
+
if np.array_equal(z["stamp"], stamp):
|
|
134
|
+
return {k: z[k] for k in z.files if k != "stamp"}
|
|
135
|
+
out = _parse_orphans(path)
|
|
136
|
+
tmp = npz.with_suffix(f".{os.getpid()}.tmp.npz")
|
|
137
|
+
try: # best effort: the CSV stays the reference
|
|
138
|
+
np.savez(tmp, stamp=stamp, **out)
|
|
139
|
+
os.replace(tmp, npz)
|
|
140
|
+
except OSError:
|
|
141
|
+
pass
|
|
142
|
+
return out
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _parse_orphans(path):
|
|
146
|
+
with gzip.open(path, "rb") as f:
|
|
147
|
+
data = f.read()
|
|
148
|
+
head, _, body = data.partition(b"\n")
|
|
149
|
+
head = next(csv.reader([head.decode()]), [])
|
|
150
|
+
ix = {k: n for n, k in enumerate(head)}
|
|
151
|
+
from . import _native
|
|
152
|
+
r = _native.lib and _native.lib.csv_columns(body, ix["id"], [ix["gaia"], ix["ls"]], [ix[k] for k in ORPHAN_FLOATS])
|
|
153
|
+
if r:
|
|
154
|
+
ids, static, num = r
|
|
155
|
+
return dict(id=np.array(ids, str), static=static, **{k: num[:, j].copy() for j, k in enumerate(ORPHAN_FLOATS)})
|
|
156
|
+
n = len(head)
|
|
157
|
+
rows = [r if len(r) == n else (r + [""] * n)[:n] for r in csv.reader(io.StringIO(body.decode(), newline="")) if r]
|
|
158
|
+
cols = list(zip(*rows)) if rows else [()] * n # as DictReader: blank rows skipped
|
|
159
|
+
num = lambda k: np.array([float(x) if x else np.nan for x in cols[ix[k]]], float)
|
|
160
|
+
return dict(id=np.array(cols[ix["id"]] if rows else [], str),
|
|
161
|
+
static=np.array([bool(a or b) for a, b in zip(cols[ix["gaia"]], cols[ix["ls"]])], bool) if rows
|
|
162
|
+
else np.zeros(0, bool), **{k: num(k) for k in ORPHAN_FLOATS})
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _exposure_box(box, margin):
|
|
166
|
+
ra0, ra1, dec0, dec1 = box
|
|
167
|
+
dm = margin / np.cos(np.radians(min(89.0, max(abs(dec0), abs(dec1)) + margin)))
|
|
168
|
+
b = (ra0 - dm, ra1 + dm, max(-90.0, dec0 - margin), min(90.0, dec1 + margin))
|
|
169
|
+
return (0.0, 360.0, b[2], b[3]) if b[1] - b[0] >= 360 else b
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def exposures_name(box, margin=1.6):
|
|
173
|
+
"""Cache name of ``exposures(box, margin)``."""
|
|
174
|
+
return f"exposures_{_tag(_exposure_box(box, margin))}"
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def exposures(box, margin=1.6):
|
|
178
|
+
"""NSC DR2 DECam exposures whose centre lies within ``margin`` deg of box -> dict of arrays
|
|
179
|
+
(name, mjd = start UTC, ra, dec, filt, exptime, depth = 95% completeness mag, fwhm ["], nmeas)."""
|
|
180
|
+
b = _exposure_box(box, margin)
|
|
181
|
+
q = ("SELECT exposure, mjd, ra, dec, filter, exptime, depth95, fwhm, nmeas FROM nsc_dr2.exposure "
|
|
182
|
+
f"WHERE instrument = 'c4d' AND {_box_where(*b)}")
|
|
183
|
+
rows = cached(exposures_name(box, margin), q)
|
|
184
|
+
g = lambda k: np.array([float(r[k]) if r[k] not in ("", None) else np.nan for r in rows])
|
|
185
|
+
return dict(name=np.array([r["exposure"] for r in rows]), mjd=g("mjd"), ra=g("ra"), dec=g("dec"),
|
|
186
|
+
filt=np.array([r["filter"] for r in rows]), exptime=g("exptime"), depth=g("depth95"),
|
|
187
|
+
fwhm=g("fwhm"), nmeas=g("nmeas"))
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def vlimit(ex):
|
|
191
|
+
"""Per-exposure limiting magnitude converted to V for a solar-colour object."""
|
|
192
|
+
return ex["depth"] + np.array([VCOL.get(f, 0.0) for f in ex["filt"]])
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
MAX_DENSITY = 30000 # detections per deg^2 after the cuts: denser tiles (Galactic plane, bulge) are not linked
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def block_orphans(centre, block, max_density=MAX_DENSITY, left_out=None):
|
|
199
|
+
"""Single-night rows of the tiles in ``block`` (from tiles.block), merged with each id once. A tile with more
|
|
200
|
+
than max_density detections per deg^2 (after the cuts) is left out (its id appended to ``left_out``); if it is
|
|
201
|
+
the centre, nothing is returned."""
|
|
202
|
+
from .tiles import area
|
|
203
|
+
rows, seen = [], set()
|
|
204
|
+
for t in block:
|
|
205
|
+
rr = orphans(t["box"])
|
|
206
|
+
if len(detections(rr)["ra"]) / area(t["box"]) > max_density:
|
|
207
|
+
if left_out is not None:
|
|
208
|
+
left_out.append(t["id"])
|
|
209
|
+
if t["id"] == centre["id"]:
|
|
210
|
+
return []
|
|
211
|
+
continue
|
|
212
|
+
for r in rr:
|
|
213
|
+
if r["id"] not in seen:
|
|
214
|
+
seen.add(r["id"])
|
|
215
|
+
rows.append(r)
|
|
216
|
+
return rows
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
OTHER_RADIUS = {"k4m": 0.45, "ksb": 0.85} # deg: Mosaic3 36' square (half diagonal 0.42), 90Prime 1.16 deg square (0.82)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@lru_cache(maxsize=1)
|
|
223
|
+
def _other_exposures():
|
|
224
|
+
"""NSC DR2 exposures of Mosaic3 (k4m) and 90Prime (ksb), sorted by start, per instrument. Shipped with the package
|
|
225
|
+
(data/nsc_dr2_k4m_ksb.csv.gz: the 71,164 rows of "SELECT instrument, mjd, exptime, ra, dec FROM nsc_dr2.exposure
|
|
226
|
+
WHERE instrument IN ('k4m','ksb')", Data Lab, 27 Nov 2026; DR2 is final), so no query and no network."""
|
|
227
|
+
from importlib.resources import files
|
|
228
|
+
with gzip.open(files(__package__).joinpath("data/nsc_dr2_k4m_ksb.csv.gz").open("rb"), "rt") as f:
|
|
229
|
+
rows = list(csv.DictReader(f))
|
|
230
|
+
out = {}
|
|
231
|
+
for ins in OTHER_RADIUS:
|
|
232
|
+
r = [x for x in rows if x["instrument"] == ins]
|
|
233
|
+
g = lambda k: np.array([float(x[k]) for x in r], float)
|
|
234
|
+
o = np.argsort(g("mjd"))
|
|
235
|
+
out[ins] = (g("mjd")[o], g("exptime")[o] / 86400, np.radians(g("ra")[o]), np.radians(g("dec")[o]))
|
|
236
|
+
return out
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def sites(mjd, ra, dec, tol=2e-4):
|
|
240
|
+
"""MPC station of NSC DR2 single-night rows: 'W84' (DECam) unless the row lies, in time AND on the sky, inside a
|
|
241
|
+
Mosaic3 exposure ('695', Mayall) or a 90Prime one ('V00', Bok): start - tol <= mjd <= start + exptime + tol and the
|
|
242
|
+
exposure centre within OTHER_RADIUS. The object table holds all three instruments; north of Dec +30 a third or more
|
|
243
|
+
of the single-night rows are Kitt Peak ones, whose parallax differs from CTIO's by ~0.2" at 40 au."""
|
|
244
|
+
mjd, ra, dec = (np.atleast_1d(np.asarray(v, float)) for v in (mjd, ra, dec))
|
|
245
|
+
out = np.full(len(mjd), "W84", dtype="<U3")
|
|
246
|
+
if not len(mjd):
|
|
247
|
+
return out
|
|
248
|
+
a, d = np.radians(ra), np.radians(dec)
|
|
249
|
+
for ins, (s, ex, era, edec) in _other_exposures().items():
|
|
250
|
+
if not len(s):
|
|
251
|
+
continue
|
|
252
|
+
j = np.searchsorted(s, mjd + tol, side="right") - 1
|
|
253
|
+
ok = j >= 0
|
|
254
|
+
j = np.clip(j, 0, None)
|
|
255
|
+
ok &= mjd <= s[j] + ex[j] + tol
|
|
256
|
+
ok &= np.sin(d) * np.sin(edec[j]) + np.cos(d) * np.cos(edec[j]) * np.cos(a - era[j]) >= np.cos(np.radians(OTHER_RADIUS[ins]))
|
|
257
|
+
out[ok] = STATIONS[ins]
|
|
258
|
+
return out
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def with_sites(d):
|
|
262
|
+
"""NSC detections (``detections``) plus d["site"], the MPC station of every row (``sites``)."""
|
|
263
|
+
d["site"] = sites(d["mjd"], d["ra"], d["dec"])
|
|
264
|
+
return d
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def clean(rows, fwhm_range=(0.7, 3.0), max_flags=4):
|
|
268
|
+
"""Shape/flag cut against cosmic rays, trails and blends (real TNO detections: fwhm 1.2-2.2", flags 0-3)."""
|
|
269
|
+
f = lambda r, k: float(r[k]) if r[k] else np.nan
|
|
270
|
+
return [r for r in rows if fwhm_range[0] <= f(r, "fwhm") <= fwhm_range[1] and f(r, "flags") < max_flags]
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def detections(rows, veto=True, fwhm_range=(0.7, 3.0)):
|
|
274
|
+
"""Orphan rows -> dict of arrays ra, dec, mjd, V (brightest band converted to V), night, id (and ndet, fwhm, flags,
|
|
275
|
+
bmag = the brightest band magnitude, for ``dense``), after
|
|
276
|
+
``clean`` and (veto=True) dropping objects with a Gaia or Legacy Survey counterpart (static sources).
|
|
277
|
+
veto="lsnd": a Legacy Survey counterpart counts only for objects measured once (ndet = 1): at a multi-exposure
|
|
278
|
+
single-night object it is often the mover itself in the LS coadd (6 of 19 NSC detections of C/2014 UN271).
|
|
279
|
+
fwhm_range: the shape cut of ``clean`` (the default is DECam's; rows of another instrument, cleaned by whoever made
|
|
280
|
+
them: (0, 99)). Rows with an ``exposure`` column keep it as ``exp`` (several detectors exposed at one time)."""
|
|
281
|
+
static = (lambda r: r["gaia"] or (r["ls"] and float(r["ndet"] or 0) <= 1)) if veto == "lsnd" else (lambda r: r["gaia"] or r["ls"])
|
|
282
|
+
keep = [r for r in clean(rows, fwhm_range) if not veto or not static(r)]
|
|
283
|
+
cols = list(MAG_COLUMNS.values())
|
|
284
|
+
m = np.array([[float(r[k]) if r[k] and float(r[k]) < 50 else np.nan for k in cols] for r in keep]).reshape(-1, len(cols))
|
|
285
|
+
off = np.array([VCOL[b] for b in MAG_COLUMNS])
|
|
286
|
+
with np.errstate(all="ignore"), warnings.catch_warnings():
|
|
287
|
+
warnings.simplefilter("ignore", RuntimeWarning) # rows with no magnitude: nan
|
|
288
|
+
V = np.nanmin(m + off, axis=1) if len(m) else np.zeros(0)
|
|
289
|
+
bmag = np.nanmin(m, axis=1) if len(m) else np.zeros(0)
|
|
290
|
+
g = lambda k: np.array([float(r[k]) for r in keep])
|
|
291
|
+
opt = lambda k: np.array([float(r[k]) if r.get(k) else np.nan for r in keep])
|
|
292
|
+
return dict(ra=g("ra"), dec=g("dec"), mjd=g("mjd"), V=V, night=night(g("mjd")), id=np.array([r["id"] for r in keep]),
|
|
293
|
+
ndet=opt("ndet"), fwhm=opt("fwhm"), flags=opt("flags"), bmag=bmag,
|
|
294
|
+
**({"exp": np.array([r["exposure"] for r in keep])} if keep and "exposure" in keep[0] else {}))
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def measurements(object_ids, allow=False):
|
|
298
|
+
"""All nsc_dr2.meas rows (single-exposure measurements) of the given object ids. The query names the ids, i.e. the
|
|
299
|
+
target's detections: only with ``allow`` (``--allow-ids``; designated objects), else net.OutboundBlocked."""
|
|
300
|
+
net.require("ids", allow)
|
|
301
|
+
ids = sorted(set(object_ids))
|
|
302
|
+
rows = []
|
|
303
|
+
for k in range(0, len(ids), 200):
|
|
304
|
+
part = ",".join(f"'{i}'" for i in ids[k:k + 200])
|
|
305
|
+
rows += tap("SELECT objectid, exposure, ccdnum, mjd, ra, dec, raerr, decerr, mag_auto, magerr_auto, filter, "
|
|
306
|
+
f"fwhm, flags FROM nsc_dr2.meas WHERE objectid IN ({part})")
|
|
307
|
+
return rows
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def exptimes(names):
|
|
311
|
+
"""Exposure time [s] of NSC DR2 exposures by name (any instrument)."""
|
|
312
|
+
names = sorted(set(names))
|
|
313
|
+
out = {}
|
|
314
|
+
for k in range(0, len(names), 200):
|
|
315
|
+
part = ",".join(f"'{n}'" for n in names[k:k + 200])
|
|
316
|
+
out.update({r["exposure"]: float(r["exptime"]) for r in tap(f"SELECT exposure, exptime FROM nsc_dr2.exposure WHERE exposure IN ({part})")})
|
|
317
|
+
return out
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def objects_near(ra, dec, radius=1.0):
|
|
321
|
+
"""All NSC DR2 objects within ``radius`` arcsec (box) of (ra, dec). Unless net.OUTBOUND is "exact": from the
|
|
322
|
+
objects of the whole 1 deg tile cell (``near``, cached), so the query never names (ra, dec)."""
|
|
323
|
+
r = radius / 3600
|
|
324
|
+
c = np.cos(np.radians(dec))
|
|
325
|
+
if not net.exact(): # ponytail: a whole cell of nsc_dr2.object (1e5-1e6 rows) per cell, cached once
|
|
326
|
+
return near("nscobj", "SELECT id, ra, dec, mjd, deltamjd, ndet FROM nsc_dr2.object", ra, dec, r)
|
|
327
|
+
return tap(f"SELECT id, ra, dec, mjd, deltamjd, ndet FROM nsc_dr2.object WHERE "
|
|
328
|
+
f"ra BETWEEN {ra - r / c} AND {ra + r / c} AND dec BETWEEN {dec - r} AND {dec + r}")
|