edfcore 0.3.8 → 0.3.10

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/CHANGELOG.md CHANGED
@@ -6,6 +6,50 @@ alone does not tell you whether you were affected.
6
6
  edfcore is pre-1.0. Patch releases have carried behaviour changes where the old behaviour was a
7
7
  defect; those are called out below.
8
8
 
9
+ ## 0.3.10
10
+
11
+ - **Changed** `toPhysicalEnvelope` to return `NaN` for a bucket no sample landed in, instead of a
12
+ number that looks like a measurement.
13
+ - `EdfEnvelopeSignal.min` and `.max` are `Int32Array`s, so there is no sentinel available outside
14
+ the sample range and an empty bucket carries a digital `0` with `counts[i] === 0` beside it to
15
+ say so. In digital units a stray `0` at least reads as nothing. Through the affine transform it
16
+ stops reading as nothing: `bitValue * (offset + 0)` is `bitValue * offset`, which is mid-scale
17
+ for any channel whose declared range is not centred on zero. A channel declared 0..1000 over a
18
+ full signed 16-bit range converts an empty bucket to **500.008** — dead centre, and
19
+ indistinguishable from a real reading.
20
+ - A viewer that plots `min`/`max` without consulting `counts` therefore drew a flat, plausible
21
+ trace across a hole in the recording. That is believable garbage, which this package's own fuzz
22
+ invariant says it never returns.
23
+ - `counts` is unchanged and is still the authoritative answer to how many samples a bucket holds.
24
+ A caller already checking it sees no difference; one that was not now gets a value no plotting
25
+ library will draw and no reader will mistake for data.
26
+ - The digital envelope is unchanged for the reason above — an `Int32Array` cannot hold `NaN` — so
27
+ `readEnvelope`, `readEnvelopeAtResolution` and `envelopeOfSamples` return exactly what they did.
28
+
29
+ ## 0.3.9
30
+
31
+ - **Fixed** `readEnvelopeAtResolution` delivering a different bucket width in each chunk of one
32
+ call. Asked for 30 s per bucket over a window covering a 100 s run and a 60 s run, it returned
33
+ four buckets of **25 s** for the first and two of **30 s** for the second. Widths that disagree
34
+ cannot go on one axis, which is the entire reason this function exists apart from `readEnvelope`.
35
+ - 0.2.31 fixed half of this. It made the bucket COUNT come from each run's own span instead of once
36
+ from the window, which was necessary and not sufficient: the fold still divided each run evenly
37
+ into that count, so the width went on following the run whenever its span was not a whole
38
+ multiple of the request. The 25 s above is 100 s divided by four.
39
+ - The bucket a sample lands in is now decided by WHEN it is — `floor(elapsed / secondsPerBucket)`,
40
+ in exact integer arithmetic on ticks and sample positions. The last bucket of a run is therefore
41
+ short by whatever the division left over, which is the "sliver" this function's own documentation
42
+ described from the start and did not produce. Its `counts` entry says how short.
43
+ - `chunk.secondsPerBucket` is the width the buckets actually have, so for this function it is now
44
+ the width that was requested, for every chunk. It was `durationSeconds / bucketCount`, which is
45
+ only the width when the run divides evenly — the same wrong number, reported.
46
+ - `readEnvelope` is unchanged. Its contract is `buckets`, a plot's pixel width, and dividing the
47
+ run evenly into that count is exactly right; the two rules are now distinct in the code.
48
+ - Boundaries are precomputed once per signal per run, so the per-sample loop advances a cursor
49
+ rather than dividing. It does not reset at a chunk boundary: chunking bounds memory and must
50
+ never move a sample between buckets, and the test for that reads a file large enough to force
51
+ more than one chunk with the boundary falling inside a bucket rather than on its edge.
52
+
9
53
  ## 0.3.8
10
54
 
11
55
  **0.3.7 claimed the exactness work "closes the set". It did not.** An audit of every public type
@@ -109,5 +109,5 @@ export declare const SIGNAL_FIELD_BLOCK_OFFSETS: {
109
109
  readonly reserved: 224;
110
110
  };
111
111
  /** Published package version. Kept in sync with package.json by a test. */
112
- export declare const VERSION = "0.3.8";
112
+ export declare const VERSION = "0.3.10";
113
113
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,EAAG,GAAY,CAAC;AAEnD,gFAAgF;AAChF,eAAO,MAAM,uBAAuB,EAAG,GAAY,CAAC;AAEpD,gGAAgG;AAChG,eAAO,MAAM,qBAAqB,EAAG,iBAA0B,CAAC;AAChE,eAAO,MAAM,qBAAqB,EAAG,iB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F;AACvF,eAAO,MAAM,gCAAgC,EAAG,KAAc,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAE1C,+BAA+B;AAC/B,eAAO,MAAM,eAAe,EAAG,CAAC,KAAc,CAAC;AAC/C,eAAO,MAAM,eAAe,EAAG,KAAc,CAAC;AAE9C,0DAA0D;AAC1D,eAAO,MAAM,eAAe,EAAG,CAAC,OAAgB,CAAC;AACjD,eAAO,MAAM,eAAe,EAAG,OAAgB,CAAC;AAEhD,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,EAAG,IAAa,CAAC;AAElD,0FAA0F;AAC1F,eAAO,MAAM,6BAA6B,EAAE,MAA0B,CAAC;AAEvE;6FAC6F;AAC7F,eAAO,MAAM,4BAA4B,EAAG,EAAa,CAAC;AAC1D,eAAO,MAAM,oBAAoB,EAAG,EAAa,CAAC;AAClD,eAAO,MAAM,cAAc,EAAG,CAAa,CAAC;AAE5C,yEAAyE;AACzE,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWhB,CAAC;AAEX;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;CAWtB,CAAC;AAEX,+FAA+F;AAC/F,eAAO,MAAM,0BAA0B;;;;;;;;;;;CAW7B,CAAC;AAEX,2EAA2E;AAC3E,eAAO,MAAM,OAAO,WAAW,CAAC"}
package/dist/constants.js CHANGED
@@ -79,5 +79,5 @@ export const SIGNAL_FIELD_BLOCK_OFFSETS = {
79
79
  reserved: 224,
80
80
  };
81
81
  /** Published package version. Kept in sync with package.json by a test. */
82
- export const VERSION = '0.3.8';
82
+ export const VERSION = '0.3.10';
83
83
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,GA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(chunkSignal: EdfChunkSignal, buckets:
69
69
  * 1 s per bucket came back as 0.27 s per bucket in one chunk and 0.09 s in the other, which are
70
70
  * not commensurable, so a viewer cannot place the two on one axis. That is the whole promise of
71
71
  * this function, so it is computed where the run's length is known (fixed in 0.2.31).
72
+ *
73
+ * The bucket count was only half of it. A bucket is a fixed WIDTH IN TIME here, and until 0.3.9
74
+ * the fold still divided each run evenly into its own count — so the width followed the run
75
+ * exactly as before whenever the span was not a whole multiple of the request. A 100 s run at 30 s
76
+ * per bucket got four buckets of 25 s, while a 60 s run in the same call got two of 30 s. The
77
+ * bucket a sample lands in is now decided by WHEN it is, so the last bucket of a run is short by
78
+ * whatever the division left over — the sliver this documentation always described — and every
79
+ * chunk of every call reports the width that was asked for.
72
80
  */
73
81
  export declare function readEnvelopeAtResolution(recording: EdfRecording, selection: {
74
82
  readonly signalIndices: readonly number[];
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAUH,OAAO,KAAK,EACV,cAAc,EAEd,gBAAgB,EAChB,iBAAiB,EAEjB,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,WAAW,EAEZ,MAAM,YAAY,CAAC;AAsBpB;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,YAAY,EACvB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,CAkBtC;AA4LD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,iBAAiB,EAC3B,GAAG,CAAC,EAAE,mBAAmB,GACxB,mBAAmB,CAuCrB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,MAA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E,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC,EACD,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,CA8DtC"}
package/dist/envelope.js CHANGED
@@ -28,6 +28,29 @@ import { gapBefore } from './recording.js';
28
28
  import { decodeAnnotations } from './tal/annotations.js';
29
29
  import { ceilDiv, secondsToTicks, ticksToSeconds } from './tal/ticks.js';
30
30
  import { resolveTimeWindow } from './time/window.js';
31
+ /**
32
+ * The first sample position of each bucket, for buckets of a fixed width in time.
33
+ *
34
+ * Bucket `b` covers `[b * bucketTicks, (b + 1) * bucketTicks)` of elapsed time within the run, and
35
+ * sample `p` of this signal sits at `p * recordDuration / samplesPerRecord`. So the first sample
36
+ * of bucket `b` is `ceil(b * bucketTicks * samplesPerRecord / recordDuration)`.
37
+ *
38
+ * Computed in bigint, once per signal per run — the array is a plot's worth of entries, not a
39
+ * recording's — so the per-sample loop compares two ordinary numbers. Every boundary is a whole
40
+ * sample index, well inside 2^53.
41
+ */
42
+ function bucketStartsFor(bucketCount, bucketTicks, samplesPerRecord, recordDurationTicks) {
43
+ // Nothing advances in time: every sample of the run is at the same instant, so one bucket holds
44
+ // them all and the even-division rule already says so.
45
+ if (recordDurationTicks <= 0n || samplesPerRecord <= 0)
46
+ return undefined;
47
+ const starts = new Float64Array(bucketCount);
48
+ const perRecord = BigInt(samplesPerRecord);
49
+ for (let bucket = 1; bucket < bucketCount; bucket += 1) {
50
+ starts[bucket] = Number(ceilDiv(BigInt(bucket) * bucketTicks * perRecord, recordDurationTicks));
51
+ }
52
+ return starts;
53
+ }
31
54
  function assertPositiveInteger(value, name) {
32
55
  if (Number.isSafeInteger(value) && value > 0)
33
56
  return;
@@ -73,7 +96,13 @@ function resolveEnvelopeSignals(header, signalIndices) {
73
96
  }
74
97
  return signals;
75
98
  }
76
- async function reduceRange(recording, records, selection, options) {
99
+ async function reduceRange(recording, records, selection, options,
100
+ /**
101
+ * Set only by `readEnvelopeAtResolution`: the width every bucket must have, in exact ticks.
102
+ * When absent the run is divided evenly into `selection.buckets`, which is `readEnvelope`'s
103
+ * contract and the right rule for a pixel width.
104
+ */
105
+ bucketTicks) {
77
106
  const { source, header, timeline } = recording;
78
107
  const signals = resolveEnvelopeSignals(header, selection.signalIndices);
79
108
  const diagnostics = [];
@@ -91,6 +120,10 @@ async function reduceRange(recording, records, selection, options) {
91
120
  consumed: 0,
92
121
  outOfRange: 0,
93
122
  scratch: undefined,
123
+ bucketStarts: bucketTicks === undefined || bucketTicks <= 0n
124
+ ? undefined
125
+ : bucketStartsFor(bucketCount, bucketTicks, signal.samplesPerRecord, header.recordDurationTicks),
126
+ bucket: 0,
94
127
  }));
95
128
  const chunkRecords = scanChunkRecords(header, options?.maxMaterializeBytes);
96
129
  let byteLength = 0;
@@ -146,7 +179,15 @@ async function reduceRange(recording, records, selection, options) {
146
179
  durationSeconds,
147
180
  durationTicks: spanTicks,
148
181
  bucketCount,
149
- secondsPerBucket: bucketCount > 0 ? durationSeconds / bucketCount : 0,
182
+ // The width the buckets ACTUALLY have. With a requested width that is the request itself, for
183
+ // every chunk — `durationSeconds / bucketCount` is the width only when the run divides evenly
184
+ // by it, and reporting that made two runs of one call disagree (fixed in 0.3.9). The last
185
+ // bucket of a run is short by whatever the division left over; its `counts` says how short.
186
+ secondsPerBucket: bucketTicks !== undefined && bucketTicks > 0n
187
+ ? ticksToSeconds(bucketTicks)
188
+ : bucketCount > 0
189
+ ? durationSeconds / bucketCount
190
+ : 0,
150
191
  byteLength,
151
192
  signals: Object.freeze(envelopeSignals),
152
193
  // The same gap a readWindow chunk would carry. An envelope promises to mirror readWindow,
@@ -178,10 +219,24 @@ function foldChunk(accumulator, header, bytes, slice, run, bucketCount, options)
178
219
  const sampleCount = accumulator.signal.samplesPerRecord * slice.count;
179
220
  const { min, max, counts } = accumulator;
180
221
  let position = accumulator.consumed;
222
+ const starts = accumulator.bucketStarts;
223
+ let cursor = accumulator.bucket;
181
224
  for (let i = 0; i < sampleCount; i += 1) {
182
225
  const value = samples[i];
183
- // Integer arithmetic on the run grid: floor(position * buckets / totalSamples).
184
- const bucket = Math.min(bucketCount - 1, Math.floor((position * bucketCount) / totalSamples));
226
+ let bucket;
227
+ if (starts === undefined) {
228
+ // Integer arithmetic on the run grid: floor(position * buckets / totalSamples). Divides the
229
+ // run evenly, which is `readEnvelope`'s contract — the caller asked for a pixel width.
230
+ bucket = Math.min(bucketCount - 1, Math.floor((position * bucketCount) / totalSamples));
231
+ }
232
+ else {
233
+ // Buckets of a fixed WIDTH IN TIME. The boundaries are sample positions computed once per
234
+ // run, so this is a cursor advance rather than a division, and it never resets at a chunk
235
+ // boundary — chunking bounds memory and must not change the answer.
236
+ while (cursor + 1 < bucketCount && position >= starts[cursor + 1])
237
+ cursor += 1;
238
+ bucket = cursor;
239
+ }
185
240
  const seen = counts[bucket];
186
241
  if (seen === 0) {
187
242
  min[bucket] = value;
@@ -197,6 +252,7 @@ function foldChunk(accumulator, header, bytes, slice, run, bucketCount, options)
197
252
  position += 1;
198
253
  }
199
254
  accumulator.consumed = position;
255
+ accumulator.bucket = cursor;
200
256
  }
201
257
  /**
202
258
  * Converts a digital envelope to physical units.
@@ -232,7 +288,28 @@ export function toPhysicalEnvelope(signal, envelope, out) {
232
288
  const low = out === undefined ? new Float64Array(length) : out.min.subarray(0, length);
233
289
  const high = out === undefined ? new Float64Array(length) : out.max.subarray(0, length);
234
290
  const decreasing = scale.bitValue < 0;
291
+ const counts = envelope.counts;
235
292
  for (let i = 0; i < length; i += 1) {
293
+ /*
294
+ * A bucket no sample landed in is NaN, not a number.
295
+ *
296
+ * `min` and `max` are Int32Arrays, which cannot hold a sentinel outside the sample range, so
297
+ * an empty bucket carries a digital 0 and `counts[i] === 0` is what distinguishes it. In
298
+ * digital units a stray 0 at least looks like nothing. Through the affine transform it stops
299
+ * looking like nothing: `bitValue * (offset + 0)` is `bitValue * offset`, which for a channel
300
+ * declared 0..1000 over a full signed 16-bit range is 500.008 — dead centre of the scale, and
301
+ * indistinguishable from a real reading. A viewer that plots min/max without consulting
302
+ * `counts` therefore drew a flat trace at mid-scale across a hole in the recording.
303
+ *
304
+ * NaN is the one value that cannot be mistaken for a measurement, and every plotting library
305
+ * treats it as a break in the line. `counts` is unchanged and is still the authoritative
306
+ * answer to how many samples a bucket holds (fixed in 0.3.10).
307
+ */
308
+ if (counts[i] === 0) {
309
+ low[i] = Number.NaN;
310
+ high[i] = Number.NaN;
311
+ continue;
312
+ }
236
313
  const a = scale.bitValue * (scale.offset + envelope.min[i]);
237
314
  const b = scale.bitValue * (scale.offset + envelope.max[i]);
238
315
  low[i] = decreasing ? b : a;
@@ -311,6 +388,14 @@ function clampToSafeInteger(value) {
311
388
  * 1 s per bucket came back as 0.27 s per bucket in one chunk and 0.09 s in the other, which are
312
389
  * not commensurable, so a viewer cannot place the two on one axis. That is the whole promise of
313
390
  * this function, so it is computed where the run's length is known (fixed in 0.2.31).
391
+ *
392
+ * The bucket count was only half of it. A bucket is a fixed WIDTH IN TIME here, and until 0.3.9
393
+ * the fold still divided each run evenly into its own count — so the width followed the run
394
+ * exactly as before whenever the span was not a whole multiple of the request. A 100 s run at 30 s
395
+ * per bucket got four buckets of 25 s, while a 60 s run in the same call got two of 30 s. The
396
+ * bucket a sample lands in is now decided by WHEN it is, so the last bucket of a run is short by
397
+ * whatever the division left over — the sliver this documentation always described — and every
398
+ * chunk of every call reports the width that was asked for.
314
399
  */
315
400
  export async function readEnvelopeAtResolution(recording, selection, options) {
316
401
  const { secondsPerBucket } = selection;
@@ -353,7 +438,7 @@ export async function readEnvelopeAtResolution(recording, selection, options) {
353
438
  startSeconds: selection.startSeconds,
354
439
  durationSeconds: selection.durationSeconds,
355
440
  buckets,
356
- }, options));
441
+ }, options, bucketTicks));
357
442
  }
358
443
  return Object.freeze(chunks);
359
444
  }
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA2BrD,SAAS,qBAAqB,CAAC,KAAa,EAAE,IAAY;IACxD,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO;IACrD,MAAM,IAAI,UAAU,CAClB,mBAAmB,IAAI,8CAA8C,KAAK,IAAI;QAC5E,8DAA8D,CACjE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,SAAuB,EACvB,SAA4B,EAC5B,OAAqB;IAErB,qBAAqB,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACpD,yFAAyF;IACzF,qEAAqE;IACrE,sBAAsB,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC;IAElE,MAAM,MAAM,GAAG,iBAAiB,CAC9B,SAAS,CAAC,QAAQ,EAClB,SAAS,CAAC,KAAK,EACf,SAAS,CAAC,YAAY,EACtB,SAAS,CAAC,eAAe,CAC1B,CAAC;IA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E,aAAa,EAAE,SAAS,CAAC,aAAa;YACtC,YAAY,EAAE,SAAS,CAAC,YAAY;YACpC,eAAe,EAAE,SAAS,CAAC,eAAe;YAC1C,OAAO;SACR,EACD,OAAO,EACP,WAAW,CACZ,CACF,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edfcore",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "Modern, typed, zero-dependency reader for EDF, EDF+, BDF and BDF+ biosignal files. Works in browsers and Node with true random access.",
5
5
  "keywords": [
6
6
  "edf",
package/src/constants.ts CHANGED
@@ -93,4 +93,4 @@ export const SIGNAL_FIELD_BLOCK_OFFSETS = {
93
93
  } as const;
94
94
 
95
95
  /** Published package version. Kept in sync with package.json by a test. */
96
- export const VERSION = '0.3.8';
96
+ export const VERSION = '0.3.10';
package/src/envelope.ts CHANGED
@@ -53,6 +53,45 @@ interface Accumulator {
53
53
  consumed: number;
54
54
  outOfRange: number;
55
55
  scratch: Int32Array | undefined;
56
+ /**
57
+ * First sample position of each bucket, when the buckets are a fixed WIDTH IN TIME rather than
58
+ * an even division of the run.
59
+ *
60
+ * `undefined` for `readEnvelope`, whose contract is `buckets` — a plot's pixel width — and for
61
+ * which dividing the run evenly is exactly right. Present for `readEnvelopeAtResolution`, whose
62
+ * contract is the width itself. See `bucketStartsFor`.
63
+ */
64
+ bucketStarts: Float64Array | undefined;
65
+ /** Cursor into `bucketStarts`, advanced as samples arrive. Chunk boundaries do not reset it. */
66
+ bucket: number;
67
+ }
68
+
69
+ /**
70
+ * The first sample position of each bucket, for buckets of a fixed width in time.
71
+ *
72
+ * Bucket `b` covers `[b * bucketTicks, (b + 1) * bucketTicks)` of elapsed time within the run, and
73
+ * sample `p` of this signal sits at `p * recordDuration / samplesPerRecord`. So the first sample
74
+ * of bucket `b` is `ceil(b * bucketTicks * samplesPerRecord / recordDuration)`.
75
+ *
76
+ * Computed in bigint, once per signal per run — the array is a plot's worth of entries, not a
77
+ * recording's — so the per-sample loop compares two ordinary numbers. Every boundary is a whole
78
+ * sample index, well inside 2^53.
79
+ */
80
+ function bucketStartsFor(
81
+ bucketCount: number,
82
+ bucketTicks: bigint,
83
+ samplesPerRecord: number,
84
+ recordDurationTicks: bigint,
85
+ ): Float64Array | undefined {
86
+ // Nothing advances in time: every sample of the run is at the same instant, so one bucket holds
87
+ // them all and the even-division rule already says so.
88
+ if (recordDurationTicks <= 0n || samplesPerRecord <= 0) return undefined;
89
+ const starts = new Float64Array(bucketCount);
90
+ const perRecord = BigInt(samplesPerRecord);
91
+ for (let bucket = 1; bucket < bucketCount; bucket += 1) {
92
+ starts[bucket] = Number(ceilDiv(BigInt(bucket) * bucketTicks * perRecord, recordDurationTicks));
93
+ }
94
+ return starts;
56
95
  }
57
96
 
58
97
  function assertPositiveInteger(value: number, name: string): void {
@@ -126,6 +165,12 @@ async function reduceRange(
126
165
  records: RecordRange,
127
166
  selection: EnvelopeSelection,
128
167
  options?: ReadOptions,
168
+ /**
169
+ * Set only by `readEnvelopeAtResolution`: the width every bucket must have, in exact ticks.
170
+ * When absent the run is divided evenly into `selection.buckets`, which is `readEnvelope`'s
171
+ * contract and the right rule for a pixel width.
172
+ */
173
+ bucketTicks?: bigint,
129
174
  ): Promise<EdfEnvelopeChunk> {
130
175
  const { source, header, timeline } = recording;
131
176
  const signals = resolveEnvelopeSignals(header, selection.signalIndices);
@@ -149,6 +194,16 @@ async function reduceRange(
149
194
  consumed: 0,
150
195
  outOfRange: 0,
151
196
  scratch: undefined,
197
+ bucketStarts:
198
+ bucketTicks === undefined || bucketTicks <= 0n
199
+ ? undefined
200
+ : bucketStartsFor(
201
+ bucketCount,
202
+ bucketTicks,
203
+ signal.samplesPerRecord,
204
+ header.recordDurationTicks,
205
+ ),
206
+ bucket: 0,
152
207
  }));
153
208
 
154
209
  const chunkRecords = scanChunkRecords(header, options?.maxMaterializeBytes);
@@ -210,7 +265,16 @@ async function reduceRange(
210
265
  durationSeconds,
211
266
  durationTicks: spanTicks,
212
267
  bucketCount,
213
- secondsPerBucket: bucketCount > 0 ? durationSeconds / bucketCount : 0,
268
+ // The width the buckets ACTUALLY have. With a requested width that is the request itself, for
269
+ // every chunk — `durationSeconds / bucketCount` is the width only when the run divides evenly
270
+ // by it, and reporting that made two runs of one call disagree (fixed in 0.3.9). The last
271
+ // bucket of a run is short by whatever the division left over; its `counts` says how short.
272
+ secondsPerBucket:
273
+ bucketTicks !== undefined && bucketTicks > 0n
274
+ ? ticksToSeconds(bucketTicks)
275
+ : bucketCount > 0
276
+ ? durationSeconds / bucketCount
277
+ : 0,
214
278
  byteLength,
215
279
  signals: Object.freeze(envelopeSignals),
216
280
  // The same gap a readWindow chunk would carry. An envelope promises to mirror readWindow,
@@ -260,10 +324,23 @@ function foldChunk(
260
324
  const { min, max, counts } = accumulator;
261
325
  let position = accumulator.consumed;
262
326
 
327
+ const starts = accumulator.bucketStarts;
328
+ let cursor = accumulator.bucket;
329
+
263
330
  for (let i = 0; i < sampleCount; i += 1) {
264
331
  const value = samples[i] as number;
265
- // Integer arithmetic on the run grid: floor(position * buckets / totalSamples).
266
- const bucket = Math.min(bucketCount - 1, Math.floor((position * bucketCount) / totalSamples));
332
+ let bucket: number;
333
+ if (starts === undefined) {
334
+ // Integer arithmetic on the run grid: floor(position * buckets / totalSamples). Divides the
335
+ // run evenly, which is `readEnvelope`'s contract — the caller asked for a pixel width.
336
+ bucket = Math.min(bucketCount - 1, Math.floor((position * bucketCount) / totalSamples));
337
+ } else {
338
+ // Buckets of a fixed WIDTH IN TIME. The boundaries are sample positions computed once per
339
+ // run, so this is a cursor advance rather than a division, and it never resets at a chunk
340
+ // boundary — chunking bounds memory and must not change the answer.
341
+ while (cursor + 1 < bucketCount && position >= (starts[cursor + 1] as number)) cursor += 1;
342
+ bucket = cursor;
343
+ }
267
344
  const seen = counts[bucket] as number;
268
345
  if (seen === 0) {
269
346
  min[bucket] = value;
@@ -277,6 +354,7 @@ function foldChunk(
277
354
  }
278
355
 
279
356
  accumulator.consumed = position;
357
+ accumulator.bucket = cursor;
280
358
  }
281
359
 
282
360
  /**
@@ -323,8 +401,29 @@ export function toPhysicalEnvelope(
323
401
  const low = out === undefined ? new Float64Array(length) : out.min.subarray(0, length);
324
402
  const high = out === undefined ? new Float64Array(length) : out.max.subarray(0, length);
325
403
  const decreasing = scale.bitValue < 0;
404
+ const counts = envelope.counts;
326
405
 
327
406
  for (let i = 0; i < length; i += 1) {
407
+ /*
408
+ * A bucket no sample landed in is NaN, not a number.
409
+ *
410
+ * `min` and `max` are Int32Arrays, which cannot hold a sentinel outside the sample range, so
411
+ * an empty bucket carries a digital 0 and `counts[i] === 0` is what distinguishes it. In
412
+ * digital units a stray 0 at least looks like nothing. Through the affine transform it stops
413
+ * looking like nothing: `bitValue * (offset + 0)` is `bitValue * offset`, which for a channel
414
+ * declared 0..1000 over a full signed 16-bit range is 500.008 — dead centre of the scale, and
415
+ * indistinguishable from a real reading. A viewer that plots min/max without consulting
416
+ * `counts` therefore drew a flat trace at mid-scale across a hole in the recording.
417
+ *
418
+ * NaN is the one value that cannot be mistaken for a measurement, and every plotting library
419
+ * treats it as a break in the line. `counts` is unchanged and is still the authoritative
420
+ * answer to how many samples a bucket holds (fixed in 0.3.10).
421
+ */
422
+ if (counts[i] === 0) {
423
+ low[i] = Number.NaN;
424
+ high[i] = Number.NaN;
425
+ continue;
426
+ }
328
427
  const a = scale.bitValue * (scale.offset + (envelope.min[i] as number));
329
428
  const b = scale.bitValue * (scale.offset + (envelope.max[i] as number));
330
429
  low[i] = decreasing ? b : a;
@@ -406,6 +505,14 @@ function clampToSafeInteger(value: bigint): number {
406
505
  * 1 s per bucket came back as 0.27 s per bucket in one chunk and 0.09 s in the other, which are
407
506
  * not commensurable, so a viewer cannot place the two on one axis. That is the whole promise of
408
507
  * this function, so it is computed where the run's length is known (fixed in 0.2.31).
508
+ *
509
+ * The bucket count was only half of it. A bucket is a fixed WIDTH IN TIME here, and until 0.3.9
510
+ * the fold still divided each run evenly into its own count — so the width followed the run
511
+ * exactly as before whenever the span was not a whole multiple of the request. A 100 s run at 30 s
512
+ * per bucket got four buckets of 25 s, while a 60 s run in the same call got two of 30 s. The
513
+ * bucket a sample lands in is now decided by WHEN it is, so the last bucket of a run is short by
514
+ * whatever the division left over — the sliver this documentation always described — and every
515
+ * chunk of every call reports the width that was asked for.
409
516
  */
410
517
  export async function readEnvelopeAtResolution(
411
518
  recording: EdfRecording,
@@ -473,6 +580,7 @@ export async function readEnvelopeAtResolution(
473
580
  buckets,
474
581
  },
475
582
  options,
583
+ bucketTicks,
476
584
  ),
477
585
  );
478
586
  }