Skip to main content

FiffRawData

Namespace: FIFFLIB  ·  Library: FIFF Library

Python equivalent

mne.io.Raw in MNE-Python.

#include <fiff/fiff_raw_data.h>

class FiffRawData

Public Methods

FiffRawData()

Default constructor.


FiffRawData(p_FiffRawData)

Copy constructor.

Parameters:

  • p_FiffRawData : const FiffRawData & FIFF raw measurement which should be copied.

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).

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).

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

Source: src/examples/ex_read_raw/main.cpp

#include <iostream>
#include <vector>
#include <math.h>

#include <fiff/fiff.h>
#include <mne/mne.h>
#include <utils/generics/mne_logger.h>

//=============================================================================================================
// QT INCLUDES
//=============================================================================================================

#include <QtCore/QCoreApplication>
#include <QCommandLineParser>
#include <QFile>

//=============================================================================================================
// USED NAMESPACES
//=============================================================================================================

using namespace FIFFLIB;
using namespace MNELIB;
using namespace UTILSLIB;
using namespace Eigen;

//=============================================================================================================
// MAIN
//=============================================================================================================

//=============================================================================================================

/**
* The function main marks the entry point of the program.
* By default, main has the storage class extern.
*
* @param[in] argc (argument count) is an integer that indicates how many arguments were entered on the command line when the program was started.
* @param[in] argv (argument vector) is an array of pointers to arrays of character objects. The array objects are null-terminated strings, representing the arguments that were entered on the command line when the program was started.
* @return the value that was set to exit() (which is 0 if exit() is called via quit()).
*/
int main(int argc, char *argv[])
{
qInstallMessageHandler(MNELogger::customLogWriter);
QCoreApplication app(argc, argv);

// Command Line Parser
QCommandLineParser parser;
parser.setApplicationDescription("Read Raw Example");
parser.addHelpOption();

QCommandLineOption inputOption("fileIn", "The input file <in>.", "in", QCoreApplication::applicationDirPath() + "/../resources/data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif");
QCommandLineOption fromOption("from", "Read data from <from> (in seconds).", "from", "42.956");
QCommandLineOption toOption("to", "Read data from <to> (in seconds).", "to", "320.670");
QCommandLineOption inSamplesOption("inSamples", "Timing is set in samples.", "inSamples", "false");
QCommandLineOption keepCompOption("keepComp", "Keep compensators.", "keepComp", "false");

parser.addOption(inputOption);
parser.addOption(fromOption);
parser.addOption(toOption);
parser.addOption(inSamplesOption);
parser.addOption(keepCompOption);

parser.process(app);

QFile t_fileRaw(parser.value(inputOption));

float from = parser.value(fromOption).toFloat();
float to = parser.value(toOption).toFloat();

bool in_samples = false;
if(parser.value(inSamplesOption) == "false" || parser.value(inSamplesOption) == "0") {
in_samples = false;
} else if(parser.value(inSamplesOption) == "true" || parser.value(inSamplesOption) == "1") {
in_samples = true;
}

bool keep_comp = false;
if(parser.value(keepCompOption) == "false" || parser.value(keepCompOption) == "0") {
keep_comp = false;
} else if(parser.value(keepCompOption) == "true" || parser.value(keepCompOption) == "1") {
keep_comp = true;
}

//
// 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);

//
// Set up projection
//
qint32 k = 0;
if (raw.info.projs.size() == 0)
qInfo("No projector specified for these data\n");
else
{
//
// Activate the projection items
//
for (k = 0; k < raw.info.projs.size(); ++k)
raw.info.projs[k].active = true;

qInfo("%lld projection items activated\n",
static_cast<long long>(raw.info.projs.size()));
//
// Create the projector
//
fiff_int_t nproj = raw.info.make_projector(raw.proj);

if (nproj == 0)
qWarning("The projection vectors do not apply to these channels\n");
else
qInfo("Created an SSP operator (subspace dimension = %d)\n",nproj);
}

//
// Set up the CTF compensator
//
qint32 current_comp = raw.info.get_current_comp();
qint32 dest_comp = 0;

if (current_comp > 0)
qInfo("Current compensation grade : %d\n",current_comp);

if (keep_comp)
dest_comp = current_comp;

if (current_comp != dest_comp)
{
if(MNE::make_compensator(raw.info, current_comp, dest_comp, raw.comp))
{
raw.info.set_current_comp(dest_comp);
qInfo("Appropriate compensator added to change to grade %d.\n",dest_comp);
}
else
{
qWarning("Could not make the compensator\n");
return -1;
}
}
//
// 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;
}

qInfo("Read %d samples.\n",(qint32)data.cols());

std::cout << data.block(0,0,10,10) << std::endl;

return app.exec();
}

//=============================================================================================================
// STATIC DEFINITIONS
//=============================================================================================================

Authors of this file