Skip to content

MRG, ENH: viz.plot_drop_log() gains special-handling for subject=None - #9015

Merged
agramfort merged 4 commits into
mne-tools:mainfrom
hoechenberger:drop-log
Mar 12, 2021
Merged

agramfort merged 4 commits into
mne-tools:mainfrom
hoechenberger:drop-log

Conversation

@hoechenberger

@hoechenberger hoechenberger commented Mar 9, 2021 •

Copy link
Copy Markdown
Member

Now omits displaying the subject name in the title if it's None (would display literal None before, causing confusion to some!)

Also changes the title of the drop log plot to make it clearer what is being shown.

@hoechenberger hoechenberger changed the title WIP: plot_drop_log gets special-handling for subject=None WIP: plot_drop_log gains special-handling for subject=None Mar 9, 2021
@hoechenberger
hoechenberger force-pushed the drop-log branch 3 times, most recently from 05f6b4b to 7d13436 Compare March 12, 2021 08:32
Now omits displaying the subject name in the title if it's None

Also changes the title of the drop log plot to make it clearer what
is being shown.
@hoechenberger hoechenberger changed the title WIP: plot_drop_log gains special-handling for subject=None ENH: plot_drop_log gains special-handling for subject=None Mar 12, 2021
@hoechenberger hoechenberger changed the title ENH: plot_drop_log gains special-handling for subject=None ENH: viz.plot_drop_log() gains special-handling for subject=None Mar 12, 2021
@hoechenberger
hoechenberger marked this pull request as ready for review March 12, 2021 08:44
@hoechenberger
hoechenberger requested a review from agramfort March 12, 2021 08:44
Comment thread mne/epochs.py

@copy_function_doc_to_method_doc(plot_drop_log)
def plot_drop_log(self, threshold=0, n_max_plot=20, subject='Unknown',
def plot_drop_log(self, threshold=0, n_max_plot=20, subject='Unknown subj',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is for consistency with viz.plot_drop_log()

@hoechenberger hoechenberger changed the title ENH: viz.plot_drop_log() gains special-handling for subject=None MRG, ENH: viz.plot_drop_log() gains special-handling for subject=None Mar 12, 2021
@agramfort
agramfort merged commit 633bee3 into mne-tools:main Mar 12, 2021
@hoechenberger
hoechenberger deleted the drop-log branch March 12, 2021 10:32

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

I know this is already merged, but see comment below

Comment thread mne/report.py
epochs = read_epochs(epo_fname)
kwargs = dict(subject=self.subject, show=False)
kwargs = dict(
subject=self.subject if self.subject is not None else self.subject,

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 this change do exactly? Why is the conditional needed?

@hoechenberger

hoechenberger commented Mar 12, 2021 •

Copy link
Copy Markdown
Member Author

@drammock
The conditional allows users to entirely disable displaying the subject ID in the plot title.

[semi-unrelated] For historical reasons (I guess?), viz.plot_drop_log() defaults to the subject ID Unknown subj, and Epochs.plot_drop_log() defaulted to Unknown; I've now made it such that the defaults are the same in both: Unknown subj

[actual argument starts here] There was, however, no way to entirely disable displaying the subject ID, e.g. if you didn't have one. In this case, you'd either have to go with the default of Unknown/Unknown subj, which is … not great; or you could try to pass subject=None or an empty string, subject=''. Let's see what happens there (running on maint/0.22):

# %%
import os
import mne

path = mne.datasets.sample.data_path()
fname_raw = os.path.join(path, 'MEG', 'sample', 'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(fname_raw, verbose=False).crop(tmax=60)
events = mne.find_events(raw, stim_channel='STI 014')
event_id = {'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3,
            'visual/right': 4, 'face': 5, 'buttonpress': 32}

# create some epochs and ensure we drop a few, so we can then plot the drop log
reject = dict(eeg=150e-6)
epochs = mne.Epochs(raw=raw, events=events, event_id=event_id,
                    tmin=-0.2, tmax=0.7, reject=reject, preload=True)


epochs.plot_drop_log()
epochs.plot_drop_log(subject=None)
epochs.plot_drop_log(subject='')

Screen Shot 2021-03-12 at 16 31 51

Screen Shot 2021-03-12 at 16 32 14

As you can see, None simply gets converted to a string, so this doesn't work. But even if we pass an empty string, the result is not good: we still get the colon and space which separate the (now non-existent) subject ID from the percentage value of dropped epochs.

Now running the above with the changes made in this PR, the first two plots (default arguments and subject=None) would look like this:
Screen Shot 2021-03-12 at 16 30 52
which I believe is more desirable.

You could of course argue that one could've just special-cased subject='' instead of adding support for None, but the None case feels cleaner to me personally.

You could also argue that users could just alter the title after plotting in whichever way they like; however, since we already have a subject kwarg, I believe it makes sense that it can be used to control the respective part of the plot title too.

Does that make sense?

@drammock

drammock commented Mar 12, 2021 •

Copy link
Copy Markdown
Member

sure, but what doesn't make sense is why

subject=self.subject if self.subject is not None else self.subject

is different/better than

subject=self.subject

Or more simply, why do this:

foo = x if x is not None else x

instead of this:

foo = x

@hoechenberger

Copy link
Copy Markdown
Member Author

sure, but what doesn't make sense is why

subject=self.subject if self.subject is not None else self.subject

is different/better than

subject=self.subject

... oh. yes this doesn't make any sense

@hoechenberger

Copy link
Copy Markdown
Member Author

I suppose this is some leftover / cruft honestly. This should be simplified. I will do a followup PR to get this fixed. Thanks for catching this!

hoechenberger added a commit to hoechenberger/mne-python that referenced this pull request Mar 12, 2021
hoechenberger added a commit that referenced this pull request Mar 12, 2021
larsoner added a commit to vpeterson/mne-python that referenced this pull request Mar 15, 2021
* upstream/main: (135 commits)
  DOC: use bibtex in plot_source_power_spectrum_opm.py (mne-tools#8906) (mne-tools#9050)
  DOC: use bibtex in plot_sleep (mne-tools#9044)
  FIX: fix sideways helmet plot (mne-tools#9059)
  FIX: bibtex mne-tools#8933 (mne-tools#9047)
  Fix bibtex citation issue mne-tools#8929. (mne-tools#9051)
  bibtex fix plot_time_frequency_global_field_power (mne-tools#9052)
  Fixed bibtex references in plot_background_statistics (mne-tools#9046)
  Bibtex raw py (mne-tools#9048)
  DOC update footcite maxwell.py (mne-tools#9043)
  update footcite [skip github] [skip azp] (mne-tools#9054)
  Adding bibtex in plot_otp (mne-tools#9049)
  fix bibtex plot_evoked_whitening (mne-tools#9042)
  MAINT: Link earlier [skip github] [skip azp] (mne-tools#9041)
  DOC: convert references in plot_parcellation to use footcite (mne-tools#9032)
  MAINT: Fix circle (mne-tools#9039)
  ENH: Allow adding custom JavaScript to Report (mne-tools#9037)
  MRG, DOC: Bump theme version (mne-tools#9036)
  MAINT: Simplify expression (followup to mne-tools#9015) (mne-tools#9035)
  MRG, MAINT: Cleaner split, fewer skips in _brain tests (mne-tools#9029)
  MRG, ENH: viz.plot_drop_log() gains special-handling for subject=None (mne-tools#9015)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants