Skip to content

Commit

Permalink
Updated code to use already calculated ets of surrogates to avoid dup…
Browse files Browse the repository at this point in the history
…licating code.
  • Loading branch information
eurunuela committed Dec 2, 2021
1 parent f4f1534 commit 875c96b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion connPFM/connectivity/connectivity_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def rss_surr(z_ts, u, v, surrprefix, sursufix, masker, irand):
# calcuate rss
rssr = np.sqrt(np.sum(np.square(etsr), axis=1))

return (rssr, np.min(etsr), np.max(etsr))
return (rssr, etsr, np.min(etsr), np.max(etsr))


def remove_neighboring_peaks(rss, idx):
Expand Down
19 changes: 4 additions & 15 deletions connPFM/connectivity/ev.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def event_detection(

hist_ranges = np.zeros((2, nsur))
for irand in range(nsur):
hist_ranges[0, irand] = surrogate_events[irand][1]
hist_ranges[1, irand] = surrogate_events[irand][2]
hist_ranges[0, irand] = surrogate_events[irand][2]
hist_ranges[1, irand] = surrogate_events[irand][3]

hist_min = np.min(hist_ranges, axis=1)[0]
hist_max = np.max(hist_ranges, axis=1)[1]
Expand Down Expand Up @@ -126,24 +126,13 @@ def event_detection(
# Initialize array for threshold
thr = np.zeros(t)

# Calculate ETS matrix of each surrogate
sur_ets = Parallel(n_jobs=-1, backend="multiprocessing")(
delayed(connectivity_utils.calculate_surrogate_ets)(
surrprefix,
sursufix,
irand,
masker,
)
for irand in range(nsur)
)

# initialize array for surrogate ets at each time point
sur_ets_at_time = np.zeros((nsur, sur_ets[0].shape[1]))
sur_ets_at_time = np.zeros((nsur, surrogate_events[0][1].shape[1]))

for time_idx in range(t):
# get first column of all sur_ets into a matrix
for sur_idx in range(nsur):
sur_ets_at_time[sur_idx, :] = sur_ets[sur_idx][time_idx, :]
sur_ets_at_time[sur_idx, :] = surrogate_events[sur_idx][1][time_idx, :]

# calculate histogram of all surrogate ets at time point
hist, bins = np.histogram(
Expand Down

0 comments on commit 875c96b

Please sign in to comment.