Skip to content

Commit 34db090

Browse files
committed
add get_band_peak_event function
1 parent 3c049ff commit 34db090

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

doc/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ The following functions take in model objects directly, which is the typical use
166166

167167
get_band_peak
168168
get_band_peak_group
169+
get_band_peak_event
169170

170171
**Array Inputs**
171172

specparam/analysis/periodic.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_band_peak(model, band, select_highest=True, threshold=None,
3030
3131
Returns
3232
-------
33-
1d or 2d array
33+
peaks : 1d or 2d array
3434
Peak data. Each row is a peak, as [CF, PW, BW].
3535
3636
Examples
@@ -67,7 +67,7 @@ def get_band_peak_group(group, band, threshold=None, thresh_param='PW', attribut
6767
6868
Returns
6969
-------
70-
2d array
70+
peaks : 2d array
7171
Peak data. Each row is a peak, as [CF, PW, BW].
7272
Each row represents an individual model from the input object.
7373
@@ -101,6 +101,40 @@ def get_band_peak_group(group, band, threshold=None, thresh_param='PW', attribut
101101
threshold, thresh_param)
102102

103103

104+
def get_band_peak_event(event, band, threshold=None, thresh_param='PW', attribute='peak_params'):
105+
"""Extract peaks from a band of interest from an event model object.
106+
107+
Parameters
108+
----------
109+
event : SpectralTimeEventModel
110+
Object to extract peak data from.
111+
band : tuple of (float, float)
112+
Frequency range for the band of interest.
113+
Defined as: (lower_frequency_bound, upper_frequency_bound).
114+
select_highest : bool, optional, default: True
115+
Whether to return single peak (if True) or all peaks within the range found (if False).
116+
If True, returns the highest power peak within the search range.
117+
threshold : float, optional
118+
A minimum threshold value to apply.
119+
thresh_param : {'PW', 'BW'}
120+
Which parameter to threshold on. 'PW' is power and 'BW' is bandwidth.
121+
attribute : {'peak_params', 'gaussian_params'}
122+
Which attribute of peak data to extract data from.
123+
124+
Returns
125+
-------
126+
peaks : 3d array
127+
Array of peak data, organized as [n_events, n_time_windows, n_peak_params].
128+
"""
129+
130+
peaks = np.zeros([event.n_events, event.n_time_windows, 3])
131+
for ind in range(event.n_events):
132+
peaks[ind, :, :] = get_band_peak_group(\
133+
event.get_group(ind, None, 'group'), band, threshold, thresh_param, attribute)
134+
135+
return peaks
136+
137+
104138
def get_band_peak_group_arr(peak_params, band, n_fits, threshold=None, thresh_param='PW'):
105139
"""Extract peaks within a given band of interest, from peaks from a group fit.
106140

specparam/tests/analysis/test_periodic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ def test_get_band_peak(tfm):
1111

1212
assert np.all(get_band_peak(tfm, (8, 12)))
1313

14-
def test_get_band_peak_group(tfg):
14+
def test_get_band_peak_group(tfg, tft):
1515

1616
assert np.all(get_band_peak_group(tfg, (8, 12)))
17+
assert np.all(get_band_peak_group(tft, (8, 12)))
18+
19+
def test_get_band_peak_event(tfe):
20+
21+
assert np.all(get_band_peak_event(tfe, (8, 12)))
1722

1823
def test_get_band_peak_group_arr():
1924

0 commit comments

Comments
 (0)