Skip to content

Fixes behavior of stc.save() as mentioned in issue #13158 #13165

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f06fc33
try_1 at fixing bug with stc.save #13158
shresth-keshari Mar 17, 2025
cfbd4d1
fixed stc.save() function, as requested in issue #13158
shresth-keshari Mar 18, 2025
b9f0e44
Merge branch 'gsoc_commits' of https://github.com/shresth-keshari/mne…
shresth-keshari Mar 18, 2025
199d93d
changed ftype input from None to auto.
shresth-keshari Mar 18, 2025
e938d4f
changed ftype input from None to auto.
shresth-keshari Mar 18, 2025
f96a03b
Merge branch 'mne-tools:main' into gsoc_commits
shresth-keshari Mar 21, 2025
b5513e6
Update mne/source_estimate.py
shresth-keshari Mar 21, 2025
0f7283a
Update mne/source_estimate.py
shresth-keshari Mar 21, 2025
6259404
Update mne/source_estimate.py
shresth-keshari Mar 21, 2025
7a401c4
Merge branch 'mne-tools:main' into gsoc_commits
shresth-keshari Apr 1, 2025
cb6db6a
minor fixes including spaces
shresth-keshari Apr 1, 2025
3c0adaf
pytest test_source_estimate.py passes, changes were made to test_sour…
shresth-keshari Apr 1, 2025
02467e2
changes documented post successful local tests have run.
shresth-keshari Apr 1, 2025
9bd1483
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 1, 2025
46168f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 1, 2025
9aee7e7
Merge branch 'main' into gsoc_commits
shresth-keshari Apr 1, 2025
9e687d7
removed multiple bullet points from 13165.bugfix.rst, and removed red…
shresth-keshari Apr 2, 2025
094c456
removed multiple bullet points from 13165.bugfix.rst, and removed red…
shresth-keshari Apr 2, 2025
9d4b46c
changes documented post successful local tests have run.
shresth-keshari Apr 2, 2025
316be19
Merge branch 'mne-tools:main' into gsoc_commits
shresth-keshari Apr 3, 2025
b0b979d
Merge branch 'main' into gsoc_commits
larsoner Apr 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions mne/source_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ class SourceEstimate(_BaseSurfaceSourceEstimate):
"""

@verbose
def save(self, fname, ftype="stc", *, overwrite=False, verbose=None):
def save(self, fname, ftype=None, overwrite=False, verbose=None):
"""Save the source estimates to a file.

Parameters
Expand All @@ -1894,18 +1894,26 @@ def save(self, fname, ftype="stc", *, overwrite=False, verbose=None):
spaces are obtained by adding ``"-lh.stc"`` and ``"-rh.stc"`` (or
``"-lh.w"`` and ``"-rh.w"``) to the stem provided, for the left and
the right hemisphere, respectively.
ftype : str
File format to use. Allowed values are ``"stc"`` (default),
``"w"``, and ``"h5"``. The ``"w"`` format only supports a single
time point.
ftype : str | None
File format to use. If None, the file format is inferred from the
file extension. Allowed values are ``"stc"``, ``"w"``, and ``"h5"``.
The ``"w"`` format only supports a single time point.
%(overwrite)s

.. versionadded:: 1.0
%(verbose)s
"""
fname = str(_check_fname(fname=fname, overwrite=True)) # checked below
if ftype is None:
if fname.endswith((".stc", "-lh.stc", "-rh.stc")):
ftype = "stc"
elif fname.endswith((".w", "-lh.w", "-rh.w")):
Copy link
Member

Choose a reason for hiding this comment

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

This can be simplified, as the first element in each endswith tuple already captures all cases we care about.

ftype = "w"
elif fname.endswith(".h5"):
ftype = "h5"
else:
raise ValueError("Cannot infer file type, please specify ftype.")
_check_option("ftype", ftype, ["stc", "w", "h5"])

lh_data = self.data[: len(self.lh_vertno)]
rh_data = self.data[-len(self.rh_vertno) :]

Expand All @@ -1918,6 +1926,8 @@ def save(self, fname, ftype="stc", *, overwrite=False, verbose=None):
"real numbers before saving."
)
logger.info("Writing STC to disk...")
if fname.endswith(".stc"):
fname = fname[:-4]
fname_l = str(_check_fname(fname + "-lh.stc", overwrite=overwrite))
fname_r = str(_check_fname(fname + "-rh.stc", overwrite=overwrite))
_write_stc(
Expand Down
Loading