Skip to content
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

[MRG][ENH]: Add Ability to export STC files as GIFTI #12309

Merged
merged 30 commits into from
Dec 21, 2023

Conversation

pmolfese
Copy link
Contributor

Reference issue

Fixes #9286

What does this implement/fix?

Add functions under mne.export to handle exporting STC files as GIFTI. Should be easy to also expand from there to handle other surface file types if later desired. Given need to export both an "anatomical" and functional datasets, opted to not include in SourceEstimate / SurfaceEstimate classes and instead do what I felt was a cleaner option.

Additional information

Work in progress. Initial code stable, need to add tests and documentation. Opinions valued. Help of course is welcome!

Screenshot 2023-12-18 at 6 54 31 PM

@larsoner
Copy link
Member

It is indeed probably long overdue to add something like this.

We already have VolSourceEstimate.as_volume for example, so maybe instead of mne.export.* it should be a mne.SourceEstimate method, maybe stc.export(...) that currently only supports gifti? If we ever add another format we can add a format="gifti" kwarg for example (but don't need to for the first PR.

@pmolfese
Copy link
Contributor Author

Thanks @larsoner - I've updated the PR to move functionality to source_estimate. I went with save_as_surface as the function name to mirror save_as_volume. As you said, we can always refactor it slightly if there's ever a desire to support other formats. Still trying to reteach myself pytest and a little confused on how to generate docs for the new function. The contribution guide on mne.tools seems to be down (linked from https://mne.tools/stable/development/index.html)

@drammock
Copy link
Member

drammock commented Dec 19, 2023

The contribution guide on mne.tools seems to be down (linked from https://mne.tools/stable/development/index.html)

This one? https://mne.tools/stable/development/contributing.html It's linked in the left sidebar of the page you mentioned.

@pmolfese
Copy link
Contributor Author

Thanks @drammock - not sure why I was laser focused on the in-line link in the text! Will check it out.

@drammock
Copy link
Member

ah, oops, now I see the inline one is 404; will fix that. Thanks for letting us know.

@pmolfese pmolfese marked this pull request as ready for review December 19, 2023 19:56
@pmolfese
Copy link
Contributor Author

Getting stuck on how to generate documentation explicitly. I copied as closely as I could to save_as_volume but sphinx doesn't seem to be generating the necessary files to show the new function method. Any tips? Happy to do reading, just unsure of where to start.

@larsoner
Copy link
Member

Can you go to https://app.circleci.com/pipelines/github/mne-tools/mne-python/22368/workflows/bd8128a6-9584-4d03-b606-810945e4c228/jobs/62531 and register/log in? Then CircleCI will build the doc and you can see how it looks

doc/changes/devel.rst Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
mne/source_estimate.py Show resolved Hide resolved
mne/tests/test_source_estimate.py Show resolved Hide resolved
pmolfese and others added 3 commits December 20, 2023 13:11
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
version add

Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
@pmolfese
Copy link
Contributor Author

@larsoner Thanks for all the input on the PR!

Getting a "block-unregistered-user" from that link after registering. Just a sanity check, do I need to be added to an authorized user list?

@larsoner
Copy link
Member

That's odd, seems like it should work. I'll push a commit to get it to run and fix the merge conflict

* upstream/main:
  MAINT: Use towncrier for release notes (mne-tools#12299)
  MAINT: More [ci skip]
  MAINT: Add bot entry [ci skip]
  BUG: handle temporal discontinuities in Neuralynx `.ncs` files (mne-tools#12279)
  MAINT: Work around bad SciPy nightly wheels (mne-tools#12317)
@larsoner
Copy link
Member

FYI I'd recommend running pre-commit install --install-hooks in your mne-python/ directory -- it should install some stuff that will auto-format when you git commit files. If you don't have pre-commit installed you can pip install pre-commit or similar first

@pmolfese
Copy link
Contributor Author

Thanks @larsoner! I'll do that. I may make documenting all of these things part of my next PR to flush out the contribution docs so I don't forget!

@larsoner
Copy link
Member

@pmolfese pmolfese changed the title [WIP] Add Ability to export STC files as GIFTI [MRG][ENH]: Add Ability to export STC files as GIFTI Dec 20, 2023
@pmolfese
Copy link
Contributor Author

Think we're ready. I could futz with it more to clean up some things but this is a win pre-holidays!

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

@drammock feel free to review/merge if you're happy!

Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

nice and clean. +1 for merge (modulo my comments/questions about dtype, which I may be mistaken about).

There is a pip-pre error here (looks like NumPy changed an error message that broke our warnings filter) that we should address in a separate PR; I'll look tomorrow if @larsoner doesn't beat me to it.

doc/changes/devel/12309.newfeature.rst Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
Comment on lines 1624 to 1626
data=s["rr"] * scale_rr,
intent="NIFTI_INTENT_POINTSET",
datatype="NIFTI_TYPE_FLOAT32",
Copy link
Member

Choose a reason for hiding this comment

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

do we need to actually cast the data to float32 here? I read in nibabel docs that they don't actually enforce that the datatype matches the descriptor, but since we can make it match, seems like we should? (I'm assuming internally for us it's float64 right?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll have to test it. I'm checking against the non-Python GIFTI world since that's my use case. We ran into issues where nilearn was writing float64 NIFTI files and that didn't cooperate well with the AFNI/FSL/SPM/Freesurfer programs. Perhaps we add it as an option to match?

Copy link
Member

Choose a reason for hiding this comment

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

For now let's just cast to and use float32. We can add float64 later if we really need it but I'd assume YAGNI until someone hits a use case where float32 isn't enough

Comment on lines 1633 to 1635
data=s["tris"],
intent="NIFTI_INTENT_TRIANGLE",
datatype="NIFTI_TYPE_INT32",
Copy link
Member

Choose a reason for hiding this comment

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

similar comment as above about casting (here to int32, not float32)

mne/source_estimate.py Outdated Show resolved Hide resolved
mne/tests/test_source_estimate.py Outdated Show resolved Hide resolved
pmolfese and others added 4 commits December 20, 2023 17:29
caps

Co-authored-by: Daniel McCloy <dan@mccloy.info>
meth instead of class in diff doc

Co-authored-by: Daniel McCloy <dan@mccloy.info>
caps in GIFTI

Co-authored-by: Daniel McCloy <dan@mccloy.info>
Repetitive text

Co-authored-by: Daniel McCloy <dan@mccloy.info>
Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

Will commit these once #12320 lands so CIs can come back green, then I'll mark for merge -- thanks in advance @pmolfese !

mne/source_estimate.py Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
mne/source_estimate.py Outdated Show resolved Hide resolved
@larsoner larsoner enabled auto-merge (squash) December 21, 2023 15:37
@larsoner larsoner merged commit a03a40d into mne-tools:main Dec 21, 2023
28 checks passed
@pmolfese pmolfese deleted the exportstc_gifti branch December 29, 2023 13:31
snwnde pushed a commit to snwnde/mne-python that referenced this pull request Mar 20, 2024
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Daniel McCloy <dan@mccloy.info>
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.

ENH: Add GIfTI output for STC
3 participants