You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently if you do stc.save("test.h5") and it's a surface source estimate, it will save test.h5-lh.stc and test.h5-rh.stc files because the default is ftype="stc", and these must be saved in two separate files. If you instead stc.save("test-lh.stc"), it will end up writing test-lh.stc-lh.stc and test-lh.stc-rh.stc files. This is documented behavior but I think we could improve it by:
Changing the ftype="stc" default to be ftype="auto", which would mean: infer from the extension if possible, otherwise assume "stc"
Change the behavior for ftype="stc" to only add the -lh.stc to the filename if it's not already there.
This would have led to the much more intuitive behaviors that doing stc.save("test.h5") would have saved a single test.h5 file, and doing stc.save("test-lh.stc") would have saved to the two files test-lh.stc and test-rh.stc. It makes for much nicer saving and checking at the user end because you can have a single path like test-lh.stc, check for its existence, and if missing then save -- all without needing to compensate for magic stuff in the paths you pass around.
This will create a small backward compat break for people who were relying on the double-naming -lh.stc-lh.stc at the end of a filename, but I think hopefully those cases are rare enough to be worth the tradeoff of what I think is much clearer, intuitive behavior.
Currently if you do stc.save("test.h5") and it's a surface source estimate, it will save test.h5-lh.stc and test.h5-rh.stc files [...]
ouch, that is not good. +1 to add ftype="auto" that infers from extension and falls back to stc.
Change the behavior for ftype="stc" to only add the -lh.stc to the filename if it's not already there.
To me it feels slightly weird to specify fname="foo-lh.stc" and have it write two files (lh and rh) but I think what you propose is still better than the status quo EDIT: and changing it to only write one file would be a big backcompat break, so +1 on that part too.
Hey @larsoner , I've fixed this by making changes in the save function in source_estimate.py, and tested this as well
I'm opening a pull request, please let me know if there are some special tests required for successfully merging.
Activity
drammock commentedon Mar 13, 2025
ouch, that is not good. +1 to add
ftype="auto"that infers from extension and falls back to stc.To me it feels slightly weird to specify
fname="foo-lh.stc"and have it write two files (lh and rh) but I think what you propose is still better than the status quo EDIT: and changing it to only write one file would be a big backcompat break, so +1 on that part too.shresth-keshari commentedon Mar 18, 2025
Hey @larsoner , I've fixed this by making changes in the save function in source_estimate.py, and tested this as well
I'm opening a pull request, please let me know if there are some special tests required for successfully merging.
try_1 at fixing bug with stc.save mne-tools#13158
fixed stc.save() function, as requested in issue mne-tools#13158
FIX: Infer file format and avoid duplicate extensions in stc.save (mn…
FIX: Infer file format and avoid duplicate extensions in stc.save (mn…
FIX: Infer file format and avoid duplicate extensions in stc.save (mn…
FIX: Infer file format and avoid duplicate extensions in stc.save (mn…
FIX: Infer file format and avoid duplicate extensions in stc.save (#1…