From 80a36bde583ade6070045c3599d69bdcd41d87f0 Mon Sep 17 00:00:00 2001 From: towsey Date: Sat, 24 Oct 2020 15:36:52 +1100 Subject: [PATCH] Pass decibel threshold to each recognizer. Issue #390 Following on from the previous commit, it was necessary to pass a decibel throld to isse run of a profile. --- .../Recognizers/GenericRecognizer.cs | 6 +++ .../Recognizers/GenericRecognizerTests.cs | 53 +++++++++---------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs b/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs index d0bb76add..5ac409c27 100644 --- a/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs +++ b/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs @@ -214,6 +214,7 @@ public static RecognizerResults RunProfiles( (spectralEvents, decibelPlots) = BlobEvent.GetBlobEvents( spectrogram, bp, + decibelThreshold, segmentStartOffset, profileName); @@ -237,6 +238,7 @@ public static RecognizerResults RunProfiles( (spectralEvents, decibelPlots) = ForwardTrackAlgorithm.GetForwardTracks( spectrogram, tp, + decibelThreshold, segmentStartOffset, profileName); @@ -248,6 +250,7 @@ public static RecognizerResults RunProfiles( (spectralEvents, decibelPlots) = OneframeTrackAlgorithm.GetOneFrameTracks( spectrogram, cp, + decibelThreshold, segmentStartOffset, profileName); @@ -259,6 +262,7 @@ public static RecognizerResults RunProfiles( (spectralEvents, decibelPlots) = UpwardTrackAlgorithm.GetUpwardTracks( spectrogram, vtp, + decibelThreshold, segmentStartOffset, profileName); @@ -270,6 +274,7 @@ public static RecognizerResults RunProfiles( (spectralEvents, decibelPlots) = HarmonicParameters.GetComponentsWithHarmonics( spectrogram, hp, + decibelThreshold, segmentStartOffset, profileName); @@ -281,6 +286,7 @@ public static RecognizerResults RunProfiles( (spectralEvents, decibelPlots) = Oscillations2012.GetComponentsWithOscillations( spectrogram, op, + decibelThreshold, segmentStartOffset, profileName); diff --git a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizerTests.cs b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizerTests.cs index 785083dee..cdeea507e 100644 --- a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizerTests.cs +++ b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizerTests.cs @@ -40,15 +40,14 @@ public static void ClassInitialize(TestContext context) [TestMethod] public void TestConfigSerialization() { - // set up an array of decibel threhsolds. - var thresholdArray = new double?[] { 3, 6, 9 }; - var config = new GenericRecognizer.GenericRecognizerConfig() { + // set up an array of decibel threhsolds. + DecibelThresholds = new double?[] { 3, 6, 9 }, Profiles = new Dictionary() { { "TestAed", new Aed.AedConfiguration() { BandpassMinimum = 12345 } }, - { "TestOscillation", new OscillationParameters() { DecibelThresholds = thresholdArray } }, + { "TestOscillation", new OscillationParameters() }, { "TestBlob", new BlobParameters() { BottomHertzBuffer = 456 } }, { "TestWhistle", new OnebinTrackParameters() { TopHertzBuffer = 789 } }, }, @@ -92,6 +91,8 @@ public void TestBlobAlgorithm() { var config = new GenericRecognizer.GenericRecognizerConfig() { + // set up an array of decibel threhsolds. + DecibelThresholds = new double?[] { 0.0 }, Profiles = new Dictionary() { { @@ -104,7 +105,6 @@ public void TestBlobAlgorithm() MaxHertz = 7200, BottomHertzBuffer = 1000, TopHertzBuffer = 500, - DecibelThresholds = new double?[] { 0.0 }, } }, }, @@ -148,6 +148,8 @@ public void TestOscillationAlgorithm() { var config = new GenericRecognizer.GenericRecognizerConfig() { + // set up an array of decibel threhsolds. + DecibelThresholds = new double?[] { 0.0 }, Profiles = new Dictionary() { { @@ -168,7 +170,6 @@ public void TestOscillationAlgorithm() MinDuration = 4, MaxDuration = 8, EventThreshold = 0.3, - DecibelThresholds = new double?[] { 0.0 }, } }, }, @@ -213,6 +214,8 @@ public void TestWhistleAlgorithm() { var config = new GenericRecognizer.GenericRecognizerConfig() { + // set up an array of decibel threhsolds. + DecibelThresholds = new double?[] { 1.0 }, Profiles = new Dictionary() { { @@ -229,7 +232,6 @@ public void TestWhistleAlgorithm() TopHertzBuffer = 0, MinDuration = 4, MaxDuration = 6, - DecibelThresholds = new double?[] { 1.0 }, SpeciesName = "NoName", } }, @@ -388,11 +390,7 @@ public void TestOnebinTrackAlgorithm() MaxHertz = 6000, MinDuration = 0.2, MaxDuration = 1.1, - DecibelThresholds = new double?[] { 2.0 }, CombinePossibleSyllableSequence = false, - - //SyllableStartDifference = TimeSpan.FromSeconds(0.2), - //SyllableHertzGap = 300, }; //Set up the virtual recording. @@ -415,9 +413,6 @@ public void TestOnebinTrackAlgorithm() var spectrogram = this.CreateArtificialSpectrogramToTestTracksAndHarmonics(sonoConfig); - //var image1 = SpectrogramTools.GetSonogramPlusCharts(spectrogram, null, null, null); - //results.Sonogram.GetImage().Save(this.outputDirectory + "\\debug.png"); - var (spectralEvents, plotList) = OnebinTrackAlgorithm.GetOnebinTracks( spectrogram, parameters, @@ -474,19 +469,16 @@ public void TestOnebinTrackAlgorithm() public void TestForwardTrackAlgorithm() { // Set up the recognizer parameters. + double? decibelThreshold = 2.0; var parameters = new ForwardTrackParameters() { MinHertz = 500, MaxHertz = 6000, MinDuration = 0.2, MaxDuration = 1.1, - DecibelThresholds = new double?[] { 2.0 }, CombinePossibleHarmonics = false, HarmonicsStartDifference = TimeSpan.FromSeconds(0.2), HarmonicsHertzGap = 200, - CombinePossibleSyllableSequence = false, - SyllableStartDifference = 0.2, - SyllableHertzGap = 300, }; //Set up the virtual recording. @@ -515,6 +507,7 @@ public void TestForwardTrackAlgorithm() var (spectralEvents, plotList) = ForwardTrackAlgorithm.GetForwardTracks( spectrogram, parameters, + decibelThreshold, segmentStartOffset, "TestProfile"); @@ -560,13 +553,13 @@ public void TestForwardTrackAlgorithm() public void TestOneframeTrackAlgorithm() { // Set up the recognizer parameters. + double? decibelThreshold = 2.0; var parameters = new OneframeTrackParameters() { MinHertz = 6000, MaxHertz = 11000, MinBandwidthHertz = 100, MaxBandwidthHertz = 5000, - DecibelThresholds = new double?[] { 2.0 }, }; //Set up the virtual recording. @@ -595,6 +588,7 @@ public void TestOneframeTrackAlgorithm() var (spectralEvents, plotList) = OneframeTrackAlgorithm.GetOneFrameTracks( spectrogram, parameters, + decibelThreshold, segmentStartOffset, "TestProfile"); @@ -643,13 +637,15 @@ public void TestOneframeTrackAlgorithm() public void Test1UpwardsTrackAlgorithm() { // Set up the recognizer parameters. + var decibelThreshold = 2.0; var parameters = new UpwardTrackParameters() { MinHertz = 6000, MaxHertz = 11000, MinBandwidthHertz = 100, MaxBandwidthHertz = 5000, - DecibelThresholds = new double?[] { 2.0 }, + + // these params are to detect calls that consist of a rapid sequence of chirps/whips. CombineProximalSimilarEvents = true, SyllableStartDifference = TimeSpan.FromSeconds(0.2), SyllableHertzDifference = 300, @@ -674,14 +670,12 @@ public void Test1UpwardsTrackAlgorithm() var spectrogram = this.CreateArtificialSpectrogramToTestTracksAndHarmonics(sonoConfig); - //var image1 = SpectrogramTools.GetSonogramPlusCharts(spectrogram, null, null, null); - //results.Sonogram.GetImage().Save(this.outputDirectory + "\\debug.png"); - var segmentStartOffset = TimeSpan.Zero; var plots = new List(); var (spectralEvents, plotList) = UpwardTrackAlgorithm.GetUpwardTracks( spectrogram, parameters, + decibelThreshold, segmentStartOffset, "TestProfile"); @@ -729,13 +723,15 @@ public void Test1UpwardsTrackAlgorithm() public void Test2UpwardsTrackAlgorithm() { // Set up the recognizer parameters. + var decibelThreshold = 2.0; var parameters = new UpwardTrackParameters() { MinHertz = 500, MaxHertz = 6000, MinBandwidthHertz = 200, MaxBandwidthHertz = 5000, - DecibelThresholds = new double?[] { 2.0 }, + + // these params are to detect calls that consist of a rapid sequence of chirps/whips. CombineProximalSimilarEvents = false, SyllableStartDifference = TimeSpan.FromSeconds(0.2), SyllableHertzDifference = 300, @@ -766,6 +762,7 @@ public void Test2UpwardsTrackAlgorithm() var (spectralEvents, plotList) = UpwardTrackAlgorithm.GetUpwardTracks( spectrogram, parameters, + decibelThreshold, segmentStartOffset, "TestProfile"); @@ -1016,6 +1013,7 @@ public void TestMultipleAlgorithms() { var config = new GenericRecognizer.GenericRecognizerConfig() { + DecibelThresholds = new double?[] { 0.0 }, Profiles = new Dictionary() { { @@ -1028,7 +1026,6 @@ public void TestMultipleAlgorithms() BgNoiseThreshold = 0.0, BottomHertzBuffer = 1000, TopHertzBuffer = 500, - DecibelThresholds = new double?[] { 0.0 }, } }, { @@ -1049,7 +1046,6 @@ public void TestMultipleAlgorithms() MaxDuration = 6, EventThreshold = 0.3, SpeciesName = "DTMF", - DecibelThresholds = new double?[] { 0.0 }, } }, { @@ -1070,7 +1066,6 @@ public void TestMultipleAlgorithms() MaxDuration = 6, EventThreshold = 0.3, SpeciesName = "DTMF", - DecibelThresholds = new double?[] { 0.0 }, } }, }, @@ -1109,8 +1104,8 @@ public void TestMultipleAlgorithms() Assert.AreEqual(null, @event.Name); @event = (SpectralEvent)results.NewEvents[1]; - Assert.AreEqual(108.1, @event.EventStartSeconds, 0.4); - Assert.AreEqual(113.15, @event.EventEndSeconds, 0.5); + Assert.AreEqual(107.78, @event.EventStartSeconds, 0.4); + Assert.AreEqual(113.57, @event.EventEndSeconds, 0.5); Assert.AreEqual(700, @event.LowFrequencyHertz, 0.1); Assert.AreEqual(1050, @event.HighFrequencyHertz, 0.1); Assert.AreEqual("DTMF", @event.Name);