@kymoscope/sdk 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kymoscope-embed.js +78 -78
- package/dist/kymoscope-sdk.js +84 -84
- package/dist/types/analysis/actions.d.ts +9 -0
- package/dist/types/analysis/aiCheck.d.ts +40 -0
- package/dist/types/analysis/badParts.d.ts +32 -0
- package/dist/types/analysis/capability.d.ts +1 -1
- package/dist/types/analysis/changes.d.ts +8 -0
- package/dist/types/analysis/context.d.ts +9 -3
- package/dist/types/analysis/control.d.ts +1 -1
- package/dist/types/analysis/energy.d.ts +21 -0
- package/dist/types/analysis/gap.d.ts +6 -0
- package/dist/types/analysis/golden.d.ts +6 -0
- package/dist/types/analysis/index.d.ts +4 -0
- package/dist/types/analysis/infer.d.ts +1 -1
- package/dist/types/analysis/known.d.ts +27 -0
- package/dist/types/analysis/lines.d.ts +1 -1
- package/dist/types/analysis/losses.d.ts +1 -1
- package/dist/types/analysis/oee.d.ts +6 -2
- package/dist/types/analysis/presets.d.ts +3 -3
- package/dist/types/analysis/ranges.d.ts +18 -0
- package/dist/types/analysis/reliability.d.ts +62 -1
- package/dist/types/analysis/report.d.ts +3 -3
- package/dist/types/analysis/review.d.ts +119 -0
- package/dist/types/analysis/runWear.d.ts +13 -0
- package/dist/types/analysis/shifts.d.ts +1 -0
- package/dist/types/analysis/stops.d.ts +10 -0
- package/dist/types/analysis/text.d.ts +1 -1
- package/dist/types/analysis/types.d.ts +35 -4
- package/dist/types/charts/ChartBody.d.ts +6 -1
- package/dist/types/components/SpectrogramChart.d.ts +24 -1
- package/dist/types/engine/createEngine.d.ts +22 -1
- package/dist/types/index.d.ts +6 -1
- package/dist/types/lib/data/liveDataSource.d.ts +9 -0
- package/dist/types/lib/live/clockProbe.d.ts +26 -0
- package/dist/types/lib/live/publisher.d.ts +5 -0
- package/dist/types/lib/live/types.d.ts +8 -0
- package/dist/types/lib/live/videoTrack.d.ts +46 -2
- package/dist/types/lib/measurePack.d.ts +13 -0
- package/dist/types/lib/recordings/videoSource.d.ts +12 -1
- package/dist/types/lib/render/heatGrid.d.ts +5 -0
- package/dist/types/lib/segments/rules.d.ts +4 -0
- package/dist/types/lib/stft.d.ts +30 -0
- package/dist/types/lib/sync/detect.d.ts +28 -0
- package/dist/types/lib/sync/estimate.d.ts +143 -0
- package/dist/types/lib/sync/flash.d.ts +49 -0
- package/dist/types/lib/sync/frameFeatures.d.ts +16 -0
- package/package.json +1 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camera ↔ data offset by content (spec 2026-11-19-camera-sync-design §5.1): something in the picture changes when some
|
|
3
|
+
* channel changes; find the lag that lines them up. Pure arrays in, an estimate or a refusal out; nothing here knows
|
|
4
|
+
* what the picture or the channel means.
|
|
5
|
+
*
|
|
6
|
+
* Video features (frameFeatures.ts): per frame an 8×6 grid of mean luminance (level) and of mean |Δ| to the previous
|
|
7
|
+
* frame (diff, divided by the frame gap: a rate, placed at the midpoint of the two frames), both high-passed. Data
|
|
8
|
+
* features per channel: the value (high-passed), |value| high-passed and |d/dt| (at the midpoint of its two samples).
|
|
9
|
+
* Pairs: level ↔ value, diff ↔ |d/dt| and |value| (motion follows a derivative, a rotation rate or vibration; a lamp or
|
|
10
|
+
* gauge a level). Channels that look like one sensor's axes add their vector's magnitude (withAxisMagnitudes), paired
|
|
11
|
+
* value ↔ diff only and always taken to the fine pass: a hand-held camera's picture moves with the whole sensor.
|
|
12
|
+
*
|
|
13
|
+
* 1. Channels: numeric, ≥ 10 Hz, the most active (moves on the second scale, not a ramp or noise), at most 8.
|
|
14
|
+
* 2. Segments: ~20 s windows over the overlap (≥ 5; at most 10, spread out, the most active of each part).
|
|
15
|
+
* 3. Coarse: every pair, pooled over the segments on a 40 ms grid over [−1 s, +3 s]: each channel's best pair by
|
|
16
|
+
* peak z-score.
|
|
17
|
+
* 4. Fine: the best channels, per segment on a 5 ms grid, parabolic peak; Theil–Sen line through the segment offsets
|
|
18
|
+
* → offset at tRef and drift; spread = MAD of the residuals around that line (not the mean: drift isn't noise).
|
|
19
|
+
* 5. Accept: ≥ 5 segments, spread ≤ ½ frame, median segment z ≥ 6, offset in [−1 frame, +3 s], and channels that
|
|
20
|
+
* pass agreeing within a frame (a setpoint's actuator delay shows up as disagreement).
|
|
21
|
+
* Sign: offsetMs > 0 = a frame is stamped later than what it shows (CameraSync): video(t) ≈ data(t − offset).
|
|
22
|
+
*/
|
|
23
|
+
export interface FrameFeatures {
|
|
24
|
+
/** Each frame's stamp (s, the data's clock: Unix s for a recording), ascending. */
|
|
25
|
+
t: ArrayLike<number>;
|
|
26
|
+
/** Features per frame (48 for the 8×6 grid). */
|
|
27
|
+
cells: number;
|
|
28
|
+
/** frames × cells: mean luminance of each cell (0..255). */
|
|
29
|
+
levels: ArrayLike<number>;
|
|
30
|
+
/** frames × cells: mean |luminance − the previous frame's| of each cell (frame 0: anything, unused). */
|
|
31
|
+
diffs: ArrayLike<number>;
|
|
32
|
+
}
|
|
33
|
+
export interface DataChannel {
|
|
34
|
+
name: string;
|
|
35
|
+
t: ArrayLike<number>;
|
|
36
|
+
v: ArrayLike<number>;
|
|
37
|
+
unit?: string;
|
|
38
|
+
/** Derived by withAxisMagnitudes: a sensor's vector magnitude, compared as a motion energy (value ~ diff). */
|
|
39
|
+
magnitude?: true;
|
|
40
|
+
}
|
|
41
|
+
export interface EstimateOptions {
|
|
42
|
+
/** Plausible offsets (ms): a stamp can't precede what it shows by more than a frame. Default −1 frame … +3000. */
|
|
43
|
+
minLagMs?: number;
|
|
44
|
+
maxLagMs?: number;
|
|
45
|
+
/** Segment length (s, default 20; shorter when the overlap holds fewer than minSegments). */
|
|
46
|
+
segmentS?: number;
|
|
47
|
+
minSegments?: number;
|
|
48
|
+
maxSegments?: number;
|
|
49
|
+
/** Channels compared (the most active first). Default 8. */
|
|
50
|
+
maxChannels?: number;
|
|
51
|
+
/** z-score needed: the median of the segments' peaks against the lags outside the peak's lobe (default 5). */
|
|
52
|
+
minZ?: number;
|
|
53
|
+
/** Channels taken to the fine pass (default 3). */
|
|
54
|
+
fineChannels?: number;
|
|
55
|
+
/** Feature pairs compared (default all three). */
|
|
56
|
+
pairs?: [DataKind, VideoKind][];
|
|
57
|
+
}
|
|
58
|
+
export interface SegmentOffset {
|
|
59
|
+
t: number;
|
|
60
|
+
offsetMs: number;
|
|
61
|
+
z: number;
|
|
62
|
+
peak: number;
|
|
63
|
+
}
|
|
64
|
+
export interface SyncEstimate {
|
|
65
|
+
ok: true;
|
|
66
|
+
offsetMs: number;
|
|
67
|
+
driftPpm: number;
|
|
68
|
+
/** Unix s the offset is at (the middle of the segments). */
|
|
69
|
+
tRef: number;
|
|
70
|
+
/** 0..1, from the z-score and the spread against half a frame. */
|
|
71
|
+
confidence: number;
|
|
72
|
+
/** MAD of the segment offsets around the fitted line (ms). */
|
|
73
|
+
spreadMs: number;
|
|
74
|
+
/** Channels whose estimates passed and agree (the offset is their median), the clearest first. */
|
|
75
|
+
channels: string[];
|
|
76
|
+
segments: SegmentOffset[];
|
|
77
|
+
z: number;
|
|
78
|
+
framePeriodMs: number;
|
|
79
|
+
/** Every channel compared in the fine pass: what it matched in the picture and its numbers. */
|
|
80
|
+
tried: TriedChannel[];
|
|
81
|
+
}
|
|
82
|
+
export interface TriedChannel {
|
|
83
|
+
channel: string;
|
|
84
|
+
feature: string;
|
|
85
|
+
offsetMs: number;
|
|
86
|
+
driftPpm: number;
|
|
87
|
+
spreadMs: number;
|
|
88
|
+
z: number;
|
|
89
|
+
segments: number;
|
|
90
|
+
refused: string | null;
|
|
91
|
+
}
|
|
92
|
+
export interface SyncRefusal {
|
|
93
|
+
ok: false;
|
|
94
|
+
/** English, for the user ("Couldn't detect: …"). */
|
|
95
|
+
reason: string;
|
|
96
|
+
/** The best channel's numbers, when one got that far. */
|
|
97
|
+
best?: {
|
|
98
|
+
channel: string;
|
|
99
|
+
offsetMs: number;
|
|
100
|
+
spreadMs: number;
|
|
101
|
+
z: number;
|
|
102
|
+
segments: number;
|
|
103
|
+
};
|
|
104
|
+
tried?: TriedChannel[];
|
|
105
|
+
}
|
|
106
|
+
export type SyncResult = SyncEstimate | SyncRefusal;
|
|
107
|
+
interface Chan extends DataChannel {
|
|
108
|
+
rate: number;
|
|
109
|
+
activity: number;
|
|
110
|
+
}
|
|
111
|
+
/** Channels worth comparing, the most active first: ≥ 10 Hz, not constant, moving on the second scale. Activity =
|
|
112
|
+
* (mean std in 20 s tiles / overall std: a ramp or a single step scores low) × lag-1 autocorrelation on a 40 ms grid
|
|
113
|
+
* (noise scores low). */
|
|
114
|
+
export declare function rankChannels(channels: DataChannel[], range: [number, number], tile?: number): Chan[];
|
|
115
|
+
/** Segments [a, b] (s) to compare: ~segmentS long, at least minSegments when the overlap allows, at most maxSegments
|
|
116
|
+
* spread over it (the most active tile of each part). `range` is where data and video both are. */
|
|
117
|
+
export declare function planSegments(channels: DataChannel[], range: [number, number], o?: EstimateOptions): {
|
|
118
|
+
segments: [number, number][];
|
|
119
|
+
video: [number, number][];
|
|
120
|
+
};
|
|
121
|
+
/** Overlapping (or within 2 s) windows joined: decoded in one pass. */
|
|
122
|
+
export declare function mergeWindows(w: [number, number][]): [number, number][];
|
|
123
|
+
/** Theil–Sen line through (t, y): slope, the value at tRef, and the MAD of the residuals around it. */
|
|
124
|
+
export declare function theilSen(t: number[], y: number[], tRef: number): {
|
|
125
|
+
slope: number;
|
|
126
|
+
at: number;
|
|
127
|
+
mad: number;
|
|
128
|
+
};
|
|
129
|
+
export type VideoKind = 'level' | 'diff';
|
|
130
|
+
export type DataKind = 'value' | 'abs' | 'rate';
|
|
131
|
+
/** Channels that look like the axes of one sensor (a shared name stem + a digit or x/y/z, 2–3 of them, the same unit
|
|
132
|
+
* and sample times) get the magnitude of their vector as a channel of its own (`<stem> |v|`), after the given ones:
|
|
133
|
+
* a hand-held or mounted camera's picture moves with the whole sensor's motion, which no single axis carries
|
|
134
|
+
* (a GoPro's GYRO). A group already derived (by name) isn't again. */
|
|
135
|
+
export declare function withAxisMagnitudes(channels: DataChannel[]): DataChannel[];
|
|
136
|
+
/**
|
|
137
|
+
* The camera's offset (and drift) against the data, or why not. `frames` and `channels` on the same clock (Unix s);
|
|
138
|
+
* `channels` any numeric ones (the most active are picked).
|
|
139
|
+
*/
|
|
140
|
+
export declare function estimateSync(frames: FrameFeatures, channels: DataChannel[], o?: EstimateOptions): SyncResult;
|
|
141
|
+
/** "high" / "medium" / "low", for the UI. */
|
|
142
|
+
export declare const confidenceLabel: (c: number) => "high" | "low" | "medium";
|
|
143
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time flash calibration of a physical camera (spec 2026-11-19-camera-sync-design.md, 5.2): a screen the camera
|
|
3
|
+
* films switches between dark and light on a known pseudo-random schedule; the camera's frame brightness (the 8×6 grid
|
|
4
|
+
* cell that follows it best: the whole screen, a corner of it, a reflection) against that schedule gives its latency:
|
|
5
|
+
* frame stamp minus the moment the screen showed what the frame shows. Stored as the camera's sync, method
|
|
6
|
+
* 'calibration'.
|
|
7
|
+
*
|
|
8
|
+
* The schedule is a function of the relay's clock (every sender's common reference, clockProbe.ts): cycles of
|
|
9
|
+
* FLASH_CYCLE_S seconds from the Unix epoch, each light at 0, switching at FLASH_INTERVALS_MS (the same every cycle,
|
|
10
|
+
* each 340–1200 ms: at most 3 switches a second, WCAG 2.3.1), dark from FLASH_ACTIVE_S to the cycle's end. Anything
|
|
11
|
+
* that knows the relay's time can show it (the app's calibration view) or simulate it (the rig's camera).
|
|
12
|
+
*/
|
|
13
|
+
import type { FrameFeatures } from './estimate';
|
|
14
|
+
export declare const FLASH_CYCLE_S = 15;
|
|
15
|
+
export declare const FLASH_ACTIVE_S = 12;
|
|
16
|
+
/** The switch intervals of a cycle (ms): MINSTD (48271, 2^31 − 1) from SEED, 340 + x mod 861 — exact in doubles. */
|
|
17
|
+
export declare const FLASH_INTERVALS_MS: readonly number[];
|
|
18
|
+
/** The schedule's level (1 light, 0 dark) at relay time `t` (Unix s). */
|
|
19
|
+
export declare function flashLevel(t: number): 0 | 1;
|
|
20
|
+
/** The start (relay Unix s) of the first cycle at least `leadS` after `t`. */
|
|
21
|
+
export declare const nextFlashCycle: (t: number, leadS?: number) => number;
|
|
22
|
+
/** A switch as shown: when (Unix s, on whatever clock the caller says) and the level from then. */
|
|
23
|
+
export interface FlashSwitch {
|
|
24
|
+
t: number;
|
|
25
|
+
level: 0 | 1;
|
|
26
|
+
}
|
|
27
|
+
/** The ideal switches of the cycle starting at `start` (relay Unix s). */
|
|
28
|
+
export declare const flashCycle: (start: number) => FlashSwitch[];
|
|
29
|
+
export type FlashResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
offsetMs: number;
|
|
32
|
+
spreadMs: number;
|
|
33
|
+
confidence: number;
|
|
34
|
+
cell: number;
|
|
35
|
+
frames: number;
|
|
36
|
+
switches: number;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
reason: string;
|
|
40
|
+
frames: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The latency of a camera that filmed `switches` (on the camera's clock, ascending; the level before the first is dark),
|
|
44
|
+
* from its frames' grid brightness (frameFeatures). Coarse: each cell's correlation with the level at each lag (10 ms);
|
|
45
|
+
* fine, on the best cell: lags 0.5 ms apart, each frame's predicted brightness the light fraction of an exposure window
|
|
46
|
+
* ending at stamp − lag (widths 0 … one frame period). Latency = stamp − the window's middle. ±: half the lags within
|
|
47
|
+
* 0.5 % of the best correlation.
|
|
48
|
+
*/
|
|
49
|
+
export declare function estimateFlash(f: FrameFeatures, switches: FlashSwitch[]): FlashResult;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A recorded camera's frames as the sync estimator's features (estimate.ts FrameFeatures), decoded in this browser
|
|
3
|
+
* (WebCodecs): each frame drawn to a 32×18 canvas, its luminance averaged in an 8×6 grid (level) and the mean
|
|
4
|
+
* |Δ luminance| of each cell's pixels to the previous frame (diff). Every VideoFrame is closed as soon as it is drawn
|
|
5
|
+
* (a hardware decoder stalls when its frames are held). Windows are decoded in pieces of PIECE_S, each continuing the
|
|
6
|
+
* previous one's decode (no gap at a keyframe boundary), so a long window never sits in memory whole.
|
|
7
|
+
*/
|
|
8
|
+
import type { VideoSource } from '../live/videoTrack';
|
|
9
|
+
import type { FrameFeatures } from './estimate';
|
|
10
|
+
export interface FrameFeatureOptions {
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
/** 0..1 over the windows' seconds. */
|
|
13
|
+
onProgress?: (fraction: number) => void;
|
|
14
|
+
}
|
|
15
|
+
/** Features of every frame decoded for `windows` ([t0, t1] Unix s, ascending, disjoint) of a recorded camera. */
|
|
16
|
+
export declare function frameFeatures(source: VideoSource, windows: [number, number][], o?: FrameFeatureOptions): Promise<FrameFeatures>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kymoscope/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "The Kymoscope data engine and charts for the browser: import large measurement files, plot them, stream live data end-to-end encrypted.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://kymoscope.com/docs/introduction",
|