ntpstats.analysis¶
Descriptive statistics, detrending and outlier handling for offset series.
detrend(t, x, kind='linear')
¶
Remove a least-squares polynomial trend.
linear removes a constant frequency offset; quadratic also
removes a linear frequency drift (aging). Time is centred first so the
fit stays well conditioned with POSIX timestamps.
linear_fit(t, x)
¶
Least-squares slope (s/s) and intercept of offset vs time.
theil_sen_slope(t, x, max_pairs=200000, seed=0)
¶
Robust (median of pairwise slopes) frequency estimate, s/s.
Insensitive to up to ~29 % outliers, unlike least squares. Pairs are randomly subsampled for long series.
mad_outliers(x, k=5.0, t=None)
¶
Boolean mask of outliers: |x - median| > k * 1.4826 * MAD.
If t is given the test is applied to linearly detrended data so a
frequency offset is not mistaken for outliers.
summary(series)
¶
Summary statistics in the spirit of NTPsec's ntpviz report.
format_seconds(v)
¶
Pretty-print a time value with an SI prefix (e.g. 12.3 µs).
compare(estimate, reference)
¶
Score estimate against a reference (e.g. simulated truth, a
GNSS/PPS-disciplined clock or a better server).
The reference is linearly interpolated onto the estimate's times over
their common span. Returns error statistics of estimate - reference.