diff --git a/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs b/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs index 570f8aa25..da6bbf8ef 100644 --- a/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs +++ b/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs @@ -179,21 +179,32 @@ public static RecognizerResults RunProfiles( var spectrogram = new SpectrogramStandard(ParametersToSonogramConfig(parameters), audioRecording.WavReader); + var profileResults = new RecognizerResults(); foreach (var threshold in decibelThresholds) { - RecognizerResults results = RunOneProfile(spectrogram, profileName, parameters, threshold, segmentStartOffset); + var thresholdResults = RunOneProfile(spectrogram, profileName, parameters, threshold, segmentStartOffset); //Log.Debug($"Event count from all profiles at {threshold} dB threshold = {results.NewEvents.Count}"); - combinedResults.NewEvents.AddRange(results.NewEvents); - combinedResults.Plots.AddRange(results.Plots); - combinedResults.Sonogram = results.Sonogram; + profileResults.NewEvents.AddRange(thresholdResults.NewEvents); + profileResults.Plots.AddRange(thresholdResults.Plots); + profileResults.Sonogram = thresholdResults.Sonogram; } // Running profiles with multiple dB thresholds produces nested (Russian doll) events. // Remove all but the outermost event. - combinedResults.NewEvents = CompositeEvent.RemoveEnclosedEvents(combinedResults.NewEvents); + profileResults.NewEvents = CompositeEvent.RemoveEnclosedEvents(profileResults.NewEvents); - Log.Debug($"Profile {profileName}: event count = {combinedResults.NewEvents.Count}"); + // Add additional info to the remaining acoustic events + profileResults.NewEvents.ForEach(ae => + { + ae.FileName = audioRecording.BaseName; + ae.Name = speciesName; + ae.Profile = profileName; + }); + + Log.Debug($"Profile {profileName}: event count = {profileResults.NewEvents.Count}"); + combinedResults.NewEvents.AddRange(profileResults.NewEvents); + combinedResults.Sonogram = spectrogram; } else if (profileConfig is Aed.AedConfiguration ac) { @@ -209,6 +220,15 @@ public static RecognizerResults RunProfiles( // GET THIS TO RETURN BLOB EVENTS. var spectralEvents = Aed.CallAed(spectrogram, ac, segmentStartOffset, audioRecording.Duration).ToList(); + + // Add additional info to the acoustic events + spectralEvents.ForEach(ae => + { + ae.FileName = audioRecording.BaseName; + ae.Name = speciesName; + ae.Profile = profileName; + }); + combinedResults.NewEvents.AddRange(spectralEvents); combinedResults.Sonogram = spectrogram; } @@ -216,18 +236,6 @@ public static RecognizerResults RunProfiles( { throw new InvalidOperationException(); } - - // Add additional info to the acoustic events - combinedResults.NewEvents.ForEach(ae => - { - ae.FileName = audioRecording.BaseName; - ae.Name = speciesName; - ae.Profile = profileName; - - //ae.SegmentDurationSeconds = audioRecording.Duration.TotalSeconds; - //ae.SegmentStartSeconds = segmentStartOffset.TotalSeconds; - //ae.SetTimeAndFreqScales(sonogram.FrameStep, sonogram.FrameDuration, sonogram.FBinWidth); - }); } return combinedResults; diff --git a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizerTests.cs b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizerTests.cs index 19aae3565..9fd409650 100644 --- a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizerTests.cs +++ b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizerTests.cs @@ -43,7 +43,7 @@ public void TestConfigSerialization() var config = new GenericRecognizer.GenericRecognizerConfig() { // set up an array of decibel threhsolds. - DecibelThresholds = new double?[] { 3, 6, 9 }, + //DecibelThresholds = new double?[] { 3, 6, 9 }, Profiles = new Dictionary() { { "TestAed", new Aed.AedConfiguration() { BandpassMinimum = 12345 } }, @@ -91,8 +91,6 @@ public void TestBlobAlgorithm() { var config = new GenericRecognizer.GenericRecognizerConfig() { - // set up an array of decibel threhsolds. - DecibelThresholds = new double?[] { 0.0 }, Profiles = new Dictionary() { { @@ -105,6 +103,9 @@ public void TestBlobAlgorithm() MaxHertz = 7200, BottomHertzBuffer = 1000, TopHertzBuffer = 500, + + // set up an array of decibel threhsolds. + DecibelThresholds = new double?[] { 0.0 }, } }, }, @@ -148,8 +149,6 @@ public void TestOscillationAlgorithm() { var config = new GenericRecognizer.GenericRecognizerConfig() { - // set up an array of decibel threhsolds. - DecibelThresholds = new double?[] { 0.0 }, Profiles = new Dictionary() { { @@ -170,6 +169,7 @@ public void TestOscillationAlgorithm() MinDuration = 4, MaxDuration = 8, EventThreshold = 0.3, + DecibelThresholds = new double?[] { 0.0 }, } }, }, @@ -214,8 +214,6 @@ public void TestWhistleAlgorithm() { var config = new GenericRecognizer.GenericRecognizerConfig() { - // set up an array of decibel threhsolds. - DecibelThresholds = new double?[] { 1.0 }, Profiles = new Dictionary() { { @@ -233,6 +231,7 @@ public void TestWhistleAlgorithm() MinDuration = 4, MaxDuration = 6, SpeciesName = "NoName", + DecibelThresholds = new double?[] { 1.0 }, } }, }, @@ -968,14 +967,13 @@ public void TestAedAlgorithm() }); var config = new GenericRecognizer.GenericRecognizerConfig() { - DecibelThresholds = new double?[] { 0.0 }, - Profiles = new Dictionary() { { "TestAed", new Aed.AedConfiguration() { + //DecibelThresholds = new double?[] { 0.0 }, NoiseReductionType = NoiseReductionType.None, NoiseReductionParameter = 15, SmallAreaThreshold = 150, @@ -1015,7 +1013,6 @@ public void TestMultipleAlgorithms() { var config = new GenericRecognizer.GenericRecognizerConfig() { - DecibelThresholds = new double?[] { 0.0 }, Profiles = new Dictionary() { { @@ -1028,12 +1025,14 @@ public void TestMultipleAlgorithms() BgNoiseThreshold = 0.0, BottomHertzBuffer = 1000, TopHertzBuffer = 500, + DecibelThresholds = new double?[] { 0.0 }, } }, { "LowerBandDTMF_z", new OscillationParameters() { + SpeciesName = "DTMFlower", FrameSize = 512, FrameStep = 512, BgNoiseThreshold = 0.0, @@ -1047,13 +1046,14 @@ public void TestMultipleAlgorithms() MinDuration = 4, MaxDuration = 6, EventThreshold = 0.3, - SpeciesName = "DTMF", + DecibelThresholds = new double?[] { 0.0 }, } }, { "UpperBandDTMF_z", new OscillationParameters() { + SpeciesName = "DTMFupper", FrameSize = 512, FrameStep = 512, BgNoiseThreshold = 0.0, @@ -1067,7 +1067,7 @@ public void TestMultipleAlgorithms() MinDuration = 4, MaxDuration = 6, EventThreshold = 0.3, - SpeciesName = "DTMF", + DecibelThresholds = new double?[] { 0.0 }, } }, }, @@ -1104,21 +1104,24 @@ public void TestMultipleAlgorithms() Assert.AreEqual(7200, @event.HighFrequencyHertz, 0.1); Assert.AreEqual("TestBlob", @event.Profile); Assert.AreEqual(null, @event.Name); + Assert.AreEqual("SpectralEvent", @event.ComponentName); @event = (SpectralEvent)results.NewEvents[1]; 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); + Assert.AreEqual("DTMFlower", @event.Name); Assert.AreEqual("LowerBandDTMF_z", @event.Profile); + Assert.AreEqual("OscillationEvent", @event.ComponentName); + Assert.AreEqual("acoustic_components", @event.FileName); @event = (SpectralEvent)results.NewEvents[2]; Assert.AreEqual(108.1, @event.EventStartSeconds, 0.4); Assert.AreEqual(113.15, @event.EventEndSeconds, 0.5); Assert.AreEqual(1350, @event.LowFrequencyHertz, 0.1); Assert.AreEqual(1650, @event.HighFrequencyHertz, 0.1); - Assert.AreEqual("DTMF", @event.Name); + Assert.AreEqual("DTMFupper", @event.Name); Assert.AreEqual("UpperBandDTMF_z", @event.Profile); } }