mne-python icon indicating copy to clipboard operation
mne-python copied to clipboard

Saving annotations as CSV results in wrong orig_time

Open schneijan opened this issue 5 years ago • 3 comments

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

schneijan avatar Nov 25 '20 11:11 schneijan

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

agramfort avatar Nov 25 '20 12:11 agramfort

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

mmagnuski avatar Dec 06 '20 17:12 mmagnuski

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

larsoner avatar Oct 29 '21 17:10 larsoner