SPB Git

Repository Public

fetch_validation.py 10.5 KB 216 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/ephemeris/fetch_validation.py11# Description      : Queries JPL Horizons for the validation fixtures of12#                    CosmosEphemeris (geometric / LT / LT+S state vectors in13#                    ICRF and ecliptic frames, body orientation quantities) and14#                    stores each raw answer with its exact query. Standard15#                    library only.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_validation.py9596Writes Packages/CosmosEphemeris/Tests/Fixtures/horizons/<name>.txt (raw Horizons answer, unmodified) and97index.json (for each fixture: the exact API parameters and URL, and the metadata the tests need).98These are test fixtures only; they are never used as production data.99"""100import json101import os102import sys103104sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))105import horizons as hz  # noqa: E402106107OUT = os.path.join(hz.ROOT, "Packages", "CosmosEphemeris", "Tests", "Fixtures", "horizons")108109# TDB Julian dates across the DE440s span (1849-12-26 .. 2150-01-22). Values are exactly representable.110DATES = [2396800.5, 2415020.5, 2433282.5, 2440587.5, 2451545.0, 2455197.5, 2460676.5, 2469807.5, 2488069.5, 2506300.5]111# Dates for apparent positions and orientation (subset).112DATES_APPARENT = [2415020.5, 2440587.5, 2451545.0, 2460676.5, 2488069.5]113114NAMES = {0: "ssb", 10: "sun", 1: "mercury-bary", 2: "venus-bary", 3: "emb", 4: "mars-bary", 5: "jupiter-bary",115         6: "saturn-bary", 7: "uranus-bary", 8: "neptune-bary", 9: "pluto-bary", 199: "mercury", 299: "venus",116         399: "earth", 301: "moon", 499: "mars", 599: "jupiter", 699: "saturn", 799: "uranus", 899: "neptune"}117118119def tlist(dates):120    return ",".join("'%.1f'" % d for d in dates)121122123def vector_cases():124    cases = []125    def add(target, center, plane, corr, dates):126        cases.append({"kind": "vectors", "target": target, "center": center, "plane": plane, "corr": corr, "dates": dates})127    for target in (10, 199, 299, 399, 301, 1, 2, 3, 4, 5, 6, 7, 8, 9):128        add(target, 0, "FRAME", "NONE", DATES)129    for target in (399, 4, 5, 301):130        add(target, 10, "ECLIPTIC", "NONE", DATES)131    for target in (301, 10, 4, 5):132        add(target, 399, "FRAME", "NONE", DATES)133    add(301, 399, "ECLIPTIC", "NONE", DATES)134    add(3, 4, "FRAME", "NONE", DATES)       # Earth-Moon barycentre seen from Mars barycentre135    add(399, 301, "FRAME", "NONE", DATES)   # Earth from the Moon136    for target in (10, 301, 4, 5, 8):137        for corr in ("LT", "LT+S"):138            add(target, 399, "FRAME", corr, DATES_APPARENT)139    add(4, 399, "ECLIPTIC", "LT+S", DATES_APPARENT)140    return cases141142143def main():144    os.makedirs(OUT, exist_ok=True)145    index = []146    for c in vector_cases():147        name = "vec_%s_from_%s_%s_%s" % (NAMES[c["target"]], NAMES[c["center"]],148                                         "icrf" if c["plane"] == "FRAME" else "eclip",149                                         c["corr"].lower().replace("+", ""))150        params = hz.vectors_params(str(c["target"]), "500@%d" % c["center"], REF_PLANE=c["plane"],151                                   VEC_CORR=c["corr"], TLIST=tlist(c["dates"]), TLIST_TYPE="JD")152        text = hz.query(params)153        rows = hz.parse_vectors(text)154        if [r[0] for r in rows] != c["dates"]:155            sys.exit("unexpected epochs in " + name)156        with open(os.path.join(OUT, name + ".txt"), "w", encoding="utf-8") as f:157            f.write(text)158        index.append({"name": name, "kind": "vectors", "target": "naif:%d" % c["target"], "center": "naif:%d" % c["center"],159                      "frame": "icrf" if c["plane"] == "FRAME" else "eclipticJ2000", "correction": c["corr"],160                      "units": "km, km/s, s; times are TDB Julian dates", "params": params, "url": hz.build_url(dict(params, format="text"))})161        hz.log("ok", name, len(rows), "rows")162163    # Body orientation: sub-observer longitude/latitude (14), observer range (20), light time (21), north pole RA/Dec (32),164    # seen from the geocentre. Observer tables take TT (not TDB) as input time scale; the tests convert.165    for target in (10, 199, 299, 499, 599, 699, 799, 899, 301, 401, 501, 606, 801):166        name = "obs_%d_from_earth" % target167        params = {168            "COMMAND": hz.quote(str(target)), "OBJ_DATA": hz.quote("NO"), "MAKE_EPHEM": hz.quote("YES"),169            "EPHEM_TYPE": hz.quote("OBSERVER"), "CENTER": hz.quote("500@399"), "QUANTITIES": hz.quote("14,20,21,32"),170            "TLIST": tlist(DATES_APPARENT), "TLIST_TYPE": hz.quote("JD"), "TIME_TYPE": hz.quote("TT"),171            "ANG_FORMAT": hz.quote("DEG"), "EXTRA_PREC": hz.quote("YES"), "CSV_FORMAT": hz.quote("YES"),172            "CAL_FORMAT": hz.quote("JD"),173        }174        text = hz.query(params)175        hz.table_lines(text)176        with open(os.path.join(OUT, name + ".txt"), "w", encoding="utf-8") as f:177            f.write(text)178        index.append({"name": name, "kind": "observer", "target": "naif:%d" % target, "center": "naif:399",179                      "units": "degrees, au, minutes; times are TT Julian dates", "params": params,180                      "url": hz.build_url(dict(params, format="text"))})181        hz.log("ok", name)182183    # Satellite kernel fixture: Tests/Fixtures/spk/mar099s_subset_orixcosmos.bsp is a 24-hour extract (Phobos,184    # Deimos, Mars relative to the Mars barycentre; SPK type 2) of NAIF's mar099s.bsp, produced with185    #   spk_subset.py https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/mar099s.bsp \186    #       Packages/CosmosEphemeris/Tests/Fixtures/spk/mar099s_subset_orixcosmos.bsp 851990400 852076800 401 402 499187    # Horizons uses the same solution (mar099) for these bodies.188    for target, center in ((401, 4), (402, 4), (499, 4), (401, 399), (402, 10)):189        name = "sat_%d_from_%d" % (target, center)190        params = hz.vectors_params(str(target), "500@%d" % center, TLIST=tlist([2461406.25, 2461406.5, 2461406.75]), TLIST_TYPE="JD")191        text = hz.query(params)192        if len(hz.parse_vectors(text)) != 3:193            sys.exit("unexpected row count in " + name)194        with open(os.path.join(OUT, name + ".txt"), "w", encoding="utf-8") as f:195            f.write(text)196        index.append({"name": name, "kind": "vectors-sat", "target": "naif:%d" % target, "center": "naif:%d" % center,197                      "frame": "icrf", "correction": "NONE", "units": "km, km/s, s; times are TDB Julian dates",198                      "params": params, "url": hz.build_url(dict(params, format="text"))})199        hz.log("ok", name)200201    # Merge with entries written by the other pipeline scripts (kinds they own are kept).202    path = os.path.join(OUT, "index.json")203    if os.path.exists(path):204        with open(path) as f:205            old = json.load(f)206        index += [e for e in old["fixtures"] if e["kind"] not in ("vectors", "observer", "vectors-sat")]207    with open(path, "w") as f:208        json.dump({"source": "NASA/JPL Horizons API (https://ssd.jpl.nasa.gov/api/horizons.api)",209                   "note": "Raw answers saved unmodified; test fixtures only.", "fixtures": index}, f, indent=1)210        f.write("\n")211    hz.log("wrote", len(index), "fixtures to", OUT)212213214if __name__ == "__main__":215    main()216
Files main
Menu

Theme