Skip to content
Snippets Groups Projects
Commit 34de2a32 authored by Stephane Chavin's avatar Stephane Chavin
Browse files

correct get_time_freq

parent ddc96b55
No related branches found
No related tags found
No related merge requests found
......@@ -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()
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,
......
......@@ -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)']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment