Skip to content

Commit

Permalink
refactor compute_presence
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Mar 26, 2024
1 parent 21a1848 commit 0858a6c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
1 change: 1 addition & 0 deletions specparam/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from specparam.core.errors import NoModelError
from specparam.data.utils import get_periodic_labels
from specparam.utils.data import compute_presence
from specparam.version import __version__ as MODULE_VERSION

###################################################################################################
Expand Down
10 changes: 3 additions & 7 deletions specparam/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,11 @@ def compute_presence(data, average=False, output='ratio'):

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

if data.ndim == 1:
presence = sum(~np.isnan(data)) / len(data)
if data.ndim == 1 or average:
presence = np.sum(~np.isnan(data)) / data.size

elif data.ndim == 2:
if average:
presence = compute_presence(data.flatten())
else:
n_events, n_windows = data.shape
presence = np.sum(~np.isnan(data), 0) / (np.ones(n_windows) * n_events)
presence = np.sum(~np.isnan(data), 0) / (np.ones(data.shape[1]) * data.shape[0])

if output == 'percent':
presence *= 100
Expand Down

0 comments on commit 0858a6c

Please sign in to comment.