Skip to content

Commit

Permalink
Deal with case where histogram mode = 0.0
Browse files Browse the repository at this point in the history
Where mode of distribution = 0.0, this will contribute to suboptimal colour rendering of histograms. Start work on setting modal value > 0.0.
  • Loading branch information
towsey committed Mar 20, 2019
1 parent d0228f1 commit 57de07e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override Task<int> Execute(CommandLineApplication app)
Log.WriteLine("# Start Time = " + tStart.ToString(CultureInfo.InvariantCulture));

//AnalyseFrogDataSet();
//Audio2CsvOverOneFile();
Audio2CsvOverOneFile();
//Audio2CsvOverMultipleFiles();

// used to get files from availae for Black rail and Least Bittern papers.
Expand All @@ -89,7 +89,7 @@ public override Task<int> Execute(CommandLineApplication app)
//ResourcesForRheobatrachusSilusRecogniser();
//TestAnalyseLongRecordingUsingArtificialSignal();
//TestArbimonSegmentationAlgorithm();
TestDrawHistogram();
//TestDrawHistogram();
//TestEigenValues();
//TestChannelIntegrity();
//TestDct();
Expand Down Expand Up @@ -324,8 +324,8 @@ public static void Audio2CsvOverOneFile()
//string outputPath = @"G:\SensorNetworks\Output\BradLaw\Pillaga24";
//string configPath = @"C:\Work\GitHub\audio-analysis\AudioAnalysis\AnalysisConfigFiles\Towsey.Acoustic.yml";

string recordingPath = @"C:\Ecoacoustics\WavFiles\LizZnidersic\TasmanIsland2015_Unit2_Mez\SM304256_0+1_20151114_031652.wav";
string outputPath = @"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\04";
string recordingPath = @"C:\Ecoacoustics\WavFiles\LizZnidersic\TasmanIsland2015_Unit2_Mez\SM304256_0+1_20151114_231652.wav";
string outputPath = @"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\24";
string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\Towsey.Acoustic.yml";

// Ivan Campos recordings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,19 @@ public void LoadSpectrogramDictionary(Dictionary<string, double[,]> dictionary)
// check if user wants to use the automated bounds.
if (this.IndexStats != null)
{
// get the stats for this key
var stats = this.IndexStats[key];
if (indexProperties.CalculateNormMin)
{
//min = this.IndexStats[key].Mode;
minBound = this.IndexStats[key].Mode - (this.IndexStats[key].StandardDeviation * 0.1);
// By default the minimum bound is set slightly below the modal value of the index.
minBound = stats.Mode - (stats.StandardDeviation * 0.1);

// case where mode = min. Usually this occurs when mode = 0.0.
if (stats.Mode < 0.001)
{
var binWidth = (stats.Maximum - stats.Minimum) / stats.Distribution.Length;
minBound += binWidth;
}

// fix case where signal is defective &= zero. We do not want ACI min ever set too low.
if (key.Equals("ACI") && minBound < 0.3)
Expand All @@ -487,12 +496,12 @@ public void LoadSpectrogramDictionary(Dictionary<string, double[,]> dictionary)

if (indexProperties.CalculateNormMax)
{
maxBound = this.IndexStats[key].GetValueOfNthPercentile(IndexDistributions.UpperPercentileDefault);
maxBound = stats.GetValueOfNthPercentile(IndexDistributions.UpperPercentileDefault);

// correct for case where max bound = zero. This can happen where ICD is very short i.e. 0.1s.
if (maxBound < 0.0001)
{
maxBound = this.IndexStats[key].Maximum * 0.1;
maxBound = stats.Maximum * 0.1;
}
}

Expand Down Expand Up @@ -621,7 +630,7 @@ public void DrawNegativeFalseColourSpectrogram(DirectoryInfo outputDirectory, st
/// <summary>
/// Draw a chromeless false colour spectrogram.
/// Chromeless means WITHOUT all the trimmings, such as title bar axis labels, grid lines etc.
/// However it does add in notated error segments
/// However it does add in notated error segments.
/// </summary>
public Image DrawFalseColourSpectrogramChromeless(string colorMode, string colorMap)
{
Expand Down
9 changes: 4 additions & 5 deletions src/TowseyLibrary/GraphsAndCharts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public static Image DrawHistogram(string label, int[] histogram, int upperPercen
g.DrawLine(pen1, 0, height - 1, imageWidth, height - 1);

// draw upper percentile bound
g.DrawLine(pen4, upperBound, height - 1, upperBound, 0);

g.DrawString(label, stringFont, Brushes.Wheat, new PointF(4, 3));
g.DrawLine(pen4, upperBound, height - 1, upperBound, height / 3);

if (statistics != null)
{
Expand Down Expand Up @@ -88,8 +86,9 @@ public static Image DrawHistogram(string label, int[] histogram, int upperPercen
g.FillRectangle(brush, x, height - y, barWidth, y);
}

// draw mode bin
g.DrawLine(pen4, modeBin, height - 1, modeBin, 0);
// draw label and modal bin
g.DrawString(label, stringFont, Brushes.Wheat, new PointF(4, 3));
g.DrawLine(pen4, modeBin, height - 1, modeBin, height / 3);

return bmp;
}
Expand Down

0 comments on commit 57de07e

Please sign in to comment.