#!/usr/bin/env python3 """Fetch the public inputs of /metamorphic-novae/ into a folder. Standard library only. Run: python3 -I fetch_public_inputs.py Downloads about 255 MB: eight TESS full-frame cutouts from MAST's TESScut, a Gaia DR3 cone around Gaia22alz, VSX's two records, Aydi et al.'s spectra from their paper's data link, and three arXiv source packages, from which it keeps only the four files our scripts read. No account is needed anywhere. A file already there is not fetched again. TESScut builds its cutouts on request, so a zip's bytes may differ from ours while the fluxes inside are the same; the recorded hashes are listed in inputs_sha256.txt, and the script says which files match. Everything downloaded is read as data. Nothing in it is run. """ import hashlib import io import os import sys import tarfile import time import urllib.parse import urllib.request UA = "factchecked-research/1.0" HERE = os.path.dirname(os.path.abspath(__file__)) RA, DEC = 142.47114, -56.29057 SECTORS = [9, 10, 36, 37, 62, 63, 89, 90] ADQL = ( "SELECT source_id,ra,dec,phot_g_mean_mag,phot_bp_mean_mag,phot_rp_mean_mag,parallax,phot_variable_flag," "DISTANCE(POINT(ra,dec),POINT(142.47114,-56.29057))*3600 AS sep_arcsec FROM gaiadr3.gaia_source " "WHERE DISTANCE(POINT(ra,dec),POINT(142.47114,-56.29057))<2.0/60 AND phot_g_mean_mag IS NOT NULL ORDER BY sep_arcsec" ) TARS = { "2611.05297": ("arxiv-2611.05297", ("f5.eps", "f6.eps")), "2207.02932": ("schaefer2022-periods", ("NovaPeriods_MNRAS.tex",)), "2511.04787": ("schaefer2025-wd-masses", ("Nova_WD_masses_ApJ.tex",)), } def get(url, data=None): req = urllib.request.Request(url, data=data, headers={"User-Agent": UA}) with urllib.request.urlopen(req, timeout=600) as r: return r.read() def save(path, blob): os.makedirs(os.path.dirname(path), exist_ok=True) tmp = path + ".part" with open(tmp, "wb") as fh: fh.write(blob) os.replace(tmp, path) def main(): root = os.path.abspath(sys.argv[1]) for s in SECTORS: path = os.path.join(root, "tess", "cut-s%04d.zip" % s) if not os.path.exists(path): url = "https://mast.stsci.edu/tesscut/api/v0.1/astrocut?ra=%s&dec=%s&y=15&x=15§or=%d" % (RA, DEC, s) print("fetching sector", s, flush=True) save(path, get(url)) time.sleep(2) path = os.path.join(root, "gaia-dr3", "cone-2arcmin.csv") if not os.path.exists(path): body = urllib.parse.urlencode({"REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "csv", "QUERY": ADQL}).encode() print("fetching the Gaia DR3 cone", flush=True) save(path, get("https://gea.esac.esa.int/tap-server/tap/sync", data=body)) for name, ident in (("vsx-gaia22alz.json", "Gaia22alz"), ("vsx-neighbour-EA.json", "ASASSN-V J092955.42-561646.0")): path = os.path.join(root, "vsx", name) if not os.path.exists(path): q = urllib.parse.urlencode({"view": "api.object", "format": "json", "ident": ident}) save(path, get("https://vsx.aavso.org/index.php?" + q)) path = os.path.join(root, "aydi2023-data", "Gaia22alz.zip") if not os.path.exists(path): print("fetching Aydi et al.'s spectra", flush=True) save(path, get("https://www.dropbox.com/s/n2qxklfizgynuok/Gaia22alz.zip?dl=1")) for arxiv, (folder, keep) in TARS.items(): paths = {k: os.path.join(root, folder, "src", k) for k in keep} if all(os.path.exists(p) for p in paths.values()): continue print("fetching the arXiv source of", arxiv, flush=True) blob = get("https://arxiv.org/e-print/" + arxiv) with tarfile.open(fileobj=io.BytesIO(blob), mode="r:*") as tf: for k, path in paths.items(): member = [m for m in tf.getmembers() if os.path.basename(m.name) == k and m.isfile()] if not member: raise SystemExit("no %s in the source of %s" % (k, arxiv)) save(path, tf.extractfile(member[0]).read()) time.sleep(3.2) # say what matches recorded = {} rec = os.path.join(HERE, "inputs_sha256.txt") if os.path.exists(rec): for line in open(rec, encoding="utf-8"): h, _, rel = line.strip().partition(" ") recorded[rel] = h for rel, h in sorted(recorded.items()): p = os.path.join(root, rel) if os.path.exists(p): now = hashlib.sha256(open(p, "rb").read()).hexdigest() print(("same bytes as ours: " if now == h else "different bytes from ours: ") + rel) if __name__ == "__main__": main()