Skip to content

Commit

Permalink
Partial unit test fixes for drawing all grey FCS
Browse files Browse the repository at this point in the history
The changes in ae5f673 broke many tests.

This commit fixes some but not all tests. More work needed.

Work for #199
  • Loading branch information
atruskie committed Dec 19, 2018
1 parent e9c9141 commit 7117f58
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
1 change: 1 addition & 0 deletions AudioAnalysis.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=appenders/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ecoacoustics/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=filenames/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=normalised/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=parallelized/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Resample/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Resampling/@EntryIndexedValue">True</s:Boolean>
Expand Down
33 changes: 15 additions & 18 deletions src/AudioAnalysisTools/Indices/SpectralIndexValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,32 @@ namespace AudioAnalysisTools.Indices

public class SpectralIndexValues : SpectralIndexBase
{
private static readonly Dictionary<string, Func<SpectralIndexBase, double[]>> CachedSelectorsInternal;
private static readonly Dictionary<string, Action<SpectralIndexValues, double[]>> CachedSettersInternal;

static SpectralIndexValues()
{
var getters = ReflectionExtensions.GetGetters<SpectralIndexValues, double[]>();

CachedSelectorsInternal = new Dictionary<string, Func<SpectralIndexBase, double[]>>(getters.Count);
CachedSelectors = new Dictionary<string, Func<SpectralIndexBase, double[]>>(getters.Count);
foreach (var keyValuePair in getters)
{
// var key = keyValuePair.Key;
var selector = keyValuePair.Value;

CachedSelectorsInternal.Add(
CachedSelectors.Add(
keyValuePair.Key,
spectrumBase => selector((SpectralIndexValues)spectrumBase));
}

Keys = CachedSelectors.Keys.ToArray();

var setters = ReflectionExtensions.GetSetters<SpectralIndexValues, double[]>();

CachedSettersInternal = new Dictionary<string, Action<SpectralIndexValues, double[]>>(getters.Count);
CachedSetters = new Dictionary<string, Action<SpectralIndexValues, double[]>>(getters.Count);
foreach (var keyValuePair in setters)
{
// var key = keyValuePair.Key;
var setter = keyValuePair.Value;

CachedSettersInternal.Add(
CachedSetters.Add(
keyValuePair.Key,
(spectrumBase, value) => setter(spectrumBase, value));
}
Expand Down Expand Up @@ -72,7 +71,9 @@ public SpectralIndexValues(int spectrumLength, Dictionary<string, IndexPropertie
// WARNING: Potential throw site
// No need to give following warning because should call CheckExistenceOfSpectralIndexValues() method before entering loop.
// This prevents multiple warnings through loop.
this.SetPropertyValue(cachedSetter.Key, initArray);
//this.SetPropertyValue(cachedSetter.Key, initArray);

cachedSetter.Value(this, initArray);
}

this.Configuration = configuration;
Expand All @@ -88,7 +89,7 @@ public SpectralIndexValues(int spectrumLength, Dictionary<string, IndexPropertie
/// </param>
public static SpectralIndexValues[] ImportFromDictionary(Dictionary<string, double[,]> dictionaryOfSpectra)
{
return dictionaryOfSpectra.FromTwoDimensionalArray<SpectralIndexValues, double>(CachedSetters, TwoDimensionalArray.Rotate90AntiClockWise);
return dictionaryOfSpectra.FromTwoDimensionalArray(CachedSetters, TwoDimensionalArray.Rotate90AntiClockWise);
}

/// <summary>
Expand All @@ -97,17 +98,14 @@ public static SpectralIndexValues[] ImportFromDictionary(Dictionary<string, doub
/// </summary>
public static void CheckExistenceOfSpectralIndexValues(Dictionary<string, IndexProperties> indexProperties)
{
var siv = new SpectralIndexValues();
double[] dummyArray = null;

foreach (var kvp in indexProperties)
{
if (!kvp.Value.IsSpectralIndex)
{
continue;
}

var success = siv.TrySetPropertyValue(kvp.Key, dummyArray);
var success = CachedSelectors.ContainsKey(kvp.Key);
if (!success)
{
LoggedConsole.WriteWarnLine(
Expand All @@ -116,15 +114,14 @@ public static void CheckExistenceOfSpectralIndexValues(Dictionary<string, IndexP
}
}

public static Dictionary<string, Func<SpectralIndexBase, double[]>> CachedSelectors => CachedSelectorsInternal;
public static Dictionary<string, Func<SpectralIndexBase, double[]>> CachedSelectors { get; }

public static Dictionary<string, Action<SpectralIndexValues, double[]>> CachedSetters => CachedSettersInternal;
public static Dictionary<string, Action<SpectralIndexValues, double[]>> CachedSetters { get; }

public static string[] Keys = CachedSelectors.Keys.ToArray();
public static string[] Keys { get; }

public static Image CreateImageOfSpectralIndices(SpectralIndexValues spectralIndices)
{

var images = new List<Image>();
foreach (var key in Keys)
{
Expand All @@ -144,7 +141,7 @@ public static Image CreateImageOfSpectralIndices(SpectralIndexValues spectralInd
/// </summary>
/// <remarks>
/// This property was added when we started generating lots of results that used
/// different parameters - we needed a way to diambiguate them.
/// different parameters - we needed a way to disambiguate them.
/// </remarks>
public IndexCalculateConfig Configuration { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="ConcatenationTests.cs" company="QutEcoacoustics">
// <copyright file="ConcatenationTests.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 @@ -78,7 +78,7 @@ public void ConcatenateEverythingYouCanLayYourHandsOn()
IndexPropertiesConfig = indexPropertiesConfig.FullName,
FalseColourSpectrogramConfig = testConfig.FullName,
ColorMap1 = LDSpectrogramRGB.DefaultColorMap1,
ColorMap2 = "BGN-POW-EVN", // POW was depracated post May 2017
ColorMap2 = "BGN-PMN-EVN", // POW was depracated post May 2017
ConcatenateEverythingYouCanLayYourHandsOn = true, // join everything found
TimeSpanOffsetHint = TimeSpan.FromHours(8),
DrawImages = true,
Expand Down Expand Up @@ -133,7 +133,7 @@ public void ConcatenateIndexFilesTest24Hour()
IndexPropertiesConfig = indexPropertiesConfig.FullName,
FalseColourSpectrogramConfig = testConfig.FullName,
ColorMap1 = LDSpectrogramRGB.DefaultColorMap1,
ColorMap2 = "BGN-POW-EVN", // POW was depracated post May 2017
ColorMap2 = "BGN-PMN-EVN", // POW was depracated post May 2017
ConcatenateEverythingYouCanLayYourHandsOn = false, // 24 hour blocks only
TimeSpanOffsetHint = TimeSpan.FromHours(8),
DrawImages = true,
Expand Down Expand Up @@ -190,7 +190,7 @@ public void ConcatenateIndexFilesTest24HourWithoutDateRange()
IndexPropertiesConfig = indexPropertiesConfig.FullName,
FalseColourSpectrogramConfig = testConfig.FullName,
ColorMap1 = LDSpectrogramRGB.DefaultColorMap1,
ColorMap2 = "BGN-POW-EVN", // POW was depracated post May 2017
ColorMap2 = "BGN-PMN-EVN", // POW was depracated post May 2017
ConcatenateEverythingYouCanLayYourHandsOn = false, // 24 hour blocks only
TimeSpanOffsetHint = TimeSpan.FromHours(8),
DrawImages = true,
Expand Down Expand Up @@ -250,7 +250,7 @@ public void ConcatenateIndexFilesTestConfigFileChanges()
var config = Yaml.Deserialize<LdSpectrogramConfig>(defaultConfigFile);

// make changes to config file as required for test
config.ColorMap1 = "BGN-ENT-POW";
config.ColorMap1 = "BGN-ENT-PMN";
config.ColorMap2 = "ACI-RNG-EVN";

// write new config
Expand Down Expand Up @@ -285,7 +285,7 @@ public void ConcatenateIndexFilesTestConfigFileChanges()
Assert.That.FileExists(outputDataDir.CombineFile(prefix + "Towsey.Acoustic.Indices.csv"));
Assert.That.FileNotExists(outputDataDir.CombineFile(prefix + "SummaryIndex.csv"));

var imageFileInfo1 = outputDataDir.CombineFile(prefix + "BGN-ENT-POW.png");
var imageFileInfo1 = outputDataDir.CombineFile(prefix + "BGN-ENT-PMN.png");
Assert.IsTrue(imageFileInfo1.Exists);

var imageFileInfo2 = outputDataDir.CombineFile(prefix + "ACI-RNG-EVN.png");
Expand Down

0 comments on commit 7117f58

Please sign in to comment.