question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Annotation and crop - different onset points after reloading the saved croppend data

See original GitHub issue

Describe the bug

I suspect that this issue is similar to the #9383. The issue only occurs when a raw instance created with Annotation. Originally labeled data as brain vision files are work fine. Cropping the instance, saving and reloading it shows the annotations in the original place before the cropping.

Steps to reproduce

import numpy as np
import mne
CH_NUM = 32
FS = 160

data = np.zeros((CH_NUM, FS * 20))
ch_names = [f'EEG{i}' for i in range(CH_NUM)]
ch_types = ['eeg'] * len(ch_names)
onset = [8, 12, 18]
duration = [2] * len(onset)
description = list(range(len(onset)))

info = mne.create_info(ch_names, ch_types=ch_types, sfreq=FS)
raw = mne.io.RawArray(data, info)
annotation = mne.Annotations(onset, duration, description)
raw = raw.set_annotations(annotation)

sess = raw.copy()
sess.crop(5, 18)
file = 'test_file_raw.fif'
sess.save(file, overwrite=True)
sess.plot(block=False)
r = mne.io.read_raw(str(file))
r.plot(block=False)
raw.plot(block=True)

Expected results

I expect that the annotated data should look like the same before and after saving it.

Actual results

The annotations are shifted…

Additional information

Platform: Windows-10-10.0.19041-SP0 Python: 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] Executable: C:\Programs\Miniconda3\envs\bci2\python.exe CPU: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel: 12 cores Memory: Unavailable (requires “psutil” package) mne: 0.23.0 numpy: 1.19.3 {blas=D:\a\1\s\numpy\build\openblas_info, lapack=D:\a\1\s\numpy\build\openblas_lapack_info} scipy: 1.6.0 matplotlib: 3.3.3 {backend=TkAgg} sklearn: 0.24.0 numba: Not found nibabel: Not found nilearn: Not found dipy: Not found cupy: Not found pandas: 1.2.0 mayavi: Not found pyvista: Not found vtk: Not found

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
larsonercommented, Oct 22, 2021

@mscheltienne I’m inclined to bump the milestone on this from 0.24 to 1.0 so we don’t have to rush a fix in the next week that will potentially break other stuff.

0reactions
mscheltiennecommented, Oct 1, 2021

A few words following discord discussion. The assumption is that:

  • Annotation onset should be relative to the beginning of the data reflected by first_samp. -> Different from @drammock comment: the origin is the beginning of the raw object instance, regardless of what its first_samp value is.
  • With this assumption, the problem would be limited to the I/O roundtrip.

I’ll have a look when I have time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The events and Annotations data structures - MNE-Python
An annotation is defined by an onset, a duration, and a string description. It can contain information about the experiment, but also details...
Read more >
Not able to size the annotations - TechSmith Support
I tried, but this way you can only crop but not resize - meaning that the text in the annotation will be cut-off...
Read more >
How to translate points on image after cropping it and resizing ...
This cropped image will be resized back to original image. However, when I do that my annotation gets completely wrong coordinates when using ......
Read more >
Resting State EEG Cropping - MNE Forum - Discourse
Do you want to crop the raw data to remove all signal before the onset of a particular annotation and after onset +...
Read more >
Crop hints tutorial | Cloud Vision API
A successful Crop Hints response returns the coordinates for a bounding box cropped around the dominant object or face in the image.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found