Download build_spacedata.py from STAR-future/Trinity-SpaceData: direct link, hf CLI and curl.
- Browser
- Download file 7.3 kB
-
https://huggingface.co/datasets/STAR-future/Trinity-SpaceData/resolve/main/build_spacedata.py
- Command line
-
hf download hf://datasets/STAR-future/Trinity-SpaceData/build_spacedata.py
-
curl -L -o build_spacedata.py https://huggingface.co/datasets/STAR-future/Trinity-SpaceData/resolve/main/build_spacedata.py
7.3 kB
| """Assemble LittleBoy-SpaceData, the public companion dataset of LittleBoy (founder's decision, 2026-11-19: "dati | |
| spaziali pubblici"), from Space STAR/02_DATA. ONLY sources whose licence allows redistribution are copied; each file | |
| carries its source, licence and SHA-256 in MANIFEST.json, and is checked against the SHA256SUMS of its fetch where one | |
| exists. Sources that may not be redistributed (CelesTrak/Space-Track TLEs, SupGP, Launch Library 2, Gaia DR3 = CC BY-NC, | |
| CCSDS and arXiv documents, the third-party papers in NASA CARA/References) are NOT copied: fetch.py downloads them from | |
| the original provider. Holdout benchmark data is never part of this dataset. | |
| python tools/littleboy/build_spacedata.py --out <stage dir> | |
| """ | |
| import argparse | |
| import hashlib | |
| import json | |
| import shutil | |
| import sys | |
| from pathlib import Path | |
| DATA = Path(__file__).resolve().parents[3] / "Space STAR" / "02_DATA" | |
| # (relative path in 02_DATA, destination folder, licence, attribution) | |
| SOURCES = [ | |
| ("data_003_gcat/currentcat.tsv", "catalogs/gcat", "CC-BY-4.0", "GCAT, J. McDowell, planet4589.org/space/gcat"), | |
| ("data_003_gcat/launchlog.tsv", "catalogs/gcat", "CC-BY-4.0", "GCAT, J. McDowell, planet4589.org/space/gcat"), | |
| ("public_batch_20261003/gcat_launch.tsv", "catalogs/gcat", "CC-BY-4.0", "GCAT, J. McDowell, planet4589.org/space/gcat"), | |
| ("public_batch_20261003/gcat_satcat.tsv", "catalogs/gcat", "CC-BY-4.0", "GCAT, J. McDowell, planet4589.org/space/gcat"), | |
| ("public_batch_20261003/exoplanets_pscomppars.csv", "catalogs/exoplanets", "NASA Exoplanet Archive, public", | |
| "NASA Exoplanet Archive, operated by Caltech under contract with NASA"), | |
| ("public_batch_20261003/sbdb_neo.json", "catalogs/small_bodies", "NASA/JPL public data", "JPL Small-Body Database, NASA/JPL-Caltech"), | |
| ("public_batch_20261003/noaa_f107_monthly.json", "space_weather/noaa", "US Government work, public domain", "NOAA SWPC"), | |
| ("public_batch_20261003/noaa_kp_observed.json", "space_weather/noaa", "US Government work, public domain", "NOAA SWPC"), | |
| ("data_006_space_weather/daily-solar-indices.txt", "space_weather/noaa", "US Government work, public domain", "NOAA SWPC"), | |
| ("data_006_space_weather/xrays-7-day.json", "space_weather/noaa", "US Government work, public domain", "NOAA SWPC (GOES)"), | |
| ("data_007_radiation_belts/differential-electrons-7-day.json", "space_weather/radiation_belts", "US Government work, public domain", "NOAA SWPC (GOES)"), | |
| ("data_007_radiation_belts/differential-protons-7-day.json", "space_weather/radiation_belts", "US Government work, public domain", "NOAA SWPC (GOES)"), | |
| ("data_007_radiation_belts/integral-electrons-7-day.json", "space_weather/radiation_belts", "US Government work, public domain", "NOAA SWPC (GOES)"), | |
| ("data_007_radiation_belts/integral-protons-7-day.json", "space_weather/radiation_belts", "US Government work, public domain", "NOAA SWPC (GOES)"), | |
| ("data_007_radiation_belts/magnetometers-7-day.json", "space_weather/radiation_belts", "US Government work, public domain", "NOAA SWPC (GOES)"), | |
| ("external/nist_acvp/ML-KEM-encapDecap-FIPS203.json", "crypto/nist_acvp", "NIST, public domain", "NIST ACVP test vectors"), | |
| ("external/nist_acvp/ML-KEM-keyGen-FIPS203.json", "crypto/nist_acvp", "NIST, public domain", "NIST ACVP test vectors"), | |
| ] | |
| CARA = ("external/nasa_cara", "conjunction/nasa_cara", "NASA Open Source Agreement (NOSA), see NOSA_*.pdf", | |
| "NASA CARA Analysis Tools", {"DataFiles", "DistributedMatlab", "OpsSystemCapabilities"}, | |
| {"README.md", "NOSA_GSC-18593-1.pdf", "NOSA_GSC-18848-1.pdf", "NOSA_GSC-19027-1.pdf", "NOSA_GSC-19374-1.pdf"}) | |
| KP = "public_batch_20261003/gfz_kp_since_1932.txt" # the SN column is CC BY-NC 4.0 (WDC-SILSO): it is removed | |
| def sha(p: Path) -> str: | |
| h = hashlib.sha256() | |
| with open(p, "rb") as f: | |
| for c in iter(lambda: f.read(1 << 20), b""): | |
| h.update(c) | |
| return h.hexdigest() | |
| def sums_of(folder: Path) -> dict: | |
| f = folder / "SHA256SUMS.txt" | |
| if not f.is_file(): | |
| return {} | |
| return {ln.split()[1].lstrip("*"): ln.split()[0] for ln in f.read_text(encoding="utf-8").splitlines() if ln.strip()} | |
| def kp_without_sn(src: Path, dst: Path) -> None: | |
| """Rewrite the GFZ file without the SN column: data rows lose field 25 (SN, after Ap), the header says so.""" | |
| out = [] | |
| for ln in src.read_text(encoding="utf-8").splitlines(): | |
| if ln.startswith("#"): | |
| if "LICENSE" in ln: | |
| ln = "# LICENSE: CC BY 4.0. Derived by S.T.A.R.: the sunspot number column (CC BY-NC 4.0, WDC-SILSO) has been removed." | |
| elif ln.startswith("#YYY"): | |
| ln = ln.replace(" SN ", " ") | |
| out.append(ln) | |
| continue | |
| f = ln.split() | |
| if len(f) != 28: | |
| raise SystemExit(f"unexpected Kp row with {len(f)} fields: {ln[:60]}") | |
| out.append(" ".join(f[:24] + f[25:])) | |
| dst.write_text("\n".join(out) + "\n", encoding="utf-8", newline="\n") | |
| def main(argv): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--out", required=True) | |
| a = ap.parse_args(argv) | |
| out = Path(a.out) | |
| shutil.rmtree(out, ignore_errors=True) | |
| files = [] | |
| for rel, dest, lic, attr in SOURCES: | |
| src = DATA / rel | |
| expected = sums_of(src.parent).get(src.name) | |
| got = sha(src) | |
| if expected and expected != got: | |
| raise SystemExit(f"{rel}: sha256 {got} differs from its SHA256SUMS {expected}") | |
| d = out / dest / src.name | |
| d.parent.mkdir(parents=True, exist_ok=True) | |
| shutil.copy2(src, d) | |
| files.append({"path": d.relative_to(out).as_posix(), "source": rel, "licence": lic, "attribution": attr, | |
| "sha256": got, "bytes": d.stat().st_size, "checked_against_fetch_sums": bool(expected)}) | |
| kd = out / "space_weather/gfz/kp_ap_f107_since_1932_noSN.txt" | |
| kd.parent.mkdir(parents=True, exist_ok=True) | |
| kp_without_sn(DATA / KP, kd) | |
| files.append({"path": kd.relative_to(out).as_posix(), "source": KP + " (SN column removed)", "licence": "CC-BY-4.0", | |
| "attribution": "Matzka et al., Geomagnetic Kp index, GFZ Data Services, doi:10.5880/Kp.0001", | |
| "sha256": sha(kd), "bytes": kd.stat().st_size, "checked_against_fetch_sums": False}) | |
| rel, dest, lic, attr, dirs, top = CARA | |
| base = DATA / rel | |
| for p in sorted(base.rglob("*")): | |
| r = p.relative_to(base) | |
| if not p.is_file() or r.parts[0] == ".git" or not (r.parts[0] in dirs or (len(r.parts) == 1 and r.name in top)): | |
| continue | |
| d = out / dest / r | |
| d.parent.mkdir(parents=True, exist_ok=True) | |
| shutil.copy2(p, d) | |
| files.append({"path": d.relative_to(out).as_posix(), "source": f"{rel}/{r.as_posix()}", "licence": lic, "attribution": attr, | |
| "sha256": sha(d), "bytes": d.stat().st_size, "checked_against_fetch_sums": False}) | |
| man = {"schema": "star.littleboy.spacedata.v1", "files": len(files), "bytes": sum(f["bytes"] for f in files), "entries": files} | |
| (out / "MANIFEST.json").write_text(json.dumps(man, indent=1) + "\n", encoding="utf-8") | |
| print(json.dumps({"files": man["files"], "bytes": man["bytes"]})) | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main(sys.argv[1:])) | |