-
Notifications
You must be signed in to change notification settings - Fork 15
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
Update mnefun._reports to work with current mne-python #364
Conversation
Codecov Report
@@ Coverage Diff @@
## main #364 +/- ##
==========================================
- Coverage 19.99% 19.99% -0.01%
==========================================
Files 33 33
Lines 5161 5167 +6
==========================================
+ Hits 1032 1033 +1
- Misses 4129 4134 +5 |
Ok, reports are working for me now except for raw_segments. On my machine, raw.plot() gives me a |
could use a context handler |
One more issue. It looks like SVG as an image format option isn't working for me for some reason. The drop_log plot uses SVG as the image format by default in mnefun (and looks like the only section to do so); it works if I change the image format to png, but otherwise not. Here's what my drop log plot looks like. lol!! |
@drammock Strangely, it looks like |
Ok, I figured out the raw_segments issue. Aside from context management, you can't pass a backend choice to raw.plot() directly; you can only set it in your mne-python.json configuration file on your own machine. Because there's already a context management function defined for mnefun reports, I think it makes sense to call |
mnefun/_report.py
Outdated
@@ -40,6 +40,7 @@ | |||
@contextmanager | |||
def report_context(): | |||
"""Create a context for making plt and mlab figures.""" | |||
mne.viz.set_browser_backend('matplotlib') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use the https://mne.tools/dev/generated/mne.viz.use_browser_backend.html context manager so that it is only set temporarily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I tried use_browser_backend first, but that failed for me (I still got a qt instance). :) I didn't dig in to why it wasn't working -- thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you do it in a "with" clause? It won't work if it's not done that way. Even though it's within another context manager, create a second context within it for the browser backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying my above comment: I think I had trouble because I don't have experience nesting context managers inside of other context managers. I can see it's possible because in the report_context()
function, you do this:
try:
with plt.style.context(style):
yield
except Exception:
matplotlib.use(old_backend, force=True)
plt.interactive(is_interactive)
raise
to use the plt style context. But what's the functional and proper way to do that embedding with mne.viz.use_browser_backend
? Then I was having doubts about how many levels of context nesting make sense! But I do see the advisability of only setting the backend temporarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do as many levels you want
with a:
with b:
...
Or if you will want them both active the whole ..
of code (nothing with just a
) then you can instead do
with a, b:
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without looking at the code... I think in report_context we probably set the backend to Agg, which is a non-GUI backend. So nothing popping up is the correct/desired behavior here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alrighty, friends, I propose the following fix. Basically, I think my issue is Pycharm, which tries to do some backend handling stuff when importing matplotlib. If I call with mne.viz.use_backend_browser('matplotlib'):
after importing matplotlib and forcing it to use Agg
in the report_context()
function, then everything works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@larsoner (Sorry, I didn't see your comment earlier). Agg
shouldn't cause your console to freeze such that you have to force quit it though, right?? 😆 I ran the above code from interactive python in a terminal earlier today, and all of the above code options worked perfectly from the terminal, so that makes me feel pretty confident that Pycharm is what's causing my problems!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🌩️#️⃣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drammock You know, you were the one who told me back in the day that checking your code in the terminal is a good troubleshooting step. Thanks for the good advice!!! 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drammock feel free to merge if you're happy
So, I propose that we just use the png format for all our mnefun plots. It's immediately functional, and we can work on the mne.reports functionality separately. |
Ok, reports are running smoothly both with my genz2 environment and with a fresh dev environment running mne 1.4, so we're in business on my end! |
Sounds good except that we should use webp instead of png nowadays. It produces smaller files even at lossless quality |
Mmm, ok. How much backward compatibility do we have with webp? |
Based on docstring from https://mne.tools/dev/generated/mne.Report.html it looks like 1.3 which is probably new enough. But you could do a version check to decide if you want to be more backward compatible |
Ok, mne.Report does its own checking to see if it can use webp, so my thought was to just use whatever it comes up with when it instantiates to control all the rest of the report building beneath that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
circle is complaining about missing config / oauth change. @larsoner do you know what that's about?
I think good_hpi_count, raw_segments, and psd under mnefun._reports could all use some help.
I'm starting with tossing the the mne.fixes call from good_hpi_count (
time_kwargs
is unused).