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
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""ESO archive: raw VST/OmegaCAM exposures (public raw frames, anonymous download). The raw file (~250 MB) goes
|
|
2
|
+
to a temporary directory; each CCD holding the clones is overscan-subtracted, trimmed and cut, then the raw file
|
|
3
|
+
is deleted. No flat field (it would need calibration frames): the local background of the measurement absorbs
|
|
4
|
+
the large-scale part, pixel-to-pixel response is left in the noise.
|
|
5
|
+
|
|
6
|
+
Older ESO imagers (VLT/VIMOS imaging, 2.2m/WFI, NTT/EMMI), raw frames too: overscan, then the night's bias and flat
|
|
7
|
+
(median of up to 3 public frames each, nearest in time, same filter; from the ESO raw archive), then the WCS: VIMOS has a
|
|
8
|
+
TAN header, WFI and EMMI have none and are solved on Gaia (``gaia_wcs``)."""
|
|
9
|
+
import tempfile
|
|
10
|
+
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
from .. import config, net
|
|
14
|
+
from . import PAD, box, cache, cached_json, stale, write_cut
|
|
15
|
+
|
|
16
|
+
# SSOIS name -> (short name, MPC site, pixel ["] for 15 um pixels unbinned, field radius [deg] for the Gaia solve, TAP instrument prefix)
|
|
17
|
+
OTHER = {"ESO-VLT/VIMOS": ("VIMOS", "309", 0.205, 0.2, "VIMOS"), "ESO-LaSilla_2.2m/WFI": ("WFI", "809", 0.238, 0.35, "WFI"),
|
|
18
|
+
"ESO-NTT/EMMI": ("EMMI", "809", 0.166, 0.15, "EMMI")}
|
|
19
|
+
INSTRUMENTS = ("ESO-VST/OMEGACAM",) + tuple(OTHER)
|
|
20
|
+
SITE = "309"
|
|
21
|
+
TAP = "https://archive.eso.org/tap_obs/sync"
|
|
22
|
+
OTHER_TAP = {v[0]: v[4] for v in OTHER.values()}
|
|
23
|
+
PIX = 0.214
|
|
24
|
+
URL = "https://dataportal.eso.org/dataportal_new/file/"
|
|
25
|
+
DATA, OVERSCAN = (slice(0, 4100), slice(48, 2096)), (slice(0, 4100), slice(2100, 2144)) # raw CCD layout (2144 x 4200)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def exposures(rows, V=None):
|
|
29
|
+
out = {}
|
|
30
|
+
for r in rows:
|
|
31
|
+
if r["Telescope/Instrument"] in INSTRUMENTS and r["Image"].startswith("OMEGA.") and float(r["Exptime"]) >= 30:
|
|
32
|
+
out.setdefault(r["Image"], dict(archive="eso", id=r["Image"], mjd=float(r["MJD"]), exptime=float(r["Exptime"]),
|
|
33
|
+
filt=r["Filter"].split("_")[0].lower(), inst="OmegaCAM", site=SITE))
|
|
34
|
+
elif r["Telescope/Instrument"] in OTHER and float(r["Exptime"]) >= 30:
|
|
35
|
+
short, site = OTHER[r["Telescope/Instrument"]][:2]
|
|
36
|
+
x = out.setdefault((short, round(float(r["MJD"]), 4)), dict(archive="eso", id=r["Image"], mjd=float(r["MJD"]),
|
|
37
|
+
exptime=float(r["Exptime"]), filt=r["Filter"], inst=short,
|
|
38
|
+
site=site, files=[]))
|
|
39
|
+
if r["Image"] not in x["files"]: # VIMOS: one file per quadrant, ms apart
|
|
40
|
+
x["files"].append(r["Image"])
|
|
41
|
+
return list(out.values())
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def tap(q):
|
|
45
|
+
import csv
|
|
46
|
+
import io
|
|
47
|
+
import urllib.parse
|
|
48
|
+
b = net.fetch(TAP, urllib.parse.urlencode(dict(REQUEST="doQuery", LANG="ADQL", FORMAT="csv", QUERY=q)).encode(), timeout=600)
|
|
49
|
+
return list(csv.DictReader(io.StringIO(b.decode())))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def raw_file(dp_id, tmp):
|
|
53
|
+
"""A raw ESO frame downloaded to ``tmp`` (Unix-compressed .Z ones are expanded with gzip) -> path."""
|
|
54
|
+
import subprocess
|
|
55
|
+
b = net.fetch(URL + dp_id, timeout=3000)
|
|
56
|
+
path = f"{tmp}/{dp_id.replace(':', '')}.fits"
|
|
57
|
+
if b[:2] == b"\x1f\x9d":
|
|
58
|
+
b = subprocess.run(["gzip", "-dc"], input=b, capture_output=True, check=True).stdout
|
|
59
|
+
with open(path, "wb") as f:
|
|
60
|
+
f.write(b)
|
|
61
|
+
return path
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def trimmed(e):
|
|
65
|
+
"""Overscan-subtracted, trimmed image of a raw ESO HDU (1 or 2 read-out amplifiers side by side, ESO DET OUTi keys)
|
|
66
|
+
-> (image, x0 of the data in the raw array, saturation)."""
|
|
67
|
+
h, a = e.header, e.data.astype(np.float32)
|
|
68
|
+
k = lambda i, n: int(h.get(f"HIERARCH ESO DET OUT{i} {n}", 0))
|
|
69
|
+
outs = [i for i in (1, 2, 3, 4) if f"HIERARCH ESO DET OUT{i} NX" in h]
|
|
70
|
+
if not any(k(i, "PRSCX") or k(i, "OVSCX") for i in outs): # no over/prescan declared (old EMMI): the bias frame does it
|
|
71
|
+
return a, 0, 65535.0
|
|
72
|
+
W = a.shape[1]
|
|
73
|
+
parts, lev = [], []
|
|
74
|
+
for n, i in enumerate(outs[:2]):
|
|
75
|
+
px, nx, ox, py, ny = k(i, "PRSCX"), k(i, "NX"), k(i, "OVSCX"), k(i, "PRSCY"), k(i, "NY")
|
|
76
|
+
x0 = px if n == 0 else W - px - nx
|
|
77
|
+
bias = (slice(2, px - 2) if px > 6 else slice(px + nx + 2, px + nx + ox - 2)) if n == 0 else \
|
|
78
|
+
(slice(W - px + 2, W - 2) if px > 6 else slice(x0 - ox + 2, x0 - 2))
|
|
79
|
+
ov = np.median(a[py:py + ny, bias], axis=1)[:, None]
|
|
80
|
+
parts.append(a[py:py + ny, x0:x0 + nx] - ov)
|
|
81
|
+
lev.append(float(np.median(ov)))
|
|
82
|
+
x0 = k(outs[0], "PRSCX")
|
|
83
|
+
return np.hstack(parts), x0, 65535.0 - max(lev)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def masters(exp, dp_id, ext, shape):
|
|
87
|
+
"""Bias and normalised flat of one HDU for the night of ``dp_id``: median of up to 3 public raw frames each, nearest
|
|
88
|
+
in time (flats: same filter, twilight ones first; VIMOS: same quadrant). Cached. -> (bias, flat), either None when not found."""
|
|
89
|
+
def make():
|
|
90
|
+
import tempfile as tf
|
|
91
|
+
from astropy.io import fits
|
|
92
|
+
me = tap(f"SELECT filter_path, det_chip1id, mjd_obs, instrument FROM dbo.raw WHERE dp_id = '{dp_id}'")
|
|
93
|
+
if not me:
|
|
94
|
+
return {}
|
|
95
|
+
m, filt, chip = float(me[0]["mjd_obs"]), me[0]["filter_path"], me[0]["det_chip1id"]
|
|
96
|
+
q = (f"SELECT dp_id, dp_type, mjd_obs FROM dbo.raw WHERE instrument LIKE '{OTHER_TAP[exp['inst']]}%' AND dp_tech LIKE 'IMAGE%' "
|
|
97
|
+
f"AND mjd_obs BETWEEN {m - 1} AND {m + 1} AND release_date < '{np.datetime64('today')}' "
|
|
98
|
+
f"AND (dp_type LIKE 'BIAS%' OR (dp_type LIKE '%FLAT%' AND filter_path = '{filt}'))" + (f" AND det_chip1id = '{chip}'" if chip else ""))
|
|
99
|
+
rows = tap(q)
|
|
100
|
+
out = {}
|
|
101
|
+
for kind in ("BIAS", "FLAT"):
|
|
102
|
+
c = sorted((r for r in rows if kind in r["dp_type"]), key=lambda r: ("SKY" not in r["dp_type"], abs(float(r["mjd_obs"]) - m)))[:3]
|
|
103
|
+
stack = []
|
|
104
|
+
with tf.TemporaryDirectory(dir=config.cache_dir()) as tmp:
|
|
105
|
+
for r in c:
|
|
106
|
+
with fits.open(raw_file(r["dp_id"], tmp)) as F:
|
|
107
|
+
hdus = [x for x in F if x.data is not None]
|
|
108
|
+
if len(hdus) > ext:
|
|
109
|
+
img = trimmed(hdus[ext])[0]
|
|
110
|
+
if img.shape == tuple(shape):
|
|
111
|
+
stack.append(img - out["BIAS"] if kind == "FLAT" and "BIAS" in out else img)
|
|
112
|
+
if stack:
|
|
113
|
+
s = np.median(stack, axis=0)
|
|
114
|
+
if kind == "FLAT":
|
|
115
|
+
s = s / np.median(s)
|
|
116
|
+
s[s < 0.2] = np.nan
|
|
117
|
+
out[kind] = s
|
|
118
|
+
return out
|
|
119
|
+
key = cache("eso", "cal", f"{exp['inst']}_{dp_id.replace(':', '')}_{ext}.npz")
|
|
120
|
+
if not key.exists():
|
|
121
|
+
np.savez_compressed(key, **make())
|
|
122
|
+
z = np.load(key)
|
|
123
|
+
return (z["BIAS"] if "BIAS" in z else None), (z["FLAT"] if "FLAT" in z else None)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _fetch_other(exp, pos, outdir):
|
|
127
|
+
from astropy.io import fits
|
|
128
|
+
from astropy.wcs import WCS
|
|
129
|
+
from . import gaia_wcs
|
|
130
|
+
short, site, pix15, radius, _ = next(v for v in OTHER.values() if v[0] == exp["inst"])
|
|
131
|
+
|
|
132
|
+
def cut(fid):
|
|
133
|
+
names = []
|
|
134
|
+
with tempfile.TemporaryDirectory(dir=config.cache_dir()) as tmp:
|
|
135
|
+
with fits.open(raw_file(fid, tmp)) as F:
|
|
136
|
+
h0 = F[0].header
|
|
137
|
+
mid = float(h0["MJD-OBS"]) + float(h0["EXPTIME"]) / 2 / 86400
|
|
138
|
+
ra, dec = pos(mid, site)
|
|
139
|
+
pix = pix15 * float(h0.get("HIERARCH ESO DET CHIP1 PSZX", 15)) / 15 * int(h0.get("HIERARCH ESO DET WIN1 BINX", 1) or 1)
|
|
140
|
+
for n, e in enumerate(x for x in F if x.data is not None):
|
|
141
|
+
img, x0, sat = trimmed(e)
|
|
142
|
+
if "RA" in str(e.header.get("CTYPE1", h0.get("CTYPE1", ""))) and "CD1_2" in (e.header if "CTYPE1" in e.header else h0):
|
|
143
|
+
hw = (e.header if "CTYPE1" in e.header else h0).copy()
|
|
144
|
+
hw["CRPIX1"] = float(hw["CRPIX1"]) - x0
|
|
145
|
+
hw["CRPIX2"] = float(hw["CRPIX2"]) - int(e.header.get("HIERARCH ESO DET OUT1 PRSCY", 0))
|
|
146
|
+
else:
|
|
147
|
+
hw = gaia_wcs(img, float(h0["RA"]), float(h0["DEC"]), pix, float(h0["MJD-OBS"]), radius)
|
|
148
|
+
if hw is None:
|
|
149
|
+
continue
|
|
150
|
+
w = WCS(hw, naxis=2)
|
|
151
|
+
b = box(w, img.shape[1], img.shape[0], ra, dec, PAD / pix)
|
|
152
|
+
if b is None:
|
|
153
|
+
continue
|
|
154
|
+
bias, flat = masters(exp, fid, n, img.shape)
|
|
155
|
+
img = img - bias if bias is not None else img
|
|
156
|
+
img = img / flat if flat is not None else img
|
|
157
|
+
name = f"{short.lower()}_{fid.split('.', 1)[1].replace(':', '').replace('-', '')}_{n}.fits.fz"
|
|
158
|
+
write_cut(outdir / name, img[b[1]:b[3], b[0]:b[2]], hw, mid, h0["EXPTIME"], exp["filt"], site, short,
|
|
159
|
+
f"{fid}[{n}]" + ("" if flat is not None else " noflat"), b[0], b[1], saturate=sat)
|
|
160
|
+
names.append(name)
|
|
161
|
+
return names
|
|
162
|
+
out = []
|
|
163
|
+
ra, dec = pos(exp["mjd"] + exp["exptime"] / 2 / 86400, site)
|
|
164
|
+
for fid in exp["files"]:
|
|
165
|
+
key = cache("eso", fid.replace(":", "") + ".json")
|
|
166
|
+
names = cached_json(key, lambda: cut(fid))
|
|
167
|
+
if names and all(stale(outdir / n, ra, dec, PAD / pix15) for n in names):
|
|
168
|
+
key.unlink()
|
|
169
|
+
names = cached_json(key, lambda: cut(fid))
|
|
170
|
+
out += [outdir / n for n in names]
|
|
171
|
+
return out
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def fetch(exp, pos, outdir):
|
|
175
|
+
if exp["inst"] != "OmegaCAM":
|
|
176
|
+
return _fetch_other(exp, pos, outdir)
|
|
177
|
+
from astropy.io import fits
|
|
178
|
+
from astropy.wcs import WCS
|
|
179
|
+
|
|
180
|
+
def cut():
|
|
181
|
+
names = []
|
|
182
|
+
with tempfile.TemporaryDirectory(dir=config.cache_dir()) as tmp:
|
|
183
|
+
raw = f"{tmp}/raw.fits"
|
|
184
|
+
with open(raw, "wb") as f:
|
|
185
|
+
f.write(net.fetch(URL + exp["id"], timeout=3000))
|
|
186
|
+
with fits.open(raw) as F:
|
|
187
|
+
h0 = F[0].header
|
|
188
|
+
mid = float(h0["MJD-OBS"]) + float(h0["EXPTIME"]) / 2 / 86400
|
|
189
|
+
ra, dec = pos(mid, SITE)
|
|
190
|
+
for e in F[1:]:
|
|
191
|
+
if e.data is None or "CRVAL1" not in e.header:
|
|
192
|
+
continue
|
|
193
|
+
h = e.header.copy()
|
|
194
|
+
h["CRPIX1"] = float(h["CRPIX1"]) - DATA[1].start
|
|
195
|
+
b = box(WCS(h, naxis=2), 2048, 4100, ra, dec, PAD / PIX)
|
|
196
|
+
if b is None:
|
|
197
|
+
continue
|
|
198
|
+
a = e.data.astype(np.float32)
|
|
199
|
+
ov = np.median(a[OVERSCAN], axis=1)[:, None]
|
|
200
|
+
img = (a[DATA] - ov)[b[1]:b[3], b[0]:b[2]]
|
|
201
|
+
chip = str(h.get("EXTNAME", len(names))).split("#")[-1]
|
|
202
|
+
name = f"vst_{exp['id'][6:].replace(':', '').replace('-', '')}_{chip}.fits.fz"
|
|
203
|
+
write_cut(outdir / name, img, h, mid, h0["EXPTIME"], exp["filt"], SITE, "OmegaCAM", f"{exp['id']}[{chip}]",
|
|
204
|
+
b[0], b[1], saturate=60000.0 - float(np.median(ov)))
|
|
205
|
+
names.append(name)
|
|
206
|
+
return names
|
|
207
|
+
key = cache("eso", exp["id"].replace(":", "") + ".json")
|
|
208
|
+
names = cached_json(key, cut)
|
|
209
|
+
ra, dec = pos(exp["mjd"] + exp["exptime"] / 2 / 86400, SITE)
|
|
210
|
+
if names and all(stale(outdir / n, ra, dec, PAD / PIX) for n in names): # all deleted since, or another object's boxes: cut again
|
|
211
|
+
key.unlink()
|
|
212
|
+
names = cached_json(key, cut)
|
|
213
|
+
return [outdir / n for n in names]
|