adding boolien to peak detection

This commit is contained in:
wendtalexander 2023-01-17 19:00:13 +01:00
parent 2ac769da9b
commit 8138e3107f

View File

@ -318,9 +318,9 @@ def main(datapath: str) -> None:
print(f"Search frequency: {search_freq}") print(f"Search frequency: {search_freq}")
#----------- chrips on the two best electrodes----------- #----------- chrips on the two best electrodes-----------
chirps_electrodes = [] chirps_electrodes = []
electrodes_of_chirps = []
# iterate through electrodes # iterate through electrodes
for el, electrode in enumerate(best_electrodes): for el, electrode in enumerate(best_electrodes):
print(el) print(el)
@ -515,7 +515,7 @@ def main(datapath: str) -> None:
axs[5, el].set_title("Search envelope") axs[5, el].set_title("Search envelope")
axs[6, el].set_title( axs[6, el].set_title(
"Filtered absolute instantaneous frequency") "Filtered absolute instantaneous frequency")
print(el)
# DETECT CHIRPS IN SEARCH WINDOW ------------------------------- # DETECT CHIRPS IN SEARCH WINDOW -------------------------------
baseline_ts = time_oi[baseline_peaks] baseline_ts = time_oi[baseline_peaks]
@ -541,6 +541,7 @@ def main(datapath: str) -> None:
timestamps)] timestamps)]
timestamps = timestamps[np.argsort(timestamps)] timestamps = timestamps[np.argsort(timestamps)]
# # get chirps # # get chirps
# diff = np.empty(timestamps.shape) # diff = np.empty(timestamps.shape)
# diff[0] = np.inf # always retain the 1st element # diff[0] = np.inf # always retain the 1st element
@ -548,15 +549,21 @@ def main(datapath: str) -> None:
# mask = diff < config.chirp_window_threshold # mask = diff < config.chirp_window_threshold
# shared_peak_indices = timestamp_idx[mask] # shared_peak_indices = timestamp_idx[mask]
current_chirps = [] current_chirps = []
for tt in timestamps: for tt in timestamps:
cm = timestamps_idx[(timestamps >= tt) & ( cm = timestamps_idx[(timestamps >= tt) & (
timestamps <= tt + config.chirp_window_threshold)] timestamps <= tt + config.chirp_window_threshold)]
if set([0, 1, 2]).issubset(timestamps_features[cm]): if set([0, 1, 2]).issubset(timestamps_features[cm]):
chirps_electrodes.append(np.mean(timestamps[cm]))
current_chirps.append(np.mean(timestamps[cm])) current_chirps.append(np.mean(timestamps[cm]))
fish_ids.append(track_id) electrodes_of_chirps.append(el)
# for checking if there are chirps on multiple electrodes
chirps_electrodes.append(current_chirps)
for ct in current_chirps: for ct in current_chirps:
axs[0, el].axvline(ct, color='r', lw=1) axs[0, el].axvline(ct, color='r', lw=1)
@ -576,9 +583,36 @@ def main(datapath: str) -> None:
np.ones_like((time_oi)[baseline_peaks]) * 600, np.ones_like((time_oi)[baseline_peaks]) * 600,
c=ps.red, c=ps.red,
) )
# make one array
chirps_electrodes = np.concatenate(chirps_electrodes)
plt.show()
# make shure they are numpy arrays
chirps_electrodes = np.asarray(chirps_electrodes)
electrodes_of_chirps = np.asarray(electrodes_of_chirps)
# sort them
sort_chirps_electrodes = chirps_electrodes[np.argsort(chirps_electrodes)]
sort_electrodes = electrodes_of_chirps[np.argsort(chirps_electrodes)]
bool_vector = np.ones(len(sort_chirps_electrodes), dtype=bool)
the_real_chirps = []
embed()
for seoc in sort_chirps_electrodes:
cm = sort_electrodes[[(sort_chirps_electrodes >= seoc) & (
sort_chirps_electrodes <= seoc + config.chirp_window_threshold)][bool_vector]]
if set([0,1]).issubset(sort_electrodes[cm]):
the_real_chirps.append(np.mean(sort_chirps_electrodes[cm]))
elif set([0,2]).issubset(sort_electrodes[cm]):
the_real_chirps.append(np.mean(sort_chirps_electrodes[cm]))
elif set([1,2]).issubset(sort_electrodes[cm]):
the_real_chirps.append(np.mean(sort_chirps_electrodes[cm]))
bool_vector[sort_electrodes[cm]] = False
if __name__ == "__main__": if __name__ == "__main__":