mne-tools / mne-tools/mne-python
ENH: Collapse BAD_ACQ_SKIP in raw.plot
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 1.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Description
Feature description
Hi, I would like to know if there is any plan to support missing data / gaps in continous raw, especially regarding:
annotations: take into account EDGE Boundary duration (time gap) when annotatingtime_as_index: get the timestamp index of aRawthat contains time gaps
Example
Let say I have two successive recordings of 5 and 3 seconds with a 2s gap in between. I have 2 channels at 100Hz, so the recording duration is 10 seconds (in real life), and I have 8 seconds of data (here I use simple sin and cos).
import mne
import numpy as np
from datetime import datetime,timedelta,timezone
# create basic info
info = mne.create_info(
ch_names=["Ch1", "Ch2"],
sfreq=100)
# create fake successive recordings 0 and 1
start_datetime = datetime.now().replace(tzinfo=timezone.utc)
x0 = np.linspace(0, 5, 500)
x1 = np.linspace(7, 10, 300)
k = 2 # only for viz purpose
raw0 = mne.io.RawArray(np.array([np.cos(k*x0), np.sin(k*x0)]), info)
raw0.set_meas_date(start_datetime);
raw1 = mne.io.RawArray(np.array([np.cos(k*x1), np.sin(k*x1)]), info)
raw1.set_meas_date(start_datetime + timedelta(0,7)); # I know when 2nd recording started
# concat and plot recordings
raws = mne.concatenate_raws([raw0, raw1])
raws.plot();
Now if I have an event that occured between the 4th and the 8th second, I would like to annotate it regarding the start of the experiment like this:
raws.annotations.append(onset=4, duration=4, description="4s event")
raws.plot();
The current behaviour is that the 4 seconds from the onset are annotated regardless of any gap/missing data. The feature would allow to annotate data that are discontinous.
The same happens with time_as_index:
raws.time_as_index(8) # would love result: array([600])
Additional comments
This is something common that recordings have gaps between one another (see the chb-mit database). If the gap is only a few seconds long that does'nt matter, one can fill with NaN or 0 as a workaround. But sometimes gaps are few hours long.
I only used the API for a few weeks, but if you think the feature is interesting and a new user can help on that, please let me know where the changes have to be made so I can fork and test it (but I feel this could have a strong impact).
Thanks a lot !
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the raw.plot() and Raw.time_as_index() entry points, then review how concatenate_raws() represents measurement-time gaps and annotations. Define expected gap-aware behavior for both APIs and add coverage using the two-recording example; done means annotations and timestamp indexing honor the missing interval without breaking continuous recordings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data, data-visualization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100