Skip to content

Commit

Permalink
Created DataProcessing class plus two new test classes
Browse files Browse the repository at this point in the history
Issue#252 set up two new testing classes but have not yet implemented any tests.
Added new data processing class because ContentDescription class was gettgin too large.
  • Loading branch information
towsey committed Sep 16, 2019
1 parent 7747fd5 commit e5645d1
Show file tree
Hide file tree
Showing 13 changed files with 594 additions and 459 deletions.
1 change: 1 addition & 0 deletions src/AudioAnalysisTools/AudioAnalysisTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
<Compile Include="ContentDescriptionTools\ContentTypes\SilverEyeMezTasmanIs.cs" />
<Compile Include="ContentDescriptionTools\ContentTypes\WindLight1.cs" />
<Compile Include="ContentDescriptionTools\ContentVisualization.cs" />
<Compile Include="ContentDescriptionTools\DataProcessing.cs" />
<Compile Include="ContentDescriptionTools\DescriptionResult.cs" />
<Compile Include="ContentDescriptionTools\ContentTypes\RainHeavy1.cs" />
<Compile Include="ContentDescriptionTools\ContentTypes\WindStrong1.cs" />
Expand Down
411 changes: 7 additions & 404 deletions src/AudioAnalysisTools/ContentDescriptionTools/ContentDescription.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// <copyright file="WindStrong1.cs" company="QutEcoacoustics">
// <copyright file="BaseContentType.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>

namespace AudioAnalysisTools.ContentDescriptionTools.ContentTypes
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using TowseyLibrary;

public abstract class BaseContentType
Expand Down Expand Up @@ -38,7 +37,7 @@ public abstract class BaseContentType
// The all important template that is used to find an acoustic content type.
// These are calculate, written to a csv file and then appropriate parts are copied into a dictionary declaration such as this.
// The arrays will all be of same length but will vary from length = 1 to 16 or potentially 256.
private static readonly Dictionary<string, double[]> SilverEyeTemplate = new Dictionary<string, double[]>
private static readonly Dictionary<string, double[]> Template = new Dictionary<string, double[]>
{
["ACI"] = new[] { 0.086, 0.043, 0.041, 0.023, 0.032, 0.027, 0.029, 0.031, 0.032, 0.032, 0.034, 0.069, 0.033, 0.024, 0.018, 0.018 },
["ENT"] = new[] { 0.124, 0.112, 0.146, 0.163, 0.157, 0.157, 0.143, 0.122, 0.113, 0.095, 0.087, 0.121, 0.075, 0.060, 0.054, 0.067 },
Expand All @@ -63,11 +62,11 @@ public static KeyValuePair<string, double> GetContent(Dictionary<string, double[
/// </summary>
public static Dictionary<string, double[]> GetTemplate(DirectoryInfo dir)
{
var dictionaryOfIndices = ContentDescription.ReadIndexMatrices(dir, BaseName);
var birdIndices = ContentDescription.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = ContentDescription.ReduceIndicesByFactor(birdIndices, ReductionFactor);
var freqBinBounds = ContentDescription.GetFreqBinBounds(BottomFreq, TopFreq, FreqBinCount);
reducedIndices = ContentDescription.ApplyBandPass(reducedIndices, freqBinBounds[0], freqBinBounds[1]);
var dictionaryOfIndices = DataProcessing.ReadIndexMatrices(dir, BaseName);
var birdIndices = DataProcessing.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(birdIndices, ReductionFactor);
var freqBinBounds = DataProcessing.GetFreqBinBounds(BottomFreq, TopFreq, FreqBinCount);
reducedIndices = DataProcessing.ApplyBandPass(reducedIndices, freqBinBounds[0], freqBinBounds[1]);
return reducedIndices;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="BirdMorningChorus1.cs" company="QutEcoacoustics">
// <copyright file="BirdChorus1.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 @@ -13,11 +13,12 @@ public class BirdMorningChorus1
{
//TEMPLATE DESCRIPTION
// Name of the template
public const string Name = "BirdMorningChorus1";
public const string Name = "BirdChorus1";

// The TEMPLATE PROVENANCE
// The source file name from which the indices are extracted.
private const string BaseName = "SM304256_0+1_20151114_041652";
private const string Location = "Mezzanine, Tasman Island";

//THESE ARE SPECIFIC ROW BOUNDS FOR PREPARING THIS TEMPLATE
// The freq bins will be averaged over the time period.
Expand All @@ -44,15 +45,15 @@ public class BirdMorningChorus1

public static KeyValuePair<string, double> GetContent(Dictionary<string, double[]> oneMinuteOfIndices)
{
var reducedIndices = ContentDescription.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);

// remove first two freq bins and last four freq bins
int bottomBin = 2;
int topBin = 11;
reducedIndices = ContentDescription.ApplyBandPass(reducedIndices, bottomBin, topBin);
reducedIndices = DataProcessing.ApplyBandPass(reducedIndices, bottomBin, topBin);

var oneMinuteVector = ContentDescription.ConvertDictionaryToVector(reducedIndices);
var templateVector = ContentDescription.ConvertDictionaryToVector(BirdChorusTemplate);
var oneMinuteVector = DataProcessing.ConvertDictionaryToVector(reducedIndices);
var templateVector = DataProcessing.ConvertDictionaryToVector(BirdChorusTemplate);

//Get Euclidian distance and normalize the distance
var distance = DataTools.EuclideanDistance(templateVector, oneMinuteVector);
Expand All @@ -63,9 +64,9 @@ public static KeyValuePair<string, double> GetContent(Dictionary<string, double[

public static Dictionary<string, double[]> GetTemplate(DirectoryInfo dir)
{
var dictionaryOfIndices = ContentDescription.ReadIndexMatrices(dir, BaseName);
var birdIndices = ContentDescription.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = ContentDescription.ReduceIndicesByFactor(birdIndices, ReductionFactor);
var dictionaryOfIndices = DataProcessing.ReadIndexMatrices(dir, BaseName);
var birdIndices = DataProcessing.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(birdIndices, ReductionFactor);
return reducedIndices;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RainHeavy1
public const string Name = "HeavyRain1";
private const int ReductionFactor = 16;

private static Dictionary<string, double[]> StrongRainTemplate = new Dictionary<string, double[]>
private static readonly Dictionary<string, double[]> HeavyRainTemplate = new Dictionary<string, double[]>
{
["ACI"] = new[] { 0.076, 0.046, 0.167, 0.360, 0.426, 0.443, 0.545, 0.595, 0.564, 0.612, 0.659, 0.570, 0.542, 0.520, 0.485, 0.485 },
["ENT"] = new[] { 0.065, 0.061, 0.176, 0.289, 0.249, 0.255, 0.296, 0.292, 0.262, 0.386, 0.462, 0.262, 0.222, 0.243, 0.217, 0.205 },
Expand All @@ -24,9 +24,9 @@ public class RainHeavy1

public static KeyValuePair<string, double> GetRainContent(Dictionary<string, double[]> oneMinuteOfIndices)
{
var reducedIndices = ContentDescription.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
var oneMinuteVector = ContentDescription.ConvertDictionaryToVector(reducedIndices);
var templateVector = ContentDescription.ConvertDictionaryToVector(StrongRainTemplate);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
var oneMinuteVector = DataProcessing.ConvertDictionaryToVector(reducedIndices);
var templateVector = DataProcessing.ConvertDictionaryToVector(HeavyRainTemplate);

//Get Euclidian distance and normalise the distance
var distance = DataTools.EuclideanDistance(templateVector, oneMinuteVector);
Expand All @@ -45,8 +45,8 @@ public static KeyValuePair<string, double> GetRainContent(Dictionary<string, dou

public static Dictionary<string, double[]> GetTemplate(Dictionary<string, double[,]> dictionaryOfIndices)
{
var windIndices = ContentDescription.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = ContentDescription.ReduceIndicesByFactor(windIndices, ReductionFactor);
var windIndices = DataProcessing.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(windIndices, ReductionFactor);
return reducedIndices;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class RainLight1

public static KeyValuePair<string, double> GetContent(Dictionary<string, double[]> oneMinuteOfIndices)
{
var reducedIndices = ContentDescription.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
var oneMinuteVector = ContentDescription.ConvertDictionaryToVector(reducedIndices);
var templateVector = ContentDescription.ConvertDictionaryToVector(LightRainTemplate);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
var oneMinuteVector = DataProcessing.ConvertDictionaryToVector(reducedIndices);
var templateVector = DataProcessing.ConvertDictionaryToVector(LightRainTemplate);

//Get Euclidian distance and normalise the distance
var distance = DataTools.EuclideanDistance(templateVector, oneMinuteVector);
Expand All @@ -58,9 +58,9 @@ public static KeyValuePair<string, double> GetContent(Dictionary<string, double[
/// </summary>
public static Dictionary<string, double[]> GetTemplate(DirectoryInfo dir)
{
var dictionaryOfIndices = ContentDescription.ReadIndexMatrices(dir, BaseName);
var windIndices = ContentDescription.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = ContentDescription.ReduceIndicesByFactor(windIndices, ReductionFactor);
var dictionaryOfIndices = DataProcessing.ReadIndexMatrices(dir, BaseName);
var windIndices = DataProcessing.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(windIndices, ReductionFactor);
return reducedIndices;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace AudioAnalysisTools.ContentDescriptionTools.ContentTypes
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -50,20 +49,19 @@ public class SilverEyeMezTasmanIs

public static KeyValuePair<string, double> GetContent(Dictionary<string, double[]> oneMinuteOfIndices)
{
var reducedIndices = ContentDescription.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);

//var freqBinBounds = ContentDescription.GetFreqBinBounds(BottomFreq, TopFreq);
//reducedIndices = ContentDescription.ApplyBandPass(reducedIndices, freqBinBounds[0], freqBinBounds[1]);

var oneMinuteVector = ContentDescription.ConvertDictionaryToVector(reducedIndices);
var templateVector = ContentDescription.ConvertDictionaryToVector(SilverEyeTemplate);
//var freqBinBounds = DataProcessing.GetFreqBinBounds(BottomFreq, TopFreq);
//reducedIndices = DataProcessing.ApplyBandPass(reducedIndices, freqBinBounds[0], freqBinBounds[1]);
//var oneMinuteVector = DataProcessing.ConvertDictionaryToVector(reducedIndices);
//var templateVector = DataProcessing.ConvertDictionaryToVector(SilverEyeTemplate);

//Get Euclidian distance and normalize the distance
// Now pass the template up the full frequency spectrum to get a spectrum of scores.
var spectralScores = ContentDescription.ScanSpectrumWithTemplate(SilverEyeTemplate, reducedIndices);
var spectralScores = DataProcessing.ScanSpectrumWithTemplate(SilverEyeTemplate, reducedIndices);

// Now check how much of spectral weight is in the correct freq band ie between 3-4 kHz.
var freqBinBounds = ContentDescription.GetFreqBinBounds(BottomFreq, TopFreq, FreqBinCount);
var freqBinBounds = DataProcessing.GetFreqBinBounds(BottomFreq, TopFreq, FreqBinCount);
double callSum = DataTools.Subarray(spectralScores, freqBinBounds[0], freqBinBounds[1]).Sum();
double totalSum = DataTools.Subarray(spectralScores, 1, spectralScores.Length - 3).Sum();
double score = callSum / totalSum;
Expand All @@ -73,11 +71,11 @@ public static KeyValuePair<string, double> GetContent(Dictionary<string, double[

public static Dictionary<string, double[]> GetTemplate(DirectoryInfo dir)
{
var dictionaryOfIndices = ContentDescription.ReadIndexMatrices(dir, BaseName);
var birdIndices = ContentDescription.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = ContentDescription.ReduceIndicesByFactor(birdIndices, ReductionFactor);
var freqBinBounds = ContentDescription.GetFreqBinBounds(BottomFreq, TopFreq, FreqBinCount);
reducedIndices = ContentDescription.ApplyBandPass(reducedIndices, freqBinBounds[0], freqBinBounds[1]);
var dictionaryOfIndices = DataProcessing.ReadIndexMatrices(dir, BaseName);
var birdIndices = DataProcessing.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(birdIndices, ReductionFactor);
var freqBinBounds = DataProcessing.GetFreqBinBounds(BottomFreq, TopFreq, FreqBinCount);
reducedIndices = DataProcessing.ApplyBandPass(reducedIndices, freqBinBounds[0], freqBinBounds[1]);
return reducedIndices;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public class WindLight1

public static KeyValuePair<string, double> GetContent(Dictionary<string, double[]> oneMinuteOfIndices)
{
var reducedIndices = ContentDescription.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
reducedIndices.Remove("ENT");
LightWindTemplate.Remove("ENT");

var oneMinuteVector = ContentDescription.ConvertDictionaryToVector(reducedIndices);
var templateVector = ContentDescription.ConvertDictionaryToVector(LightWindTemplate);
var oneMinuteVector = DataProcessing.ConvertDictionaryToVector(reducedIndices);
var templateVector = DataProcessing.ConvertDictionaryToVector(LightWindTemplate);

var distance = DataTools.EuclideanDistance(templateVector, oneMinuteVector);

Expand All @@ -54,9 +54,9 @@ public static KeyValuePair<string, double> GetContent(Dictionary<string, double[

public static Dictionary<string, double[]> GetTemplate(DirectoryInfo dir)
{
var dictionaryOfIndices = ContentDescription.ReadIndexMatrices(dir, BaseName);
var windIndices = ContentDescription.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = ContentDescription.ReduceIndicesByFactor(windIndices, ReductionFactor);
var dictionaryOfIndices = DataProcessing.ReadIndexMatrices(dir, BaseName);
var windIndices = DataProcessing.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(windIndices, ReductionFactor);
return reducedIndices;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class WindStrong1

public static KeyValuePair<string, double> GetContent(Dictionary<string, double[]> oneMinuteOfIndices)
{
var reducedIndices = ContentDescription.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
var oneMinuteVector = ContentDescription.ConvertDictionaryToVector(reducedIndices);
var templateVector = ContentDescription.ConvertDictionaryToVector(StrongWindTemplate);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(oneMinuteOfIndices, ReductionFactor);
var oneMinuteVector = DataProcessing.ConvertDictionaryToVector(reducedIndices);
var templateVector = DataProcessing.ConvertDictionaryToVector(StrongWindTemplate);

var distance = DataTools.EuclideanDistance(templateVector, oneMinuteVector);

Expand All @@ -51,9 +51,9 @@ public static KeyValuePair<string, double> GetContent(Dictionary<string, double[

public static Dictionary<string, double[]> GetTemplate(DirectoryInfo dir)
{
var dictionaryOfIndices = ContentDescription.ReadIndexMatrices(dir, BaseName);
var windIndices = ContentDescription.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = ContentDescription.ReduceIndicesByFactor(windIndices, ReductionFactor);
var dictionaryOfIndices = DataProcessing.ReadIndexMatrices(dir, BaseName);
var windIndices = DataProcessing.AverageIndicesOverMinutes(dictionaryOfIndices, StartRowId, EndRowId);
var reducedIndices = DataProcessing.ReduceIndicesByFactor(windIndices, ReductionFactor);
return reducedIndices;
}

Expand Down
Loading

0 comments on commit e5645d1

Please sign in to comment.