Skip to content

Commit

Permalink
commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
nkinsky committed Apr 5, 2024
1 parent 2b089b3 commit b91dd1a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions neuropy/analyses/oscillations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _detect_freq_band_epochs(
low and high threshold for detection
mindur : float, optional
minimum duration of epoch
maxdur : float, optiona
maxdur : float, optional
chans : list
channels used for epoch detection, if None then chooses best chans
"""
Expand All @@ -41,16 +41,19 @@ def _detect_freq_band_epochs(
# Because here one shank is selected per shank, based on visualization:
# mean: very conservative in cases where some shanks may not have that strong ripple
# max: works well but may have ocassional false positives

# First, bandpass the signal in the range of interest
power = np.zeros(signals.shape[1])
for sig in signals:
yf = signal_process.filter_sig.bandpass(sig, lf=lf, hf=hf, fs=fs)
# zsc_chan = smooth(stats.zscore(np.abs(signal_process.hilbertfast(yf))))
# zscsignal[sig_i] = zsc_chan
power += np.abs(signal_process.hilbertfast(yf))

# mean and smooth
# Second, take the mean and smooth the signal with a sigma wide gaussian kernel
power = smooth(power / signals.shape[0])

# Third, exclude any noisy periods due to motion or other artifact
# ---------setting noisy periods zero --------
if ignore_times is not None:
assert ignore_times.ndim == 2, "ignore_times should be 2 dimensional array"
Expand All @@ -65,16 +68,20 @@ def _detect_freq_band_epochs(
noisy_frames = noisy_frames[noisy_frames < len(power)]
power[noisy_frames] = 0

# Fourth, identify candidate epochs above edge_cutoff threshold
# ---- thresholding and detection ------
power = stats.zscore(power)
power_thresh = np.where(power >= edge_cutoff, power, 0)

# Fifth, refine candidate epochs to periods between lowthresh and highthresh
peaks, props = sg.find_peaks(
power_thresh, height=[lowthresh, highthresh], prominence=0
)
starts, stops = props["left_bases"], props["right_bases"]
peaks_power = power_thresh[peaks]

# ----- merge overlapping epochs ------
# Last, merge any epochs that overlap into one longer epoch
n_epochs = len(starts)
ind_delete = []
for i in range(n_epochs - 1):
Expand Down

0 comments on commit b91dd1a

Please sign in to comment.