We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Memory consumption in plot_brainstorm_phantom_elekta
Circle is failing because it's using so much memory.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tutorials/plot_brainstorm_phantom_elekta.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """
3 ==========================================
4 Brainstorm Elekta phantom tutorial dataset
5 ==========================================
6 
7 Here we compute the evoked from raw for the Brainstorm Elekta phantom
8 tutorial dataset. For comparison, see [1]_ and:
9 
10     http://neuroimage.usc.edu/brainstorm/Tutorials/PhantomElekta
11 
12 References
13 ----------
14 .. [1] Tadel F, Baillet S, Mosher JC, Pantazis D, Leahy RM.
15        Brainstorm: A User-Friendly Application for MEG/EEG Analysis.
16        Computational Intelligence and Neuroscience, vol. 2011, Article ID
17        879716, 13 pages, 2011. doi:10.1155/2011/879716
18 """
19 
20 # Authors: Eric Larson <larson.eric.d@gmail.com>
21 #
22 # License: BSD (3-clause)
23 
24 import os.path as op
25 import numpy as np
26 
27 import mne
28 from mne import find_events, fit_dipole
29 from mne.datasets.brainstorm import bst_phantom_elekta
30 from mne.io import read_raw_fif
31 
32 print(__doc__)
33 
34 ###############################################################################
35 # The data were collected with an Elekta Neuromag VectorView system at 1000 Hz
36 # and low-pass filtered at 330 Hz. Here the medium-amplitude (200 nAm) data
37 # are read to construct instances of :class:`mne.io.Raw`.
38 data_path = bst_phantom_elekta.data_path()
39 
40 raw_fname = op.join(data_path, 'kojak_all_200nAm_pp_no_chpi_no_ms_raw.fif')
41 raw = read_raw_fif(raw_fname, preload=True)
42 
43 ###############################################################################
44 # Data channel array consisted of 204 MEG planor gradiometers,
45 # 102 axial magnetometers, and 3 stimulus channels. Let's get the events
46 # for the phantom, where each dipole (1-32) gets its own event:
47 
48 events = find_events(raw, 'STI201')
49 raw.plot(events=events)
50 raw.info['bads'] = ['MEG2421']
51 
52 ###############################################################################
53 # The data have strong line frequency (60 Hz and harmonics) and cHPI coil
54 # noise (five peaks around 300 Hz):
55 
56 raw.plot_psd()
57 
58 ###############################################################################
59 # We know our phantom produces sinusoidal bursts below 25 Hz, so let's filter.
60 
61 raw.filter(None, 40., h_trans_bandwidth=10., filter_length='1s')
62 raw.plot_psd()
63 
64 ###############################################################################
65 # The data are still a bit noisy, so let's use Maxwell filtering to clean it.
66 # Ideally we would have the fine calibration and cross-talk information
67 # for the site of interest, but we don't, so we just do:
68 
69 raw.fix_mag_coil_types()
70 raw = mne.preprocessing.maxwell_filter(raw, origin=(0., 0., 0.))
71 raw.plot(events=events)
72 
73 ###############################################################################
74 # Now we epoch our data, average it, and look at the first dipole response.
75 # The first peak appears around 3 ms.
76 
77 tmin, tmax = -0.2, 0.2
78 event_id = list(range(1, 33))
79 epochs = mne.Epochs(raw, events, event_id, tmin, tmax, baseline=(None, -0.01))
80 epochs['1'].average().plot()
81 
82 ###############################################################################
83 # Let's do some dipole fits. The phantom is properly modeled by a single-shell
84 # sphere with origin (0., 0., 0.). We compute covariance, then do the fits.
85 
86 t_peak = 0.061  # 3 MS at largest peak
87 sphere = mne.make_sphere_model(r0=(0., 0., 0.), head_radius=None)
88 cov = mne.compute_covariance(epochs, tmax=0)
89 data = []
90 for ii in range(1, 33):
91     evoked = epochs[str(ii)].average().crop(t_peak, t_peak)
92     data.append(evoked.data[:, 0])
93 evoked = mne.EvokedArray(np.array(data).T, evoked.info, tmin=0.)
94 dip = fit_dipole(evoked, cov, sphere, n_jobs=2)[0]
95 
96 ###############################################################################
97 # Now we can compare to the actual locations, taking the difference in mm:
98 
99 actual_pos = mne.dipole.get_phantom_dipoles(kind='122')[0]
100 diffs = 1000 * np.sqrt(np.sum((dip.pos - actual_pos) ** 2, axis=-1))
101 print('Differences (mm):\n%s' % diffs[:, np.newaxis])
102
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/tutorials/plot_brainstorm_phantom_elekta.py b/tutorials/plot_brainstorm_phantom_elekta.py
--- a/tutorials/plot_brainstorm_phantom_elekta.py
+++ b/tutorials/plot_brainstorm_phantom_elekta.py
@@ -38,7 +38,7 @@
 data_path = bst_phantom_elekta.data_path()
 
 raw_fname = op.join(data_path, 'kojak_all_200nAm_pp_no_chpi_no_ms_raw.fif')
-raw = read_raw_fif(raw_fname, preload=True)
+raw = read_raw_fif(raw_fname)
 
 ###############################################################################
 # Data channel array consisted of 204 MEG planor gradiometers,
@@ -51,39 +51,41 @@
 
 ###############################################################################
 # The data have strong line frequency (60 Hz and harmonics) and cHPI coil
-# noise (five peaks around 300 Hz):
+# noise (five peaks around 300 Hz). Here we plot only out to 60 seconds
+# to save memory:
 
-raw.plot_psd()
+raw.plot_psd(tmax=60.)
 
 ###############################################################################
-# We know our phantom produces sinusoidal bursts below 25 Hz, so let's filter.
-
-raw.filter(None, 40., h_trans_bandwidth=10., filter_length='1s')
-raw.plot_psd()
-
-###############################################################################
-# The data are still a bit noisy, so let's use Maxwell filtering to clean it.
+# Let's use Maxwell filtering to clean the data a bit.
 # Ideally we would have the fine calibration and cross-talk information
 # for the site of interest, but we don't, so we just do:
 
 raw.fix_mag_coil_types()
 raw = mne.preprocessing.maxwell_filter(raw, origin=(0., 0., 0.))
+
+###############################################################################
+# We know our phantom produces sinusoidal bursts below 25 Hz, so let's filter.
+
+raw.filter(None, 40., h_trans_bandwidth=10., filter_length='1s')
 raw.plot(events=events)
 
 ###############################################################################
 # Now we epoch our data, average it, and look at the first dipole response.
-# The first peak appears around 3 ms.
+# The first peak appears around 3 ms. Because we low-passed at 40 Hz,
+# we can also decimate our data to save memory.
 
-tmin, tmax = -0.2, 0.2
+tmin, tmax = -0.1, 0.1
 event_id = list(range(1, 33))
-epochs = mne.Epochs(raw, events, event_id, tmin, tmax, baseline=(None, -0.01))
+epochs = mne.Epochs(raw, events, event_id, tmin, tmax, baseline=(None, -0.01),
+                    decim=5)
 epochs['1'].average().plot()
 
 ###############################################################################
 # Let's do some dipole fits. The phantom is properly modeled by a single-shell
 # sphere with origin (0., 0., 0.). We compute covariance, then do the fits.
 
-t_peak = 0.061  # 3 MS at largest peak
+t_peak = 60e-3  # ~60 MS at largest peak
 sphere = mne.make_sphere_model(r0=(0., 0., 0.), head_radius=None)
 cov = mne.compute_covariance(epochs, tmax=0)
 data = []

{"golden_diff": "diff --git a/tutorials/plot_brainstorm_phantom_elekta.py b/tutorials/plot_brainstorm_phantom_elekta.py\n--- a/tutorials/plot_brainstorm_phantom_elekta.py\n+++ b/tutorials/plot_brainstorm_phantom_elekta.py\n@@ -38,7 +38,7 @@\n data_path = bst_phantom_elekta.data_path()\n \n raw_fname = op.join(data_path, 'kojak_all_200nAm_pp_no_chpi_no_ms_raw.fif')\n-raw = read_raw_fif(raw_fname, preload=True)\n+raw = read_raw_fif(raw_fname)\n \n ###############################################################################\n # Data channel array consisted of 204 MEG planor gradiometers,\n@@ -51,39 +51,41 @@\n \n ###############################################################################\n # The data have strong line frequency (60 Hz and harmonics) and cHPI coil\n-# noise (five peaks around 300 Hz):\n+# noise (five peaks around 300 Hz). Here we plot only out to 60 seconds\n+# to save memory:\n \n-raw.plot_psd()\n+raw.plot_psd(tmax=60.)\n \n ###############################################################################\n-# We know our phantom produces sinusoidal bursts below 25 Hz, so let's filter.\n-\n-raw.filter(None, 40., h_trans_bandwidth=10., filter_length='1s')\n-raw.plot_psd()\n-\n-###############################################################################\n-# The data are still a bit noisy, so let's use Maxwell filtering to clean it.\n+# Let's use Maxwell filtering to clean the data a bit.\n # Ideally we would have the fine calibration and cross-talk information\n # for the site of interest, but we don't, so we just do:\n \n raw.fix_mag_coil_types()\n raw = mne.preprocessing.maxwell_filter(raw, origin=(0., 0., 0.))\n+\n+###############################################################################\n+# We know our phantom produces sinusoidal bursts below 25 Hz, so let's filter.\n+\n+raw.filter(None, 40., h_trans_bandwidth=10., filter_length='1s')\n raw.plot(events=events)\n \n ###############################################################################\n # Now we epoch our data, average it, and look at the first dipole response.\n-# The first peak appears around 3 ms.\n+# The first peak appears around 3 ms. Because we low-passed at 40 Hz,\n+# we can also decimate our data to save memory.\n \n-tmin, tmax = -0.2, 0.2\n+tmin, tmax = -0.1, 0.1\n event_id = list(range(1, 33))\n-epochs = mne.Epochs(raw, events, event_id, tmin, tmax, baseline=(None, -0.01))\n+epochs = mne.Epochs(raw, events, event_id, tmin, tmax, baseline=(None, -0.01),\n+                    decim=5)\n epochs['1'].average().plot()\n \n ###############################################################################\n # Let's do some dipole fits. The phantom is properly modeled by a single-shell\n # sphere with origin (0., 0., 0.). We compute covariance, then do the fits.\n \n-t_peak = 0.061  # 3 MS at largest peak\n+t_peak = 60e-3  # ~60 MS at largest peak\n sphere = mne.make_sphere_model(r0=(0., 0., 0.), head_radius=None)\n cov = mne.compute_covariance(epochs, tmax=0)\n data = []\n", "issue": "Memory consumption in plot_brainstorm_phantom_elekta\nCircle is failing because it's using so much memory.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\n==========================================\nBrainstorm Elekta phantom tutorial dataset\n==========================================\n\nHere we compute the evoked from raw for the Brainstorm Elekta phantom\ntutorial dataset. For comparison, see [1]_ and:\n\n    http://neuroimage.usc.edu/brainstorm/Tutorials/PhantomElekta\n\nReferences\n----------\n.. [1] Tadel F, Baillet S, Mosher JC, Pantazis D, Leahy RM.\n       Brainstorm: A User-Friendly Application for MEG/EEG Analysis.\n       Computational Intelligence and Neuroscience, vol. 2011, Article ID\n       879716, 13 pages, 2011. doi:10.1155/2011/879716\n\"\"\"\n\n# Authors: Eric Larson <larson.eric.d@gmail.com>\n#\n# License: BSD (3-clause)\n\nimport os.path as op\nimport numpy as np\n\nimport mne\nfrom mne import find_events, fit_dipole\nfrom mne.datasets.brainstorm import bst_phantom_elekta\nfrom mne.io import read_raw_fif\n\nprint(__doc__)\n\n###############################################################################\n# The data were collected with an Elekta Neuromag VectorView system at 1000 Hz\n# and low-pass filtered at 330 Hz. Here the medium-amplitude (200 nAm) data\n# are read to construct instances of :class:`mne.io.Raw`.\ndata_path = bst_phantom_elekta.data_path()\n\nraw_fname = op.join(data_path, 'kojak_all_200nAm_pp_no_chpi_no_ms_raw.fif')\nraw = read_raw_fif(raw_fname, preload=True)\n\n###############################################################################\n# Data channel array consisted of 204 MEG planor gradiometers,\n# 102 axial magnetometers, and 3 stimulus channels. Let's get the events\n# for the phantom, where each dipole (1-32) gets its own event:\n\nevents = find_events(raw, 'STI201')\nraw.plot(events=events)\nraw.info['bads'] = ['MEG2421']\n\n###############################################################################\n# The data have strong line frequency (60 Hz and harmonics) and cHPI coil\n# noise (five peaks around 300 Hz):\n\nraw.plot_psd()\n\n###############################################################################\n# We know our phantom produces sinusoidal bursts below 25 Hz, so let's filter.\n\nraw.filter(None, 40., h_trans_bandwidth=10., filter_length='1s')\nraw.plot_psd()\n\n###############################################################################\n# The data are still a bit noisy, so let's use Maxwell filtering to clean it.\n# Ideally we would have the fine calibration and cross-talk information\n# for the site of interest, but we don't, so we just do:\n\nraw.fix_mag_coil_types()\nraw = mne.preprocessing.maxwell_filter(raw, origin=(0., 0., 0.))\nraw.plot(events=events)\n\n###############################################################################\n# Now we epoch our data, average it, and look at the first dipole response.\n# The first peak appears around 3 ms.\n\ntmin, tmax = -0.2, 0.2\nevent_id = list(range(1, 33))\nepochs = mne.Epochs(raw, events, event_id, tmin, tmax, baseline=(None, -0.01))\nepochs['1'].average().plot()\n\n###############################################################################\n# Let's do some dipole fits. The phantom is properly modeled by a single-shell\n# sphere with origin (0., 0., 0.). We compute covariance, then do the fits.\n\nt_peak = 0.061  # 3 MS at largest peak\nsphere = mne.make_sphere_model(r0=(0., 0., 0.), head_radius=None)\ncov = mne.compute_covariance(epochs, tmax=0)\ndata = []\nfor ii in range(1, 33):\n    evoked = epochs[str(ii)].average().crop(t_peak, t_peak)\n    data.append(evoked.data[:, 0])\nevoked = mne.EvokedArray(np.array(data).T, evoked.info, tmin=0.)\ndip = fit_dipole(evoked, cov, sphere, n_jobs=2)[0]\n\n###############################################################################\n# Now we can compare to the actual locations, taking the difference in mm:\n\nactual_pos = mne.dipole.get_phantom_dipoles(kind='122')[0]\ndiffs = 1000 * np.sqrt(np.sum((dip.pos - actual_pos) ** 2, axis=-1))\nprint('Differences (mm):\\n%s' % diffs[:, np.newaxis])\n", "path": "tutorials/plot_brainstorm_phantom_elekta.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\n==========================================\nBrainstorm Elekta phantom tutorial dataset\n==========================================\n\nHere we compute the evoked from raw for the Brainstorm Elekta phantom\ntutorial dataset. For comparison, see [1]_ and:\n\n    http://neuroimage.usc.edu/brainstorm/Tutorials/PhantomElekta\n\nReferences\n----------\n.. [1] Tadel F, Baillet S, Mosher JC, Pantazis D, Leahy RM.\n       Brainstorm: A User-Friendly Application for MEG/EEG Analysis.\n       Computational Intelligence and Neuroscience, vol. 2011, Article ID\n       879716, 13 pages, 2011. doi:10.1155/2011/879716\n\"\"\"\n\n# Authors: Eric Larson <larson.eric.d@gmail.com>\n#\n# License: BSD (3-clause)\n\nimport os.path as op\nimport numpy as np\n\nimport mne\nfrom mne import find_events, fit_dipole\nfrom mne.datasets.brainstorm import bst_phantom_elekta\nfrom mne.io import read_raw_fif\n\nprint(__doc__)\n\n###############################################################################\n# The data were collected with an Elekta Neuromag VectorView system at 1000 Hz\n# and low-pass filtered at 330 Hz. Here the medium-amplitude (200 nAm) data\n# are read to construct instances of :class:`mne.io.Raw`.\ndata_path = bst_phantom_elekta.data_path()\n\nraw_fname = op.join(data_path, 'kojak_all_200nAm_pp_no_chpi_no_ms_raw.fif')\nraw = read_raw_fif(raw_fname)\n\n###############################################################################\n# Data channel array consisted of 204 MEG planor gradiometers,\n# 102 axial magnetometers, and 3 stimulus channels. Let's get the events\n# for the phantom, where each dipole (1-32) gets its own event:\n\nevents = find_events(raw, 'STI201')\nraw.plot(events=events)\nraw.info['bads'] = ['MEG2421']\n\n###############################################################################\n# The data have strong line frequency (60 Hz and harmonics) and cHPI coil\n# noise (five peaks around 300 Hz). Here we plot only out to 60 seconds\n# to save memory:\n\nraw.plot_psd(tmax=60.)\n\n###############################################################################\n# Let's use Maxwell filtering to clean the data a bit.\n# Ideally we would have the fine calibration and cross-talk information\n# for the site of interest, but we don't, so we just do:\n\nraw.fix_mag_coil_types()\nraw = mne.preprocessing.maxwell_filter(raw, origin=(0., 0., 0.))\n\n###############################################################################\n# We know our phantom produces sinusoidal bursts below 25 Hz, so let's filter.\n\nraw.filter(None, 40., h_trans_bandwidth=10., filter_length='1s')\nraw.plot(events=events)\n\n###############################################################################\n# Now we epoch our data, average it, and look at the first dipole response.\n# The first peak appears around 3 ms. Because we low-passed at 40 Hz,\n# we can also decimate our data to save memory.\n\ntmin, tmax = -0.1, 0.1\nevent_id = list(range(1, 33))\nepochs = mne.Epochs(raw, events, event_id, tmin, tmax, baseline=(None, -0.01),\n                    decim=5)\nepochs['1'].average().plot()\n\n###############################################################################\n# Let's do some dipole fits. The phantom is properly modeled by a single-shell\n# sphere with origin (0., 0., 0.). We compute covariance, then do the fits.\n\nt_peak = 60e-3  # ~60 MS at largest peak\nsphere = mne.make_sphere_model(r0=(0., 0., 0.), head_radius=None)\ncov = mne.compute_covariance(epochs, tmax=0)\ndata = []\nfor ii in range(1, 33):\n    evoked = epochs[str(ii)].average().crop(t_peak, t_peak)\n    data.append(evoked.data[:, 0])\nevoked = mne.EvokedArray(np.array(data).T, evoked.info, tmin=0.)\ndip = fit_dipole(evoked, cov, sphere, n_jobs=2)[0]\n\n###############################################################################\n# Now we can compare to the actual locations, taking the difference in mm:\n\nactual_pos = mne.dipole.get_phantom_dipoles(kind='122')[0]\ndiffs = 1000 * np.sqrt(np.sum((dip.pos - actual_pos) ** 2, axis=-1))\nprint('Differences (mm):\\n%s' % diffs[:, np.newaxis])\n", "path": "tutorials/plot_brainstorm_phantom_elekta.py"}]}