Skip to content

Commit

Permalink
Merge pull request #277 from QutEcoacoustics/Remove-Spectral-Index-R3…
Browse files Browse the repository at this point in the history
…D-Issue-#276

Removed calculation of R3D, Closes #246
  • Loading branch information
atruskie authored Nov 25, 2019
2 parents 781d0a3 + b45652f commit b160627
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 119 deletions.
11 changes: 0 additions & 11 deletions src/AnalysisConfigFiles/IndexPropertiesConfig.HiRes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -522,17 +522,6 @@ RNG:
CalculateNormBounds: true
ProjectID: Acoustic Indices
Units: "tracks/s"
R3D:
Name: spectralR3D
Comment: "Spectrum of max value of horizontal, positive and negative slope ridges per sec."
DataType: double[]
DefaultValue: 0.0
DoDisplay: true
NormMin: 0.15
NormMax: 1.0
CalculateNormBounds: true
ProjectID: Acoustic Indices
Units: "tracks/s"
SPT:
Name: spectralSPT
Comment: "Spectrum of average number of spectral Peak Tracks per second within each freq bin."
Expand Down
11 changes: 0 additions & 11 deletions src/AnalysisConfigFiles/IndexPropertiesConfig.Zooming.yml
Original file line number Diff line number Diff line change
Expand Up @@ -616,17 +616,6 @@ RNG:
CalculateNormBounds: false
ProjectID: Acoustic Indices
Units: "tracks/s"
R3D:
Name: spectralR3D
Comment: "Spectrum of max value of horizontal, positive and negative slope ridges per sec."
DataType: double[]
DefaultValue: 0.0
DoDisplay: true
NormMin: 0.15
NormMax: 1.0
CalculateNormBounds: false
ProjectID: Acoustic Indices
Units: "tracks/s"
SPT:
Name: spectralSPT
Comment: "Spectrum of average number of spectral Peak Tracks per second within each freq bin."
Expand Down
14 changes: 0 additions & 14 deletions src/AnalysisConfigFiles/IndexPropertiesConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -664,20 +664,6 @@ RNG:
#CalculateNormMax: false
ProjectID: Acoustic Indices
Units: "tracks/s"
R3D:
Name: spectralR3D
Comment: "Spectrum of max value of horizontal, positive and negative slope ridges per sec."
DataType: double[]
DefaultValue: 0.0
DoDisplay: true
NormMin: 0.15
NormMax: 1.0
CalculateNormBounds: true
# Merge conflict values from https://github.com/QutEcoacoustics/audio-analysis/pull/233
#CalculateNormMin: false
#CalculateNormMax: false
ProjectID: Acoustic Indices
Units: "tracks/s"
SPT:
Name: spectralSPT
Comment: "Spectrum of average number of spectral Peak Tracks per second within each freq bin."
Expand Down
2 changes: 1 addition & 1 deletion src/AnalysisConfigFiles/SpectrogramFalseColourConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# It should NOT contain dynamic data (like file names or analysis types)

ColorMap1: "ACI-ENT-EVN"
ColorMap2: "BGN-PMN-R3D"
ColorMap2: "BGN-PMN-EVN"

# The ColourFilter parameter determines how much the low index values are emphasized or de-emphasized.
# The purpose is to make low intensity features stand out (emphasis) or become even less obvious (de-emphasis).
Expand Down
2 changes: 1 addition & 1 deletion src/AnalysisPrograms/Recognizers/Base/RecognizerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void DrawLongDurationSpectrogram(
FalseColourSpectrogramConfig = spectrogramConfig.FullName,
IndexPropertiesConfig = ipConfig.FullName,
ColourMap1 = "BGN-DMN-EVN",
ColourMap2 = "R3D-RVT-SPT", //R3D replaces PHN as new derived index
ColourMap2 = "RHZ-RVT-SPT", //R3D replaces PHN as new derived index
TemporalScale = hiResTimeScale,
};

Expand Down
7 changes: 0 additions & 7 deletions src/AudioAnalysisTools/Indices/IndexCalculate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,6 @@ public static IndexCalculateResult Analysis(
spectralIndices.RVT = sptInfo.RvtSpectrum;
spectralIndices.RPS = sptInfo.RpsSpectrum;
spectralIndices.RNG = sptInfo.RngSpectrum;
spectralIndices.R3D = sptInfo.R3DSpectrum;

//images for debugging
//ImageTools.DrawMatrix(dspOutput3.amplitudeSpectrogram, @"C:\SensorNetworks\Output\BAC\HiResRidge\dspOutput3.amplitudeSpectrogram.png");
//ImageTools.DrawMatrix(ridgeSpectrogram, @"C:\SensorNetworks\Output\BAC\HiResRidge\ridgeSpectrogram.png");
//ImageTools.DrawMatrix(sptInfo.RvtSpectrum, @"C:\SensorNetworks\Output\BAC\HiResRidge\ridgeSpectrum.png");

summaryIndices.SptDensity = sptInfo.TrackDensity;

// these are two other indices that I tried but they do not seem to add anything of interest.
Expand Down
2 changes: 0 additions & 2 deletions src/AudioAnalysisTools/Indices/InitialiseIndexProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ public static class InitialiseIndexProperties

//public const string KeYspectralAci = "ACI";
//public const string KeySpectralBgn = "BGN";
//public const string KeYspectralCls = "CLS";
//public const string KeYspectralCvr = "CVR";
//public const string KeYspectralEnt = "ENT";
//public const string KeYspectralEvn = "EVN";
//public const string KeySpectralOsc = "OSC";
//public const string KeySpectralPmn = "PMN";
//public const string KeySpectralR3D = "R3D";
//public const string KeySpectralRhz = "RHZ";
//public const string KeySpectralRng = "RNG";
//public const string KeySpectralRps = "RPS";
Expand Down
16 changes: 7 additions & 9 deletions src/AudioAnalysisTools/Indices/SpectralIndexValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,31 +163,29 @@ public static Image CreateImageOfSpectralIndices(SpectralIndexValues spectralInd

/// <summary>
/// Gets or sets the oscillation spectral index index. Created October 2018.
/// 6.
/// </summary>
public double[] OSC { get; set; }

// 8: Sum of Spectral Ridges in Horizontal, postive and neg slope directions (RHZ+RPS+RNG)
public double[] R3D { get; set; }

/// <summary>
/// Gets or sets PMN = Power Minus Noise.
/// PMN is measured in decibels but should replace POW as the average decibel spectrogram.
/// 7: PMN is measured in decibels but should replace POW as the average decibel spectrogram.
/// </summary>
public double[] PMN { get; set; }

// 9: Spectral Ridges Horizontal
// 8: Spectral Ridges Horizontal
public double[] RHZ { get; set; }

// 10: Spectral Ridges Vertical
// 9: Spectral Ridges Vertical
public double[] RVT { get; set; }

// 11: Spectral Ridges Positive slope
// 10: Spectral Ridges Positive slope
public double[] RPS { get; set; }

// 12: Spectral Ridges Negative Slope
// 11: Spectral Ridges Negative Slope
public double[] RNG { get; set; }

// 13: Spectral Peak Tracks
// 12: Spectral Peak Tracks
public double[] SPT { get; set; }

// This property only calculated for ACI when zooming
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static LdSpectrogramConfig ReadYamlToConfig(FileInfo path)

/// <summary>
/// NOTE: As of August 2015, we are using EVN (event count) in both spectrograms because CVR (cover) is too highly correlated with POW.
/// NOTE: As of May 2017, PMN replaces POW and we are using R3D in spectrogram2 because it is less correlated with PMN.
/// NOTE: As of May 2017, PMN replaces POW.
/// </summary>
public static LdSpectrogramConfig GetDefaultConfig()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public class LDSpectrogramRGB
public static string[] GetArrayOfAvailableKeys()
{
// Before May 2017, only the required six spectral indices were incorporated in a dictionary of spectral matrices.
// Since May 2017, all the likely available matrices are incorporated into a dictionary. Note the new names for PMN and R3D, previously POW and HPN respectively.
// Since May 2017, all the likely available matrices are incorporated into a dictionary. Note the new name for PMN, previously POW.
// Note 1: This default array will be subsequently over-written by the indices in the IndexPropertiesConfig file if one is available.
// Note 1: RHZ, SPT and CVR are correlated with POW and do not add much. CLS is not particularly useful. Currently using R3D
// Decmeber 2018: Now all spectral indices are always used in drawing images
// Note 1: RHZ, SPT and CVR are correlated with PMN and do not add much.
// December 2018: Now all spectral indices are always used in drawing images
return SpectralIndexValues.Keys;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ public static class SpectrogramConstants

public const string RGBMap_ACI_ENT_PMN = "ACI-ENT-PMN"; //R-G-B
public const string RGBMap_ACI_ENT_CVR = "ACI-ENT-CVR"; //R-G-B
public const string RGBMap_ACI_ENT_CLS = "ACI-ENT-CLS"; //R-G-B
public const string RGBMap_ACI_ENT_EVN = "ACI-ENT-EVN"; //R-G-B
public const string RGBMap_ACI_ENT_SPT = "ACI-ENT-SPT"; //R-G-B

// A second set of RGB mappings based on BGN and PMN.
public const string RGBMap_BGN_PMN_EVN = "BGN-PMN-EVN"; //R-G-B
public const string RGBMap_BGN_PMN_SPT = "BGN-PMN-SPT"; //R-G-B
public const string RGBMap_BGN_PMN_CLS = "BGN-PMN-CLS"; //R-G-B
public const string RGBMap_BGN_PMN_OSC = "BGN-PMN-OSC";
public const string RGBMap_BGN_PMN_R3D = "BGN-PMN-R3D";
public const string RGBMap_BGN_PMN_RHZ = "BGN-PMN-RHZ";
public const string RGBMap_BGN_PMN_CVR = "BGN-PMN-CVR"; //R-G-B

Expand Down
29 changes: 3 additions & 26 deletions src/AudioAnalysisTools/SpectralPeakTracks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="SpectralPeakTracks.cs" company="QutEcoacoustics">
// <copyright file="SpectralPeakTracks.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 @@ -16,7 +16,7 @@ namespace AudioAnalysisTools
/// </summary>
public class SpectralPeakTracks
{
private static readonly string[] RidgeKeys = { "SPT", "RVT", "RHZ", "RPS", "RNG", "R3D" };
private static readonly string[] RidgeKeys = { "SPT", "RVT", "RHZ", "RPS", "RNG" };

/// <summary>
/// Initializes a new instance of the <see cref="SpectralPeakTracks"/> class.
Expand All @@ -31,7 +31,6 @@ public SpectralPeakTracks(double[,] dBSpectrogram, double peakThreshold)
// It was changed while in Toulon to the following line which does not require a threshold.
// this.GetRidgeSpectraVersion1(dBSpectrogram, ridgeThreshold: 4.0);
this.GetRidgeSpectraVersion2(dBSpectrogram);
this.CalculateCombinationOfThreeDirections();
}

public double[,] Peaks { get; private set; }
Expand Down Expand Up @@ -69,11 +68,6 @@ public SpectralPeakTracks(double[,] dBSpectrogram, double peakThreshold)
/// </summary>
public double[] RngSpectrum { get; private set; }

/// <summary>
/// gets three directions ridge value
/// </summary>
public double[] R3DSpectrum { get; private set; }

public static string[] GetDefaultRidgeKeys()
{
return RidgeKeys;
Expand Down Expand Up @@ -324,23 +318,6 @@ public void GetPeakTracksSpectrum(double[,] dBSpectrogram, double dBThreshold)
//this.AvTrackDuration = TimeSpan.FromSeconds(avFramesPerTrack / framesPerSecond);
}

/// <summary>
/// Calculates the max of the Horizontal, positive and negative slope ridges.
/// Could alternatively calculate the sum of the Horizontal, positive and negative slope ridges.
/// </summary>
public void CalculateCombinationOfThreeDirections()
{
this.R3DSpectrum = new double[this.RhzSpectrum.Length];
for (int i = 0; i < this.RhzSpectrum.Length; i++)
{
var array = new[] { this.RhzSpectrum[i], this.RpsSpectrum[i], this.RngSpectrum[i] };
this.R3DSpectrum[i] = array.Max();

// alternatively, sum the indices
//this.R3DSpectrum[i] = this.RhzSpectrum[i] + this.RpsSpectrum[i] + this.RngSpectrum[i];
}
}

// ################################### STATIC METHODS BELOW HERE ########################################

/// <summary>
Expand Down Expand Up @@ -389,7 +366,7 @@ public void CalculateCombinationOfThreeDirections()
} // LocalPeaks()

/// <summary>
/// CALCULATEs SPECTRAL PEAK TRACKS: spectralIndices.SPT, RHZ, RVT, RPS, RNG, R3D,
/// CALCULATEs SPECTRAL PEAK TRACKS: spectralIndices.SPT, RHZ, RVT, RPS, RNG
/// This method is only called from IndexCalulate.analysis() when the IndexCalculation Duration is less than 10 seconds,
/// because need to recalculate background noise etc.
/// Otherwise the constructor of this class is called: sptInfo = new SpectralPeakTracks(decibelSpectrogram, peakThreshold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ public void TestAnalyzeSr22050Recording()
var resultsDirectory = this.outputDirectory.Combine("Towsey.Acoustic");
var listOfFiles = resultsDirectory.EnumerateFiles().ToArray();

Assert.AreEqual(40, listOfFiles.Length);
Assert.AreEqual(38, listOfFiles.Length);

var csvCount = listOfFiles.Count(f => f.Name.EndsWith(".csv"));
Assert.AreEqual(16, csvCount);
Assert.AreEqual(15, csvCount);

var jsonCount = listOfFiles.Count(f => f.Name.EndsWith(".json"));
Assert.AreEqual(2, jsonCount);

var pngCount = listOfFiles.Count(f => f.Name.EndsWith(".png"));
Assert.AreEqual(22, pngCount);
Assert.AreEqual(21, pngCount);

var twoMapsImagePath = resultsDirectory.CombineFile("TemporaryRecording1__2Maps.png");
var twoMapsImage = ImageTools.ReadImage2Bitmap(twoMapsImagePath.FullName);
Expand Down Expand Up @@ -207,10 +207,10 @@ public void TestAnalyzeSr64000Recording()
var resultsDirectory = this.outputDirectory.Combine("Towsey.Acoustic");
var listOfFiles = resultsDirectory.EnumerateFiles().ToArray();

Assert.AreEqual(20, listOfFiles.Length);
Assert.AreEqual(19, listOfFiles.Length);

var csvCount = listOfFiles.Count(f => f.Name.EndsWith(".csv"));
Assert.AreEqual(16, csvCount);
Assert.AreEqual(15, csvCount);

var jsonCount = listOfFiles.Count(f => f.Name.EndsWith(".json"));
Assert.AreEqual(2, jsonCount);
Expand Down Expand Up @@ -269,7 +269,7 @@ public void TestAnalyzeSr64000Recording()
// test number of images - should now be 23
listOfFiles = resultsDirectory.EnumerateFiles().ToArray();
pngCount = listOfFiles.Count(f => f.Name.EndsWith(".png"));
Assert.AreEqual(23, pngCount);
Assert.AreEqual(22, pngCount);

var twoMapsImagePath = resultsDirectory.CombineFile(recordingName + "__2Maps.png");
var twoMapsImage = ImageTools.ReadImage2Bitmap(twoMapsImagePath.FullName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public static void ClassInitialize(TestContext context)

// do some basic checks that the indices were generated
var listOfFiles = ResultsDirectory.EnumerateFiles().ToArray();
Assert.AreEqual(20, listOfFiles.Length);
Assert.AreEqual(19, listOfFiles.Length);
var csvCount = listOfFiles.Count(f => f.Name.EndsWith(".csv"));
Assert.AreEqual(16, csvCount);
Assert.AreEqual(15, csvCount);
var jsonCount = listOfFiles.Count(f => f.Name.EndsWith(".json"));
Assert.AreEqual(2, jsonCount);
var pngCount = listOfFiles.Count(f => f.Name.EndsWith(".png"));
Expand Down
Loading

0 comments on commit b160627

Please sign in to comment.