Repository navigation
Description
A dataset's own header decides which file is read as its samples.
For a pipeline that loads datasets other people contributed, the header can point the loader at any file the process can read, and what the pipeline reports (statistics, a plot, a saved copy) is derived from that file.
pop_loadbv joins DataFile and MarkerFile to the header's directory without a check (_referenced_file), so a .., a sub-directory and an absolute path all leave the directory.
pop_loadset reduces a relative data or datfile to its file name, which stays in the directory, but takes an absolute one as it is (_sidecar_path).
pop_load_frombids reaches pop_loadbv for a .vhdr.
import pathlib, tempfile
import numpy as np, scipy.io
from eegprep import pop_loadbv, pop_loadset
HEADER = """Brain Vision Data Exchange Header File Version 1.0
[Common Infos]
DataFile={data}
DataFormat=BINARY
DataOrientation=MULTIPLEXED
NumberOfChannels=2
SamplingInterval=4000
[Binary Infos]
BinaryFormat=INT_16
[Channel Infos]
Ch1=A,,1,uV
Ch2=B,,1,uV
"""
root = pathlib.Path(tempfile.mkdtemp())
(root / "elsewhere").mkdir(); (root / "dataset").mkdir()
np.full((100, 2), 7, "<i2").tofile(root / "elsewhere" / "other.eeg") # a file outside the dataset
np.full((100, 2), 7, "<f4").tofile(root / "elsewhere" / "other.fdt")
for name, ref in {"absolute": str(root / "elsewhere" / "other.eeg"), "parent": "../elsewhere/other.eeg"}.items():
header = root / "dataset" / (name + ".vhdr")
header.write_text(HEADER.format(data=ref))
print("pop_loadbv", name, pop_loadbv(str(header))["data"].mean()) # 7.0 for both
def write_set(path, data, datfile):
chanlocs = np.empty((2,), dtype=[("labels", "O")]); chanlocs[0], chanlocs[1] = ("A",), ("B",)
scipy.io.savemat(path, dict(nbchan=2.0, pnts=100.0, trials=1.0, srate=250.0, xmin=0.0, xmax=0.396,
data=data, datfile=datfile, chanlocs=chanlocs))
other = str(root / "elsewhere" / "other.fdt")
write_set(str(root / "dataset" / "a.set"), other, "") # data is an absolute path
write_set(str(root / "dataset" / "b.set"), "in set file", other) # datfile is, and data says to use it
for name in ("a", "b"):
print("pop_loadset", name, pop_loadset(str(root / "dataset" / (name + ".set")))["data"].mean()) # 7.0 for bothExpected: a reference that leaves the header's directory raises (a ValueError), or the loaders take an option that allows it and the default does not.
A pipeline can refuse such headers itself before it calls eegprep, which is what ours does, but the default would protect every caller.
Checked on eegprep 0.5.0.
Activity
Fix S9 dataset loading and save layout (F15/F26/F34, #497/#561)
Address Claude review: annex-safe #561 paths, shared MFF dependency, …
Stream 9: Importers and dataset files (F10, F15, F18–F23, F26, F34, F…