Skip to content

Commit

Permalink
Issue #252 Set up new data structures for content description
Browse files Browse the repository at this point in the history
Issue #252 Set up new data structures for content description based on discussion with Anthony. Separate out main template information into yaml files.
  • Loading branch information
towsey committed Sep 19, 2019
1 parent 6a319be commit 0132e83
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 47 deletions.
111 changes: 111 additions & 0 deletions src/AnalysisConfigFiles/ContentDescriptionTemplateManifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
# WARNING!!! The keys (i.e. root name of each object below) MUST BE EXACTLY the SAME as those
# declared in the class InitialiseIndexProperties (starting at line 30).
# The root object name maps to the Key property on the IndexProperties class
# and to the members in the class SummaryIndexValues:SummaryIndexBase

RainLight1:
TemplateId: 0
Name: "Light Rain 1"
Comment: "Detects light rain."
SourceFileName: "SM304256_0+1_20151114_071652"
# Status can be "locked", etc
Status: "locked"
RecordingLocation: "Mezzanine, Tasman Is, Tasmania"
RecordingDateTime: "2015-11-14 07:16:52 +1100"
FeatureExtractionAlgorithm: 1
# Temporal Selection - minutes are inclusive"
StartMinute: 32
EndMinute: 36
TemporalReduction: "Average"
#Spectral Processing
SpectralReductionFactor: 16
# Frequency band selection
BandMinHz:
BandMaxHz:
WindStrong1:
TemplateId: 01
Name: Strong Wind 1
Comment: "Detects strong wind."
SourceFileName: "SM304256_0+1_20151114_011652"
# Status can be "locked", etc
Status: "locked"
RecordingLocation: "Mezzanine, Tasman Is, Tasmania"
RecordingDateTime: "2015-11-14 01:16:52 +1100"
FeatureExtractionAlgorithm: 1
# Temporal Selection - minutes are inclusive"
StartMinute: 2
EndMinute: 27
TemporalReduction: "Average"
#Spectral Processing
SpectralReductionFactor: 16
# Frequency band selection
BandMinHz:
BandMaxHz:
WindLight1:
TemplateId: 02
Name: Light Wind 1
Comment: "Detects light wind."
SourceFileName: "SM304256_0+1_20151114_021652"
# Status can be "locked", etc
Status: "locked"
RecordingLocation: "Mezzanine, Tasman Is, Tasmania"
RecordingDateTime: "2015-11-14 02:16:52 +1100"
# NOTE: Remove the ENT index before applying this template
FeatureExtractionAlgorithm: 1
# Temporal Selection - minutes are inclusive"
StartMinute: 50
EndMinute: 53
TemporalReduction: "Average"
#Spectral Processing
SpectralReductionFactor: 16
# Frequency band selection
BandMinHz:
BandMaxHz:
BirdChorus1:
TemplateId: 03
Name: Bird Chorus
Comment: "Detects chorus of bird song."
SourceFileName: "SM304256_0+1_20151114_041652"
# Status can be "locked", etc
Status: "locked"
RecordingLocation: "Mezzanine, Tasman Is, Tasmania"
RecordingDateTime: "2015-11-14 04:16:52 +1100"
# Only want the interval 2-8 kHz for bird morning chorus.
# After reducing 256 freq bins to 16, each bin has width 689Hz.
# Therefore to get band 2-8 kHz, need to remove the bottom two freq bins and the top four freq bins.
# This leaves a template with 10 freq bins.
FeatureExtractionAlgorithm: 1
# Temporal Selection - minutes are inclusive"
StartMinute: 22
EndMinute: 23
TemporalReduction: "Average"
#Spectral Processing
SpectralReductionFactor: 16
# Frequency band selection - select freq bins 2 to 11
BandMinHz: 2000
BandMaxHz: 8000
SilverEye:
TemplateId: 04
Name: Silver Eye
Comment: "Detects Silver Eye song in a Tasman Island recording."
SourceFileName: "SM304256_0+1_20151114_071652"
# Status can be "locked", etc
Status: "locked"
RecordingLocation: "Mezzanine, Tasman Is, Tasmania"
RecordingDateTime: "2015-11-14 07:16:52 +1100"
# Only want the interval 3-4 kHz for Silver-eye band.
# After reducing 256 freq bins to 16 bins, each bin has width 689Hz.
# Therefore to get band 3-4 kHz, this leaves a template with 2 or 3 freq bins which are then averaged.
# So each index ends up with only one value.
FeatureExtractionAlgorithm: 1
# Temporal Selection - minutes are inclusive"
StartMinute: 6
EndMinute: 11
TemporalReduction: "Average"
#Spectral Processing
SpectralReductionFactor: 16
# Frequency band selection
BandMinHz: 3000
BandMaxHz: 4000

86 changes: 86 additions & 0 deletions src/AnalysisConfigFiles/ContentDescriptionTemplates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
RainLight1:
TemplateId: 0
Name: "Light Rain 1"
Status: "locked"
Template:
ACI: [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: [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]
EVN: [0.136, 0.009, 0.022, 0.051, 0.072, 0.092, 0.109, 0.150, 0.175, 0.176, 0.193, 0.155, 0.171, 0.135, 0.109, 0.133]
BGN: [0.366, 0.249, 0.181, 0.148, 0.122, 0.111, 0.106, 0.105, 0.104, 0.111, 0.111, 0.111, 0.105, 0.100, 0.090, 0.048]
PMN: [0.182, 0.076, 0.243, 0.459, 0.470, 0.501, 0.592, 0.651, 0.625, 0.699, 0.792, 0.599, 0.572, 0.550, 0.490, 0.488]
FeatureExtractionAlgorithm: 1
StartMinute: 32
EndMinute: 36
TemporalReduction: "Average"
SpectralReductionFactor: 16
BandMinHz:
BandMaxHz:
WindStrong1:
TemplateId: 01
Name: Strong Wind 1
Status: "locked"
Template:
ACI: [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: [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]
EVN: [0.376, 0.440, 0.590, 0.621, 0.648, 0.621, 0.565, 0.363, 0.273, 0.191, 0.164, 0.221, 0.104, 0.040, 0.017, 0.032]
BGN: [0.472, 0.360, 0.273, 0.199, 0.156, 0.121, 0.096, 0.085, 0.075, 0.069, 0.064, 0.061, 0.060, 0.058, 0.054, 0.026]
PMN: [0.468, 0.507, 0.687, 0.743, 0.757, 0.751, 0.665, 0.478, 0.391, 0.317, 0.276, 0.367, 0.187, 0.109, 0.071, 0.096]
FeatureExtractionAlgorithm: 1
StartMinute: 2
EndMinute: 27
TemporalReduction: "Average"
SpectralReductionFactor: 16
BandMinHz:
BandMaxHz:
WindLight1:
TemplateId: 02
Name: Light Wind 1
Status: "locked"
Template:
ACI: [0.072, 0.035, 0.015, 0.008, 0.008, 0.009, 0.016, 0.018, 0.017, 0.015, 0.020, 0.022, 0.029, 0.026, 0.027, 0.098]
ENT: [0.063, 0.069, 0.071, 0.059, 0.052, 0.051, 0.050, 0.050, 0.050, 0.050, 0.050, 0.052, 0.051, 0.050, 0.051, 0.058]
EVN: [0.160, 0.099, 0.077, 0.023, 0.009, 0.009, 0.005, 0.004, 0.003, 0.004, 0.003, 0.006, 0.002, 0.004, 0.003, 0.015]
BGN: [0.387, 0.257, 0.151, 0.094, 0.069, 0.055, 0.049, 0.045, 0.042, 0.041, 0.041, 0.042, 0.043, 0.044, 0.043, 0.017]
PMN: [0.228, 0.199, 0.179, 0.087, 0.065, 0.048, 0.042, 0.034, 0.035, 0.035, 0.036, 0.038, 0.038, 0.037, 0.044, 0.081]
FeatureExtractionAlgorithm: 1
StartMinute: 50
EndMinute: 53
TemporalReduction: "Average"
SpectralReductionFactor: 16
BandMinHz:
BandMaxHz:
BirdChorus1:
TemplateId: 03
Name: Bird Chorus
Status: "locked"
Template:
ACI: [0.274, 0.366, 0.591, 0.820, 0.997, 0.975, 0.796, 0.846, 0.605, 0.260]
ENT: [0.293, 0.415, 0.804, 0.972, 0.910, 0.876, 0.923, 0.971, 0.840, 0.491]
EVN: [0.445, 0.691, 0.291, 0.266, 0.407, 0.417, 0.306, 0.321, 0.199, 0.091]
BGN: [0.140, 0.099, 0.072, 0.059, 0.055, 0.051, 0.048, 0.048, 0.045, 0.042]
PMN: [0.671, 0.967, 0.924, 0.998, 1.000, 1.000, 0.998, 1.000, 0.952, 0.633]
FeatureExtractionAlgorithm: 10
StartMinute: 22
EndMinute: 23
TemporalReduction: "Average"
SpectralReductionFactor: 16
BandMinHz: 2000
BandMaxHz: 8000
SilverEye:
TemplateId: 04
Name: Silver Eye
Status: "locked"
Template:
ACI: [0.779]
ENT: [0.393]
EVN: [0.686]
BGN: [0.085]
PMN: [0.883]
FeatureExtractionAlgorithm: 10
StartMinute: 6
EndMinute: 11
TemporalReduction: "Average"
SpectralReductionFactor: 16
BandMinHz: 3000
BandMaxHz: 4000
69 changes: 38 additions & 31 deletions src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public override Task<int> Execute(CommandLineApplication app)
Log.WriteLine("# Start Time = " + tStart.ToString(CultureInfo.InvariantCulture));

// CONTENT DESCRIPTION
//ReadSpectralIndicesFromTwoFalseColourSpectrogramRibbons();
ContentDescriptionDev();
//ContentDescriptionCreateTemplates();
ContentDescriptionApplyTemplates();

//AnalyseFrogDataSet();
//Audio2CsvOverOneFile();
Expand Down Expand Up @@ -119,7 +119,35 @@ public override Task<int> Execute(CommandLineApplication app)
}
}

public static void ContentDescriptionDev()
public static void ContentDescriptionCreateTemplates()
{
//PREPARE STRONG WIND TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez02\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//WindStrong1.WriteTemplateToFile(ipDir, opDir);

//PREPARE LIGHT WIND TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez03\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//WindLight1.WriteTemplateToFile(ipDir, opDir);

//PREPARE LIGHT RAIN TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez08\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//WindLight1.WriteTemplateToFile(ipDir, opDir);

//PREPARE BIRD MORNING CHORUS1 TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez05\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//BirdMorningChorus1.WriteTemplateToFile(ipDir, opDir);

//PREPARE MEZZANINE-TASMAN ISLAND SILVER-EYE TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez08\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//SilverEyeMezTasmanIs.WriteTemplateToFile(ipDir, opDir);
}

public static void ContentDescriptionApplyTemplates()
{
DirectoryInfo[] directories =
{
Expand Down Expand Up @@ -149,7 +177,9 @@ public static void ContentDescriptionDev()
new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez24\Towsey.Acoustic"),
};

string[] baseNames = { "SM304256_0+1_20151114_001652",
string[] baseNames =
{
"SM304256_0+1_20151114_001652",
"SM304256_0+1_20151114_011652",
"SM304256_0+1_20151114_021652",
"SM304256_0+1_20151114_031652",
Expand All @@ -173,42 +203,19 @@ public static void ContentDescriptionDev()
"SM304256_0+1_20151114_211652",
"SM304256_0+1_20151114_221652",
"SM304256_0+1_20151114_231652",
};

//PREPARE STRONG WIND TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez02\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//WindStrong1.WriteTemplateToFile(ipDir, opDir);

//PREPARE LIGHT WIND TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez03\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//WindLight1.WriteTemplateToFile(ipDir, opDir);

//PREPARE LIGHT RAIN TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez08\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//WindLight1.WriteTemplateToFile(ipDir, opDir);

//PREPARE BIRD MORNING CHORUS1 TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez05\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//BirdMorningChorus1.WriteTemplateToFile(ipDir, opDir);
};

//PREPARE MEZZANINE-TASMAN ISLAND SILVER-EYE TEMPLATE
//var ipDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\Mez08\Towsey.Acoustic");
//var opDir = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription");
//SilverEyeMezTasmanIs.WriteTemplateToFile(ipDir, opDir);
var templatesConfig = new FileInfo(@"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\ContentDescriptionTemplates.yml");

var contentPlots = ContentDescription.ContentDescriptionOfMultipleRecordingFiles(directories, baseNames);
var contentPlots = ContentDescription.ContentDescriptionOfMultipleRecordingFiles(directories, baseNames, templatesConfig);

// Attach content description plots to LDFC spectrogram
var path = Path.Combine(@"C:\Ecoacoustics\Output\Test\Test24HourRecording", "Testing__2Maps.png");
var ldfcSpectrogram = Image.FromFile(path);

//Write image + contentPlots to file.
var image = ContentVisualization.DrawLdfcSpectrogramWithContentScoreTracks(ldfcSpectrogram, contentPlots);
var path1 = Path.Combine(@"C:\Ecoacoustics\Output\ContentDescription", "Testing_2Maps.CONTENT10.png");
var path1 = Path.Combine(@"C:\Ecoacoustics\Output\ContentDescription", "Testing_2Maps.CONTENTnew01.png");
image.Save(path1);
}

Expand Down
3 changes: 3 additions & 0 deletions src/AudioAnalysisTools/AudioAnalysisTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
<Compile Include="ActivityAndCover.cs" />
<Compile Include="BirdClefExperiment1.cs" />
<Compile Include="ChannelIntegrity.cs" />
<Compile Include="ContentDescriptionTools\ContentAlgorithms.cs" />
<Compile Include="ContentDescriptionTools\ContentDescription.cs" />
<Compile Include="ContentDescriptionTools\ContentTypes\BaseContentType.cs" />
<Compile Include="ContentDescriptionTools\ContentTypes\RainLight1.cs" />
Expand All @@ -252,6 +253,8 @@
<Compile Include="ContentDescriptionTools\DescriptionResult.cs" />
<Compile Include="ContentDescriptionTools\ContentTypes\RainHeavy1.cs" />
<Compile Include="ContentDescriptionTools\ContentTypes\WindStrong1.cs" />
<Compile Include="ContentDescriptionTools\ContentTemplate.cs" />
<Compile Include="ContentDescriptionTools\TemplateCollection.cs" />
<Compile Include="CrossCorrelation.cs" />
<Compile Include="DSP\Clipping.cs" />
<Compile Include="DSP\DSP_Filters.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// <copyright file="ContentAlgorithms.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>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AudioAnalysisTools.ContentDescriptionTools
{
using TowseyLibrary;

public static class ContentAlgorithms
{
public static double GetContent1(Dictionary<string, double[]> oneMinuteOfIndices, ContentTemplate template, Dictionary<string, double[]> templateIndices)
{
var reductionFactor = template.SpectralReductionFactor;
var reducedIndices = DataProcessing.ReduceIndicesByFactor(oneMinuteOfIndices, reductionFactor);
var oneMinuteVector = DataProcessing.ConvertDictionaryToVector(reducedIndices);
var templateVector = DataProcessing.ConvertDictionaryToVector(templateIndices);

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

//normalise the distance
distance /= Math.Sqrt(templateVector.Length);
return 1 - distance;
}
}
}
Loading

0 comments on commit 0132e83

Please sign in to comment.