Skip to content
Snippets Groups Projects
Commit 9d300058 authored by Loic-Lenof's avatar Loic-Lenof
Browse files

Small changes

- removed results and variable used during test sessions
parent 66cad036
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ print("Parameters ready to use!")
#%% Importation of ata and function
print("\rImportation of csv data", end="\r")
from FuncUtils import get_csv, get_category
from BBPUtils import get_csv, get_category
data_20_21, audio_paths = get_csv(csv_f, slash="/")
print("Importation of csv data complete!")
......@@ -92,7 +92,7 @@ if input('\nSave table with categories [Y/n] ? ') == 'Y':
for cat in ['acoustic', 'fishing_net', 'behavior', 'beacon', 'date', 'number', 'net']:
data_to_save[cat] = get_category(files_in_folder, audio_paths, data_20_21, cat)
data_to_save['audio_names'] = [file[:-10] for file in files_in_folder]
data_to_save['audio_names'] = files_in_folder
data_to_save['Buzz'] = Buzz_per_file.astype(int)
data_to_save['Burst-pulse'] = Burst_per_file.astype(int)
data_to_save.to_csv(os.path.join(save_f, datetime.now().strftime("%d-%m-%y_%Hh%M")+"_number_of_BBP.csv"),
......
......@@ -78,9 +78,9 @@ def get_csv(csv_folder, slash="\\"):
csv_names = [a for a in os.listdir(csv_folder) if a.endswith('.csv')]
# import data
data = import_csv(csv_names[0], csv_folder, separator=slash)
data = import_csv(csv_names[0], csv_folder, slash=slash)
for i in range(1,len(csv_names)):
data = data + import_csv(csv_names[i], csv_folder, separator=slash)[1:]
data = data + import_csv(csv_names[i], csv_folder, slash=slash)[1:]
data_frame = pd.DataFrame(data=data[:][1:], columns=data[:][0])
# change dtype for selected columns
......
This diff is collapsed.
File added
......@@ -84,7 +84,7 @@ for file in range(len(audio_paths)):
map_clean=np.copy(map_peaks)
# save detections
# np.save(os.path.join(save_f, audio_paths[file][-27:-4], "_peaks"),
# np.save(os.path.join(save_f, audio_paths[file][-27:-4] + "_peaks"),
# np.nonzero(map_clean)[0])
print(f"\r\t1- {file+1} on {len(audio_paths)}: Found {len(np.nonzero(map_clean)[0])} \
......
numb_stats_c[is.na(numb_stats_c)] <- 0
numb_stats_c$number <- as.factor(numb_stats_c$number)
numb_stats_c %>%
ggplot(aes(x=number, y=mean, group=1)) +
geom_errorbar(aes(x=number, ymin=mean-ic, ymax=mean+ic),
color="red", width=.1)+
geom_point() + geom_line() +
theme_classic() + theme(text=element_text(size=12)) +
ylab("Mean number of clicks per min")+
xlab("Number of echolocation clicks in group")
########################################################################
# STATISTICS
# Author : Loic LEHNHOFF
# Adapted from Yannick OUTREMAN
# Agrocampus Ouest - 2020
#######################################################################
library(pscl)
library(MASS)
library(lmtest)
library(multcomp)
......@@ -46,7 +29,22 @@ acoustic.dta <- clicks.dta
acoustic.dta$number_of_bbp <- bbp.dta$number_of_BBP
acoustic.dta$total_whistles_duration <- whistles.dta$total_whistles_duration
rm(whistles.dta, bbp.dta, clicks.dta)
# suppress "T" acoustic data (data not related to this analysis)
# add group IDs
id2020 <- read.table(file=paste0(folder, 'CSV_data/Audio_Data_2020.csv'),
sep = ',', header=TRUE)[1:396,]
id2021 <- read.table(file=paste0(folder, 'CSV_data/Audio_Data_2021.csv'),
sep = ',', header=TRUE)[1:96,]
id2021$ID <- id2021$ID+max(id2020$ID)
id2021$Seq <- id2021$Seq+max(id2020$Seq)
id.dta <- rbind(id2020, id2021)
id.dta$Fichier.Audio <-str_sub(id.dta$Fichier.Audio, -27, -5)
acoustic.dta$ID <- rep(-1, 490)
for (name in acoustic.dta$audio_names){
acoustic.dta$ID[match(name, acoustic.dta$audio_names)] <- id.dta$ID[match(name, id.dta$Fichier.Audio)]
}
acoustic.dta$ID <- as.factor(acoustic.dta$ID)
rm(id2020, id2021, id.dta)
# suppress "T" acoustic data (other groups not tested on our variables)
acoustic.dta <- acoustic.dta[acoustic.dta$acoustic!="T",]
# shuffle dataframe
acoustic.dta <- acoustic.dta[sample(1:nrow(acoustic.dta)), ]
......@@ -430,7 +428,7 @@ ytitle="Mean number of clicks per dolphin per min")+
theme(axis.text.x=element_text(size=8))+
scale_x_discrete(guide=guide_axis(n.dodge = 2))
# NC stands for "Unknown". Corresponding to categories where the beacon was not turned on yet ('BEF')
#### Plots by group ID ####
#### Plots by number of dolphins ####
# Whistles
numb_stats_w <- computeStats(acoustic.dta, number, total_whistles_duration/375)
numb_stats_w[is.na(numb_stats_w)] <- 0
......@@ -467,7 +465,7 @@ geom_point() + geom_line() +
theme_classic() + theme(text=element_text(size=12)) +
ylab("Mean number of clicks per min")+
xlab("Number of echolocation clicks in group")
#### Plots by Number of dolphins in group ####
#### Plots by Group ID ####
# Whistles
numb_stats_w <- computeStats(acoustic.dta, ID, whistling_time_per_dolphin/375)
numb_stats_w[is.na(numb_stats_w)] <- 0
......@@ -510,3 +508,5 @@ data_test <- acoustic.dta[acoustic.dta$ID!="2",]
print( posthocKW(data_test$whistling_time_per_dolphin, data_test$ID))
print( posthocKW(data_test$BBPs_per_dolphin, data_test$ID))
print( posthocKW(data_test$clicks_per_dolphin, data_test$ID))
hist(acoustic.dta$ID)
hist(acoustic.dta$number)
......@@ -24,7 +24,7 @@ print("Importation of packages complete!")
print("\rSetting up parameters...", end="\r")
audio_f = "./../Audio_data" # Path to recordings
csv_f = "./../CSV_data" # Path to data in csv
save_f = "./Trajectories" # Path were
save_f = "./Trajectories" # Path were results are stored
# Audio parameters
start = 0 # start time for signal (in sec)
......@@ -63,21 +63,19 @@ print("Importation of csv data complete!\n")
#%% Main execution
print("Spectral detector of whistles")
for file in np.array([418]):#range(len(audio_paths)):
for file in range(len(audio_paths)):
# import audio recording
signal, fe = load(os.path.join(audio_f, audio_paths[file][4:8], audio_paths[file]),
sr=None)
signal = signal[int(start*fe):int(stop*fe)]
# resample
signal_dec = resample(signal, int(((stop-start)*new_sr)))
print("1")
# extract spectral 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:,:]
print("2")
# Selection algorithm
max_loc_per_bin_check1 = get_local_maxima(spectre, spectre, nrg_rap)[1]
......@@ -86,7 +84,6 @@ for file in np.array([418]):#range(len(audio_paths)):
corrected_traj = sparsity_ridoff(final_traj, error_thresh=sparsity)
harmonized_traj = harmonize_trajectories(corrected_traj, min_r=min_r_coef,
min_common=taille_traj_min*2, delete=True)
print("3")
# Saving results
values = np.unique(harmonized_traj)[1:]
......@@ -96,30 +93,10 @@ for file in np.array([418]):#range(len(audio_paths)):
dict_traj[key+1] = [np.where(harmonized_traj == value)[0].tolist(),
np.where(harmonized_traj == value)[1].tolist()]
startstop[key] = np.array([min(dict_traj[key+1][1]), max(dict_traj[key+1][1])])
print("4")
# f = open(os.path.join(save_f, audio_paths[file].split('/')[-1][:-4] + ".json"), "w")
# json.dump(dict_traj, f, indent=4)
# f.close()
f = open(os.path.join(save_f, audio_paths[file].split('/')[-1][:-4] + ".json"), "w")
json.dump(dict_traj, f, indent=4)
f.close()
print(f"\r\tFile {file+1} on {len(audio_paths)}: found {len(values)} whistles", end='\r')
print("\nDetection of whistles finished!")
\ No newline at end of file
#%% Display the beautiful selection
final_traj[final_traj != 0] = 1
#harmonized_traj[harmonized_traj != 0] = 1
# colors to differenciate detected trajectories
prism = cm.get_cmap('prism', 256)
newcolors = prism(np.linspace(0, 1, np.unique(harmonized_traj).shape[0]))
pink = np.array([0/256, 0/256, 0/256, 1])
newcolors[0, :] = pink
newcmp = ListedColormap(newcolors)
a = plot_spectrums([amplitude_to_db(spectre), max_loc_per_bin_check1, final_traj, harmonized_traj],
['gray_r', 'gray', 'gray', newcmp],
titles=['Spectrogram (dB scale)', 'Local maxima selection', 'Extraction of continuous trajectories',
'Exclusion of harmonics'],
ylabels=["Frequency"]*4,
bins=375, title="")
plt.show(block=True)
\ No newline at end of file
......@@ -22,10 +22,9 @@ print("Importation of packages complete!")
#%% Parameters
print("\rSetting up parameters...", end="\r")
audio_f = "./../Audio_data" # Path to recordings
csv_f = "./../CSV_data" # Path to data in csv
save_f = "./Trajectories" # Path were
results_f = "./Evaluation"
save_f = "./Trajectories" # Path were trajectories are stored
results_f = "./Evaluation" # Path were results are stored
keep_if = 1 # minimal length of a whistle to be kept
print("Parameters ready to use!")
......
......@@ -83,9 +83,9 @@ def get_csv(csv_folder, slash="\\"):
csv_names = [a for a in os.listdir(csv_folder) if a.endswith('.csv')]
# import data
data = import_csv(csv_names[0], csv_folder, separator=slash)
data = import_csv(csv_names[0], csv_folder, slash=slash)
for i in range(1,len(csv_names)):
data = data + import_csv(csv_names[i], csv_folder, separator=slash)[1:]
data = data + import_csv(csv_names[i], csv_folder, slash=slash)[1:]
data_frame = pd.DataFrame(data=data[:][1:], columns=data[:][0])
# change dtype for selected columns
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment