diff --git a/BBPs/BBPUtils.py b/BBPs/BBPUtils.py index 02d765ca0f69c6e5a0398d391bee8d0cebe772c5..ff3a73bdfaffdcfc7aeed245d3dbf0801c49779d 100755 --- a/BBPs/BBPUtils.py +++ b/BBPs/BBPUtils.py @@ -13,7 +13,7 @@ import pandas as pd from scipy.signal import butter, filtfilt #%% Functions process -def import_csv(csv_name, folder, separator, useless=True): +def import_csv(csv_name, folder, useless=True, slash="/"): """ Parameters ---------- @@ -35,7 +35,7 @@ def import_csv(csv_name, folder, separator, useless=True): data = [] # read data csv - with open(folder + separator + csv_name, newline="") as csv_file: + with open(folder + slash + csv_name, newline="") as csv_file: lines = csv.reader(csv_file, delimiter=',') for row in lines: data = data + [row] @@ -72,7 +72,7 @@ def get_csv(csv_folder, slash="\\"): ------- data_20_21 : DATAFRAME Contains the inforamtion inside the .CSVs. - audio_paths : LIST + sorted_names : LIST Names corresponding to audio files in the first column of the .CSVs. """ csv_names = [a for a in os.listdir(csv_folder) if a.endswith('.csv')] @@ -92,8 +92,19 @@ def get_csv(csv_folder, slash="\\"): for filename in data_frame["Fichier Audio"]: if filename.endswith(".wav"): audio_names = np.append(audio_names, filename.replace('/', slash)) + + # sort audio files names + # We want to sort it by year + years = np.unique([path[4:8] for path in audio_names]) + sorted_names = np.array([], dtype='<U49') + # and inside each year, sort it by date. + for year in years: + idx_to_sort = np.where(np.array([path[4:8] for path in audio_names]) == year)[0] + temp_path = np.copy(audio_names[idx_to_sort]) + temp_path.sort() + sorted_names = np.append(temp_path, sorted_names) - return data_frame, audio_names + return data_frame, sorted_names def butter_pass_filter(data, cutoff, fs, order=1, mode='high'): """ diff --git a/Clicks/ClickUtils.py b/Clicks/ClickUtils.py index 65223dbadb8004481ebfd03d4db925c4b52262f8..280852a325648df9d5fce0e13ece42a1de7e1885 100755 --- a/Clicks/ClickUtils.py +++ b/Clicks/ClickUtils.py @@ -76,7 +76,7 @@ def get_csv(csv_folder, slash="\\"): ------- data_20_21 : DATAFRAME Contains the inforamtion inside the .CSVs. - audio_paths : LIST + sorted_names : LIST Names corresponding to audio files in the first column of the .CSVs. """ csv_names = [a for a in os.listdir(csv_folder) if a.endswith('.csv')] @@ -96,8 +96,19 @@ def get_csv(csv_folder, slash="\\"): for filename in data_frame["Fichier Audio"]: if filename.endswith(".wav"): audio_names = np.append(audio_names, filename.replace('/', slash)) + + # sort audio files names + # We want to sort it by year + years = np.unique([path[4:8] for path in audio_names]) + sorted_names = np.array([], dtype='<U49') + # and inside each year, sort it by date. + for year in years: + idx_to_sort = np.where(np.array([path[4:8] for path in audio_names]) == year)[0] + temp_path = np.copy(audio_names[idx_to_sort]) + temp_path.sort() + sorted_names = np.append(temp_path, sorted_names) - return data_frame, audio_names + return data_frame, sorted_names def butter_pass_filter(data, cutoff, fs, order=1, mode='high'): """ diff --git a/Clicks/__pycache__/ClickUtils.cpython-39.pyc b/Clicks/__pycache__/ClickUtils.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..637b1f10f4e9ed909a15627bce8f38dc038a2d95 Binary files /dev/null and b/Clicks/__pycache__/ClickUtils.cpython-39.pyc differ diff --git a/Whistles/WhistleUtils.py b/Whistles/WhistleUtils.py index 7c7c5e4bed80ff468ebd5a537c9af7acfce9642c..a285afde7b259e897fdb3ecc0f7c407b47b1e0c7 100755 --- a/Whistles/WhistleUtils.py +++ b/Whistles/WhistleUtils.py @@ -77,15 +77,15 @@ def get_csv(csv_folder, slash="\\"): ------- data_20_21 : DATAFRAME Contains the inforamtion inside the .CSVs. - audio_paths : LIST + sorted_names : LIST Names corresponding to audio files in the first column of the .CSVs. """ csv_names = [a for a in os.listdir(csv_folder) if a.endswith('.csv')] # import data - data = import_csv(csv_names[0], csv_folder, slash=slash) + data = import_csv(csv_names[0], csv_folder, separator=slash) for i in range(1,len(csv_names)): - data = data + import_csv(csv_names[i], csv_folder, slash=slash)[1:] + data = data + import_csv(csv_names[i], csv_folder, separator=slash)[1:] data_frame = pd.DataFrame(data=data[:][1:], columns=data[:][0]) # change dtype for selected columns @@ -97,8 +97,19 @@ def get_csv(csv_folder, slash="\\"): for filename in data_frame["Fichier Audio"]: if filename.endswith(".wav"): audio_names = np.append(audio_names, filename.replace('/', slash)) + + # sort audio files names + # We want to sort it by year + years = np.unique([path[4:8] for path in audio_names]) + sorted_names = np.array([], dtype='<U49') + # and inside each year, sort it by date. + for year in years: + idx_to_sort = np.where(np.array([path[4:8] for path in audio_names]) == year)[0] + temp_path = np.copy(audio_names[idx_to_sort]) + temp_path.sort() + sorted_names = np.append(temp_path, sorted_names) - return data_frame, audio_names + return data_frame, sorted_names #%% Trajectories algorithms def get_local_maxima(spectrogram, spectrogram2, hardness, threshold=10e-5):