|
19 | 19 | from specparam.sim import sim_spectrogram
|
20 | 20 | from specparam.plts.spectra import plot_spectrogram
|
21 | 21 |
|
22 |
| - |
23 | 22 | ###################################################################################################
|
24 | 23 | # Parameterizing Spectrograms
|
25 | 24 | # ---------------------------
|
|
42 | 41 |
|
43 | 42 | ###################################################################################################
|
44 | 43 |
|
45 |
| -# Create & plot an example spectrogram |
| 44 | +# Define simulation parameters for a spectrogram |
46 | 45 | n_pre_post = 50
|
47 | 46 | freq_range = [3, 25]
|
48 |
| -ap_params = [[1, 1.5]] * n_pre_post + [[1, 1]] * n_pre_post |
49 |
| -pe_params = [[10, 1.5, 2.5]] * n_pre_post + [[10, 0.5, 2.]] * n_pre_post |
| 47 | +ap_params = {'fixed' : [[1, 1.5]] * n_pre_post + [[1, 1]] * n_pre_post} |
| 48 | +pe_params = {'gaussian' : [[10, 1.5, 2.5]] * n_pre_post + [[10, 0.5, 2.]] * n_pre_post} |
| 49 | + |
| 50 | +# Simulate spectrogram |
50 | 51 | freqs, spectrogram = sim_spectrogram(n_pre_post * 2, freq_range, ap_params, pe_params, nlvs=0.1)
|
51 | 52 |
|
52 | 53 | ###################################################################################################
|
53 | 54 |
|
54 | 55 | # Plot our simulated spectrogram
|
55 | 56 | plot_spectrogram(freqs, spectrogram)
|
56 | 57 |
|
57 |
| -################################################################################################### |
58 |
| -# SpectralTimeModel |
59 |
| -# ----------------- |
60 |
| -# |
61 |
| -# The :class:`~specparam.SpectralTimeModel` object is an extension of the SpectralModel objects |
62 |
| -# to support parameterizing neural power spectra that are organized across time (spectrograms). |
63 |
| -# |
64 |
| -# In practice, this object is very similar to the previously introduced spectral model objects, |
65 |
| -# especially the Group model object. The time object is a mildly updated Group object. |
66 |
| -# |
67 |
| -# The main differences with the SpectralTimeModel from previous model objects are that the |
68 |
| -# data it accepts and parameterizes should be organized as as array of power spectra over |
69 |
| -# time windows - basically as a spectrogram. |
70 |
| -# |
71 |
| - |
72 |
| -################################################################################################### |
73 |
| - |
74 |
| -# Initialize a SpectralTimeModel model, which accepts all the same settings as SpectralModel |
75 |
| -ft = SpectralTimeModel() |
76 |
| - |
77 | 58 | ###################################################################################################
|
78 | 59 | # Defining Oscillation Bands
|
79 | 60 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
93 | 74 | # Define a bands object to organize peak parameters
|
94 | 75 | bands = Bands({'alpha' : [7, 14]})
|
95 | 76 |
|
| 77 | +################################################################################################### |
| 78 | +# SpectralTimeModel |
| 79 | +# ----------------- |
| 80 | +# |
| 81 | +# The :class:`~specparam.SpectralTimeModel` object is an extension of the SpectralModel objects |
| 82 | +# to support parameterizing neural power spectra that are organized across time (spectrograms). |
| 83 | +# |
| 84 | +# In practice, this object is very similar to the previously introduced spectral model objects, |
| 85 | +# especially the Group model object. The time object is a mildly updated Group object. |
| 86 | +# |
| 87 | +# The main differences with the SpectralTimeModel from previous model objects are that the |
| 88 | +# data it accepts and parameterizes should be organized as as array of power spectra over |
| 89 | +# time windows - basically as a spectrogram. |
| 90 | +# |
| 91 | + |
| 92 | +################################################################################################### |
| 93 | + |
| 94 | +# Initialize a SpectralTimeModel model, which accepts all the same settings as SpectralModel |
| 95 | +ft = SpectralTimeModel(bands=bands) |
| 96 | + |
96 | 97 | ###################################################################################################
|
97 | 98 | #
|
98 | 99 | # Now we are ready to fit our spectrogram! As with all model objects, we can fit the models
|
|
102 | 103 | ###################################################################################################
|
103 | 104 |
|
104 | 105 | # Fit the spectrogram and print out report
|
105 |
| -ft.report(freqs, spectrogram, peak_org=bands) |
| 106 | +ft.report(freqs, spectrogram) |
106 | 107 |
|
107 | 108 | ###################################################################################################
|
108 | 109 | #
|
|
129 | 130 | n_events = 3
|
130 | 131 | spectrograms = []
|
131 | 132 | for ind in range(n_events):
|
132 |
| - freqs, cur_spect = sim_spectrogram(n_pre_post * 2, freq_range, ap_params, pe_params, nlvs=0.1) |
| 133 | + freqs, cur_spect = sim_spectrogram(\ |
| 134 | + n_pre_post * 2, freq_range, ap_params, pe_params, nlvs=0.1) |
133 | 135 | spectrograms.append(cur_spect)
|
134 | 136 |
|
135 | 137 | ###################################################################################################
|
|
157 | 159 | ###################################################################################################
|
158 | 160 |
|
159 | 161 | # Initialize the spectral event model
|
160 |
| -fe = SpectralTimeEventModel() |
| 162 | +fe = SpectralTimeEventModel(bands=bands) |
161 | 163 |
|
162 | 164 | ###################################################################################################
|
163 | 165 |
|
164 | 166 | # Fit the spectrograms and print out report
|
165 |
| -fe.report(freqs, spectrograms, peak_org=bands) |
| 167 | +fe.report(freqs, spectrograms) |
166 | 168 |
|
167 | 169 | ###################################################################################################
|
168 | 170 | #
|
|
0 commit comments