edf2csv 0.4.8 → 0.4.9

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
@@ -3,6 +3,35 @@
3
3
  Notable changes to edf2csv. Versions follow [semantic versioning](https://semver.org); while the
4
4
  major version is 0, a minor bump may contain breaking changes.
5
5
 
6
+ ## 0.4.9
7
+
8
+ ### Fixed: a continuous recording that starts mid-second put its samples and its events on different clocks
9
+
10
+ EDF+ puts the header's start time and every annotation onset on one origin, and says the first
11
+ data record's timekeeping TAL "always starts with +0.X" — the fraction of a second by which
12
+ that record follows it. Continuous files never read it. Their samples were timed from zero
13
+ while their events kept their true onsets, so the two ended up half a second apart:
14
+
15
+ ```
16
+ first sample times event at +0.75 lands on
17
+ EDF+D 0.500, 0.750, 1.000 sample 1 correct
18
+ EDF+C 0.000, 0.250, 0.500 sample 3 half a second late
19
+ ```
20
+
21
+ Those two files are byte-identical apart from the reserved field. The discontinuous copy reads
22
+ its record times and gets the answer right; the continuous copy assumed record *k* begins at
23
+ *k* × the record duration, which is true of the spacing but not of the origin.
24
+
25
+ Nothing about the output says so. Both files convert cleanly, and the CSV is well formed —
26
+ the event simply sits on the wrong row, two samples from where the recording put it.
27
+
28
+ A continuous recording's records are still contiguous, which is what continuous means: only
29
+ the origin moves. A first TAL of `+0` needs no adjustment at all, which is nearly every file,
30
+ and every existing fixture is unchanged.
31
+
32
+ The test converts both copies of the same recording and requires them to agree, rather than
33
+ asserting a number either one of them happens to produce.
34
+
6
35
  ## 0.4.8
7
36
 
8
37
  ### Fixed: `--duration` dropped every annotation on a recording that starts after zero
@@ -1 +1 @@
1
- {"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../src/convert/timing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,cAAc,EAAE,oBAAoB,GACnC;IAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,CAmE5D"}
1
+ {"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../src/convert/timing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,cAAc,EAAE,oBAAoB,GACnC;IAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,CA2F5D"}
@@ -16,8 +16,31 @@ export function deriveRecordStarts(file, annotationData) {
16
16
  hint: 'The rest were exported normally. The file may have been written by a non-conforming tool.',
17
17
  });
18
18
  }
19
- if (file.header.continuity !== 'EDF+D')
20
- return { starts: null, diagnostics };
19
+ /*
20
+ A continuous recording's records are contiguous, but the first one need not sit at zero.
21
+
22
+ EDF+ puts the header's start time and every annotation onset on one origin, and says the
23
+ first data record's timekeeping TAL "always starts with +0.X", stating the fraction of a
24
+ second by which that record follows it. Ignoring that fraction timed the samples from 0
25
+ while the events kept their true onsets, so the two ended up on origins half a second
26
+ apart — an event at +0.75 in a 4 Hz recording whose first TAL reads +0.5 landed on sample
27
+ 3 instead of sample 1. The same file marked EDF+D, byte-identical but for the reserved
28
+ field, placed it correctly, which is what gives the omission away.
29
+
30
+ Records stay contiguous, which is what continuous means: only the origin moves. A first
31
+ TAL of +0 needs no table at all, and that is nearly every file.
32
+ */
33
+ if (file.header.continuity !== 'EDF+D') {
34
+ const first = annotationData.recordStarts[0];
35
+ if (file.header.continuity !== 'EDF+C' || typeof first !== 'number' || first === 0) {
36
+ return { starts: null, diagnostics };
37
+ }
38
+ const contiguous = new Float64Array(file.recordCount);
39
+ for (let i = 0; i < file.recordCount; i++) {
40
+ contiguous[i] = first + i * file.header.recordDuration;
41
+ }
42
+ return { starts: contiguous, diagnostics };
43
+ }
21
44
  if (file.annotationSignals.length === 0) {
22
45
  diagnostics.push({
23
46
  code: 'DISCONTINUOUS',
@@ -1 +1 @@
1
- {"version":3,"file":"timing.js","sourceRoot":"","sources":["../../src/convert/timing.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAa,EACb,cAAoC;IAEpC,MAAM,WAAW,GAAiB,EAAE,CAAC;IAErC,IAAI,cAAc,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;QACjC,WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,0BAA0B;YAChC,QAAQ,EAAE,SAAS;YACnB,OAAO,EACL,GAAG,cAAc,CAAC,SAAS,mBAAmB,cAAc,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,GAAG;gBACtG,uCAAuC;YACzC,IAAI,EAAE,2FAA2F;SAClG,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAE7E,IAAI,IAAI,CAAC,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,eA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WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,eAAe;YACrB,QAAQ,EAAE,SAAS;YACnB,OAAO,EAAE,GAAG,UAAU,eAAe,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,2CAA2C;YAC3G,IAAI,EAAE,qFAAqF;SAC5F,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AACjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edf2csv",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "Convert EDF, EDF+ and BDF biosignal recordings (European Data Format) to CSV from the command line. Local, streaming, and never resamples or alters units.",
5
5
  "keywords": [
6
6
  "edf",