From 5763e807d0c44e4d1e9ee6eee519da24a64d6cbb Mon Sep 17 00:00:00 2001 From: weygoldt <88969563+weygoldt@users.noreply.github.com> Date: Tue, 24 Jan 2023 11:43:10 +0100 Subject: [PATCH] better chirpdetector --- code/chirpdetection.py | 18 +++++------ code/chirpdetector_conf.yml | 64 +++++++++++++++++-------------------- code/extract_chirps.py | 4 +-- 3 files changed, 40 insertions(+), 46 deletions(-) diff --git a/code/chirpdetection.py b/code/chirpdetection.py index 415da4a..39db060 100755 --- a/code/chirpdetection.py +++ b/code/chirpdetection.py @@ -886,25 +886,25 @@ def chirpdetection(datapath: str, plot: str, debug: str = 'false') -> None: # normalize all three feature arrays to the same range to make # peak detection simpler - baseline_envelope = minmaxnorm([baseline_envelope])[0] - search_envelope = minmaxnorm([search_envelope])[0] - baseline_frequency_filtered = minmaxnorm( - [baseline_frequency_filtered] - )[0] + # baseline_envelope = minmaxnorm([baseline_envelope])[0] + # search_envelope = minmaxnorm([search_envelope])[0] + # baseline_frequency_filtered = minmaxnorm( + # [baseline_frequency_filtered] + # )[0] # PEAK DETECTION ---------------------------------------------- # detect peaks baseline_enelope baseline_peak_indices, _ = find_peaks( - baseline_envelope, prominence=config.prominence + baseline_envelope, prominence=config.baseline_prominence ) # detect peaks search_envelope search_peak_indices, _ = find_peaks( - search_envelope, prominence=config.prominence + search_envelope, prominence=config.search_prominence ) # detect peaks inst_freq_filtered frequency_peak_indices, _ = find_peaks( - baseline_frequency_filtered, prominence=config.prominence + baseline_frequency_filtered, prominence=config.frequency_prominence ) # DETECT CHIRPS IN SEARCH WINDOW ------------------------------ @@ -1097,4 +1097,4 @@ if __name__ == "__main__": 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/chirpdetection/GP2023_chirp_detection/data/mount_data/2020-03-13-10_00/" - chirpdetection(datapath, plot="show", debug="fish") + chirpdetection(datapath, plot="show", debug="false") diff --git a/code/chirpdetector_conf.yml b/code/chirpdetector_conf.yml index 4bc7d63..058448d 100755 --- a/code/chirpdetector_conf.yml +++ b/code/chirpdetector_conf.yml @@ -1,47 +1,41 @@ -# directory setup -dataroot: "../data/" -outputdir: "../output/" +# Path setup ------------------------------------------------------------------ -# Duration and overlap of the analysis window in seconds -window: 5 -overlap: 1 -edge: 0.25 +dataroot: "../data/" # path to data +outputdir: "../output/" # path to save plots to -# Number of electrodes to go over -number_electrodes: 3 -minimum_electrodes: 2 +# Rolling window parameters --------------------------------------------------- -# Search window bandwidth and minimal baseline bandwidth -minimal_bandwidth: 20 +window: 5 # rolling window length in seconds +overlap: 1 # window overlap in seconds +edge: 0.25 # window edge cufoffs to mitigate filter edge effects -# Instantaneous frequency smoothing usint a gaussian kernel of this width -baseline_frequency_smoothing: 5 +# Electrode iteration parameters ---------------------------------------------- -# Baseline processing parameters -baseline_envelope_cutoff: 25 -baseline_envelope_bandpass_lowf: 2 -baseline_envelope_bandpass_highf: 100 -# baseline_envelope_envelope_cutoff: 4 +number_electrodes: 2 # number of electrodes to go over +minimum_electrodes: 1 # mimumun number of electrodes a chirp must be on -# search envelope processing parameters -search_envelope_cutoff: 10 +# Feature extraction parameters ----------------------------------------------- -# Instantaneous frequency bandpass filter cutoff frequencies -# baseline_frequency_highpass_cutoff: 0.000005 -# baseline_frequency_envelope_cutoff: 0.000005 +search_df_lower: 20 # start searching this far above the baseline +search_df_upper: 100 # stop searching this far above the baseline +search_res: 1 # search window resolution +default_search_freq: 60 # search here if no need for a search frequency +minimal_bandwidth: 10 # minimal bandpass filter width for baseline +search_bandwidth: 10 # minimal bandpass filter width for search frequency +baseline_frequency_smoothing: 10 # instantaneous frequency smoothing -# peak detecion parameters -prominence: 0.7 +# Feature processing parameters ----------------------------------------------- -# search freq parameter -search_df_lower: 20 -search_df_upper: 100 -search_res: 1 -search_bandwidth: 20 -default_search_freq: 60 - -# Classify events as chirps if they are less than this time apart -chirp_window_threshold: 0.015 +baseline_envelope_cutoff: 25 # envelope estimation cutoff +baseline_envelope_bandpass_lowf: 2 # envelope badpass lower cutoff +baseline_envelope_bandpass_highf: 100 # envelope bandbass higher cutoff +search_envelope_cutoff: 10 # search envelope estimation cufoff +# Peak detecion parameters ---------------------------------------------------- +baseline_prominence: 0.00005 # peak prominence threshold for baseline envelope +search_prominence: 0.000004 # peak prominence threshold for search envelope +frequency_prominence: 2 # peak prominence threshold for baseline freq +# Classify events as chirps if they are less than this time apart +chirp_window_threshold: 0.02 diff --git a/code/extract_chirps.py b/code/extract_chirps.py index 4e229fa..9b32928 100644 --- a/code/extract_chirps.py +++ b/code/extract_chirps.py @@ -8,7 +8,7 @@ from IPython import embed def main(datapaths): for path in datapaths: - chirpdetection(path, plot='show', debug='electrode') + chirpdetection(path, plot='show') if __name__ == '__main__': @@ -43,6 +43,6 @@ if __name__ == '__main__': recs = pd.DataFrame(columns=['recording'], data=valid_datasets) recs.to_csv('../recs.csv', index=False) - # main(datapaths) + main(datapaths) # window 1524 + 244 in dataset index 4 is nice example