SPB Git

Repository Public

finalize.py 7.5 KB 158 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/finalize.py11# Description      : Writes manifest.json of every catalogue pack from its12#                    draft (pack.json) and the files present: sizes, SHA-256,13#                    roles. Run after the builders and again after the Swift14#                    step that adds the octree.15# Module           : DataPipeline16# Repository       : https://git.spboucher.ai/orix-cosmos17# Project Website  : https://www.orixlab.dev18# Created          : 2026-11-2419# Last Modified    : 2026-11-2420#21# =============================================================================22# AUTHOR & PROFESSIONAL AFFILIATION23# =============================================================================24#25# Author           : Simon-Pierre Boucher26# Position         : Professor of Finance27# Institution      : Université du Québec en Outaouais (UQO)28# Department       : Département des sciences administratives29# Organization     : SP Boucher30#31# Website          : https://spboucher.ai32# Git              : https://git.spboucher.ai33#34# =============================================================================35# OFFICIAL CONTACT DIRECTORY36# =============================================================================37#38# General          : info@spboucher.ai39# Professional     : contact@spboucher.ai40# Direct           : simon@spboucher.ai41# Research         : research@spboucher.ai42# Development      : dev@spboucher.ai43# Support          : support@spboucher.ai44# Security/Admin   : admin@spboucher.ai45# Notifications    : notifications@spboucher.ai46#47# Preferred Contact: support@spboucher.ai48#49# =============================================================================50# COPYRIGHT & INTELLECTUAL PROPERTY51# =============================================================================52#53# Copyright (c) 202654# Simon-Pierre Boucher55#56# All rights reserved where applicable.57#58# This file is governed by the applicable project license,59# copyright notices, institutional agreements and relevant law.60#61# Unless expressly authorized by the applicable license or62# rights holder, copying, redistribution, sublicensing,63# publication and commercial exploitation are not permitted.64#65# Existing third-party rights and notices remain unaffected.66#67# =============================================================================68# CONFIDENTIALITY & SECURITY69# =============================================================================70#71# Classification   : Public72# Distribution     : Public repository; use is governed by the project license73# Security Contact : admin@spboucher.ai74#75# Access to this source does not independently grant permission76# to redistribute or disclose confidential materials.77#78# Do not embed credentials, private keys, access tokens,79# certificates or confidential personal information.80#81# =============================================================================82# LICENSE & MAINTENANCE83# =============================================================================84#85# License          : None specified (no license file in this repository)86# Maintainer       : Simon-Pierre Boucher87# Technical Contact: dev@spboucher.ai88#89# =============================================================================90# END OF SP BOUCHER SOURCE HEADER91# =============================================================================9293"""Usage: finalize.py [--out DIR]"""94import json95import os96import sys9798from common import PACKS, log99from store import write_manifest100101FILES = [("catalog.sqlite", "catalog-db", "SQLite store: objects, designations, typed records, provenance (schema version 1, no WAL)"),102         ("stars.bin", "star-file", "Binary star catalogue: 112-byte records in sky tiles by magnitude band, HIP and Gaia DR3 identifier indices (format version 1)"),103         ("octree.bin", "octree", "3D level-of-detail octree of the stars that have a distance: barycentric ICRF positions at J2016.0 in metres, brightness = -absolute magnitude, payload = record index in stars.bin (format version 1)")]104105106TITLES_FR = {107    "starter": "Catalogue de départ : étoiles brillantes, nommées et proches, constellations, objets Messier et NGC/IC brillants",108    "stars-hipparcos": "Étoiles Hipparcos (nouvelle réduction, 117 955 étoiles) avec identification croisée Gaia DR3",109    "stars-gaia-nearby": "Catalogue Gaia des étoiles proches (100 pc, 331 312 étoiles)",110    "stars-gaia-g10": "Étoiles Gaia DR3 jusqu'à G = 10",111    "stars-gaia-g12": "Étoiles Gaia DR3, 10 < G <= 12",112    "exoplanets": "Exoplanètes confirmées et leurs étoiles hôtes (NASA Exoplanet Archive)",113    "exoplanet-candidates": "Objets d'intérêt TESS (candidats, pas des planètes confirmées)",114    "deep-sky": "Objets NGC, IC et Messier (OpenNGC)",115    "galaxies": "Galaxies naines du Groupe local et de son voisinage (McConnachie 2012) et amas riches d'Abell/ACO",116    "galaxies-2mrs": "Relevé de décalages vers le rouge 2MASS (Huchra et al. 2012) : 43 533 galaxies",117    "satellites": "Satellites artificiels : éléments orbitaux GP (instantané CelesTrak)",118    "minor-bodies": "Petits corps : astéroïdes numérotés avec H <= 10 et comètes périodiques numérotées (JPL SBDB)",119}120121122def main(argv):123    out_dir = argv[argv.index("--out") + 1] if "--out" in argv else PACKS124    done = 0125    for name in sorted(os.listdir(out_dir)):126        pack_dir = os.path.join(out_dir, name)127        draft_path, manifest_path = os.path.join(pack_dir, "pack.json"), os.path.join(pack_dir, "manifest.json")128        if os.path.exists(draft_path):129            with open(draft_path, encoding="utf-8") as f:130                d = json.load(f)131            title, licence = d["title"], d["licence"]132            r = d["redistribution"]133            redistribution = (r["allowed"], r["statement"]) if isinstance(r, dict) else tuple(r)134        elif os.path.exists(manifest_path):135            with open(manifest_path, encoding="utf-8") as f:136                d = json.load(f)137            if "redistributionTerms" not in d or d.get("id") not in TITLES_FR:138                continue  # not one of the catalogue packs built here139            title, licence = d["title"]["en"], d["license"]140            redistribution = (d["redistributionTerms"]["class"], d["redistributionTerms"]["statement"])141        else:142            continue143        files = [f for f in FILES if os.path.exists(os.path.join(pack_dir, f[0]))]144        content = d["coverage"].get("content") or d["coverage"].get("limit") or d["coverage"].get("stars") or title145        m = write_manifest(pack_dir, d["id"], title, d["version"], d["retrieved"], licence, d["acknowledgement"],146                           redistribution, files, d["sources"], d["counts"], d["coverage"], d.get("starFlag"),147                           title_fr=TITLES_FR.get(d["id"]), description={"en": content})148        if os.path.exists(draft_path):149            os.remove(draft_path)150        log("manifest %s: %d files, %.1f MB, redistribution: %s (%s)" % (d["id"], len(files), m["installedSize"] / 1e6, m["redistribution"], redistribution[0]))151        done += 1152    if not done:153        sys.exit("no catalogue pack found in " + out_dir)154155156if __name__ == "__main__":157    main(sys.argv)158
Files main
Menu

Theme