Skip to content

Commit 6dab254

Browse files
committed
Make tutorial independent of data saved from other tutorials
1 parent ea400cf commit 6dab254

File tree

2 files changed

+71
-48
lines changed

2 files changed

+71
-48
lines changed

tutorial/06-FurtherAnalysis.ipynb

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
"# General imports\n",
4242
"import numpy as np\n",
4343
"\n",
44-
"# Import FOOOF objects\n",
44+
"# Import FOOOF objects & synth utilities\n",
4545
"from fooof import FOOOF, FOOOFGroup\n",
46+
"from fooof.synth import gen_group_power_spectra, param_sampler\n",
4647
"\n",
4748
"# FOOOF comes with some basic analysis function to work with FOOOF outputs\n",
4849
"from fooof.analysis import get_band_peak, get_band_peak_group"
@@ -51,18 +52,29 @@
5152
{
5253
"cell_type": "code",
5354
"execution_count": 2,
54-
"metadata": {
55-
"collapsed": true
56-
},
55+
"metadata": {},
5756
"outputs": [],
5857
"source": [
59-
"# Initialize a FOOOF object, and load data saved from previous tutorials\n",
60-
"fm = FOOOF()\n",
61-
"fm.load()\n",
62-
"\n",
63-
"# Initialize a FOOOFGroup, and load data saved from the previous tutorials\n",
64-
"fg = FOOOFGroup()\n",
65-
"fg.load()"
58+
"# Reload some data and fit a FOOOF model to use\n",
59+
"freqs = np.load('dat/freqs_lfp.npy')\n",
60+
"spectrum = np.load('dat/spectrum_lfp.npy')\n",
61+
"fm = FOOOF(peak_width_limits=[2, 8])\n",
62+
"fm.fit(freqs, spectrum, [3, 30])"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 3,
68+
"metadata": {},
69+
"outputs": [],
70+
"source": [
71+
"# Generate some synthetic power spectra and fit a FOOOFGroup to use\n",
72+
"freqs, spectra, _ = gen_group_power_spectra(n_spectra=10,\n",
73+
" freq_range=[3, 40],\n",
74+
" background_params=param_sampler([[20, 2], [35, 1.5]]),\n",
75+
" gauss_params=param_sampler([[], [10, 0.5, 2]]))\n",
76+
"fg = FOOOFGroup(peak_width_limits=[1, 8], min_peak_amplitude=0.05, max_n_peaks=6, verbose=False)\n",
77+
"fg.fit(freqs, spectra)"
6678
]
6779
},
6880
{
@@ -82,7 +94,7 @@
8294
},
8395
{
8496
"cell_type": "code",
85-
"execution_count": 3,
97+
"execution_count": 4,
8698
"metadata": {
8799
"collapsed": true
88100
},
@@ -101,7 +113,7 @@
101113
},
102114
{
103115
"cell_type": "code",
104-
"execution_count": 4,
116+
"execution_count": 5,
105117
"metadata": {
106118
"collapsed": true
107119
},
@@ -113,36 +125,37 @@
113125
},
114126
{
115127
"cell_type": "code",
116-
"execution_count": 5,
128+
"execution_count": 6,
117129
"metadata": {
118130
"collapsed": true
119131
},
120132
"outputs": [],
121133
"source": [
122134
"# Define frequency bands of interest\n",
123135
"theta_band = [4, 8]\n",
124-
"alpha_band = [8, 12]"
136+
"alpha_band = [8, 12]\n",
137+
"beta_band = [15, 30]"
125138
]
126139
},
127140
{
128141
"cell_type": "code",
129-
"execution_count": 6,
142+
"execution_count": 7,
130143
"metadata": {},
131144
"outputs": [
132145
{
133146
"data": {
134147
"text/plain": [
135-
"array([ 7.98920599, 0.82222326, 2.06407363])"
148+
"array([16.08799633, 0.31497775, 2.91456728])"
136149
]
137150
},
138-
"execution_count": 6,
151+
"execution_count": 7,
139152
"metadata": {},
140153
"output_type": "execute_result"
141154
}
142155
],
143156
"source": [
144-
"# Extract any theta band oscillations from the FOOOF model\n",
145-
"get_band_peak(fm.peak_params_, theta_band)"
157+
"# Extract any beta band oscillations from the FOOOF model\n",
158+
"get_band_peak(fm.peak_params_, beta_band)"
146159
]
147160
},
148161
{
@@ -156,7 +169,7 @@
156169
},
157170
{
158171
"cell_type": "code",
159-
"execution_count": 7,
172+
"execution_count": 8,
160173
"metadata": {
161174
"collapsed": true
162175
},
@@ -168,20 +181,20 @@
168181
},
169182
{
170183
"cell_type": "code",
171-
"execution_count": 8,
184+
"execution_count": 9,
172185
"metadata": {},
173186
"outputs": [
174187
{
175188
"data": {
176189
"text/plain": [
177-
"array([[ 10.09964663, 0.47133132, 3.60705373],\n",
178-
" [ 10.08879109, 0.47731098, 3.68490876],\n",
179-
" [ nan, nan, nan],\n",
180-
" [ 10.09665833, 0.47097969, 3.6633977 ],\n",
181-
" [ 10.02854683, 0.48826778, 3.81333837]])"
190+
"array([[ nan, nan, nan],\n",
191+
" [10.02967719, 0.48536385, 3.80421559],\n",
192+
" [ nan, nan, nan],\n",
193+
" [ nan, nan, nan],\n",
194+
" [10.04113301, 0.49012133, 3.78016585]])"
182195
]
183196
},
184-
"execution_count": 8,
197+
"execution_count": 9,
185198
"metadata": {},
186199
"output_type": "execute_result"
187200
}
@@ -208,16 +221,16 @@
208221
},
209222
{
210223
"cell_type": "code",
211-
"execution_count": 9,
224+
"execution_count": 10,
212225
"metadata": {},
213226
"outputs": [
214227
{
215228
"name": "stdout",
216229
"output_type": "stream",
217230
"text": [
218-
"Alpha CF : 10.0606832091\n",
219-
"Alpha Amp: 0.482675280189\n",
220-
"Alpha BW : 3.73077799688\n"
231+
"Alpha CF : 10.032316994652476\n",
232+
"Alpha Amp: 0.48704968437097024\n",
233+
"Alpha BW : 3.793087577369318\n"
221234
]
222235
}
223236
],
@@ -250,7 +263,7 @@
250263
},
251264
{
252265
"cell_type": "code",
253-
"execution_count": 10,
266+
"execution_count": 11,
254267
"metadata": {
255268
"collapsed": true
256269
},
@@ -262,17 +275,17 @@
262275
},
263276
{
264277
"cell_type": "code",
265-
"execution_count": 11,
278+
"execution_count": 12,
266279
"metadata": {},
267280
"outputs": [
268281
{
269282
"data": {
270283
"text/plain": [
271-
"array([ 2.03219939, 2.5261983 , 1.9998798 , 2.53002688, 1.51648434,\n",
272-
" 1.50259231, 2.52335528, 2.01688269, 1.51448427, 2.52317579])"
284+
"array([1.49974605, 2.02193707, 1.50243998, 1.50058702, 2.01839346,\n",
285+
" 2.02086515, 1.49905775, 1.50216495, 1.52005248, 1.5156712 ])"
273286
]
274287
},
275-
"execution_count": 11,
288+
"execution_count": 12,
276289
"metadata": {},
277290
"output_type": "execute_result"
278291
}
@@ -336,7 +349,7 @@
336349
"name": "python",
337350
"nbconvert_exporter": "python",
338351
"pygments_lexer": "ipython3",
339-
"version": "3.6.3"
352+
"version": "3.6.6"
340353
}
341354
},
342355
"nbformat": 4,

tutorials/plot_06-FurtherAnalysis.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,30 @@
2525
# General imports
2626
import numpy as np
2727

28-
# Import FOOOF objects
28+
# Import FOOOF objects & synth utilities
2929
from fooof import FOOOF, FOOOFGroup
30+
from fooof.synth import gen_group_power_spectra, param_sampler
3031

3132
# FOOOF comes with some basic analysis function to work with FOOOF outputs
3233
from fooof.analysis import get_band_peak, get_band_peak_group
3334

3435
###############################################################################
3536

36-
# Initialize a FOOOF object, and load data saved from previous tutorials
37-
fm = FOOOF()
38-
fm.load()
37+
# Reload some data and fit a FOOOF model to use
38+
freqs = np.load('dat/freqs_lfp.npy')
39+
spectrum = np.load('dat/spectrum_lfp.npy')
40+
fm = FOOOF(peak_width_limits=[2, 8])
41+
fm.fit(freqs, spectrum, [3, 30])
3942

40-
# Initialize a FOOOFGroup, and load data saved from the previous tutorials
41-
fg = FOOOFGroup()
42-
fg.load()
43+
###############################################################################
44+
45+
# Generate some synthetic power spectra and fit a FOOOFGroup to use
46+
freqs, spectra, _ = gen_group_power_spectra(n_spectra=10,
47+
freq_range=[3, 40],
48+
background_params=param_sampler([[20, 2], [35, 1.5]]),
49+
gauss_params=param_sampler([[], [10, 0.5, 2]]))
50+
fg = FOOOFGroup(peak_width_limits=[1, 8], min_peak_amplitude=0.05, max_n_peaks=6, verbose=False)
51+
fg.fit(freqs, spectra)
4352

4453
###############################################################################
4554
# FOOOF Analysis Utilities
@@ -66,12 +75,13 @@
6675
# Define frequency bands of interest
6776
theta_band = [4, 8]
6877
alpha_band = [8, 12]
78+
beta_band = [15, 30]
6979

7080
###############################################################################
71-
# Use :func:`get_band_peak` to extract oscillations
81+
# Use :func:`get_band_peak` to extract oscillations from a single FOOOF model
7282

73-
# Extract any theta band oscillations from the FOOOF model
74-
get_band_peak(fm.peak_params_, theta_band)
83+
# Extract any beta band oscillations from the FOOOF model
84+
get_band_peak(fm.peak_params_, beta_band)
7585

7686
###############################################################################
7787
#

0 commit comments

Comments
 (0)