-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix read_raw_eyelink() failure when recording blocks are empty or starting with empty values
#13571
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
Open
qian-chu
wants to merge
16
commits into
mne-tools:main
Choose a base branch
from
qian-chu:fix-read-eyelink
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+52
−22
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cb45659
FIX: handle empty first Eyelink recording block
varunkasyap c6a624f
fix bug where empty first element leads to error
qian-chu 90e172d
FIX: Corrected typos across codebase (#13563)
varunkasyap bfd14ae
FIX: Fixed incorrect module stripping in logging (#13561)
varunkasyap a44267a
Update _utils.py
qian-chu fecb178
Update _utils.py
qian-chu 911310e
Create 13571.bugfix.rst
qian-chu e289a1a
Merge branch 'mne-tools:main' into fix-read-eyelink
qian-chu 0510acc
merge two PR contents
qian-chu 629c900
fix typos
qian-chu e22ebb9
two more typos
qian-chu f9af109
add simulation of block starting with empty samples without a status …
qian-chu bb406ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cc6a93c
add third block that is completely empty
qian-chu b2c7e0c
Update test_eyelink.py
qian-chu a16a950
Merge branch 'main' into fix-read-eyelink
qian-chu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix bug where :func:`mne.io.read_raw_eyelink` fails to handle data starting with empty blocks or blocks starting with missing values, by :newcontrib:`Varun Kasyap Pentamaraju` and `Qian Chu`_. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,7 +172,7 @@ def test_fill_times(fname): | |
|
|
||
|
|
||
| def test_find_overlaps(): | ||
| """Test finding overlapping occular events between the left and right eyes. | ||
| """Test finding overlapping ocular events between the left and right eyes. | ||
|
|
||
| In the simulated blink df below, the first two rows | ||
| will be considered an overlap because the diff() of both the 'time' and | ||
|
|
@@ -360,7 +360,13 @@ def _simulate_eye_tracking_data(in_file, out_file): | |
| fp.write("START\t7452389\tRIGHT\tSAMPLES\tEVENTS\n") | ||
| fp.write(f"{new_samples_line}\n") | ||
|
|
||
| for timestamp in np.arange(7452389, 7453390): # simulate a second block | ||
| # simulate a second block that starts with empty samples | ||
| for timestamp in np.arange(7452389, 7453154): | ||
| # samples without last status column | ||
| # see https://github.com/mne-tools/mne-python/issues/13567 | ||
| fp.write(f"{timestamp}\t.\t.\t0.0\t.\t.\t.\t.\t0.0\t...\t.\t.\t.\n") | ||
|
|
||
| for timestamp in np.arange(7453154, 7453390): # second block continues | ||
| fp.write( | ||
| f"{timestamp}\t-2434.0\t-1760.0\t840.0\t100\t20\t45\t45\t127.0\t" | ||
| "...\t1497\t5189\t512.5\t.............\n" | ||
|
|
@@ -382,13 +388,22 @@ def _simulate_eye_tracking_data(in_file, out_file): | |
| "1497.0\t5189.0\t512.5\t.............\n" | ||
| ) | ||
| button_idx += 1 | ||
| fp.write("END\t7453390\tRIGHT\tSAMPLES\tEVENTS\n") | ||
| fp.write("END\t7453490\tRIGHT\tSAMPLES\tEVENTS\n") | ||
|
|
||
| # simulate a third block with no samples at all | ||
| fp.write("START\t7454490\tRIGHT\tSAMPLES\tEVENTS\n") | ||
| fp.write(f"{new_samples_line}\n") | ||
| for timestamp in np.arange(7454490, 7454990): | ||
| fp.write( | ||
| f"{timestamp}\t.\t.\t0.0\t.\t.\t.\t.\t0.0\t...\t.\t.\t.\n" # All empty | ||
| ) | ||
| fp.write("END\t7454990\tRIGHT\tSAMPLES\tEVENTS\n") | ||
|
|
||
|
|
||
| @requires_testing_data | ||
| @pytest.mark.parametrize("fname", [fname_href]) | ||
| def test_multi_block_misc_channels(fname, tmp_path): | ||
| """Test a file with many edge casses. | ||
| """Test a file with many edge cases. | ||
|
|
||
| This file has multiple acquisition blocks, each tracking a different eye. | ||
| The coordinates are in raw units (not pixels or radians). | ||
|
|
@@ -399,7 +414,7 @@ def test_multi_block_misc_channels(fname, tmp_path): | |
|
|
||
| with ( | ||
| _record_warnings(), | ||
| pytest.warns(RuntimeWarning, match="Raw eyegaze coordinates"), | ||
| pytest.warns(RuntimeWarning, match="Raw pupil position data detected"), | ||
| pytest.warns(RuntimeWarning, match="The eye being tracked changed"), | ||
| ): | ||
| raw = read_raw_eyelink(out_file, apply_offsets=True) | ||
|
|
@@ -426,15 +441,15 @@ def test_multi_block_misc_channels(fname, tmp_path): | |
| assert raw.ch_names == chs_in_file | ||
| assert raw.annotations.description[1] == "SYNCTIME" | ||
|
|
||
| assert raw.annotations.description[-7] == "BAD_ACQ_SKIP" | ||
| assert np.isclose(raw.annotations.onset[-7], 1.001) | ||
| assert np.isclose(raw.annotations.duration[-7], 0.1) | ||
| assert raw.annotations.description[-8] == "BAD_ACQ_SKIP" | ||
| assert np.isclose(raw.annotations.onset[-8], 1.001) | ||
| assert np.isclose(raw.annotations.duration[-8], 0.1) | ||
|
Comment on lines
-429
to
+446
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Event indices all move "up" by one becase a new "BAD_ACQ_SKIP" is introduced between block 2 and 3. |
||
|
|
||
| data, times = raw.get_data(return_times=True) | ||
| assert not np.isnan(data[0, np.where(times < 1)[0]]).any() | ||
| assert np.isnan(data[0, np.logical_and(times > 1, times <= 1.1)]).all() | ||
|
|
||
| assert raw.annotations.description[-6] == "button_1_press" | ||
| assert raw.annotations.description[-7] == "button_1_press" | ||
| button_idx = [ | ||
| ii | ||
| for ii, desc in enumerate(raw.annotations.description) | ||
|
|
@@ -443,6 +458,9 @@ def test_multi_block_misc_channels(fname, tmp_path): | |
| assert len(button_idx) == 6 | ||
| assert_allclose(raw.annotations.onset[button_idx[0]], 2.102, atol=1e-3) | ||
|
|
||
| assert raw.annotations.description[-1] == "BAD_ACQ_SKIP" | ||
| assert_allclose(raw.annotations.duration[-1], 1.0, atol=1e-3) | ||
|
|
||
| # smoke test for reading events with missing samples (should not emit a warning) | ||
| find_events(raw, verbose=True) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a small typo, because the timestamps are from 7453390 to 7453490, therefore block end message should be 7453490
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!