Skip to content

Commit 555b4e2

Browse files
authored
Merge pull request #64 from eurunuela/fix/time-locked
Fix time-locked ETS thresholding bug
2 parents 261f172 + f2d3ee2 commit 555b4e2

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

connPFM/connectivity/connectivity_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ def calculate_hist(
130130

131131
def calculate_hist_threshold(hist, bins, percentile=95):
132132
"""Calculate histogram threshold."""
133-
ets_hist_sum = np.sum(hist, axis=0)
134-
cumsum_percentile = np.cumsum(ets_hist_sum) / np.sum(ets_hist_sum) * 100
133+
cumsum_percentile = np.cumsum(hist) / np.sum(hist) * 100
135134
thr = bins[len(cumsum_percentile[cumsum_percentile <= percentile])]
136135

137136
return thr
@@ -163,7 +162,9 @@ def surrogates_histogram(
163162

164163
bin_edges = hist[0][1]
165164

165+
ets_hist_sum = np.sum(ets_hist, axis=0)
166+
166167
# calculate histogram threshold
167-
thr = calculate_hist_threshold(ets_hist, bin_edges, percentile)
168+
thr = calculate_hist_threshold(ets_hist_sum, bin_edges, percentile)
168169

169170
return thr

connPFM/connectivity/ev.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ def event_detection(
108108
idxpeak = idx
109109

110110
# get co-fluctuation at peaks
111-
etspeaks = connectivity_utils.threshold_ets_matrix(ets, thr=0, selected_idxs=idxpeak)
111+
etspeaks = connectivity_utils.threshold_ets_matrix(
112+
ets.copy(), thr=0, selected_idxs=idxpeak
113+
)
112114

113115
# Make selection of points with edge time-series matrix
114116
elif "ets" in peak_detection:
@@ -145,7 +147,7 @@ def event_detection(
145147
)
146148

147149
# Apply threshold on edge time-series matrix
148-
etspeaks = connectivity_utils.threshold_ets_matrix(ets, thr)
150+
etspeaks = connectivity_utils.threshold_ets_matrix(ets.copy(), thr)
149151
idxpeak = np.where(etspeaks != 0)[0]
150152
rss = np.sqrt(np.sum(np.square(etspeaks), axis=1))
151153
# calculate mean co-fluctuation (edge time series) across all peaks

0 commit comments

Comments
 (0)