Skip to content
stone edited this page Nov 13, 2026 · 3 revisions

Spacecraft clocks (SCLK)

Support covers type 1 clocks only. The model follows the NAIF SCLK Required Reading.

Fields and ticks

A type-1 clock is a series of cascading integer counters. For a kernel with n fields, moduli m[i] and offsets o[i], the encoded tick count is

ticks = sum over i of (field[i] - o[i]) * product(m[i+1..n])

o[i] is the first displayed value of field i. This matters for clocks such as Voyager, whose third field is offset by 1: the displayed count 1 encodes as tick 0.

kernel.ticks_from_fields(&[0, 0, 1])?; // 0.0
kernel.fields_from_ticks(0.0)?;        // [0, 0, 1]

fields_from_ticks requires an integral tick value (within 1e-6); continuous ticks are valid for the time conversions but not for a field representation.

Ticks to time

One count of the most significant field is

MSF = product(m[1..n])

ticks. A kernel coefficient triplet (ticks_i, seconds_i, rate_i) defines a piecewise-linear segment whose slope is rate_i / MSF seconds per tick:

parallel(ticks) = seconds_i + (rate_i / MSF) * (ticks - ticks_i)

rate_i is in parallel-time seconds per most significant clock count, so the kernel's SCLK01_TIME_SYSTEM decides what parallel means:

SCLK01_TIME_SYSTEM Parallel scale Conversion to ET
1 (default) TDB ticks are already ET seconds past J2000
2 TDT (TT) TT is converted to ET with the NAIF model

The conversions exposed are:

sclk.parallel_seconds(ticks)      // kernel's own scale
sclk.ticks_from_parallel(seconds)
sclk.ticks_to_et(ticks, &lsk)
sclk.et_to_ticks(et, &lsk)
sclk.ticks_to_tai(ticks, &lsk)
sclk.tai_to_ticks(epoch, &lsk)

The steps are ordered to match CSPICE sct2e and sce2t arithmetic, including the UNITIM iteration count, because coefficient rounding can put a queried tick on the other side of a segment boundary otherwise.

Continuous ticks

ET to ticks produces a continuous (non-integral) value, as CSPICE sce2c does. Such values are valid inputs to all conversions. format_string and fields_from_ticks reject them, because a clock displays whole counts.

Partitions

Partition bounds are parsed, validated and exposed:

let (starts, ends) = kernel.partitions();

Rules:

  • each partition must satisfy start <= end and both values must be finite;
  • the two arrays must have equal length;
  • cross-partition ordering is not required — a clock may jump ahead or regress, and that discontinuity is why a partition exists;
  • each endpoint is rounded to integral ticks before its duration is accumulated, as NAIF does.

The summed durations define the encoded domain:

domain = sum over partitions of (round(end) - round(start))

A tick below the first coefficient or above domain is rejected with SclkParse. A kernel with no partition metadata has no declared upper bound.

The legacy field-vector and string helpers reject multiple partitions or a nonzero partition start. Use encode_native_sclk and decode_native_sclk for partition-aware strings. encode_native_sclk_with_context preserves native parser history when the same SclkStringContext is reused. String endpoint rounding and continuous tick bounds have separate rules; see the API guide and its referenced native evidence for the exercised cases.

String ↔ ET helper

SclkClock binds a kernel to an LSK and implements the SclkMap trait:

use stkcraft_time::sclk::{SclkClock, SclkMap};

let clock = SclkClock { kernel: &kernel, lsk: &lsk };
let et = clock.sclk_to_et("123:45")?;
let text = clock.et_to_sclk(et)?;

SclkClock selects the native string path for multiple partitions or a nonzero partition start. The explicit native_sclk_to_et, native_sclk_to_et_with_context, and native_et_to_sclk methods preserve additional native error details. These APIs cover the recorded reference cases; they do not establish exhaustive parity for every clock or kernel.

Delimiters

Input strings may use any of - . , : or blanks, as NAIF allows. Output uses the delimiter selected by SCLK01_OUTPUT_DELIM:

Code Delimiter
1 .
2 :
3 -
4 ,
5 space

Validation

tests/sclk_spice.rs replays committed CSPICE references for two real mission kernels — MRO_SCLKSCET.00120.tsc (clock -74) and juice_step_250412_v01.tsc (clock -28) — in both directions:

Direction Cases
forward, ticks → ET (sct2e) 2 719
inverse, ET → ticks (sce2c) 8 152
total 10 871

Every case compares f64 bit patterns, not a tolerance:

cargo test --test sclk_spice

The fixtures include coefficient neighbours and the TDT/ET rounding cases that failed earlier (0.93 ns and 119.21 ns).

The external check runs the same kernels through the Python validator:

python tools/validate_sclk.py \
    --sclk tests/kernels/MRO_SCLKSCET.00120.tsc --id -74

Bit-exact agreement is agreement with the reference engine; it is not a claim about the physical calibration of a spacecraft clock.

Limits

  • Only clock type 1.
  • No mission SCLK kernel is bundled.
  • Legacy field-vector helpers do not support partition-aware conversion.
  • Native string parity is limited to the documented reference corpus.

Clone this wiki locally