eegdash.to_bids.icare module#
I-CARE 2.0 (BDSP, WFDB) as BIDS.
A user obtains the International Cardiac Arrest REsearch consortium (I-CARE)
database from the Brain Data Science Platform (BDSP) under its restricted
licence and data use agreement, which forbid sharing it, and makes the tree
from that copy. The source is the release root: training/, validation/
and test/ (the 2023 PhysioNet Challenge partitions; a copy that holds only
some of them is read as it is), one folder per patient
<split>/<patient>/ with the patient’s clinical file <patient>.txt and
WFDB records <patient>_<segment>_<hour>_<group>.hea + .mat (MATLAB v4,
int16), one record per signal group (EEG, ECG, REF, OTHER) of a
segment. Times count from the return of spontaneous circulation (ROSC), as
BDSP’s page states; a segment ends on the hour, or at the end of the
recording. PhysioNet’s I-CARE 2.1 (the 607 training patients) used the same
record and file names.
Every segment with an EEG record is one recording, written as an EDF file
(linkable = False): the EEG, ECG, REF and OTHER records of the segment
merged, in that order; a group whose sampling rate or length differs from the
EEG record’s is left out with a warning, and a segment without an EEG record
is left out. The entities:
sub-<patient>;task-icu;acq-h<hour>: the hour, as in the file name;run-<segment>: the segment number, as in the file name (two segments can share an hour).
A recording’s key is <patient>_<segment>_<hour>; its source is the EEG
record’s .hea: a run is written again when that file changes or the
adapter’s revision does, not when only another group’s record changes.
Samples. The EDF file holds WFDB’s 16-bit digital values unchanged, but
for a trailing part second, dropped when no EDF data record of at most
RECORD_SECONDS_MAX seconds, whose duration EDF’s 8-character field holds
exactly, divides the record (record_layout();
reported in the sidecar as TrailingSamplesDropped), and for the format’s
missing-sample code (-32768), which is replaced by the
linear interpolation of the channel’s nearest valid codes on either side (the
nearest one at either end of the recording; fill_missing()) and counted
per channel in the sidecar. (Revision icare/2; the first revision,
icare/1, wrote the channel’s baseline, clipped to int16: for a baseline
below -32768 that is the missing code itself, read as a spike of the range’s
end.) A
channel’s EDF physical range is derived from its gain and baseline
(physical_range()), so the EDF physical value of a code is WFDB’s
(code - baseline) / gain: exactly, as a decimal, when EDF’s 8-character
fields can hold such a range (the full int16 range, or one that encloses the
channel’s codes); otherwise the full int16 range with its ends rounded to
8 characters (a physical value then differs from WFDB’s by at most half a unit
of the last decimal place, 0.005 uV for a range under 10 mV), and the channel
is listed in the sidecar. A unit WFDB declares (uV, mV, V) is
kept; nu (no unit, PhysioNet’s 2.1) or none is read as microvolts: the
values match microvolts in amplitude, which the
release does not state. A range too wide for 8 characters in microvolts is
written in millivolts or volts, the codes unchanged.
Channels are named by their WFDB label; the EDF label is <group>
<label>, so the type follows the group (tables/icare-2.0.channels.csv):
EEG-group 10-20 names are EEG (a bipolar pair is MISC), ECG-group ECG,
REF-group (A1, M1, C2, …) MISC, OTHER-group EMG (EMG*,
LEG*, LAT*), EOG (LOC, ROC) or MISC (SpO2). participants.tsv
holds the clinical file’s fields and the split. The sidecar’s
HourAfterArrest, StartTimeAfterArrest and EndTimeAfterArrest say
Arrest in their names; their times count from ROSC, as above. wfdb is needed to write data (pip install wfdb)
and is imported only then. As the adapter is not linkable, a dry run converts
every segment into a temporary folder, removed after: it costs a full
conversion, though it writes nothing under the cache.
- class eegdash.to_bids.icare.ICARE(src: Path, version: str)[source]
Bases:
AdapterI-CARE 2.0 (BDSP, WFDB): see the module docstring.
- channels(rec: Recording, header: Header) list[Channel][source]
One channel per label of header, in its order.
- dataset_description() dict[str, Any][source]
Name,License,Authors, DOI and links of dataset_description.json.
- participants(subjects: Sequence[str]) tuple[list[dict], dict][source]
participants.tsv rows (
participant_idfirst) for subjects, and participants.json.
- readme(summary: dict[str, Any]) str[source]
README.md, from the run’s summary (subjects, recordings, hours, warnings).
- recordings() Iterator[Recording][source]
Every data file of the source: a walk that opens no data file.
- eegdash.to_bids.icare.declared_units(path: Path) list[str | None][source]
The unit of each signal line of a WFDB header as written; None where there is none.
The wfdb package reads a missing unit as
mV; here it stays None.
- eegdash.to_bids.icare.edf_exact(x: Fraction) str | None[source]
x as a decimal of at most 8 characters, or None when it has none.
- eegdash.to_bids.icare.edf_rounded(x: Fraction) str | None[source]
x rounded to the most decimals 8 characters hold; None when its integer part does not fit.
- eegdash.to_bids.icare.fill_missing(col: ndarray, baseline: float) int[source]
Replace WFDB’s missing-sample code in the int16 column col, in place; returns how many.
A missing code takes the linear interpolation, rounded, of the nearest valid codes before and after it; one before the first valid code or after the last takes that code. A column with no valid code is written as the baseline, clipped to int16 without the missing code itself. No missing code is left, and no value outside the valid codes’ range is made.
- eegdash.to_bids.icare.header_comments(path: Path) dict[str, str][source]
The
#Key: valuecomments of a WFDB header (Utility frequency,Start time, …).
- eegdash.to_bids.icare.lattice_step(per: Fraction, places: int) int[source]
The code step on which
code / peris a decimal of places places.(code - baseline) * Q * 10**places / Pis an integer, with per =P / Qcodes per physical unit, whenP / gcd(P, Q * 10**places)dividescode - baseline.
- eegdash.to_bids.icare.parse_name(name: str, patient: str) tuple[str, str, str] | str[source]
(segment, hour, group)of a header file name of patient, or why it is not one.f001_001_003_EEG.hea->("001", "003", "EEG").
- eegdash.to_bids.icare.physical_range(gain: float, baseline: int, lo: int, hi: int, unit: str | None = None) dict[str, Any][source]
The EDF fields of a channel whose codes run from lo to hi; physical
(code - baseline) / gain.unit is the unit WFDB declares (None or
nu: microvolts). Returnsunit,dmin,dmax,pmin,pmax(texts of at most 8 characters) andexact. Tried in order, in the declared voltage unit and then each larger one: the full int16 range; then, from 7 decimal places down, the narrowest range enclosing lo to hi whose ends are codes with a decimal physical value. When none is exact: the full int16 range rounded to 8 characters, in the first unit it fits.
- eegdash.to_bids.icare.read_patient_file(path: Path) dict[str, str][source]
The
Key: valuelines of a patient’s clinical file, in their order.
- eegdash.to_bids.icare.record_layout(n_times: int, sfreq: float) tuple[int, int, str, int][source]
(samples per EDF data record, records, the duration field, samples dropped).One second when it divides n_times; else the longest record of at most
RECORD_SECONDS_MAXseconds that divides it and whose duration is an exact field (the reader’s rate, samples / duration, is sfreq); else one-second records and the trailing part second dropped.
- eegdash.to_bids.icare.write_edf(path: Path, labels: Sequence[str], ranges: Sequence[dict[str, Any]], data: ndarray, sfreq: float) int[source]
Write data (samples x channels, int16) as an EDF file; returns the samples dropped.
Plain EDF, no annotation signal; start date 01.01.85 (EDF+’s date for an unknown one: I-CARE’s times count from ROSC and are in the sidecar).