Skip to content

Commit 0858a6c

Browse files
committed
refactor compute_presence
1 parent 21a1848 commit 0858a6c

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

specparam/core/strings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from specparam.core.errors import NoModelError
66
from specparam.data.utils import get_periodic_labels
7+
from specparam.utils.data import compute_presence
78
from specparam.version import __version__ as MODULE_VERSION
89

910
###################################################################################################

specparam/utils/data.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,11 @@ def compute_presence(data, average=False, output='ratio'):
108108

109109
assert output in ['ratio', 'percent'], 'Setting for output type not understood.'
110110

111-
if data.ndim == 1:
112-
presence = sum(~np.isnan(data)) / len(data)
111+
if data.ndim == 1 or average:
112+
presence = np.sum(~np.isnan(data)) / data.size
113113

114114
elif data.ndim == 2:
115-
if average:
116-
presence = compute_presence(data.flatten())
117-
else:
118-
n_events, n_windows = data.shape
119-
presence = np.sum(~np.isnan(data), 0) / (np.ones(n_windows) * n_events)
115+
presence = np.sum(~np.isnan(data), 0) / (np.ones(data.shape[1]) * data.shape[0])
120116

121117
if output == 'percent':
122118
presence *= 100

0 commit comments

Comments
 (0)