Skip to content
Snippets Groups Projects
Commit 85b04279 authored by Paul Best's avatar Paul Best
Browse files

run_baseline ok

parent 7518ad5a
No related branches found
No related tags found
No related merge requests found
run_baseline.py 100644 → 100755
from tqdm import tqdm
from soundsig.sound import Biosound
import p_tqdm
from soundsig.sound import BioSound
import soundfile as sf
from scipy.signal import resample
import argparse
import pandas as pd
import pandas as pd, numpy as np
import models
parser = argparse.ArgumentParser()
......@@ -15,22 +16,37 @@ def norm(arr):
return (arr - np.mean(arr) ) / np.std(arr)
meta = models.meta[args.specie]
feats = ['fund', 'cvfund', 'maxfund', 'minfund', 'meansal', 'meanspect', 'stdspect', 'skewspect',\
'kurtosisspect', 'entropyspect', 'q1', 'q2', 'q3', 'meantime', 'stdtime', 'skewtime', 'kurtosistime', 'entropytime']
for idx, row in tqdm(df.iterrows(), total=len(df)):
info = sf.info(self.audiopath+row.fn)
def process(idx):
row = df.loc[idx]
info = sf.info(f'{args.specie}/audio/{row.fn}')
dur, fs = info.duration, info.samplerate
start = int(np.clip(row.pos - meta['sampleDur']/2, 0, max(0, dur - meta['sampleDur'])) * fs)
sig, fs = sf.read(self.audiopath+row.fn, start=start, stop=start + int(meta['sampleDur']*fs))
sig, fs = sf.read(f'{args.specie}/audio/{row.fn}', start=start, stop=start + int(meta['sampleDur']*fs))
if sig.ndim == 2:
sig = sig[:,0]
if len(sig) < meta['sampleDur'] * fs:
sig = np.concatenate([sig, np.zeros(int(self.sampleDur * fs) - len(sig))])
if fs != meta['sr']:
sig = resample(sig, int(len(sig)/fs*meta['sr']))
sound = BioSound(soundWave=norm(sig), fs=fs)
sound.spectroCalc(max_freq=meta['sr']//2)
sound.rms = myBioSound.sound.std()
sound.rms = sound.sound.std()
sound.ampenv(cutoff_freq = 20, amp_sample_rate = 1000)
sound.spectrum(f_high=10000)
sound.fundest(maxFund = 1500, minFund = 300, lowFc = 200, highFc = 6000,
sound.spectrum(f_high=meta['sr']//2 - 1)
sound.fundest(maxFund = 6000, minFund = 200, lowFc = 200, highFc = 6000,
minSaliency = 0.5, debugFig = 0,
minFormantFreq = 500, maxFormantBW = 500, windowFormant = 0.1,
method='Stack')
\ No newline at end of file
method='Stack')
return [sound.__dict__[f] for f in feats]
res = p_tqdm.p_map(process, df.index[:10])
for i, mr in zip(df.index[:10], res):
for f, r in zip(feats, mr):
df.loc[i, f] = r
df.to_csv(f'{args.specie}/{args.specie}_biosound.csv', index=False)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment