public void CellsEquivalence() { using (var ds = DataSet.Open("msds:memory")) { ds.AddAxisCells("Lat", "Degrees", 12.0, 15.0, 0.5); ds.AddAxisCells("Lon", "Degrees", 8.0, 11.0, 0.25); ds.AddClimatologyAxisYearly(yearStep: 29); ds.Commit(); ds.Fetch(ClimateParameter.FC_TEMPERATURE, "air0"); ds.Commit(); double[, ,] temp = (double[, , ])ds.Variables["air0"].GetData(); Assert.AreEqual(ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, 12.0, 12.5, 8.0, 8.25), temp[0, 0, 0], 1e-8); Assert.AreEqual(ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, 13.5, 14.0, 9.25, 9.5), temp[0, 3, 5], 1e-8); Assert.AreEqual(ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, 14.5, 15.0, 10.75, 11.0), temp[0, 5, 11], 1e-8); } using (var ds = DataSet.Open("msds:memory")) { ds.AddAxisCells("Lat", "Degrees", 12.0f, 15.0f, 0.5f); ds.AddAxisCells("Lon", "Degrees", 8.0, 11.0, 0.25); ds.AddClimatologyAxisYearly(yearStep: 30); ds.Commit(); ds.Fetch(ClimateParameter.FC_TEMPERATURE, "air0"); ds.Commit(); double[, ,] temp = (double[, , ])ds.Variables["air0"].GetData(); Assert.AreEqual(ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, 12.0, 12.5, 8.0, 8.25), temp[0, 0, 0], 1e-8); Assert.AreEqual(ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, 13.5, 14.0, 9.25, 9.5), temp[0, 3, 5], 1e-8); Assert.AreEqual(ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, 14.5, 15.0, 10.75, 11.0), temp[0, 5, 11], 1e-8); } }
public void CellsToGridFallBack() { using (var ds = DataSet.Open("msds:memory")) { ds.AddAxisCells("Lat", "Degrees", 12.0f, 15.0f, 0.5f); //here is cells ds.AddAxis("Lon", "Degrees", 8.0f, 11.0f, 0.25f); //here is grid ds.AddClimatologyAxisYearly(yearStep: 30); ds.Fetch(ClimateParameter.FC_TEMPERATURE, "air0"); ds.Commit(); double[, ,] temp = (double[, , ])ds.Variables["air0"].GetData(); Assert.AreEqual(ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, 12.0, 12.0, 8.0, 8.0), temp[0, 0, 0], 1e-8); Assert.AreEqual(ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, 13.5, 13.5, 9.25, 9.25), temp[0, 3, 5], 1e-8); Assert.AreEqual(ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, 15.0, 15.0, 11.0, 11.0), temp[0, 6, 12], 1e-8); } }
/// <summary> /// Method to get the list of precipitation and temparature values. /// </summary> /// <param name="latMin">Min latitude.</param> /// <param name="latMax">Max latitude.</param> /// <param name="longMin">Min longitude.</param> /// <param name="longMax">Max longitude.</param> /// <param name="dlat">Delta latitude.</param> /// <param name="dlong">Delta longitude.</param> /// <returns>List of FetchClimateOutputModel objects.</returns> public static List <FetchClimateOutputModel> GetPrecipitationAndTemp(double latMin, double latMax, double longMin, double longMax, double dlat, double dlong) { List <FetchClimateOutputModel> lstFetchClimateValues = new List <FetchClimateOutputModel>(); double longMinTemp = longMin; try { // Creating collection of latitude and longitude values dependingon the user inputs. while (latMin < latMax) { while (longMin < longMax) { lstFetchClimateValues.Add(new FetchClimateOutputModel(latMin, latMin + dlat, longMin, longMin + dlong, 0.00, 0.00)); longMin += dlong; } latMin += dlat; longMin = longMinTemp; } // Getting list of precipitation values from fetch climate API double[] precipitation = ClimateService.FetchClimate(ClimateParameter.FC_PRECIPITATION, lstFetchClimateValues.Select(o => o.MinLatitude).ToArray(), lstFetchClimateValues.Select(o => o.MaxLatitude).ToArray(), lstFetchClimateValues.Select(o => o.MinLongitude).ToArray(), lstFetchClimateValues.Select(o => o.MaxLongitude).ToArray()); // Getting list of temparature values from fetch climate API double[] temp = ClimateService.FetchClimate(ClimateParameter.FC_TEMPERATURE, lstFetchClimateValues.Select(o => o.MinLatitude).ToArray(), lstFetchClimateValues.Select(o => o.MaxLatitude).ToArray(), lstFetchClimateValues.Select(o => o.MinLongitude).ToArray(), lstFetchClimateValues.Select(o => o.MaxLongitude).ToArray()); // Assigning precipitation and temparature values. lstFetchClimateValues.ForEach(location => { int index = lstFetchClimateValues.IndexOf(location); location.Precipitation = precipitation[index]; location.Temperature = temp[index]; }); } catch { lstFetchClimateValues = null; } return(lstFetchClimateValues); }
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]); } }