Metadata-Version: 2.4
Name: star-timescales
Version: 0.2.0
Summary: UTC/TAI/TT offsets from the IERS leap-second table and Julian dates, with explicit validity domains.
License-Expression: Apache-2.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Provides-Extra: crosscheck
Requires-Dist: astropy>=6; extra == "crosscheck"
Dynamic: license-file

# S.T.A.R. — Systems, Testing, Assurance & Reliability

[![tests](https://github.com/Andrea07072000/S.T.A.R.-/actions/workflows/tests.yml/badge.svg)](https://github.com/Andrea07072000/S.T.A.R.-/actions/workflows/tests.yml)
[![packages](https://github.com/Andrea07072000/S.T.A.R.-/actions/workflows/packages.yml/badge.svg)](https://github.com/Andrea07072000/S.T.A.R.-/actions/workflows/packages.yml)

**Website:** [andrea07072000.github.io/S.T.A.R.-](https://andrea07072000.github.io/S.T.A.R.-/) — the packages, the evidence and how to request an engineering assessment.

> **Correction 2026-10-08 (second)** — `star_kepler` 0.1.0 failed with `OverflowError` on hyperbolic orbits
> propagated for long times (first seen: a 20 km/s flyby after 1e6 s); 0.1.1 propagates them (energy conserved to
> 1e-11 up to 1e9 s) and gives the same numbers where 0.1.0 worked. `star_cdm` 0.2.1 `rtn_axes` divided by zero when
> position and velocity are parallel or zero; 0.2.2 refuses with `ValueError`. `star_maneuver` 0.2.1 raised
> `OverflowError` or `TypeError` for inputs beyond 1e100 or that are not numbers; 0.2.2 refuses with `ValueError`.
> Found by calling all 317 public functions of the 70 packages with hostile values; the 57 most recent packages
> showed no leak. Older packages still answer a wrong *type* (for example `None`) with `TypeError`.
>
> **Correction 2026-10-08** — `star_telemetry` up to 0.2.6 could lose or invent a Space Packet when packets span
> frames: a packet ending exactly at the end of a frame with no packet start was lost; after a lost frame, leftover
> data could be delivered as a packet that was never sent; an unfinished packet could be joined to bytes of a later
> frame. 0.2.7 fixes the three (frame header decoding was not affected). If you reassemble packets across frames,
> update. `star_sphere` 0.1.0 was wrong in the sixth digit for separations of 1e-9 degree (and worse below);
> 0.1.1 is right to the last digits. We found both ourselves, the second one after noticing that some of our tests
> compared small numbers with a tolerance that let anything through; three test files were corrected (`star_era`
> 0.1.2, `star_units` 0.1.1, `star_sphere` 0.1.1); the other comparisons of that kind were re-run with a strict
> tolerance and pass, but are still written the loose way in this repository. Seven more packages: anomalies
> and Kepler's equation, CCSDS Space Packets, exact least-squares polynomials, small linear systems, attitude from
> vector observations (TRIAD and Wahba's problem), natural cubic splines and modified Rodrigues parameters.
> 70 packages.
>
> **Correction 2026-10-07 (second update)** — `star_lambert` 0.1.2 accepted some pairs of positions exactly opposite
> each other (a 180-degree transfer, whose plane is not defined) and returned meaningless velocities; 0.1.3 always
> refuses them. If you used 0.1.2 near 180 degrees, update. We found it ourselves after correcting our mutation-testing
> tool, which had been skipping the inner operator of nested expressions; 59 modules have been re-measured so far (the
> rest are being done), `star_era` 0.1.1 adds the tests that the corrected measurement asked for, and `star_elements`
> 0.2.4 no longer returns an angle of exactly 2 pi where 0 was meant. Nine more packages: CCSDS ASCII time
> codes, CRCs of space data links, exact summary statistics, line fit, quantiles and tabulated integrals, attitude
> interpolation, inertial-to-rotating frame, range rate and Doppler. 63 packages in all.
>
> **Update 2026-10-07** — 54 packages in [`packages/`](packages/README.md), all Apache-2.0. Twenty-four new ones:
> map projections (transverse Mercator and UTM, Lambert conic, Albers, Mercator, polar stereographic), sky and
> coordinate frames (ecliptic, galactic, horizon, epochs, sexagesimal angles, separations on the sphere, angle
> reduction), isentropic flow and normal shocks, unit conversion with a dimension check, n-sigma coverage, two-body
> quantities, 3-vectors and 3x3 matrices, and numerics that decide in exact arithmetic (real roots of quadratics and
> cubics, Gauss-Legendre rules, bracketed roots to the last float, Lagrange interpolation, Chebyshev series).
> Each one is compared with independent libraries wherever one exists (its README says where none does),
> mutation-tested, re-tested by GitHub on every push, and its README says what it does *not* claim.

S.T.A.R. is an engineering platform for verification evidence: every requirement is linked to the tests
that check it, and every result can be reproduced. This repository holds its open components. Each one ships
with its requirements, its tests and a reproducible record of its verification.

The rule behind all of it: **a result is either verified, or it says why it is not.** No plausible number
outside a validity domain, no green check without a test that ran.

## First component: `star_timescales`

UTC is not continuous: 27 leap seconds have been added since 1972, and the official table expires. Code that
converts between time scales usually returns the last known offset forever. This library returns the correct
offset inside the table's validity, and **refuses** outside it.

```python
from datetime import datetime, timezone
from star_timescales import tai_minus_utc, tt_minus_utc, julian_date, gps_week_and_seconds

t = datetime(2026, 9, 28, tzinfo=timezone.utc)
tai_minus_utc(t)   # 37        TAI - UTC, seconds (IERS Bulletin C)
tt_minus_utc(t)    # 69.184    TT - UTC, seconds
julian_date(t)     # 2461311.5
gps_week_and_seconds(t)  # (2438, 86418.0)  full GPS week, seconds of week

tai_minus_utc(datetime(2030, 1, 1, tzinfo=timezone.utc))
# LeapSecondTableError: leap-second table valid until 2027-06-28; update it from IERS Bulletin C ...
tai_minus_utc(datetime(2026, 9, 28))
# NaiveDatetimeError: 2026-09-28T00:00:00 has no timezone; pass an aware datetime ...
```

From a terminal, for any instant or for now:

```text
$ python -m star_timescales 2026-09-28T00:00:00Z
instant (UTC)   2026-09-28T00:00:00+00:00
TAI - UTC       37 s
TT - UTC        69.184 s
JD / MJD        2461311.500000 / 61311.000000
GPS - UTC       18 s
GPS week / SOW  2438 / 86418.000000 s
CCSDS CUC       1E 81 4C 0C A5 00 00  (Level 1, P-field 1E: 4+2 octets, TAI since 1958)
table           IERS Bulletin C, Leap_Second.dat (updated through Bulletin 72, July 2026; expires 2027-06-28)
table valid     until 2027-06-28 (N days from today)

$ python -m star_timescales 2030-01-01T00:00:00Z
refused: leap-second table valid until 2027-06-28; update it from IERS Bulletin C before using later epochs
```

### Spacecraft time: GPS weeks and CCSDS time codes

Telemetry is timestamped in TAI-based codes, ground systems think in UTC, navigation in GPS weeks. The same
verified leap-second table drives all three:

```python
from star_timescales import encode_cuc, decode_cuc, cuc_to_utc, gps_week_and_seconds

t = datetime(2026, 9, 28, tzinfo=timezone.utc)
encode_cuc(t).hex(" ").upper()   # '1E 81 4C 0C A5 00 00'  CCSDS CUC Level 1, 4 coarse + 2 fine octets
decode_cuc(encode_cuc(t))        # Fraction(2169244837, 1)  exact TAI seconds since 1958-01-01
cuc_to_utc(encode_cuc(t, fine_octets=3)) == t   # True: exact round trip to the microsecond
gps_week_and_seconds(t)          # (2438, 86418.0)  full week number, not modulo 1024
```

Across the leap second of 2016-12-31 both scales advance by 2 s between UTC 23:59:59 and 00:00:00, as they
must; a code that falls inside 23:59:60 is refused when converted back to UTC, not silently shifted.

Install and test:

```bash
python -m pip install "git+https://github.com/Andrea07072000/S.T.A.R.-"   # the library, no dependencies
git clone https://github.com/Andrea07072000/S.T.A.R.- && cd S.T.A.R.-
python -m pip install pytest pyerfa && python -m pytest                    # 42 tests
```

Python 3.10 to 3.13; tested on Linux, macOS and Windows (see the badge above).

## How it is verified

- **Requirements.** Nine requirements (`TS-REQ-001` to `009`) in [`verification/REQUIREMENTS.md`](verification/REQUIREMENTS.md),
  each linked to the tests that verify it.
- **Primary source.** IERS publishes the Modified Julian Date of every leap-second step. Every calendar date in
  the table, converted by this library, must give exactly the published MJD.
- **Independent implementation.** Results are compared with ERFA, the open implementation of the IAU SOFA
  routines: TAI − UTC one second before, at, and 100 days after every step. The one convention difference
  (ERFA stretches a leap-second day to 86 401 s for Julian dates) is measured and bounded, not hidden.
  CCSDS codes are checked the same way against ERFA's `utctai`, at every leap-second step and at 300 random instants.
- **Published values.** GPS weeks are checked against the week-number rollovers of 1999-08-21T23:59:47Z (week
  1024) and 2019-04-06T23:59:42Z (week 2048); the CUC P-field against the layout of CCSDS 301.0-B-4.
- **Evidence.** `python verification/run_verification.py` regenerates [`verification/evidence/`](verification/evidence/):
  test results, environment and SHA-256 digests. The committed copy records the commit it was produced from.

The first version of the cross-check used a wrong reference and reported an error that was not there. The
account of how that was found is in [`verification/REQUIREMENTS.md`](verification/REQUIREMENTS.md#what-was-found-while-writing-these-tests).

## Status

| | Status |
|---|---|
| `star_timescales` 0.2.0 | Implemented, verified as above |
| Further open components | Published one at a time, only once verified |
| The S.T.A.R. assurance tooling (requirement-to-evidence traceability) | In development, not open source, not in this repository |

## What is not claimed

S.T.A.R. is not affiliated with, endorsed or certified by NASA, ESA, SpaceX, CCSDS, IERS, the IAU or any regulatory or
mission authority; those names appear only to cite public data and algorithms. Nothing here is flight-certified
or a statement of compliance with a standard.

## Sources

Leap seconds: IERS Earth Orientation Centre, Bulletin C, `Leap_Second.dat` (through Bulletin 72, July 2026;
expires 2027-06-28). Julian date: J. Meeus, *Astronomical Algorithms*, reimplemented. CCSDS 301.0-B-4,
*Time Code Formats* (section 3.2, Unsegmented Time Code). GPS time: IS-GPS-200 (GPS = TAI − 19 s).

## Also from this author

[**nightshift-skills**](https://github.com/Andrea07072000/nightshift-skills) — skills for AI coding agents that work
unattended (preflight before overnight runs, honest status reports), each one benchmarked with and without the skill.

## License, security, contributing

[Apache-2.0](LICENSE) · [Security policy](SECURITY.md) · [Contributing](CONTRIBUTING.md) ·
[Changelog](CHANGELOG.md) · Cite: [`CITATION.cff`](CITATION.cff)

Andrea Cavazzini — Info.and.News.S.T.A.R@proton.me
