I am building a custom wrapper/driver around the package MNE-Python that does realtime EEG signal analysis. I am taking a static-class approach and has methods like these:
@staticmethod
def plot_psd(mne_driver, *args, **kwargs):
psd_fig = mne_driver.mne_raw.compute_psd().plot(*args, **kwargs)
if mne_driver.output_destination is not None:
psd_fig.savefig(mne_driver.get_path_name("psd.png"))
mne_driver.sequence += 1
return mne_driver
@staticmethod
def plot_topomap(mne_driver, *args, **kwargs):
topomap_fig = mne_driver.mne_raw.compute_psd().plot_topomap(*args, **kwargs)
if mne_driver.output_destination is not None:
topomap_fig.savefig(mne_driver.get_path_name("topomap.png"))
mne_driver.sequence += 1
return mne_driver
where mne_driver.mne_raw
is an mne.io.Raw
object.
When I plot the PSD graph, it gets saved correctly to the predefined location. However, when I plot the PSD topomap, it does not get saved; instead, the program seems to stop proceeding after executing the line topomap_fig = mne_driver.mne_raw.compute_psd().plot_topomap(*args, **kwargs)
: it opens the window containing the correct, functioning graph and does not go on to the next line of code.
According to MNE-Python’s documentation, both Raw.compute_psd().plot()
and compute_psd().plot_topomap()
shall return a Matplotlib Figure
object, which could then be saved.
Thus, I am curious whether there is a difference in the implementation of the two methods the causing the saving behavior to be different, and if so, how could I fix this?