From 33c50944e07d639662f22b2a6493b6a8aeff44d2 Mon Sep 17 00:00:00 2001 From: Michael Towsey Date: Thu, 14 Nov 2019 14:32:18 +1000 Subject: [PATCH] Issue-#238 Fix failed tests for flying fox 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. --- .../Recognizers/PteropusSpecies.cs | 44 +++++++------------ src/AnalysisPrograms/Sandpit.cs | 7 +-- src/AudioAnalysisTools/AcousticEvent.cs | 1 + src/AudioAnalysisTools/Oscillations2012.cs | 4 +- .../Recognizers/PteropusSp/PteropusSpTests.cs | 24 +++++----- 5 files changed, 36 insertions(+), 44 deletions(-) diff --git a/src/AnalysisPrograms/Recognizers/PteropusSpecies.cs b/src/AnalysisPrograms/Recognizers/PteropusSpecies.cs index 71280803e..c91cb1b77 100644 --- a/src/AnalysisPrograms/Recognizers/PteropusSpecies.cs +++ b/src/AnalysisPrograms/Recognizers/PteropusSpecies.cs @@ -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, @@ -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; diff --git a/src/AnalysisPrograms/Sandpit.cs b/src/AnalysisPrograms/Sandpit.cs index 8525ae7a9..4a48d6ca1 100644 --- a/src/AnalysisPrograms/Sandpit.cs +++ b/src/AnalysisPrograms/Sandpit.cs @@ -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"; @@ -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"; diff --git a/src/AudioAnalysisTools/AcousticEvent.cs b/src/AudioAnalysisTools/AcousticEvent.cs index 98cd00ff9..92ec1a46b 100644 --- a/src/AudioAnalysisTools/AcousticEvent.cs +++ b/src/AudioAnalysisTools/AcousticEvent.cs @@ -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 diff --git a/src/AudioAnalysisTools/Oscillations2012.cs b/src/AudioAnalysisTools/Oscillations2012.cs index 9a2a1d91a..e4e6173ff 100644 --- a/src/AudioAnalysisTools/Oscillations2012.cs +++ b/src/AudioAnalysisTools/Oscillations2012.cs @@ -402,11 +402,11 @@ public static List 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++) diff --git a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/PteropusSp/PteropusSpTests.cs b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/PteropusSp/PteropusSpTests.cs index 0884f4f93..6b37bf0d9 100644 --- a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/PteropusSp/PteropusSpTests.cs +++ b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/PteropusSp/PteropusSpTests.cs @@ -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); }