Skip to content

Commit

Permalink
Pass decibel threshold to each recognizer.
Browse files Browse the repository at this point in the history
Issue #390 Following on from the previous commit, it was necessary to pass a decibel throld to isse run of a profile.
  • Loading branch information
towsey authored and atruskie committed Nov 1, 2020
1 parent cf30bdf commit 80a36bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
6 changes: 6 additions & 0 deletions src/AnalysisPrograms/Recognizers/GenericRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public static RecognizerResults RunProfiles(
(spectralEvents, decibelPlots) = BlobEvent.GetBlobEvents(
spectrogram,
bp,
decibelThreshold,
segmentStartOffset,
profileName);

Expand All @@ -237,6 +238,7 @@ public static RecognizerResults RunProfiles(
(spectralEvents, decibelPlots) = ForwardTrackAlgorithm.GetForwardTracks(
spectrogram,
tp,
decibelThreshold,
segmentStartOffset,
profileName);

Expand All @@ -248,6 +250,7 @@ public static RecognizerResults RunProfiles(
(spectralEvents, decibelPlots) = OneframeTrackAlgorithm.GetOneFrameTracks(
spectrogram,
cp,
decibelThreshold,
segmentStartOffset,
profileName);

Expand All @@ -259,6 +262,7 @@ public static RecognizerResults RunProfiles(
(spectralEvents, decibelPlots) = UpwardTrackAlgorithm.GetUpwardTracks(
spectrogram,
vtp,
decibelThreshold,
segmentStartOffset,
profileName);

Expand All @@ -270,6 +274,7 @@ public static RecognizerResults RunProfiles(
(spectralEvents, decibelPlots) = HarmonicParameters.GetComponentsWithHarmonics(
spectrogram,
hp,
decibelThreshold,
segmentStartOffset,
profileName);

Expand All @@ -281,6 +286,7 @@ public static RecognizerResults RunProfiles(
(spectralEvents, decibelPlots) = Oscillations2012.GetComponentsWithOscillations(
spectrogram,
op,
decibelThreshold,
segmentStartOffset,
profileName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>()
{
{ "TestAed", new Aed.AedConfiguration() { BandpassMinimum = 12345 } },
{ "TestOscillation", new OscillationParameters() { DecibelThresholds = thresholdArray } },
{ "TestOscillation", new OscillationParameters() },
{ "TestBlob", new BlobParameters() { BottomHertzBuffer = 456 } },
{ "TestWhistle", new OnebinTrackParameters() { TopHertzBuffer = 789 } },
},
Expand Down Expand Up @@ -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<string, object>()
{
{
Expand All @@ -104,7 +105,6 @@ public void TestBlobAlgorithm()
MaxHertz = 7200,
BottomHertzBuffer = 1000,
TopHertzBuffer = 500,
DecibelThresholds = new double?[] { 0.0 },
}
},
},
Expand Down Expand Up @@ -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<string, object>()
{
{
Expand All @@ -168,7 +170,6 @@ public void TestOscillationAlgorithm()
MinDuration = 4,
MaxDuration = 8,
EventThreshold = 0.3,
DecibelThresholds = new double?[] { 0.0 },
}
},
},
Expand Down Expand Up @@ -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<string, object>()
{
{
Expand All @@ -229,7 +232,6 @@ public void TestWhistleAlgorithm()
TopHertzBuffer = 0,
MinDuration = 4,
MaxDuration = 6,
DecibelThresholds = new double?[] { 1.0 },
SpeciesName = "NoName",
}
},
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -515,6 +507,7 @@ public void TestForwardTrackAlgorithm()
var (spectralEvents, plotList) = ForwardTrackAlgorithm.GetForwardTracks(
spectrogram,
parameters,
decibelThreshold,
segmentStartOffset,
"TestProfile");

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -595,6 +588,7 @@ public void TestOneframeTrackAlgorithm()
var (spectralEvents, plotList) = OneframeTrackAlgorithm.GetOneFrameTracks(
spectrogram,
parameters,
decibelThreshold,
segmentStartOffset,
"TestProfile");

Expand Down Expand Up @@ -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,
Expand All @@ -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<Plot>();
var (spectralEvents, plotList) = UpwardTrackAlgorithm.GetUpwardTracks(
spectrogram,
parameters,
decibelThreshold,
segmentStartOffset,
"TestProfile");

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -766,6 +762,7 @@ public void Test2UpwardsTrackAlgorithm()
var (spectralEvents, plotList) = UpwardTrackAlgorithm.GetUpwardTracks(
spectrogram,
parameters,
decibelThreshold,
segmentStartOffset,
"TestProfile");

Expand Down Expand Up @@ -1016,6 +1013,7 @@ public void TestMultipleAlgorithms()
{
var config = new GenericRecognizer.GenericRecognizerConfig()
{
DecibelThresholds = new double?[] { 0.0 },
Profiles = new Dictionary<string, object>()
{
{
Expand All @@ -1028,7 +1026,6 @@ public void TestMultipleAlgorithms()
BgNoiseThreshold = 0.0,
BottomHertzBuffer = 1000,
TopHertzBuffer = 500,
DecibelThresholds = new double?[] { 0.0 },
}
},
{
Expand All @@ -1049,7 +1046,6 @@ public void TestMultipleAlgorithms()
MaxDuration = 6,
EventThreshold = 0.3,
SpeciesName = "DTMF",
DecibelThresholds = new double?[] { 0.0 },
}
},
{
Expand All @@ -1070,7 +1066,6 @@ public void TestMultipleAlgorithms()
MaxDuration = 6,
EventThreshold = 0.3,
SpeciesName = "DTMF",
DecibelThresholds = new double?[] { 0.0 },
}
},
},
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 80a36bd

Please sign in to comment.