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

Allow passing list of dict as argument to events parameter (=allow writing mne.annotations to VMRK) #86

Merged
merged 21 commits into from
May 27, 2022

Conversation

sappelhoff
Copy link
Member

@sappelhoff sappelhoff commented May 23, 2022

closes #77

this is what's needed to make pybv a "writer" in the MNE-Python export module.

It will allow writing more detailed events to VMRK (everything 100% in line with the spec).
Specifically we will support:

  • writing event types other than "Stimulus" --> for now I added "Stimulus", "Response", and "Comment"
    • "Comment" is special because it will allow any string as a "description", instead of positive ints as previously required for Stimulus
  • writing events pertaining to specific channels

One caveat is, that in principle the BrainVision format does not restrict the event type to "Stimulus", "Response", "Comment. --> in fact, one could have any type, see #24 (comment)

Yet in practice, we most often see:

  • Stimulus
  • Response
  • Comment
  • New Segment
  • SyncStatus

Here I implement Stimulus and Response as previously for only Stimulus --> writing integer code "event descriptions".

Comment can then be used for free form strings ... I think this suffices for now and we can see whether users will need additional stuff in the future. Let's go step by step.

  • add tests
  • docstr documentation
  • unify API to "under the hood" always use list of dict

@codecov
Copy link

codecov bot commented May 23, 2022

Codecov Report

Merging #86 (6f55d5f) into main (4e11a71) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              main       #86    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            3         3            
  Lines          431       535   +104     
==========================================
+ Hits           431       535   +104     
Impacted Files Coverage Δ
pybv/io.py 100.00% <100.00%> (ø)
pybv/tests/test_bv_writer.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e11a71...6f55d5f. Read the comment docs.

pybv/io.py Show resolved Hide resolved
pybv/io.py Outdated Show resolved Hide resolved
Copy link
Member Author

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

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

in general I should probably make it so that "under the hood", everything is using the "list of dict" API 🤔 --> when array is being passed, this is quickly converted inside the func

pybv/io.py Outdated Show resolved Hide resolved
pybv/io.py Show resolved Hide resolved
@sappelhoff sappelhoff added the enhancement New feature or request label May 24, 2022
@sappelhoff sappelhoff added this to the 0.7.0 milestone May 24, 2022
@sappelhoff sappelhoff marked this pull request as ready for review May 26, 2022 09:45
@sappelhoff sappelhoff changed the title Allow writing mne.annotations to VMRK Allow passing list of dict as argument to events parameter (=allow writing mne.annotations to VMRK) May 26, 2022
Copy link
Member Author

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

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

Hey @hoechenberger @cbrnr @adam2392 note this feature :-)

I hope this will allow us to add pybv as an "export" module to mne-python soon.

Feel free to review and let me know if you have suggestions for improvements.

Test failures are unrelated / due to some Internet issue

@sappelhoff sappelhoff requested a review from hoechenberger May 26, 2022 10:58
@sappelhoff sappelhoff requested a review from cbrnr May 26, 2022 10:58
@sappelhoff sappelhoff assigned adam2392 and unassigned adam2392 May 26, 2022
@sappelhoff sappelhoff requested a review from adam2392 May 26, 2022 10:58
Copy link
Collaborator

@cbrnr cbrnr left a comment

Choose a reason for hiding this comment

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

I didn't run and test your changes myself, but I assume that your tests cover these additions. Apart from my comments, one of the issues is the use of single or double backticks, which is currently inconsistent.

Furthermore, I was wondering if passing a pandas.DataFrame to the events parameter might be a good idea. I'd think that it would be easier to create and maintain than a list of dicts. I'm not saying that we should get rid of the list of dicts, but we could support dataframes as another option.

.flake8 Show resolved Hide resolved
pybv/io.py Show resolved Hide resolved
pybv/io.py Show resolved Hide resolved
pybv/io.py Show resolved Hide resolved
pybv/io.py Outdated Show resolved Hide resolved
pybv/io.py Outdated Show resolved Hide resolved
pybv/io.py Outdated Show resolved Hide resolved
pybv/io.py Outdated Show resolved Hide resolved
pybv/io.py Outdated Show resolved Hide resolved
pybv/io.py Outdated Show resolved Hide resolved
@hoechenberger
Copy link
Collaborator

Furthermore, I was wondering if passing a pandas.DataFrame to the events parameter might be a good idea. I'd think that it would be easier to create and maintain than a list of dicts. I'm not saying that we should get rid of the list of dicts, but we could support dataframes as another option.

+1 to that.

@sappelhoff
Copy link
Member Author

Furthermore, I was wondering if passing a pandas.DataFrame to the events parameter might be a good idea. I'd think that it would be easier to create and maintain than a list of dicts. I'm not saying that we should get rid of the list of dicts, but we could support dataframes as another option.

Fine by me if someone wants to add this in a future PR, we'd need to then add pandas as a dependency, which is okay.

@sappelhoff
Copy link
Member Author

Thanks for the review @cbrnr I addressed all your comments except the one for "single" precision, where I am unsure what to do.

@cbrnr
Copy link
Collaborator

cbrnr commented May 27, 2022

Great! Forget about it, it's just that single-precision floats can represent 7 decimal places (at least), not 6.

pybv/io.py Show resolved Hide resolved
Copy link
Member

@adam2392 adam2392 left a comment

Choose a reason for hiding this comment

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

Looked good to me, but I didn't thoroughly look thru everything. Just skimmed.

@sappelhoff sappelhoff merged commit e8f7ea4 into bids-standard:main May 27, 2022
@sappelhoff
Copy link
Member Author

Thanks for the reviews

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enable writing (MNE-Python) annotations
4 participants