Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use public get_data in epoch acquisition to avoid resetting the number of new samples #371

Merged
merged 6 commits into from
Nov 29, 2024

Conversation

mscheltienne
Copy link
Member

Closes #369

@mscheltienne mscheltienne added 🐞 bug Issue related to a bug (crash or error) or undefined behavior. stream Issues related to the Stream API. labels Nov 28, 2024
@mscheltienne mscheltienne self-assigned this Nov 28, 2024
Comment on lines +1011 to +1074
@pytest.fixture
def sinfo_marker() -> StreamInfo:
"""Stream info for a marker stream."""
sinfo = StreamInfo(
name="events",
stype="marker",
n_channels=1,
sfreq=0,
dtype=np.int8,
source_id=uuid.uuid4().hex,
)
sinfo.set_channel_names(["marker"])
return sinfo


@pytest.fixture
def outlet_marker(sinfo_marker: StreamInfo) -> Generator[StreamOutlet, None, None]:
"""Stream outlet for a marker stream."""
outlet = StreamOutlet(sinfo_marker)
yield outlet
outlet._del()
del outlet


def test_epochs_single_event(mock_lsl_stream, outlet_marker: StreamOutlet):
"""Test epochs with a single event."""
stream = StreamLSL(
3, name=mock_lsl_stream.name, source_id=mock_lsl_stream.source_id
).connect(acquisition_delay=0.1)
sinfo = outlet_marker.get_sinfo()
event_stream = StreamLSL(2, name=sinfo.name, source_id=sinfo.source_id).connect(
acquisition_delay=0.1
)
epochs = EpochsStream(
stream,
bufsize=5,
event_id=None,
event_channels="marker",
event_stream=event_stream,
tmin=0,
tmax=1.5, # large tmax to ensure that the event can't be consumed right away
baseline=None,
picks="eeg",
).connect(acquisition_delay=0)
assert epochs.n_new_epochs == 0
epochs.acquire()
time.sleep(0.5)
epochs.acquire()
assert epochs.n_new_epochs == 0
# push a single event, and then acquire it multiple times
outlet_marker.push_sample(np.array([1], dtype=sinfo.dtype))
time.sleep(0.2)
epochs.acquire()
assert epochs.n_new_epochs == 0
time.sleep(0.2)
epochs.acquire()
assert epochs.n_new_epochs == 0
# loop until we get it or timeout
start = time.monotonic()
while epochs.n_new_epochs == 0 and time.monotonic() - start < 2.6:
epochs.acquire()
time.sleep(0.2)
assert epochs.n_new_epochs == 1
assert event_stream.n_new_samples == 1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mzgsxs this test reproduces your issue and fails on main while it passes on this PR.

@mscheltienne mscheltienne enabled auto-merge (squash) November 29, 2024 09:52
@mscheltienne mscheltienne merged commit a59c84e into mne-tools:main Nov 29, 2024
26 of 27 checks passed
@mscheltienne mscheltienne deleted the fix-epochs branch November 29, 2024 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Issue related to a bug (crash or error) or undefined behavior. stream Issues related to the Stream API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EpochsStream acquisition_delay for separate event stream
1 participant