Skip to content

Commit

Permalink
Update GenericRecognizerTests.cs
Browse files Browse the repository at this point in the history
Issue #370 Start process of getting the Test class for Generic recognizers to accept the new array of decibel thresholds. Next step is to ensure those tests pass.
  • Loading branch information
towsey authored and atruskie committed Oct 14, 2020
1 parent 5fb425d commit 55fda89
Showing 1 changed file with 32 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void TestConfigSerialization()
Profiles = new Dictionary<string, object>()
{
{ "TestAed", new Aed.AedConfiguration() { BandpassMinimum = 12345 } },
{ "TestOscillation", new OscillationParameters() { DecibelThreshold = 123 } },
{ "TestOscillation", new OscillationParameters() { DecibelThresholds = new double?[] { 123.0 } } },
{ "TestBlob", new BlobParameters() { BottomHertzBuffer = 456 } },
{ "TestWhistle", new OnebinTrackParameters() { TopHertzBuffer = 789 } },
},
Expand Down Expand Up @@ -76,7 +76,7 @@ public void TestConfigSerialization()
Assert.IsInstanceOfType(config2.Profiles["TestWhistle"], typeof(OnebinTrackParameters));

Assert.AreEqual((config2.Profiles["TestAed"] as Aed.AedConfiguration)?.BandpassMinimum, 12345);
Assert.AreEqual((config2.Profiles["TestOscillation"] as OscillationParameters)?.DecibelThreshold, 123);
Assert.AreEqual((config2.Profiles["TestOscillation"] as OscillationParameters)?.DecibelThresholds, 123);
Assert.AreEqual((config2.Profiles["TestBlob"] as BlobParameters)?.BottomHertzBuffer, 456);
Assert.AreEqual((config2.Profiles["TestWhistle"] as OnebinTrackParameters)?.TopHertzBuffer, 789);
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public void TestWhistleAlgorithm()
TopHertzBuffer = 0,
MinDuration = 4,
MaxDuration = 6,
DecibelThreshold = 1.0,
DecibelThresholds = new double?[] { 1.0 },
SpeciesName = "NoName",
}
},
Expand Down Expand Up @@ -331,8 +331,9 @@ public void TestOnebinTrackAlgorithm()
MaxHertz = 6000,
MinDuration = 0.2,
MaxDuration = 1.1,
DecibelThreshold = 2.0,
DecibelThresholds = new double?[] { 2.0 },
CombinePossibleSyllableSequence = false,

//SyllableStartDifference = TimeSpan.FromSeconds(0.2),
//SyllableHertzGap = 300,
};
Expand Down Expand Up @@ -360,18 +361,15 @@ public void TestOnebinTrackAlgorithm()
//var image1 = SpectrogramTools.GetSonogramPlusCharts(spectrogram, null, null, null);
//results.Sonogram.GetImage().Save(this.outputDirectory + "\\debug.png");

var plots = new List<Plot>();
var (spectralEvents, dBArray) = OnebinTrackAlgorithm.GetOnebinTracks(
var (spectralEvents, plotList) = OnebinTrackAlgorithm.GetOnebinTracks(
spectrogram,
parameters,
segmentStartOffset);
segmentStartOffset,
"TestProfile");

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 5 * parameters.DecibelThreshold.Value;
var dBThreshold = parameters.DecibelThreshold.Value / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot1 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
plots.Add(plot1);
var plots = new List<Plot>();
plots.AddRange(plotList);

var allResults = new RecognizerResults()
{
Expand Down Expand Up @@ -424,7 +422,7 @@ public void TestForwardTrackAlgorithm()
MaxHertz = 6000,
MinDuration = 0.2,
MaxDuration = 1.1,
DecibelThreshold = 2.0,
DecibelThresholds = new double?[] { 2.0 },
CombinePossibleHarmonics = false,
HarmonicsStartDifference = TimeSpan.FromSeconds(0.2),
HarmonicsHertzGap = 200,
Expand Down Expand Up @@ -456,18 +454,14 @@ public void TestForwardTrackAlgorithm()
//results.Sonogram.GetImage().Save(this.outputDirectory + "\\debug.png");

var segmentStartOffset = TimeSpan.Zero;
var plots = new List<Plot>();
var (spectralEvents, dBArray) = ForwardTrackAlgorithm.GetForwardTracks(
var (spectralEvents, plotList) = ForwardTrackAlgorithm.GetForwardTracks(
spectrogram,
parameters,
segmentStartOffset);
segmentStartOffset,
"TestProfile");

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 5 * parameters.DecibelThreshold.Value;
var dBThreshold = parameters.DecibelThreshold.Value / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot1 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
plots.Add(plot1);
var plots = new List<Plot>();
plots.AddRange(plotList);

var allResults = new RecognizerResults()
{
Expand Down Expand Up @@ -514,7 +508,7 @@ public void TestOneframeTrackAlgorithm()
MaxHertz = 11000,
MinBandwidthHertz = 100,
MaxBandwidthHertz = 5000,
DecibelThreshold = 2.0,
DecibelThresholds = new double?[] { 2.0 },
};

//Set up the virtual recording.
Expand All @@ -540,18 +534,14 @@ public void TestOneframeTrackAlgorithm()
//results.Sonogram.GetImage().Save(this.outputDirectory + "\\debug.png");

var segmentStartOffset = TimeSpan.Zero;
var plots = new List<Plot>();
var (spectralEvents, dBArray) = OneframeTrackAlgorithm.GetOneFrameTracks(
var (spectralEvents, plotList) = OneframeTrackAlgorithm.GetOneFrameTracks(
spectrogram,
parameters,
segmentStartOffset);
segmentStartOffset,
"TestProfile");

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 5 * parameters.DecibelThreshold.Value;
var dBThreshold = parameters.DecibelThreshold.Value / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot1 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
plots.Add(plot1);
var plots = new List<Plot>();
plots.AddRange(plotList);

var allResults = new RecognizerResults()
{
Expand Down Expand Up @@ -601,7 +591,7 @@ public void Test1UpwardsTrackAlgorithm()
MaxHertz = 11000,
MinBandwidthHertz = 100,
MaxBandwidthHertz = 5000,
DecibelThreshold = 2.0,
DecibelThresholds = new double?[] { 2.0 },
CombineProximalSimilarEvents = true,
SyllableStartDifference = TimeSpan.FromSeconds(0.2),
SyllableHertzDifference = 300,
Expand Down Expand Up @@ -631,17 +621,13 @@ public void Test1UpwardsTrackAlgorithm()

var segmentStartOffset = TimeSpan.Zero;
var plots = new List<Plot>();
var (spectralEvents, dBArray) = UpwardTrackAlgorithm.GetUpwardTracks(
var (spectralEvents, plotList) = UpwardTrackAlgorithm.GetUpwardTracks(
spectrogram,
parameters,
segmentStartOffset);
segmentStartOffset,
"TestProfile");

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 5 * parameters.DecibelThreshold.Value;
var dBThreshold = parameters.DecibelThreshold.Value / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot1 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
plots.Add(plot1);
plots.AddRange(plotList);

var allResults = new RecognizerResults()
{
Expand Down Expand Up @@ -691,7 +677,7 @@ public void Test2UpwardsTrackAlgorithm()
MaxHertz = 6000,
MinBandwidthHertz = 200,
MaxBandwidthHertz = 5000,
DecibelThreshold = 2.0,
DecibelThresholds = new double?[] { 2.0 },
CombineProximalSimilarEvents = false,
SyllableStartDifference = TimeSpan.FromSeconds(0.2),
SyllableHertzDifference = 300,
Expand Down Expand Up @@ -719,17 +705,14 @@ public void Test2UpwardsTrackAlgorithm()
var plots = new List<Plot>();

// do a SECOND TEST of the vertical tracks
var (spectralEvents, dBArray) = UpwardTrackAlgorithm.GetUpwardTracks(
var (spectralEvents, plotList) = UpwardTrackAlgorithm.GetUpwardTracks(
spectrogram,
parameters,
segmentStartOffset);
segmentStartOffset,
"TestProfile");

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 5 * parameters.DecibelThreshold.Value;
var dBThreshold = parameters.DecibelThreshold.Value / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot2 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
plots.Add(plot2);
plots.AddRange(plotList);

var allResults2 = new RecognizerResults()
{
Expand Down

0 comments on commit 55fda89

Please sign in to comment.