cleaned up a bit
This commit is contained in:
parent
12d1c3c1af
commit
b41e03c681
@ -138,7 +138,6 @@ def double_bandpass(
|
|||||||
def main(datapath: str) -> None:
|
def main(datapath: str) -> None:
|
||||||
|
|
||||||
# load raw file
|
# load raw file
|
||||||
file = os.path.join(datapath, "traces-grid1.raw")
|
|
||||||
data = LoadData(datapath)
|
data = LoadData(datapath)
|
||||||
|
|
||||||
# ititialize data collection
|
# ititialize data collection
|
||||||
@ -223,11 +222,10 @@ def main(datapath: str) -> None:
|
|||||||
|
|
||||||
print(f"Track ID: {track_id}")
|
print(f"Track ID: {track_id}")
|
||||||
|
|
||||||
|
|
||||||
# get index of track data in this time window
|
# get index of track data in this time window
|
||||||
window_index = np.arange(len(data.idx))[
|
window_index = np.arange(len(data.idx))[
|
||||||
(data.ident == track_id) & (data.time[data.idx] >= t0) & (
|
(data.ident == track_id) & (data.time[data.idx] >= t0) & (
|
||||||
data.time[data.idx] <= (t0 + dt))
|
data.time[data.idx] <= (t0 + dt))
|
||||||
]
|
]
|
||||||
|
|
||||||
# get tracked frequencies and their times
|
# get tracked frequencies and their times
|
||||||
@ -257,8 +255,9 @@ def main(datapath: str) -> None:
|
|||||||
powers_temp, axis=0))[-config.electrodes:]
|
powers_temp, axis=0))[-config.electrodes:]
|
||||||
|
|
||||||
# frequency where second filter filters
|
# frequency where second filter filters
|
||||||
search_window = np.arange(np.median(freq_temp)+config.search_df_lower, np.median(
|
search_window = np.arange(
|
||||||
freq_temp)+config.search_df_upper, config.search_res)
|
np.median(freq_temp)+config.search_df_lower, np.median(
|
||||||
|
freq_temp)+config.search_df_upper, config.search_res)
|
||||||
|
|
||||||
# search window in boolean
|
# search window in boolean
|
||||||
search_window_bool = np.ones(len(search_window), dtype=bool)
|
search_window_bool = np.ones(len(search_window), dtype=bool)
|
||||||
@ -273,7 +272,9 @@ def main(datapath: str) -> None:
|
|||||||
for j, check_track_id in enumerate(check_track_ids):
|
for j, check_track_id in enumerate(check_track_ids):
|
||||||
|
|
||||||
q1, q2 = np.percentile(
|
q1, q2 = np.percentile(
|
||||||
data.freq[data.ident == check_track_id], config.search_freq_percentiles)
|
data.freq[data.ident == check_track_id],
|
||||||
|
config.search_freq_percentiles
|
||||||
|
)
|
||||||
|
|
||||||
search_window_bool[(search_window > q1) & (
|
search_window_bool[(search_window > q1) & (
|
||||||
search_window < q2)] = False
|
search_window < q2)] = False
|
||||||
@ -296,7 +297,9 @@ def main(datapath: str) -> None:
|
|||||||
# if the last value is -1, the array ends with true, so a gap
|
# if the last value is -1, the array ends with true, so a gap
|
||||||
if nonzeros[-1] == 1:
|
if nonzeros[-1] == 1:
|
||||||
stops = np.append(
|
stops = np.append(
|
||||||
search_window_indices[search_window_gaps == -1], len(search_window) - 1)
|
search_window_indices[search_window_gaps == -1],
|
||||||
|
len(search_window) - 1
|
||||||
|
)
|
||||||
|
|
||||||
# else it starts with false, so no gap
|
# else it starts with false, so no gap
|
||||||
if nonzeros[0] == 1:
|
if nonzeros[0] == 1:
|
||||||
@ -306,7 +309,9 @@ def main(datapath: str) -> None:
|
|||||||
# if the last value is -1, the array ends with true, so a gap
|
# if the last value is -1, the array ends with true, so a gap
|
||||||
if nonzeros[-1] == 1:
|
if nonzeros[-1] == 1:
|
||||||
stops = np.append(
|
stops = np.append(
|
||||||
search_window_indices[search_window_gaps == -1], len(search_window))
|
search_window_indices[search_window_gaps == -1],
|
||||||
|
len(search_window)
|
||||||
|
)
|
||||||
|
|
||||||
# get the frequency ranges of the gaps
|
# get the frequency ranges of the gaps
|
||||||
search_windows = [search_window[x:y]
|
search_windows = [search_window[x:y]
|
||||||
@ -339,7 +344,10 @@ def main(datapath: str) -> None:
|
|||||||
|
|
||||||
# filter baseline and above
|
# filter baseline and above
|
||||||
baseline, search = double_bandpass(
|
baseline, search = double_bandpass(
|
||||||
data_oi[:, electrode], data.raw_rate, freq_temp, search_freq
|
data_oi[:, electrode],
|
||||||
|
data.raw_rate,
|
||||||
|
freq_temp,
|
||||||
|
search_freq
|
||||||
)
|
)
|
||||||
|
|
||||||
# compute instantaneous frequency on broad signal
|
# compute instantaneous frequency on broad signal
|
||||||
@ -399,14 +407,20 @@ def main(datapath: str) -> None:
|
|||||||
valid_t1 = baseline_freq_time[-1] - \
|
valid_t1 = baseline_freq_time[-1] - \
|
||||||
(int(window_edge) / data.raw_rate)
|
(int(window_edge) / data.raw_rate)
|
||||||
|
|
||||||
inst_freq_filtered = inst_freq_filtered[(baseline_freq_time >= valid_t0) & (
|
inst_freq_filtered = inst_freq_filtered[
|
||||||
baseline_freq_time <= valid_t1)]
|
(baseline_freq_time >= valid_t0) & (
|
||||||
|
baseline_freq_time <= valid_t1)
|
||||||
|
]
|
||||||
|
|
||||||
baseline_freq = baseline_freq[(baseline_freq_time >= valid_t0) & (
|
baseline_freq = baseline_freq[
|
||||||
baseline_freq_time <= valid_t1)]
|
(baseline_freq_time >= valid_t0) & (
|
||||||
|
baseline_freq_time <= valid_t1)
|
||||||
|
]
|
||||||
|
|
||||||
baseline_freq_time = baseline_freq_time[(baseline_freq_time >= valid_t0) & (
|
baseline_freq_time = baseline_freq_time[
|
||||||
baseline_freq_time <= valid_t1)] + t0
|
(baseline_freq_time >= valid_t0) & (
|
||||||
|
baseline_freq_time <= valid_t1)
|
||||||
|
] + t0
|
||||||
|
|
||||||
# overwrite raw time to valid region
|
# overwrite raw time to valid region
|
||||||
time_oi = time_oi[valid]
|
time_oi = time_oi[valid]
|
||||||
@ -436,18 +450,23 @@ def main(datapath: str) -> None:
|
|||||||
|
|
||||||
# detect peaks inst_freq_filtered
|
# detect peaks inst_freq_filtered
|
||||||
prominence = np.percentile(
|
prominence = np.percentile(
|
||||||
inst_freq_filtered, config.instantaneous_prominence_percentile)
|
inst_freq_filtered,
|
||||||
|
config.instantaneous_prominence_percentile
|
||||||
|
)
|
||||||
inst_freq_peaks, _ = find_peaks(
|
inst_freq_peaks, _ = find_peaks(
|
||||||
np.abs(inst_freq_filtered), prominence=prominence)
|
np.abs(inst_freq_filtered),
|
||||||
|
prominence=prominence
|
||||||
|
)
|
||||||
|
|
||||||
# SAVE DATA ----------------------------------------------------
|
# SAVE DATA ---------------------------------------------------
|
||||||
|
|
||||||
baseline_ts_subsub.append(time_oi[baseline_peaks].tolist())
|
baseline_ts_subsub.append(time_oi[baseline_peaks].tolist())
|
||||||
search_ts_subsub.append(time_oi[search_peaks].tolist())
|
search_ts_subsub.append(time_oi[search_peaks].tolist())
|
||||||
freq_ts_subsub.append(baseline_freq_time[inst_freq_peaks].tolist())
|
freq_ts_subsub.append(
|
||||||
|
baseline_freq_time[inst_freq_peaks].tolist())
|
||||||
electrodes_subsub.append(electrode)
|
electrodes_subsub.append(electrode)
|
||||||
|
|
||||||
# PLOT ------------------------------------------------------------
|
# PLOT --------------------------------------------------------
|
||||||
|
|
||||||
# plot spectrogram
|
# plot spectrogram
|
||||||
plot_spectrogram(
|
plot_spectrogram(
|
||||||
@ -531,11 +550,11 @@ def main(datapath: str) -> None:
|
|||||||
fish_ids.append(fish_ids_sub)
|
fish_ids.append(fish_ids_sub)
|
||||||
electrodes.append(electrodes_sub)
|
electrodes.append(electrodes_sub)
|
||||||
|
|
||||||
|
# reorder this mess of nested lists to make it understandable
|
||||||
|
num_snippets = len(window_starts)
|
||||||
embed()
|
embed()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
datapath = "../data/2022-06-02-10_00/"
|
datapath = "../data/2022-06-02-10_00/"
|
||||||
main(datapath)
|
main(datapath)
|
||||||
|
Loading…
Reference in New Issue
Block a user