Skip to content

Commit

Permalink
Issue-#238 Fix failed tests for flying fox
Browse files Browse the repository at this point in the history
For some reason, acoustic event bounds were not being calculated. Had to fix acoustic event class, and then do slight readjustments to the expected bounds of wing-beat events.
  • Loading branch information
towsey committed Nov 14, 2019
1 parent b31598b commit 33c5094
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 44 deletions.
44 changes: 17 additions & 27 deletions src/AnalysisPrograms/Recognizers/PteropusSpecies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ private static RecognizerResults WingBeats(AudioRecording audioRecording, Config
var decibelArray = SNR.CalculateFreqBandAvIntensity(sonogram.Data, minHz, maxHz, sonogram.NyquistFrequency);

// Look for wing beats using oscillation detector
/*
int scoreSmoothingWindow = 11; // sets a default that was good for Cane toad
//Oscillations2012.Execute(
Oscillations2019.Execute(
(SpectrogramStandard)sonogram,
(SpectrogramStandard)sonogram,
minHz,
maxHz,
decibelThreshold,
Expand All @@ -354,33 +354,23 @@ private static RecognizerResults WingBeats(AudioRecording audioRecording, Config
out var acousticEvents,
//out var hits,
segmentStartOffset);

/*
* //NOTE: The following was an experiment which was discontinued!
// Look for wing beats using pulse train detector
double pulsesPerSecond = 5.1;
var scores = PulseTrain.GetPulseTrainScore(decibelArray, pulsesPerSecond, sonogram.FramesPerSecond, 1.0);
//iii: CONVERT Pulse Train SCORES TO ACOUSTIC EVENTS
double pulseTrainThreshold = 0.5;
var minTimeSpan = TimeSpan.FromSeconds(minDurationSeconds);
var maxTimeSpan = TimeSpan.FromSeconds(maxDurationSeconds);
var acousticEvents = AcousticEvent.GetEventsAroundMaxima(
scores,
segmentStartOffset,
*/
Oscillations2012.Execute(
(SpectrogramStandard)sonogram,
minHz,
maxHz,
pulseTrainThreshold,
minTimeSpan,
maxTimeSpan,
sonogram.FramesPerSecond,
sonogram.FBinWidth
);
double scoreThreshold = 0.5;
var normalisedScoreArray = DataTools.NormaliseInZeroOne(scores, 0, 1.0);
var plot2 = new Plot(speciesName + " Wingbeat Pulse-train Score", normalisedScoreArray, scoreThreshold);
*/
//decibelThreshold,
dctDuration,
(int)Math.Floor(minOscFreq),
(int)Math.Floor(maxOscFreq),
dctThreshold,
eventThreshold,
minDurationSeconds,
maxDurationSeconds,
out var scores,
out var acousticEvents,
out var hits,
segmentStartOffset);

// prepare plots
double intensityNormalisationMax = 3 * decibelThreshold;
Expand Down
7 changes: 4 additions & 3 deletions src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,14 @@ public static void Audio2CsvOverOneFile()

// FLYING FOX RECORDINGS
//string recordingPath = @"C:\Ecoacoustics\WavFiles\BradLawData\FlyingFox\20190127_Bellingen_Feeding_SM4.wav";
string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding.wav";
string recordingPath = @"D:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding_minute6.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding_minute6_OneChannel22050.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190121_2_Bellingen_Feeding.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190127_Bellingen_Feeding_SM4.wav";
string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\RecognizerConfigFiles\Towsey.PteropusSpecies.yml";
string outputPath = @"C:\Ecoacoustics\Output\BradLaw\FlyingFox";
//string outputPath = @"C:\Ecoacoustics\Output\BradLaw\FlyingFox";
string outputPath = @"C:\Ecoacoustics\FlyingFox";

// TSHERING DEMA BHUTAN RECORDINGS
//string recordingPath = @"C:\SensorNetworks\WavFiles\TsheringDema\WBH12HOURS-D_20160403_120000.wav";
Expand Down Expand Up @@ -400,7 +401,7 @@ public static void Audio2CsvOverOneFile()
//string outputPath = @"C:\Ecoacoustics\Output\SERF\SERFIndicesNew_2013June19";
//string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\Towsey.Acoustic.yml";

// USE 24-hour data or parts of from MEZ, TASMAn ISLAND, liz Znidersic
// USE 24-hour data or parts of from MEZ, TASMAn ISLAND, liz Znidersic
// these are six hour recordings
//string recordingPath = @"C:\Ecoacoustics\WavFiles\LizZnidersic\TasmanIsland2015_Unit2_Mez\SM304256_0+1_20151114_031652.wav";
//string outputPath = @"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\04";
Expand Down
1 change: 1 addition & 0 deletions src/AudioAnalysisTools/AcousticEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ public void SetTimeAndFreqScales(double frameOffset, double frameDuration, doubl
{
this.FramesPerSecond = 1 / frameOffset; //inverse of the frame offset
this.FrameDuration = frameDuration; //frame duration in seconds
this.FrameOffset = frameOffset; //frame duration in seconds

//this.FreqBinCount = binCount; //required for conversions to & from MEL scale
this.FreqBinWidth = freqBinWidth; //required for freq-binID conversions
Expand Down
4 changes: 2 additions & 2 deletions src/AudioAnalysisTools/Oscillations2012.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ public static List<AcousticEvent> ConvertOscillationScores2Events(
var ev = new AcousticEvent(segmentStartOffset, startTime, duration, minHz, maxHz)
{
Name = "Oscillation", //default name

//ev.SetTimeAndFreqScales(framesPerSec, freqBinWidth);
FileName = fileName,
};

ev.SetTimeAndFreqScales(framesPerSec, freqBinWidth);

//obtain average score.
double av = 0.0;
for (int n = startFrame; n <= i; n++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,25 @@ public void TestGetWingBeatEvents()

Assert.AreEqual(4, acousticEvents.Count);

Assert.AreEqual(4, acousticEvents[0].Oblong.ColumnLeft);
Assert.AreEqual(47, acousticEvents[0].Oblong.ColumnRight);
Assert.AreEqual(5, acousticEvents[0].Oblong.ColumnLeft);
Assert.AreEqual(46, acousticEvents[0].Oblong.ColumnRight);
Assert.AreEqual(1280, acousticEvents[0].Oblong.RowTop);
Assert.AreEqual(1380, acousticEvents[0].Oblong.RowBottom);
Assert.AreEqual(1381, acousticEvents[0].Oblong.RowBottom);

Assert.AreEqual(4, acousticEvents[1].Oblong.ColumnLeft);
Assert.AreEqual(47, acousticEvents[1].Oblong.ColumnRight);
Assert.AreEqual(5, acousticEvents[1].Oblong.ColumnLeft);
Assert.AreEqual(46, acousticEvents[1].Oblong.ColumnRight);
Assert.AreEqual(1762, acousticEvents[1].Oblong.RowTop);
Assert.AreEqual(1825, acousticEvents[1].Oblong.RowBottom);
Assert.AreEqual(1826, acousticEvents[1].Oblong.RowBottom);

Assert.AreEqual(4, acousticEvents[2].Oblong.ColumnLeft);
Assert.AreEqual(47, acousticEvents[2].Oblong.ColumnRight);
Assert.AreEqual(5, acousticEvents[2].Oblong.ColumnLeft);
Assert.AreEqual(46, acousticEvents[2].Oblong.ColumnRight);
Assert.AreEqual(2083, acousticEvents[2].Oblong.RowTop);
Assert.AreEqual(2207, acousticEvents[2].Oblong.RowBottom);
Assert.AreEqual(2208, acousticEvents[2].Oblong.RowBottom);

Assert.AreEqual(4, acousticEvents[3].Oblong.ColumnLeft);
Assert.AreEqual(47, acousticEvents[3].Oblong.ColumnRight);
Assert.AreEqual(5, acousticEvents[3].Oblong.ColumnLeft);
Assert.AreEqual(46, acousticEvents[3].Oblong.ColumnRight);
Assert.AreEqual(2334, acousticEvents[3].Oblong.RowTop);
Assert.AreEqual(2382, acousticEvents[3].Oblong.RowBottom);
Assert.AreEqual(2383, acousticEvents[3].Oblong.RowBottom);

//Assert.AreEqual(0.6062, stats.SpectralEnergyDistribution, 1E-4);
}
Expand Down

0 comments on commit 33c5094

Please sign in to comment.