diff --git a/get_time_freq_detection.py b/get_time_freq_detection.py index 29655bef8e59c4c0a2d3c82e1d6068c0650757bc..803ed72c1e2612794da4a84327d746d288735d72 100755 --- a/get_time_freq_detection.py +++ b/get_time_freq_detection.py @@ -20,7 +20,7 @@ def main(arguments): df, dir_path = utils.detection2time_freq(annotations_folder=arguments.path_to_data, duration=arguments.duration, outdir=arguments.directory, - sr=arguments.sr, + rf=arguments.rf, names=names, wav=args.path_to_wav, raven=args.raven) @@ -35,7 +35,10 @@ def main(arguments): '"begin time (s)"; "end time (s)" and the species detected' ' in the given files.') ds.attrs['date_created'] = pd.Timestamp.now().isoformat() - ds.attrs['creator_name'] = os.getlogin() + try: + ds.attrs['creator_name'] = os.getlogin() + except Exception: + ds.attrs['creator_name'] = input('Your name : ') # Save Dataset to NetCDF file ds.to_netcdf(dir_path) @@ -51,8 +54,8 @@ if __name__ == "__main__": help='Directory where the dataframe will be stored') parser.add_argument('names', type=str, help='path to YOLOv5 custom_data.yaml file') - parser.add_argument('-s', '--sr', type=int, - help='Sampling Rate of the spectrogram', required=True) + parser.add_argument('--rf', type=int, + help='Resample frequency', required=True) parser.add_argument('--duration', type=int, help='Duration of the spectrogram', default=8) parser.add_argument('--path_to_wav', type=utils.arg_directory, diff --git a/utils.py b/utils.py index 080aa8fa5469a49e76aa8986a4510a4face30117..bab268fdb36927a22f535f0ccfeb43c3bb3d9059 100755 --- a/utils.py +++ b/utils.py @@ -355,17 +355,19 @@ def prepare_dataframe(df, args): return df, species_list -def detection2time_freq(annotations_folder, duration, outdir, sr, names, wav, raven): +def detection2time_freq(annotations_folder, duration, outdir, rf, names, wav, raven): """ Collect all .txt detection and get time and frequency informations - :param annotations_folder (str): Path to the .json files + :param annotations_folder (str): Path to the .txt files :param duration (int): Directory to save the .txt files - :param outfir (str): Directory to save the .txt files - :param sr (int): Directory to save the .txt files - :param names (str): Directory to save the .txt files + :param outdir (str): Directory to save the .txt files + :param rf (int): Resampling freq. + :param names (str): names of the classes + :param wav (str): Path to the wav + :param raven (int): Save into Raven format or not """ today = date.today() - out_file = f'YOLO_detection_{today.day}_{today.month}_freq_{sr}_duration_{duration}.nc' + out_file = f'YOLO_detection_{today.day}_{today.month}_freq_{rf}_duration_{duration}.nc' # Load and process data df = pd.concat({f: pd.read_csv(os.path.join(annotations_folder, f), @@ -390,8 +392,8 @@ def detection2time_freq(annotations_folder, duration, outdir, sr, names, wav, ra df['species'] = df['class'].apply(lambda x: names[int(x)]) df['pos'] = (df['x'] * duration) + df['class'].astype(int) - df['Low Freq (Hz)'] = (1 - df['y']) * (sr / 2) - (df['h'] * (sr / 2)) / 2 - df['High Freq (Hz)'] = (1 - df['y']) * (sr / 2) + (df['h'] * (sr / 2)) / 2 + df['Low Freq (Hz)'] = (1 - df['y']) * (rf / 2) - (df['h'] * (rf / 2)) / 2 + df['High Freq (Hz)'] = (1 - df['y']) * (rf / 2) + (df['h'] * (rf / 2)) / 2 df['Begin Time (s)'] = df['pos'] - (df['w'] * duration) / 2 df['End Time (s)'] = df['pos'] + (df['w'] * duration) / 2 df['duration'] = df['End Time (s)'] - df['Begin Time (s)']