FiffRawData
Namespace: FIFFLIB · Library: FIFF Library
mne.io.Raw in MNE-Python.
#include <fiff/fiff_raw_data.h>
class FIFFLIB::FiffRawData
Continuous FIFF raw recording: FiffInfo plus a random-access directory of FIFF_DATA_BUFFER tags.
The directory built into FiffRawDir lets segment reads jump straight to the buffers covering the requested sample window, decode them through the channel cals and active projectors and return a contiguous channel × sample Eigen matrix without rescanning the file.
Open a recording and pick the MEG channels plus the trigger channel:
//
// Setup for reading the raw data
//
FiffRawData raw(t_fileRaw);
//
// Set up pick list: MEG + STI 014 - bad channels
//
QStringList include;
include << "STI 014";
bool want_meg = true;
bool want_eeg = false;
bool want_stim = false;
RowVectorXi picks = raw.info.pick_types(want_meg, want_eeg, want_stim, include, raw.info.bads);
Read a window of the picked channels, in seconds or in samples:
//
// Read a data segment
// times output argument is optional
//
bool readSuccessful = false;
MatrixXd data;
MatrixXd times;
if (in_samples)
readSuccessful = raw.read_raw_segment(data, times, (qint32)from, (qint32)to, picks);
else
readSuccessful = raw.read_raw_segment_times(data, times, from, to, picks);
if (!readSuccessful) {
qWarning("Could not read raw segment.\n");
return -1;
}
Public Methods
FiffRawData()
Default constructor.
FiffRawData(p_FiffRawData)
Copy constructor.
Parameters:
- p_FiffRawData : const FiffRawData & FIFF raw measurement which should be copied.
operator=(other)
Copy assignment.
Every member has value semantics, so the compiler-generated member-wise assignment is correct. It is declared explicitly because declaring a copy constructor and/or a destructor deprecates the implicitly generated one.
Parameters:
- other : const FiffRawData & Object to assign from.
Returns:
- FiffRawData & — reference to this object.
FiffRawData(p_IODevice)
Constructs fiff raw data, by reading from a IO device.
Parameters:
- p_IODevice : QIODevice & IO device to read the raw data from .
FiffRawData(p_IODevice, b_littleEndian)
Constructs fiff raw data, by reading from a IO device with specified endianness.
Parameters:
-
p_IODevice : QIODevice & IO device to read the raw data from.
-
b_littleEndian : bool If true, read data as little-endian.
~FiffRawData()
Destroys the FiffInfo.
clear()
Initializes the fiff raw measurement data.
isEmpty()
True if fiff raw data are empty.
Returns:
- bool — true if fiff raw data are empty.
read_raw_segment(data, times, from, to, sel, do_debug)
Read a specific raw data segment.
Parameters:
-
data : Eigen::MatrixXd & returns the data matrix (channels x samples).
-
times : Eigen::MatrixXd & returns the time values corresponding to the samples.
-
from : fiff_int_t first sample to include. If omitted, defaults to the first sample in data (optional).
-
to : fiff_int_t last sample to include. If omitted, defaults to the last sample in data (optional).
-
sel : const Eigen::RowVectorXi & channel selection vector (optional).
-
do_debug : bool Print diagnostic output while reading.
Returns:
- bool — true if succeeded, false otherwise.
read_raw_segment(data, times, multSegment, from, to, sel, do_debug)
Read a specific raw data segment.
Parameters:
-
data : Eigen::MatrixXd & returns the data matrix (channels x samples).
-
times : Eigen::MatrixXd & returns the time values corresponding to the samples.
-
multSegment : Eigen::SparseMatrix< double > & used multiplication matrix (compensator,projection,calibration).
-
from : fiff_int_t first sample to include. If omitted, defaults to the first sample in data (optional).
-
to : fiff_int_t last sample to include. If omitted, defaults to the last sample in data (optional).
-
sel : const Eigen::RowVectorXi & channel selection vector (optional).
-
do_debug : bool Print diagnostic output while reading.
Returns:
- bool — true if succeeded, false otherwise.
read_raw_segment_times(data, times, from, to, sel)
Read a specific raw data segment.
Parameters:
-
data : Eigen::MatrixXd & returns the data matrix (channels x samples).
-
times : Eigen::MatrixXd & returns the time values corresponding to the samples.
-
from : float starting time of the segment in seconds.
-
to : float end time of the segment in seconds.
-
sel : const Eigen::RowVectorXi & optional channel selection vector.
Returns:
- bool — true if succeeded, false otherwise.
save(p_IODevice, picks, decim, from, to)
Save raw data to a FIFF file, optionally with decimation and channel picking.
Ported from save.c (MNE-C).
Parameters:
-
p_IODevice : QIODevice & Output device to write to.
-
picks : const Eigen::RowVectorXi & Channel indices to include (empty = all channels).
-
decim : int Decimation factor (1 = no decimation).
-
from : int First sample to save (-1 = from start of raw data).
-
to : int Last sample to save (-1 = to end of raw data).
Returns:
- bool — true on success.
Example
- Full source:
src/examples/ex_read_raw/main.cpp - Build target:
ex_read_raw(compiled in CI) - Data: MNE sample data
Used in examples
ex_fiff_structure
FIFF library: fixed-length epochs, CTF compensation, the file directory and raw buffers, and handing.
QFile rawFile(rawPath);
FiffRawData raw(rawFile);
MatrixXd data;
MatrixXd times;
ok &= raw.read_raw_segment(data, times); // all 6007 samples
const double sfreq = raw.info.sfreq;
const QList<FiffEpochData> epochs = FiffEpochs::makeFixedLengthEpochs(data, sfreq, 2.0, 0.5); // 2 s, 0.5 s overlap
const FiffEvoked average = FiffEpochs::averageEpochs(epochs, sfreq);
// mne.make_fixed_length_epochs(raw, duration=2, overlap=0.5): 13 epochs of 601 samples, 450 samples apart
ok &= expect(epochs.size() == 13 && epochs[0].data.cols() == 601 && std::lround((epochs[1].tmin - epochs[0].tmin) * sfreq) == 450 && average.nave == 13,
"FiffEpochs/FiffEpochData: 13 fixed-length epochs like mne.make_fixed_length_epochs, averaged over 13");
ex_dsp_rt
DSP real-time workers: averaging, covariance, noise spectrum, connectivity, HPI fitting and inverse operators.
// ---------------------------------------------------------------------------------------------------------
// HPI: fit the four coils of the test recording on the worker and directly
QFile hpiFile(dataDir + "/MEG/sample/test_hpiFit_raw.fif");
FiffRawData hpiRaw(hpiFile);
const FiffInfo::SPtr hpiInfo = FiffInfo::SPtr::create(hpiRaw.info);
MatrixXd hpiData;
MatrixXd hpiTimes;
ok &= hpiRaw.read_raw_segment(hpiData, hpiTimes, hpiRaw.first_samp, hpiRaw.first_samp + 399);
MatrixXd projectors = MatrixXd::Identity(hpiInfo->nchan, hpiInfo->nchan);
FiffInfo projInfo = *hpiInfo;
for (FiffProj& proj : projInfo.projs) {
proj.active = true;
}
projInfo.make_projector(projectors);
ex_averaging
Average data from a raw data file.
// Setup for reading the raw data
FiffRawData raw(t_fileRaw);
MNE::setup_compensators(raw, dest_comp, keep_comp);
Also used in ex_clustered_inverse_mne_raw, ex_clustered_inverse_pwl_rap_music_raw, ex_clustered_inverse_rap_music_raw, ex_compute_forward, ex_connectivity, ex_connectivity_comparison, ex_connectivity_performance, ex_disp, ex_dsp_maxwell, ex_fiff_api, ex_filtering, ex_fwd_api, ex_hpiFit, ex_inv_hpi, ex_inverse_mne_raw, ex_make_layout, ex_mne_api, ex_read_epochs, ex_read_raw, ex_read_write_raw, ex_roi_clustered_inverse_pwl_rap_music, ex_st_clustered_inverse_pwl_rap_music.
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>
- Christof Pieloth <pieloth@labp.htwk-leipzig.de>
- Lorenz Esch <lorenz.esch@tu-ilmenau.de>
- Gabriel Motta <gabrielbenmotta@gmail.com>
- Juan GPC <jgarciaprieto@mgh.harvard.edu>