Skip to content

FIX: Infer file format and avoid duplicate extensions in stc.save (#13158) - #14491

Merged
larsoner merged 3 commits into
mne-tools:mainfrom
ishaaaan17:fix/stc-save-naming-and-ftype
Nov 4, 2026
Merged

larsoner merged 3 commits into
mne-tools:mainfrom
ishaaaan17:fix/stc-save-naming-and-ftype

Conversation

@ishaaaan17

Copy link
Copy Markdown
Contributor

reference issue (if any)

Closes #13158
Supersedes #13165

what does this implement/fix?

  • supports ftype='auto' as the default in SourceEstimate.save() and VolSourceEstimate.save() to infer file format from file extension.
  • avoids duplicate extension/hemisphere tags when fname already ends with tags like -lh.stc or .stc (e.g. preventing test-lh.stc-lh.stc).
  • updates read_source_estimate() to gracefully resolve both clean filenames and legacy filenames.
  • augments existing tests in test_source_estimate.py to cover auto inference and deduplicated extensions.

Co-authored-by: Shresth Keshari [email protected]

additional information

ai assistance disclosure: i used google antigravity to help locate the abandoned pr history, identify the edge cases in read_source_estimate, and write the test cases in test_source_estimate.py.

@ishaaaan17
ishaaaan17 force-pushed the fix/stc-save-naming-and-ftype branch 2 times, most recently from cc8cc30 to b835096 Compare November 3, 2026 18:38

@CarinaFo CarinaFo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi Ishaaaan17,

thanks for taking on this bug.

I think it would make sense to update the other filetypes as well if they suffer from the same double extension issue (which I think they do, particularly "w").

Comment thread mne/source_estimate.py
vertices=self.rh_vertno,
data=rh_data,
)
elif ftype == "w":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should also update the code for saving with "w"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch! updated save() and read_source_estimate() to handle both "stc" and "w" files with the same logic, and added test coverage for "w" in test_io_w.

Comment thread mne/source_estimate.py
fname_r = str(_check_fname(fname + "-rh.w", overwrite=overwrite))
_write_w(fname_l, vertices=self.lh_vertno, data=lh_data[:, 0])
_write_w(fname_r, vertices=self.rh_vertno, data=rh_data[:, 0])
elif ftype == "h5":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

haven't looked into h5 file types, but might be the same issue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

looked into h5 files, _BaseSourceEstimate.save() already handles this safely via fname.suffix != ".h5" (it only appends -stc.h5 if .h5 is not already present), so saving test.h5 or test-stc.h5 does not suffer from double extensions.

@ishaaaan17
ishaaaan17 force-pushed the fix/stc-save-naming-and-ftype branch from b835096 to f7545b8 Compare November 4, 2026 02:52
…e-tools#13158)

- Support ftype='auto' as default to infer format from file extension.
- Avoid duplicate extensions when fname already ends with hemisphere or format tags.
- Support reading both new and legacy formatted files in read_source_estimate.

Co-authored-by: Shresth Keshari <[email protected]>
@ishaaaan17
ishaaaan17 force-pushed the fix/stc-save-naming-and-ftype branch from f7545b8 to 5507306 Compare November 4, 2026 02:55

@CarinaFo CarinaFo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Thanks again.

@larsoner

larsoner commented Nov 4, 2026

Copy link
Copy Markdown
Member

Just pushed a tiny commit to extend the behavior properly to volume source estimates, marking for merge-when-green, thanks in advance @ishaaaan17 !

@larsoner
larsoner enabled auto-merge (squash) November 4, 2026 19:54
@larsoner
larsoner merged commit 0e67c54 into mne-tools:main Nov 4, 2026
25 checks passed
@ishaaaan17
ishaaaan17 deleted the fix/stc-save-naming-and-ftype branch November 5, 2026 19:40
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.

BUG: Bugs with stc.save behavior

3 participants