Skip to content

WIP: Tfr plot joint - #4981

Merged
larsoner merged 63 commits into
mne-tools:masterfrom
jona-sassenhagen:tfr_plot_joint
Mar 29, 2018
Merged

larsoner merged 63 commits into
mne-tools:masterfrom
jona-sassenhagen:tfr_plot_joint

Conversation

@jona-sassenhagen

@jona-sassenhagen jona-sassenhagen commented Mar 3, 2018 •

Copy link
Copy Markdown
Contributor

Finishing #4134 , which has been sitting in limbo cause @mmagnuski and I are lazy :)

closes #3801

Todo:

  • fix all tests
  • docs
  • take care of multiple channel types smoothly

@codecov

codecov Bot commented Mar 3, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #4981 into master will increase coverage by <.01%.
The diff coverage is 87.85%.

@@            Coverage Diff             @@
##           master    #4981      +/-   ##
==========================================
+ Coverage   87.92%   87.92%   +<.01%     
==========================================
  Files         356      356              
  Lines       63677    63863     +186     
  Branches    10882    10935      +53     
==========================================
+ Hits        55989    56154     +165     
- Misses       4923     4938      +15     
- Partials     2765     2771       +6

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Ready for reviews. @mmagnuski ?

@mmagnuski

Copy link
Copy Markdown
Member

@jona-sassenhagen I'd be happy to review, but unfortunatelly won't have time before wednesday or tuesday. :(

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Errrr I fucked up something with MEG. Not yet ready for review.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Here is an example:

import mne
path = mne.datasets.testing.data_path()

fname = path + '/EEGLAB/test_raw.set'
m = path + "/EEGLAB/test_chans.locs"

event_id = {"rt":1, "square":2}
raw = mne.io.read_raw_eeglab(fname, event_id=event_id,
                             montage=m, preload=True)

from mne.time_frequency import tfr_morlet

events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, event_id=event_id,
                    tmin=-.5, tmax=1.5, preload=True)
freqs = np.arange(3, 30)
tfr = tfr_morlet(epochs["square"], freqs, 3, return_itc=False).apply_baseline((None, 0))
timefreqs = {(.4, 3): (0.1, .5),
             (1.1, 10): (0.1, .5)}
tfr.plot_joint(
    timefreqs=timefreqs
              );

unknown-130

@agramfort

agramfort commented Mar 4, 2018 via email

Copy link
Copy Markdown
Member

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Yes, I've thought about that. Would allow us to skip the text at the top.

I'm willing to do it, but I'd prefer to finish up and merge this first, and do squares in a second PR? I tend to get lost in long PRs.

@agramfort

agramfort commented Mar 4, 2018 via email

Copy link
Copy Markdown
Member

Comment thread mne/time_frequency/tfr.py Outdated
####################

# find and/or setup timefreqs
try: # There are a trillin ways for this to go wrong ...

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.

@agramfort are you ok with this try/except?

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.

not really. You shoudl have a simple private auxilary function that does the checks on types, dims and values.

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.

Here is one error case I'm not sure about how to check without a try: if timefreqs is a non-iterable. There's a ton of iterables. I could do hasattr(item, '__len__'), but that does not seem perfect.

Comment thread mne/time_frequency/tfr.py
to style the topomaps. `axes` and `show` are ignored. If `times`
is not in this dict, automatic peak detection is used. Beyond that,
if ``None``, no customizable arguments will be passed.
Defaults to ``None``.

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.

note to self: fix this

Comment thread mne/viz/utils.py Outdated
return noise_cov


def _get_channel_types(info):

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.

Is this a duplicate?

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Example:

https://7132-1301584-gh.circle-artifacts.com/0/tmp/circle-artifacts.nszbKOg/html/_images/sphx_glr_plot_sensors_time_frequency_007.png

@larsoner

larsoner commented Mar 6, 2018

Copy link
Copy Markdown
Member

IIRC @agramfort asked about boxes overlaid to show the averaging window, and I agree it would help. The lines indicate the center but not the extent.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Yes, my suggestion was I do it in another PR, Alex said that would be ok.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Btw this is quite ready for review :)

@agramfort

agramfort commented Mar 7, 2018 via email

Copy link
Copy Markdown
Member

Comment thread mne/time_frequency/tfr.py Outdated
combine : 'mean' | 'rms' | None
Type of aggregation to perform across selected channels. If
None, plot one figure per selected channel.
exclude : None | list of str | 'bads'

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.

What does None do? If it's the same as [] just use ().

@larsoner larsoner 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.

Other than a few minor things LGTM!

Comment thread mne/time_frequency/tfr.py Outdated
The time-frequency point(s) for which topomaps will be plotted.
Each tuple defines a pair (time, frequency) in s and Hz on the
TFR plot. For example, to look at 10 Hz activity 1 second into
the epoch and 3 Hz activity 300 msec into the epoch,

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.

end with :: to render as code instead of inline 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.

Also this is too long, move to Notes section and refer people there

Comment thread mne/time_frequency/tfr.py Outdated

Notes
-----
.. versionadded:: 0.15.0

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.

No time traveling allowed

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.

:D

Comment thread mne/time_frequency/tfr.py Outdated


def _is_numeric(n):
return isinstance(n, (int, float))

@larsoner larsoner Mar 7, 2018 •

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.

Maybe better as n = np.asarray(n); return n.dtype.kind not in 'OSU' and n.shape == ()

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.

... what

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.

What you wrote will fail for various numpy types. You can adapt what I wrote to work for them (maybe you also want to exclude complex in addition to object, string, and unicode (OSU))

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.

Hm. I think out of these:
https://docs.scipy.org/doc/numpy/reference/arrays.scalars.html
we want all the ints and floats, but not bool, complex, anything else. Wouldn't it be more economic to make an inclusive check than an exclusive check?

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.

I.e., isinstance(n, (np.integer, np.floating))

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.

sounds good

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.

Seems this was needed: isinstance(n, (np.integer, np.floating, int, float))

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Comments addressed, anyone else?

@larsoner

larsoner commented Mar 9, 2018

Copy link
Copy Markdown
Member

This one already got a lot of review love in #4134 so we might not need so much here. @mmagnuski you looked at the original one, do you have time to check this one out, too?

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Yes, the API is largely unchanged from there. The main point with the underlying functionality is that the vlims are independent between the image and the maps, and that the colorbar is drawn without reference to the image (only the maps).

The underlying code is changed by a lot though.

@mmagnuski

Copy link
Copy Markdown
Member

I can try this out tomorrow in the morning, but won't be able to give full review in a few days. But I trust you both :)

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

@mmagnuski ? :D

@mmagnuski

Copy link
Copy Markdown
Member

Oops, sorry, thanks for reminding. I'm on a limited time budget this weekend but I'll try it out today.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

👯‍♂️

@jona-sassenhagen jona-sassenhagen changed the title WIP: Tfr plot joint MRG: Tfr plot joint Mar 12, 2018
@mmagnuski

Copy link
Copy Markdown
Member

Sorry, Jona to keep you waiting so long, I have an application deadline tomorrow that will set me free. :)

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

@larsoner can you try again, see if the lines no longer cross?

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

(If yes, my error was also due to a brilliant piece of overengineering, specifically fixing the same problem twice.)

@jona-sassenhagen jona-sassenhagen added this to the 0.16 milestone Mar 27, 2018
@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Milestoned because it carries an API change wrt @cbrnr 's newest PR that should be merged before release.

@larsoner

Copy link
Copy Markdown
Member

Yep, lines no longer cross on 2.1.2

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

All green, ready for merge.

@agramfort

Copy link
Copy Markdown
Member

we have some rendering issues with colorbars cf. https://7444-1301584-gh.circle-artifacts.com/0/tmp/circle-artifacts.krdig2e/html/auto_tutorials/plot_visualize_evoked.html#sphx-glr-auto-tutorials-plot-visualize-evoked-py but you should do it another PR.

anyone feel free to merge if you're happy. Ok for me.

thanks @jona-sassenhagen for all the efforts.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

@hubertjb did the base!

@larsoner
larsoner merged commit d0f8da7 into mne-tools:master Mar 29, 2018
@larsoner

Copy link
Copy Markdown
Member

Thanks @jona-sassenhagen and @hubertjb !

@hubertjb

Copy link
Copy Markdown
Contributor

Also, thanks to @nicproulx with whom I initially work on this. Thanks @jona-sassenhagen for wrapping it up!

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Thanks everyone!

@mmagnuski

Copy link
Copy Markdown
Member

Thanks @jona-sassenhagen, @hubertjb and @nicproulx ! 🚀

@jona-sassenhagen
jona-sassenhagen deleted the tfr_plot_joint branch June 2, 2018 09:22
britta-wstnr pushed a commit to britta-wstnr/mne-python that referenced this pull request Jul 5, 2018
* [MRG] Implementing plot_joint method in AverageTFR class

* Created internal _plot method called by averageTFR.plot() and plot_joint()

* Added aggregate (mean or rms) and exclude arguments to averageTFR.plot

* Adding example of `plot_joint` inside time frequency tutorial

* Adding test_joint_plot

* Passing topomap_args to improve run time of tests

* Removing description of interactive colorbar in AverageTFR.plot()

* Adding private function for joining channel names

* Moved connection_line method to viz/utils from viz/evoked and added y
* argument.

* Adding private function for preparing a joint plot's axes

* Added automatic title option in _plot method

* `exclude` and `aggregate` arguments in plot_joint

* ...

* init

* agg->combine

* api and costring fixes

* code cleanup

* excessive testing

* tests

* pep8

* pep8

* pep8

* fix test

* pep8git add *git add *git add *

* fix vlims

* better example

* ffff

* title

* factor out timefreqs input check

* fix verbose error

* fix verbose, 2

* fix timefreq test

* minor cleanup

* i think we are finally getting somewhere

* bug

* force circle rebuild

* remove duplicate function

* refactor

* fix bug

* fix bug, 2

* fix pep8

* minor cleanup

* fascist pep8

* factor out preproc_tfr_inst

* the incomparable pep8 again. who else.

* timefreqs order

* force circleci rebuild

* fix sorting of timefreqs

* comments

* minor

* move picks function, pinpoint lines

* fix interactive, add colorbar helper

* fix a few tests for cbar

* fix more tests

* fix more tests

* fix pep8

* fix pep8b

* adjust plot lims

* add ch type to title

* force circle

* just a circle test

* another circle test

* another circle test

* another circle test

* show sysinfo

* undo stupid line

* show sysinfo

* show sysinfo again

* undo circle

* warn for mpl 2.1.0 missing lines

* add explanation of mpl bug

* fix order

* mask_alpha

* pep8
@psychoxiatao

Copy link
Copy Markdown

Example:

https://7132-1301584-gh.circle-artifacts.com/0/tmp/circle-artifacts.nszbKOg/html/_images/sphx_glr_plot_sensors_time_frequency_007.png

Hello, for the command power.plot_joint, How could I fix the color scale between conditions? I see that topomap_args control the topo maps color scale, but I did not know how to set it. In addition, How could show both image color scale and topo maps color scale? Thanks a lot.

@mmagnuski

Copy link
Copy Markdown
Member

@psychoxiatao Please create another issue. Did you try vmin and vmax?

@psychoxiatao

Copy link
Copy Markdown

@mmagnuski Yeah, but it doesn't work.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

@psychoxiatao
Please post a code example. If it’s a bug, please post a reproducible Code piece to a new issue. Thanks.

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.

Viz improvement: AverageTFR.plot_joint

6 participants