BidsRawData
Namespace: BIDSLIB · Library: BIDS Library
mne_bids.read_raw_bids in MNE-Python.
#include <bids/bids_raw_data.h>
class BIDSLIB::BidsRawData
Central container for a BIDS raw dataset, bundling electrophysiological data with all associated sidecar metadata.
BidsRawData is the primary data object of the BIDS library, analogous to FiffRawData for the FIFF library. It owns both the data and the I/O logic:
read()— static factory that loads a BIDS dataset from disk.write()— member that writes the current dataset to a BIDS directory.
Sidecar and coordinate-system fields that are derivable from FiffInfo (sampling frequency, channel counts) are computed on write and applied to FiffInfo on read. Only fields carrying independent information are stored as explicit members.
BidsRawData data = BidsRawData::read(ieeg); // raw data plus channels, events, electrodes and sidecar metadata
QTemporaryDir out;
BidsRawData::WriteOptions options;
options.datasetName = "ex_bids";
const BIDSPath written = data.write(BIDSPath(out.path(), "01", "01", "rest", "ieeg", "ieeg", ".vhdr"), vhdr, options);
const BidsRawData readBack = BidsRawData::read(written);
Public Methods
BidsRawData()
Default constructor.
Creates an empty, invalid BidsRawData.
~BidsRawData()
Destructor.
BidsRawData(other)
operator=(other)
BidsRawData()
operator=()
write(bidsPath, sourcePath, options)
Write this dataset to a BIDS-compliant directory.
Orchestrates writing of: Directory structure: root/sub-XX/[ses-YY/]<datatype>/
Raw data file — copies the source file into the BIDS directory
*_channels.tsv
*_electrodes.tsv + *_coordsystem.json
*_events.tsv
*_{datatype}.json (iEEG sidecar)
dataset_description.json
Parameters:
-
bidsPath : const BIDSPath & Target
BIDSPath(root, subject, task, datatype, suffix, extension). -
sourcePath : const QString & Path to the original raw data file to copy. If empty, the raw data file is not copied.
-
options : const WriteOptions & Write options (overwrite, dataset name, etc.).
Returns:
write(bidsPath, sourcePath)
Convenience overload — write with default options.
Parameters:
-
bidsPath : const BIDSPath & Target
BIDSPath(root, subject, task, datatype, suffix, extension). -
sourcePath : const QString & Path to the original raw data file to copy; if empty, it is not copied.
Returns:
isValid()
Returns true if the data was loaded successfully.
Returns:
- bool — True if the data is valid, false otherwise.
setValid(bValid)
Marks the data as valid or invalid.
Parameters:
- bValid : bool True to mark the data as valid, false to mark it invalid.
clear()
Clears all data members and resets to invalid state.
Static Methods
read(bidsPath)
Read a BIDS dataset from disk.
Static factory that orchestrates reading of: Raw data file via the appropriate format reader (EDF, BrainVision, …)
*_channels.tsv → channel types, units, bad-channel marking
*_electrodes.tsv + *_coordsystem.json → digitization points
*_events.tsv → event annotations
*_{datatype}.json → line frequency and recording metadata
The BIDSPath must have at minimum: root, subject, datatype, suffix, extension.
Parameters:
Returns:
- BidsRawData — Populated
BidsRawData. CheckisValid()to determine success.
createReader(sExtension)
Create the appropriate format reader for a given file extension.
Parameters:
- sExtension : const QString & File extension including dot (e.g. ".vhdr", ".edf").
Returns:
- AbstractFormatReader::UPtr — Shared pointer to the reader, or nullptr if unsupported.
Example
- Full source:
src/examples/ex_bids/main.cpp - Build target:
ex_bids(runs under CTest) - Data: mne-cpp-test-data
Used in examples
ex_bids
BIDS library: paths, sidecar TSVs, BrainVision/EDF readers and a raw-data round trip.
std::unique_ptr<AbstractFormatReader> edf = BidsRawData::createReader(".edf"); // or construct EDFReader directly
const bool edfOpen = edf->open(BIDSPath(root, "02", "01", "rest", "eeg", "eeg", ".edf").filePath());
const FIFFLIB::FiffInfo edfInfo = edf->getInfo();
const MatrixXf edfHead = edf->readRawSegment(0, 201);
// mne.io.read_raw_edf: 25 channels at 128 Hz, 1228 samples, first channel "EEG Fp1"; data[3, 200] = 0.1757724
ok &= expect(edfOpen && dynamic_cast<EDFReader*>(edf.get()) != nullptr && edf->formatName() == "EDF" && edfInfo.nchan == 25 && edfInfo.ch_names.first() == "EEG Fp1" && edf->getSampleCount() == 1228 && near(edfHead(0, 0), 0.17594066, 1e-5) && near(edfHead(3, 200), 0.17577240650034331, 1e-5),
QString("EDF: %1 channels, %2 samples, (3,200) = %3 match mne").arg(edfInfo.nchan).arg(edf->getSampleCount()).arg(edfHead(3, 200), 0, 'g', 8));
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>