Skip to content

Commit 6e641a4

Browse files
committed
add compute_arr_desc
1 parent 0858a6c commit 6e641a4

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

specparam/tests/utils/test_data.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ def test_compute_presence():
6565
assert compute_presence(data2_full, average=True) == 1.0
6666
assert compute_presence(data2_nan, average=True) == 0.6
6767

68+
def test_compute_arr_desc():
69+
70+
data1_full = np.array([1., 2., 3., 4., 5.])
71+
minv, maxv, meanv = compute_arr_desc(data1_full)
72+
for val in [minv, maxv, meanv]:
73+
assert isinstance(val, float)
74+
75+
data1_nan = np.array([np.nan, 2., 3., np.nan, 5.])
76+
minv, maxv, meanv = compute_arr_desc(data1_nan)
77+
for val in [minv, maxv, meanv]:
78+
assert isinstance(val, float)
79+
6880
def test_trim_spectrum():
6981

7082
f_in = np.array([0., 1., 2., 3., 4., 5.])

specparam/utils/data.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ def compute_presence(data, average=False, output='ratio'):
120120
return presence
121121

122122

123+
def compute_arr_desc(data):
124+
"""Compute descriptive measures of an array of data.
125+
126+
Parameters
127+
----------
128+
data : array
129+
Array of numeric data.
130+
131+
Returns
132+
-------
133+
min_val : float
134+
Minimum value of the array.
135+
max_val : float
136+
Maximum value of the array.
137+
mean_val : float
138+
Mean value of the array.
139+
"""
140+
141+
min_val = np.nanmin(data)
142+
max_val = np.nanmax(data)
143+
mean_val = np.nanmean(data)
144+
145+
return min_val, max_val, mean_val
146+
147+
123148
def trim_spectrum(freqs, power_spectra, f_range):
124149
"""Extract a frequency range from power spectra.
125150

0 commit comments

Comments
 (0)