Exemplo n.º 1
0
        /// <summary>
        /// Gets the statistics of all the values. If the entire content is not currently in-ram,
        /// ReadRow will be used to read individual lines and perform the calculations.
        /// </summary>
        public override void GetStatistics()
        {
            ProgressMeter pm = new ProgressMeter(ProgressHandler, DataStrings.CalculatingStatistics, NumRows);

            T min = Global.MaximumValue <T>();
            T max = Global.MinimumValue <T>();

            double total    = 0;
            double sqrTotal = 0;
            int    count    = 0;

            if (!IsInRam || !this.IsFullyWindowed())
            {
                for (int row = 0; row < NumRowsInFile; row++)
                {
                    T[] values = ReadRow(row);
                    for (int col = 0; col < NumColumnsInFile; col++)
                    {
                        T      val    = values[col];
                        double dblVal = Global.ToDouble(val);
                        if (dblVal == NoDataValue)
                        {
                            continue;
                        }

                        if (val.CompareTo(max) > 0)
                        {
                            max = val;
                        }
                        if (val.CompareTo(min) < 0)
                        {
                            min = val;
                        }
                        total    += dblVal;
                        sqrTotal += dblVal * dblVal;
                        count++;
                    }

                    pm.CurrentValue = row;
                }
            }
            else
            {
                for (int row = 0; row < NumRows; row++)
                {
                    for (int col = 0; col < NumColumns; col++)
                    {
                        T      val    = Data[row][col];
                        double dblVal = Global.ToDouble(val);
                        if (dblVal == NoDataValue)
                        {
                            continue;
                        }

                        if (val.CompareTo(max) > 0)
                        {
                            max = val;
                        }
                        if (val.CompareTo(min) < 0)
                        {
                            min = val;
                        }
                        total    += dblVal;
                        sqrTotal += dblVal * dblVal;
                        count++;
                    }

                    pm.CurrentValue = row;
                }
            }

            Value.Updated = false;
            Minimum       = Global.ToDouble(min);
            Maximum       = Global.ToDouble(max);
            Mean          = total / count;
            NumValueCells = count;
            StdDeviation  = (float)Math.Sqrt((sqrTotal / NumValueCells) - (total / NumValueCells * (total / NumValueCells)));

            pm.Reset();
        }