#!/usr/bin/env python3 """Download every raw input used by the fp_kiii study into RAW (re-runnable; cached). Sources * 6dFGSv Fundamental Plane data, Campbell et al. 2014 (VizieR J/MNRAS/443/1231) * SDSS PV catalogue, Howlett et al. 2022 (Zenodo record 6824749) * SDSS DR17 SkyServer SQL: our own, un-clipped early-type parent sample """ import os import sys import time import urllib.parse import urllib.request RAW = os.environ.get("FP_KIII_RAW", "fermi_raw/fp_kiii") VIZ = "https://tapvizier.cds.unistra.fr/TAPVizieR/tap/sync" SKY = "https://skyserver.sdss.org/dr17/SkyServerWS/SearchTools/SqlSearch" def fetch(url, dest, data=None, timeout=900, tries=8, min_bytes=50): if os.path.exists(dest) and os.path.getsize(dest) >= min_bytes: return dest os.makedirs(os.path.dirname(dest), exist_ok=True) last = None for k in range(tries): try: req = urllib.request.Request(url, data=data) with urllib.request.urlopen(req, timeout=timeout) as r: blob = r.read() if len(blob) < min_bytes or blob[:1] == b"{" or b" 50 AND p.fracDeV_r >= 0.5 AND s.ra >= {lo} AND s.ra < {hi} """ def sdss_chunks(step=4): out = [] for lo in range(0, 360, step): dest = os.path.join(RAW, "sdss_own", "sdss_etg_ra%03d_%03d.csv" % (lo, lo + step)) sql = " ".join(SDSS_SQL.format(lo=lo, hi=lo + step).split()) url = SKY + "?" + urllib.parse.urlencode({"cmd": sql, "format": "csv"}) # an empty RA slice returns only the header (~900 bytes) which is fine fetch(url, dest, timeout=900, min_bytes=100) out.append(dest) print(" sdss chunk", lo, os.path.getsize(dest), flush=True) return out def main(): for t in ("FPsample", "table2", "table9"): vizier("J/MNRAS/443/1231/" + t, os.path.join(RAW, "6df_%s.csv" % t)) print("6dFGSv tables ok", flush=True) for f in ("SDSS_PV_public.dat", "data_description.pdf"): fetch("https://zenodo.org/api/records/6824749/files/%s/content" % f, os.path.join(RAW, "sdss_pv", f)) print("SDSS PV (Howlett 2022) ok", flush=True) sdss_chunks() print("SDSS DR17 own sample ok", flush=True) if __name__ == "__main__": sys.exit(main())