Exemplo n.º 1
0
        public IndexBoundingBox GetBoundingBox(ITimeSegment t)
        {
            Debug.Assert(t.FirstYear != t.LastYear || t.FirstDay <= t.LastDay);
            int lastDay = t.LastDay;

            bool isLeapYear = (t.FirstYear == t.LastYear && DateTime.IsLeapYear(t.FirstYear));
            var  p1         = DaysOfYearConversions.ProjectFirstDay(t.FirstDay, isLeapYear);
            var  p2         = DaysOfYearConversions.ProjectLastDay(t.LastDay, isLeapYear);

            IndexBoundingBox bb;

            if (lastDay < t.FirstDay)
            {
                bb = new IndexBoundingBox()
                {
                    first = 0, last = 11
                }
            }
            ;                                                         //new year overlap
            else
            {
                bb = new IndexBoundingBox()
                {
                    first = (int)Math.Floor(p1),
                    last  = (int)Math.Floor(p2 - 1e-2) //the shift is less than "1 day" is needed to handle exact end of the month
                }
            };

            return(bb);
        }
Exemplo n.º 2
0
        public IndexBoundingBox GetBoundingBox(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 minInd = Array.BinarySearch(extendedGrid, min);

            if (minInd < 0)
            {
                minInd = ~minInd - 1;
            }


            int maxInd = Array.BinarySearch(extendedGrid, max);

            if (maxInd < 0)
            {
                maxInd = ~maxInd;
            }

            bool wholeGlobe = maxInd - minInd == 360;

            minInd = minInd % initialLen;
            maxInd = maxInd % initialLen;

            IndexBoundingBox bb;

            if (maxInd < minInd || wholeGlobe)
            {
                bb = new IndexBoundingBox()
                {
                    first = 0, last = initialLen - 1
                }
            }
            ;
            else
            {
                bb = new IndexBoundingBox()
                {
                    first = minInd, last = maxInd
                }
            };


            return(bb);
        }
        public IndexBoundingBox GetBoundingBox(ITimeSegment t)
        {
            var intervals = GetTimeIntervals(t).Select(irvl => timeAxisProjection.ProjectIntervalToTheAxis(irvl)).ToArray();
            IndexBoundingBox boundingBox = new IndexBoundingBox();

            foreach (var interval in intervals)
            {
                var bb1 = dataMaskProvider.GetBoundingBox(grid, interval.Item1, interval.Item2);
                boundingBox = IndexBoundingBox.Union(boundingBox, bb1);
            }

            return(boundingBox);
        }
Exemplo n.º 4
0
        public IndexBoundingBox GetBoundingBox(double min, double max)
        {
            IndexBoundingBox boundingBox = weightsProvider.GetBoundingBox(grid, min, max);

            if (areLatsInverted && !boundingBox.IsSingular)
            {
                boundingBox = new IndexBoundingBox {
                    first = backIndexOffset - boundingBox.last, last = backIndexOffset - boundingBox.first
                }
            }
            ;
            return(boundingBox);
        }
Exemplo n.º 5
0
        public int[] GetIndices(double[] grid, double min, double max, DoubleEpsComparer dec = null)
        {
            IndexBoundingBox bb = GetBoundingBox(grid, min, max, dec);

            if (bb.IsSingular)
            {
                return(new int[0]);
            }
            else
            {
                int first = bb.first;
                return(Enumerable.Range(first, bb.last - first + 1).ToArray());
            }
        }
Exemplo n.º 6
0
        public void ContinuousDaysStepIntegratorGetBoundingBox()
        {
            double[] axis = new double[] { 0, 31, 61, 92 };
            DaysAxisStepIntegrator mmsi = new DaysAxisStepIntegrator(axis, new DateTime(2001, 5, 1)); //121 - 1 may

            IndexBoundingBox bb = mmsi.GetBoundingBox(new TimeSegment(2001, 2001, 152 /*1 june*/, 212 /*31 jul*/, 0, 24));

            Assert.AreEqual(1, bb.first);
            Assert.AreEqual(2, bb.last);

            bb = mmsi.GetBoundingBox(new TimeSegment(2001, 2001, 135 /*15 may*/, 166 /*15 june*/, 0, 24));

            Assert.AreEqual(0, bb.first);
            Assert.AreEqual(1, bb.last);
        }
        public void ContinuousDaysStepIntegrator360GetBoundingBox()
        {
            double[] axis = new double[] { 14400, 14430, 14460, 14490, 14520, 14550, 14580, 14610 };
            ContinousDaysAxisIntegrator360 <StepFunctionWeightsProvider, ContinousMeansCoverageEvaluator> mmsi = new ContinousDaysAxisIntegrator360 <StepFunctionWeightsProvider, ContinousMeansCoverageEvaluator>(axis, 1960, 1);

            IndexBoundingBox bb = mmsi.GetBoundingBox(new TimeSegment(2000, 2000, 153 /*1 june*/, 213 /*31 jul*/, 0, 24));

            Assert.AreEqual(5, bb.first);
            Assert.AreEqual(6, bb.last);

            bb = mmsi.GetBoundingBox(new TimeSegment(2000, 2000, 135 /*15 may*/, 166 /*15 june*/, 0, 24));

            Assert.AreEqual(4, bb.first);
            Assert.AreEqual(5, bb.last);
        }
Exemplo n.º 8
0
        public IndexBoundingBox GetBoundingBox(double coord)
        {
            int first, last;

            if (coord < extendedGrid[0])
            {
                coord += 360.0;
            }

            IndexBoundingBox bb;
            int ind = Array.BinarySearch(extendedGrid, coord);

            if (ind >= 0)
            {
                ind = ind % initialLen;
                bb  = new IndexBoundingBox()
                {
                    first = ind, last = ind
                };
            }
            else
            {
                ind   = ~ind;
                first = (ind - 1) % initialLen;
                last  = ind % initialLen;
                if (last < first)
                {
                    bb = new IndexBoundingBox()
                    {
                        first = 0, last = initialLen - 1
                    }
                }
                ;
                else
                {
                    bb = new IndexBoundingBox()
                    {
                        first = first, last = last
                    }
                };
            }
            return(bb);
        }
        public void TestGetBoundingBox()
        {
            MonthlyMeansOverYearsStepIntegratorFacade a = new MonthlyMeansOverYearsStepIntegratorFacade();
            IndexBoundingBox ibb = a.GetBoundingBox(new TimeSegment(1931, 1932, 106, 166, 0, 24));

            Assert.AreEqual(3, ibb.first);
            Assert.AreEqual(5, ibb.last);

            ibb = a.GetBoundingBox(new TimeSegment(1944, 1944, 107, 167, 0, 24));
            Assert.AreEqual(3, ibb.first);
            Assert.AreEqual(5, ibb.last);

            ibb = a.GetBoundingBox(new TimeSegment(1931, 1931, 244, 273, 0, 24));
            Assert.AreEqual(8, ibb.first);
            Assert.AreEqual(8, ibb.last);

            ibb = a.GetBoundingBox(new TimeSegment(1931, 1932, 305, 59, 0, 24));
            Assert.AreEqual(0, ibb.first);
            Assert.AreEqual(11, ibb.last);
        }