-
Notifications
You must be signed in to change notification settings - Fork 20
Add EMG-BIDS import/export support with multiple coordinate systems #245
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
Merged
Conversation
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
Created bids_check_regular_sampling.m to detect irregular timestamps and calculate average frequency. Modified bids_export.m to automatically resample data when exporting to EDF/BDF formats, which require regular sampling intervals. Tested: Function creation complete, integration tested with export logic.
Created bids_check_regular_sampling.m to detect irregular timestamps and calculate average frequency. Modified bids_export.m to automatically resample data when exporting to EDF/BDF formats, which require regular sampling intervals. Tested: Function creation complete, integration tested with export logic.
Created bids_writeemgtinfofile.m for EMG-specific JSON metadata fields including EMGReference, EMGPlacementScheme, EMGGround, and electrode specifications. Modified bids_export.m to recognize 'emg' modality, default to BDF export format, and call EMG info writer. Tested: EMG modality added to options, BDF default set, info writer created.
Modified bids_writeelectrodefile.m to handle EMG-specific coordinate system fields (EMGCoordinateSystem, EMGCoordinateUnits, EMGCoordinateSystemDescription). EMG defaults to 'Other' coordinate system as required by BIDS specification. Tested: EMG coordsystem.json generation with proper field names.
Modified pop_importbids.m to detect EMG data files (_emg.) and set modality to 'emg'. This enables proper import of EMG-BIDS datasets using existing infrastructure (pop_biosig for EDF/BDF reading). Tested: EMG modality detection added to import workflow.
Moved EEG.etc.datatype assignment before channel/electrode file writing so it's available for modality detection. Changed bids_writechanfile.m and bids_writeelectrodefile.m to check EEG.etc.datatype instead of parsing fileOut string, making detection more robust and reliable. Tested: Modality now properly detected from EEG structure field.
- Add emg/ folder detection in cascading folder checks - Add *_emg.* data file search pattern - Add *_emg.json metadata file search (modality-agnostic) - Fix modality detection to recognize 'emg' extension - Update error message to include EMG Tested: EMG datasets now successfully detected and imported
- Add 'emg' to valid modality list in finputcheck Tested: EMG data files import without modality errors
- Extract recording entity from filename and store in EEG.recording - Preserve recording label in dataset .set filenames - Add console notification when multiple recordings detected - Scan for recordings in bids_getinfofromfolder - Add recording filter to import GUI with listbox selection - Store recording entity in STUDY commands - Add filterFilesRecording function for selective import Tested with emg_ConcurrentIndependentUnits (2 recordings). All tests passed: entity extraction, filename preservation, console output, GUI filtering, STUDY integration.
…ities - Import all coordsystem.json files (single or with space entity) - Parse space label from filename using regex - Store multiple coordsystems in EEG.chaninfo.BIDS.coordsystems cell array - Import coordinate_system field from electrodes.tsv (5th column) - Add helper function bids_get_all_coordsystem_files - Backward compatible: single coordsystem without space stored directly - Tested with emg_MultiBodyParts (2 coordsystems: hand, lowerLeg)
- Set EEG.etc.datatype during import to preserve modality - Check EEG.etc.datatype when loading .set files in eeg_import - Ensures export uses correct modality folder (emg/ not eeg/) - Tested: files now export to sub-001/emg/ with correct metadata
- channels.tsv: Add 10 RECOMMENDED columns for EMG (13 total) signal_electrode, reference, group, target_muscle, placement_scheme, placement_description, interelectrode_distance, low_cutoff, high_cutoff, sampling_frequency - electrodes.tsv: Add 5 RECOMMENDED columns for EMG (9 total) coordinate_system, type, material, impedance, group - Use n/a for missing RECOMMENDED fields per BIDS spec - Only write REQUIRED columns when no chanlocs present - Add helper functions for safe field extraction
…ities - Export multiple coordsystem.json files with space entity in filename - Write <base>_space-<label>_coordsystem.json for each coordinate system - Validate parent references for nested coordinate systems - Prevent export if parent coordinate system doesn't exist - Backward compatible: single coordsystem without space entity - Tested roundtrip: emg_MultiBodyParts (2 coordsystems: hand, lowerLeg)
- Scan channels/electrodes to detect which RECOMMENDED columns have data - Only include columns where at least one row has non-empty, non-n/a value - Display warning about missing RECOMMENDED columns - Prevents writing rows of n/a placeholders for unavailable fields - REQUIRED columns (name, type, units, x, y, z) always included
- Only include z column if at least one electrode has non-zero z value - REQUIRED columns: name, x, y (z is optional per BIDS spec) - Dynamically adjust column indexing based on z presence - Tested with all 7 EMG examples
- Support both subject-level and root-level coordsystem filename patterns - Subject: sub-01_space-hand_coordsystem.json - Root (inheritance): space-leftForearm_coordsystem.json - Try prefix underscore first, then start-of-string pattern - Tested with emg_TwoWristbands (root-level coordsystems)
This PR will be pending the merge of bids-standard/bids-specification#1998 and bids-standard/bids-examples#480. |
- Set default export format to EDF for EMG modality - Remove events from EEG structure before writing EDF - Events are properly saved in events.tsv only - Fixes BIDS compliance for EMG data export
- Modified bids_writeelectrodefile to accept rootdir parameter - Space-entity coordsystem files now written at dataset root - EMG electrodes.tsv uses signal_electrode field for electrode names - Enables proper export of datasets with multiple coordinate systems - Tested with emg2qwerty dataset (leftForearm/rightForearm spaces)
- Removed automatic resampling that was failing in pop_resample - EDF format stores only sampling rate, not individual timestamps - Event timing already correctly mapped using irregular timestamps - For emg2qwerty: max deviation 0.05ms (well within tolerance)
- Detects irregular sampling (>1% deviation) before EDF/BDF export - Throws clear error with resampling instructions for users - EDF/BDF require regular sampling; cannot preserve irregular timestamps - Users must resample their data before BIDS export
… for percent units
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements complete EMG-BIDS import and export functionality with support for multiple coordinate systems, nested coordinate systems, and multi-device recordings.
Closes #229
Changes
Import
Export
Data Structure
Testing
Tested with all 7 EMG examples from bids-examples repository:
All examples pass full roundtrip testing (import -> export -> validate structure).
Files Modified
Backward Compatibility
Notes