public static void Execute(Arguments arguments) { MainEntry.WarnIfDeveloperEntryUsed(); if (arguments == null) { throw new NoDeveloperMethodException(); } // READ PARAMETER VALUES FROM INI FILE var config = ConfigFile.Deserialize(arguments.Config); var aedConfig = Aed.GetAedParametersFromConfigFileOrDefaults(config); var input = arguments.Source; Tuple <BaseSonogram, List <AcousticEvent> > result = Detect(input, aedConfig, Default.eprNormalisedMinScore, TimeSpan.Zero); List <AcousticEvent> eprEvents = result.Item2; eprEvents.Sort((ae1, ae2) => ae1.TimeStart.CompareTo(ae2.TimeStart)); LoggedConsole.WriteLine(); foreach (AcousticEvent ae in eprEvents) { LoggedConsole.WriteLine(ae.TimeStart + "," + ae.EventDurationSeconds + "," + ae.LowFrequencyHertz + "," + ae.HighFrequencyHertz); } LoggedConsole.WriteLine(); string outputFolder = arguments.Config.ToFileInfo().DirectoryName; string wavFilePath = input.FullName; BaseSonogram sonogram = result.Item1; string imagePath = Path.Combine(outputFolder, Path.GetFileNameWithoutExtension(wavFilePath) + ".png"); var image = Aed.DrawSonogram(sonogram, eprEvents.ConvertAcousticEventsToSpectralEvents()); image.Save(imagePath); }
/// <summary> /// Detect using EPR. /// </summary> /// <param name="wavFilePath"> /// The wav file path. /// </param> /// <param name="eprNormalisedMinScore"> /// The epr Normalised Min Score. /// </param> /// <returns> /// Tuple containing base Sonogram and list of acoustic events. /// </returns> public static Tuple <BaseSonogram, List <AcousticEvent> > Detect(FileInfo wavFilePath, Aed.AedConfiguration aedConfiguration, double eprNormalisedMinScore, TimeSpan segmentStartOffset) { Tuple <EventCommon[], AudioRecording, BaseSonogram> aed = Aed.Detect(wavFilePath, aedConfiguration, segmentStartOffset); var events = aed.Item1; var newEvents = new List <AcousticEvent>(); foreach (var be in events) { newEvents.Add(EventConverters.ConvertSpectralEventToAcousticEvent((SpectralEvent)be)); } var aeEvents = newEvents.Select(ae => Util.fcornersToRect(ae.TimeStart, ae.TimeEnd, ae.HighFrequencyHertz, ae.LowFrequencyHertz)).ToList(); Log.Debug("EPR start"); var eprRects = EventPatternRecog.DetectGroundParrots(aeEvents, eprNormalisedMinScore); Log.Debug("EPR finished"); var sonogram = aed.Item3; SonogramConfig config = sonogram.Configuration; double framesPerSec = 1 / config.GetFrameOffset(); // Surely this should go somewhere else double freqBinWidth = config.NyquistFreq / (double)config.FreqBinCount; // TODO this is common with AED var eprEvents = new List <AcousticEvent>(); foreach (var rectScore in eprRects) { var ae = new AcousticEvent( segmentStartOffset, rectScore.Item1.Left, rectScore.Item1.Right - rectScore.Item1.Left, rectScore.Item1.Bottom, rectScore.Item1.Top); ae.SetTimeAndFreqScales(framesPerSec, freqBinWidth); ae.SetTimeAndFreqScales(sonogram.NyquistFrequency, sonogram.Configuration.WindowSize, 0); ae.SetScores(rectScore.Item2, 0, 1); ae.BorderColour = aedConfiguration.AedEventColor; ae.SegmentStartSeconds = segmentStartOffset.TotalSeconds; ae.SegmentDurationSeconds = aed.Item2.Duration.TotalSeconds; eprEvents.Add(ae); } return(Tuple.Create(sonogram, eprEvents)); }
public override AnalysisResult2 Analyze <T>(AnalysisSettings analysisSettings, SegmentSettings <T> segmentSettings) { FileInfo audioFile = segmentSettings.SegmentAudioFile; var eprNormalizedMinScore = GetEprParametersFromConfigFileOrDefaults(analysisSettings.Configuration); var aedConfigFile = ConfigFile.Resolve( analysisSettings.Configuration["AedConfig"], analysisSettings.ConfigFile.Directory); var rawAedConfig = ConfigFile.Deserialize(aedConfigFile); var aedConfig = Aed.GetAedParametersFromConfigFileOrDefaults(rawAedConfig); Tuple <BaseSonogram, List <AcousticEvent> > results = Detect(audioFile, aedConfig, eprNormalizedMinScore, segmentSettings.SegmentStartOffset); var analysisResults = new AnalysisResult2(analysisSettings, segmentSettings, results.Item1.Duration) { AnalysisIdentifier = this.Identifier, Events = results.Item2.ToArray(), }; BaseSonogram sonogram = results.Item1; if (analysisSettings.AnalysisDataSaveBehavior) { this.WriteEventsFile(segmentSettings.SegmentEventsFile, analysisResults.Events); analysisResults.EventsFile = segmentSettings.SegmentEventsFile; } if (analysisSettings.AnalysisDataSaveBehavior) { var unitTime = TimeSpan.FromMinutes(1.0); analysisResults.SummaryIndices = this.ConvertEventsToSummaryIndices(analysisResults.Events, unitTime, analysisResults.SegmentAudioDuration, 0); this.WriteSummaryIndicesFile(segmentSettings.SegmentSummaryIndicesFile, analysisResults.SummaryIndices); } // save image of sonograms if (analysisSettings.AnalysisImageSaveBehavior.ShouldSave(analysisResults.Events.Length)) { Image image = Aed.DrawSonogram(sonogram, results.Item2); image.Save(segmentSettings.SegmentImageFile.FullName, ImageFormat.Png); analysisResults.ImageFile = segmentSettings.SegmentImageFile; } return(analysisResults); }
public override Task <int> Execute(CommandLineApplication app) { Aed.Execute(this); return(this.Ok()); }
public override void WriteEventsFile(FileInfo destination, IEnumerable <EventBase> results) { Aed.WriteEventsFileStatic(destination, results); }