Repository navigation
MRG: Add whitening to plots - #4799
Conversation
|
Certainly not the prettiest example I've ever made: |
Codecov Report
@@ Coverage Diff @@
## master #4799 +/- ##
==========================================
+ Coverage 83.66% 87.68% +4.02%
==========================================
Files 348 348
Lines 62410 62321 -89
Branches 10736 10729 -7
==========================================
+ Hits 52215 54647 +2432
+ Misses 7443 4927 -2516
+ Partials 2752 2747 -5 |
|
This is now ready for review/merge from my end |
|
if you pass a noise cov that does not contain a certain channel you should remove it as presently when I click on a bad channel I get errors such as: |
130e55a to
04a2d02
Compare
|
@agramfort fixed, now if you un-mark a bad it disappears from the plot, feel free to try it. I also fixed the overlapping name issue in the example, and a small bug with switching to/from Here are the updated examples: |
|
@larsoner you need to rebase this one |
| noise_cov : instance of Covariance | str | None | ||
| Noise covariance used to whiten the data while plotting. | ||
| Whitened data channels are scaled by ``scalings['whitened']``, | ||
| and their channel names are shown in italic. |
There was a problem hiding this comment.
now I see that it is to be able to read from file from disk.
Please document it.
| @@ -78,181 +78,184 @@ def test_plot_evoked(): | |||
| import matplotlib.pyplot as plt | |||
| rng = np.random.RandomState(0) | |||
| evoked = _get_epochs().average() | |||
There was a problem hiding this comment.
can you explain me the big diff in this file?
There was a problem hiding this comment.
There is no reason to have the with warnings.catch_warnings in there -- it could be masking useful warnings (and might have been, don't remember)
|
if I toggle off the bad eeg channel in the epochs.plot I get: also when I do evoked.plot(noise_cov=noise_cov) and select a time interval the topos that are produced look weird. |
larsoner
left a comment
There was a problem hiding this comment.
I'll fix the other things soon
| # test GFP only | ||
| evoked.plot(gfp='only') | ||
| assert_raises(ValueError, evoked.plot, gfp='foo') | ||
| evoked.plot(noise_cov=cov_fname) |
| @@ -78,181 +78,184 @@ def test_plot_evoked(): | |||
| import matplotlib.pyplot as plt | |||
| rng = np.random.RandomState(0) | |||
| evoked = _get_epochs().average() | |||
There was a problem hiding this comment.
There is no reason to have the with warnings.catch_warnings in there -- it could be masking useful warnings (and might have been, don't remember)
I think this likely isn't bad math, but rather just whitened topos looking weird. |
Actually I think this is reasonable behavior and error message. If you try to plot whitened data and your noise cov does not have all data channels, you should get an error, no? Other comments addressed and rebased. |
|
I think we should not display signals that are not part of the noise
covariance. That would be the easiest.
|
|
Okay lines have been removed |
|
CI failure is a sporadic unrelated Travis OSX problem |
|
@larsoner @agramfort why would we need evoked.plot(noise_cov=noise_cov) if there is evoked.plot_white? How should a user understand when to use which one? I am not sure what is the answer. |
|
The former is (consistent with raw and epochs options and) more useful for
browsing data and responses, the latter is more useful for diagnostic plots
for the covariance.
|
|
Any chance for review here? I'd like to move on to doing |
|
just played a bit. Behavior with bad channels is still not super robust.
See
[image: Inline image 1]
Basically you see that the bad channel in whiten mode is not plotted but
the label is not in Italic. You can also click on the bad in whiten mode
and you
get a gray line although in whiten mode the bad channels should just be
not plotted at all.
|
|
@agramfort done. (Also the image you tried to post did not post, but I think I understood what you meant: never show traces of bads from |
|
Okay scaling fixed / should now match that of I also fixed a bug with on On this PR it gives better labeling (and more uniform line widths to match The interesting thing is that our magnetometer scaling gets a bit far from the +/- 1.96 limits for SSS'ed data. Adding I think is to be expected, though. It actually exists in |
|
Examples (some didn't change much): plot_whitened, plot_compute_covariance, plot_evoked_whitening, plot_covariance_whitening_dspm. |
| the assumption of Gaussian white noise from which we expect values around | ||
| 0 with less than 2 standard deviations. Covariance estimation and diagnostic | ||
| plots are based on [1]_. | ||
| the assumption of Gaussian white noise during the baseline period. |
There was a problem hiding this comment.
can we specify +/- 1.96 here as expectation?
| and their channel names are shown in italic. | ||
| Can be a string to load a covariance from disk. | ||
| See also :meth:`mne.Evoked.plot_white` for additional inspection | ||
| of noise covariance properties when whitening evoked data. |
There was a problem hiding this comment.
, specifically, for inspection of expected values and model violations ... {or so}
There was a problem hiding this comment.
I'm wary of adding more text to an already long description here. I'll add it to the text for plot_evoked_white
| Can be a string to load a covariance from disk. | ||
| See also :meth:`mne.Evoked.plot_white` for additional inspection | ||
| of noise covariance properties when whitening evoked data. | ||
| For data processed with SSS, the effective dependence between |
There was a problem hiding this comment.
whatever is changed above should also be changed here (model violations / expected values etc).
| whitened GFPs based on each estimator separately for each sensor type. | ||
| Instead of numbers of channels the GFP display shows the estimated rank. | ||
| Note. The rank estimation will be printed by the logger for each noise | ||
| covariance estimator that is passed. |
There was a problem hiding this comment.
why is this removed? There is a lot of specific information. I think this is not a good idea.
| rank_list.append(this_rank) | ||
| evoked.pick_types(meg=True, eeg=True, ref_meg=False, exclude='bads') | ||
| n_ch_used, rank_list, picks_list, has_sss = _triage_rank_sss( | ||
| evoked.info, noise_cov, rank, scalings) |
There was a problem hiding this comment.
@larsoner is this call replacing all the work of the helper functions and other lines you removed?
There was a problem hiding this comment.
Yes it was copy-paste to refactor + bug fixes
| n_times=raw.n_times, bad_color=bad_color, picks=picks, | ||
| first_time=first_time, data_picks=[], decim=1) | ||
| first_time=first_time, data_picks=[], decim=1, | ||
| noise_cov=None, whitened_ch_names=()) |
There was a problem hiding this comment.
@larsoner why are we doing this actually? Just because we can or because people will need this. How does our whitening interact with ICA?
There was a problem hiding this comment.
Need to pass the params / API uniformity internally. They shouldn't use it with ICA which is why it's not exposed in the public facing APIs for ICA plotting.
| # (but in gray), but here we don't need to because "projector" | ||
| # starts out as identity. So all that is left to do is take any | ||
| # *good* data channels that are not in the noise cov to be NaN | ||
| nan_names = data_names - (bad_names | cov_names) |
There was a problem hiding this comment.
maybe the case for using set methods for better readability.
There was a problem hiding this comment.
I think set operations are clearly described using their arithmetic equivalents ...?
|
@larsoner I am not sure it is the best example. Can we plot the whitening of the evoked to see what is going on? As we discussed, the magnetometers are expected to be much lower in amplitude after SSS. Together with gradiometers they make up n_sss_components dimensions, as is shown in the GFP plot of the whitening. We're getting somewhere, don't give up :) I think we're moving in the right direction . |
Which example? The script I posted above? The three images in my previous post all come from the same script so it has |
| # we risk the rank estimates being incorrect (i.e., if the projectors | ||
| # do not match). | ||
| info_proj = info.copy() | ||
| info_proj['projs'] += cov['projs'] |
There was a problem hiding this comment.
This is one bugfix -- the estimated rank needs to use the union of projectors to mirror what happens in computing the whitener
| projector = setup_proj(this_info, add_eeg_ref=False)[0] | ||
| this_C = C[idx] | ||
| if projector is not None: | ||
| this_C = np.dot(np.dot(projector, this_C), projector.T) |
There was a problem hiding this comment.
... and correspondingly this joint projector actually needs to be applied to the covariance matrix to ensure rank estimation works properly
| ax.axhline(hline, color='red', linestyle='--') | ||
| ax.axhline(hline, color='red', linestyle='--', lw=2) | ||
| ax.set(title='{0} ({1} channels)'.format(titles_[ch_type], | ||
| len(picks))) |
There was a problem hiding this comment.
this is a bug / consistency fix (the one I show with a script in a previous comment)
|
@dengemann comments addressed (I think) |
|
ping @dengemann let me know if this is good to go for you |
|
Looks good. We should move on. I let @agramfort take another look. |
|
@agramfort okay for you too? |
|
works now like a charm and both give consistent scales. thanks @larsoner |
* WIP: Add whitening to plots * FIX: Add tests * FIX: Fix for labels and butterfly * DOC: Document option * FIX: Remove lines * FIX: Never show bads in whiten mode * FIX: Fix bad behavior * FIX: Add doc * FIX: Fix scaling * FIX: Unify cov handling and add warning about SSS * DOC: Better description



Need to:
Will post CircleCI result once it comes up.
Closes #3926.