Finished the simulation part of the method sections.

This commit is contained in:
j-hartling
2026-05-13 17:07:51 +02:00
parent 5ef09bef6c
commit 688f153bef
10 changed files with 1349 additions and 1161 deletions

View File

@@ -0,0 +1,41 @@
import json
from thunderhopper.filetools import search_files
from misc_functions import sort_files_by_rec
from IPython import embed
# GENERAL SETTINGS:
target_species = [
'Chorthippus_biguttulus',
'Chorthippus_mollis',
'Chrysochraon_dispar',
'Gomphocerippus_rufus',
'Omocestus_rufipes',
'Pseudochorthippus_parallelus',
]
search_kwargs = dict(
ext='.wav',
dir='../data/raw/',
)
sources = ['BM04', 'BM93', 'DJN', 'GBC', 'FTN']
# EXECUTION:
n_songs, n_recs, n_sources = {}, {}, {}
for species in target_species:
print(f'\nCounting {species} songs...')
# Fetch all species-specific song files:
paths = search_files(species, **search_kwargs)
# Sort song files by recording:
sorted_paths = sort_files_by_rec(paths, sources, return_dict=True)
# Count number of available sources:
n_sources[species] = len(sorted_paths)
# Count number of available recordings:
n_recs[species] = sum(len(rec_paths) for rec_paths in sorted_paths.values())
# Count number of available songs:
n_songs[species] = sum(sum(len(paths) for paths in rec_paths) for rec_paths in sorted_paths.values())
print(f'Found {n_songs[species]} songs from {n_recs[species]} recordings across {n_sources[species]} sources.')

View File

@@ -45,7 +45,8 @@ def reduce_kernel_set(data, inds, keys=None, combis=None):
data[key] = data[key][:, inds, ...]
return data
def sort_files_by_rec(paths, sources=['BM04', 'BM93', 'DJN', 'GBC', 'FTN']):
def sort_files_by_rec(paths, sources=['BM04', 'BM93', 'DJN', 'GBC', 'FTN'],
return_dict=False):
# Separate by source:
sorted_paths = {}
for source in sources:
@@ -73,7 +74,11 @@ def sort_files_by_rec(paths, sources=['BM04', 'BM93', 'DJN', 'GBC', 'FTN']):
# Open new recording-specific slot:
sorted_paths[source].append([])
sorted_paths[source][sub_id - 1].append(path)
# Keep source separation:
if return_dict:
return sorted_paths
# Re-sort song files by recording only (discarding source separation):
sorted_paths = [path for paths in sorted_paths.values() for path in paths]
return sorted_paths