Esempio n. 1
0
        public void TestParameterIgnoringProvenance(ClimateParameter p, EnvironmentalDataSource ds)
        {
            ClimateService.ServiceUrl = "http://fetchclimate2.cloudapp.net/";

            const double MoscowLat = 55.7;
            const double MoscowLon = 37.5;

            const double PacificLat = -20;
            const double PacificLon = 170;

            const double PacificLatA = -15;
            const double PacificLonA = 175;

            const double KrasnoyarskLat = 56.017;
            const double KrasnoyarskLon = 92.867;

            const double AroundKrasnoyarskLatMin = 55;
            const double AroundKrasnoyarskLonMin = 91;

            const double AroundKrasnoyarskLatMax = 60;
            const double AroundKrasnoyarskLonMax = 95;

            const double SriLankaLatMin = 5;
            const double SriLankaLonMin = 70;

            const double SriLankaLatMax = 20;
            const double SriLankaLonMax = 87;

            string varName = ClimateService.ClimateParameterToFC2VariableName(p);

            Assert.AreNotEqual("", varName, string.Format("Mapping for {0} does not exist.", p.ToString()));

            string[] sources = ClimateService.EnvironmentalDataSourceToArrayOfFC2DataSources(ds);

            //Single point fetch
            var tr1 = new TimeRegion(1961, 1990);
            var tr2 = new TimeRegion(1990, 2000);
            //Moscow
            var request1 = new FetchRequest(
                varName,
                FetchDomain.CreatePoints(
                    new double[] { MoscowLat },
                    new double[] { MoscowLon },
                    tr1),
                sources);
            var    result1 = ClimateService.FetchAsync(request1).Result;
            double sd1     = ((double[])result1["sd"].GetData())[0];
            double value1  = ((double[])result1["values"].GetData())[0];

            Assert.AreEqual(sd1, ClimateService.FetchClimateUncertainty(p, MoscowLat, MoscowLat, MoscowLon, MoscowLon, dataSource: ds));
            Assert.AreEqual(value1, ClimateService.FetchClimate(p, MoscowLat, MoscowLat, MoscowLon, MoscowLon, dataSource: ds));

            //somewhere in Pacific Ocean
            var request2 = new FetchRequest(
                varName,
                FetchDomain.CreatePoints(
                    new double[] { PacificLat },
                    new double[] { PacificLon },
                    tr1),
                sources);
            var    result2 = ClimateService.FetchAsync(request2).Result;
            double sd2     = ((double[])result2["sd"].GetData())[0];
            double value2  = ((double[])result2["values"].GetData())[0];

            Assert.AreEqual(sd2, ClimateService.FetchClimateUncertainty(p, PacificLat, PacificLat, PacificLon, PacificLon, dataSource: ds));
            Assert.AreEqual(value2, ClimateService.FetchClimate(p, PacificLat, PacificLat, PacificLon, PacificLon, dataSource: ds));

            //Cell around Krasnoyarsk
            var request3 = new FetchRequest(
                varName,
                FetchDomain.CreateCells(
                    new double[] { AroundKrasnoyarskLatMin },
                    new double[] { AroundKrasnoyarskLonMin },
                    new double[] { AroundKrasnoyarskLatMax },
                    new double[] { AroundKrasnoyarskLonMax },
                    tr2),
                sources);
            var    result3 = ClimateService.FetchAsync(request3).Result;
            double sd3     = ((double[])result3["sd"].GetData())[0];
            double value3  = ((double[])result3["values"].GetData())[0];

            Assert.AreEqual(sd3, ClimateService.FetchClimateUncertainty(p, AroundKrasnoyarskLatMin, AroundKrasnoyarskLatMax, AroundKrasnoyarskLonMin, AroundKrasnoyarskLonMax, startyear: 1990, stopyear: 2000, dataSource: ds));
            Assert.AreEqual(value3, ClimateService.FetchClimate(p, AroundKrasnoyarskLatMin, AroundKrasnoyarskLatMax, AroundKrasnoyarskLonMin, AroundKrasnoyarskLonMax, startyear: 1990, stopyear: 2000, dataSource: ds));

            //Cell somewhere in Pacific Ocean
            var request4 = new FetchRequest(
                varName,
                FetchDomain.CreateCells(
                    new double[] { PacificLat },
                    new double[] { PacificLon },
                    new double[] { PacificLatA },
                    new double[] { PacificLonA },
                    tr2),
                sources);
            var    result4 = ClimateService.FetchAsync(request4).Result;
            double sd4     = ((double[])result4["sd"].GetData())[0];
            double value4  = ((double[])result4["values"].GetData())[0];

            Assert.AreEqual(sd4, ClimateService.FetchClimateUncertainty(p, PacificLat, PacificLatA, PacificLon, PacificLonA, startyear: 1990, stopyear: 2000, dataSource: ds));
            Assert.AreEqual(value4, ClimateService.FetchClimate(p, PacificLat, PacificLatA, PacificLon, PacificLonA, startyear: 1990, stopyear: 2000, dataSource: ds));

            //batch request
            double[] batchLonMin    = new double[] { PacificLon, AroundKrasnoyarskLonMin };
            double[] batchLonMax    = new double[] { PacificLon, AroundKrasnoyarskLonMax };
            double[] batchLatMin    = new double[] { PacificLat, AroundKrasnoyarskLatMin };
            double[] batchLatMax    = new double[] { PacificLat, AroundKrasnoyarskLatMax };
            int[]    batchStartYear = new int[] { 1961, 1990 };
            int[]    batchStopYear  = new int[] { 1990, 2000 };

            double[] sdGuess1    = ClimateService.FetchClimateUncertainty(p, batchLatMin, batchLatMax, batchLonMin, batchLonMax, null, null, null, null, batchStartYear, batchStopYear, ds);
            double[] valueGuess1 = ClimateService.FetchClimate(p, batchLatMin, batchLatMax, batchLonMin, batchLonMax, null, null, null, null, batchStartYear, batchStopYear, ds);

            Assert.AreEqual(sd2, sdGuess1[0]);
            Assert.AreEqual(sd3, sdGuess1[1]);
            Assert.AreEqual(value2, valueGuess1[0]);
            Assert.AreEqual(value3, valueGuess1[1]);

            //grid request
            var request5 = new FetchRequest(
                varName,
                FetchDomain.CreateCellGrid(
                    Enumerable.Range(0, (int)Math.Round((SriLankaLatMax - SriLankaLatMin) / 1) + 1).Select(i => SriLankaLatMin + i).ToArray(),
                    Enumerable.Range(0, (int)Math.Round((SriLankaLonMax - SriLankaLonMin) / 1) + 1).Select(i => SriLankaLonMin + i).ToArray(),
                    tr2),
                sources);
            var result5 = ClimateService.FetchAsync(request5).Result;

            double[,] gridSds    = (double[, ])result5["sd"].GetData();
            double[,] gridValues = (double[, ])result5["values"].GetData();
            int len0 = gridSds.GetLength(0), len1 = gridSds.GetLength(1);

            double[,] sdGuess2    = ClimateService.FetchUncertaintyGrid(p, SriLankaLatMin, SriLankaLatMax, SriLankaLonMin, SriLankaLonMax, 1, 1, yearmin: 1990, yearmax: 2000, dataSource: ds);
            double[,] valueGuess2 = ClimateService.FetchClimateGrid(p, SriLankaLatMin, SriLankaLatMax, SriLankaLonMin, SriLankaLonMax, 1, 1, yearmin: 1990, yearmax: 2000, dataSource: ds);

            //in FC2 grid is lon x lat while in FC1 it was lat x lon
            Assert.AreEqual(len0, sdGuess2.GetLength(1));
            Assert.AreEqual(len1, sdGuess2.GetLength(0));
            Assert.AreEqual(len0, valueGuess2.GetLength(1));
            Assert.AreEqual(len1, valueGuess2.GetLength(0));
            for (int i = 0; i < len0; ++i)
            {
                for (int j = 0; j < len1; ++j)
                {
                    Assert.AreEqual(gridSds[i, j], sdGuess2[j, i]);
                    Assert.AreEqual(gridValues[i, j], valueGuess2[j, i]);
                }
            }

            //Yearly TimeSeries for Krasnoyarsk
            var tr3      = new TimeRegion().GetYearlyTimeseries(1990, 2000);
            var request6 = new FetchRequest(
                varName,
                FetchDomain.CreatePoints(
                    new double[] { KrasnoyarskLat },
                    new double[] { KrasnoyarskLon },
                    tr3),
                sources);
            var result6 = ClimateService.FetchAsync(request6).Result;

            double[,] seriesSds1    = (double[, ])result6["sd"].GetData();
            double[,] seriesValues1 = (double[, ])result6["values"].GetData();

            double[] seriesSdsGuess1    = ClimateService.FetchClimateYearlyUncertainty(p, KrasnoyarskLat, KrasnoyarskLat, KrasnoyarskLon, KrasnoyarskLon, yearmin: 1990, yearmax: 2000, dataSource: ds);
            double[] seriesValuesGuess1 = ClimateService.FetchClimateYearly(p, KrasnoyarskLat, KrasnoyarskLat, KrasnoyarskLon, KrasnoyarskLon, yearmin: 1990, yearmax: 2000, dataSource: ds);

            Assert.AreEqual(seriesSds1.Length, seriesSdsGuess1.Length);
            Assert.AreEqual(seriesValues1.Length, seriesValuesGuess1.Length);
            for (int i = 0; i < seriesValues1.Length; ++i)
            {
                Assert.AreEqual(seriesSds1[0, i], seriesSdsGuess1[i]);
                Assert.AreEqual(seriesValues1[0, i], seriesValuesGuess1[i]);
            }

            //Monthly TimeSeries for Krasnoyarsk
            var tr4      = new TimeRegion(1990, 1991).GetSeasonlyTimeseries(30, 40);
            var request7 = new FetchRequest(
                varName,
                FetchDomain.CreatePoints(
                    new double[] { KrasnoyarskLat },
                    new double[] { KrasnoyarskLon },
                    tr4),
                sources);
            var result7 = ClimateService.FetchAsync(request7).Result;

            double[,] seriesSds2    = (double[, ])result7["sd"].GetData();
            double[,] seriesValues2 = (double[, ])result7["values"].GetData();

            double[] seriesSdsGuess2    = ClimateService.FetchClimateSeasonlyUncertainty(p, KrasnoyarskLat, KrasnoyarskLat, KrasnoyarskLon, KrasnoyarskLon, daymin: 30, daymax: 40, yearmin: 1990, yearmax: 1991, dataSource: ds);
            double[] seriesValuesGuess2 = ClimateService.FetchClimateSeasonly(p, KrasnoyarskLat, KrasnoyarskLat, KrasnoyarskLon, KrasnoyarskLon, daymin: 30, daymax: 40, yearmin: 1990, yearmax: 1991, dataSource: ds);

            Assert.AreEqual(seriesSds2.Length, seriesSdsGuess2.Length);
            Assert.AreEqual(seriesValues2.Length, seriesValuesGuess2.Length);
            for (int i = 0; i < seriesValues2.Length; ++i)
            {
                Assert.AreEqual(seriesSds2[0, i], seriesSdsGuess2[i]);
                Assert.AreEqual(seriesValues2[0, i], seriesValuesGuess2[i]);
            }

            //Hourly TimeSeries for Krasnoyarsk
            var tr5      = new TimeRegion(1990, 1991, 30, 31).GetHourlyTimeseries(isIntervalTimeseries: true);
            var request8 = new FetchRequest(
                varName,
                FetchDomain.CreatePoints(
                    new double[] { KrasnoyarskLat },
                    new double[] { KrasnoyarskLon },
                    tr5),
                sources);
            var result8 = ClimateService.FetchAsync(request8).Result;

            double[,] seriesSds3    = (double[, ])result8["sd"].GetData();
            double[,] seriesValues3 = (double[, ])result8["values"].GetData();

            double[] seriesSdsGuess3    = ClimateService.FetchClimateHourlyUncertainty(p, KrasnoyarskLat, KrasnoyarskLat, KrasnoyarskLon, KrasnoyarskLon, daymin: 30, daymax: 31, yearmin: 1990, yearmax: 1991, dataSource: ds);
            double[] seriesValuesGuess3 = ClimateService.FetchClimateHourly(p, KrasnoyarskLat, KrasnoyarskLat, KrasnoyarskLon, KrasnoyarskLon, daymin: 30, daymax: 31, yearmin: 1990, yearmax: 1991, dataSource: ds);

            Assert.AreEqual(seriesSds3.Length, seriesSdsGuess3.Length);
            Assert.AreEqual(seriesValues3.Length, seriesValuesGuess3.Length);
            for (int i = 0; i < seriesValues3.Length; ++i)
            {
                Assert.AreEqual(seriesSds3[0, i], seriesSdsGuess3[i]);
                Assert.AreEqual(seriesValues3[0, i], seriesValuesGuess3[i]);
            }
        }