Skip to content

Commit

Permalink
Testing that manifest to tesmplates works
Browse files Browse the repository at this point in the history
Issue #252 Testing that manifest to tesmplates works with various combinations of edit status.
  • Loading branch information
towsey committed Oct 7, 2019
1 parent 82f0329 commit 17a56e3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static void ContentDescriptionApplyTemplates()
var path = Path.Combine(@"C:\Ecoacoustics\Output\Test\Test24HourRecording", "Testing__2Maps.png");
var ldfcSpectrogram = Image.FromFile(path);
var image = ContentVisualization.DrawLdfcSpectrogramWithContentScoreTracks(ldfcSpectrogram, contentPlots);
var path2 = Path.Combine(@"C:\Ecoacoustics\ContentDescription", "Testing_2Maps.CONTENTnew05.png");
var path2 = Path.Combine(@"C:\Ecoacoustics\ContentDescription", "Testing_2Maps.CONTENTnew07.png");
image.Save(path2);
Console.WriteLine("# Finished scanning recording with content description templates");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public class ContentDescription
{
// All the code base for content description assumes a sampling rate of 22050 (i.e. a Nyquist = 11025) and frame size = 512 (i.e. 256 frequency bins).
public const int Nyquist = 11025;

//public int FrameSize { get; set; }
public const int FreqBinCount = 256;

public const string AnalysisString = "__Towsey.Acoustic.";

/// <summary>
Expand Down Expand Up @@ -47,7 +44,7 @@ public static List<Plot> ContentDescriptionOfMultipleRecordingFiles(FileInfo lis
var completeListOfResults = new List<DescriptionResult>();

// cycle through the directories
// WARNING: Assume one-hour duration for each recording
// TODO WARNING: Assume one-hour duration for each recording
for (int i = 0; i < filePaths.Count; i++)
{
// read the spectral indices for the current file
Expand All @@ -58,7 +55,8 @@ public static List<Plot> ContentDescriptionOfMultipleRecordingFiles(FileInfo lis
// ContentDescription.DrawNormalisedIndexMatrices(dir1, baseName, dictionary);

// get the rows and do something with them one by one.
var results = AnalyzeMinutes(templates, templatesAsDictionary, dictionaryOfRecordingIndices, i * 60); // WARNING: HACK: ASSUME ONE HOUR FILES
// TODO WARNING: HACK: ASSUME ONE HOUR FILES - must fix this.
var results = AnalyzeMinutes(templates, templatesAsDictionary, dictionaryOfRecordingIndices, i * 60);
completeListOfResults.AddRange(results);
}

Expand All @@ -72,7 +70,7 @@ public static List<Plot> ContentDescriptionOfMultipleRecordingFiles(FileInfo lis
//contentPlots = DataProcessing.SubtractModeAndSd(contentPlots);

// Use percentile thresholding followed by normalize in 0,1.
contentPlots = DataProcessing.PercentileThresholding(contentPlots, 80);
contentPlots = DataProcessing.PercentileThresholding(contentPlots, 90);
return contentPlots;
}

Expand Down Expand Up @@ -127,7 +125,7 @@ public static List<DescriptionResult> AnalyzeMinutes(
break;
}

var result = new KeyValuePair<string, double>(template.Name, score);
var result = new KeyValuePair<string, double>(template.Description, score);
descriptionResult.AddDescription(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ public class DescriptionResult
{
private readonly Dictionary<string, double> descriptionDictionary = new Dictionary<string, double>();

public DescriptionResult(int startTimeInMinutes)
{
this.StartTimeInCurrentRecordingFile = TimeSpan.FromMinutes(startTimeInMinutes);
}
public DescriptionResult(int startTimeInMinutes) => this.StartTimeInCurrentRecordingFile = TimeSpan.FromMinutes(startTimeInMinutes);

public TimeSpan StartTimeInCurrentRecordingFile { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void CreateNewFileOfTemplateDefinitions(FileInfo manifestFile, Fil
// the current manifest is not an existing template - therefore make it.
var newTemplate = CreateNewTemplateFromManifest(manifest);
newTemplate.TemplateId = i;
newTemplate.Template = CreateTemplateDeftn(manifest);
newTemplate.Template = CreateTemplateDefinition(manifest);
newTemplate.MostRecentEdit = DateTime.Now;
newTemplateList.Add(newTemplate);
continue;
Expand All @@ -51,7 +51,7 @@ public static void CreateNewFileOfTemplateDefinitions(FileInfo manifestFile, Fil
// edit an existing template but use the manifest.
var newTemplate = CreateNewTemplateFromManifest(manifest);
newTemplate.TemplateId = i;
newTemplate.Template = CreateTemplateDeftn(manifest);
newTemplate.Template = CreateTemplateDefinition(manifest);
newTemplate.MostRecentEdit = DateTime.Now;
newTemplateList.Add(newTemplate);
continue;
Expand Down Expand Up @@ -104,7 +104,7 @@ public static void CreateNewFileOfTemplateDefinitions(FileInfo manifestFile, Fil
/// <summary>
/// THis method calculates new template based on passed manifest.
/// </summary>
public static Dictionary<string, double[]> CreateTemplateDeftn(TemplateManifest templateManifest)
public static Dictionary<string, double[]> CreateTemplateDefinition(TemplateManifest templateManifest)
{
// Get the template provenance. Assume array contains only one element.
var provenanceArray = templateManifest.Provenance;
Expand Down Expand Up @@ -143,6 +143,7 @@ public static TemplateManifest CreateNewTemplateFromManifest(TemplateManifest te
var newTemplate = new TemplateManifest
{
Name = templateManifest.Name,
Description = templateManifest.Description,
TemplateId = templateManifest.TemplateId,
FeatureExtractionAlgorithm = templateManifest.FeatureExtractionAlgorithm,
SpectralReductionFactor = templateManifest.SpectralReductionFactor,
Expand Down

0 comments on commit 17a56e3

Please sign in to comment.