Write MATLAB field classes EEGLAB expects on save - #320
Open
arnodelorme wants to merge 1 commit into
Open
Conversation
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
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
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.
🤖 Write the MATLAB classes EEGLAB expects when saving a
.setfile.Problem
Loading an EEGPrep-written
.setin MATLAB (class_compareof every struct field against the original EEGLAB file, R2025b) showed:epoch(k).eventasint64, andepoch(k).eventlatency/eventtype/eventposition/eventureventas plaindouble/charmatrices where EEGLAB builds cell arrays.event.position,event.urevent,urevent.position,urchanlocs.thetaetc.,reject.thresh*,icachansindasint64;reject.gcomprejectasuint8. MATLAB integer arithmetic rounds (int64(3) * 1000 / 128is23), so any EEGLAB code doing math on these fields silently misbehaves.roias a1x1 structinstead of[],splinefile/icasplinefileas[]instead of'',epochdescription/eventdescriptionas[]instead of{}.Fix (
pop_saveset.py)_matlab_double: recursive cast of Python/NumPy integers to double across the exported struct (dicts, lists, object arrays, and the object-typed rows built byflatten_dict). Booleans stay boolean sosavematwrites MATLABlogicalfor masks such asetc.clean_sample_mask._epoch_fields_to_matlab: follows theeeg_checkset.mrule.epoch.eventis a double row vector; eachevent<field>is a cell array unless no epoch holds more than one event (maxlen <= 1), in which case it is the bare value.chanlocs.urchanwritten as double instead of int32.roi->[], spline file names ->'', empty description fields ->{}.In-memory EEG dicts are unchanged; the caller's data is deep-copied before conversion as before.
Verification
tests/test_pop_saveset.py: rawscipy.io.loadmatof the saved epoched sample checks double/cell classes for epoch, event, chanlocs, urchanlocs, reject, and icachansind, plus an in-memory round trip; a second test reduces the sample to one event per epoch and checks the scalar (non-cell) form.eeglab_data_epochs_ica.setandeeglab_data.set;epoch(k).eventmatches the original for all 80 epochs,eventurevent == event(epoch.event).urevent, data bit-identical,eeg_checkset(EEG, 'eventconsistency')clean.datasingle vs double (EEGLAB also writes single),chaninfo.filecontentcell vs char matrix,eventdescriptionelement class, nestedreject.disprej[]vs{}.Follows #314.