mne-python icon indicating copy to clipboard operation
mne-python copied to clipboard

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

Open shresth-keshari opened this issue 9 months ago • 5 comments

Fixes #13158 .

Doing stc.save("test.h5") saves a single test.h5 file, and doing stc.save("test.stc") saves to the two files test-lh.stc and test-rh.stc.

Please let me know if any more changes required in the current iteration.

shresth-keshari avatar Mar 18 '25 13:03 shresth-keshari

@drammock I have changed ftype from None to auto coz it was fairly easy. I also put it to test by saving a sample of both .stc as well as .h5 filetypes. You can see them in the screenshot, that they're being saved in the directory, named as it was suggested by @larsoner in the issue. (will be deleting these files before commit)

Screenshot from 2025-03-18 22-39-54

But, while running tests, it shows the following error:

image

which says: FAILED test_source_estimate.py::test_io_stc - OSError: SourceEstimate File(s) not found for: PosixPath('/tmp/pytest-of-shresth/pytest-1/test_io_stc0/tmp.stc')

I'm not aware about how to fix this error. Please help.

shresth-keshari avatar Mar 18 '25 17:03 shresth-keshari

Hey, @drammock, I implemented your suggestions, and ran pytest with --pdb flag. The issue seems to be coming from "read_source_estimate" in source_estimate.py, which looks like this in the terminal:

test_source_estimate.py:484: in test_io_stc
    stc2 = read_source_estimate(tmp_path / "tmp.stc")

..\source_estimate.py:330: in read_source_estimate
    raise OSError(f"SourceEstimate File(s) not found for: {fname_arg!r}")

E   OSError: SourceEstimate File(s) not found for: WindowsPath('C:/Users/kesha/AppData/Local/Temp/pytest-of-kesha/pytest-3/test_io_stc0/tmp.stc')

Now that I look at test_source_estimate.py, in the function definition of test_io_stc, the stc file is saved first, using stc.save() function. Later, the same file is being read using read _source_estimate. Since we changed the naming of the files being saved, I believe that's what causes the issue. Will try fixing that and will get back to you with a solution soon.

have attached screenshots as well, please have a look:

image image

shresth-keshari avatar Mar 22 '25 11:03 shresth-keshari

I was able to successfully run " pytest test_source_estimate.py" with no fails, locally. I feel the issue has been solved and desired "intuitive naming" of stc files while saving them has been achieved. Please review the pull request once.

shresth-keshari avatar Apr 01 '25 21:04 shresth-keshari

Hello, @drammock and @larsoner I believe that most of the changes have passed checks, but after numerous pytests, I can't pinpoint where does the issue lie that is stopping the remaining checks from passing.

Please guide me ahead..

shresth-keshari avatar Apr 19 '25 10:04 shresth-keshari

I merged main into your branch to see if it fixes the CIs

larsoner avatar Apr 23 '25 15:04 larsoner