/// <summary> /// Cycles through a set of acoustic indices in the order listed and calculates one acoustic signature for each minute of recording. /// WARNING!!!! It is assumed that the indices are listed in temporal order of the original recordings and that the original recordings were continuous. /// When these conditions satisfied, the returned plots contain scores over consecutive minutes. /// Alternatively could read recording minute from its file name. /// </summary> /// <param name="listOfIndexFiles">A text file, each line being the path to the acoustic indices derived from one recording.</param> /// <param name="templatesFile">A json file containing an array of acoustic templates.</param> /// <returns>A list of plots - each plot is the minute by minute scores for a single template.</returns> public static Dictionary <string, double[]> ContentDescriptionOfMultipleRecordingFiles(FileInfo listOfIndexFiles, FileInfo templatesFile) { // TODO: inline this method into AnalysisPrograms.ContentDescription.UseModel.Analyse const int startMinute = 0; // Read in all the prepared templates var templates = Json.Deserialize <FunctionalTemplate[]>(templatesFile); var templatesAsDictionary = DataProcessing.ExtractDictionaryOfTemplateDictionaries(templates); // Read in list of paths to index files var filePaths = FileTools.ReadTextFile(listOfIndexFiles.FullName); // init a list to collect description results var completeListOfResults = new List <DescriptionResult>(); //init a minute index int elapsedMinutes = 0; // cycle through the directories for (int i = 0; i < filePaths.Count; i++) { // read the spectral indices for the current file. //IMPORTANT: This method returns normalised index values var dictionaryOfRecordingIndices = DataProcessing.ReadIndexMatrices(filePaths[i]); // Draw the index matrices for check/debug purposes // var dir1 = new DirectoryInfo(@"C:\Ecoacoustics\Output\ContentDescription"); // ContentDescription.DrawNormalisedIndexMatrices(dir1, baseName, dictionary); // get the rows and do something with them one by one. var results = AnalyzeMinutes(templates, templatesAsDictionary, dictionaryOfRecordingIndices, elapsedMinutes); completeListOfResults.AddRange(results); // calculate the elapsed minutes in this recording var matrix = dictionaryOfRecordingIndices.FirstValue(); elapsedMinutes += matrix.GetLength(0); } // convert completeListOfResults to dictionary of score arrays var contentDictionary = DataProcessing.ConvertResultsToDictionaryOfArrays(completeListOfResults, elapsedMinutes, startMinute); return(contentDictionary); }
/// <summary> /// This method calculates new template based on passed manifest. /// </summary> public static Dictionary <string, double[]> CreateTemplateDefinition(TemplateManifest templateManifest) { // Get the template provenance. Assume array contains only one element. var provenanceArray = templateManifest.Provenance; var provenance = provenanceArray[0]; var sourceDirectory = provenance.Directory; var baseName = provenance.Basename; // Read all indices from the complete recording. The path variable is a partial path requiring to be appended. var path = Path.Combine(sourceDirectory, baseName + ContentSignatures.AnalysisString); var dictionaryOfIndices = DataProcessing.ReadIndexMatrices(path); var algorithmType = templateManifest.FeatureExtractionAlgorithm; Dictionary <string, double[]> newTemplateDefinition; switch (algorithmType) { case 1: newTemplateDefinition = ContentAlgorithms.CreateFullBandTemplate1(templateManifest, dictionaryOfIndices); break; case 2: newTemplateDefinition = ContentAlgorithms.CreateBroadbandTemplate1(templateManifest, dictionaryOfIndices); break; case 3: newTemplateDefinition = ContentAlgorithms.CreateNarrowBandTemplate1(templateManifest, dictionaryOfIndices); break; default: //LoggedConsole.WriteWarnLine("Algorithm " + algorithmType + " does not exist."); newTemplateDefinition = null; break; } return(newTemplateDefinition); }