Skip to content

Very WIP: sequential colors for plot_compare_evoked - #4221

Closed
jona-sassenhagen wants to merge 11 commits into
mne-tools:masterfrom
jona-sassenhagen:plt_comp_ev_sequential
Closed

jona-sassenhagen wants to merge 11 commits into
mne-tools:masterfrom
jona-sassenhagen:plt_comp_ev_sequential

Conversation

Comment thread mne/viz/evoked.py Outdated

norm = mpl.colors.BoundaryNorm(numbers + [numbers[-1] +1], l.N)
sm = matplotlib.cm.ScalarMappable(cmap=l, norm=norm
)

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.

a lonely bracket, lost in the code, help it find its way home!

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.

That whole chunk of code is just very terrible in general ... I don't dare fixing it yet.

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.

But you've given some hope to the lonely bracket now ;)

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

@mmagnuski do you think you can test it a bit?

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

I don't get where the error is coming from:

======================================================================
FAIL: Test module docstring formatting.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/miniconda/envs/test/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/travis/build/mne-tools/mne-python/mne/utils.py", line 824, in dec
    return function(*args, **kwargs)
  File "/home/travis/build/mne-tools/mne-python/mne/tests/test_docstring_parameters.py", line 143, in test_docstring_parameters
    raise AssertionError(msg)
AssertionError: 
mne.utils.run_subprocess arg mismatch: ['-------', 'Returns', 'stderr', 'stdout']
>>  raise AssertionError("\nmne.utils.run_subprocess arg mismatch: ['-------', 'Returns', 'stderr', 'stdout']")
    

@larsoner

Copy link
Copy Markdown
Member

@jona-sassenhagen I'll see if I can fix it

Comment thread mne/utils.py

Returns
-------
Returns

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.

@jona-sassenhagen this is where it comes from

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.

How the hell did that show up here!?

Thanks Eric. I was combing through the parts I could remember changing, but couldn't find anything.

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.

FWYW on a somewhat related note I find that checking my own diffs top-to-bottom on GitHub I usually find one or two things I didn't mean to put in there or forgot to change. I usually try to do it before requesting a review, as it cuts down on the review iteration cycles/time a bit.

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.

Ha, this isn't ready for review yet, first I have to see if I can convince @agramfort to allow all of the clumsy magic for the sake of a convenience plotting function.

@codecov-io

codecov-io commented Apr 24, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #4221 into master will decrease coverage by 0.02%.
The diff coverage is 69.66%.

@@            Coverage Diff            @@
##           master   #4221      +/-   ##
=========================================
- Coverage   86.23%   86.2%   -0.03%     
=========================================
  Files         357     357              
  Lines       64534   64595      +61     
  Branches     9831    9850      +19     
=========================================
+ Hits        55651   55686      +35     
- Misses       6180    6204      +24     
- Partials     2703    2705       +2

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Sadly this is adding like 2 secs to the tests.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Error is just coverage ...

@agramfort did you have time to look at the API (see gist)?
Maybe @dengemann has comments?

@mmagnuski

Copy link
Copy Markdown
Member

@jona-sassenhagen Yes, I can test later today. I'll let you know.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Thanks @mmagnuski ... I don't mean 'stress testing', just if you find the function useful and the API sensible.

@agramfort

Copy link
Copy Markdown
Member

When I set sequential to False in the last cell it breaks.

To me it's too much magic. I would go with a more explicit approach, maybe inspired by pandas or seaborn.

meta = dict(num_letters=[4, 4, ...], concrete=[0, 1, 0, 1]) 
# or
meta = pd.DataFrame(dict(num_letters=[4, 4, ...], concrete=[0, 1, 0, 1]))

mne.viz.evoked.plot_compare_evokeds(
    evokeds.values(), meta=meta, color='num_letters', linestyle='concrete',
    colormap=plt.cm.viridis
    picks=...
).set_size_inches((6, 3));

inferring variables from strings (keys here) is for me very much like black magic.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

So a design matrix-like approach?

How about:

evokeds = {cond1 + "/" + cond2: epochs[cond1 + cond2].average()
    for cond2 in {"freq_1", "_freq_2", "freq_3} for cond1 in {"concrete", "abstract"}}
order = {cond: int(cond.split("_")[-1]) for cond in evokeds}

mne.viz.plot_compare_evokeds(evokeds, colors="viridis", order=order)

(E.g. a dict mapping conditions to integers, where the integers indicate color on a colormap)

The API needs the split legend though. Though I think this can be as easy as directly mapping the linestyles dict to a legend.
Zero magic in either case.

One also needs to set the colorbar label though, somehow. E.g., minimally, here

mne.viz.plot_compare_evokeds(evokeds, colors="viridis", color_units='frequency', order=order)

@agramfort

agramfort commented Apr 27, 2017 •

Copy link
Copy Markdown
Member

let's draft the different use cases:

First a 2/2 design:

evokeds = {'A/C': evoked1, 'B/C': evoked2, 'A/C': evoked3, 'B/D': evoked4}
mne.viz.plot_compare_evokeds(evokeds, colors="viridis")

then a mix of categorical and continuous:

evokeds = {'A/1': evoked1, 'A/1': evoked2, 'B/2': evoked3, 'B/2': evoked4}
mne.viz.plot_compare_evokeds(evokeds, colors="viridis")

or using meta

meta = dict(n_letters=[1, 1, 2, 2])
evokeds = {'A/1': evoked1, 'A/1': evoked2, 'B/2': evoked3, 'B/2': evoked4}
mne.viz.plot_compare_evokeds(evokeds, colormap="viridis", meta=meta, color='n_letters')

@jona-sassenhagen please edit this so we have a compact view of what use case we want to support

@mmagnuski

Copy link
Copy Markdown
Member

@jona-sassenhagen sorry for the delay, it works well for me but I tested only simple cases with one sequential var. I like the meta approach - but it would require using OrderedDict or list for evokeds.

@jona-sassenhagen

jona-sassenhagen commented Apr 27, 2017 •

Copy link
Copy Markdown
Contributor Author

@agramfort something changed the post as I was editing and I lost all my comments, so I'm putting it here ...

Factorial:

evokeds = {'A/C': evoked1, 'B/C': evoked2, 'A/C': evoked3, 'B/D': evoked4}
mne.viz.plot_compare_evokeds(evokeds, colors="viridis")
or
mne.viz.plot_compare_evokeds(evokeds, colors={"A":"r", "B":"b"}, linestyles={"C":"-", "D":":"})

Continuous

evokeds = [evoked1, evoked2, evoked3, evoked4]
colors = list(range(len(evokeds)))
cmap = {"colorbar_label":"viridis"}
mne.viz.plot_compare_evokeds(evokeds, colors=colors, cmap=cmap)

colors is of the same shape as evokeds

Mixed:

evokeds = {'A/1': evoked1, 'A/2': evoked2, 'B/1': evoked3, 'B/2': evoked4}
linestyles = {"A":"-", "B":":"}
colors = {"1":1, "2":2}
cmap = {"colorbar_label":"jet"}
mne.viz.plot_compare_evokeds(evokeds, colors=colors, linestyles=linestyles, cmap=cmap)

(Mixed would depend on 1. giving a cmap parameter, 2. colors being a dict that links from HED tags to numeric.)

Mixed by order:
edit: this actually won't work because we don't have condition names

evokeds = [evoked1, evoked2, evoked3, evoked4]
linestyles = ["-", ":", "-", ":"]
colors = [1, 1, 2, 2]
cmap = {"colorbar_label":"jet"}
mne.viz.plot_compare_evokeds(evokeds, colors=colors, linestyles=linestyles, cmap=cmap)

(Currently, evokeds can be either 1. an Evoked obj, 2. a list of evoked objs, 3. a dict of evoked objs, 4. a list of lists of evoked objs, 5. a dict of lists of evoked objs.)

Right now I'm not sure the "dict of dicts" approach we discussed would be such a good idea.
colors = {"condition_label":[{"1":1}, {"2":2}, {"3":3}]} doesn't look so good.
Creating a pandas series might help, but isn't it overkill when we could simply have a dict?

I think your 'meta' idea would be better for something where we allow more flexibility (e.g., seaborn which has hue, col, row, marker, ...). But here we only ever have two: color and linestyle. Right?

@agramfort

Copy link
Copy Markdown
Member

@jona-sassenhagen fine with the proposal except I don't like the:

cmap = {"colorbar_label":"jet"}

cmap should be None, str or an instance of plt.cm.XXX

so ok for cmap = 'jet'

so colors and linestyles cannot be dict if evoked is not a dict. If evoked is a dict then everything is a dict and we use HED

last thing, how do you specify what to show in the legend?

@agramfort

Copy link
Copy Markdown
Member

sorry @jona-sassenhagen I was not notified of your edit of the previous message.

I don't understand why you say that the mixed use case will not work.

My summary is:

List input for Continuous

evokeds = [evoked1, evoked2, evoked3, evoked4]
colors = list(range(len(evokeds)))
cmap = {"colorbar_label":"viridis"}
mne.viz.plot_compare_evokeds(evokeds, colors=colors, cmap=cmap)

colors is of the same shape as evokeds

then we use evokeds as dict:

Factorial:

evokeds = {'A/C': evoked1, 'B/C': evoked2, 'A/C': evoked3, 'B/D': evoked4}
mne.viz.plot_compare_evokeds(evokeds, colors="viridis")
or
mne.viz.plot_compare_evokeds(evokeds, colors={"A":"r", "B":"b"}, linestyles={"C":"-", "D":":"})

and then mixed if one of the value in the color dict is not a string.

Mixed:

evokeds = {'A/1': evoked1, 'A/2': evoked2, 'B/1': evoked3, 'B/2': evoked4}
linestyles = {"A":"-", "B":":"}
colors = {"1":1, "2":2}
cmap = {"colorbar_label":"jet"}
mne.viz.plot_compare_evokeds(evokeds, colors=colors, linestyles=linestyles, cmap=cmap)

it means that what is not color coded with an int does not generate a colorbar.

clear? do I miss something?

@jona-sassenhagen

jona-sassenhagen commented Jul 16, 2017 via email

Copy link
Copy Markdown
Contributor Author

@agramfort

agramfort commented Jul 16, 2017 via email

Copy link
Copy Markdown
Member

@jona-sassenhagen

jona-sassenhagen commented Jul 16, 2017 via email

Copy link
Copy Markdown
Contributor Author

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Ok I'm back at this since #4289 looks like it'll get merged soon.

@agramfort

agramfort commented Aug 31, 2017 via email

Copy link
Copy Markdown
Member

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Closed for #4526

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