Conversion to .fif format in MNE

Hello,

I have a problem linked to the conversion of files into .fif format in MNE, in a way that these are readable in fieldtrip.
My original files are .csv tables with samples as rows and 8 EEG channels and one trigger as columns.
I read these and transform them to .fif format using the following code:

chan_names = list(data_csv.columns.values)
channel_types = ['eeg'] * 8 + ['stim']
dValues = data_csv.values.T
infor = create_info(channel_names, sfreq, channel_types)
eeg_raw = RawArray(dValues, info=infor, verbose=False)
eeg_raw.notch_filter(...)
eeg_raw.filter(...)
eeg_raw.save(eeg_raw.fif)

The issue arises when I’m trying to process those files in the Matlab “ERP PCA Toolkit” from Joseph Dien (ERP PCA Toolkit Activity, The ERP PCA Toolkit: an open source program for advanced statistical analysis of event-related potential data - PubMed). This toolbox can read in files in .fif format, but when it tries, it throws an error in the fieldtrip ‘fiff_open’ function. In exchange with the developer I learned that fiff_open.m wants the .fif file to start with the value 100 (FIFF.FIFF_FILE_ID) whereas MNE’s “RawArray” is not generating the file with 100 as the starting value, but instead 1296127052 (too long to be one of the .fif header codes).

So I’m wondering, is this some issue with how I convert these files, or with the MNE code itself?

  • MNE version: e.g. 1.0.3
  • fieldtrip version: 20221223
  • operating system: Windows 10
2 Likes

I’d be interested as well. @agramfort or @larsoner, as someone with a lot of experience with FIFF, do you have any advice?

1 Like

Can you share the file?

If you mne show_fiff <your_filename> does the file structure make sense?

Sure, here is an example file:

The ouput of ‘show_fiff’ is a bit cryptic for me:

999 = FIFFB_ROOT
    100 = FIFF_FILE_ID (20b ids) = {'version': 65540, 'machid': a ... dict len=4
    101 = FIFF_DIR_POINTER (4b >i4) = [-1]
    106 = FIFF_FREE_LIST (4b >i4) = [-1]
    108 = FIFF_NOP (0b nul)
    100 = FIFFB_MEAS
        103 = FIFF_BLOCK_ID (20b ids) = {'version': 65540, 'machid': a ... dict len=4
        101 = FIFFB_MEAS_INFO
            222 = FIFF_COORD_TRANS (104b cts) = <Transform | MEG device->head> ... dict len=3
            200 = FIFF_NCHAN (4b >i4) = [8]
            201 = FIFF_SFREQ (4b >f4) = [250.]
            219 = FIFF_LOWPASS (4b >f4) = [35.]
            223 = FIFF_HIGHPASS (4b >f4) = [1.]
            202 = FIFF_DATA_PACK (4b >i4) = [4]
            x8: 203 = FIFF_CH_INFO (96b cis) = {'scanno': 8, 'logno': 9, 'kin ... dict len=11
            107 = FIFFB_ISOTRAK
                x10: 213 = FIFF_DIG_POINT (20b dps) = {'kind': 3 (FIFFV_POINT_EEG),  ... dict len=4
        102 = FIFFB_RAW_DATA
            x317: 300 = FIFF_DATA_BUFFER (4928b >f4) = [-1.5370786e+00  2.6221213e+00 ... array size=1232