//public static Image DrawImageOfDistribution(double[,] matrix, int width, int height, string label)
        //{
        //    double[] array = DataTools.Matrix2Array(matrix);
        //    SpectralStats stats = GetModeAndOneTailedStandardDeviation(array, width, UpperPercentileDefault);
        //    double value = stats.GetValueOfNthPercentile(UpperPercentileDefault);

        //    var image =
        //        GraphsAndCharts.DrawHistogram(
        //            label,
        //            stats.Distribution,
        //            stats.UpperPercentileBin,
        //            new Dictionary<string, double>()
        //            {
        //                        { "min",  stats.Minimum },
        //                        { "max",  stats.Maximum },
        //                        { "mode", stats.Mode },
        //                        { "sd",   stats.StandardDeviation },
        //                        { UpperPercentileLabel,  value },
        //                        { "count",  stats.Count },
        //            },
        //            width,
        //            height);
        //    return image;
        //}

        public static Dictionary <string, SpectralStats> WriteSummaryIndexDistributionStatistics(Dictionary <string, double[]> summaryIndices, DirectoryInfo outputDirectory, string fileStem)
        {
            // to accumulate the images
            int width     = 100; // pixels
            int height    = 100; // pixels
            var imageList = new List <Image>();
            Dictionary <string, SpectralStats> indexDistributionStatistics = new Dictionary <string, SpectralStats>();

            string[] indexKeys = summaryIndices.Keys.ToArray();

            foreach (string key in indexKeys)
            {
                if (summaryIndices.ContainsKey(key))
                {
                    double[]      array = summaryIndices[key];
                    SpectralStats stats = GetModeAndOneTailedStandardDeviation(array, width, UpperPercentileDefault);
                    stats.GetValueOfNthPercentile(UpperPercentileDefault, out int binId, out double value);
                    stats.UpperPercentileBin = binId;
                    indexDistributionStatistics.Add(key, stats); // add index statistics

                    // CVR (cover) and EVN (events/sec) have discrete, sparse distributions when calculating for zoomed tiles,
                    // and most values are in the zero bin.
                    // Therefore they return value = 0.0; This is a bug!
                    // To avoid this problem, set value = maximum when percentileBin = 0
                    if (binId == 0)
                    {
                        value = stats.Maximum;
                    }

                    imageList.Add(
                        GraphsAndCharts.DrawHistogram(
                            key,
                            stats.Distribution,
                            stats.UpperPercentileBin,
                            new Dictionary <string, double>()
                    {
                        { "min", stats.Minimum },
                        { "max", stats.Maximum },
                        { "mode", stats.Mode },
                        { "sd", stats.StandardDeviation },
                        { UpperPercentileLabel, value },
                        { "count", stats.Count },
                    },
                            width,
                            height));
                }
            }

            FileInfo statsFile = new FileInfo(GetSummaryStatsPath(outputDirectory, fileStem));

            Json.Serialise(statsFile, indexDistributionStatistics);

            Image  image3    = ImageTools.CombineImagesVertically(imageList.ToArray());
            string imagePath = GetSummaryImagePath(outputDirectory, fileStem);

            image3.Save(imagePath);

            return(indexDistributionStatistics);
        }
示例#2
0
        public static Dictionary <string, SpectralStats> WriteSummaryIndexDistributionStatistics(Dictionary <string, double[]> summaryIndices, DirectoryInfo outputDirectory, string fileStem)
        {
            // to accumulate the images
            int width     = 100; // pixels
            int height    = 100; // pixels
            var imageList = new List <Image>();
            Dictionary <string, SpectralStats> indexDistributionStatistics = new Dictionary <string, SpectralStats>();

            string[] indexKeys = summaryIndices.Keys.ToArray();

            foreach (string key in indexKeys)
            {
                if (summaryIndices.ContainsKey(key))
                {
                    double[]      array = summaryIndices[key];
                    SpectralStats stats = GetModeAndOneTailedStandardDeviation(array, width, UpperPercentileDefault);
                    indexDistributionStatistics.Add(key, stats); // add index statistics
                    double value = stats.GetValueOfNthPercentile(UpperPercentileDefault);

                    imageList.Add(
                        GraphsAndCharts.DrawHistogram(
                            key,
                            stats.Distribution,
                            stats.UpperPercentileBin,
                            new Dictionary <string, double>()
                    {
                        { "min", stats.Minimum },
                        { "max", stats.Maximum },
                        { "mode", stats.Mode },
                        { "sd", stats.StandardDeviation },
                        { UpperPercentileLabel, value },
                        { "count", stats.Count },
                    },
                            width,
                            height));
                }
            }

            FileInfo statsFile = new FileInfo(GetSummaryStatsPath(outputDirectory, fileStem));

            Json.Serialise(statsFile, indexDistributionStatistics);

            Image  image3    = ImageTools.CombineImagesVertically(imageList.ToArray());
            string imagePath = GetSummaryImagePath(outputDirectory, fileStem);

            image3.Save(imagePath);

            return(indexDistributionStatistics);
        }
示例#3
0
        public static Image DrawImageOfDistribution(double[,] matrix, int width, int height, string label)
        {
            SpectralStats stats = GetModeAndOneTailedStandardDeviation(matrix, width, UpperPercentileDefault);
            double        value = stats.GetValueOfNthPercentile(UpperPercentileDefault);

            var image =
                GraphsAndCharts.DrawHistogram(
                    label,
                    stats.Distribution,
                    stats.UpperPercentileBin,
                    new Dictionary <string, double>()
            {
                { "min", stats.Minimum },
                { "max", stats.Maximum },
                { "mode", stats.Mode },
                { "sd", stats.StandardDeviation },
                { UpperPercentileLabel, value },
                { "count", stats.Count },
            },
                    width,
                    height);

            return(image);
        }