all broken
This commit is contained in:
parent
369f26123a
commit
a3ddd49040
@ -130,7 +130,7 @@ class PlotBuffer:
|
|||||||
data_oi,
|
data_oi,
|
||||||
self.data.raw_rate,
|
self.data.raw_rate,
|
||||||
self.t0 - 5,
|
self.t0 - 5,
|
||||||
[np.max(self.frequency) - 200, np.max(self.frequency) + 200]
|
[np.min(self.frequency) - 200, np.max(self.frequency) + 200]
|
||||||
)
|
)
|
||||||
|
|
||||||
for track_id in self.data.ids:
|
for track_id in self.data.ids:
|
||||||
@ -145,14 +145,15 @@ class PlotBuffer:
|
|||||||
|
|
||||||
# get tracked frequencies and their times
|
# get tracked frequencies and their times
|
||||||
f = self.data.freq[window_idx]
|
f = self.data.freq[window_idx]
|
||||||
t = self.data.time[
|
# t = self.data.time[
|
||||||
self.data.idx[self.data.ident == self.track_id]]
|
# self.data.idx[self.data.ident == self.track_id]]
|
||||||
tmask = (t >= t0_track) & (t <= (t0_track + dt_track))
|
# tmask = (t >= t0_track) & (t <= (t0_track + dt_track))
|
||||||
|
t = self.data.time[self.data.idx[window_idx]]
|
||||||
if track_id == self.track_id:
|
if track_id == self.track_id:
|
||||||
ax0.plot(t[tmask]-self.t0_old, f, lw=lw,
|
ax0.plot(t-self.t0_old, f, lw=lw,
|
||||||
zorder=10, color=ps.gblue1)
|
zorder=10, color=ps.gblue1)
|
||||||
else:
|
else:
|
||||||
ax0.plot(t[tmask]-self.t0_old, f, lw=lw,
|
ax0.plot(t-self.t0_old, f, lw=lw,
|
||||||
zorder=10, color=ps.gray, alpha=0.5)
|
zorder=10, color=ps.gray, alpha=0.5)
|
||||||
|
|
||||||
ax0.fill_between(
|
ax0.fill_between(
|
||||||
@ -472,7 +473,9 @@ def find_searchband(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# search window in boolean
|
# search window in boolean
|
||||||
search_window_bool = np.ones_like(len(search_window), dtype=bool)
|
bool_lower = np.ones_like(search_window, dtype=bool)
|
||||||
|
bool_upper = np.ones_like(search_window, dtype=bool)
|
||||||
|
search_window_bool = np.ones_like(search_window, dtype=bool)
|
||||||
|
|
||||||
# make seperate arrays from the qartiles
|
# make seperate arrays from the qartiles
|
||||||
q25 = np.asarray([i[0] for i in frequency_percentiles])
|
q25 = np.asarray([i[0] for i in frequency_percentiles])
|
||||||
@ -492,11 +495,10 @@ def find_searchband(
|
|||||||
q25_temp = q25[percentiles_ids == check_track_id]
|
q25_temp = q25[percentiles_ids == check_track_id]
|
||||||
q75_temp = q75[percentiles_ids == check_track_id]
|
q75_temp = q75[percentiles_ids == check_track_id]
|
||||||
|
|
||||||
print(q25_temp, q75_temp)
|
bool_lower[search_window > q25_temp - config.search_res] = False
|
||||||
|
bool_upper[search_window < q75_temp + config.search_res] = False
|
||||||
search_window_bool[
|
search_window_bool[(bool_lower == False) &
|
||||||
(search_window > q25_temp) & (search_window < q75_temp)
|
(bool_upper == False)] = False
|
||||||
] = False
|
|
||||||
|
|
||||||
# find gaps in search window
|
# find gaps in search window
|
||||||
search_window_indices = np.arange(len(search_window))
|
search_window_indices = np.arange(len(search_window))
|
||||||
@ -552,7 +554,7 @@ def find_searchband(
|
|||||||
return config.default_search_freq
|
return config.default_search_freq
|
||||||
|
|
||||||
|
|
||||||
def main(datapath: str, plot: str) -> None:
|
def chirpdetection(datapath: str, plot: str) -> None:
|
||||||
|
|
||||||
assert plot in [
|
assert plot in [
|
||||||
"save",
|
"save",
|
||||||
@ -561,6 +563,7 @@ def main(datapath: str, plot: str) -> None:
|
|||||||
], "plot must be 'save', 'show' or 'false'"
|
], "plot must be 'save', 'show' or 'false'"
|
||||||
|
|
||||||
# load raw file
|
# load raw file
|
||||||
|
print('datapath', datapath)
|
||||||
data = LoadData(datapath)
|
data = LoadData(datapath)
|
||||||
|
|
||||||
# load config file
|
# load config file
|
||||||
@ -589,8 +592,8 @@ def main(datapath: str, plot: str) -> None:
|
|||||||
raw_time = np.arange(data.raw.shape[0]) / data.raw_rate
|
raw_time = np.arange(data.raw.shape[0]) / data.raw_rate
|
||||||
|
|
||||||
# good chirp times for data: 2022-06-02-10_00
|
# good chirp times for data: 2022-06-02-10_00
|
||||||
# window_start_index = (3 * 60 * 60 + 6 * 60 + 43.5 + 5) * data.raw_rate
|
window_start_index = (3 * 60 * 60 + 6 * 60 + 43.5 + 5) * data.raw_rate
|
||||||
# window_duration_index = 60 * data.raw_rate
|
window_duration_index = 60 * data.raw_rate
|
||||||
|
|
||||||
# t0 = 0
|
# t0 = 0
|
||||||
# dt = data.raw.shape[0]
|
# dt = data.raw.shape[0]
|
||||||
@ -651,14 +654,14 @@ def main(datapath: str, plot: str) -> None:
|
|||||||
# approximate sampling rate to compute expected durations if there
|
# approximate sampling rate to compute expected durations if there
|
||||||
# is data available for this time window for this fish id
|
# is data available for this time window for this fish id
|
||||||
|
|
||||||
track_samplerate = np.mean(1 / np.diff(data.time))
|
# track_samplerate = np.mean(1 / np.diff(data.time))
|
||||||
expected_duration = (
|
# expected_duration = (
|
||||||
(window_start_seconds + window_duration_seconds)
|
# (window_start_seconds + window_duration_seconds)
|
||||||
- window_start_seconds
|
# - window_start_seconds
|
||||||
) * track_samplerate
|
# ) * track_samplerate
|
||||||
|
|
||||||
# check if tracked data available in this window
|
# check if tracked data available in this window
|
||||||
if len(current_frequencies) < expected_duration / 2:
|
if len(current_frequencies) < 3:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Track {track_id} has no data in window {st}, skipping."
|
f"Track {track_id} has no data in window {st}, skipping."
|
||||||
)
|
)
|
||||||
@ -918,11 +921,9 @@ def main(datapath: str, plot: str) -> None:
|
|||||||
multielectrode_chirps.append(singleelectrode_chirps)
|
multielectrode_chirps.append(singleelectrode_chirps)
|
||||||
|
|
||||||
# only initialize the plotting buffer if chirps are detected
|
# only initialize the plotting buffer if chirps are detected
|
||||||
chirp_detected = (
|
chirp_detected = (el == (config.number_electrodes - 1)
|
||||||
(el == config.number_electrodes - 1)
|
& (plot in ["show", "save"])
|
||||||
& (len(singleelectrode_chirps) > 0)
|
)
|
||||||
& (plot in ["show", "save"])
|
|
||||||
)
|
|
||||||
|
|
||||||
if chirp_detected:
|
if chirp_detected:
|
||||||
|
|
||||||
@ -987,11 +988,12 @@ def main(datapath: str, plot: str) -> None:
|
|||||||
# if chirps are detected and the plot flag is set, plot the
|
# if chirps are detected and the plot flag is set, plot the
|
||||||
# chirps, otheswise try to delete the buffer if it exists
|
# chirps, otheswise try to delete the buffer if it exists
|
||||||
|
|
||||||
if len(multielectrode_chirps_validated) > 0:
|
if ((len(multielectrode_chirps_validated) > 0) & (plot in ["show", "save"])):
|
||||||
try:
|
try:
|
||||||
buffer.plot_buffer(multielectrode_chirps_validated, plot)
|
buffer.plot_buffer(multielectrode_chirps_validated, plot)
|
||||||
|
del buffer
|
||||||
except NameError:
|
except NameError:
|
||||||
pass
|
embed()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
del buffer
|
del buffer
|
||||||
@ -1049,4 +1051,4 @@ if __name__ == "__main__":
|
|||||||
datapath = "../data/2022-06-02-10_00/"
|
datapath = "../data/2022-06-02-10_00/"
|
||||||
# datapath = "/home/weygoldt/Data/uni/efishdata/2016-colombia/fishgrid/2016-04-09-22_25/"
|
# datapath = "/home/weygoldt/Data/uni/efishdata/2016-colombia/fishgrid/2016-04-09-22_25/"
|
||||||
# datapath = "/home/weygoldt/Data/uni/chirpdetection/GP2023_chirp_detection/data/mount_data/2020-03-13-10_00/"
|
# datapath = "/home/weygoldt/Data/uni/chirpdetection/GP2023_chirp_detection/data/mount_data/2020-03-13-10_00/"
|
||||||
main(datapath, plot="save")
|
chirpdetection(datapath, plot="show")
|
||||||
|
@ -3,7 +3,7 @@ dataroot: "../data/"
|
|||||||
outputdir: "../output/"
|
outputdir: "../output/"
|
||||||
|
|
||||||
# Duration and overlap of the analysis window in seconds
|
# Duration and overlap of the analysis window in seconds
|
||||||
window: 10
|
window: 5
|
||||||
overlap: 1
|
overlap: 1
|
||||||
edge: 0.25
|
edge: 0.25
|
||||||
|
|
||||||
|
44
code/extract_chirps.py
Normal file
44
code/extract_chirps.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import os
|
||||||
|
import numpy as np
|
||||||
|
from chirpdetection import chirpdetection
|
||||||
|
from IPython import embed
|
||||||
|
|
||||||
|
|
||||||
|
def main(datapaths):
|
||||||
|
|
||||||
|
for path in datapaths:
|
||||||
|
chirpdetection(path, plot='show')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
dataroot = '../data/mount_data/'
|
||||||
|
|
||||||
|
datasets = sorted([name for name in os.listdir(dataroot) if os.path.isdir(
|
||||||
|
os.path.join(dataroot, name))])
|
||||||
|
|
||||||
|
valid_datasets = []
|
||||||
|
|
||||||
|
for dataset in datasets:
|
||||||
|
|
||||||
|
path = os.path.join(dataroot, dataset)
|
||||||
|
csv_name = '-'.join(dataset.split('-')[:3]) + '.csv'
|
||||||
|
|
||||||
|
if os.path.exists(os.path.join(path, csv_name)) is False:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if os.path.exists(os.path.join(path, 'ident_v.npy')) is False:
|
||||||
|
continue
|
||||||
|
|
||||||
|
ident = np.load(os.path.join(path, 'ident_v.npy'))
|
||||||
|
number_of_fish = len(np.unique(ident[~np.isnan(ident)]))
|
||||||
|
if number_of_fish != 2:
|
||||||
|
continue
|
||||||
|
|
||||||
|
valid_datasets.append(dataset)
|
||||||
|
|
||||||
|
datapaths = [os.path.join(dataroot, dataset) +
|
||||||
|
'/' for dataset in valid_datasets]
|
||||||
|
embed()
|
||||||
|
|
||||||
|
main(datapaths[3])
|
Loading…
Reference in New Issue
Block a user