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

ENH: Improve report usability #12901

Merged
merged 11 commits into from
Oct 18, 2024
Merged

ENH: Improve report usability #12901

merged 11 commits into from
Oct 18, 2024

Conversation

larsoner
Copy link
Member

@larsoner larsoner commented Oct 17, 2024

I'm using mne.Report for some data analyses and hit some limitations. This PR proposes a few different things, quoting the changelog entry:

- :meth:`mne.Report.add_projs` can now plot with :func:`mne.viz.plot_projs_joint` rather than :func:`mne.viz.plot_projs_topomap`
- :class:`mne.Report` now has attributes ``img_max_width`` and ``img_max_res`` that can be used to control image scaling.
- :class:`mne.Report` now has an attribute ``collapse`` that allows collapsing sections and/or subsections by default.
- :func:`mne.viz.plot_head_positions` now has a ``totals=True`` option to show the total distance and angle of the head.

The first is a fairly straightforward improvement to add_projs to make use of plot_projs_joint instead of plain plot_projs_topomap when you want to do so.

Next is adding a few attributes to mne.Report to control behavior of 1) image scaling, and 2) section collapsing. I never liked that I couldn't get full-res images using the default functions like add_raw or add_projs, now you can set report.img_max_width = None to stop it from shrinking those plots, e.g. on main (you'll need to open separately to see the downscaling quality issue):

Screenshot from 2024-10-17 16-49-31

On this PR you get full res (up to the browser max-width 100% limitation):

Screenshot from 2024-10-17 16-56-37

And for section collapsing, I added support for collapsing sections and/or subsections by setting report.collapse = ["section", "subsection"]. I think this is a good enough start, but I think it's also future compatible with potentially also supporting regex-matching to HTML subsection titles for example.

Finally, it adds an option to plot_head_positions to summarize the distance and rotation in terms of the vector magnitude and angle. The distance is nice, but the big gain I think is the angle as it's a lot more human-readable than the quats themselves, e.g.:

image

Draft mode since I need to add tests for all of this stuff and modify some examples but I figured I'd open this to get the ball rolling. I could split these off if it would help review, but happy to keep them together if review will be doable with them all in one place. (Or at least the report stuff together in one PR, and the head pos stuff in another.)

@larsoner
Copy link
Member Author

Okay tests added, this one should be good to go!

Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

looks good! My suggestions are super minor, feel free to apply them in with ci skip and manually merge. Thanks @larsoner!

doc/changes/devel/12901.bugfix.rst Outdated Show resolved Hide resolved
mne/report/tests/test_report.py Outdated Show resolved Hide resolved
mne/report/tests/test_report.py Outdated Show resolved Hide resolved
@@ -305,10 +323,18 @@ def plot_head_positions(

if destination is not None:
vals = np.array(
[destination[:, 3], rot_to_quat(destination[:, :3])]
[1000 * destination[:3, 3], rot_to_quat(destination[:3, :3])]
Copy link
Member

Choose a reason for hiding this comment

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

huh, was position previously in meters but labeled as millimeters? oops.

Copy link
Member Author

Choose a reason for hiding this comment

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

They were in mm before but it was done by modifying destination inplace earlier. So no bugfix just a change in where the multiplication happens!

@larsoner larsoner enabled auto-merge (squash) October 18, 2024 17:08
@larsoner larsoner merged commit 56e522b into mne-tools:main Oct 18, 2024
28 checks passed
@larsoner larsoner deleted the report branch October 18, 2024 18:06
larsoner added a commit to larsoner/mne-python that referenced this pull request Oct 28, 2024
* upstream/main: (824 commits)
  Add `psd_args` to `plot_ica_sources` and `ICA.plot_sources` (mne-tools#12912)
  Fix GDF NumPy >= 2 (mne-tools#12909)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12908)
  ENH: Improve report usability (mne-tools#12901)
  MAINT: Avoid problematic PySide6 (mne-tools#12902)
  Sync README dependencies with pyproject.toml (mne-tools#12890)
  remove trailing slash from pybv base URL [ci skip] (mne-tools#12892)
  Cast tuple of filenames to list to improve error handling (mne-tools#12891)
  Website (mne-tools#12885)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12888)
  BUG: Fix bugs with coreg (mne-tools#12884)
  Bump mamba-org/setup-micromamba from 1 to 2 in the actions group (mne-tools#12887)
  Update spacing for comments in pyproject.toml (mne-tools#12886)
  make HTML repr for Forward match others (mne-tools#12883)
  MAINT: Linkchecks [circle deploy] (mne-tools#12882)
  Update roadmap (mne-tools#12872)
  [MRG] Require good and bad channels when creating a SpectrumArray object (mne-tools#12877)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12879)
  MAINT: Update code credit (mne-tools#12880)
  BUG: Fix bug with Path casting (mne-tools#12878)
  ...
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.

2 participants