public static void TestTemplates(FileInfo listOfIndexFiles, FileInfo templatesFile, FileInfo imageOfLdfcSpectrogram) { var contentDictionary = ContentSignatures.ContentDescriptionOfMultipleRecordingFiles(listOfIndexFiles, templatesFile); // Write the results to a csv file var outputDirectory = templatesFile.DirectoryName; var filePath = Path.Combine(outputDirectory ?? throw new InvalidOperationException("Output directory does not exist."), "AcousticSignatures.csv"); FileTools.WriteDictionaryAsCsvFile(contentDictionary, filePath); // get content description plots and use to examine score distributions. var contentPlots = ContentSignatures.GetPlots(contentDictionary); var images = GraphsAndCharts.DrawPlotDistributions(contentPlots); var plotsImage = ImageTools.CombineImagesVertically(images); var path1 = Path.Combine(outputDirectory, "ScoreDistributions.png"); plotsImage.Save(path1); // Attach plots to LDFC spectrogram and write to file var imageList = new List <Image <Rgb24> >(); if (imageOfLdfcSpectrogram != null) { var ldfcSpectrogram = Image.Load <Rgb24>(imageOfLdfcSpectrogram.FullName); imageList.Add(ldfcSpectrogram); } if (contentPlots != null) { int plotHeight = 30; foreach (var plot in contentPlots) { var imageOfPlot = plot.DrawAnnotatedPlot(plotHeight); imageList.Add(imageOfPlot); } } if (imageList.Count != 0) { var opImage = ImageTools.CombineImagesVertically(imageList); var path2 = Path.Combine(outputDirectory, templatesFile.BaseName() + ".TestOfTemplates.png"); opImage.Save(path2); } //Console.WriteLine("# Finished test of content description templates"); }
public static void Execute(Arguments arguments) { MainEntry.WarnIfDeveloperEntryUsed(); TowseyLibrary.Log.Verbosity = 1; string date = "# DATE AND TIME: " + DateTime.Now; LoggedConsole.WriteLine("# Running acoustic event detection."); LoggedConsole.WriteLine(date); FileInfo recodingFile = arguments.Source; var recodingBaseName = recodingFile.BaseName(); DirectoryInfo outputDir = arguments.Output.Combine(EcosoundsAedIdentifier); outputDir.Create(); Log.Info("# Output folder =" + outputDir); Log.Info("# Recording file: " + recodingFile.Name); // READ PARAMETER VALUES FROM INI FILE AedConfiguration configruation = ConfigFile.Deserialize <AedConfiguration>(arguments.Config); var aedConfig = GetAedParametersFromConfigFileOrDefaults(configruation); var results = Detect(recodingFile, aedConfig, TimeSpan.Zero); // print image // save image of sonograms var outputImagePath = outputDir.CombineFile(recodingBaseName + ".Sonogram.png"); Image image = DrawSonogram(results.Item3, results.Item1); image.Save(outputImagePath.FullName, ImageFormat.Png); Log.Info("Image saved to: " + outputImagePath.FullName); // output csv var outputCsvPath = outputDir.CombineFile(recodingBaseName + ".Events.csv"); WriteEventsFileStatic(outputCsvPath, results.Item1); Log.Info("CSV file saved to: " + outputCsvPath.FullName); TowseyLibrary.Log.WriteLine("Finished"); }
public static void Execute(Arguments arguments) { string date = "# DATE AND TIME: " + DateTime.Now; Log.WriteLine("# DETECTING LOW FREQUENCY AMPLITUDE OSCILLATIONS"); Log.WriteLine(date); Log.Verbosity = 1; FileInfo recordingFile = arguments.Source; FileInfo iniPath = arguments.Config.ToFileInfo(); DirectoryInfo outputDir = arguments.Output; string opFName = "OcillationReconiserResults.cav"; string opPath = outputDir + opFName; Log.WriteIfVerbose("# Output folder =" + outputDir); //READ PARAMETER VALUES FROM INI FILE var config = new ConfigDictionary(iniPath); Dictionary <string, string> dict = config.GetTable(); Dictionary <string, string> .KeyCollection keys = dict.Keys; bool doSegmentation = bool.Parse(dict[key_DO_SEGMENTATION]); int minHz = int.Parse(dict[key_MIN_HZ]); int maxHz = int.Parse(dict[key_MAX_HZ]); double frameOverlap = double.Parse(dict[key_FRAME_OVERLAP]); double dctDuration = double.Parse(dict[key_DCT_DURATION]); //duration of DCT in seconds double dctThreshold = double.Parse(dict[key_DCT_THRESHOLD]); //minimum acceptable value of a DCT coefficient int minOscilFreq = int.Parse(dict[key_MIN_OSCIL_FREQ]); //ignore oscillations below this threshold freq int maxOscilFreq = int.Parse(dict[key_MAX_OSCIL_FREQ]); //ignore oscillations above this threshold freq double minDuration = double.Parse(dict[key_MIN_DURATION]); //min duration of event in seconds double maxDuration = double.Parse(dict[key_MAX_DURATION]); //max duration of event in seconds double eventThreshold = double.Parse(dict[key_EVENT_THRESHOLD]); //min score for an acceptable event int DRAW_SONOGRAMS = int.Parse(dict[key_DRAW_SONOGRAMS]); //options to draw sonogram Log.WriteIfVerbose("Freq band: {0} Hz - {1} Hz.)", minHz, maxHz); Log.WriteIfVerbose("Oscill bounds: " + minOscilFreq + " - " + maxOscilFreq + " Hz"); Log.WriteIfVerbose("minAmplitude = " + dctThreshold); Log.WriteIfVerbose("Duration bounds: " + minDuration + " - " + maxDuration + " seconds"); //############################################################################################################################################# var results = Execute_ODDetect(recordingFile, doSegmentation, minHz, maxHz, frameOverlap, dctDuration, dctThreshold, minOscilFreq, maxOscilFreq, eventThreshold, minDuration, maxDuration); Log.WriteLine("# Finished detecting oscillation events."); //############################################################################################################################################# var sonogram = results.Item1; var hits = results.Item2; var scores = results.Item3; var predictedEvents = results.Item4; var intensity = results.Item5; var analysisDuration = results.Item6; Log.WriteLine("# Event Count = " + predictedEvents.Count()); int pcHIF = 100; if (intensity != null) { int hifCount = intensity.Count(p => p >= 0.001); //count of high intensity frames pcHIF = 100 * hifCount / sonogram.FrameCount; } //write event count to results file. double sigDuration = sonogram.Duration.TotalSeconds; string fname = recordingFile.BaseName(); int count = predictedEvents.Count; //string str = String.Format("#RecordingName\tDuration(sec)\t#Ev\tCompT(ms)\t%hiFrames\n{0}\t{1}\t{2}\t{3}\t{4}\n", fname, sigDuration, count, analysisDuration.TotalMilliseconds, pcHIF); string str = string.Format("{0}\t{1}\t{2}\t{3}\t{4}", fname, sigDuration, count, analysisDuration.TotalMilliseconds, pcHIF); StringBuilder sb = AcousticEvent.WriteEvents(predictedEvents, str); FileTools.WriteTextFile(opPath, sb.ToString()); //draw images of sonograms string imagePath = outputDir + fname + ".png"; if (DRAW_SONOGRAMS == 2) { DrawSonogram(sonogram, imagePath, hits, scores, predictedEvents, eventThreshold, intensity); } else if (DRAW_SONOGRAMS == 1 && predictedEvents.Count > 0) { DrawSonogram(sonogram, imagePath, hits, scores, predictedEvents, eventThreshold, intensity); } Log.WriteLine("# Finished recording:- " + recordingFile.Name); }