edf2csv 0.9.42 → 0.9.43

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.
@@ -303,6 +303,44 @@ export function buildPlan(input, options = {}) {
303
303
  if (writeSignals && groups.length > 0 && estimate.rows === 0 && !untimeable) {
304
304
  diagnostics.push(emptyWindow(range, input.recordCount, groups, options.gzip === true, options.toStdout === true));
305
305
  }
306
+ else if (writeSignals && (options.layout ?? 'wide') !== 'long' && !untimeable) {
307
+ /*
308
+ And a window that empties one rate and not another, which nothing said at all.
309
+
310
+ The check above asks whether the run wrote any rows. A rate group is what gets a file,
311
+ and a window can hold samples of one rate and none of another — a channel sampled once
312
+ a second has a sample every 1s, so `--start 0.1 --end 0.4` falls between two of them
313
+ while a 4 Hz channel in the same recording keeps one:
314
+
315
+ $ edf2csv mixed.edf --start 0.1 --end 0.4 --out ./converted
316
+ Wrote ./converted
317
+ signals_4hz.csv 1 row
318
+ signals_1hz.csv 0 rows
319
+
320
+ Two lines of a summary, one of them a file holding its header and nothing else, and no
321
+ warning — where the same file arrived at through a window that empties every rate
322
+ raises one, and `--strict` exits 1 over it. The rule EMPTY_WINDOW's own docstring
323
+ states is that everywhere a request produces nothing this tool says so.
324
+
325
+ Only the wide layout: a long conversion puts every rate in one table, so a rate with no
326
+ samples in the window costs it rows and not a file.
327
+ */
328
+ const empty = groups.filter((group) => rowsInRange(group, range, input.recordDuration, input.recordStarts) === 0);
329
+ const kept = groups.filter((group) => !empty.includes(group));
330
+ if (empty.length > 0 && kept.length > 0) {
331
+ const rates = (which) => listed(formatRates(which.map((g) => g.rate)).map((rate) => `${rate} Hz`));
332
+ diagnostics.push({
333
+ code: 'EMPTY_RATE_WINDOW',
334
+ severity: 'warning',
335
+ message: `No samples fall inside the requested window at ${rates(empty)}, so ` +
336
+ `${listed(empty.map((g) => destination(g)))} ` +
337
+ `${empty.length === 1 ? 'holds its header' : 'hold their headers'} and no data.`,
338
+ hint: `The window does hold samples at ${rates(kept)}. A window narrower than a ` +
339
+ `channel's sample interval can fall between two of its samples, and the slower ` +
340
+ `the channel the wider that gap is.`,
341
+ });
342
+ }
343
+ }
306
344
  if (estimate.exceedsSpreadsheetLimit) {
307
345
  /*
308
346
  And the file it is about, which `--stdout` does not write either.
@@ -638,6 +676,30 @@ function emptyWindow(range, recordCount, groups, gzip, toStdout) {
638
676
  `the channel table --info prints and in ${outputCsvName('channels', gzip)}.`,
639
677
  };
640
678
  }
679
+ /**
680
+ * How many rows of one rate group fall inside the window.
681
+ *
682
+ * Lifted out of `estimateOutput`, which counted this per group to add up, because the count
683
+ * per group is a fact the report needs on its own: a window can hold samples of one rate and
684
+ * none of another, and the file for the second is then written with its header and no data
685
+ * while the run as a whole has rows and says nothing about it.
686
+ */
687
+ function rowsInRange(group, range, recordDuration, recordStarts) {
688
+ let rows = 0;
689
+ for (let record = range.startRecord; record < range.endRecord; record++) {
690
+ const recordStart = recordStarts
691
+ ? (recordStarts[record] ?? record * recordDuration)
692
+ : record * recordDuration;
693
+ rows += countSamplesInRange({
694
+ recordStart,
695
+ rate: group.rate,
696
+ samplesPerRecord: group.samplesPerRecord,
697
+ startSeconds: range.startSeconds,
698
+ endSeconds: range.endSeconds,
699
+ });
700
+ }
701
+ return rows;
702
+ }
641
703
  function estimateOutput(groups, range, recordDuration, recordStarts, bom, layout) {
642
704
  let rows = 0;
643
705
  let bytes = 0;
@@ -646,19 +708,7 @@ function estimateOutput(groups, range, recordDuration, recordStarts, bom, layout
646
708
  // largest group, and the header and mark are counted once rather than once per group.
647
709
  let longRows = 0;
648
710
  for (const group of groups) {
649
- let groupRows = 0;
650
- for (let record = range.startRecord; record < range.endRecord; record++) {
651
- const recordStart = recordStarts
652
- ? (recordStarts[record] ?? record * recordDuration)
653
- : record * recordDuration;
654
- groupRows += countSamplesInRange({
655
- recordStart,
656
- rate: group.rate,
657
- samplesPerRecord: group.samplesPerRecord,
658
- startSeconds: range.startSeconds,
659
- endSeconds: range.endSeconds,
660
- });
661
- }
711
+ const groupRows = rowsInRange(group, range, recordDuration, recordStarts);
662
712
  if (layout === 'long') {
663
713
  // A row per sample per channel rather than a row per sample time.
664
714
  const groupCells = groupRows * group.channels.length;
@@ -1 +1 @@
1
- {"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/convert/plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAClG,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAgHpE,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAE9C,oFAAoF;AACpF,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAE/C,MAAM,UAAU,SAAS,CAAC,KAAgB,EAAE,UAAuB,EAAE;IACnE,oFAAoF;IACpF,yEAAyE;IACzE,aAAa,CAAC,OAAO,CAAC,CAAC;IACvB,2FAA2F;IAC3F,0FAA0F;IAC1F,kCAAkC;IAClC,eAAe,CAAC,KAAK,CAAC,CAAC;IAEvB,MAAM,WAAW,GAAiB,EAAE,CAAC;IACrC,MAAM,WAAW,GAAG,gBAAgB,CA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QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACvE,IAAI,GAAG;YAAE,KAAK,IAAI,SAAS,CAAC;IAC9B,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,CAAC;AAC3D,CAAC","sourcesContent":["/**\n * Turning a request into a concrete conversion plan.\n *\n * The plan is where the tool's central promise is enforced: channels recorded at\n * different sampling rates are never merged into one table. A single wide CSV can\n * only hold mixed rates by inventing samples for the slow channels — MNE, for\n * instance, expands three genuine 1 Hz temperature readings into 768 interpolated\n * values without warning. Instead each distinct rate gets its own file, so every\n * number in every output file is a number that was actually recorded.\n */\n\nimport type { Diagnostic } from '../edf/errors.js';\nimport type { EdfSignal } from '../edf/header.js';\nimport { formatRate, formatRates } from '../edf/header.js';\nimport { decimalsAreClamped, decimalsForSignal, makeScaler } from '../edf/scale.js';\nimport { UTF8_BOM, csvRow, escapeCsvField } from '../format/csv.js';\nimport { counted, grouped, listed } from '../format/list.js';\nimport { fixed, plainSeconds, timeDecimals } from '../format/number.js';\nimport { TIME_COLUMN, buildColumnNames, renamedByCollision, selectChannels } from './channels.js';\nimport { assertOptions, assertPlanInput } from './options.js';\nimport { countSamplesInRange, resolveRange } from './time-range.js';\nimport type { ResolvedRange } from './time-range.js';\n\nexport interface PlannedChannel {\n signal: EdfSignal;\n column: string;\n decimals: number;\n}\n\nexport interface RateGroup {\n /** Sampling rate in Hz shared by every channel in this group. */\n rate: number;\n samplesPerRecord: number;\n fileName: string;\n timeDecimals: number;\n channels: PlannedChannel[];\n}\n\nexport interface PlanInput {\n signals: readonly EdfSignal[];\n recordDuration: number;\n recordCount: number;\n hasAnnotationChannel: boolean;\n /**\n * True start time of each data record, supplied for discontinuous files. The\n * requested time window is resolved against these rather than against\n * `recordCount * recordDuration`, which for a file with gaps is the amount of\n * data rather than the span of time it covers.\n */\n recordStarts?: Float64Array | null | undefined;\n}\n\nexport interface PlanOptions {\n channels?: readonly string[] | undefined;\n start?: number | undefined;\n /** The `--start` value exactly as typed, for error messages. */\n startText?: string | undefined;\n duration?: number | undefined;\n /** The `--duration` value exactly as typed, for error messages. */\n durationText?: string | undefined;\n end?: number | undefined;\n /** The `--end` value exactly as typed, for error messages. */\n endText?: string | undefined;\n annotationsOnly?: boolean | undefined;\n /** Force a fixed number of decimals instead of deriving it per channel. */\n decimals?: number | undefined;\n /** Compress each CSV with gzip, giving every one of them a `.gz` name. */\n gzip?: boolean | undefined;\n /** Start each CSV with a UTF-8 byte order mark, so Excel reads it as UTF-8. */\n bom?: boolean | undefined;\n /**\n * How the samples are arranged in the CSV.\n *\n * `'wide'`, the default, gives one column per channel and one file per sampling rate.\n * `'long'` gives one file, three columns — `time_s`, `channel`, `value` — and one row per\n * sample. See ConversionPlan.layout for why that is the only way to put channels recorded\n * at different rates in one table without inventing samples.\n */\n layout?: 'wide' | 'long' | undefined;\n /**\n * Whether the one table this produces goes to stdout rather than to a directory.\n *\n * Read only by the warnings that name where their rows land. Nothing about the plan itself\n * changes — `--stdout` is refused unless the recording makes exactly one table — but three\n * of those warnings named `signals.csv`, a file such a run never writes.\n */\n toStdout?: boolean | undefined;\n}\n\nexport interface ConversionPlan {\n groups: RateGroup[];\n /**\n * How the samples are arranged. `'wide'` is a column per channel and a file per rate;\n * `'long'` is `time_s,channel,value`, one row per sample, all rates in one file.\n *\n * The wide layout has to split a mixed-rate recording across files: a 100 Hz channel and\n * a 1 Hz channel share no rows, and putting them in one wide table means either 99 empty\n * cells out of every hundred or inventing the samples that would fill them. In the long\n * layout each sample carries its own time, so nothing has to line up and nothing is\n * invented — which also makes it the one layout `--stdout` can stream for such a file.\n */\n layout: 'wide' | 'long';\n\n /**\n * Whether the CSVs will be compressed.\n *\n * Recorded rather than inferred from the group file names. Under `--annotations-only`\n * there are no groups to read it off, and `--info` named `annotations.csv` for a run that\n * wrote `annotations.csv.gz`.\n */\n gzip: boolean;\n range: ResolvedRange;\n columnNames: Map<number, string>;\n writeSignals: boolean;\n diagnostics: Diagnostic[];\n estimate: OutputEstimate;\n}\n\nexport interface OutputEstimate {\n /** Total data rows across every signal file. */\n rows: number;\n /**\n * Approximate size of the signal CSVs as CSV text, which under `gzip` is not their size on\n * disk: what is counted here is what the compressor is handed, and the file holds what it\n * produces. `--info` writes \"before compression\" beside this number for that reason, and\n * `infoJson` calls it a character count.\n */\n bytes: number;\n /** True when any single file would exceed Excel's row limit. */\n exceedsSpreadsheetLimit: boolean;\n}\n\nconst BOM_BYTES = Buffer.byteLength(UTF8_BOM);\n\n/** Excel and most spreadsheet tools stop at 1,048,576 rows including the header. */\nexport const SPREADSHEET_ROW_LIMIT = 1_048_576;\n\nexport function buildPlan(input: PlanInput, options: PlanOptions = {}): ConversionPlan {\n // First, and before a directory is created or a stream opened, so a rejected option\n // leaves nothing behind. See assertOptions for what used to get through.\n assertOptions(options);\n // And the argument in front of it, which carries the numbers every figure below is derived\n // from — and was never looked at. See assertPlanInput for what a plan made of two missing\n // ones said about the conversion.\n assertPlanInput(input);\n\n const diagnostics: Diagnostic[] = [];\n const columnNames = buildColumnNames(input.signals);\n\n // A channel whose own label was taken by something else in the header. Usually that is\n // another channel's disambiguating suffix — the duplicate-label warning is about the labels\n // that collided, this is about the channel that lost its name to them. The other way is a\n // channel labelled `time_s`, where what took the name is the time column itself, which every\n // signals.csv begins with and no file supplies.\n /*\n \"so its column is\" was a sentence about the wide layout, printed in both.\n\n A long signals.csv has three columns — time_s, channel, value — and none of them is a\n label: a channel appears there as a value in the `channel` column. So a `--layout long`\n run was told that a column had been renamed to avoid colliding with a column neither of\n them has, under a hint promising that \"column names are unique\" about a set of three\n fixed strings the file never got from the header.\n\n The rename is right in both layouts, which is why only the noun moves. The names have to\n agree between the `channel` cells and channels.csv and across runs, and the `pivot` the\n documentation gives for turning a long table back into a wide one would otherwise put a\n `time_s` column against a `time_s` index — the collision one step later.\n */\n const inLongLayout = (options.layout ?? 'wide') === 'long';\n const writeSignals = options.annotationsOnly !== true;\n const channelsFile = outputCsvName('channels', options.gzip === true);\n for (const signal of renamedByCollision(input.signals, columnNames)) {\n const taker =\n signal.label === TIME_COLUMN\n ? 'the name of the time column every signals.csv starts with'\n : `also the column name another channel's \"_ch\" suffix produces`;\n /*\n And the third place a renamed channel can be named, which is the only one left when no\n signal table is written at all.\n\n 0.8.24 gave this sentence a long-layout branch, because a long signals.csv names a\n channel in its `channel` column rather than in a column of its own. `--annotations-only`\n writes neither: it writes channels.csv and annotations.csv, and the rename shows up in\n the `column` cell of the first. So the mode that never gets a signal table was told its\n column had been renamed, by a run that wrote no column anywhere.\n\n The rename still happens and still matters — the names have to agree with channels.csv\n and across runs, which is the reason the paragraph above gives.\n */\n const named = !writeSignals\n ? `it is named \"${columnNames.get(signal.index)}\" in ${channelsFile}'s column cell`\n : inLongLayout\n ? `it is named \"${columnNames.get(signal.index)}\" in the channel column`\n : `its column is \"${columnNames.get(signal.index)}\"`;\n diagnostics.push({\n code: 'DUPLICATE_LABEL',\n severity: 'warning',\n message: `Signal ${signal.index} is labelled \"${signal.label}\", which is ${taker}, so ${named}.`,\n /*\n And the name that file is written under, which `--gzip` changes.\n\n `outputCsvName` exists because \"`--info` named `annotations.csv` for a run that wrote\n `annotations.csv.gz`\", and 0.8.48 took the two warnings in `run.ts` through it. These\n two hints send a reader to a file by name — it is the whole advice — and named the one\n a `--gzip` run does not write, four lines above a summary listing `channels.csv.gz`.\n */\n hint:\n inLongLayout || !writeSignals\n ? `Channel names are unique; look this channel up in ${channelsFile} by its signal_index.`\n : `Column names are unique; look this channel up in ${channelsFile} by its signal_index.`,\n });\n }\n\n const range = resolveRange({\n start: options.start,\n startText: options.startText,\n duration: options.duration,\n durationText: options.durationText,\n end: options.end,\n endText: options.endText,\n recordDuration: input.recordDuration,\n recordCount: input.recordCount,\n recordStarts: input.recordStarts,\n });\n\n\n let chosen: EdfSignal[] = input.signals.filter((s) => !s.isAnnotations);\n\n /*\n Channel names are checked even under --annotations-only, where the selection is not\n otherwise used.\n\n Skipping the check meant `--channels TYPO --annotations-only` exited 0 in silence while\n the same typo without the flag was a usage error, and `--channels \"\"` stayed an error\n in both — so a mistyped name was the one form of bad input the tool accepted quietly.\n Everywhere else a term matching nothing is reported rather than ignored; a flag that\n happens not to apply is a poor reason to make an exception.\n */\n if (options.channels && options.channels.length > 0) {\n const selection = selectChannels(input.signals, options.channels);\n if (writeSignals) chosen = selection.signals;\n for (const { term, matched } of selection.ambiguous) {\n diagnostics.push({\n code: 'DUPLICATE_LABEL',\n severity: 'warning',\n message:\n `\"${term}\" matches ${counted(matched.length, 'channel')} (positions ` +\n `${listed(matched.map((s) => `#${s.index}`))}); all of them were selected.`,\n hint: `Use --channels \"#${matched[0]?.index ?? 0}\" to pick just one.`,\n });\n }\n }\n\n const layout = options.layout ?? 'wide';\n const groups = writeSignals\n ? groupByRate(chosen, columnNames, options.decimals, options.gzip === true, layout)\n : [];\n const estimate = estimateOutput(\n groups,\n range,\n input.recordDuration,\n input.recordStarts,\n options.bom === true,\n layout,\n );\n\n /*\n The mixed-rate warning describes what this conversion does, not what the file holds.\n\n The header parser raises its own, which is right for `parseHeader` — but it sees every\n channel and knows nothing about `--channels`. Converting one channel out of a three-rate\n recording therefore announced \"3 different sampling rates ... written to one file per\n rate\" over a run that wrote one file, in the same output where `--info` had already\n marked the other two \"(not selected)\". Selecting two of the three was wrong the other\n way: still \"3\".\n\n Callers combining these with a file's own diagnostics drop that copy in favour of this\n one; see `withoutFileRateWarning`.\n */\n if (groups.length > 1) {\n diagnostics.push({\n code: 'MIXED_SAMPLING_RATES',\n severity: 'warning',\n message:\n `Channels use ${counted(groups.length, 'different sampling rate')} ` +\n `(${listed(formatRates(groups.map((g) => g.rate)).map((r) => `${r} Hz`))}).`,\n hint:\n layout === 'long'\n ? 'They share one table, each row carrying its own time, so no channel is resampled.'\n : 'They are written to one file per rate so no channel is resampled.',\n });\n }\n\n /*\n A time column that cannot tell two samples apart.\n\n Sample times are written to at most fifteen decimal places, which separates everything a\n terminating rate can reach — every power of two through 32768 Hz and far past it. Below\n that interval the column repeats: at 3e15 Hz, whose reciprocal never terminates, the rows\n of one record carry the same time_s, so joining or plotting on it silently collapses\n samples that are genuinely distinct. Nothing is lost from the file — every sample is\n there, in order — but the column stops being an identifier, and that is worth saying\n rather than leaving to be discovered.\n\n This said nine places and a gigahertz, and illustrated it with 1 ns records — all three of\n which stopped being true when 0.4.55 raised the search bound. Fifteen places resolve\n 1e-15 s, so a nanosecond interval is written exactly and that recording raises nothing at\n all. warnings-and-errors.md was corrected then and carries a note saying so; the comment\n it was written from was not, and the hint printed four lines below here has said \"the\n fifteen places a double can hold exactly\" ever since.\n */\n /*\n Where the rows a warning is about actually land.\n\n Three warnings below name `group.fileName`, which is the file the wide layout writes — and\n under `--stdout` no file is written at all. `repeating-fast.edf --info --stdout` printed\n both halves two lines apart:\n\n 0 ch1 ch1 uV 3000000000000000 Hz -100 to 100 (stdout)\n warning: Channels at 3000000000000000 Hz sample faster than the time column can\n distinguish, so consecutive rows in signals.csv carry the same time_s value.\n\n The OUTPUT column has said `(stdout)` since 0.8.31. The warning under it did not, so a\n reader is told the rows go to the terminal and then sent to look in a file for them.\n */\n const destination = (group: RateGroup): string =>\n options.toStdout === true ? 'the CSV on stdout' : group.fileName;\n\n for (const group of groups) {\n const step = group.rate > 0 ? 1 / group.rate : 0;\n /*\n The limit of the same failure, which read as the absence of it.\n\n `samplesPerRecord / recordDuration` is a double, and a record duration of 1e-308 with\n four samples in it is Infinity. `1 / Infinity` is 0, so `step > 0` was false and this\n said nothing — while every sample was dropped, the run exited 0, and the only warning\n printed was EMPTY_WINDOW's \"This recording's 2 data records carry no samples in range\",\n which is untrue twice over: the records carry eight samples and no range was asked for.\n\n One power of ten away, at 1e-300, the rate is 4e300 and the file converts with the\n warning below. Same guard `decimalsAreClamped` had before 0.5.83, in the column next\n door: a step of exactly zero means no resolution at all, not nothing to report.\n\n Its own branch because the hint below is false here — no rows are written at all, so\n \"Every sample is written, in order\" would be the third untrue sentence.\n */\n if (!Number.isFinite(group.rate)) {\n diagnostics.push({\n code: 'TIME_RESOLUTION',\n severity: 'warning',\n message:\n `Channels in ${destination(group)} work out to a sampling rate of ${formatRate(group.rate)} Hz ` +\n `— their samples per record over a record duration too small to divide into — so ` +\n `their samples cannot be placed in time and no rows are written for them.`,\n hint:\n 'Check the record duration in the header. One power of ten larger and the same ' +\n 'file converts, with consecutive rows carrying the same time_s.',\n });\n } else if (step > 0 && step < 10 ** -group.timeDecimals) {\n diagnostics.push({\n code: 'TIME_RESOLUTION',\n severity: 'warning',\n message:\n `Channels at ${formatRate(group.rate)} Hz sample faster than the time column can ` +\n `distinguish, so consecutive rows in ${destination(group)} carry the same time_s value.`,\n /*\n \"or convert one rate at a time with --channels\" was advice that does nothing.\n\n It parses, it runs, it exits 0, and the warning comes back word for word — so\n somebody who followed it had every reason to think the column had been fixed. In\n the wide layout each rate already has its own file and its own precision, and\n `timeDecimals` is a function of the rate alone, so a narrowed conversion writes the\n same column it wrote before. In the long layout the shared column takes the finest\n precision *in the conversion*, and dropping rates can only make it coarser — never\n fine enough to separate samples that were already inseparable.\n\n Nor is there another option that would: --decimals sets the value precision and\n says so, and every rate that reaches this warning has already been given the\n fifteen places that are the ceiling. The first sentence was the whole of the\n answer, so it is the whole of the hint.\n */\n hint:\n 'Every sample is written, in order. Use the row number rather than time_s to tell ' +\n 'them apart: the column already carries the fifteen places a double can hold ' +\n 'exactly, so no option or selection separates them.',\n });\n }\n }\n\n /*\n The same failure as TIME_RESOLUTION, one column over.\n\n A channel whose quantization step is below 1e-98 needs more decimals than `toFixed` can\n print, so consecutive digital codes round to the same text and the arithmetic the FAQ\n gives for recovering them stops working. That used to happen at 1e-20 and silently — see\n MAX_DERIVED_DECIMALS. It is rare now, but \"rare\" is the reason to say so rather than the\n reason not to.\n\n Asked of the ceiling, not of the precision in use, and so asked whatever `--decimals`\n says. `--decimals 2` on a channel needing 3 is a trade the caller made knowingly, and\n reporting it was reporting the flag back at the person who typed it — every channel of an\n ordinary EEG raised this, and since --strict turns any diagnostic into exit 1,\n `--decimals 2 --strict` could not succeed on any recording at all.\n\n 0.5.10 fixed that by skipping the check whenever `--decimals` was given, which suppressed\n the real case along with the false one: at `--decimals 20` a channel stepping by 1e-106\n printed every code it had as `0.00000000000000000000`, and said nothing. The question is\n not who chose the precision. It is whether any precision the tool can print would\n separate consecutive codes.\n */\n for (const group of groups) {\n const short = group.channels.filter((c) => decimalsAreClamped(c.signal));\n if (short.length === 0) continue;\n diagnostics.push({\n code: 'VALUE_RESOLUTION',\n severity: 'warning',\n message:\n `${listed(short.map((c) => c.column))} ${short.length === 1 ? 'steps' : 'step'} by less ` +\n `than any number of decimals this can print, so some consecutive samples round to ` +\n `the same value in ${destination(group)}.`,\n hint:\n 'Every sample is written, in order, and the physical values are computed at full ' +\n 'precision either way. What is lost is only in the printed text.',\n });\n }\n\n /*\n A window that selects nothing is a fact about the plan, so the plan is where it is raised.\n\n It was pushed by `convert()` from the rows actually written, which meant `--info` never\n said it: `--info --start 0.31 --end 0.39` on a 10 Hz recording printed \"Would write 0\n rows\" with no warning and exited 0 under `--strict`, while converting the same window\n warned and exited 1. The hint says \"Run with --info to see where the records actually\n sit\" — advising the reader into the one mode that would not tell them.\n\n The estimate's row count is exact, which `npm run estimate` checks across every fixture\n crossed with every option set, so raising it from the plan says the same thing the rows\n would have.\n */\n /*\n Not when a rate above already explained it. EMPTY_WINDOW says the records \"carry no\n samples in range\", and on a recording whose rate overflowed to Infinity that is untrue\n twice: the records carry their samples, and no range was asked for. The rate warning is\n the accurate account of the same zero.\n */\n const untimeable = groups.some((group) => !Number.isFinite(group.rate));\n if (writeSignals && groups.length > 0 && estimate.rows === 0 && !untimeable) {\n diagnostics.push(\n emptyWindow(range, input.recordCount, groups, options.gzip === true, options.toStdout === true),\n );\n }\n\n if (estimate.exceedsSpreadsheetLimit) {\n /*\n And the file it is about, which `--stdout` does not write either.\n\n \"At least one output file will have more than 1,048,576 rows\" was said to a run whose\n summary reads \"Wrote 1,075,200 rows to stdout\", advising the reader to \"read the file\n with pandas or R\" — there is no file, and what a spreadsheet can open is not the question\n a pipe raises. The count is the useful half and it does not change; the noun and the\n advice do. Redirecting the stream is how it becomes a file a spreadsheet would refuse,\n which is what the sentence says now.\n */\n const toStdout = options.toStdout === true;\n diagnostics.push({\n code: 'LARGE_OUTPUT',\n severity: 'warning',\n message: toStdout\n ? `The CSV on stdout will have more than ${grouped(SPREADSHEET_ROW_LIMIT)} rows, ` +\n `which is more than Excel or Numbers can open.`\n : `At least one output file will have more than ${grouped(SPREADSHEET_ROW_LIMIT)} ` +\n `rows, which is more than Excel or Numbers can open.`,\n hint: toStdout\n ? 'Use --start and --duration to stream a section, or read the stream with pandas ' +\n 'or R rather than redirecting it into a spreadsheet.'\n : 'Use --start and --duration to convert a section, or read the file with pandas or R.',\n });\n }\n\n return { groups, layout, gzip: options.gzip === true, range, columnNames, writeSignals, diagnostics, estimate };\n}\n\n/**\n * Partition channels by sampling rate, largest first.\n *\n * The common case — every channel at one rate — collapses to a single group and a\n * single `signals.csv`, so the honest behaviour costs nothing when there is nothing\n * to be honest about.\n */\nfunction groupByRate(\n signals: readonly EdfSignal[],\n columnNames: Map<number, string>,\n forcedDecimals: number | undefined,\n gzip: boolean,\n layout: 'wide' | 'long',\n): RateGroup[] {\n const byRate = new Map<number, EdfSignal[]>();\n for (const signal of signals) {\n // A channel with no samples has no sampling rate to group by, and would\n // otherwise produce an empty \"0hz\" file. The header parser already warned.\n if (signal.samplesPerRecord === 0) continue;\n const bucket = byRate.get(signal.samplingRate);\n if (bucket) bucket.push(signal);\n else byRate.set(signal.samplingRate, [signal]);\n }\n\n const rates = [...byRate.keys()].sort((a, b) => b - a);\n // The long layout writes one table whatever the rates are, so every group names it.\n const single = rates.length === 1 || layout === 'long';\n\n /*\n Two distinct rates can produce the same slug, because the slug rounds to six decimal\n places. Rates come from samplesPerRecord / recordDuration and every channel shares the\n record duration, so the closest two rates can be is 1 / recordDuration — which drops\n below 1e-6 once a record is longer than about eleven days. Absurd, but the header\n permits it, and the failure was silent and destructive: both groups opened a write\n stream on the same path, so the file ended up holding interleaved rows from both\n channels under a header naming only one of them.\n\n Distinct rates therefore get distinct files, always. The suffix is only ever reached by\n a collision, so ordinary recordings keep the names they have always had.\n\n Naming from the whole set of rates at once removes most of those collisions before the\n suffix has to. Rounding each rate on its own gave 1e-6 Hz and 1.25e-6 Hz the same slug,\n and the numbering below then produced signals_0_000001hz.csv and signals_0_000001hz_2.csv\n — two files that no longer overwrite each other, but of which only one is named for the\n rate it holds. The suffix stays as the backstop for anything this still cannot separate.\n */\n const suffix = gzip ? '.csv.gz' : '.csv';\n const slugs = formatRates(rates).map(slugFor);\n const used = new Set<string>();\n const uniqueName = (index: number): string => {\n const base = `signals_${slugs[index]}`;\n let name = `${base}${suffix}`;\n for (let n = 2; used.has(name); n++) name = `${base}_${n}${suffix}`;\n used.add(name);\n return name;\n };\n\n return rates.map((rate, index) => {\n const members = byRate.get(rate) ?? [];\n const first = members[0];\n return {\n rate,\n samplesPerRecord: first ? first.samplesPerRecord : 0,\n fileName: single ? `signals${suffix}` : uniqueName(index),\n /*\n In the long layout every rate shares a `time_s` column, so they share its precision:\n the finest any of them needs. Writing 100 Hz at three places and 256 Hz at eight in\n the same column would make the column's meaning depend on the row.\n */\n timeDecimals: layout === 'long' ? Math.max(...rates.map(timeDecimals)) : timeDecimals(rate),\n channels: members.map((signal) => ({\n signal,\n column: columnNames.get(signal.index) ?? `signal_${signal.index}`,\n decimals: forcedDecimals ?? decimalsForSignal(signal),\n })),\n };\n });\n}\n\n/**\n * A file's diagnostics with the header's mixed-rate warning removed.\n *\n * `buildPlan` raises that warning for the channels actually being converted, so keeping both\n * would either duplicate it or contradict it. The header parser's copy stays where it is, for\n * callers reading a header without planning a conversion.\n */\nexport function withoutFileRateWarning(diagnostics: readonly Diagnostic[]): Diagnostic[] {\n return diagnostics.filter((d) => d.code !== 'MIXED_SAMPLING_RATES');\n}\n\n/** `256hz`, `12_5hz` — safe in a filename on every platform. */\nfunction slugFor(rendered: string): string {\n return `${rendered.replace('.', '_')}hz`;\n}\n\n/**\n * One rate's slug, rendered on its own.\n *\n * The names a conversion writes come from `formatRates` over the whole set, which widens the\n * precision until rates that differ read as differing — so on a recording carrying both,\n * 1e-6 Hz and 1.25e-6 Hz are `0_000001hz` and `0_00000125hz`. This renders one rate with no\n * set to separate it from, and both of those come back `0_000001hz`.\n *\n * Which is right for the question it is asked, and was worth saying: a caller reaching for the\n * exported slug function to predict a filename got a name the tool does not write, on exactly\n * the rates the reference warns `formatRate` collapses. The two now spell a rendered rate the\n * same way, through the line above, so only the rendering differs and nothing can drift.\n */\nexport function rateSlug(rate: number): string {\n // `formatRate` checks the argument; the two spell a rendered rate the same way, so they\n // refuse the same values too.\n return slugFor(formatRate(rate));\n}\n\n/**\n * The name a CSV is written under, which `--gzip` changes.\n *\n * `plan.gzip` is recorded rather than inferred because \"`--info` named `annotations.csv` for a\n * run that wrote `annotations.csv.gz`\" — and the warnings *about* those files went on doing it\n * after the file list stopped. A run that says \"annotations.csv holds its header and no rows\"\n * three lines above a summary listing `annotations.csv.gz` names two files and writes one.\n *\n * Written once here because three places already computed it by hand.\n */\nexport function outputCsvName(base: string, gzip: boolean): string {\n return `${base}${gzip ? '.csv.gz' : '.csv'}`;\n}\n\n/**\n * Characters the time column occupies, measured over both ends of the window and signed.\n *\n * Both estimates measured the column against `range.endSeconds` alone, unsigned — while the\n * value column two lines below already allowed for a sign when either bound is negative. A\n * recording timed from before zero prints `-100.000` where that budgeted for `100.000`, so\n * every row came out a byte short: 203 predicted against 216 written, and 131 against 159 on\n * a shorter one. An estimate reading low is the one direction the correctness page says it\n * never goes — \"no byte count under the truth\" is what the estimate sweep asserts over every\n * fixture, and no fixture began before zero.\n *\n * The far end is not always the widest: from -100s to -97s it is the start.\n */\nfunction timeWidthFor(range: ResolvedRange, decimals: number): number {\n return widthOf(\n Math.max(Math.abs(range.startSeconds), Math.abs(range.endSeconds)),\n decimals,\n range.startSeconds < 0 || range.endSeconds < 0,\n );\n}\n\n/**\n * How wide a value cell can print, from the channel's own calibration.\n *\n * Zero when that calibration holds no mapping — a digital range of one point, a physical span\n * that overflows or underflows a double — because such a channel writes an empty cell for\n * every sample rather than a number, which is the whole point of `makeScaler` returning NaN.\n *\n * Budgeting a full-width number for one broke the bound this estimate states beside never\n * reading low. A single-channel recording whose digital minimum equals its maximum, at\n * `--decimals 20`, was predicted at 651 bytes and wrote 151 — 4.31x, against a documented wall\n * of three. No fixture reaches it because `degenerate-range.edf` has two ordinary channels\n * beside its flat one, whose real cells pad the total back under the wall.\n *\n * Asked of `makeScaler` rather than restated here, for the reason `csvRow` measures the header\n * row: the function that decides whether a cell gets a number is the one that can still be\n * right when the rule changes. Both ends of the declared range are probed, so a calibration\n * that is finite anywhere keeps its full width and the estimate cannot start reading low.\n */\nfunction valueWidthOf(channel: PlannedChannel): number {\n const scale = makeScaler(channel.signal);\n const blank =\n !Number.isFinite(scale(channel.signal.digitalMin)) &&\n !Number.isFinite(scale(channel.signal.digitalMax));\n if (blank) return 0;\n return widthOf(\n Math.max(Math.abs(channel.signal.physicalMin), Math.abs(channel.signal.physicalMax)),\n channel.decimals,\n channel.signal.physicalMin < 0 || channel.signal.physicalMax < 0,\n );\n}\n\n/** Integer digits in `Number.MAX_VALUE`, which is the widest a finite double prints. */\nconst MAX_DOUBLE_DIGITS = 309;\n\n/** Characters a fixed-decimal number of this magnitude occupies, sign included. */\nfunction widthOf(magnitude: number, decimals: number, signed = false): number {\n const size = Math.abs(magnitude);\n const sign = signed ? 1 : 0;\n const fraction = decimals > 0 ? 1 + decimals : 0;\n\n /*\n Cells are written with toFixed, which rounds. Taking the integer digits from the floor of\n the bound therefore under-counted whenever rounding carried into a new digit: a channel\n bounded at 9999.999 and written to zero decimals produces \"10000\", five characters where\n the floor of 9999.999 suggests four. Every cell on such a channel was a byte short, and\n `--info` reported 127 KB for a file that came out 131 KB.\n\n Measuring the bound as rendered removes that. toFixed switches to exponential notation\n past 1e21, so the arithmetic form still covers magnitudes beyond it.\n */\n /*\n A bound that is not a number bounds nothing, so the widest cell it can produce is taken\n instead: 309 digits, which is `Number.MAX_VALUE` written out.\n\n One digit was budgeted, and the estimate read low — the one direction the correctness page\n says it never goes. `latest` is `recordCount * recordDuration`, so a header stating a\n record duration near the top of a double overflows it while every sample time under it\n stays finite and prints in full. Three records of 1e308, eight samples:\n\n Would write 8 rows, roughly 115 B. signals.csv is 2,244 bytes.\n\n Each of those rows carries a 313-character time cell. `fixed` writes an empty cell for a\n value that is itself non-finite, so nothing wider than this is ever printed.\n */\n if (!Number.isFinite(size)) return sign + MAX_DOUBLE_DIGITS + fraction;\n if (size < 1e21) return sign + size.toFixed(Math.min(decimals, 100)).length;\n return sign + (Math.floor(Math.log10(size)) + 1) + fraction;\n}\n\n/**\n * Raised when the conversion had signal tables to fill and put no data rows in any of them.\n *\n * A window can land where there are no samples without being past the end of the recording:\n * between the last sample and the nominal end of the last record, or — on a discontinuous\n * file — inside a gap. `--start 2 --end 10` on a recording whose records sit at 0s, 1s and\n * 10s asks for eight seconds that contain no data at all.\n *\n * What came out was a signals.csv holding its header and nothing else, exit 0, no warning,\n * and `--strict` passing. The closing summary does say \"signals.csv 0 rows\" and --json\n * carries `rows: 0`, so it was not quite invisible — but a header-only file is exactly what\n * a successful extraction of an empty range looks like, and everywhere else that a request\n * produces nothing this tool says so: a --channels term matching nothing is an error, and\n * --annotations-only on a file with no events raises NO_ANNOTATIONS. A warning rather than\n * an error because a batch of five hundred recordings should not stop for one whose gap\n * happens to line up with the window; --strict turns it into a failure for those who want\n * that.\n */\nfunction emptyWindow(\n range: ResolvedRange,\n recordCount: number,\n groups: readonly RateGroup[],\n gzip: boolean,\n toStdout: boolean,\n): Diagnostic {\n const fileCount = groups.length;\n const asked = !range.isWholeRecording;\n /*\n A window narrower than one sample interval, which is the commonest way to get here and\n was the one cause the hint did not name.\n\n Sample times sit on a grid of `1 / rate`, so a half-open window at least one interval\n wide always contains one — which makes the converse exact: on a continuous recording, a\n window inside the recording that selects nothing is a window narrower than the interval.\n `--start 0.31 --end 0.39` on a 10 Hz file is 0.08s of a 0.1s grid, and the hint answered\n \"past the last sample, or inside a gap in a discontinuous file\", neither of which is true\n of it — one being a special case of the same thing and the other belonging to a file\n shape this one does not have.\n\n The fastest rate, since that is the one whose grid is finest: if none of its samples fits,\n none of the slower ones does either.\n */\n const fastest = Math.max(...groups.map((group) => group.rate).filter(Number.isFinite), 0);\n const interval = fastest > 0 ? 1 / fastest : 0;\n const width = range.endSeconds - range.startSeconds;\n const narrow = asked && interval > 0 && width > 0 && width < interval;\n /*\n One rate is one file, which is nearly every recording, and this said \"files\" either way:\n \"so the signal files hold their headers and no data\" over a single signals.csv. The count\n is `plan.groups.length` and the caller has had it all along — it is the same number the\n mixed-rate warning three functions up counts to decide whether to fire at all.\n */\n /*\n And where that header lands, which under `--stdout` is not a file.\n\n `destination` three functions up has said `the CSV on stdout` since the rate warnings were\n taught the difference; this sentence had \"the signal file\" either way, over a run whose own\n summary line reads \"Wrote 0 rows to stdout\" and whose `--info` OUTPUT column reads\n `(stdout)`. The header is still written — it goes to the stream — so what changes is the\n noun, not the claim.\n */\n const tables = toStdout\n ? 'the CSV on stdout carries its header and no data'\n : fileCount === 1\n ? 'the signal file holds its header and no data'\n : 'the signal files hold their headers and no data';\n return {\n code: 'EMPTY_WINDOW',\n severity: 'warning',\n message: asked\n ? `No samples fall inside the requested window (${fixed(range.startSeconds, 3)}s to ` +\n `${fixed(range.endSeconds, 3)}s), so ${tables}.`\n : `This recording's ${counted(recordCount, 'data record')} carry no samples in range, ` +\n `so ${tables}.`,\n hint: asked\n ? /*\n Which of the two it was, rather than the second one always.\n\n A recording does not have to start at zero: its first record's timekeeping TAL is\n what it is timed from, so a file whose records begin at 1000s is asked for with\n `--start 1000`. `--start 0 --end 1` on that file was told \"The window is inside the\n recording but lands where there is no data — past the last sample, or inside a gap\n in a discontinuous file\", when the window sits entirely before the recording and\n neither offered explanation applies to it. A start at or past the *end* is already\n an error, so the window being outside can only mean it is before the beginning.\n */\n range.endSeconds <= range.recordingStartSeconds\n ? `This recording starts at ${fixed(range.recordingStartSeconds, 3)}s, so the whole ` +\n 'window sits before it. --start and --end are read on the recording\\'s own clock, ' +\n 'which --info prints as \"Timed from\".'\n : narrow\n ? `It is ${fixed(width, 3)}s wide and the fastest channel here samples every ` +\n `${plainSeconds(interval)}s, so no sample time falls inside it. Widen it to at least ` +\n 'one sample interval, or convert more of the recording and take the row nearest ' +\n 'the moment you want.'\n : /*\n Advice that does something in the mode it is printed in.\n\n `EMPTY_WINDOW` is a fact about the plan, and `--info` builds the plan — so\n `discontinuous.edf --info --start 4s --end 4.2s` answered with the command that\n had just printed it. 0.8.42 fixed the same loop in channel selection; these are\n the two hints that were left.\n\n The replacement is also the better answer for a conversion. `--info` does not\n print where the records sit: it prints a count, a duration and a time span that\n \"includes discontinuities\". The record positions are in `time_s`, one per row,\n which is what a conversion without a window writes.\n */\n 'The window is inside the recording but lands where there is no data — inside a ' +\n 'gap in a discontinuous file, or past the last sample. Convert without --start ' +\n 'and --end and read time_s to see where the records actually sit.'\n : // The same loop, in the branch where no window was asked for at all.\n 'What the header declares for each channel — its samples per data record — is in ' +\n `the channel table --info prints and in ${outputCsvName('channels', gzip)}.`,\n };\n}\n\nfunction estimateOutput(\n groups: readonly RateGroup[],\n range: ResolvedRange,\n recordDuration: number,\n recordStarts: Float64Array | null | undefined,\n bom: boolean,\n layout: 'wide' | 'long',\n): OutputEstimate {\n let rows = 0;\n let bytes = 0;\n let exceeds = false;\n // One table in the long layout, so the row limit applies to the sum rather than the\n // largest group, and the header and mark are counted once rather than once per group.\n let longRows = 0;\n\n for (const group of groups) {\n let groupRows = 0;\n for (let record = range.startRecord; record < range.endRecord; record++) {\n const recordStart = recordStarts\n ? (recordStarts[record] ?? record * recordDuration)\n : record * recordDuration;\n groupRows += countSamplesInRange({\n recordStart,\n rate: group.rate,\n samplesPerRecord: group.samplesPerRecord,\n startSeconds: range.startSeconds,\n endSeconds: range.endSeconds,\n });\n }\n if (layout === 'long') {\n // A row per sample per channel rather than a row per sample time.\n const groupCells = groupRows * group.channels.length;\n rows += groupCells;\n longRows += groupCells;\n /*\n `time_s,channel,value`: the time, the channel name as it will be escaped into the\n cell, and the widest the value can print. Same over-counting rule as the wide\n layout — the declared physical range bounds a cell, and most samples sit under it.\n */\n const timeWidth = timeWidthFor(range, group.timeDecimals);\n for (const channel of group.channels) {\n const valueWidth = valueWidthOf(channel);\n const nameWidth = Buffer.byteLength(escapeCsvField(channel.column));\n // Two commas and the newline.\n bytes += groupRows * (timeWidth + nameWidth + valueWidth + 3);\n }\n continue;\n }\n\n rows += groupRows;\n if (groupRows + 1 > SPREADSHEET_ROW_LIMIT) exceeds = true;\n\n /*\n Width per cell, from the channel's own calibration rather than a flat allowance.\n\n The old `decimals + 6` budgeted six characters for the sign, integer part and decimal\n point on every channel, whatever it actually held. That over-counted a millivolt\n channel spanning ±5 by four characters a cell and ran 30-55% high across the fixture\n set — on a number people use to decide whether a conversion is worth starting.\n\n The channel's declared physical range is what bounds a cell, so that bound is what is\n used. Most samples sit below it, so this still reads high, which is the direction a\n size estimate should err in.\n\n One case is outside the bound rather than under it: nothing obliges a recording to keep\n its samples inside the digital range it declares, and one that does not maps outside the\n physical range too. Such a file can convert larger than the estimate. Clamping the data\n to make the estimate true is not a trade worth making — the samples are what they are.\n */\n const timeWidth = timeWidthFor(range, group.timeDecimals);\n const cellWidth = group.channels.reduce((sum, c) => sum + valueWidthOf(c), 0);\n // One comma per channel, plus the newline.\n bytes += groupRows * (timeWidth + cellWidth + group.channels.length + 1);\n /*\n The header row, measured as it will be written rather than as the labels are stored.\n\n A column name is quoted when it contains a comma, a quote, a carriage return or a line\n feed, and every quote inside it is doubled. Counting the raw label under-counted\n that row: three channels labelled `a,b,c,d,e`, `x\"y` and `plain` write a 32-byte header\n and were budgeted 27. EDF labels are free text, so commas in them are ordinary — a montage\n written as `EEG Fpz-Cz, ref` is exactly the kind of thing this is for.\n\n csvRow is the function that writes it, so it is the function that measures it. Nothing\n else is in a position to stay correct when the quoting rules change.\n */\n bytes += Buffer.byteLength(csvRow(['time_s', ...group.channels.map((c) => c.column)])) + 1;\n // Three bytes per file under --bom. Small, but exactly known — unlike the sample\n // overshoot two paragraphs up, which is the one thing here that can read under what gets\n // written and cannot be counted in advance. On a one-row conversion three bytes is a\n // tenth of the file.\n if (bom) bytes += BOM_BYTES;\n }\n\n if (layout === 'long' && groups.length > 0) {\n if (longRows + 1 > SPREADSHEET_ROW_LIMIT) exceeds = true;\n bytes += Buffer.byteLength(csvRow(['time_s', 'channel', 'value'])) + 1;\n if (bom) bytes += BOM_BYTES;\n }\n\n return { rows, bytes, exceedsSpreadsheetLimit: exceeds };\n}\n"]}
1
+ {"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/convert/plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAClG,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAgHpE,MAAM,SAAS,GAAG,MAAM,CAAC,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AC,SAAS,GAAG,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACzE;;;;;;;;;;;UAWE;QACF,KAAK,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC3F,iFAAiF;QACjF,yFAAyF;QACzF,qFAAqF;QACrF,qBAAqB;QACrB,IAAI,GAAG;YAAE,KAAK,IAAI,SAAS,CAAC;IAC9B,CAAC;IAED,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3C,IAAI,QAAQ,GAAG,CAAC,GAAG,qBAAqB;YAAE,OAAO,GAAG,IAAI,CAAC;QACzD,KAAK,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACvE,IAAI,GAAG;YAAE,KAAK,IAAI,SAAS,CAAC;IAC9B,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,CAAC;AAC3D,CAAC","sourcesContent":["/**\n * Turning a request into a concrete conversion plan.\n *\n * The plan is where the tool's central promise is enforced: channels recorded at\n * different sampling rates are never merged into one table. A single wide CSV can\n * only hold mixed rates by inventing samples for the slow channels — MNE, for\n * instance, expands three genuine 1 Hz temperature readings into 768 interpolated\n * values without warning. Instead each distinct rate gets its own file, so every\n * number in every output file is a number that was actually recorded.\n */\n\nimport type { Diagnostic } from '../edf/errors.js';\nimport type { EdfSignal } from '../edf/header.js';\nimport { formatRate, formatRates } from '../edf/header.js';\nimport { decimalsAreClamped, decimalsForSignal, makeScaler } from '../edf/scale.js';\nimport { UTF8_BOM, csvRow, escapeCsvField } from '../format/csv.js';\nimport { counted, grouped, listed } from '../format/list.js';\nimport { fixed, plainSeconds, timeDecimals } from '../format/number.js';\nimport { TIME_COLUMN, buildColumnNames, renamedByCollision, selectChannels } from './channels.js';\nimport { assertOptions, assertPlanInput } from './options.js';\nimport { countSamplesInRange, resolveRange } from './time-range.js';\nimport type { ResolvedRange } from './time-range.js';\n\nexport interface PlannedChannel {\n signal: EdfSignal;\n column: string;\n decimals: number;\n}\n\nexport interface RateGroup {\n /** Sampling rate in Hz shared by every channel in this group. */\n rate: number;\n samplesPerRecord: number;\n fileName: string;\n timeDecimals: number;\n channels: PlannedChannel[];\n}\n\nexport interface PlanInput {\n signals: readonly EdfSignal[];\n recordDuration: number;\n recordCount: number;\n hasAnnotationChannel: boolean;\n /**\n * True start time of each data record, supplied for discontinuous files. The\n * requested time window is resolved against these rather than against\n * `recordCount * recordDuration`, which for a file with gaps is the amount of\n * data rather than the span of time it covers.\n */\n recordStarts?: Float64Array | null | undefined;\n}\n\nexport interface PlanOptions {\n channels?: readonly string[] | undefined;\n start?: number | undefined;\n /** The `--start` value exactly as typed, for error messages. */\n startText?: string | undefined;\n duration?: number | undefined;\n /** The `--duration` value exactly as typed, for error messages. */\n durationText?: string | undefined;\n end?: number | undefined;\n /** The `--end` value exactly as typed, for error messages. */\n endText?: string | undefined;\n annotationsOnly?: boolean | undefined;\n /** Force a fixed number of decimals instead of deriving it per channel. */\n decimals?: number | undefined;\n /** Compress each CSV with gzip, giving every one of them a `.gz` name. */\n gzip?: boolean | undefined;\n /** Start each CSV with a UTF-8 byte order mark, so Excel reads it as UTF-8. */\n bom?: boolean | undefined;\n /**\n * How the samples are arranged in the CSV.\n *\n * `'wide'`, the default, gives one column per channel and one file per sampling rate.\n * `'long'` gives one file, three columns — `time_s`, `channel`, `value` — and one row per\n * sample. See ConversionPlan.layout for why that is the only way to put channels recorded\n * at different rates in one table without inventing samples.\n */\n layout?: 'wide' | 'long' | undefined;\n /**\n * Whether the one table this produces goes to stdout rather than to a directory.\n *\n * Read only by the warnings that name where their rows land. Nothing about the plan itself\n * changes — `--stdout` is refused unless the recording makes exactly one table — but three\n * of those warnings named `signals.csv`, a file such a run never writes.\n */\n toStdout?: boolean | undefined;\n}\n\nexport interface ConversionPlan {\n groups: RateGroup[];\n /**\n * How the samples are arranged. `'wide'` is a column per channel and a file per rate;\n * `'long'` is `time_s,channel,value`, one row per sample, all rates in one file.\n *\n * The wide layout has to split a mixed-rate recording across files: a 100 Hz channel and\n * a 1 Hz channel share no rows, and putting them in one wide table means either 99 empty\n * cells out of every hundred or inventing the samples that would fill them. In the long\n * layout each sample carries its own time, so nothing has to line up and nothing is\n * invented — which also makes it the one layout `--stdout` can stream for such a file.\n */\n layout: 'wide' | 'long';\n\n /**\n * Whether the CSVs will be compressed.\n *\n * Recorded rather than inferred from the group file names. Under `--annotations-only`\n * there are no groups to read it off, and `--info` named `annotations.csv` for a run that\n * wrote `annotations.csv.gz`.\n */\n gzip: boolean;\n range: ResolvedRange;\n columnNames: Map<number, string>;\n writeSignals: boolean;\n diagnostics: Diagnostic[];\n estimate: OutputEstimate;\n}\n\nexport interface OutputEstimate {\n /** Total data rows across every signal file. */\n rows: number;\n /**\n * Approximate size of the signal CSVs as CSV text, which under `gzip` is not their size on\n * disk: what is counted here is what the compressor is handed, and the file holds what it\n * produces. `--info` writes \"before compression\" beside this number for that reason, and\n * `infoJson` calls it a character count.\n */\n bytes: number;\n /** True when any single file would exceed Excel's row limit. */\n exceedsSpreadsheetLimit: boolean;\n}\n\nconst BOM_BYTES = Buffer.byteLength(UTF8_BOM);\n\n/** Excel and most spreadsheet tools stop at 1,048,576 rows including the header. */\nexport const SPREADSHEET_ROW_LIMIT = 1_048_576;\n\nexport function buildPlan(input: PlanInput, options: PlanOptions = {}): ConversionPlan {\n // First, and before a directory is created or a stream opened, so a rejected option\n // leaves nothing behind. See assertOptions for what used to get through.\n assertOptions(options);\n // And the argument in front of it, which carries the numbers every figure below is derived\n // from — and was never looked at. See assertPlanInput for what a plan made of two missing\n // ones said about the conversion.\n assertPlanInput(input);\n\n const diagnostics: Diagnostic[] = [];\n const columnNames = buildColumnNames(input.signals);\n\n // A channel whose own label was taken by something else in the header. Usually that is\n // another channel's disambiguating suffix — the duplicate-label warning is about the labels\n // that collided, this is about the channel that lost its name to them. The other way is a\n // channel labelled `time_s`, where what took the name is the time column itself, which every\n // signals.csv begins with and no file supplies.\n /*\n \"so its column is\" was a sentence about the wide layout, printed in both.\n\n A long signals.csv has three columns — time_s, channel, value — and none of them is a\n label: a channel appears there as a value in the `channel` column. So a `--layout long`\n run was told that a column had been renamed to avoid colliding with a column neither of\n them has, under a hint promising that \"column names are unique\" about a set of three\n fixed strings the file never got from the header.\n\n The rename is right in both layouts, which is why only the noun moves. The names have to\n agree between the `channel` cells and channels.csv and across runs, and the `pivot` the\n documentation gives for turning a long table back into a wide one would otherwise put a\n `time_s` column against a `time_s` index — the collision one step later.\n */\n const inLongLayout = (options.layout ?? 'wide') === 'long';\n const writeSignals = options.annotationsOnly !== true;\n const channelsFile = outputCsvName('channels', options.gzip === true);\n for (const signal of renamedByCollision(input.signals, columnNames)) {\n const taker =\n signal.label === TIME_COLUMN\n ? 'the name of the time column every signals.csv starts with'\n : `also the column name another channel's \"_ch\" suffix produces`;\n /*\n And the third place a renamed channel can be named, which is the only one left when no\n signal table is written at all.\n\n 0.8.24 gave this sentence a long-layout branch, because a long signals.csv names a\n channel in its `channel` column rather than in a column of its own. `--annotations-only`\n writes neither: it writes channels.csv and annotations.csv, and the rename shows up in\n the `column` cell of the first. So the mode that never gets a signal table was told its\n column had been renamed, by a run that wrote no column anywhere.\n\n The rename still happens and still matters — the names have to agree with channels.csv\n and across runs, which is the reason the paragraph above gives.\n */\n const named = !writeSignals\n ? `it is named \"${columnNames.get(signal.index)}\" in ${channelsFile}'s column cell`\n : inLongLayout\n ? `it is named \"${columnNames.get(signal.index)}\" in the channel column`\n : `its column is \"${columnNames.get(signal.index)}\"`;\n diagnostics.push({\n code: 'DUPLICATE_LABEL',\n severity: 'warning',\n message: `Signal ${signal.index} is labelled \"${signal.label}\", which is ${taker}, so ${named}.`,\n /*\n And the name that file is written under, which `--gzip` changes.\n\n `outputCsvName` exists because \"`--info` named `annotations.csv` for a run that wrote\n `annotations.csv.gz`\", and 0.8.48 took the two warnings in `run.ts` through it. These\n two hints send a reader to a file by name — it is the whole advice — and named the one\n a `--gzip` run does not write, four lines above a summary listing `channels.csv.gz`.\n */\n hint:\n inLongLayout || !writeSignals\n ? `Channel names are unique; look this channel up in ${channelsFile} by its signal_index.`\n : `Column names are unique; look this channel up in ${channelsFile} by its signal_index.`,\n });\n }\n\n const range = resolveRange({\n start: options.start,\n startText: options.startText,\n duration: options.duration,\n durationText: options.durationText,\n end: options.end,\n endText: options.endText,\n recordDuration: input.recordDuration,\n recordCount: input.recordCount,\n recordStarts: input.recordStarts,\n });\n\n\n let chosen: EdfSignal[] = input.signals.filter((s) => !s.isAnnotations);\n\n /*\n Channel names are checked even under --annotations-only, where the selection is not\n otherwise used.\n\n Skipping the check meant `--channels TYPO --annotations-only` exited 0 in silence while\n the same typo without the flag was a usage error, and `--channels \"\"` stayed an error\n in both — so a mistyped name was the one form of bad input the tool accepted quietly.\n Everywhere else a term matching nothing is reported rather than ignored; a flag that\n happens not to apply is a poor reason to make an exception.\n */\n if (options.channels && options.channels.length > 0) {\n const selection = selectChannels(input.signals, options.channels);\n if (writeSignals) chosen = selection.signals;\n for (const { term, matched } of selection.ambiguous) {\n diagnostics.push({\n code: 'DUPLICATE_LABEL',\n severity: 'warning',\n message:\n `\"${term}\" matches ${counted(matched.length, 'channel')} (positions ` +\n `${listed(matched.map((s) => `#${s.index}`))}); all of them were selected.`,\n hint: `Use --channels \"#${matched[0]?.index ?? 0}\" to pick just one.`,\n });\n }\n }\n\n const layout = options.layout ?? 'wide';\n const groups = writeSignals\n ? groupByRate(chosen, columnNames, options.decimals, options.gzip === true, layout)\n : [];\n const estimate = estimateOutput(\n groups,\n range,\n input.recordDuration,\n input.recordStarts,\n options.bom === true,\n layout,\n );\n\n /*\n The mixed-rate warning describes what this conversion does, not what the file holds.\n\n The header parser raises its own, which is right for `parseHeader` — but it sees every\n channel and knows nothing about `--channels`. Converting one channel out of a three-rate\n recording therefore announced \"3 different sampling rates ... written to one file per\n rate\" over a run that wrote one file, in the same output where `--info` had already\n marked the other two \"(not selected)\". Selecting two of the three was wrong the other\n way: still \"3\".\n\n Callers combining these with a file's own diagnostics drop that copy in favour of this\n one; see `withoutFileRateWarning`.\n */\n if (groups.length > 1) {\n diagnostics.push({\n code: 'MIXED_SAMPLING_RATES',\n severity: 'warning',\n message:\n `Channels use ${counted(groups.length, 'different sampling rate')} ` +\n `(${listed(formatRates(groups.map((g) => g.rate)).map((r) => `${r} Hz`))}).`,\n hint:\n layout === 'long'\n ? 'They share one table, each row carrying its own time, so no channel is resampled.'\n : 'They are written to one file per rate so no channel is resampled.',\n });\n }\n\n /*\n A time column that cannot tell two samples apart.\n\n Sample times are written to at most fifteen decimal places, which separates everything a\n terminating rate can reach — every power of two through 32768 Hz and far past it. Below\n that interval the column repeats: at 3e15 Hz, whose reciprocal never terminates, the rows\n of one record carry the same time_s, so joining or plotting on it silently collapses\n samples that are genuinely distinct. Nothing is lost from the file — every sample is\n there, in order — but the column stops being an identifier, and that is worth saying\n rather than leaving to be discovered.\n\n This said nine places and a gigahertz, and illustrated it with 1 ns records — all three of\n which stopped being true when 0.4.55 raised the search bound. Fifteen places resolve\n 1e-15 s, so a nanosecond interval is written exactly and that recording raises nothing at\n all. warnings-and-errors.md was corrected then and carries a note saying so; the comment\n it was written from was not, and the hint printed four lines below here has said \"the\n fifteen places a double can hold exactly\" ever since.\n */\n /*\n Where the rows a warning is about actually land.\n\n Three warnings below name `group.fileName`, which is the file the wide layout writes — and\n under `--stdout` no file is written at all. `repeating-fast.edf --info --stdout` printed\n both halves two lines apart:\n\n 0 ch1 ch1 uV 3000000000000000 Hz -100 to 100 (stdout)\n warning: Channels at 3000000000000000 Hz sample faster than the time column can\n distinguish, so consecutive rows in signals.csv carry the same time_s value.\n\n The OUTPUT column has said `(stdout)` since 0.8.31. The warning under it did not, so a\n reader is told the rows go to the terminal and then sent to look in a file for them.\n */\n const destination = (group: RateGroup): string =>\n options.toStdout === true ? 'the CSV on stdout' : group.fileName;\n\n for (const group of groups) {\n const step = group.rate > 0 ? 1 / group.rate : 0;\n /*\n The limit of the same failure, which read as the absence of it.\n\n `samplesPerRecord / recordDuration` is a double, and a record duration of 1e-308 with\n four samples in it is Infinity. `1 / Infinity` is 0, so `step > 0` was false and this\n said nothing — while every sample was dropped, the run exited 0, and the only warning\n printed was EMPTY_WINDOW's \"This recording's 2 data records carry no samples in range\",\n which is untrue twice over: the records carry eight samples and no range was asked for.\n\n One power of ten away, at 1e-300, the rate is 4e300 and the file converts with the\n warning below. Same guard `decimalsAreClamped` had before 0.5.83, in the column next\n door: a step of exactly zero means no resolution at all, not nothing to report.\n\n Its own branch because the hint below is false here — no rows are written at all, so\n \"Every sample is written, in order\" would be the third untrue sentence.\n */\n if (!Number.isFinite(group.rate)) {\n diagnostics.push({\n code: 'TIME_RESOLUTION',\n severity: 'warning',\n message:\n `Channels in ${destination(group)} work out to a sampling rate of ${formatRate(group.rate)} Hz ` +\n `— their samples per record over a record duration too small to divide into — so ` +\n `their samples cannot be placed in time and no rows are written for them.`,\n hint:\n 'Check the record duration in the header. One power of ten larger and the same ' +\n 'file converts, with consecutive rows carrying the same time_s.',\n });\n } else if (step > 0 && step < 10 ** -group.timeDecimals) {\n diagnostics.push({\n code: 'TIME_RESOLUTION',\n severity: 'warning',\n message:\n `Channels at ${formatRate(group.rate)} Hz sample faster than the time column can ` +\n `distinguish, so consecutive rows in ${destination(group)} carry the same time_s value.`,\n /*\n \"or convert one rate at a time with --channels\" was advice that does nothing.\n\n It parses, it runs, it exits 0, and the warning comes back word for word — so\n somebody who followed it had every reason to think the column had been fixed. In\n the wide layout each rate already has its own file and its own precision, and\n `timeDecimals` is a function of the rate alone, so a narrowed conversion writes the\n same column it wrote before. In the long layout the shared column takes the finest\n precision *in the conversion*, and dropping rates can only make it coarser — never\n fine enough to separate samples that were already inseparable.\n\n Nor is there another option that would: --decimals sets the value precision and\n says so, and every rate that reaches this warning has already been given the\n fifteen places that are the ceiling. The first sentence was the whole of the\n answer, so it is the whole of the hint.\n */\n hint:\n 'Every sample is written, in order. Use the row number rather than time_s to tell ' +\n 'them apart: the column already carries the fifteen places a double can hold ' +\n 'exactly, so no option or selection separates them.',\n });\n }\n }\n\n /*\n The same failure as TIME_RESOLUTION, one column over.\n\n A channel whose quantization step is below 1e-98 needs more decimals than `toFixed` can\n print, so consecutive digital codes round to the same text and the arithmetic the FAQ\n gives for recovering them stops working. That used to happen at 1e-20 and silently — see\n MAX_DERIVED_DECIMALS. It is rare now, but \"rare\" is the reason to say so rather than the\n reason not to.\n\n Asked of the ceiling, not of the precision in use, and so asked whatever `--decimals`\n says. `--decimals 2` on a channel needing 3 is a trade the caller made knowingly, and\n reporting it was reporting the flag back at the person who typed it — every channel of an\n ordinary EEG raised this, and since --strict turns any diagnostic into exit 1,\n `--decimals 2 --strict` could not succeed on any recording at all.\n\n 0.5.10 fixed that by skipping the check whenever `--decimals` was given, which suppressed\n the real case along with the false one: at `--decimals 20` a channel stepping by 1e-106\n printed every code it had as `0.00000000000000000000`, and said nothing. The question is\n not who chose the precision. It is whether any precision the tool can print would\n separate consecutive codes.\n */\n for (const group of groups) {\n const short = group.channels.filter((c) => decimalsAreClamped(c.signal));\n if (short.length === 0) continue;\n diagnostics.push({\n code: 'VALUE_RESOLUTION',\n severity: 'warning',\n message:\n `${listed(short.map((c) => c.column))} ${short.length === 1 ? 'steps' : 'step'} by less ` +\n `than any number of decimals this can print, so some consecutive samples round to ` +\n `the same value in ${destination(group)}.`,\n hint:\n 'Every sample is written, in order, and the physical values are computed at full ' +\n 'precision either way. What is lost is only in the printed text.',\n });\n }\n\n /*\n A window that selects nothing is a fact about the plan, so the plan is where it is raised.\n\n It was pushed by `convert()` from the rows actually written, which meant `--info` never\n said it: `--info --start 0.31 --end 0.39` on a 10 Hz recording printed \"Would write 0\n rows\" with no warning and exited 0 under `--strict`, while converting the same window\n warned and exited 1. The hint says \"Run with --info to see where the records actually\n sit\" — advising the reader into the one mode that would not tell them.\n\n The estimate's row count is exact, which `npm run estimate` checks across every fixture\n crossed with every option set, so raising it from the plan says the same thing the rows\n would have.\n */\n /*\n Not when a rate above already explained it. EMPTY_WINDOW says the records \"carry no\n samples in range\", and on a recording whose rate overflowed to Infinity that is untrue\n twice: the records carry their samples, and no range was asked for. The rate warning is\n the accurate account of the same zero.\n */\n const untimeable = groups.some((group) => !Number.isFinite(group.rate));\n if (writeSignals && groups.length > 0 && estimate.rows === 0 && !untimeable) {\n diagnostics.push(\n emptyWindow(range, input.recordCount, groups, options.gzip === true, options.toStdout === true),\n );\n } else if (writeSignals && (options.layout ?? 'wide') !== 'long' && !untimeable) {\n /*\n And a window that empties one rate and not another, which nothing said at all.\n\n The check above asks whether the run wrote any rows. A rate group is what gets a file,\n and a window can hold samples of one rate and none of another — a channel sampled once\n a second has a sample every 1s, so `--start 0.1 --end 0.4` falls between two of them\n while a 4 Hz channel in the same recording keeps one:\n\n $ edf2csv mixed.edf --start 0.1 --end 0.4 --out ./converted\n Wrote ./converted\n signals_4hz.csv 1 row\n signals_1hz.csv 0 rows\n\n Two lines of a summary, one of them a file holding its header and nothing else, and no\n warning — where the same file arrived at through a window that empties every rate\n raises one, and `--strict` exits 1 over it. The rule EMPTY_WINDOW's own docstring\n states is that everywhere a request produces nothing this tool says so.\n\n Only the wide layout: a long conversion puts every rate in one table, so a rate with no\n samples in the window costs it rows and not a file.\n */\n const empty = groups.filter(\n (group) => rowsInRange(group, range, input.recordDuration, input.recordStarts) === 0,\n );\n const kept = groups.filter((group) => !empty.includes(group));\n if (empty.length > 0 && kept.length > 0) {\n const rates = (which: readonly RateGroup[]): string =>\n listed(formatRates(which.map((g) => g.rate)).map((rate) => `${rate} Hz`));\n diagnostics.push({\n code: 'EMPTY_RATE_WINDOW',\n severity: 'warning',\n message:\n `No samples fall inside the requested window at ${rates(empty)}, so ` +\n `${listed(empty.map((g) => destination(g)))} ` +\n `${empty.length === 1 ? 'holds its header' : 'hold their headers'} and no data.`,\n hint:\n `The window does hold samples at ${rates(kept)}. A window narrower than a ` +\n `channel's sample interval can fall between two of its samples, and the slower ` +\n `the channel the wider that gap is.`,\n });\n }\n }\n\n if (estimate.exceedsSpreadsheetLimit) {\n /*\n And the file it is about, which `--stdout` does not write either.\n\n \"At least one output file will have more than 1,048,576 rows\" was said to a run whose\n summary reads \"Wrote 1,075,200 rows to stdout\", advising the reader to \"read the file\n with pandas or R\" — there is no file, and what a spreadsheet can open is not the question\n a pipe raises. The count is the useful half and it does not change; the noun and the\n advice do. Redirecting the stream is how it becomes a file a spreadsheet would refuse,\n which is what the sentence says now.\n */\n const toStdout = options.toStdout === true;\n diagnostics.push({\n code: 'LARGE_OUTPUT',\n severity: 'warning',\n message: toStdout\n ? `The CSV on stdout will have more than ${grouped(SPREADSHEET_ROW_LIMIT)} rows, ` +\n `which is more than Excel or Numbers can open.`\n : `At least one output file will have more than ${grouped(SPREADSHEET_ROW_LIMIT)} ` +\n `rows, which is more than Excel or Numbers can open.`,\n hint: toStdout\n ? 'Use --start and --duration to stream a section, or read the stream with pandas ' +\n 'or R rather than redirecting it into a spreadsheet.'\n : 'Use --start and --duration to convert a section, or read the file with pandas or R.',\n });\n }\n\n return { groups, layout, gzip: options.gzip === true, range, columnNames, writeSignals, diagnostics, estimate };\n}\n\n/**\n * Partition channels by sampling rate, largest first.\n *\n * The common case — every channel at one rate — collapses to a single group and a\n * single `signals.csv`, so the honest behaviour costs nothing when there is nothing\n * to be honest about.\n */\nfunction groupByRate(\n signals: readonly EdfSignal[],\n columnNames: Map<number, string>,\n forcedDecimals: number | undefined,\n gzip: boolean,\n layout: 'wide' | 'long',\n): RateGroup[] {\n const byRate = new Map<number, EdfSignal[]>();\n for (const signal of signals) {\n // A channel with no samples has no sampling rate to group by, and would\n // otherwise produce an empty \"0hz\" file. The header parser already warned.\n if (signal.samplesPerRecord === 0) continue;\n const bucket = byRate.get(signal.samplingRate);\n if (bucket) bucket.push(signal);\n else byRate.set(signal.samplingRate, [signal]);\n }\n\n const rates = [...byRate.keys()].sort((a, b) => b - a);\n // The long layout writes one table whatever the rates are, so every group names it.\n const single = rates.length === 1 || layout === 'long';\n\n /*\n Two distinct rates can produce the same slug, because the slug rounds to six decimal\n places. Rates come from samplesPerRecord / recordDuration and every channel shares the\n record duration, so the closest two rates can be is 1 / recordDuration — which drops\n below 1e-6 once a record is longer than about eleven days. Absurd, but the header\n permits it, and the failure was silent and destructive: both groups opened a write\n stream on the same path, so the file ended up holding interleaved rows from both\n channels under a header naming only one of them.\n\n Distinct rates therefore get distinct files, always. The suffix is only ever reached by\n a collision, so ordinary recordings keep the names they have always had.\n\n Naming from the whole set of rates at once removes most of those collisions before the\n suffix has to. Rounding each rate on its own gave 1e-6 Hz and 1.25e-6 Hz the same slug,\n and the numbering below then produced signals_0_000001hz.csv and signals_0_000001hz_2.csv\n — two files that no longer overwrite each other, but of which only one is named for the\n rate it holds. The suffix stays as the backstop for anything this still cannot separate.\n */\n const suffix = gzip ? '.csv.gz' : '.csv';\n const slugs = formatRates(rates).map(slugFor);\n const used = new Set<string>();\n const uniqueName = (index: number): string => {\n const base = `signals_${slugs[index]}`;\n let name = `${base}${suffix}`;\n for (let n = 2; used.has(name); n++) name = `${base}_${n}${suffix}`;\n used.add(name);\n return name;\n };\n\n return rates.map((rate, index) => {\n const members = byRate.get(rate) ?? [];\n const first = members[0];\n return {\n rate,\n samplesPerRecord: first ? first.samplesPerRecord : 0,\n fileName: single ? `signals${suffix}` : uniqueName(index),\n /*\n In the long layout every rate shares a `time_s` column, so they share its precision:\n the finest any of them needs. Writing 100 Hz at three places and 256 Hz at eight in\n the same column would make the column's meaning depend on the row.\n */\n timeDecimals: layout === 'long' ? Math.max(...rates.map(timeDecimals)) : timeDecimals(rate),\n channels: members.map((signal) => ({\n signal,\n column: columnNames.get(signal.index) ?? `signal_${signal.index}`,\n decimals: forcedDecimals ?? decimalsForSignal(signal),\n })),\n };\n });\n}\n\n/**\n * A file's diagnostics with the header's mixed-rate warning removed.\n *\n * `buildPlan` raises that warning for the channels actually being converted, so keeping both\n * would either duplicate it or contradict it. The header parser's copy stays where it is, for\n * callers reading a header without planning a conversion.\n */\nexport function withoutFileRateWarning(diagnostics: readonly Diagnostic[]): Diagnostic[] {\n return diagnostics.filter((d) => d.code !== 'MIXED_SAMPLING_RATES');\n}\n\n/** `256hz`, `12_5hz` — safe in a filename on every platform. */\nfunction slugFor(rendered: string): string {\n return `${rendered.replace('.', '_')}hz`;\n}\n\n/**\n * One rate's slug, rendered on its own.\n *\n * The names a conversion writes come from `formatRates` over the whole set, which widens the\n * precision until rates that differ read as differing — so on a recording carrying both,\n * 1e-6 Hz and 1.25e-6 Hz are `0_000001hz` and `0_00000125hz`. This renders one rate with no\n * set to separate it from, and both of those come back `0_000001hz`.\n *\n * Which is right for the question it is asked, and was worth saying: a caller reaching for the\n * exported slug function to predict a filename got a name the tool does not write, on exactly\n * the rates the reference warns `formatRate` collapses. The two now spell a rendered rate the\n * same way, through the line above, so only the rendering differs and nothing can drift.\n */\nexport function rateSlug(rate: number): string {\n // `formatRate` checks the argument; the two spell a rendered rate the same way, so they\n // refuse the same values too.\n return slugFor(formatRate(rate));\n}\n\n/**\n * The name a CSV is written under, which `--gzip` changes.\n *\n * `plan.gzip` is recorded rather than inferred because \"`--info` named `annotations.csv` for a\n * run that wrote `annotations.csv.gz`\" — and the warnings *about* those files went on doing it\n * after the file list stopped. A run that says \"annotations.csv holds its header and no rows\"\n * three lines above a summary listing `annotations.csv.gz` names two files and writes one.\n *\n * Written once here because three places already computed it by hand.\n */\nexport function outputCsvName(base: string, gzip: boolean): string {\n return `${base}${gzip ? '.csv.gz' : '.csv'}`;\n}\n\n/**\n * Characters the time column occupies, measured over both ends of the window and signed.\n *\n * Both estimates measured the column against `range.endSeconds` alone, unsigned — while the\n * value column two lines below already allowed for a sign when either bound is negative. A\n * recording timed from before zero prints `-100.000` where that budgeted for `100.000`, so\n * every row came out a byte short: 203 predicted against 216 written, and 131 against 159 on\n * a shorter one. An estimate reading low is the one direction the correctness page says it\n * never goes — \"no byte count under the truth\" is what the estimate sweep asserts over every\n * fixture, and no fixture began before zero.\n *\n * The far end is not always the widest: from -100s to -97s it is the start.\n */\nfunction timeWidthFor(range: ResolvedRange, decimals: number): number {\n return widthOf(\n Math.max(Math.abs(range.startSeconds), Math.abs(range.endSeconds)),\n decimals,\n range.startSeconds < 0 || range.endSeconds < 0,\n );\n}\n\n/**\n * How wide a value cell can print, from the channel's own calibration.\n *\n * Zero when that calibration holds no mapping — a digital range of one point, a physical span\n * that overflows or underflows a double — because such a channel writes an empty cell for\n * every sample rather than a number, which is the whole point of `makeScaler` returning NaN.\n *\n * Budgeting a full-width number for one broke the bound this estimate states beside never\n * reading low. A single-channel recording whose digital minimum equals its maximum, at\n * `--decimals 20`, was predicted at 651 bytes and wrote 151 — 4.31x, against a documented wall\n * of three. No fixture reaches it because `degenerate-range.edf` has two ordinary channels\n * beside its flat one, whose real cells pad the total back under the wall.\n *\n * Asked of `makeScaler` rather than restated here, for the reason `csvRow` measures the header\n * row: the function that decides whether a cell gets a number is the one that can still be\n * right when the rule changes. Both ends of the declared range are probed, so a calibration\n * that is finite anywhere keeps its full width and the estimate cannot start reading low.\n */\nfunction valueWidthOf(channel: PlannedChannel): number {\n const scale = makeScaler(channel.signal);\n const blank =\n !Number.isFinite(scale(channel.signal.digitalMin)) &&\n !Number.isFinite(scale(channel.signal.digitalMax));\n if (blank) return 0;\n return widthOf(\n Math.max(Math.abs(channel.signal.physicalMin), Math.abs(channel.signal.physicalMax)),\n channel.decimals,\n channel.signal.physicalMin < 0 || channel.signal.physicalMax < 0,\n );\n}\n\n/** Integer digits in `Number.MAX_VALUE`, which is the widest a finite double prints. */\nconst MAX_DOUBLE_DIGITS = 309;\n\n/** Characters a fixed-decimal number of this magnitude occupies, sign included. */\nfunction widthOf(magnitude: number, decimals: number, signed = false): number {\n const size = Math.abs(magnitude);\n const sign = signed ? 1 : 0;\n const fraction = decimals > 0 ? 1 + decimals : 0;\n\n /*\n Cells are written with toFixed, which rounds. Taking the integer digits from the floor of\n the bound therefore under-counted whenever rounding carried into a new digit: a channel\n bounded at 9999.999 and written to zero decimals produces \"10000\", five characters where\n the floor of 9999.999 suggests four. Every cell on such a channel was a byte short, and\n `--info` reported 127 KB for a file that came out 131 KB.\n\n Measuring the bound as rendered removes that. toFixed switches to exponential notation\n past 1e21, so the arithmetic form still covers magnitudes beyond it.\n */\n /*\n A bound that is not a number bounds nothing, so the widest cell it can produce is taken\n instead: 309 digits, which is `Number.MAX_VALUE` written out.\n\n One digit was budgeted, and the estimate read low — the one direction the correctness page\n says it never goes. `latest` is `recordCount * recordDuration`, so a header stating a\n record duration near the top of a double overflows it while every sample time under it\n stays finite and prints in full. Three records of 1e308, eight samples:\n\n Would write 8 rows, roughly 115 B. signals.csv is 2,244 bytes.\n\n Each of those rows carries a 313-character time cell. `fixed` writes an empty cell for a\n value that is itself non-finite, so nothing wider than this is ever printed.\n */\n if (!Number.isFinite(size)) return sign + MAX_DOUBLE_DIGITS + fraction;\n if (size < 1e21) return sign + size.toFixed(Math.min(decimals, 100)).length;\n return sign + (Math.floor(Math.log10(size)) + 1) + fraction;\n}\n\n/**\n * Raised when the conversion had signal tables to fill and put no data rows in any of them.\n *\n * A window can land where there are no samples without being past the end of the recording:\n * between the last sample and the nominal end of the last record, or — on a discontinuous\n * file — inside a gap. `--start 2 --end 10` on a recording whose records sit at 0s, 1s and\n * 10s asks for eight seconds that contain no data at all.\n *\n * What came out was a signals.csv holding its header and nothing else, exit 0, no warning,\n * and `--strict` passing. The closing summary does say \"signals.csv 0 rows\" and --json\n * carries `rows: 0`, so it was not quite invisible — but a header-only file is exactly what\n * a successful extraction of an empty range looks like, and everywhere else that a request\n * produces nothing this tool says so: a --channels term matching nothing is an error, and\n * --annotations-only on a file with no events raises NO_ANNOTATIONS. A warning rather than\n * an error because a batch of five hundred recordings should not stop for one whose gap\n * happens to line up with the window; --strict turns it into a failure for those who want\n * that.\n */\nfunction emptyWindow(\n range: ResolvedRange,\n recordCount: number,\n groups: readonly RateGroup[],\n gzip: boolean,\n toStdout: boolean,\n): Diagnostic {\n const fileCount = groups.length;\n const asked = !range.isWholeRecording;\n /*\n A window narrower than one sample interval, which is the commonest way to get here and\n was the one cause the hint did not name.\n\n Sample times sit on a grid of `1 / rate`, so a half-open window at least one interval\n wide always contains one — which makes the converse exact: on a continuous recording, a\n window inside the recording that selects nothing is a window narrower than the interval.\n `--start 0.31 --end 0.39` on a 10 Hz file is 0.08s of a 0.1s grid, and the hint answered\n \"past the last sample, or inside a gap in a discontinuous file\", neither of which is true\n of it — one being a special case of the same thing and the other belonging to a file\n shape this one does not have.\n\n The fastest rate, since that is the one whose grid is finest: if none of its samples fits,\n none of the slower ones does either.\n */\n const fastest = Math.max(...groups.map((group) => group.rate).filter(Number.isFinite), 0);\n const interval = fastest > 0 ? 1 / fastest : 0;\n const width = range.endSeconds - range.startSeconds;\n const narrow = asked && interval > 0 && width > 0 && width < interval;\n /*\n One rate is one file, which is nearly every recording, and this said \"files\" either way:\n \"so the signal files hold their headers and no data\" over a single signals.csv. The count\n is `plan.groups.length` and the caller has had it all along — it is the same number the\n mixed-rate warning three functions up counts to decide whether to fire at all.\n */\n /*\n And where that header lands, which under `--stdout` is not a file.\n\n `destination` three functions up has said `the CSV on stdout` since the rate warnings were\n taught the difference; this sentence had \"the signal file\" either way, over a run whose own\n summary line reads \"Wrote 0 rows to stdout\" and whose `--info` OUTPUT column reads\n `(stdout)`. The header is still written — it goes to the stream — so what changes is the\n noun, not the claim.\n */\n const tables = toStdout\n ? 'the CSV on stdout carries its header and no data'\n : fileCount === 1\n ? 'the signal file holds its header and no data'\n : 'the signal files hold their headers and no data';\n return {\n code: 'EMPTY_WINDOW',\n severity: 'warning',\n message: asked\n ? `No samples fall inside the requested window (${fixed(range.startSeconds, 3)}s to ` +\n `${fixed(range.endSeconds, 3)}s), so ${tables}.`\n : `This recording's ${counted(recordCount, 'data record')} carry no samples in range, ` +\n `so ${tables}.`,\n hint: asked\n ? /*\n Which of the two it was, rather than the second one always.\n\n A recording does not have to start at zero: its first record's timekeeping TAL is\n what it is timed from, so a file whose records begin at 1000s is asked for with\n `--start 1000`. `--start 0 --end 1` on that file was told \"The window is inside the\n recording but lands where there is no data — past the last sample, or inside a gap\n in a discontinuous file\", when the window sits entirely before the recording and\n neither offered explanation applies to it. A start at or past the *end* is already\n an error, so the window being outside can only mean it is before the beginning.\n */\n range.endSeconds <= range.recordingStartSeconds\n ? `This recording starts at ${fixed(range.recordingStartSeconds, 3)}s, so the whole ` +\n 'window sits before it. --start and --end are read on the recording\\'s own clock, ' +\n 'which --info prints as \"Timed from\".'\n : narrow\n ? `It is ${fixed(width, 3)}s wide and the fastest channel here samples every ` +\n `${plainSeconds(interval)}s, so no sample time falls inside it. Widen it to at least ` +\n 'one sample interval, or convert more of the recording and take the row nearest ' +\n 'the moment you want.'\n : /*\n Advice that does something in the mode it is printed in.\n\n `EMPTY_WINDOW` is a fact about the plan, and `--info` builds the plan — so\n `discontinuous.edf --info --start 4s --end 4.2s` answered with the command that\n had just printed it. 0.8.42 fixed the same loop in channel selection; these are\n the two hints that were left.\n\n The replacement is also the better answer for a conversion. `--info` does not\n print where the records sit: it prints a count, a duration and a time span that\n \"includes discontinuities\". The record positions are in `time_s`, one per row,\n which is what a conversion without a window writes.\n */\n 'The window is inside the recording but lands where there is no data — inside a ' +\n 'gap in a discontinuous file, or past the last sample. Convert without --start ' +\n 'and --end and read time_s to see where the records actually sit.'\n : // The same loop, in the branch where no window was asked for at all.\n 'What the header declares for each channel — its samples per data record — is in ' +\n `the channel table --info prints and in ${outputCsvName('channels', gzip)}.`,\n };\n}\n\n/**\n * How many rows of one rate group fall inside the window.\n *\n * Lifted out of `estimateOutput`, which counted this per group to add up, because the count\n * per group is a fact the report needs on its own: a window can hold samples of one rate and\n * none of another, and the file for the second is then written with its header and no data\n * while the run as a whole has rows and says nothing about it.\n */\nfunction rowsInRange(\n group: RateGroup,\n range: ResolvedRange,\n recordDuration: number,\n recordStarts: Float64Array | null | undefined,\n): number {\n let rows = 0;\n for (let record = range.startRecord; record < range.endRecord; record++) {\n const recordStart = recordStarts\n ? (recordStarts[record] ?? record * recordDuration)\n : record * recordDuration;\n rows += countSamplesInRange({\n recordStart,\n rate: group.rate,\n samplesPerRecord: group.samplesPerRecord,\n startSeconds: range.startSeconds,\n endSeconds: range.endSeconds,\n });\n }\n return rows;\n}\n\nfunction estimateOutput(\n groups: readonly RateGroup[],\n range: ResolvedRange,\n recordDuration: number,\n recordStarts: Float64Array | null | undefined,\n bom: boolean,\n layout: 'wide' | 'long',\n): OutputEstimate {\n let rows = 0;\n let bytes = 0;\n let exceeds = false;\n // One table in the long layout, so the row limit applies to the sum rather than the\n // largest group, and the header and mark are counted once rather than once per group.\n let longRows = 0;\n\n for (const group of groups) {\n const groupRows = rowsInRange(group, range, recordDuration, recordStarts);\n if (layout === 'long') {\n // A row per sample per channel rather than a row per sample time.\n const groupCells = groupRows * group.channels.length;\n rows += groupCells;\n longRows += groupCells;\n /*\n `time_s,channel,value`: the time, the channel name as it will be escaped into the\n cell, and the widest the value can print. Same over-counting rule as the wide\n layout — the declared physical range bounds a cell, and most samples sit under it.\n */\n const timeWidth = timeWidthFor(range, group.timeDecimals);\n for (const channel of group.channels) {\n const valueWidth = valueWidthOf(channel);\n const nameWidth = Buffer.byteLength(escapeCsvField(channel.column));\n // Two commas and the newline.\n bytes += groupRows * (timeWidth + nameWidth + valueWidth + 3);\n }\n continue;\n }\n\n rows += groupRows;\n if (groupRows + 1 > SPREADSHEET_ROW_LIMIT) exceeds = true;\n\n /*\n Width per cell, from the channel's own calibration rather than a flat allowance.\n\n The old `decimals + 6` budgeted six characters for the sign, integer part and decimal\n point on every channel, whatever it actually held. That over-counted a millivolt\n channel spanning ±5 by four characters a cell and ran 30-55% high across the fixture\n set — on a number people use to decide whether a conversion is worth starting.\n\n The channel's declared physical range is what bounds a cell, so that bound is what is\n used. Most samples sit below it, so this still reads high, which is the direction a\n size estimate should err in.\n\n One case is outside the bound rather than under it: nothing obliges a recording to keep\n its samples inside the digital range it declares, and one that does not maps outside the\n physical range too. Such a file can convert larger than the estimate. Clamping the data\n to make the estimate true is not a trade worth making — the samples are what they are.\n */\n const timeWidth = timeWidthFor(range, group.timeDecimals);\n const cellWidth = group.channels.reduce((sum, c) => sum + valueWidthOf(c), 0);\n // One comma per channel, plus the newline.\n bytes += groupRows * (timeWidth + cellWidth + group.channels.length + 1);\n /*\n The header row, measured as it will be written rather than as the labels are stored.\n\n A column name is quoted when it contains a comma, a quote, a carriage return or a line\n feed, and every quote inside it is doubled. Counting the raw label under-counted\n that row: three channels labelled `a,b,c,d,e`, `x\"y` and `plain` write a 32-byte header\n and were budgeted 27. EDF labels are free text, so commas in them are ordinary — a montage\n written as `EEG Fpz-Cz, ref` is exactly the kind of thing this is for.\n\n csvRow is the function that writes it, so it is the function that measures it. Nothing\n else is in a position to stay correct when the quoting rules change.\n */\n bytes += Buffer.byteLength(csvRow(['time_s', ...group.channels.map((c) => c.column)])) + 1;\n // Three bytes per file under --bom. Small, but exactly known — unlike the sample\n // overshoot two paragraphs up, which is the one thing here that can read under what gets\n // written and cannot be counted in advance. On a one-row conversion three bytes is a\n // tenth of the file.\n if (bom) bytes += BOM_BYTES;\n }\n\n if (layout === 'long' && groups.length > 0) {\n if (longRows + 1 > SPREADSHEET_ROW_LIMIT) exceeds = true;\n bytes += Buffer.byteLength(csvRow(['time_s', 'channel', 'value'])) + 1;\n if (bom) bytes += BOM_BYTES;\n }\n\n return { rows, bytes, exceedsSpreadsheetLimit: exceeds };\n}\n"]}
@@ -6,7 +6,7 @@
6
6
  * we can continue, but the user needs to know something about their data that
7
7
  * they would not otherwise see.
8
8
  */
9
- export type DiagnosticCode = 'MIXED_SAMPLING_RATES' | 'DISCONTINUOUS' | 'RECORD_COUNT_UNKNOWN' | 'RECORD_COUNT_MISMATCH' | 'TRAILING_BYTES' | 'DEGENERATE_DIGITAL_RANGE' | 'DEGENERATE_PHYSICAL_RANGE' | 'UNUSABLE_PHYSICAL_RANGE' | 'INVERTED_PHYSICAL_RANGE' | 'DUPLICATE_LABEL' | 'EMPTY_LABEL' | 'NO_ANNOTATIONS' | 'ANNOTATION_DECODE_FAILED' | 'COMMA_DECIMAL' | 'LARGE_OUTPUT' | 'NO_SIGNAL_CHANNELS' | 'NO_SAMPLES' | 'STALE_OUTPUT' | 'INPUT_CHANGED' | 'EMPTY_WINDOW' | 'TIME_RESOLUTION' | 'VALUE_RESOLUTION' | 'HEADER_BYTES_MISMATCH' | 'NONPRINTABLE_LABEL'
9
+ export type DiagnosticCode = 'MIXED_SAMPLING_RATES' | 'DISCONTINUOUS' | 'RECORD_COUNT_UNKNOWN' | 'RECORD_COUNT_MISMATCH' | 'TRAILING_BYTES' | 'DEGENERATE_DIGITAL_RANGE' | 'DEGENERATE_PHYSICAL_RANGE' | 'UNUSABLE_PHYSICAL_RANGE' | 'INVERTED_PHYSICAL_RANGE' | 'DUPLICATE_LABEL' | 'EMPTY_LABEL' | 'NO_ANNOTATIONS' | 'ANNOTATION_DECODE_FAILED' | 'COMMA_DECIMAL' | 'LARGE_OUTPUT' | 'NO_SIGNAL_CHANNELS' | 'NO_SAMPLES' | 'STALE_OUTPUT' | 'INPUT_CHANGED' | 'EMPTY_WINDOW' | 'EMPTY_RATE_WINDOW' | 'TIME_RESOLUTION' | 'VALUE_RESOLUTION' | 'HEADER_BYTES_MISMATCH' | 'NONPRINTABLE_LABEL'
10
10
  /**
11
11
  * Header text that a spreadsheet will run instead of read.
12
12
  *
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/edf/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAsHH;;;GAGG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAe;IACnB,IAAI,CAAqB;IAElC,YAAY,IAAkB,EAAE,OAAe,EAAE,IAAa;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["/**\n * Error and diagnostic types.\n *\n * The distinction that matters here: an EdfError means we cannot produce\n * trustworthy output and must stop. A Diagnostic with severity 'warning' means\n * we can continue, but the user needs to know something about their data that\n * they would not otherwise see.\n */\n\nexport type DiagnosticCode =\n | 'MIXED_SAMPLING_RATES'\n | 'DISCONTINUOUS'\n | 'RECORD_COUNT_UNKNOWN'\n | 'RECORD_COUNT_MISMATCH'\n | 'TRAILING_BYTES'\n | 'DEGENERATE_DIGITAL_RANGE'\n | 'DEGENERATE_PHYSICAL_RANGE'\n | 'UNUSABLE_PHYSICAL_RANGE'\n | 'INVERTED_PHYSICAL_RANGE'\n | 'DUPLICATE_LABEL'\n | 'EMPTY_LABEL'\n | 'NO_ANNOTATIONS'\n | 'ANNOTATION_DECODE_FAILED'\n | 'COMMA_DECIMAL'\n | 'LARGE_OUTPUT'\n | 'NO_SIGNAL_CHANNELS'\n | 'NO_SAMPLES'\n | 'STALE_OUTPUT'\n | 'INPUT_CHANGED'\n | 'EMPTY_WINDOW'\n | 'TIME_RESOLUTION'\n | 'VALUE_RESOLUTION'\n | 'HEADER_BYTES_MISMATCH'\n | 'NONPRINTABLE_LABEL'\n /**\n * Header text that a spreadsheet will run instead of read.\n *\n * Excel, LibreOffice and Google Sheets treat a cell beginning `=`, `+` or `@` as a formula,\n * whatever file it arrived in. EDF labels, units, transducer and prefiltering fields are\n * free text out of the header, and this tool writes them through unchanged on purpose — so\n * a channel labelled `=1+1` becomes a column header that computes 2, and one labelled\n * `=HYPERLINK(...)` becomes a link the reader did not write. The README says the output\n * opens in Excel and SECURITY.md already treats these fields as attacker-controlled; this\n * is the one place they reach a program that executes text.\n *\n * A warning rather than a rewrite. Prefixing the cell with a quote is the usual mitigation\n * and it would mean writing something the header does not say, which is the one thing this\n * tool does not do — the same answer NONPRINTABLE_LABEL gives for control bytes.\n */\n | 'FORMULA_LABEL'\n /**\n * The header's start date or time is not a date or a time.\n *\n * Every other unusable header field reports itself. This one did not, so a recording whose\n * timestamp cannot be read converted in silence, passed `--strict`, and left\n * `start_datetime_local` null in metadata.json with nothing saying why — on the field the\n * documented recipe for an absolute instant depends on.\n */\n | 'START_TIME_UNREADABLE'\n /**\n * The header's start time names the sixtieth second of a minute.\n *\n * A leap second is a real instant and `23.59.60` is how UTC writes it, but no calendar date\n * has a sixtieth second and `Date` has no way to hold one: asking for it rolls over into the\n * next minute. So the instant is kept as `:59`, one second earlier — which was done silently,\n * and `start_datetime_local` then named a moment the header does not, on the field the\n * documented recipe for an absolute instant depends on.\n */\n | 'LEAP_SECOND_START'\n /**\n * An EDF+ recording identification field whose `Startdate` is not the header's start date.\n *\n * EDF+ requires the two to be the same date, and the four-digit year in the recording ID is\n * what lets a file say which century it belongs to. When they disagree about the day or the\n * month, or about a year that is not the same year at all, neither is corroborated and the\n * one number naming when the recording happened cannot be trusted — which nothing said.\n */\n | 'START_DATE_MISMATCH'\n /**\n * An annotation channel with a non-zero origin, in a file marked neither EDF+C nor EDF+D.\n *\n * The marker decides whether the origin is applied, and the annotation channel is found by\n * label instead. So a file carrying one without the marker got samples timed from zero and events\n * timed from the origin, and the two CSVs came out on clocks seconds apart.\n */\n | 'MISSING_EDF_PLUS_MARKER'\n /**\n * `--info --stdout` on a recording `--stdout` would refuse.\n *\n * Only `--info` raises it. A conversion refuses outright instead, with the same words —\n * this is that refusal shown ahead of time, which is what `--info` is for.\n */\n | 'STDOUT_UNSUPPORTED';\n\nexport interface Diagnostic {\n code: DiagnosticCode;\n /**\n * Always `'warning'`. One field, one value, because there has only ever been one.\n *\n * It was `'warning' | 'info'`, and nothing in this codebase has ever built an `'info'`.\n * A published union is a promise about what a caller may receive, so the two pages that\n * print this interface told them to expect a second value and handle it — a branch that\n * cannot run, in the type a `--json` consumer reads `severity` out of. The terminal was\n * worse: `formatDiagnostics` labelled anything that was not `'warning'` as `note:`, so the\n * one thing the type said could arrive would have arrived under a third name again.\n *\n * Kept as a field rather than dropped: `metadata.json`, both JSON streams and this\n * interface all carry it, and removing it from a document people have archived is a\n * different and worse change than narrowing what it can say.\n */\n severity: 'warning';\n message: string;\n /** What the user can do about it. Omitted when there is nothing useful to say. */\n hint?: string;\n}\n\nexport type EdfErrorCode =\n | 'FILE_TOO_SMALL'\n | 'BAD_HEADER_FIELD'\n | 'NO_DATA_RECORDS'\n | 'INVALID_SIGNAL_COUNT'\n | 'INVALID_RECORD_DURATION'\n | 'NO_SAMPLES'\n | 'UNREADABLE';\n\n/**\n * A fatal problem with the recording itself. Carries a stable `code` so the CLI\n * can map it to an exit status, and a `hint` so the user is not left guessing.\n */\nexport class EdfError extends Error {\n readonly code: EdfErrorCode;\n readonly hint: string | undefined;\n\n constructor(code: EdfErrorCode, message: string, hint?: string) {\n super(message);\n this.name = 'EdfError';\n this.code = code;\n this.hint = hint;\n }\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/edf/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgIH;;;GAGG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAe;IACnB,IAAI,CAAqB;IAElC,YAAY,IAAkB,EAAE,OAAe,EAAE,IAAa;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["/**\n * Error and diagnostic types.\n *\n * The distinction that matters here: an EdfError means we cannot produce\n * trustworthy output and must stop. A Diagnostic with severity 'warning' means\n * we can continue, but the user needs to know something about their data that\n * they would not otherwise see.\n */\n\nexport type DiagnosticCode =\n | 'MIXED_SAMPLING_RATES'\n | 'DISCONTINUOUS'\n | 'RECORD_COUNT_UNKNOWN'\n | 'RECORD_COUNT_MISMATCH'\n | 'TRAILING_BYTES'\n | 'DEGENERATE_DIGITAL_RANGE'\n | 'DEGENERATE_PHYSICAL_RANGE'\n | 'UNUSABLE_PHYSICAL_RANGE'\n | 'INVERTED_PHYSICAL_RANGE'\n | 'DUPLICATE_LABEL'\n | 'EMPTY_LABEL'\n | 'NO_ANNOTATIONS'\n | 'ANNOTATION_DECODE_FAILED'\n | 'COMMA_DECIMAL'\n | 'LARGE_OUTPUT'\n | 'NO_SIGNAL_CHANNELS'\n | 'NO_SAMPLES'\n | 'STALE_OUTPUT'\n | 'INPUT_CHANGED'\n | 'EMPTY_WINDOW'\n /*\n One rate's file empty while the run has rows, which `EMPTY_WINDOW` cannot say.\n\n A rate group is what gets a file, and a window can hold samples of one rate and none of\n another. `EMPTY_WINDOW` means the run produced nothing, which is what a script watching\n for a useless conversion matches on; this one means the run produced something and one of\n its files came out with a header and no rows. Coding them the same would have that script\n quarantine a conversion that worked.\n */\n | 'EMPTY_RATE_WINDOW'\n | 'TIME_RESOLUTION'\n | 'VALUE_RESOLUTION'\n | 'HEADER_BYTES_MISMATCH'\n | 'NONPRINTABLE_LABEL'\n /**\n * Header text that a spreadsheet will run instead of read.\n *\n * Excel, LibreOffice and Google Sheets treat a cell beginning `=`, `+` or `@` as a formula,\n * whatever file it arrived in. EDF labels, units, transducer and prefiltering fields are\n * free text out of the header, and this tool writes them through unchanged on purpose — so\n * a channel labelled `=1+1` becomes a column header that computes 2, and one labelled\n * `=HYPERLINK(...)` becomes a link the reader did not write. The README says the output\n * opens in Excel and SECURITY.md already treats these fields as attacker-controlled; this\n * is the one place they reach a program that executes text.\n *\n * A warning rather than a rewrite. Prefixing the cell with a quote is the usual mitigation\n * and it would mean writing something the header does not say, which is the one thing this\n * tool does not do — the same answer NONPRINTABLE_LABEL gives for control bytes.\n */\n | 'FORMULA_LABEL'\n /**\n * The header's start date or time is not a date or a time.\n *\n * Every other unusable header field reports itself. This one did not, so a recording whose\n * timestamp cannot be read converted in silence, passed `--strict`, and left\n * `start_datetime_local` null in metadata.json with nothing saying why — on the field the\n * documented recipe for an absolute instant depends on.\n */\n | 'START_TIME_UNREADABLE'\n /**\n * The header's start time names the sixtieth second of a minute.\n *\n * A leap second is a real instant and `23.59.60` is how UTC writes it, but no calendar date\n * has a sixtieth second and `Date` has no way to hold one: asking for it rolls over into the\n * next minute. So the instant is kept as `:59`, one second earlier — which was done silently,\n * and `start_datetime_local` then named a moment the header does not, on the field the\n * documented recipe for an absolute instant depends on.\n */\n | 'LEAP_SECOND_START'\n /**\n * An EDF+ recording identification field whose `Startdate` is not the header's start date.\n *\n * EDF+ requires the two to be the same date, and the four-digit year in the recording ID is\n * what lets a file say which century it belongs to. When they disagree about the day or the\n * month, or about a year that is not the same year at all, neither is corroborated and the\n * one number naming when the recording happened cannot be trusted — which nothing said.\n */\n | 'START_DATE_MISMATCH'\n /**\n * An annotation channel with a non-zero origin, in a file marked neither EDF+C nor EDF+D.\n *\n * The marker decides whether the origin is applied, and the annotation channel is found by\n * label instead. So a file carrying one without the marker got samples timed from zero and events\n * timed from the origin, and the two CSVs came out on clocks seconds apart.\n */\n | 'MISSING_EDF_PLUS_MARKER'\n /**\n * `--info --stdout` on a recording `--stdout` would refuse.\n *\n * Only `--info` raises it. A conversion refuses outright instead, with the same words —\n * this is that refusal shown ahead of time, which is what `--info` is for.\n */\n | 'STDOUT_UNSUPPORTED';\n\nexport interface Diagnostic {\n code: DiagnosticCode;\n /**\n * Always `'warning'`. One field, one value, because there has only ever been one.\n *\n * It was `'warning' | 'info'`, and nothing in this codebase has ever built an `'info'`.\n * A published union is a promise about what a caller may receive, so the two pages that\n * print this interface told them to expect a second value and handle it — a branch that\n * cannot run, in the type a `--json` consumer reads `severity` out of. The terminal was\n * worse: `formatDiagnostics` labelled anything that was not `'warning'` as `note:`, so the\n * one thing the type said could arrive would have arrived under a third name again.\n *\n * Kept as a field rather than dropped: `metadata.json`, both JSON streams and this\n * interface all carry it, and removing it from a document people have archived is a\n * different and worse change than narrowing what it can say.\n */\n severity: 'warning';\n message: string;\n /** What the user can do about it. Omitted when there is nothing useful to say. */\n hint?: string;\n}\n\nexport type EdfErrorCode =\n | 'FILE_TOO_SMALL'\n | 'BAD_HEADER_FIELD'\n | 'NO_DATA_RECORDS'\n | 'INVALID_SIGNAL_COUNT'\n | 'INVALID_RECORD_DURATION'\n | 'NO_SAMPLES'\n | 'UNREADABLE';\n\n/**\n * A fatal problem with the recording itself. Carries a stable `code` so the CLI\n * can map it to an exit status, and a `hint` so the user is not left guessing.\n */\nexport class EdfError extends Error {\n readonly code: EdfErrorCode;\n readonly hint: string | undefined;\n\n constructor(code: EdfErrorCode, message: string, hint?: string) {\n super(message);\n this.name = 'EdfError';\n this.code = code;\n this.hint = hint;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edf2csv",
3
- "version": "0.9.42",
3
+ "version": "0.9.43",
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",