Skip to content

Commit

Permalink
Get code to build after major rework re scores and track drawing etc
Browse files Browse the repository at this point in the history
Issue#297 Still not unit tested.
  • Loading branch information
towsey committed Apr 27, 2020
1 parent 3bfd4c8 commit 269edd1
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 44 deletions.
30 changes: 8 additions & 22 deletions src/AnalysisPrograms/Recognizers/GenericRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace AnalysisPrograms.Recognizers
using AudioAnalysisTools.Events.Types;
using AudioAnalysisTools.Indices;
using AudioAnalysisTools.StandardSpectrograms;
using AudioAnalysisTools.Tracks;
using AudioAnalysisTools.WavTools;
using log4net;
using SixLabors.ImageSharp;
Expand Down Expand Up @@ -194,14 +195,9 @@ public override RecognizerResults Recognize(
{
//get the array of intensity values minus intensity in side/buffer bands.
double[] decibelArray;
(spectralEvents, decibelArray) = OnebinTrackParameters.GetOnebinTracks(
(spectralEvents, decibelArray) = OnebinTrackAlgorithm.GetOnebinTracks(
sonogram,
wp.MinHertz.Value,
wp.MaxHertz.Value,
wp.DecibelThreshold.Value,
wp.MinDuration.Value,
wp.MaxDuration.Value,
wp.CombinePossibleSequence,
wp,
segmentStartOffset);

var plot = PreparePlot(decibelArray, $"{profileName} (Whistle:dB Intensity)", wp.DecibelThreshold.Value);
Expand All @@ -210,7 +206,7 @@ public override RecognizerResults Recognize(
else if (profileConfig is ForwardTrackParameters tp)
{
double[] decibelArray;
(spectralEvents, decibelArray) = TrackExtractor.GetForwardTracks(
(spectralEvents, decibelArray) = ForwardTrackAlgorithm.GetForwardTracks(
sonogram,
tp,
segmentStartOffset);
Expand All @@ -221,14 +217,9 @@ public override RecognizerResults Recognize(
else if (profileConfig is OneframeTrackParameters cp)
{
double[] decibelArray;
(spectralEvents, decibelArray) = OneframeTrackParameters.GetOneFrameTracks(
(spectralEvents, decibelArray) = OneframeTrackAlgorithm.GetOneFrameTracks(
sonogram,
cp.MinHertz.Value,
cp.MaxHertz.Value,
cp.DecibelThreshold.Value,
cp.MinBandwidthHertz.Value,
cp.MaxBandwidthHertz.Value,
cp.CombineProximalSimilarEvents,
cp,
segmentStartOffset);

var plot = PreparePlot(decibelArray, $"{profileName} (Clicks:dB Intensity)", cp.DecibelThreshold.Value);
Expand All @@ -237,14 +228,9 @@ public override RecognizerResults Recognize(
else if (profileConfig is UpwardTrackParameters vtp)
{
double[] decibelArray;
(spectralEvents, decibelArray) = UpwardTrackParameters.GetUpwardTracks(
(spectralEvents, decibelArray) = UpwardTrackAlgorithm.GetUpwardTracks(
sonogram,
vtp.MinHertz.Value,
vtp.MaxHertz.Value,
vtp.DecibelThreshold.Value,
vtp.MinBandwidthHertz.Value,
vtp.MaxBandwidthHertz.Value,
vtp.CombineProximalSimilarEvents,
vtp,
segmentStartOffset);

var plot = PreparePlot(decibelArray, $"{profileName} (VerticalTrack:dB Intensity)", vtp.DecibelThreshold.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ public EventRenderingOptions(UnitConverters converters)
/// <summary>
/// Gets or sets the default fille color for an event.
/// </summary>
public IBrush Fill { get; set; } = new SolidBrush(Color.Red.WithAlpha(0.5f));
public IBrush Fill { get; set; } = new SolidBrush(Color.FromRgb(0, 255, 0));

/// <summary>
/// Gets or sets the graphics options that should be used with the
/// <see cref="Fill"/> brush for rendering the contents of an event.
/// </summary>
public GraphicsOptions FillOptions { get; set; } = new GraphicsOptions()
{
ColorBlendingMode = SixLabors.ImageSharp.PixelFormats.PixelColorBlendingMode.Lighten,

// TODO: ENABLE THIS IS NECESSARY
// BlendPercentage = 0.5,
};

/// <summary>
Expand Down
20 changes: 15 additions & 5 deletions src/AudioAnalysisTools/Events/Types/ChirpEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class ChirpEvent : SpectralEvent, ITracks<Track>
public ChirpEvent(Track chirp, double maxScore)
{
this.Tracks.Add(chirp);

this.maxScore = maxScore;
}

Expand All @@ -49,17 +48,28 @@ public ChirpEvent(Track chirp, double maxScore)
this.Tracks.Max(x => x.HighFreqHertz);

/// <summary>
/// Gets the average normalised amplitude.
/// Gets the average track amplitude.
/// </summary>
/// <remarks>
/// This score is a normalised value for the chirp's track score.
/// NOTE: It is assumed that the minimum value of the score range = zero.
/// Thevent score is an average value of the track score.
/// </remarks>
public override double Score
{
get
{
return this.Tracks.Single().GetAverageTrackAmplitude() / this.maxScore;
return this.Tracks.Single().GetAverageTrackAmplitude();
}
}

/// <summary>
/// Gets the normalised value for the event's track score.
/// NOTE: It is assumed that the minimum value of the score range = zero.
/// </summary>
public double ScoreNormalised
{
get
{
return this.Score / this.maxScore;
}
}

Expand Down
31 changes: 30 additions & 1 deletion src/AudioAnalysisTools/Events/Types/ClickEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ namespace AudioAnalysisTools

public class ClickEvent : SpectralEvent, ITracks<Track>
{
public ClickEvent(Track click)
private readonly double maxScore;

public ClickEvent(Track click, double maxScore)
{
this.Tracks.Add(click);
this.maxScore = maxScore;
}

public List<Track> Tracks { get; private set; } = new List<Track>(1);
Expand All @@ -34,6 +37,32 @@ public ClickEvent(Track click)
public override double HighFrequencyHertz =>
this.Tracks.Max(x => x.HighFreqHertz);

/// <summary>
/// Gets the average track amplitude.
/// </summary>
/// <remarks>
/// Thevent score is an average value of the track score.
/// </remarks>
public override double Score
{
get
{
return this.Tracks.Single().GetAverageTrackAmplitude();
}
}

/// <summary>
/// Gets the normalised value for the event's track score.
/// NOTE: It is assumed that the minimum value of the score range = zero.
/// </summary>
public double ScoreNormalised
{
get
{
return this.Score / this.maxScore;
}
}

public override void Draw(IImageProcessingContext graphics, EventRenderingOptions options)
{
// foreach (var track in tracks) {
Expand Down
31 changes: 30 additions & 1 deletion src/AudioAnalysisTools/Events/Types/WhipEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ namespace AudioAnalysisTools

public class WhipEvent : SpectralEvent, ITracks<Track>
{
public WhipEvent(Track whip)
private readonly double maxScore;

public WhipEvent(Track whip, double maxScore)
{
this.Tracks.Add(whip);
this.maxScore = maxScore;
}

public List<Track> Tracks { get; private set; } = new List<Track>(1);
Expand All @@ -34,6 +37,32 @@ public WhipEvent(Track whip)
public override double HighFrequencyHertz =>
this.Tracks.Max(x => x.HighFreqHertz);

/// <summary>
/// Gets the average track amplitude.
/// </summary>
/// <remarks>
/// Thevent score is an average value of the track score.
/// </remarks>
public override double Score
{
get
{
return this.Tracks.Single().GetAverageTrackAmplitude();
}
}

/// <summary>
/// Gets the normalised value for the event's track score.
/// NOTE: It is assumed that the minimum value of the score range = zero.
/// </summary>
public double ScoreNormalised
{
get
{
return this.Score / this.maxScore;
}
}

public override void Draw(IImageProcessingContext graphics, EventRenderingOptions options)
{
// foreach (var track in tracks) {
Expand Down
31 changes: 30 additions & 1 deletion src/AudioAnalysisTools/Events/Types/WhistleEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ namespace AudioAnalysisTools

public class WhistleEvent : SpectralEvent, ITracks<Track>
{
public WhistleEvent(Track whistle)
private readonly double maxScore;

public WhistleEvent(Track whistle, double maxScore)
{
this.Tracks.Add(whistle);
this.maxScore = maxScore;
}

public List<Track> Tracks { get; private set; } = new List<Track>(1);
Expand All @@ -34,6 +37,32 @@ public WhistleEvent(Track whistle)
public override double HighFrequencyHertz =>
this.Tracks.Max(x => x.HighFreqHertz);

/// <summary>
/// Gets the average track amplitude.
/// </summary>
/// <remarks>
/// Thevent score is an average value of the track score.
/// </remarks>
public override double Score
{
get
{
return this.Tracks.Single().GetAverageTrackAmplitude();
}
}

/// <summary>
/// Gets the normalised value for the event's track score.
/// NOTE: It is assumed that the minimum value of the score range = zero.
/// </summary>
public double ScoreNormalised
{
get
{
return this.Score / this.maxScore;
}
}

public override void Draw(IImageProcessingContext graphics, EventRenderingOptions options)
{
// foreach (var track in tracks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public static Image<Rgb24> GetSonogramPlusCharts(
foreach (SpectralEvent ev in events)
{
var options = new EventRenderingOptions(new UnitConverters(segmentStartTime.TotalSeconds, segmentDuration.TotalSeconds, nyquist, width, height));

spectrogram.Mutate(x => ev.Draw(x, options));
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/AudioAnalysisTools/Tracks/ForwardTrackAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public static (List<EventCommon> Events, double[] CombinedIntensity) GetForwardT
double maxDuration = parameters.MaxDuration.Value;
double decibelThreshold = parameters.DecibelThreshold.Value;

double maxScore = parameters.MaxScore.Value;

var converter = new UnitConverters(
segmentStartOffset: segmentStartOffset.TotalSeconds,
sampleRate: sonogram.SampleRate,
Expand Down Expand Up @@ -75,6 +73,7 @@ public static (List<EventCommon> Events, double[] CombinedIntensity) GetForwardT
var combinedIntensityArray = new double[frameCount];
foreach (var track in tracks)
{
var maxScore = decibelThreshold * 5;
var ae = new ChirpEvent(track, maxScore)
{
SegmentDurationSeconds = frameCount * converter.StepSize,
Expand Down
3 changes: 2 additions & 1 deletion src/AudioAnalysisTools/Tracks/OnebinTrackAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ public static (List<EventCommon> ListOfevents, double[] CombinedIntensityArray)
// initialise tracks as events and get the combined intensity array.
var events = new List<EventCommon>();
var combinedIntensityArray = new double[frameCount];
var maxScore = decibelThreshold * 5;
foreach (var track in tracks)
{
var ae = new WhistleEvent(track)
var ae = new WhistleEvent(track, maxScore)
{
SegmentDurationSeconds = frameCount * converter.StepSize,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace AudioAnalysisTools.Tracks
{
using System;
using System.Collections.Generic;
using System.Text;
using AnalysisPrograms.Recognizers.Base;
using AudioAnalysisTools.Events;
using AudioAnalysisTools.Events.Tracks;
Expand Down Expand Up @@ -76,9 +75,10 @@ public static (List<EventCommon> Events, double[] Intensity) GetOneFrameTracks(
// initialise tracks as events and get the combined intensity array.
var events = new List<EventCommon>();
var temporalIntensityArray = new double[frameCount];
var maxScore = decibelThreshold * 5;
foreach (var track in tracks)
{
var ae = new ClickEvent(track)
var ae = new ClickEvent(track, maxScore)
{
SegmentDurationSeconds = frameCount * frameStep,
};
Expand Down
3 changes: 2 additions & 1 deletion src/AudioAnalysisTools/Tracks/UpwardTrackAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ public static (List<EventCommon> Events, double[] CombinedIntensity) GetUpwardTr
// initialise tracks as events and get the combined intensity array.
var events = new List<EventCommon>();
var temporalIntensityArray = new double[frameCount];
var maxScore = decibelThreshold * 5;
foreach (var track in tracks)
{
var ae = new WhipEvent(track)
var ae = new WhipEvent(track, maxScore)
{
SegmentDurationSeconds = frameCount * frameStep,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ public void TestOnebinTrackAlgorithm()
MinDuration = 0.2,
MaxDuration = 1.1,
DecibelThreshold = 2.0,
MaxScore = 12.0,
CombinePossibleSyllableSequence = false,
//SyllableStartDifference = TimeSpan.FromSeconds(0.2),
//SyllableHertzGap = 300,
Expand Down Expand Up @@ -486,7 +485,6 @@ public void TestOneframeTrackAlgorithm()
MinBandwidthHertz = 100,
MaxBandwidthHertz = 5000,
DecibelThreshold = 2.0,
MaxScore = 12.0,
//CombineProximalSimilarEvents = false,
//SyllableStartDifference = TimeSpan.FromSeconds(0.2),
//SyllableHertzDifference = 300,
Expand Down Expand Up @@ -569,10 +567,7 @@ public void Test1UpwardsTrackAlgorithm()
MaxHertz = 11000,
MinBandwidthHertz = 100,
MaxBandwidthHertz = 5000,
//MinDuration = 0.2,
//MaxDuration = 1.1,
DecibelThreshold = 2.0,
MaxScore = 12.0,
CombineProximalSimilarEvents = false,
SyllableStartDifference = TimeSpan.FromSeconds(0.2),
SyllableHertzDifference = 300,
Expand Down Expand Up @@ -658,7 +653,6 @@ public void Test2UpwardsTrackAlgorithm()
//MinDuration = 0.2,
//MaxDuration = 1.1,
DecibelThreshold = 2.0,
MaxScore = 12.0,
CombineProximalSimilarEvents = false,
SyllableStartDifference = TimeSpan.FromSeconds(0.2),
SyllableHertzDifference = 300,
Expand Down

0 comments on commit 269edd1

Please sign in to comment.