mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.72k stars 1.32k forks source link

Saving annotations as CSV results in wrong orig_time #8573

Open schneijan opened 3 years ago

schneijan commented 3 years ago

Describe the bug

When creating annotations with orig_time=None and saving them to a *.csv file using the save function, orig_time=None is ignored and replaced by 1970-01-01 00:00:00. Thus, when importing the annotations again, the orig_time of the imported annotations differs from the original ones. This seems odd to me and not intended, because the issue does not occur when saving the annotations to *.txt file

Steps to reproduce

Here is a minimal working example:

# Create annotation and save it to CSV file
annotations = mne.Annotations(onset=[2.5], duration=[5], description=["Test"], orig_time=None)
annotations.save("annotation.csv")

# Read annotation from file again
read_annotations = mne.read_annotations("annotation.csv")

# Output orig_time
print(read_annotations[0]['orig_time']) #Outputs 1970-01-01 00:00:02.500000+00:00 instead of None

Expected results

I expected the output to be None. This is even the result when using a *.txt file instead of a *.csv file.

Actual results

1970-01-01 00:00:02.500000+00:00 In the annotations dict, the orig_time is stored as ('orig_time', datetime.datetime(1970, 1, 1, 0, 0, 2, 500000, tzinfo=datetime.timezone.utc))

agramfort commented 3 years ago

there is a use case for files with absolute time stamps and a relative.

what was discussed in the past is that .csv will be index by time to orig_time None is hard to make it work ok. What I would suggest is to prevent saving annotations to csv without a valid orig_time

mmagnuski commented 3 years ago

(@agramfort - I think you meant "prevent" so I took the liberty to correct the typo :) )

larsoner commented 3 years ago

Bumping to the next release milestone, I don't think we can look into this in the next couple of days