Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
Related to work michael was doing with new event classes.

Also moved event paramters to audio analysis tools to simplify function invocation.

Workd done for #310
  • Loading branch information
atruskie committed Apr 22, 2020
1 parent 08a8645 commit 9ce3db6
Show file tree
Hide file tree
Showing 49 changed files with 476 additions and 505 deletions.
40 changes: 22 additions & 18 deletions src/AnalysisPrograms/AED.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,34 @@ public static SpectralEvent[] CallAed(BaseSonogram sonogram, AedConfiguration ae
IEnumerable<Oblong> oblongs = AcousticEventDetection.detectEvents(aedOptions, sonogram.Data);
Log.Info("AED finished");

var unitConverters = new UnitConverters(
segmentStartOffset.TotalSeconds,
sonogram.SampleRate,
sonogram.Configuration.WindowSize,
sonogram.Configuration.WindowOverlap);

var events = oblongs.Select(
o =>
{
if (!aedConfiguration.IncludeHitElementsInOutput)
var blob = new BlobEvent()
{
o.HitElements = null;
SegmentDurationSeconds = segmentDuration.TotalSeconds,
Name = "AED Event",
};

unitConverters.SetBounds(blob, o);

if (aedConfiguration.IncludeHitElementsInOutput)
{
o.HitElements
.Select(p => unitConverters.ConvertPointToSpectralPoint(p, 1.0))
.ForEach(sp => blob.Points.Add(sp));
}

var ae = AcousticEvent.InitializeAcousticEvent(
segmentStartOffset,
o,
sonogram.NyquistFrequency,
sonogram.Configuration.FreqBinCount,
sonogram.FrameDuration,
sonogram.FrameStep,
sonogram.FrameCount);

ae.BorderColour = aedConfiguration.AedEventColor;
ae.HitColour = aedConfiguration.AedHitColor;
ae.SegmentDurationSeconds = segmentDuration.TotalSeconds;

return EventConverters.ConvertAcousticEventToSpectralEvent(ae);
}).ToArray();
return events;
return blob;
});

return events.ToArray();
}

public static Image DrawSonogram(BaseSonogram sonogram, IEnumerable<SpectralEvent> events)
Expand Down
10 changes: 6 additions & 4 deletions src/AnalysisPrograms/GroundParrotRecogniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace AnalysisPrograms
using AnalysisPrograms.Production;
using AnalysisPrograms.Production.Arguments;
using AudioAnalysisTools;
using AudioAnalysisTools.Events;
using AudioAnalysisTools.Events.Types;
using AudioAnalysisTools.StandardSpectrograms;
using AudioAnalysisTools.WavTools;
using log4net;
Expand Down Expand Up @@ -129,9 +131,9 @@ public override Task<int> Execute(CommandLineApplication app)
/// </returns>
public static Tuple<BaseSonogram, List<AcousticEvent>> Detect(FileInfo wavFilePath, Aed.AedConfiguration aedConfiguration, double eprNormalisedMinScore, TimeSpan segmentStartOffset)
{
Tuple<AcousticEvent[], AudioRecording, BaseSonogram> aed = Aed.Detect(wavFilePath, aedConfiguration, segmentStartOffset);
Tuple<SpectralEvent[], AudioRecording, BaseSonogram> aed = Aed.Detect(wavFilePath, aedConfiguration, segmentStartOffset);

var events = aed.Item1.Select(ae => Util.fcornersToRect(ae.TimeStart, ae.TimeEnd, ae.HighFrequencyHertz, ae.LowFrequencyHertz)).ToList();
var events = aed.Item1.Select(se => se.ConvertSpectralEventToAcousticEvent()).Select(ae => Util.fcornersToRect(ae.TimeStart, ae.TimeEnd, ae.HighFrequencyHertz, ae.LowFrequencyHertz)).ToList();

Log.Debug("EPR start");

Expand Down Expand Up @@ -198,7 +200,7 @@ public static void Execute(Arguments arguments)
string wavFilePath = input.FullName;
BaseSonogram sonogram = result.Item1;
string imagePath = Path.Combine(outputFolder, Path.GetFileNameWithoutExtension(wavFilePath) + ".png");
var image = Aed.DrawSonogram(sonogram, eprEvents);
var image = Aed.DrawSonogram(sonogram, eprEvents.ConvertAcousticEventsToSpectralEvents());
image.Save(imagePath);

//ProcessingTypes.SaveAeCsv(eprEvents, outputFolder, wavFilePath);
Expand Down Expand Up @@ -309,7 +311,7 @@ public override AnalysisResult2 Analyze<T>(AnalysisSettings analysisSettings, Se
// save image of sonograms
if (analysisSettings.AnalysisImageSaveBehavior.ShouldSave(analysisResults.Events.Length))
{
Image image = Aed.DrawSonogram(sonogram, results.Item2);
Image image = Aed.DrawSonogram(sonogram, results.Item2.ConvertAcousticEventsToSpectralEvents());
image.Save(segmentSettings.SegmentImageFile.FullName);
analysisResults.ImageFile = segmentSettings.SegmentImageFile;
}
Expand Down
5 changes: 4 additions & 1 deletion src/AnalysisPrograms/KoalaMale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace AnalysisPrograms
using AnalysisBase.ResultBases;
using AudioAnalysisTools;
using AudioAnalysisTools.DSP;
using AudioAnalysisTools.Events.Types;
using AudioAnalysisTools.StandardSpectrograms;
using AudioAnalysisTools.WavTools;
using SixLabors.ImageSharp;
Expand Down Expand Up @@ -166,10 +167,12 @@ public static KoalaMaleResults Analysis(AudioRecording recording, IDictionary<st
minDuration,
maxDuration,
out var scores,
out var events,
out var oscillationEvents,
out var hits,
segmentStartOffset);

var events = oscillationEvents.ConvertSpectralEventsToAcousticEvents();

// remove isolated koala events - this is to remove false positive identifications
events = FilterMaleKoalaEvents(events);

Expand Down
129 changes: 0 additions & 129 deletions src/AnalysisPrograms/Recognizers/Base/ForwardTrackParameters.cs

This file was deleted.

11 changes: 3 additions & 8 deletions src/AnalysisPrograms/Recognizers/Base/RecognizerResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public RecognizerResults()
this.Plots = new List<Plot>();
}

public List<AcousticEvent> Events { get; set; }
public List<AcousticEvent> Events { get; set; } = new List<AcousticEvent>();

public List<EventCommon> NewEvents { get; set; }
public List<EventCommon> NewEvents { get; set; } = new List<EventCommon>();

public double[,] Hits { get; set; }

Expand Down Expand Up @@ -60,12 +60,7 @@ public List<Plot> Plots

set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value), "Cannot be set to null");
}

this.plots = value;
this.plots = value ?? throw new ArgumentNullException(nameof(value), "Cannot be set to null");
}
}
}
Expand Down
57 changes: 0 additions & 57 deletions src/AnalysisPrograms/Recognizers/Base/RecognizerResults2.cs

This file was deleted.

5 changes: 4 additions & 1 deletion src/AnalysisPrograms/Recognizers/CycloranaNovaehollandiae.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace AnalysisPrograms.Recognizers
using AnalysisPrograms.Recognizers.Base;
using AudioAnalysisTools;
using AudioAnalysisTools.DSP;
using AudioAnalysisTools.Events.Types;
using AudioAnalysisTools.Indices;
using AudioAnalysisTools.StandardSpectrograms;
using AudioAnalysisTools.WavTools;
Expand Down Expand Up @@ -164,10 +165,12 @@ public override RecognizerResults Recognize(
maxDuration,
scoreSmoothingWindow,
out var scores,
out var acousticEvents,
out var oscillationEvents,
out var hits,
segmentStartOffset);

var acousticEvents = oscillationEvents.ConvertSpectralEventsToAcousticEvents();

acousticEvents.ForEach(
ae =>
{
Expand Down
Loading

0 comments on commit 9ce3db6

Please sign in to comment.