Skip to content

Conversation

@mscheltienne
Copy link
Member

I added support for passing a callable to control how the channels are combined when plotting a TFR.
For now, it only supported 'mean' and 'rms'. I could use this feature as I'd like to do a weighted average instead.

@mscheltienne mscheltienne changed the title Add support for a callable in the combine argument of TFR plots MRG: Add support for a callable in the combine argument of TFR plots Nov 16, 2022
@mscheltienne
Copy link
Member Author

CI failures seem unrelated.

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

Just a couple of minor comments, otherwise LGTM!

Comment on lines +1354 to +1361
if (
not isinstance(data, np.ndarray)
or data.shape != tfr.data.shape[1:]
):
raise RuntimeError(
"A callable 'combine' must return a numpy array of shape "
"(n_freqs, n_times)."
)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (
not isinstance(data, np.ndarray)
or data.shape != tfr.data.shape[1:]
):
raise RuntimeError(
"A callable 'combine' must return a numpy array of shape "
"(n_freqs, n_times)."
)
_validate_type(data, np.ndarray, 'data returned by callable')
_check_option('data.shape returned by callable',
data.shape, (tfr.data.shape[1:],))

Copy link
Member Author

@mscheltienne mscheltienne Nov 17, 2022

Choose a reason for hiding this comment

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

Honestly, I think the shorter error message with what the shape represent is more informative, even if it takes 4 additional lines (because of the 79 character limit 😄)

Copy link
Member

Choose a reason for hiding this comment

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

What I wrote should tell you the wrong shape that was supplied and the correct shape that is needed, did you check? I could be wrong...

Copy link
Member

Choose a reason for hiding this comment

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

Ohh you mean the dimension names. Okay

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the names. And, IMO, the phrasing from _check_option doesn't really fit this context.

Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
@mscheltienne
Copy link
Member Author

mscheltienne commented Nov 18, 2022

I didn't notice earlier, but the title generation if set to 'auto' uses the 'combine' argument. It should render a better title now.


def _set_title_multiple_electrodes(title, combine, ch_names, max_chans=6,
all=False, ch_type=None):
all_=False, ch_type=None):
Copy link
Member Author

@mscheltienne mscheltienne Nov 18, 2022

Choose a reason for hiding this comment

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

I renamed the argument because of the function all(), and made sure it wasn't used as a kwarg across mne.
LMK if you want me to revert if you think other packages in the ecosystem use this function and might use all= in the function call.

Copy link
Member

Choose a reason for hiding this comment

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

if they do, their CIs will hopefully tell us :)

@larsoner
Copy link
Member

pip pre failure is unrelated, but I restarted Azure because the Conda job had a 404 that I'd like to see come back green

@larsoner
Copy link
Member

Pushed a commit that adds a temporary workaround for the mpl issue, marking for merge-when-green, thanks @mscheltienne !

@larsoner larsoner enabled auto-merge (squash) November 18, 2022 15:15
@larsoner
Copy link
Member

Okay that wasn't enough... pushed a commit to install matplotlib<3.7 that hopefully we can revert while dealing with #11332 properly

@larsoner larsoner merged commit 063a3e8 into mne-tools:main Nov 18, 2022
@mscheltienne mscheltienne deleted the callable_combine branch November 18, 2022 20:37
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.

4 participants