Skip to content

MRG, ENH: Create a tutorial for how to find intracranial electrode contacts from a CT and an MR image#9484

Merged
larsoner merged 55 commits intomne-tools:mainfrom
alexrockhill:tut
Jun 24, 2021
Merged

MRG, ENH: Create a tutorial for how to find intracranial electrode contacts from a CT and an MR image#9484
larsoner merged 55 commits intomne-tools:mainfrom
alexrockhill:tut

Conversation

@alexrockhill
Copy link
Copy Markdown
Contributor

@alexrockhill alexrockhill commented Jun 16, 2021

Addresses part of #9155.

This is a tutorial for how to:

  1. Align a CT to an MR using Dipy
  2. Find the electrode contacts using a GUI (another PR for the GUI but it's the img_pipe one)
  3. Warp the electrode contacts to fsaverage using Dipy

This prepares you to start the working with SEEG and working with ECoG tutorials which require you to already have electrode positions in MNI space before starting but don't explain how you find them.

@larsoner
Copy link
Copy Markdown
Member

@alexrockhill feel free to ping me when I should look

@alexrockhill
Copy link
Copy Markdown
Contributor Author

Just a WIP so far but probably tomorrow

@alexrockhill
Copy link
Copy Markdown
Contributor Author

alexrockhill commented Jun 17, 2021

Ok @larsoner, if you have time to review once the artifact renders, this is a good first draft.

It does look like the SDR does a better job with the morph than the Talairach:

SDR (this is actually for cvs_avg35_inMNI152 not fsaverage)
Screen Shot 2021-06-17 at 10 33 21 AM

Talairach
Screen Shot 2021-06-17 at 10 37 29 AM

@alexrockhill
Copy link
Copy Markdown
Contributor Author

The references won't work until #9480 merges though....

@alexrockhill
Copy link
Copy Markdown
Contributor Author

Uh oh I think the SDR takes longer than 10 minutes... not sure how to fix that

@alexrockhill
Copy link
Copy Markdown
Contributor Author

alexrockhill commented Jun 17, 2021

I'm not sure what the latest error was but maybe rebasing will take care of it. I still think it's probably related to execution time. I'll look in the SDR tests for source space to see if there's a way to do things faster...

generating gallery for auto_tutorials/clinical... [ 25%] 10_ieeg_localize.py
  19.0 s : 456.8 MB   
ERROR:mprof:Program resulted with a non-zero exit code: -9
make: *** [Makefile:65: html_dev-pattern-memory] Error 247

@alexrockhill
Copy link
Copy Markdown
Contributor Author

Ok so still failing with the weird error. I'm going to try profiling the code but the SDR function and maybe the affine registrations too might need to be added to misc data so that they can just be loaded instead of computed.

@alexrockhill
Copy link
Copy Markdown
Contributor Author

I'm not sure what the latest error was but maybe rebasing will take care of it. I still think it's probably related to execution time. I'll look in the SDR tests for source space to see if there's a way to do things faster...

generating gallery for auto_tutorials/clinical... [ 25%] 10_ieeg_localize.py
  19.0 s : 456.8 MB   
ERROR:mprof:Program resulted with a non-zero exit code: -9
make: *** [Makefile:65: html_dev-pattern-memory] Error 247

I have no idea what this error means, if anyone had a chance to give it a look that would be appreciated.

@alexrockhill
Copy link
Copy Markdown
Contributor Author

program.prof.zip

Ok, I know it's not rendering but it does run locally and it would be great to get a review of the content @larsoner if you have a minute. Here is the cProfile output as well that can be visualized, it looks like the affine registration just takes a long time but it does run in just over ten minutes.

@alexrockhill
Copy link
Copy Markdown
Contributor Author

Hmmm so there's an issue that the affine_registration from Dipy doesn't work to align the CT and MR... I have used the nipy histogram registration but it isn't a dependency... Looking into reimplementing

@larsoner
Copy link
Copy Markdown
Member

Is it expected to work? If so, might be worth opening an issue on dipy, they might know a workaround

We could add another dependency if histogram registration is expected to work on most cases

@alexrockhill
Copy link
Copy Markdown
Contributor Author

Is it expected to work? If so, might be worth opening an issue on dipy, they might know a workaround

We could add another dependency if histogram registration is expected to work on most cases

I don't think so, I don't think Dipy has any reason to use or have tested anything using CT images.

The Nipy histogram registration is written in cython so that would be a bit harder to reimplement, but I could give it a try and see how slow it is in pure python...

@alexrockhill
Copy link
Copy Markdown
Contributor Author

So this last version has all the parts working but there is some confusion converting between nibabel and nipy image objects that is not ideal. This adds a nipy dependency but I'm not sure how else to register the CT to the MR.

I think I'm going to start on the GUI next week and we can continue to iterate on this.

@alexrockhill
Copy link
Copy Markdown
Contributor Author

Ok, I think that addressed all your comments @larsoner, I think the changes from your commit caused a few tests to fail though...

@alexrockhill
Copy link
Copy Markdown
Contributor Author

Once mne-tools/mne-misc-data#6 merges, we should be good to go.

Copy link
Copy Markdown
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.

Great progress! I think working on this example is useful for seeing what actually needs to be done to make this work, thanks for sticking with it. The align_volumes seems like the simplest solution I can think of, but if you see problems with it maybe we should have a quick chat tomorrow.

Also if you are sick of iterating on this and want to move onto GUI I can try implementing my suggested changes locally. I can also fix the tests I broke if it would help.

@alexrockhill
Copy link
Copy Markdown
Contributor Author

Also if you are sick of iterating on this and want to move onto GUI I can try implementing my suggested changes locally. I can also fix the tests I broke if it would help.

If you wouldn't mind fixing the tests you broke, I'm not exactly sure what you were doing there. You're welcome to make some changes if you'd like, I stopped working on it today.

@larsoner
Copy link
Copy Markdown
Member

I won't get to it until tomorrow morning EDT but I'll push something then after pulling your latest changes

@alexrockhill
Copy link
Copy Markdown
Contributor Author

I won't get to it until tomorrow morning EDT but I'll push something then after pulling your latest changes

Thanks for all the help! Sounds good, I think what needs to happen is that the tests need to be fixed and if you want to refactor the SDR morph you could do that but I might save it for a followup PR as it's going to affect the other SDR tests.

@alexrockhill
Copy link
Copy Markdown
Contributor Author

Ok, I'm happy to keep iterating if you have a chance to look at it tomorrow @larsoner but this looks like a viable tutorial to me

@larsoner larsoner changed the title [WIP, ENH] Create a tutorial for how to find intracranial electrode contacts from a CT and an MR image MRG, ENH: Create a tutorial for how to find intracranial electrode contacts from a CT and an MR image Jun 24, 2021
@larsoner larsoner merged commit 44f5ecb into mne-tools:main Jun 24, 2021
@larsoner
Copy link
Copy Markdown
Member

Thanks @alexrockhill !

sphinx_copybutton
https://github.com/mne-tools/mne-bids/archive/main.zip
pyxdf
nipy
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.

We probably don't need this

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.

2 participants