Skip to content

Conversation

@JuliusWelzel
Copy link
Contributor

@JuliusWelzel JuliusWelzel commented Aug 25, 2025

PR Description

This PR adds motion as an allowed datatype for the BIDSPath with relevant changes in the config.py in a693a4e.

Closes #1145.

Merge checklist

Maintainer, please confirm the following before merging.
If applicable:

  • All comments are resolved
  • This is not your own PR
  • All CIs are happy
  • PR title starts with [MRG]
  • whats_new.rst is updated
  • New contributors have been added to CITATION.cff
  • PR description includes phrase "closes <#issue-number>"

@JuliusWelzel
Copy link
Contributor Author

The CI's fail for two example scripts anonymize_dataset.py and bidspath.py (Error here).

If I run the same scripts locally, I cannot recreate the same error. @sappelhoff, maybe you have an idea how to solve this?

@scott-huberty
Copy link
Collaborator

@JuliusWelzel If I checkout your branch locally, I do get the same error that the CI's are hitting:

RuntimeError: Found more than one matching data file for the requested recording. While searching:
    BIDSPath(
    root: /Users/scotterik/devel/repos/mne-bids/mne_bids/tests/data/tiny_bids
    datatype: eeg
    basename: sub-01_ses-eeg)
Found 5 paths:
    /Users/scotterik/devel/repos/mne-bids/mne_bids/tests/data/tiny_bids/sub-01/ses-eeg/eeg/sub-01_ses-eeg_electrodes.tsv
    /Users/scotterik/devel/repos/mne-bids/mne_bids/tests/data/tiny_bids/sub-01/ses-eeg/eeg/sub-01_ses-eeg_space-CapTrak_electrodes.tsv
    /Users/scotterik/devel/repos/mne-bids/mne_bids/tests/data/tiny_bids/sub-01/ses-eeg/eeg/sub-01_ses-eeg_task-rest_channels.tsv
    /Users/scotterik/devel/repos/mne-bids/mne_bids/tests/data/tiny_bids/sub-01/ses-eeg/eeg/sub-01_ses-eeg_task-rest_eeg.vhdr
    /Users/scotterik/devel/repos/mne-bids/mne_bids/tests/data/tiny_bids/sub-01/ses-eeg/eeg/sub-01_ses-eeg_task-rest_events.tsv

I think I see the problem.

Comment on lines +152 to +155
allowed_extensions_motion = [
".tsv", # Tab-separated values
]

Copy link
Collaborator

@scott-huberty scott-huberty Aug 27, 2025

Choose a reason for hiding this comment

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

This seems to be the line causing the issue, which makes sense because the EEG BIDS datasets have sidecar files that are just text files. So adding .tsv to the allowed datafile extensions seems to be confusing some of mne_bids internal functions..

Motion data might be the first modality with data that are stored in simple text files that we are trying to add into MNE-BIDS, which is why we are hitting this problem now. But I know that Eye-tracking BIDS will have the same issue.. So supporting these data might require more refactoring of the codebase.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As a grumpy sidenote, I never understood why BIDS encourages storing some modalities of data in text files... !

Copy link
Member

Choose a reason for hiding this comment

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

without having looked into it too deeply, that could be something that needs refactoring, yes.

Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

couple minor comments. I haven't yet tried to debug the CI error

"description",
"suffix",
"extension",
"tracking-system",
Copy link
Member

Choose a reason for hiding this comment

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

this is hyphen-separated, but below in ALLOWED_PATH_ENTITIES_SHORT it's underscore_separated. Is that intentional?

"physio",
"stim", # behavioral
"nirs",
"motion", # motion
Copy link
Member

Choose a reason for hiding this comment

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

redundant comment

Suggested change
"motion", # motion
"motion",

@drammock
Copy link
Member

49b5c02 (#1430) should fix the tests. Honestly I'm not sure it's the right fix, but to me the way it was before was buggy / coincidentally working. Adding motion revealed a bug IMO. But we should check with @hoechenberger or @sappelhoff, whether my fix is the right one.

@sappelhoff
Copy link
Member

Honestly I'm not sure it's the right fix, but to me the way it was before was buggy / coincidentally working.

the fix looks good to me

@JuliusWelzel JuliusWelzel changed the title Add motion to BIDSPath [MRG] Add motion to BIDSPath Sep 8, 2025
@codecov
Copy link

codecov bot commented Sep 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.43%. Comparing base (a478527) to head (c235ca2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1430   +/-   ##
=======================================
  Coverage   97.42%   97.43%           
=======================================
  Files          40       40           
  Lines        9136     9147   +11     
=======================================
+ Hits         8901     8912   +11     
  Misses        235      235           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JuliusWelzel
Copy link
Contributor Author

Hi,

thanks for the help with fixing the tests. All CI's are passing now. One question from my side:
The tracksys path entity was introduced with Motion BIDS. In 0373d18 I changed all tracking-system to tracking_system. One reason for this was that the BIDSPath.__init__ function cannot take tracking-system with a hyphen. Another option would be that I simply rename it to trackingsystem to follow the current format. Any thoughts on this?

@drammock
Copy link
Member

drammock commented Sep 8, 2025

Another option would be that I simply rename it to trackingsystem to follow the current format. Any thoughts on this?

Underscore seems ok to me.

Copy link
Member

@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.

@JuliusWelzel could you please also add a what's new entry and resolve the conflicts?

Copy link
Member

@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.

Cool, LGTM! Thanks @JuliusWelzel.

If this is doing what you need for mne-bids to be helpful for motion data, then I think this can be merged as is.

@JuliusWelzel
Copy link
Contributor Author

JuliusWelzel commented Sep 29, 2025

Thanks @sappelhoff.

The changes would now allow me to use mne-bids to handle the path to motion, but not write motion data.
Once the class is created, I would update it for each file and "manually" write my data in BIDS-like manner into the dir:

import numpy as np
from mne_bids import BIDSPath

# define motion-bids relevant information
subject_id = "01"
session = "01"
task = "walking"
tracking_system = "imu1"

# initialize BIDSPath for motion data
motion_raw_bids_path = BIDSPath(subject=subject_id, task=task, datatype='motion', tracking_system=tracking_system, root=bids_root)
print(motion_raw_bids_path)
motion_raw_bids_path.mkdir()

# generate random data for 9 markers and 10 seconds of data at 200Hz srate
raw_motion_data = np.random.rand(9, 10 * 200) # 9 channels, 10 seconds, 200 Hz

#store as tsv without headers
np.savetxt(str(motion_raw_bids_path), raw_motion_data, delimiter='\t', header='', comments='')

# update path for motion.json
motion_json_bids_path = motion_raw_bids_path.update(extension='.json')
print(motion_json_bids_path)

# update path for channels
motion_channels_bids_path = motion_raw_bids_path.update(suffix='channels', extension='.tsv')
print(motion_channels_bids_path)

As long as MNE does not want/allow motion data the current approach is already helpful. However, I am open to extend the write_raw_bids function to allow motion data, but would need a little support.

If you think this the current approach is to much of an edge case and not relevant to Brain Imaging Data, I am happy not to merge :)

@sappelhoff
Copy link
Member

Thanks for the explanation @JuliusWelzel I am happy with how you aim to use mne-bids for motion data. And will merge this, thanks!

Looking forward to future enhancements (to mne or mne-bids) for motion data compatibility. 🚀

@sappelhoff sappelhoff merged commit 2ccfdf1 into mne-tools:main Sep 29, 2025
24 checks passed
drammock added a commit to drammock/mne-bids that referenced this pull request Nov 10, 2025
drammock added a commit to drammock/mne-bids that referenced this pull request Nov 10, 2025
@drammock drammock mentioned this pull request Nov 10, 2025
7 tasks
drammock added a commit to drammock/mne-bids that referenced this pull request Nov 11, 2025
drammock added a commit to drammock/mne-bids that referenced this pull request Nov 13, 2025
larsoner pushed a commit that referenced this pull request Nov 13, 2025
* fixups from #1430

* fix wrong orig_unit sometimes written to channels.tsv

* fix doctest (bad syntax; add verbose; avoid np types)

* add curryreader to full and test deps

* importorskip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Motion-BIDS

4 participants