-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
ENH: Add support for Harmonic Field correction #11536
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
Conversation
|
Could you run HFC (of different orders, e.g., maybe just 1, 2, and 3) using your MATLAB code on the |
Interesting that |
For this sort of thing I often boil it down to a single use case to test (sounds like you're already there!) and then
You can do the same thing by manually inspecting variables but that's not always easier... |
|
Below are the results for the three orders when for varying amount of field correction computation done in MNE. Top table is max absolute error, bottom is max relative error. The numbers correspoding to Basis & Projector are smaller than the values posted last week due to a way I save out the data involving fewer casting steps. MAX ABS DIFFERENCE
MAX REL DIFFERENCE
Currently pointing to an unexpected divergence between |
|
I'm going to see what happens if we tell MNE to assume these are point magnetometers. Will report back. |
|
Wait the max relative difference is now 1e-9? That seems fine to me! I mean ideally for double float we'd end up at something closer to 1e-12 but 1e-9 should be good enough (especially since we routinely save to disk in single precision which will lead to ~1e-6 relative errors anyway) |
This could definitely be it, so feel free. But as above I think 1e-9 relative error is already enough. We routinely check for equivalence with MNE-C inverses for example at around 1e-7 relative precision or so |
For |
Ahh okay great that you isolated it! BTW there has always been a slight mismatch when regularizing the maxwell filtering (SSS) basis set between what MNE chooses and what MaxFilter by MEGIN chooses. I wonder if we have some slight lingering scale factor or sign bug that changes things slightly... let me know what you find. |
|
(Also in maxwell_filter we column normalize the bases so scale factor differences might not matter there, whereas they could for this function) |
|
@georgeoneill awesome! A bit scary that the coil def matters this much. But in theory at least MNE has a better definition I think (?), so maybe we're good here. If you want, in tests you could set the coil type manually to be a point magnetometer and test against some hard-coded MATLAB values that you either write in ASCII (ouch) or add to MNE-testing-data. Then you can have a nice satisfying |
|
I'll have a think about how we proceed with this. I'm not entirely sure how well definied the accurate coil definitions for QuSpin sensors actually are. There's the further complication for the triaxial sensors that there is a second laser used to generate the third axis so the 'accurate' coil definition may not entirely reflect the volume we should be integrating over. I'll probably add a custom point magnetometer function to go with the accurate coil definition found in |
+ Add the ability to choose a point magnetometer definition instead of accurate definition. + Add load/save functionality + Add EOGRegression-like behaviour
|
Still have the tests to make but wanted to at least get a near-final HFC script into the cloud! |
Big update. + Changes API call to FieldCorrector to match EOGRegression. + Change coill accuracy calls. + Update tutorial to include HFC + Create test_hfc.
larsoner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, looks very close now! Feel free to implement my (hopefully) final suggestions or, if you're sick of iterating, I can quickly push 😄
| # The below channels in the test data do not have positions, set to bad | ||
| bads = ['G2-DS-Y', 'G2-DS-Z', 'G2-DT-Y', 'G2-DT-Z', 'G2-MW-Y', 'G2-MW-Z'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! This might be what you actually end up wanting to do in practice with your data, but for now it allows us to decide the right course of action. If it is something you'll do a lot, we can do something like mne.preprocessing.mark_invalid_position_bad(inst) that looks through all data channels (which would include MEG) and looks at ch['loc'] and marks ones as bad that don't have valid positions 👍
|
Hi @larsoner I think I agree with/understand most of the motivation. Happy for you to push those changes as I think you'll be able to get them to stick with a bit more precision than I can. |
|
@georgeoneill sorry for the slow response here, I plan to tackle this tomorrow |
|
No worries, no rush? Unless we need to get this in for the 1.4 deadline and I can have a go tonight? |
|
It would be nice to have for 1.4 but we're going to push that release date/deadline at least a week I think so. I'll just adjust it on GitHub now -- we have a lot of PRs/issues marked that we need to sort through. |
|
Okay, if you need me to step back in to make the revisions, let me know. |
* upstream/main: BUG: Fix bug with paths (mne-tools#11639) MAINT: Report download time and size (mne-tools#11635) MRG: Allow retrieval of channel names via make_1020_channel_selections() (mne-tools#11632) Fix index name in to_data_frame()'s docstring (mne-tools#11457) MAINT: Use VTK prerelease wheels in pre jobs (mne-tools#11629) ENH: Allow gradient compensated data in maxwell_filter (mne-tools#10554) make test compatible with future pandas (mne-tools#11625)
|
Okay @georgeoneill I pushed some simplifying commits. Can you take a look at the diff now and see if you're happy with my changes? Hopefully you can see most (all?) places I changed simplified some stuff |
|
Hi @larsoner, this looks excellent. I've just renamed one of the test functions. I think its ready to go! |
|
Okay marked for auto-merge when green, thanks for working through this one @georgeoneill ! |
|
Thank you for the assistance on this one. |
* upstream/main: (152 commits) FIX: missing channels/fiducials can be np.nan (mne-tools#11634) use py3.10 in precommit config (mne-tools#11648) MAINT: Unify GH Actions pytest (mne-tools#11644) MRG: Rename "Discourse" link in top navigation to "Forum" [ci skip] (mne-tools#11649) ENH: Add support for Harmonic Field correction (mne-tools#11536) Add pre-commit (mne-tools#11541) BUG: Fix bug with paths (mne-tools#11639) MAINT: Report download time and size (mne-tools#11635) MRG: Allow retrieval of channel names via make_1020_channel_selections() (mne-tools#11632) Fix index name in to_data_frame()'s docstring (mne-tools#11457) MAINT: Use VTK prerelease wheels in pre jobs (mne-tools#11629) ENH: Allow gradient compensated data in maxwell_filter (mne-tools#10554) make test compatible with future pandas (mne-tools#11625) Display SVG figures correctly in Report (mne-tools#11623) API: Port ieeg gui over to mne-gui-addons and add tfr gui example (mne-tools#11616) MAINT: Add token [ci skip] (mne-tools#11622) API: One cycle of backward compat (mne-tools#11621) MAINT: Use git rather than zipball (mne-tools#11620) ENH: Speed up code a bit (mne-tools#11614) [BUG, MRG] Don't modify info in place for transform points (mne-tools#11612) ...
* upstream/main: (117 commits) FIX: missing channels/fiducials can be np.nan (mne-tools#11634) use py3.10 in precommit config (mne-tools#11648) MAINT: Unify GH Actions pytest (mne-tools#11644) MRG: Rename "Discourse" link in top navigation to "Forum" [ci skip] (mne-tools#11649) ENH: Add support for Harmonic Field correction (mne-tools#11536) Add pre-commit (mne-tools#11541) BUG: Fix bug with paths (mne-tools#11639) MAINT: Report download time and size (mne-tools#11635) MRG: Allow retrieval of channel names via make_1020_channel_selections() (mne-tools#11632) Fix index name in to_data_frame()'s docstring (mne-tools#11457) MAINT: Use VTK prerelease wheels in pre jobs (mne-tools#11629) ENH: Allow gradient compensated data in maxwell_filter (mne-tools#10554) make test compatible with future pandas (mne-tools#11625) Display SVG figures correctly in Report (mne-tools#11623) API: Port ieeg gui over to mne-gui-addons and add tfr gui example (mne-tools#11616) MAINT: Add token [ci skip] (mne-tools#11622) API: One cycle of backward compat (mne-tools#11621) MAINT: Use git rather than zipball (mne-tools#11620) ENH: Speed up code a bit (mne-tools#11614) [BUG, MRG] Don't modify info in place for transform points (mne-tools#11612) ...



Fixes #10780.
What does this implement/fix?
- Creates anFieldCorrector()class which can be extend to correct forward models (important for deeper sources).Projector()for each column of the basis set.To do
Sorry this has taken this long to get around to this, I've been spinning a lot of plates recently, but this initial PR should keep this in the forefront of my mind for a while!