Skip to content

Commit

Permalink
re raise ex (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: gferraro <[email protected]>
  • Loading branch information
gferraro and gferraro authored Jul 14, 2024
1 parent 4e8ac57 commit bbf1835
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
38 changes: 20 additions & 18 deletions Melt/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,26 @@ def species_identify(file_name, morepork_model, bird_models, analyse_tracks):
morepork_ids = identify_morepork(file_name, morepork_model)
labels.extend(morepork_ids)
if bird_models is not None:
bird_ids, length, chirps, signals = classify(
file_name, bird_models, analyse_tracks, meta_data
)
labels.extend([track.get_meta() for track in bird_ids])
cacophony_index, version = calc_cacophony_index(filter_tracks(bird_ids), length)
if not analyse_tracks:
max_chirps = get_max_chirps(length)
version = "2.0"
chirp_index = 0 if max_chirps == 0 else round(100 * chirps / max_chirps)

result["cacophony_index"] = cacophony_index
result["cacophony_index_version"] = version
result["chirps"] = {
"chirps": chirps,
"max_chirps": max_chirps,
"chirp_index": chirp_index,
"signals": [s.to_array() for s in signals],
}
classify_res = classify(file_name, bird_models, analyse_tracks, meta_data)
if classify_res is not None:
bird_ids, length, chirps, signals = classify_res
labels.extend([track.get_meta() for track in bird_ids])
cacophony_index, version = calc_cacophony_index(
filter_tracks(bird_ids), length
)
if not analyse_tracks:
max_chirps = get_max_chirps(length)
version = "2.0"
chirp_index = 0 if max_chirps == 0 else round(100 * chirps / max_chirps)

result["cacophony_index"] = cacophony_index
result["cacophony_index_version"] = version
result["chirps"] = {
"chirps": chirps,
"max_chirps": max_chirps,
"chirp_index": chirp_index,
"signals": [s.to_array() for s in signals],
}

result["species_identify"] = labels
result["species_identify_version"] = "2021-02-01"
Expand Down
23 changes: 14 additions & 9 deletions Melt/identify_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ def get_max_chirps(length):


def load_recording(file, resample=48000):
# librosa.load(file) giving strange results
aro = audioread.ffdec.FFmpegAudioFile(file)
frames, sr = librosa.load(aro, sr=None)
aro.close()
if resample is not None and resample != sr:
frames = librosa.resample(frames, orig_sr=sr, target_sr=resample)
sr = resample
return frames, sr
try:
# librosa.load(file) giving strange results
aro = audioread.ffdec.FFmpegAudioFile(file)
frames, sr = librosa.load(aro, sr=None)
aro.close()
if resample is not None and resample != sr:
frames = librosa.resample(frames, orig_sr=sr, target_sr=resample)
sr = resample
return frames, sr
except:
logging.error("Could not load %s", file, exc_info=True)
# for some reason the original exception causes docker to hang
raise Exception(f"Could not load {file}")


def load_samples(
Expand Down Expand Up @@ -327,7 +332,7 @@ def classify(file, models, analyse_tracks, meta_data=None):
# want to use signals for chrips
if analyse_tracks:
if meta_data is None:
return
return None
meta_tracks = [t for t in meta_data["Tracks"]]
tracks = []
for t in meta_tracks:
Expand Down

0 comments on commit bbf1835

Please sign in to comment.