Skip to content
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

WIP: added colors option to grow_labels #8519

Merged
merged 11 commits into from Nov 17, 2020

Conversation

olafhauk
Copy link
Contributor

@olafhauk olafhauk commented Nov 13, 2020

Closes #8517

What does this implement/fix?

Added colors option to mne.grow_label() to avoid error message for large number of seeds.

Additional information

@agramfort
Copy link
Member

can you update a test?

mne/label.py Outdated
else:
# use specified colors
label_colors = colors
Copy link
Member

Choose a reason for hiding this comment

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

There is no guarantee or check that label_colors is the right size. I think you had the right approach before, namely to do:

label_colors = np.empty((len(labels), 3))
label_colors[:] = colors

This guarantees that whatever colors is, it can broadcast and you will end up with label_colors of the right shape.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fine by me, but _n_colors() (label.py) returns array, shape (n, 4).

Copy link
Member

Choose a reason for hiding this comment

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

Then you can do label_colors = np.ones((len(labels), 4)); label_colors[:, :3] = label_colors if you want. I doubt anyone wants an alpha < 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then you can do label_colors = np.ones((len(labels), 4)); label_colors[:, :3] = label_colors if you want. I doubt anyone wants an alpha < 1

I'm now allowing four columns and added info about RGB/alpha values to doc-string.

@olafhauk olafhauk marked this pull request as ready for review November 16, 2020 14:24
@larsoner
Copy link
Member

LGTM -- can you update latest.inc and remove WIP from the title if you're happy and we'll merge? Thanks @olafhauk

else:
# use specified colors
label_colors = np.empty((len(labels), 4))
label_colors[:] = colors
Copy link
Member

Choose a reason for hiding this comment

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

label_colors = np.array(colors)

seems easier and equivalent.

also do you test somewhere that len(colors) == len(labels) ?

Copy link
Member

@larsoner larsoner Nov 16, 2020

Choose a reason for hiding this comment

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

No it's not equivalent. The point of doing the np.empty is that

  1. It allows broadcasting like colors=0. if you don't care about the color they can all be black transparent, or color=(1, 0, 0, 1) to make them all red, and
  2. It automatically makes sure len(labels) == len(colors)

EDIT: in other words, we let NumPy do the sanity checking for us by using np.empty

Copy link
Member

Choose a reason for hiding this comment

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

ok then. +1 for MRG if CIs are green.

thx @olafhauk !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

colors can also be of shape (, 4) (one color for all labels). I amended doc-string and added checks/tests.

@@ -3197,3 +3197,110 @@ def _get_src_nn(s, use_cps=True, vertices=None):
else:
nn = s['nn'][vertices, :]
return nn


def vertex_depth(inst, info=None, picks=None, trans=None, mode='dist',
Copy link
Member

Choose a reason for hiding this comment

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

Errant push of vertex_depth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh no.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I never know what to do about the codecov errors. Otherwise I think it's fine now.

@agramfort agramfort merged commit 23acc99 into mne-tools:master Nov 17, 2020
3 of 4 checks passed
@agramfort
Copy link
Member

Thx @olafhauk !

@olafhauk olafhauk deleted the grow_labels_colors branch November 18, 2020 09:13
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.

Spherical searchlights as labels for all vertices in source space
3 participants