chatgpt alternative functions tested
This commit is contained in:
commit
5dc98d6163
@ -1,4 +1,4 @@
|
||||
import os
|
||||
import itertools
|
||||
|
||||
import numpy as np
|
||||
from IPython import embed
|
||||
@ -12,7 +12,7 @@ from sklearn.preprocessing import normalize
|
||||
from modules.filters import bandpass_filter, envelope, highpass_filter
|
||||
from modules.filehandling import ConfLoader, LoadData
|
||||
from modules.plotstyle import PlotStyle
|
||||
from modules.timestamps import group_timestamps, group_timestamp_v2
|
||||
from modules.timestamps import group_timestamps, group_timestamps_v2
|
||||
|
||||
ps = PlotStyle()
|
||||
|
||||
@ -517,6 +517,7 @@ def main(datapath: str) -> None:
|
||||
axs[6, el].set_title(
|
||||
"Filtered absolute instantaneous frequency")
|
||||
|
||||
|
||||
# DETECT CHIRPS IN SEARCH WINDOW -------------------------------
|
||||
|
||||
baseline_ts = time_oi[baseline_peaks]
|
||||
@ -527,6 +528,10 @@ def main(datapath: str) -> None:
|
||||
if len(baseline_ts) == 0 or len(search_ts) == 0 or len(freq_ts) == 0:
|
||||
continue
|
||||
|
||||
#current_chirps = group_timestamps_v2(
|
||||
# [list(baseline_ts), list(search_ts), list(freq_ts)], 3)
|
||||
|
||||
|
||||
# get index for each feature
|
||||
baseline_idx = np.zeros_like(baseline_ts)
|
||||
search_idx = np.ones_like(search_ts)
|
||||
@ -562,8 +567,10 @@ def main(datapath: str) -> None:
|
||||
bool_timestamps[cm] = False
|
||||
|
||||
# for checking if there are chirps on multiple electrodes
|
||||
|
||||
chirps_electrodes.append(current_chirps)
|
||||
|
||||
|
||||
for ct in current_chirps:
|
||||
axs[0, el].axvline(ct, color='r', lw=1)
|
||||
|
||||
@ -583,6 +590,7 @@ def main(datapath: str) -> None:
|
||||
np.ones_like((time_oi)[baseline_peaks]) * 600,
|
||||
c=ps.red,
|
||||
)
|
||||
|
||||
# make one array
|
||||
chirps_electrodes = np.concatenate(chirps_electrodes)
|
||||
|
||||
@ -597,33 +605,51 @@ def main(datapath: str) -> None:
|
||||
bool_vector = np.ones(len(sort_chirps_electrodes), dtype=bool)
|
||||
# make index vector
|
||||
index_vector = np.arange(len(sort_chirps_electrodes))
|
||||
# make it more than only two electrodes for the search after chirps
|
||||
combinations_best_elctrodes = list(
|
||||
itertools.combinations(range(3), 2))
|
||||
|
||||
the_real_chirps = []
|
||||
for chirp_index, seoc in enumerate(sort_chirps_electrodes):
|
||||
if bool_vector[chirp_index] == False:
|
||||
continue
|
||||
else:
|
||||
cm = index_vector[(sort_chirps_electrodes >= seoc) & (
|
||||
sort_chirps_electrodes <= seoc + config.chirp_window_threshold)]
|
||||
|
||||
|
||||
chirps_unique = []
|
||||
for combination in combinations_best_elctrodes:
|
||||
if set(combination).issubset(sort_electrodes[cm]):
|
||||
chirps_unique.append(np.mean(sort_chirps_electrodes[cm]))
|
||||
|
||||
the_real_chirps.append(np.mean(chirps_unique))
|
||||
|
||||
|
||||
"""
|
||||
if set([0,1]).issubset(sort_electrodes[cm]):
|
||||
the_real_chirps.append(
|
||||
np.mean(sort_chirps_electrodes[cm]))
|
||||
the_real_chirps.append(np.mean(sort_chirps_electrodes[cm]))
|
||||
elif set([1,0]).issubset(sort_electrodes[cm]):
|
||||
the_real_chirps.append(
|
||||
np.mean(sort_chirps_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]))
|
||||
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]))
|
||||
|
||||
the_real_chirps.append(np.mean(sort_chirps_electrodes[cm]))
|
||||
"""
|
||||
bool_vector[cm] = False
|
||||
chirps.append(the_real_chirps)
|
||||
|
||||
for ct in the_real_chirps:
|
||||
axs[0, el].axvline(ct, color='b', lw=1)
|
||||
|
||||
embed()
|
||||
plt.show()
|
||||
fig, ax = plt.subplots()
|
||||
t0 = (3 * 60 * 60 + 6 * 60 + 43.5)
|
||||
data_oi = data.raw[window_starts[0]:window_starts[-1]+ int(dt*data.raw_rate), 10]
|
||||
plot_spectrogram(ax, data_oi, data.raw_rate, t0)
|
||||
for ch in chirps:
|
||||
ax. axvline(ch, color='b', lw=1)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -72,7 +72,37 @@ def group_timestamps(sublists: List[List[float]], n: int, threshold: float) -> L
|
||||
timestamps.sort()
|
||||
|
||||
groups = []
|
||||
<<<<<<< HEAD
|
||||
current_group = [timestamps[0]]
|
||||
=======
|
||||
# Create a variable to store the current group of timestamps
|
||||
current_group = []
|
||||
# Create a set to store the timestamps that occur in at least n of the sublists
|
||||
common_timestamps = set.intersection(*[set(lst) for lst in sublists])
|
||||
# convert the set to a list
|
||||
common_timestamps = list(common_timestamps)
|
||||
# Iterate through the timestamps
|
||||
for i in range(len(common_timestamps)):
|
||||
# If the current timestamp is less than 50 milliseconds away from the previous timestamp
|
||||
if i > 0 and common_timestamps[i] - common_timestamps[i-1] < time_threshold:
|
||||
# Add the current timestamp to the current group
|
||||
current_group.append(common_timestamps[i])
|
||||
else:
|
||||
# If the current timestamp is not part of the current group
|
||||
if current_group:
|
||||
# Add the current group to the list of groups
|
||||
groups.append(current_group)
|
||||
# Reset the current group
|
||||
current_group = []
|
||||
# Add the current timestamp to a new group
|
||||
current_group.append(common_timestamps[i])
|
||||
# If there is a group left after the loop
|
||||
if current_group:
|
||||
# Add the current group to the list of groups
|
||||
groups.append(current_group)
|
||||
# Compute the mean of each group and return it
|
||||
return [np.mean(group) for group in groups]
|
||||
>>>>>>> ef61cec6958a71f2b0a513fc073e1c9427a0171b
|
||||
|
||||
for i in range(1, len(timestamps)):
|
||||
if timestamps[i] - timestamps[i-1] < threshold:
|
||||
|
Loading…
Reference in New Issue
Block a user