Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue300 fix debug spectrograms #301

Merged
merged 12 commits into from
Mar 20, 2020
17 changes: 10 additions & 7 deletions src/AnalysisBase/ResultBases/EventBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="EventBase.cs" company="QutEcoacoustics">
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group).
// </copyright>
Expand All @@ -12,14 +12,14 @@ namespace AnalysisBase.ResultBases
using System;

/// <summary>
/// The base class for all Event style results
/// The base class for all Event style results.
/// </summary>
public abstract class EventBase : ResultBase
{
private double eventStartSeconds;

/// <summary>
/// Gets or sets the time the current audio segment is offset from the start of the file/recording.
/// Gets or sets the time (in seconds) from start of the file/recording to start of the current audio segment.
/// </summary>
/// <remarks>
/// <see cref="EventStartSeconds"/> will always be greater than or equal to <see cref="SegmentStartSeconds"/>.
Expand All @@ -36,7 +36,7 @@ public abstract class EventBase : ResultBase
/// </summary>
/// <remarks>
/// 2017-09: This field USED to be offset relative to the current segment.
/// 2017-09: This field is NOW equivalent to <see cref="ResultBase.ResultStartSeconds"/>
/// 2017-09: This field is NOW equivalent to <see cref="ResultBase.ResultStartSeconds"/>.
/// </remarks>
public virtual double EventStartSeconds
{
Expand All @@ -60,10 +60,13 @@ public virtual double EventStartSeconds
/// </summary>
public virtual double? LowFrequencyHertz { get; protected set; }

protected void SetEventStartRelative(TimeSpan segmentStart, double eventStartSegmentRelative)
/// <summary>
/// Sets both the Segment start and the Event start wrt to recording.
/// </summary>
protected void SetSegmentAndEventStartsWrtRecording(TimeSpan segmentStartWrtRecording, double eventStartWrtSegment)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrt is an unacceptable abbreviation. Remove, please. Use the old names - they are consistently used in the project

If you need to document the purpose of these parameters then add documentation.

{
this.SegmentStartSeconds = segmentStart.TotalSeconds;
this.EventStartSeconds = this.SegmentStartSeconds + eventStartSegmentRelative;
this.SegmentStartSeconds = segmentStartWrtRecording.TotalSeconds;
this.EventStartSeconds = this.SegmentStartSeconds + eventStartWrtSegment;
}
}
}
29 changes: 0 additions & 29 deletions src/AnalysisPrograms/Recognizers/Base/RecognizerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,35 +336,6 @@ protected virtual Image DrawSonogram(
double eventThreshold)
{
var image = SpectrogramTools.GetSonogramPlusCharts(sonogram, predictedEvents, scores, hits);

//const bool doHighlightSubband = false;
//const bool add1KHzLines = true;
//var image = new Image_MultiTrack(sonogram.GetImage(doHighlightSubband, add1KHzLines, doMelScale: false));
//image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
//image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));

//if (scores != null)
//{
// foreach (var plot in scores)
// {
// image.AddTrack(ImageTrack.GetNamedScoreTrack(plot.data, 0.0, 1.0, plot.threshold, plot.title));
// }
//}

//if (hits != null)
//{
// image.OverlayRedTransparency(hits);
//}

//if (predictedEvents != null && predictedEvents.Count > 0)
//{
// image.AddEvents(
// predictedEvents,
// sonogram.NyquistFrequency,
// sonogram.Configuration.FreqBinCount,
// sonogram.FramesPerSecond);
//}

return image;
}

Expand Down
37 changes: 5 additions & 32 deletions src/AnalysisPrograms/Recognizers/Base/WhistleParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static (List<AcousticEvent>, double[]) GetWhistles(
double decibelThreshold,
double minDuration,
double maxDuration,
TimeSpan segmentStartOffset)
TimeSpan segmentStartWrtRecording)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TimeSpan segmentStartWrtRecording)
TimeSpan segmentStartOffset)

{
var sonogramData = sonogram.Data;
int frameCount = sonogramData.GetLength(0);
Expand All @@ -39,10 +39,6 @@ public static (List<AcousticEvent>, double[]) GetWhistles(
double binWidth = nyquist / (double)binCount;
int minBin = (int)Math.Round(minHz / binWidth);
int maxBin = (int)Math.Round(maxHz / binWidth);
//int binCountInBand = maxBin - minBin + 1;

// buffer zone around whistle is four bins wide.
int N = 4;

// list of accumulated acoustic events
var events = new List<AcousticEvent>();
Expand All @@ -54,7 +50,8 @@ public static (List<AcousticEvent>, double[]) GetWhistles(
// set up an intensity array for the frequency bin.
double[] intensity = new double[frameCount];

if (minBin < N)
// buffer zone around whistle is four bins wide.
if (minBin < 4)
{
// for all time frames in this frequency bin
for (int t = 0; t < frameCount; t++)
Expand Down Expand Up @@ -96,7 +93,7 @@ public static (List<AcousticEvent>, double[]) GetWhistles(
decibelThreshold,
minDuration,
maxDuration,
segmentStartOffset);
segmentStartWrtRecording);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
segmentStartWrtRecording);
segmentStartOffset);


// add to conbined intensity array
for (int t = 0; t < frameCount; t++)
Expand All @@ -110,33 +107,9 @@ public static (List<AcousticEvent>, double[]) GetWhistles(
} //end for all freq bins

// combine adjacent acoustic events
events = AcousticEvent.CombineOverlappingEvents(events);
events = AcousticEvent.CombineOverlappingEvents(events, segmentStartWrtRecording);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix name


return (events, combinedIntensityArray);
}

/*
/// <summary>
/// Calculates the average intensity in a freq band having min and max freq,
/// AND then subtracts average intensity in the side/buffer bands, below and above.
/// THis method adds dB log values incorrectly but it is faster than doing many log conversions.
/// This method is used to find acoustic events and is accurate enough for the purpose.
/// </summary>
public static double[] CalculateFreqBandAvIntensityMinusBufferIntensity(double[,] sonogramData, int minHz, int maxHz, int nyquist)
{
var bandIntensity = SNR.CalculateFreqBandAvIntensity(sonogramData, minHz, maxHz, nyquist);
var bottomSideBandIntensity = SNR.CalculateFreqBandAvIntensity(sonogramData, minHz - bottomHzBuffer, minHz, nyquist);
var topSideBandIntensity = SNR.CalculateFreqBandAvIntensity(sonogramData, maxHz, maxHz + topHzBuffer, nyquist);

int frameCount = sonogramData.GetLength(0);
double[] netIntensity = new double[frameCount];
for (int i = 0; i < frameCount; i++)
{
netIntensity[i] = bandIntensity[i] - bottomSideBandIntensity[i] - topSideBandIntensity[i];
}

return netIntensity;
}
*/
}
}
2 changes: 1 addition & 1 deletion src/AnalysisPrograms/Recognizers/GenericRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static void SaveDebugSpectrogram(RecognizerResults results, Config genericConfig
var image3 = SpectrogramTools.GetSonogramPlusCharts(results.Sonogram, results.Events, results.Plots, null);

//image3.Save(Path.Combine(outputDirectory.FullName, baseName + ".profile.png"));
image3.Save(Path.Combine("C:\\temp", baseName + ".profile.png"));
//image3.Save(Path.Combine("C:\\temp", baseName + ".profile.png"));

//sonogram.GetImageFullyAnnotated("test").Save("C:\\temp\\test.png");
}
Expand Down
6 changes: 4 additions & 2 deletions src/AnalysisPrograms/Recognizers/LewiniaPectoralis.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LewiniaPectoralis.cs" company="QutEcoacoustics">
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group).
// </copyright>
Expand Down Expand Up @@ -193,13 +193,15 @@ public override RecognizerResults Recognize(
prunedEvents.Add(ae);
}

// do a recognizer TEST.
/*
// do a recognizer TEST. DELETE ONE DAY!
if (false)
{
var testDir = new DirectoryInfo(outputDirectory.Parent.Parent.FullName);
TestTools.RecognizerScoresTest(recording.BaseName, testDir, recognizerConfig.AnalysisName, scoreArray);
AcousticEvent.TestToCompareEvents(recording.BaseName, testDir, recognizerConfig.AnalysisName, predictedEvents);
}
*/

// increase very low scores
for (int j = 0; j < scoreArray.Length; j++)
Expand Down
6 changes: 4 additions & 2 deletions src/AnalysisPrograms/Recognizers/LitoriaBicolor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ public override RecognizerResults Recognize(AudioRecording recording, Config con
ae.SegmentDurationSeconds = recordingDuration.TotalSeconds;
}

// do a RECOGNIZER TEST.
/*
// do a RECOGNIZER TEST. DELETE ONE DAY!
if (false)
{
var testDir = new DirectoryInfo(outputDirectory.Parent.Parent.FullName);
TestTools.RecognizerScoresTest(recording.BaseName, testDir, recognizerConfig.AnalysisName, scoreArray);
AcousticEvent.TestToCompareEvents(recording.BaseName, testDir, recognizerConfig.AnalysisName, predictedEvents);
}
*/

var plot = new Plot(this.DisplayName, scoreArray, recognizerConfig.EventThreshold);
return new RecognizerResults()
Expand All @@ -171,7 +173,7 @@ public override RecognizerResults Recognize(AudioRecording recording, Config con
}

/// <summary>
/// ################ THE KEY ANALYSIS METHOD
/// THE KEY ANALYSIS METHOD.
/// </summary>
/// <param name="recording"></param>
/// <param name="sonoConfig"></param>
Expand Down
8 changes: 5 additions & 3 deletions src/AnalysisPrograms/Recognizers/LitoriaWatjulumensis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,15 @@ public override RecognizerResults Recognize(AudioRecording recording, Config con
ae.SegmentStartSeconds = segmentStartOffset.TotalSeconds;
}

// do a recognizer TEST.
/*
// do a recognizer TEST. DELETE ONE DAY!
if (false)
{
var testDir = new DirectoryInfo(outputDirectory.Parent.Parent.FullName);
TestTools.RecognizerScoresTest(recording.BaseName, testDir, recognizerConfig.AnalysisName, scoreArray);
AcousticEvent.TestToCompareEvents(recording.BaseName, testDir, recognizerConfig.AnalysisName, predictedEvents);
}
*/

var plot = new Plot(this.DisplayName, scoreArray, recognizerConfig.EventThreshold);
return new RecognizerResults()
Expand All @@ -175,8 +177,8 @@ public override RecognizerResults Recognize(AudioRecording recording, Config con
};
}

/// <summary>
/// ################ THE KEY ANALYSIS METHOD for TRILLS
/// <summary>
/// ################ THE KEY ANALYSIS METHOD for TRILLS
///
/// See Anthony's ExempliGratia.Recognize() method in order to see how to use methods for config profiles.
/// </summary>
Expand Down
Loading