Skip to content

MRG: Add OPM example#5525

Merged
agramfort merged 5 commits into
mne-tools:masterfrom
larsoner:opm
Sep 21, 2018
Merged

MRG: Add OPM example#5525
agramfort merged 5 commits into
mne-tools:masterfrom
larsoner:opm

Conversation

@larsoner

@larsoner larsoner commented Sep 14, 2018

Copy link
Copy Markdown
Member

Todo:

  • make example work locally
  • add context manager for using custom coil def
  • add tests and docs for context manager
  • complete formatting of dataset
  • upload dataset
  • add as MNE dataset
  • add example file to PR
  • update whats_new.rst

@larsoner larsoner added this to the 0.17 milestone Sep 14, 2018
@larsoner larsoner changed the title WIP: Add OPM example MRG: Add OPM example Sep 19, 2018
@codecov

codecov Bot commented Sep 19, 2018

Copy link
Copy Markdown

Codecov Report

Merging #5525 into master will increase coverage by <.01%.
The diff coverage is 94.02%.

@@            Coverage Diff             @@
##           master    #5525      +/-   ##
==========================================
+ Coverage    88.3%   88.31%   +<.01%     
==========================================
  Files         361      363       +2     
  Lines       67406    67456      +50     
  Branches    11421    11427       +6     
==========================================
+ Hits        59521    59571      +50     
- Misses       5043     5044       +1     
+ Partials     2842     2841       -1

@larsoner

Copy link
Copy Markdown
Member Author

Ready for review/merge from my end.

@ rzetter @ jiivana @LauriParkkonen can you take a look at the rendered example and make sure I didn't break anything:

https://9416-1301584-gh.circle-artifacts.com/0/html/auto_examples/datasets/plot_opm_data.html

Also @rzetter please check whats_new.rst and datasets_index.rst to make sure you're happy with the URL I chose and credits, etc. Let me know if there are other names (w/URLs) I should add.

@LauriParkkonen

LauriParkkonen commented Sep 19, 2018 via email

Copy link
Copy Markdown
Member

@rzetter

rzetter commented Sep 19, 2018

Copy link
Copy Markdown

Hi, this looks great! I have some minor comments:

-The low-pass can and should be upped to e.g. 90 Hz, the 40 Hz limit is something that might have been left from my earlier scripts by mistake. A slight high-pass could also be used (0.03 Hz or 0.1 Hz), but I guess it isn't needed. However, a 50 Hz notch filter will be useful, since we typically do have some (electrical) 50 Hz noise in the OPMs.

-Agreed with Lauri regarding the color map limits in the MNE visualization. With the current limits, the entire physiologically interesting region is saturated with white. Also, the color bar in the current figure seems to have been corrupted somehow.

-Some information about the experiment paradigm could be added to the start of the script plot_opm_data.py, e.g.:
"Electrical median nerve stimulation was delivered to the left wrist of the subject. Somatosensory evoked fields were measured using nine QuSpin SERF OPMs placed over the right-hand side somatomotor area. Here we demonstrate how to localize these custom OPM data in MNE."

-I also sent Neuromag SQUID data for the same experiment, do you want to include that in the example for comparison purposes?

-Great that you've added a mechanism to use custom coil definitions on the fly, that will definitely be useful!

-Also great to see the tweaks to the 3D visualization, we already had to do some small hacks to our local MNE installations for proper visualization in plot_alignment().

in examples/datasets/plot_opm_data.py, lines 96-98:
"# Due to the small number of sensors, there will be some leakage of activity

to areas with low/no sensitivity occurs. Constraining the source space to

areas we are sensitive to might be a good idea."

Clumsy sentence (by me), remove 'occur'.

in datasets_index.rst, lines 231-232:
"Thus the MEG<->Head and Head<->MRI coordinate transforms are both taken to
be identity matrices (i.e., everything is in MRI coordinates)..."
In the FIF files I sent, the MEG<->Head transform is not an identity matrix! However, it is included in the raw data FIF file as raw.info['dev_head_t']. Did you apply the transform directly to the channel locations?

With these small tweaks, everything should be good for review/merge. I'll leave it up to you if you want to include SQUID data as a comparison or not.

@larsoner

Copy link
Copy Markdown
Member Author

@rzetter to make life easier in the future if you click over to the "Files changed" tab, you can leave comments directly in line with the code.

I'll try to address comments in the next couple of days

Comment thread mne/viz/_3d.py
"""Get the sensor shape vertices."""
rrs = np.empty([0, 2])
tris = np.empty([0, 3], int)
from scipy.spatial import ConvexHull

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what is the convention in placing imports inside the functions?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Some scipy imports are nested to improve import mne speed. There is a test for violations in mne/tests/test_import_nesting.py::test_module_nesting and the rules are listed there

Comment thread mne/viz/tests/test_3d.py Outdated
def test_plot_alignment(tmpdir):
"""Test plotting of -trans.fif files and MEG sensor layouts."""
# generate fiducials file for testing
tempdir = _TempDir()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do not overwrite tempdir

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed it to be tempdir = str(tmpdir). This works around a pytest bug where tmpdir on older pytest is not seen properly as a string by some functions, so casting it explicitly to a string makes some things work better

Comment thread mne/viz/tests/test_3d.py Outdated
info_cube['chs'][0]['coil_type'] = 9999
with pytest.raises(RuntimeError, match='coil definition not found'):
plot_alignment(info_cube, meg='sensors', surfaces=())
coil_def_fname = op.join(str(tmpdir), 'temp')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you are using pytest tmpdir I would do this:
coil_def_fname = tmpdir.join('temp')

@larsoner

Copy link
Copy Markdown
Member Author

@agramfort agramfort left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

besides this nitpick LGTM !

Comment thread examples/datasets/plot_opm_data.py Outdated
# -----------------------------
# First we filter and epoch the data:

raw = mne.io.Raw(raw_fname, preload=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please use read_raw_fif

@agramfort

Copy link
Copy Markdown
Member

beautiful ! thanks @larsoner @LauriParkkonen and @rzetter for making this happen.

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.

5 participants