Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] - Add support for peak height spacing #297

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions specparam/tests/utils/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
###################################################################################################
###################################################################################################

def test_get_freq_ind():

freqs = np.array([1, 2, 3, 4, 5])

assert get_freq_ind(freqs, 2.2) == 1
assert get_freq_ind(freqs, 3.7) == 3

def test_compute_average():

data = np.array([[0., 1., 2., 3., 4., 5.],
Expand Down
19 changes: 19 additions & 0 deletions specparam/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@
###################################################################################################
###################################################################################################

def get_freq_ind(freqs, freq):
"""Get the index of the closest frequency value to a specified input frequency.

Parameters
----------
freqs : 1d array
Frequency values.
freq : float
Frequency value to select closest index to.

Returns
-------
int
Index of closest value in `freqs` to `freq`.
"""

return np.argmin(np.abs(freqs - freq))


def compute_average(data, average='mean'):
"""Compute the average across an array of data.

Expand Down