diff --git a/src/AnalysisPrograms/Sandpit.cs b/src/AnalysisPrograms/Sandpit.cs index a5326c07c..bdbf8defa 100644 --- a/src/AnalysisPrograms/Sandpit.cs +++ b/src/AnalysisPrograms/Sandpit.cs @@ -64,7 +64,7 @@ public override Task Execute(CommandLineApplication app) Log.WriteLine("# Start Time = " + tStart.ToString(CultureInfo.InvariantCulture)); //AnalyseFrogDataSet(); - //Audio2CsvOverOneFile(); + Audio2CsvOverOneFile(); //Audio2CsvOverMultipleFiles(); // used to get files from availae for Black rail and Least Bittern papers. @@ -103,8 +103,8 @@ public override Task Execute(CommandLineApplication app) //TestTernaryPlots(); //TestDirectorySearchAndFileSearch(); //TestNoiseReduction(); - Oscillations2014.TESTMETHOD_DrawOscillationSpectrogram(); - Oscillations2014.TESTMETHOD_GetSpectralIndex_Osc(); + //Oscillations2014.TESTMETHOD_DrawOscillationSpectrogram(); + //Oscillations2014.TESTMETHOD_GetSpectralIndex_Osc(); //Test_DrawFourSpectrograms(); Console.WriteLine("# Finished Sandpit Task! Press any key to exit."); @@ -380,8 +380,14 @@ public static void Audio2CsvOverOneFile() // SERF RECORDINGS FROM 19th June 2013 // these are six hour recordings - string recordingPath = @"G:\Ecoacoustics\WavFiles\SERF\2013June19\SERF_20130619_064615_000.wav"; - string outputPath = @"C:\Ecoacoustics\Output\SERF\SERFIndicesNew_2013June19"; + //string recordingPath = @"G:\Ecoacoustics\WavFiles\SERF\2013June19\SERF_20130619_064615_000.wav"; + //string outputPath = @"C:\Ecoacoustics\Output\SERF\SERFIndicesNew_2013June19"; + //string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\Towsey.Acoustic.yml"; + + // USE 24-hour data or parts of from MEZ, TASMAn ISLAND, liz Znidersic + // these are six hour recordings + string recordingPath = @"C:\Ecoacoustics\WavFiles\LizZnidersic\TasmanIsland2015_Unit2_Mez\SM304256_0+1_20151114_031652.wav"; + string outputPath = @"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\04"; string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\Towsey.Acoustic.yml"; // GROUND PARROT diff --git a/src/AudioAnalysisTools/Indices/IndexDisplay.cs b/src/AudioAnalysisTools/Indices/IndexDisplay.cs index 2317462cc..fdb2018bc 100644 --- a/src/AudioAnalysisTools/Indices/IndexDisplay.cs +++ b/src/AudioAnalysisTools/Indices/IndexDisplay.cs @@ -11,7 +11,7 @@ namespace AudioAnalysisTools.Indices using System.Linq; using System.Reflection; using AnalysisBase.ResultBases; - using AudioAnalysisTools.StandardSpectrograms; + using StandardSpectrograms; using log4net; using LongDurationSpectrograms; using TowseyLibrary; @@ -74,11 +74,11 @@ public static Bitmap DrawImageOfSummaryIndices( titleText, indexCalculationDuration, recordingStartDate, - sunriseDataFile = null); + sunriseDataFile); } /// - /// Converts summary indices to a tracks image + /// Converts summary indices to a tracks image. /// public static Bitmap DrawImageOfSummaryIndices( Dictionary listOfIndexProperties, @@ -98,6 +98,7 @@ public static Bitmap DrawImageOfSummaryIndices( var bitmapList = new List>(dictionaryOfSummaryIndices.Keys.Count); // accumulate the individual tracks in a List + var backgroundColour = Color.White; foreach (string key in dictionaryOfSummaryIndices.Keys) { string correctKey = key; @@ -130,53 +131,51 @@ public static Bitmap DrawImageOfSummaryIndices( continue; } - string name = ip.Name; double[] array = dictionaryOfSummaryIndices[key]; scaleLength = array.Length; - Image bitmap = ip.GetPlotImage(array, errors); + // alternate rows have different colour to make tracks easier to read + backgroundColour = backgroundColour == Color.LightGray ? Color.White : Color.LightGray; + var bitmap = ip.GetPlotImage(array, backgroundColour, errors); bitmapList.Add(Tuple.Create(ip, bitmap)); } var listOfBitmaps = bitmapList - .OrderBy(tuple => tuple.Item1.Order) + // .OrderBy(tuple => tuple.Item1.Order) // don't order because want to preserve alternating gray/white rows. .Select(tuple => tuple.Item2) .Where(b => b != null).ToList(); //set up the composite image parameters - int X_offset = 2; - int graphWidth = X_offset + scaleLength; - int imageWidth = X_offset + scaleLength + TrackEndPanelWidth; - TimeSpan scaleDuration = TimeSpan.FromMinutes(scaleLength); - int imageHt = trackHeight * (listOfBitmaps.Count + 4); //+3 for title and top and bottom time tracks + int x_offset = 2; + int graphWidth = x_offset + scaleLength; + int imageWidth = x_offset + scaleLength + TrackEndPanelWidth; Bitmap titleBmp = ImageTrack.DrawTitleTrack(imageWidth, trackHeight, titleText); - //Bitmap time1Bmp = ImageTrack.DrawTimeTrack(scaleDuration, TimeSpan.Zero, DrawSummaryIndices.TimeScale, graphWidth, TrackHeight, "Time (hours)"); TimeSpan xAxisPixelDuration = indexCalculationDuration; TimeSpan fullDuration = TimeSpan.FromTicks(xAxisPixelDuration.Ticks * graphWidth); Bitmap timeBmp1 = ImageTrack.DrawTimeRelativeTrack(fullDuration, graphWidth, trackHeight); Bitmap timeBmp2 = timeBmp1; - Bitmap suntrack = null; DateTimeOffset? dateTimeOffset = recordingStartDate; if (dateTimeOffset.HasValue) { // draw extra time scale with absolute start time. AND THEN Do SOMETHING WITH IT. timeBmp2 = ImageTrack.DrawTimeTrack(fullDuration, dateTimeOffset, graphWidth, trackHeight); - suntrack = SunAndMoon.AddSunTrackToImage(scaleLength, dateTimeOffset, sunriseDataFile); } //draw the composite bitmap - var imageList = new List(); - imageList.Add(titleBmp); - imageList.Add(timeBmp1); - for (int i = 0; i < listOfBitmaps.Count; i++) + var imageList = new List { - imageList.Add(listOfBitmaps[i]); + titleBmp, + timeBmp1, + }; + + foreach (var image in listOfBitmaps) + { + imageList.Add(image); } imageList.Add(timeBmp2); - imageList.Add(suntrack); - Bitmap compositeBmp = (Bitmap)ImageTools.CombineImagesVertically(imageList); + var compositeBmp = (Bitmap)ImageTools.CombineImagesVertically(imageList); return compositeBmp; } diff --git a/src/AudioAnalysisTools/Indices/IndexProperties.cs b/src/AudioAnalysisTools/Indices/IndexProperties.cs index f2e6991e1..33a9fcf3f 100644 --- a/src/AudioAnalysisTools/Indices/IndexProperties.cs +++ b/src/AudioAnalysisTools/Indices/IndexProperties.cs @@ -260,12 +260,14 @@ public string GetPlotAnnotation() return string.Format(" {0} ({1:f2} .. {2:f2} {3})", this.Name, this.NormMin, this.NormMax, this.Units); } + public Image GetPlotImage(double[] array, List errors = null) => this.GetPlotImage(array, Color.White, errors); + /// /// For writing this method: /// See CLASS: DrawSummaryIndices /// METHOD: Bitmap ConstructVisualIndexImage(DataTable dt, string title, int timeScale, double[] order, bool doNormalise) /// - public Image GetPlotImage(double[] array, List errors = null) + public Image GetPlotImage(double[] array, Color backgroundColour, List errors = null) { int dataLength = array.Length; string annotation = this.GetPlotAnnotation(); @@ -273,11 +275,10 @@ public Image GetPlotImage(double[] array, List errors = null) int trackWidth = dataLength + IndexDisplay.TrackEndPanelWidth; int trackHeight = IndexDisplay.DefaultTrackHeight; - Color[] grayScale = ImageTools.GrayScale(); Bitmap bmp = new Bitmap(trackWidth, trackHeight); Graphics g = Graphics.FromImage(bmp); - g.Clear(grayScale[240]); + g.Clear(backgroundColour); // for pixels in the line for (int i = 0; i < dataLength; i++) @@ -312,11 +313,8 @@ public Image GetPlotImage(double[] array, List errors = null) bmp.SetPixel(i, 0, Color.Gray); } - // end over all pixels - int endWidth = trackWidth - dataLength; var font = new Font("Arial", 9.0f, FontStyle.Regular); - g.FillRectangle(Brushes.Black, dataLength + 1, 0, endWidth, trackHeight); - g.DrawString(annotation, font, Brushes.White, new PointF(dataLength + 5, 2)); + g.DrawString(annotation, font, Brushes.Black, new PointF(dataLength, 5)); // now add in image patches for possible erroneous index segments if (errors != null && errors.Count > 0)