SPB Git

Repository Public

fetch_sources.py 10.6 KB 237 lines python

1#!/usr/bin/env python32# =============================================================================3#                  SP BOUCHER | SOFTWARE & RESEARCH4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project          : ORIX Cosmos10# File             : DataPipeline/catalogs/fetch_sources.py11# Description      : Adapters for the non-Gaia sources of the catalogue packs12#                    (IAU star names, cross-identifications, constellations,13#                    OpenNGC, NASA Exoplanet Archive, 2MRS, Local Group, Abell,14#                    JPL SBDB, CelesTrak). One cached download per file; every15#                    answer is checked before use by the builders.16# Module           : DataPipeline17# Repository       : https://git.spboucher.ai/orix-cosmos18# Project Website  : https://www.orixlab.dev19# Created          : 2026-11-2420# Last Modified    : 2026-11-2421#22# =============================================================================23# AUTHOR & PROFESSIONAL AFFILIATION24# =============================================================================25#26# Author           : Simon-Pierre Boucher27# Position         : Professor of Finance28# Institution      : Université du Québec en Outaouais (UQO)29# Department       : Département des sciences administratives30# Organization     : SP Boucher31#32# Website          : https://spboucher.ai33# Git              : https://git.spboucher.ai34#35# =============================================================================36# OFFICIAL CONTACT DIRECTORY37# =============================================================================38#39# General          : info@spboucher.ai40# Professional     : contact@spboucher.ai41# Direct           : simon@spboucher.ai42# Research         : research@spboucher.ai43# Development      : dev@spboucher.ai44# Support          : support@spboucher.ai45# Security/Admin   : admin@spboucher.ai46# Notifications    : notifications@spboucher.ai47#48# Preferred Contact: support@spboucher.ai49#50# =============================================================================51# COPYRIGHT & INTELLECTUAL PROPERTY52# =============================================================================53#54# Copyright (c) 202655# Simon-Pierre Boucher56#57# All rights reserved where applicable.58#59# This file is governed by the applicable project license,60# copyright notices, institutional agreements and relevant law.61#62# Unless expressly authorized by the applicable license or63# rights holder, copying, redistribution, sublicensing,64# publication and commercial exploitation are not permitted.65#66# Existing third-party rights and notices remain unaffected.67#68# =============================================================================69# CONFIDENTIALITY & SECURITY70# =============================================================================71#72# Classification   : Public73# Distribution     : Public repository; use is governed by the project license74# Security Contact : admin@spboucher.ai75#76# Access to this source does not independently grant permission77# to redistribute or disclose confidential materials.78#79# Do not embed credentials, private keys, access tokens,80# certificates or confidential personal information.81#82# =============================================================================83# LICENSE & MAINTENANCE84# =============================================================================85#86# License          : None specified (no license file in this repository)87# Maintainer       : Simon-Pierre Boucher88# Technical Contact: dev@spboucher.ai89#90# =============================================================================91# END OF SP BOUCHER SOURCE HEADER92# =============================================================================9394"""Usage: fetch_sources.py all | <source> [<source> ...]9596Sources: names crossid constellations openngc exoplanets twomrs localgroup abell sbdb satellites97Each download happens once (cache under DataPipeline/raw/catalogs/); delete a cached file to refresh it.98CelesTrak asks for at most one download per data update (2 h) and no retry on HTTP 301/403/404: the cache and99`fetch(..., stop_on=...)` enforce both.100"""101import json102import sys103import time104import urllib.parse105106from common import fetch, log107108OPENNGC_TAG = "v20260501"109STELLARIUM_TAG = "v26.3"110CFA = "https://vizier.cfa.harvard.edu/ftp/cats"  # official VizieR mirror (CDS Strasbourg was unavailable on 2026-11-24)111NEA_TAP = "https://exoplanetarchive.ipac.caltech.edu/TAP/sync"112113# Planet/host columns kept from pscomppars. For each measured quantity q the archive provides q, qerr1 (+),114# qerr2 (−), qlim (−1 lower limit, 0 value, 1 upper limit) and q_reflink.115NEA_MEASURED = ["pl_orbper", "pl_orbsmax", "pl_orbeccen", "pl_orbincl", "pl_orblper", "pl_orbtper", "pl_tranmid",116                "pl_rade", "pl_radj", "pl_bmasse", "pl_bmassj", "pl_dens", "pl_eqt", "pl_insol", "pl_trandep",117                "pl_trandur", "pl_rvamp", "st_teff", "st_rad", "st_mass", "st_met", "st_logg", "st_lum", "st_age",118                "st_radv", "st_rotp"]119NEA_PLAIN = ["pl_name", "hostname", "pl_letter", "hd_name", "hip_name", "tic_id", "gaia_dr2_id", "gaia_dr3_id",120             "sy_snum", "sy_pnum", "cb_flag", "discoverymethod", "disc_year", "disc_refname", "disc_facility",121             "pl_controv_flag", "pl_bmassprov", "st_spectype", "ra", "dec",122             "sy_dist", "sy_disterr1", "sy_disterr2", "sy_plx", "sy_plxerr1", "sy_plxerr2",123             "sy_pmra", "sy_pmraerr1", "sy_pmdec", "sy_pmdecerr1",124             "sy_vmag", "sy_vmagerr1", "sy_gaiamag", "sy_gaiamagerr1", "sy_kmag", "sy_kmagerr1"]125126127def nea_columns():128    cols = list(NEA_PLAIN)129    for q in NEA_MEASURED:130        cols += [q, q + "err1", q + "err2", q + "lim", q + "_reflink"]131    return cols132133134TOI_COLUMNS = ["tid", "toi", "tfopwg_disp", "ra", "dec", "st_tmag", "st_tmagerr1", "pl_orbper", "pl_orbpererr1",135               "pl_tranmid", "pl_tranmiderr1", "pl_trandurh", "pl_trandurherr1", "pl_trandep", "pl_trandeperr1",136               "pl_rade", "pl_radeerr1", "pl_insol", "pl_eqt", "st_dist", "st_disterr1", "st_teff", "st_tefferr1",137               "st_rad", "st_raderr1", "st_pmra", "st_pmdec", "toi_created", "rowupdate"]138139SBDB_FIELDS = "spkid,full_name,pdes,name,prefix,kind,class,H,G,M1,K1,diameter,albedo,rot_per,GM,epoch,e,a,q,i,om,w,ma,tp,per,n,orbit_id,condition_code,sigma_e,sigma_a,sigma_i"140CELESTRAK_GROUPS = ["stations", "visual", "gnss", "geo"]141142143def do_names():144    fetch("iau", "IAU-CSN.txt", "https://www.pas.rochester.edu/~emamajek/WGSN/IAU-CSN.txt")145146147def do_crossid():148    # HYG v4.1 (CC BY-SA 4.0): used only for cross-identifications (HR, Bayer, Flamsteed, Gliese), not for astrometry149    base = "https://raw.githubusercontent.com/astronexus/HYG-Database/main/"150    fetch("hyg", "hygdata_v41.csv", base + "hyg/CURRENT/hygdata_v41.csv")151    fetch("hyg", "LICENSE", base + "LICENSE")152    fetch("hyg", "README.md", base + "README.md")153154155def do_constellations():156    # VizieR VI/49 (Davenhall & Leggett 1989), J2000 boundary points: used only to validate our own precession of157    # the B1875 edges, never copied into a pack (the CDS rules-of-usage page was unavailable on 2026-11-24)158    fetch("vizier", "VI_49_ReadMe", CFA + "/VI/49/ReadMe")159    fetch("vizier", "VI_49_bound_20.dat.gz", CFA + "/VI/49/bound_20.dat.gz")160    base = "https://raw.githubusercontent.com/Stellarium/stellarium/%s/skycultures/modern/" % STELLARIUM_TAG161    fetch("stellarium", "modern_index_%s.json" % STELLARIUM_TAG, base + "index.json")162    fetch("stellarium", "modern_description_%s.md" % STELLARIUM_TAG, base + "description.md")163164165def do_openngc():166    base = "https://raw.githubusercontent.com/mattiaverga/OpenNGC/%s/" % OPENNGC_TAG167    fetch("openngc", "NGC_%s.csv" % OPENNGC_TAG, base + "database_files/NGC.csv")168    fetch("openngc", "addendum_%s.csv" % OPENNGC_TAG, base + "database_files/addendum.csv")169    fetch("openngc", "CC-BY-SA-4.0_%s.txt" % OPENNGC_TAG, base + "LICENSES/CC-BY-SA-4.0.txt")170    fetch("openngc", "NGC_guide_%s.txt" % OPENNGC_TAG, base + "NGC_guide.txt")171    fetch("openngc", "README_%s.md" % OPENNGC_TAG, base + "README.md")172173174def do_exoplanets():175    q = "select " + ",".join(nea_columns()) + " from pscomppars"176    fetch("nea", "pscomppars.csv", NEA_TAP + "?" + urllib.parse.urlencode({"query": q, "format": "csv"}))177    q = "select " + ",".join(TOI_COLUMNS) + " from toi"178    fetch("nea", "toi.csv", NEA_TAP + "?" + urllib.parse.urlencode({"query": q, "format": "csv"}))179180181def do_twomrs():182    fetch("2mrs", "2mrs_readme.html", "http://tdc-www.harvard.edu/2mrs/2mrs_readme.html")183    fetch("2mrs", "2mrs_v240.tgz", "http://tdc-www.harvard.edu/2mrs/2mrs_v240.tgz")184185186def do_localgroup():187    base = "https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/files/vault/PANDAS/NearbyGals/"188    fetch("localgroup", "NearbyGalaxies_Jan2021_PUBLIC.fits", base + "NearbyGalaxies_Jan2021_PUBLIC.fits")189    fetch("localgroup", "References.dat", base + "References.dat")190    fetch("localgroup", "Update.log", base + "Update.log")191192193def do_abell():194    fetch("vizier", "VII_110A_ReadMe", CFA + "/VII/110A/ReadMe")195    fetch("vizier", "VII_110A_table3.dat.gz", CFA + "/VII/110A/table3.dat.gz")196    fetch("vizier", "VII_110A_table4.dat.gz", CFA + "/VII/110A/table4.dat.gz")197198199def do_sbdb():200    api = "https://ssd-api.jpl.nasa.gov/sbdb_query.api?"201    common = {"fields": SBDB_FIELDS, "full-prec": "true", "sb-ns": "n"}202    a = dict(common, **{"sb-kind": "a", "sb-cdata": json.dumps({"AND": ["H|LE|10"]}, separators=(",", ":"))})203    fetch("sbdb", "asteroids_numbered_H10.json", api + urllib.parse.urlencode(a))204    time.sleep(1)205    c = dict(common, **{"sb-kind": "c"})206    fetch("sbdb", "comets_numbered.json", api + urllib.parse.urlencode(c))207208209def do_satellites():210    for group in CELESTRAK_GROUPS:211        fetch("celestrak", "gp_%s.json" % group,212              "https://celestrak.org/NORAD/elements/gp.php?GROUP=%s&FORMAT=json" % group, retries=1,213              stop_on=(301, 400, 403, 404, 500))214        time.sleep(2)215216217SOURCES = {"names": do_names, "crossid": do_crossid, "constellations": do_constellations, "openngc": do_openngc,218           "exoplanets": do_exoplanets, "twomrs": do_twomrs, "localgroup": do_localgroup, "abell": do_abell,219           "sbdb": do_sbdb, "satellites": do_satellites}220221222def main(argv):223    names = argv[1:]224    if not names:225        sys.exit(__doc__)226    if names == ["all"]:227        names = list(SOURCES)228    for n in names:229        if n not in SOURCES:230            sys.exit("unknown source %r\n%s" % (n, __doc__))231        log("== source", n)232        SOURCES[n]()233234235if __name__ == "__main__":236    main(sys.argv)237
Files main
Menu

Theme