Trouble reading brainvision data

Hello, I got an error:

ValueError: unconverted data remains: 0 when trying to use a function mne.io.read_raw_brainvision.

mne version is the most recent available. I suspect, smth is wrong with data format, but I don’t know how to fix it. Could somebody help me, please.

That is the code:

bv_file = 'C:/Data/strob16/NeoRec_2023-03-04_17-09-00.vhdr'
raw = mne.io.read_raw_brainvision(bv_file, preload=True, verbose=False)

That is the traceback (most recent call last)

<ipython-input-104-3fce4471b04a> in <module>
      1 # Load BrainVision data
----> 2 raw = mne.io.read_raw_brainvision(bv_file, preload=True, verbose=False)

C:\ProgramData\Anaconda3\lib\site-packages\mne\io\brainvision\brainvision.py in read_raw_brainvision(vhdr_fname, eog, misc, scale, preload, verbose)
    886     mne.io.Raw : Documentation of attribute and methods.
    887     """
--> 888     return RawBrainVision(vhdr_fname=vhdr_fname, eog=eog,
    889                           misc=misc, scale=scale, preload=preload,
    890                           verbose=verbose)

<decorator-gen-240> in __init__(self, vhdr_fname, eog, misc, scale, preload, verbose)

C:\ProgramData\Anaconda3\lib\site-packages\mne\io\brainvision\brainvision.py in __init__(self, vhdr_fname, eog, misc, scale, preload, verbose)
     73         ahdr_format = True if ext == '.ahdr' else False
     74         (info, data_fname, fmt, order, n_samples, mrk_fname, montage,
---> 75          orig_units) = _get_hdr_info(hdr_fname, eog, misc, scale)
     76 
     77         with open(data_fname, 'rb') as f:

C:\ProgramData\Anaconda3\lib\site-packages\mne\io\brainvision\brainvision.py in _get_hdr_info(hdr_fname, eog, misc, scale)
    512         if match:
    513             date_str = match[0]
--> 514             info['meas_date'] = _str_to_meas_date(date_str)
    515             break
    516     else:

C:\ProgramData\Anaconda3\lib\site-packages\mne\io\brainvision\brainvision.py in _str_to_meas_date(date_str)
    361     # they are relative (subtraction below)
    362     try:
--> 363         meas_date = datetime.strptime(date_str, '%Y%m%d%H%M%S%f')
    364     except ValueError as e:
    365         if 'does not match format' in str(e):

C:\ProgramData\Anaconda3\lib\_strptime.py in _strptime_datetime(cls, data_string, format)
    566     """Return a class cls instance based on the input string and the
    567     format string."""
--> 568     tt, fraction, gmtoff_fraction = _strptime(data_string, format)
    569     tzname, gmtoff = tt[-2:]
    570     args = tt[:6] + (fraction,)

C:\ProgramData\Anaconda3\lib\_strptime.py in _strptime(data_string, format)
    350                          (data_string, format))
    351     if len(data_string) != found.end():
--> 352         raise ValueError("unconverted data remains: %s" %
    353                           data_string[found.end():])
    354 

ValueError: unconverted data remains: 0

Thank you in advance

Hi @Julia, could you please share the associated .vmrk file? I suspect there is something wrong with the date string there. Perhaps you could also just tell use what your .vmrk file says on this line (see example here):

You can open the .vmrk file in any text editor.

It looks like the offending date string is in the .vhdr file (and not the .vmrk). But to be sure, please paste the contents of both files here.

The content of .vhdr file:

Brain Vision Data Exchange Header File Version 1.0

[Common Infos]
Codepage=UTF-8
DataFile=NeoRec_2023-03-04_17-09-00.eeg
MarkerFile=NeoRec_2023-03-04_17-09-00.vmrk
DataFormat=BINARY
DataOrientation=MULTIPLEXED
NumberOfChannels=21
SamplingInterval=1000

[Binary Infos]
BinaryFormat=IEEE_FLOAT_32

[Channel Infos]
Ch1=A1,,0.0488281,uV
Ch2=A2,,0.0488281,uV
Ch3=P3,,0.0488281,uV
Ch4=P4,,0.0488281,uV
Ch5=C3,,0.0488281,uV
Ch6=C4,,0.0488281,uV
Ch7=Cp3,,0.0488281,uV
Ch8=Cp4,,0.0488281,uV
Ch9=Fc3,,0.0488281,uV
Ch10=Fc4,,0.0488281,uV
Ch11=brow1,,0.0488281,uV
Ch12=brow2,,0.0488281,uV
Ch13=brow3,,0.0488281,uV
Ch14=eye1,,0.0488281,uV
Ch15=eye2,,0.0488281,uV
Ch16=eye3,,0.0488281,uV
Ch17=eye4,,0.0488281,uV
Ch18=eye5,,0.0488281,uV
Ch19=eye6,,0.0488281,uV
Ch20=eye7,,0.0488281,uV
Ch21=eye8,,0.0488281,uV

The content of .vmrk file:

Brain Vision Data Exchange Marker File Version 1.0

[Common Infos]
Codepage=UTF-8
DataFile=NeoRec_2023-03-04_17-09-00.eeg

[Marker Infos]
Mk1=New Segment,,1,1,0,20230341548310686000
Mk2=1,State record,50,1,0
Mk3=2,State stop,111443,1,0

Thank you for your answers!

@sappelhoff was right, this is not a valid date. It is interpreted as 2023-03-41 (year-month-day), which is invalid. Do you know when the data was recorded? I suspect that a leading zero is missing, so it could be 20230304154831068600 (2023-03-04 15:48.310686). You could directly edit this timestamp in your marker file.

1 Like

I am just wondering how this issue came up in the first place. How were these files created @Julia? It doesn’t look like “BrainVision Recorder” to me (looking at the float data type)

Actually, I don’t know about he data. Didn’t acquire it myself.

Your advice has helped! Thank you so much!

Okay, if you have any chance to contact someone who may know more, it’d be great if you could direct them to this thread to provide us with the information. This could help to solve a bug in some software, and it’s always good to get to the root of a problem :slight_smile:

OK, I’ll try to help!

1 Like