From 6b90e4fb45607f7ea9e0feb373b75155865d9c8b Mon Sep 17 00:00:00 2001 From: Michael Towsey Date: Tue, 29 Jun 2021 21:09:52 +1000 Subject: [PATCH] Update PteropusSpTests.cs Issue #500 1: Make adjustments to the start and end of wingbeat events. THis is necessary due to changes in the way the beginning and end of oscillations events are calculated. 2: Make a debug spectrogram image available so user can see what is happening. --- .../Recognizers/PteropusSpTests.cs | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/PteropusSpTests.cs b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/PteropusSpTests.cs index 110d6eedc..d5d3da4d6 100644 --- a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/PteropusSpTests.cs +++ b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/PteropusSpTests.cs @@ -8,8 +8,11 @@ namespace Acoustics.Test.AnalysisPrograms.Recognizers using System.Collections.Generic; using System.IO; using Acoustics.Test.TestHelpers; + using global::AnalysisPrograms.Recognizers; + using global::AnalysisPrograms.Recognizers.Base; using global::AudioAnalysisTools; using global::AudioAnalysisTools.DSP; + using global::AudioAnalysisTools.Events; using global::AudioAnalysisTools.StandardSpectrograms; using global::AudioAnalysisTools.WavTools; using global::TowseyLibrary; @@ -17,7 +20,7 @@ namespace Acoustics.Test.AnalysisPrograms.Recognizers using SixLabors.ImageSharp; [TestClass] - public class PteropusSpTests + public class PteropusSpTests : OutputDirectoryTest { private DirectoryInfo outputDirectory; private AudioRecording audioRecording; @@ -57,12 +60,12 @@ public void TestGetWingBeatEvents() //string abbreviatedSpeciesName = "Pteropus"; int minHz = 200; int maxHz = 2000; - double minDurationSeconds = 1.0; + double minDurationSeconds = 0.8; double maxDurationSeconds = 10.0; double dctDuration = 0.8; double dctThreshold = 0.5; double minOscilFreq = 4.0; - double maxOscilFreq = 6.0; + double maxOscilFreq = 6.2; double eventThreshold = 0.6; TimeSpan segmentStartOffset = TimeSpan.Zero; @@ -84,33 +87,58 @@ public void TestGetWingBeatEvents() out var hits, segmentStartOffset); + // set up results so can draw spectrogram + // first convert Oscill events to EventCommon + var eventList = new List(); + foreach (var ev in acousticEvents) + { + eventList.Add(ev); + } + + var plot = new Plot("Wing beats", oscScores, 0.5); + var plots = new List + { + plot, + }; + + var results = new RecognizerResults() + { + NewEvents = eventList, + ScoreTrack = null, + Plots = plots, + Sonogram = this.sonogram, + }; + + this.SaveTestOutput( + outputDirectory => GenericRecognizer.SaveDebugSpectrogram(results, null, outputDirectory, "PteropusSp")); + Assert.AreEqual(this.sonogram.FrameCount, bandDecibels.Length); Assert.AreEqual(this.sonogram.FrameCount, oscScores.Length); Assert.AreEqual(4, acousticEvents.Count); - Assert.AreEqual(29.9, acousticEvents[0].EventStartSeconds, 0.1); + Assert.AreEqual(29.7, acousticEvents[0].EventStartSeconds, 0.1); Assert.AreEqual(32.0, acousticEvents[0].EventEndSeconds, 0.1); Assert.AreEqual(200, acousticEvents[0].LowFrequencyHertz); Assert.AreEqual(2000, acousticEvents[0].HighFrequencyHertz); - Assert.AreEqual(0.2, acousticEvents[0].Periodicity, 0.1); + Assert.AreEqual(0.2, acousticEvents[0].Periodicity, 0.02); - Assert.AreEqual(41.2, acousticEvents[1].EventStartSeconds, 0.1); - Assert.AreEqual(42.0, acousticEvents[1].EventEndSeconds, 0.1); + Assert.AreEqual(40.9, acousticEvents[1].EventStartSeconds, 0.1); + Assert.AreEqual(42.4, acousticEvents[1].EventEndSeconds, 0.1); Assert.AreEqual(200, acousticEvents[1].LowFrequencyHertz); Assert.AreEqual(2000, acousticEvents[1].HighFrequencyHertz); - Assert.AreEqual(0.2, acousticEvents[0].Periodicity, 0.1); + Assert.AreEqual(0.2, acousticEvents[0].Periodicity, 0.02); Assert.AreEqual(48.6, acousticEvents[2].EventStartSeconds, 0.1); Assert.AreEqual(51.0, acousticEvents[2].EventEndSeconds, 0.1); Assert.AreEqual(200, acousticEvents[2].LowFrequencyHertz); Assert.AreEqual(2000, acousticEvents[2].HighFrequencyHertz); - Assert.AreEqual(0.2, acousticEvents[0].Periodicity, 0.1); + Assert.AreEqual(0.2, acousticEvents[0].Periodicity, 0.02); - Assert.AreEqual(54.4, acousticEvents[3].EventStartSeconds, 0.1); - Assert.AreEqual(55.1, acousticEvents[3].EventEndSeconds, 0.1); + Assert.AreEqual(54.2, acousticEvents[3].EventStartSeconds, 0.1); + Assert.AreEqual(55.3, acousticEvents[3].EventEndSeconds, 0.1); Assert.AreEqual(200, acousticEvents[3].LowFrequencyHertz); Assert.AreEqual(2000, acousticEvents[3].HighFrequencyHertz); - Assert.AreEqual(0.2, acousticEvents[0].Periodicity, 0.1); + Assert.AreEqual(0.2, acousticEvents[0].Periodicity, 0.02); //Assert.AreEqual(0.6062, stats.SpectralEnergyDistribution, 1E-4); }