Beispiel #1
0
        public IPs GetTempIPs(ITimeSegment t)
        {
            Debug.Assert(t.FirstYear != t.LastYear || t.FirstDay <= t.LastDay);

            bool isLeap = false;

            if (t.FirstYear == t.LastYear && DateTime.IsLeapYear(t.FirstYear))
            {
                isLeap = true;
            }


            int lastDay = t.LastDay;

            if (t.LastDay < t.FirstDay) //handling new year overlap
            {
                lastDay += 365;
            }

            double startProjection = DaysOfYearConversions.ProjectFirstDay(t.FirstDay, isLeap);
            double endProjection   = DaysOfYearConversions.ProjectLastDay(lastDay, isLeap);

            var r = coverageEvaluator.EvaluateInterval(axis, startProjection, endProjection);

            Debug.Assert(r != DataCoverageResult.OutOfData);

            int startIndex, stopIndex;

            double[] weights = weightsProvider.GetWeights(axis, startProjection, endProjection, out startIndex, out stopIndex);

            double[] accumulatedWeights = new double[12];
            for (int i = startIndex; i <= stopIndex; i++)
            {
                accumulatedWeights[i % 12] += weights[i - startIndex];
            }
            List <double> weightsL = new List <double>(12);
            List <int>    indecesL = new List <int>(12);

            for (int i = 0; i < 12; i++)
            {
                if (accumulatedWeights[i] != 0.0) //both number and NAN will cause generation of IP
                {
                    indecesL.Add(i);
                    weightsL.Add(accumulatedWeights[i]);
                }
            }

            IPs integrationPoints = new IPs {
                Indices = indecesL.ToArray(), Weights = weightsL.ToArray(), BoundingIndices = new IndexBoundingBox {
                    first = indecesL[0], last = indecesL[indecesL.Count - 1]
                }
            };

            return(integrationPoints);
        }
Beispiel #2
0
        public IPs GetIPsForCell(double min, double max)
        {
            int start, stop;

            double[] weights           = weightsProvider.GetWeights(grid, min, max, out start, out stop);
            IPs      integrationPoints = BuildIPs(start, weights);

            System.Diagnostics.Debug.Assert(Math.Abs(integrationPoints.Weights.Sum() - 1.0) < 1e-12);

            return(integrationPoints);
        }
        public IPs GetIPsForCell(double min, double max)
        {
            double minData = extendedGrid[0];

            if (max < minData || min < minData)
            {
                max += 360.0;
                min += 360.0;
            }
            if (min > max)
            {
                max += 360.0;
            }
            int start, stop;


            double[] weights           = weightsProvider.GetWeights(extendedGrid, min, max, out start, out stop);
            IPs      integrationPoints = BuildIPs(start, weights);

            return(integrationPoints);
        }
        public IPs GetTempIPs(ITimeSegment t)
        {
            var           intervals = GetTimeIntervals(t);
            var           projections = intervals.Select(a => timeAxisProjection.ProjectIntervalToTheAxis(a));
            List <int>    indecesList = new List <int>(1024);
            List <double> weightsList = new List <double>(1024);
            int           start, stop;

            double[] weights    = null;
            double   sumWeights = 0.0;

            foreach (var projection in projections)
            {
                weights = weightsProvider.GetWeights(grid, projection.Item1, projection.Item2, out start, out stop);
                if (weights.Length == 0)
                {
                    return new IPs {
                               Indices = new int[0], Weights = new double[0]
                    }
                }
                ;
                else
                {
                    weightsList.AddRange(weights);

                    indecesList.AddRange(Enumerable.Range(start, stop - start + 1));
                }
            }
            if (weights == null)
            {
                throw new InvalidOperationException("ProjectIntervalToTheAxis returned no intervals");
            }

            IPs integrationPoints;

            Dictionary <int, double> weightsDict = new Dictionary <int, double>(1024);
            int N = weightsList.Count;

            for (int i = 0; i < N; i++)
            {
                int    idx = indecesList[i];
                double w   = weightsList[i];
                if (weightsDict.ContainsKey(idx))
                {
                    weightsDict[idx] += w;
                }
                else
                {
                    weightsDict.Add(idx, w);
                }
                sumWeights += w;
            }
            int M = weightsDict.Count;

            double[] resultWeigths = new double[M];
            int[]    resultIdx     = new int[M];
            int      iter          = 0;
            double   multipier     = 1.0 / sumWeights;

            foreach (var item in weightsDict)
            {
                resultWeigths[iter] = item.Value * multipier;
                resultIdx[iter]     = item.Key;
                iter++;
            }
            integrationPoints = new IPs {
                Indices = resultIdx, Weights = resultWeigths, BoundingIndices = new IndexBoundingBox {
                    first = resultIdx.Min(), last = resultIdx.Max()
                }
            };

            Debug.Assert(Math.Abs(integrationPoints.Weights.Sum() - 1.0) < 1e-6, string.Format("the difference is {0}", Math.Abs(integrationPoints.Weights.Sum() - 1.0)));
            return(integrationPoints);
        }