From 515b2ff0177bdba75322972de9e7d73f95e15e23 Mon Sep 17 00:00:00 2001 From: Michael Towsey Date: Thu, 22 Mar 2018 10:42:53 +1000 Subject: [PATCH] additional work in sandpit Work on cluster sequence analysis --- src/AnalysisPrograms/Sandpit.cs | 59 +++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/AnalysisPrograms/Sandpit.cs b/src/AnalysisPrograms/Sandpit.cs index ebe5dbd0a..a42ff4274 100644 --- a/src/AnalysisPrograms/Sandpit.cs +++ b/src/AnalysisPrograms/Sandpit.cs @@ -103,7 +103,7 @@ public static void DrawClusterSequence() { for (int i = 1; i <= 60; i++) { - DrawClusterSequence1(i); + DrawClusterSequence2(i); } } @@ -116,7 +116,7 @@ public static void DrawClusterSequence1(int clusterId) var g = Graphics.FromImage(image); g.Clear(Color.White); - DirectoryInfo dir = new DirectoryInfo(@"H:\Documents\SensorNetworks\Students\AniekRoelofs\Complete\Complete\SummaryIndices"); + DirectoryInfo dir = new DirectoryInfo(@"H:\Documents\SensorNetworks\Students\AniekRoelofs\Results 22Feb2018\Complete\SummaryIndices"); string fileName = "Cluster60Sequence_Gympie2015June22_SuI.csv"; string path = Path.Combine(dir.FullName, fileName); @@ -158,6 +158,61 @@ public static void DrawClusterSequence1(int clusterId) //Console.ReadLine(); } + public static void DrawClusterSequence2(int requiredCusterId) + { + // set up an image into which to draw presence/absence of each cluster. + int height = 400; + int width = 1440; + + Color[] colorchart = { Color.Red, Color.Orange, Color.Green, Color.Aqua, Color.Blue, Color.BlueViolet, Color.Black, Color.DarkMagenta, Color.LawnGreen, Color.DarkRed}; + var image = new Bitmap(width, height, PixelFormat.Format24bppRgb); + var g = Graphics.FromImage(image); + g.Clear(Color.White); + + DirectoryInfo dir = new DirectoryInfo(@"H:\Documents\SensorNetworks\Students\AniekRoelofs\Results 14March2018"); + string fileName = "Cluster60_Hidstate10_Gympie2015June22_SuI_bestof4.csv"; + string path = Path.Combine(dir.FullName, fileName); + int clusterSize = 0; + + using (TextReader reader = new StreamReader(path)) + { + // read the header and ignore + string line = reader.ReadLine(); + int minCounter = 0; + while ((line = reader.ReadLine()) != null) + { + //read one line at a time in string array + string[] words = line.Split(','); + int minuteOfday = int.Parse(words[0]); + int day = minCounter / width; + int hidStateId = int.Parse(words[2]); + + if (words[1].StartsWith("NaN")) + { + image.SetPixel(minuteOfday, day, Color.Gray); + } + else + if (requiredCusterId == int.Parse(words[1])) + { + clusterSize++; + image.SetPixel(minuteOfday, day, colorchart[hidStateId - 1]); + } + + minCounter++; + } // end while + + Console.WriteLine("Counter=" + minCounter); + } //using + + g.DrawString("Cluster" + requiredCusterId + " Size=" + clusterSize, new Font("Tahoma", 20), Brushes.Black, new PointF(10, 10)); + + string imageName = $"cluster{requiredCusterId}.png"; + string savePath = Path.Combine(dir.FullName + "\\ClusterImages", imageName); + image.Save(savePath); + + // Console.ReadLine(); + } + /// /// This calls AnalysisPrograms.DrawLongDurationSpectrograms.Execute() to produce LD FC spectrograms from matrices of indices. /// See, for example, using the Pillaga Forest data.