MNERawData
Namespace: MNELIB · Library: MNE Library
#include <mne/mne_raw_data.h>
class MNELIB::MNERawData
Implements the MNE Raw Data (Replaces *mneRawData,mneRawDataRec; struct of MNE-C mne_types.h).
A comprehensive raw data structure
// MNE-C style reader: buffer directory, channel selection, projection and overlap-add filter
MNEFilterDef filter; // 40 Hz lowpass, 5 Hz transition, 4096-sample blocks
filter.filter_on = true;
filter.size = 4096;
filter.taper_size = 2048;
filter.lowpass = filter.eog_lowpass = 40.0f;
filter.lowpass_width = filter.eog_lowpass_width = 5.0f;
std::unique_ptr<MNERawData> mneRaw(MNERawData::open_file(rawFile.fileName(), false, false, filter));
const MNERawInfo& rawInfo = *mneRaw->info;
const MNERawBufDef& firstBuffer = mneRaw->bufs.front();
MNEChSelection sel; // channel names are stored without spaces
sel.chspick = sel.chspick_nospace = {"MEG0113", "EEG001", "EOG061"};
sel.nchan = sel.ndef = static_cast<int>(sel.chspick.size());
sel.pick_deriv = VectorXi::Constant(sel.nchan, -1);
sel.pick.resize(sel.nchan);
for (int c = 0; c < sel.nchan; ++c) {
sel.pick[c] = static_cast<int>(mneRaw->ch_names.indexOf(sel.chspick[c]));
}
const int ns = 25;
Matrix<float, Dynamic, Dynamic, RowMajor> segment(sel.nchan, ns);
std::vector<float*> rows{segment.row(0).data(), segment.row(1).data(), segment.row(2).data()};
mneRaw->pick_data(&sel, mneRaw->first_samp + 2990, ns, rows.data()); // calibrated, across a buffer boundary
const double eegRaw = segment(1, 0);
mneRaw->pick_data_filt(&sel, mneRaw->first_samp + 2990, ns, rows.data());
const double eegFilt = segment(1, 0);
// The file stores its 4 SSP projectors as inactive; makeProjection switches them on
std::unique_ptr<MNEProjOp> proj;
MNEProjOp::makeProjection({rawFile.fileName()}, rawInfo.chInfo, rawInfo.nchan, proj);
proj->assign_channels(mneRaw->ch_names, rawInfo.nchan);
proj->make_proj();
const MNEProjItem& firstItem = proj->items[0];
mneRaw->proj = std::move(proj);
mneRaw->pick_data_proj(&sel, mneRaw->first_samp + 2990, ns, rows.data());
const double eegProj = segment(1, 0);
Public Methods
MNERawData()
Constructs the MNE Raw Data Refactored: new_raw_data (mne_raw_data.c).
~MNERawData()
Destroys the MNE Raw Data Refactored: mne_raw_free_data (mne_raw_data.c).
add_filter_response(highpass_effective)
Create a frequency-domain filter response from the current filter definition and sampling frequency, replacing any existing response.
Parameters:
- highpass_effective : *int ** Set to non-zero if the highpass filter is active.
setup_filter_bufs()
Allocate filter output buffers spanning the entire raw data range (with taper overlap), initialize a ring buffer for filtered data, and create the filter response.
setFilter(newFilter)
Switch to another filter.
Already filtered data is discarded, so later pick_data_filt calls return data filtered with the new definition. Refactored: filter change handling of mne_browse_raw (analyze.c, mne_compare_filters, mne_raw_forget_filtered).
Parameters:
- newFilter : const MNEFilterDef & The new filter definition.
Returns:
- bool — true if the filter changed, false if it equals the current one.
load_one_buffer(buf)
Read a single raw data buffer from the FIFF file into memory, allocating from the ring buffer if needed.
Parameters:
- buf : *MNERawBufDef ** The buffer definition to load.
Returns:
- int — OK on success, FAIL on read error.
compensate_buffer(buf)
Apply CTF compensation to a loaded raw data buffer if its compensation status differs from the desired one.
Parameters:
- buf : *MNERawBufDef ** The buffer to compensate.
Returns:
- int — OK on success, FAIL on error.
pick_data(sel, firsts, ns, picked)
Extract raw data samples for selected channels (including derived channels) with compensation applied, zero-padding or edge-extending as needed at boundaries.
Parameters:
-
sel : mneChSelection Channel selection descriptor.
-
firsts : int First sample index (absolute).
-
ns : int Number of samples to extract.
-
picked : *float *** Array of per-channel data vectors (pre-allocated).
Returns:
- int — OK on success, FAIL on error.
pick_data_proj(sel, firsts, ns, picked)
Extract raw data with SSP projection applied to each time sample before channel selection.
Parameters:
-
sel : mneChSelection Channel selection descriptor.
-
firsts : int First sample index (absolute).
-
ns : int Number of samples to extract.
-
picked : *float *** Array of per-channel data vectors (pre-allocated).
Returns:
- int — OK on success, FAIL on error.
load_one_filt_buf(buf)
Load a single filter-sized buffer by picking projected unfiltered data with taper margins for overlap-add filtering.
Parameters:
- buf : *MNERawBufDef ** The filter buffer definition to load.
Returns:
- int — OK on success, FAIL on error.
pick_data_filt(sel, firsts, ns, picked)
Pick filtered data for a channel selection by loading filter buffers, applying the frequency-domain filter per channel (skipping stimulus channels), and accumulating overlapping results.
Parameters:
-
sel : mneChSelection Channel selection descriptor.
-
firsts : int First sample index (absolute).
-
ns : int Number of samples to extract.
-
picked : *float *** Array of per-channel data vectors (pre-allocated).
Returns:
- int — OK on success, FAIL on error.
attachDerivations(derivations, keepPrevious)
Attaches channel derivations (MNE-C mne_raw_attach_derivations): merges them into deriv, matches the merged set to the channels of the file into deriv_matched and validates it against the channel info.
Parameters:
-
derivations : const MNEDerivSet & The derivations to add.
-
keepPrevious : bool Keep the derivations attached before instead of replacing them.
Returns:
- int — The number of derived channels that are valid for these data.
Static Methods
open_file_comp(name, omit_skip, allow_maxshield, filter, comp_set)
Open a raw FIFF file with explicit compensation grade.
Reads channel info, compensation data, SSS data, sets up data/filter buffers and bad channels, and returns a fully initialized raw data object.
Parameters:
-
name : const QString & Path to the raw FIFF file.
-
omit_skip : int If non-zero, discard initial skip samples.
-
allow_maxshield : int If non-zero, allow MaxShield data.
-
filter : const MNEFilterDef & Filter definition to apply.
-
comp_set : int Desired compensation grade (-1 for file native).
Returns:
- *MNERawData ** — A new raw data object, or NULL on failure. Caller takes ownership.
open_file(name, omit_skip, allow_maxshield, filter)
Open a raw FIFF file using the file's native compensation grade.
Convenience wrapper for open_file_comp() with comp_set = -1.
Parameters:
-
name : const QString & Path to the raw FIFF file.
-
omit_skip : int If non-zero, discard initial skip samples.
-
allow_maxshield : int If non-zero, allow MaxShield data.
-
filter : const MNEFilterDef & Filter definition to apply.
Returns:
- *MNERawData ** — A new raw data object, or NULL on failure. Caller takes ownership.
Example
- Full source:
src/examples/ex_mne_api/main.cpp - Build target:
ex_mne_api(runs under CTest) - Data: mne-cpp-test-data
Used in examples
ex_mne_api
MNE library: BEM surfaces, surface projection, ICP, source spaces and epochs.
filter.taper_size = 2048;
filter.lowpass = filter.eog_lowpass = 40.0f;
filter.lowpass_width = filter.eog_lowpass_width = 5.0f;
std::unique_ptr<MNERawData> mneRaw(MNERawData::open_file(rawFile.fileName(), false, false, filter));
const MNERawInfo& rawInfo = *mneRaw->info;
const MNERawBufDef& firstBuffer = mneRaw->bufs.front();
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>