diff --git a/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs b/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs index 8299a8223..486e304c5 100644 --- a/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs +++ b/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs @@ -178,7 +178,7 @@ public override RecognizerResults Recognize( spectrogram.NyquistFrequency); // prepare plot of resultant blob decibel array. - var plot = PreparePlot(decibelArray, $"{profileName} (Blob:db Intensity)", bp.DecibelThreshold.Value); + var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Blob:db Intensity)", bp.DecibelThreshold.Value); plots.Add(plot); // iii: CONVERT blob decibel SCORES TO ACOUSTIC EVENTS. @@ -204,7 +204,7 @@ public override RecognizerResults Recognize( wp, segmentStartOffset); - var plot = PreparePlot(decibelArray, $"{profileName} (Whistle:dB Intensity)", wp.DecibelThreshold.Value); + var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Whistle:dB Intensity)", wp.DecibelThreshold.Value); plots.Add(plot); } else if (profileConfig is ForwardTrackParameters tp) @@ -215,7 +215,7 @@ public override RecognizerResults Recognize( tp, segmentStartOffset); - var plot = PreparePlot(decibelArray, $"{profileName} (Chirps:dB Intensity)", tp.DecibelThreshold.Value); + var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Chirps:dB Intensity)", tp.DecibelThreshold.Value); plots.Add(plot); } else if (profileConfig is OneframeTrackParameters cp) @@ -226,7 +226,7 @@ public override RecognizerResults Recognize( cp, segmentStartOffset); - var plot = PreparePlot(decibelArray, $"{profileName} (Clicks:dB Intensity)", cp.DecibelThreshold.Value); + var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Clicks:dB Intensity)", cp.DecibelThreshold.Value); plots.Add(plot); } else if (profileConfig is UpwardTrackParameters vtp) @@ -237,7 +237,7 @@ public override RecognizerResults Recognize( vtp, segmentStartOffset); - var plot = PreparePlot(decibelArray, $"{profileName} (VerticalTrack:dB Intensity)", vtp.DecibelThreshold.Value); + var plot = Plot.PreparePlot(decibelArray, $"{profileName} (VerticalTrack:dB Intensity)", vtp.DecibelThreshold.Value); plots.Add(plot); } else if (profileConfig is HarmonicParameters hp) @@ -257,7 +257,7 @@ public override RecognizerResults Recognize( hp.MaxFormantGap.Value, segmentStartOffset); - var plot = PreparePlot(harmonicIntensityScores, $"{profileName} (Harmonics:dct intensity)", hp.DctThreshold.Value); + var plot = Plot.PreparePlot(harmonicIntensityScores, $"{profileName} (Harmonics:dct intensity)", hp.DctThreshold.Value); plots.Add(plot); } else if (profileConfig is OscillationParameters op) @@ -281,7 +281,7 @@ public override RecognizerResults Recognize( spectralEvents = new List(oscillationEvents); //plots.Add(new Plot($"{profileName} (:OscillationScore)", scores, op.EventThreshold)); - var plot = PreparePlot(scores, $"{profileName} (:OscillationScore)", op.EventThreshold); + var plot = Plot.PreparePlot(scores, $"{profileName} (:OscillationScore)", op.EventThreshold); plots.Add(plot); } else @@ -438,23 +438,6 @@ public static string SaveDebugSpectrogram(RecognizerResults results, Config gene return path; } - /// - /// Prepares a plot of an array of score values. - /// To obtain a more useful display, the maximum display value is set to 3 times the threshold value. - /// - /// an array of double. - /// to accompany the plot. - /// A threshold value to be drawn on the plot. - /// the plot. - private static Plot PreparePlot(double[] array, string title, double threshold) - { - double intensityNormalizationMax = 3 * threshold; - var eventThreshold = threshold / intensityNormalizationMax; - var normalisedIntensityArray = DataTools.NormaliseInZeroOne(array, 0, intensityNormalizationMax); - var plot = new Plot(title, normalisedIntensityArray, eventThreshold); - return plot; - } - private static SonogramConfig ParametersToSonogramConfig(CommonParameters common) { int windowSize = (int)common.FrameSize; diff --git a/src/AudioAnalysisTools/Tracks/ForwardTrackAlgorithm.cs b/src/AudioAnalysisTools/Tracks/ForwardTrackAlgorithm.cs index d28280e18..d354ce155 100644 --- a/src/AudioAnalysisTools/Tracks/ForwardTrackAlgorithm.cs +++ b/src/AudioAnalysisTools/Tracks/ForwardTrackAlgorithm.cs @@ -21,6 +21,28 @@ namespace AudioAnalysisTools.Tracks public static class ForwardTrackAlgorithm { + public static (List Events, List DecibelPlots) GetForwardTracks( + SpectrogramStandard spectrogram, + ForwardTrackParameters parameters, + TimeSpan segmentStartOffset, + string profileName) + { + var thresholds = parameters.DecibelThreshold; + + double[] decibelArray; + List spectralEvents; + var plots = new List(); + + (spectralEvents, decibelArray) = ForwardTrackAlgorithm.GetForwardTracks( + spectrogram, + parameters, + segmentStartOffset); + + var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Chirps:dB Intensity)", thresholds.Value); + plots.Add(plot); + return (spectralEvents, plots); + } + /// /// This method returns foward (spectral peak) tracks enclosed in spectral events. /// It averages dB log values incorrectly but it is faster than doing many log conversions. diff --git a/src/TowseyLibrary/Plot.cs b/src/TowseyLibrary/Plot.cs index eab1eda79..8084bbfff 100644 --- a/src/TowseyLibrary/Plot.cs +++ b/src/TowseyLibrary/Plot.cs @@ -25,6 +25,23 @@ public Plot(string _title, double[] _data, double _threshold) this.threshold = _threshold; } + /// + /// Prepares a plot of an array of score values. + /// To obtain a more useful display, the maximum display value is set to 3 times the threshold value. + /// + /// an array of double. + /// to accompany the plot. + /// A threshold value to be drawn on the plot. + /// the plot. + public static Plot PreparePlot(double[] array, string title, double threshold) + { + double intensityNormalizationMax = 3 * threshold; + var eventThreshold = threshold / intensityNormalizationMax; + var normalisedIntensityArray = DataTools.NormaliseInZeroOne(array, 0, intensityNormalizationMax); + var plot = new Plot(title, normalisedIntensityArray, eventThreshold); + return plot; + } + public string title { get; set; } public double[] data { get; set; }