Skip to content

Commit

Permalink
Finish Unit tests for Flying FOx class
Browse files Browse the repository at this point in the history
Issue #238 Complete two tests of methods used in the Flying Fox recogniser.
  • Loading branch information
towsey committed Sep 1, 2019
1 parent 70caaaf commit 1228b46
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 49 deletions.
3 changes: 2 additions & 1 deletion src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ public static void Audio2CsvOverOneFile()
// FLYING FOX RECORDINGS
//string recordingPath = @"C:\Ecoacoustics\WavFiles\BradLawData\FlyingFox\20190127_Bellingen_Feeding_SM4.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding.wav";
string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding_minute6.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding_minute6.wav";
string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding_minute6_OneChannel22050.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190121_2_Bellingen_Feeding.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190127_Bellingen_Feeding_SM4.wav";
string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\RecognizerConfigFiles\Towsey.PteropusSpecies.yml";
Expand Down
5 changes: 5 additions & 0 deletions src/AudioAnalysisTools/AcousticEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ public static Oblong ConvertEvent2Oblong(AcousticEvent ae)
return new Oblong(topRow, leftCol, bottomRow, rightCol);
}

/// <summary>
/// Should check that Oblong is not null before calling this method.
/// </summary>
public Rectangle GetEventAsRectangle() => new Rectangle(this.Oblong.ColumnLeft, this.Oblong.RowTop, this.Oblong.ColWidth, this.Oblong.RowWidth);

/// <summary>
/// Sets the passed score and also a value normalised between a min and a max.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ namespace Acoustics.Test.AnalysisPrograms.Recognizers.PteropusSp
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using Acoustics.Shared;
using Acoustics.Shared.ConfigFile;
using Acoustics.Test.TestHelpers;
using Acoustics.Tools.Wav;
using global::AnalysisPrograms.Recognizers;
using global::AudioAnalysisTools;
using global::AudioAnalysisTools.DSP;
using global::AudioAnalysisTools.EventStatistics;
using global::AudioAnalysisTools.StandardSpectrograms;
using global::AudioAnalysisTools.WavTools;
using global::TowseyLibrary;
Expand All @@ -28,6 +27,12 @@ public class PteropusSpTests
private AudioRecording audioRecording;
private BaseSonogram sonogram;

/// <summary>
/// The one-minute recording used for these tests was originally recorded at 40kHz in two channels.
/// It was resampled to 22050 in one channel using Audacity for these tests.
/// The number of wing-beat and call events is somewhat sensitive to parameter settings.
/// With test settings get and extra call event.
/// </summary>
[TestInitialize]
public void Setup()
{
Expand All @@ -40,7 +45,7 @@ public void Setup()
NoiseReductionParameter = 3.0,
WindowOverlap = 0.0,
};
this.sonogram = (BaseSonogram)new SpectrogramStandard(sonoConfig, this.audioRecording.WavReader);
this.sonogram = new SpectrogramStandard(sonoConfig, this.audioRecording.WavReader);
}

[TestCleanup]
Expand Down Expand Up @@ -112,11 +117,11 @@ public void TestGetEventsAroundMaxima()
{
//string abbreviatedSpeciesName = "Pteropus";
string speciesName = "Pteropus species";
var minTimeSpan = TimeSpan.FromSeconds(0.1);
var maxTimeSpan = TimeSpan.FromSeconds(10.0);
double decibelThreshold = 0.5;
int minHz = 100;
int maxHz = 3000;
int minHz = 800;
int maxHz = 8000;
var minTimeSpan = TimeSpan.FromSeconds(0.15);
var maxTimeSpan = TimeSpan.FromSeconds(0.8);
double decibelThreshold = 9.0;
TimeSpan segmentStartOffset = TimeSpan.Zero;

var decibelArray = SNR.CalculateFreqBandAvIntensity(this.sonogram.Data, minHz, maxHz, this.sonogram.NyquistFrequency);
Expand All @@ -140,47 +145,13 @@ public void TestGetEventsAroundMaxima()
this.sonogram.FramesPerSecond,
this.sonogram.FBinWidth);

Assert.AreEqual(8, acousticEvents.Count);
Assert.AreEqual(10, acousticEvents.Count);

Assert.AreEqual(19, acousticEvents[0].Oblong.ColumnLeft);
Assert.AreEqual(186, acousticEvents[0].Oblong.ColumnRight);
Assert.AreEqual(1280, acousticEvents[0].Oblong.RowTop);
Assert.AreEqual(1380, acousticEvents[0].Oblong.RowBottom);

Assert.AreEqual(19, acousticEvents[1].Oblong.ColumnLeft);
Assert.AreEqual(186, acousticEvents[1].Oblong.ColumnRight);
Assert.AreEqual(1762, acousticEvents[1].Oblong.RowTop);
Assert.AreEqual(1825, acousticEvents[1].Oblong.RowBottom);

Assert.AreEqual(19, acousticEvents[2].Oblong.ColumnLeft);
Assert.AreEqual(186, acousticEvents[2].Oblong.ColumnRight);
Assert.AreEqual(2083, acousticEvents[2].Oblong.RowTop);
Assert.AreEqual(2207, acousticEvents[2].Oblong.RowBottom);

Assert.AreEqual(19, acousticEvents[3].Oblong.ColumnLeft);
Assert.AreEqual(186, acousticEvents[3].Oblong.ColumnRight);
Assert.AreEqual(2334, acousticEvents[3].Oblong.RowTop);
Assert.AreEqual(2382, acousticEvents[3].Oblong.RowBottom);

Assert.AreEqual(19, acousticEvents[4].Oblong.ColumnLeft);
Assert.AreEqual(186, acousticEvents[4].Oblong.ColumnRight);
Assert.AreEqual(1280, acousticEvents[4].Oblong.RowTop);
Assert.AreEqual(1380, acousticEvents[4].Oblong.RowBottom);

Assert.AreEqual(19, acousticEvents[5].Oblong.ColumnLeft);
Assert.AreEqual(186, acousticEvents[5].Oblong.ColumnRight);
Assert.AreEqual(1762, acousticEvents[5].Oblong.RowTop);
Assert.AreEqual(1825, acousticEvents[5].Oblong.RowBottom);

Assert.AreEqual(19, acousticEvents[6].Oblong.ColumnLeft);
Assert.AreEqual(186, acousticEvents[6].Oblong.ColumnRight);
Assert.AreEqual(2083, acousticEvents[6].Oblong.RowTop);
Assert.AreEqual(2207, acousticEvents[6].Oblong.RowBottom);

Assert.AreEqual(19, acousticEvents[7].Oblong.ColumnLeft);
Assert.AreEqual(186, acousticEvents[7].Oblong.ColumnRight);
Assert.AreEqual(2334, acousticEvents[7].Oblong.RowTop);
Assert.AreEqual(2382, acousticEvents[7].Oblong.RowBottom);
Assert.AreEqual(new Rectangle(19, 1751, 168, 27), acousticEvents[0].GetEventAsRectangle());
Assert.AreEqual(new Rectangle(19, 1840, 168, 10), acousticEvents[2].GetEventAsRectangle());
Assert.AreEqual(new Rectangle(19, 1961, 168, 31), acousticEvents[5].GetEventAsRectangle());
Assert.AreEqual(new Rectangle(19, 2294, 168, 17), acousticEvents[7].GetEventAsRectangle());
Assert.AreEqual(new Rectangle(19, 2504, 168, 7), acousticEvents[9].GetEventAsRectangle());

//Assert.AreEqual(28.Seconds() + segmentOffset, stats.ResultStartSeconds.Seconds());
}
Expand Down

0 comments on commit 1228b46

Please sign in to comment.