diff --git a/BBPs/2-manual_verification.py b/BBPs/2-manual_verification.py index 54134273ea6294bc27bc2dc8f24b9fa6a160f6f9..2c3da3c932e990c7b4ada38f68469ddf6e92a3a5 100644 --- a/BBPs/2-manual_verification.py +++ b/BBPs/2-manual_verification.py @@ -109,8 +109,8 @@ for file in range(len(audio_paths)): width=[0,max_length])[0] Magnitude_audio = stft(signal_high, n_fft=nfft, hop_length=hop_length) - #spectre = amplitude_to_db(np.abs(Magnitude_audio)) - spectre = pcen(np.abs(Magnitude_audio) * (2**31)) + #spectrum = amplitude_to_db(np.abs(Magnitude_audio)) + spectrum = pcen(np.abs(Magnitude_audio) * (2**31)) # show ICI of each BBP n_BBP = np.unique(BBP_all[use,-1]) @@ -143,7 +143,7 @@ for file in range(len(audio_paths)): axs[0].axis(xmin=lower, xmax=upper) axs[0].tick_params('x', labelbottom=False, bottom=False) - axs[1].imshow(spectre[::-1][:,int(lower/hop_length):int(upper/hop_length)], + axs[1].imshow(spectrum[::-1][:,int(lower/hop_length):int(upper/hop_length)], aspect='auto', interpolation='none', cmap='jet', extent=(0,(upper-lower)/sr,0,int(sr/2))) axs[1].set_title("Spectrogram (dB scale)") @@ -195,7 +195,7 @@ for file in range(len(audio_paths)): plt.close('all') del signal, signal_high, signal_peaks, tk_signal,\ - Magnitude_audio, spectre + Magnitude_audio, spectrum dict_annot[audio_paths[file]] = BBP_manual # Temp save (in case of a crash) diff --git a/Whistles/1-Identification_of_whistles.py b/Whistles/1-Identification_of_whistles.py index ec49c2dd6764976171e178859ea248bbe664ff9e..906ed0f605c6cff15c5025b70b7ea0dd93974904 100644 --- a/Whistles/1-Identification_of_whistles.py +++ b/Whistles/1-Identification_of_whistles.py @@ -71,14 +71,14 @@ for file in range(len(audio_paths)): # resample signal_dec = resample(signal, int(((stop-start)*new_sr))) - # extract spectral informations + # extract spectrum informations Magnitude_audio = stft(signal_dec, n_fft=nfft, hop_length=hop_length) - spectre = np.copy(np.abs(Magnitude_audio[f_min:,:])) - # PCEN could replace spectrogram in very noisy recordings - #spectre_pcen = pcen(np.abs(Magnitude_audio) * (2**31), bias=10)[f_min:,:] + spectrum = np.copy(np.abs(Magnitude_audio[f_min:,:])) + # PCEN could replace spectrum in very noisy recordings + #spectrum_pcen = pcen(np.abs(Magnitude_audio) * (2**31), bias=10)[f_min:,:] # Selection algorithm - max_loc_per_bin_check1 = get_local_maxima(spectre, spectre, nrg_rap)[1] + max_loc_per_bin_check1 = get_local_maxima(spectrum, spectrum, nrg_rap)[1] trajectories = get_trajectories(max_loc_per_bin_check1, dist_f=dist_f, dist_t=dist_t) final_traj = select_trajectories(trajectories, taille_traj_min, min_acce, max_acce, verbose=0) corrected_traj = sparsity_ridoff(final_traj, error_thresh=sparsity) diff --git a/Whistles/WhistleUtils.py b/Whistles/WhistleUtils.py index 33132e89f39d61b2b3f5a020a57d61ef72f2f03d..56b8271a34271d9fe9b223ae8c4ef017c5d893ba 100755 --- a/Whistles/WhistleUtils.py +++ b/Whistles/WhistleUtils.py @@ -112,11 +112,11 @@ def get_csv(csv_folder, slash="\\"): return data_frame, sorted_names #%% Trajectories algorithms -def get_local_maxima(spectrogram, spectrogram2, hardness, threshold=10e-5): +def get_local_maxima(spectrum, spectrum2, hardness, threshold=10e-5): """ Parameters ---------- - spectrogram : NUMPY ARRAY + spectrum : NUMPY ARRAY Spectrogram (float values) of an audio signal. hardness : INT or FLOAT Number of times a value has to be above the geometric mean in order to be kept. @@ -128,21 +128,21 @@ def get_local_maxima(spectrogram, spectrogram2, hardness, threshold=10e-5): local_max2 : NUMPY ARRAY Spectrogram with 1 & 0 indicating local maxima above hardness*geom_mean """ - local_max1 = np.zeros(spectrogram.shape, dtype=int) - local_max2 = np.zeros(spectrogram.shape, dtype=int) - geom_mean = gmean(gmean(spectrogram, axis=1)) - geom_mean0 = gmean(spectrogram, axis=0) - geom_mean1 = gmean(spectrogram, axis=1) - # geom_mean0, geom_mean1 = gmean(spectrogram), gmean(spectrogram) - - for each_bin in range(spectrogram.shape[1]): - for freq in range(1, spectrogram.shape[0]-1): - if (spectrogram2[freq, each_bin] > spectrogram2[freq-1, each_bin]) and \ - (spectrogram2[freq, each_bin] > spectrogram2[freq+1, each_bin]): + local_max1 = np.zeros(spectrum.shape, dtype=int) + local_max2 = np.zeros(spectrum.shape, dtype=int) + geom_mean = gmean(gmean(spectrum, axis=1)) + geom_mean0 = gmean(spectrum, axis=0) + geom_mean1 = gmean(spectrum, axis=1) + # geom_mean0, geom_mean1 = gmean(spectrum), gmean(spectrum) + + for each_bin in range(spectrum.shape[1]): + for freq in range(1, spectrum.shape[0]-1): + if (spectrum1[freq, each_bin] > spectrum2[freq-1, each_bin]) and \ + (spectrum2[freq, each_bin] > spectrum2[freq+1, each_bin]): local_max1[freq, each_bin] = 1 - if (spectrogram[freq, each_bin] > (threshold)): - if (spectrogram[freq, each_bin] > (geom_mean0[each_bin]*hardness)): - if (spectrogram[freq, each_bin] > (geom_mean1[freq]*hardness)): + if (spectrum[freq, each_bin] > (threshold)): + if (spectrum[freq, each_bin] > (geom_mean0[each_bin]*hardness)): + if (spectrum[freq, each_bin] > (geom_mean1[freq]*hardness)): local_max2[freq, each_bin] = 1 return local_max1, local_max2