private void VariableRequestTest(string name) { RemoteFetchClient client = new RemoteFetchClient(new Uri(serviceUri)); FetchRequest request = new FetchRequest(name, CreateCellGridDomain(CreateSingleTimeInterval())); using (var result = client.FetchAsync(request, s => Trace.WriteLine(s)).Result) { var v = result.Variables["values"]; Assert.IsTrue(v.Dimensions.Count == 2 && v.Dimensions[0].Length == request.Domain.Lons.Length - 1 && v.Dimensions[1].Length == request.Domain.Lats.Length - 1); var p = result.Variables["provenance"]; Assert.IsTrue(p.Dimensions.Count == 2 && p.Dimensions[0].Length == request.Domain.Lons.Length - 1 && p.Dimensions[1].Length == request.Domain.Lats.Length - 1); var sd = result.Variables["sd"]; Assert.IsTrue(sd.Dimensions.Count == 2 && sd.Dimensions[0].Length == request.Domain.Lons.Length - 1 && sd.Dimensions[1].Length == request.Domain.Lats.Length - 1); } }
public void GetConfigurationTest() { RemoteFetchClient client = new RemoteFetchClient(new Uri(serviceUri)); var latestConfig = client.GetConfiguration(DateTime.MaxValue); var latestConfig2 = client.GetConfiguration(latestConfig.TimeStamp); Assert.AreEqual(latestConfig, latestConfig2); }
public void PointRequestTest() { var tr = new TimeRegion(1990, 2000, 1, 358).GetYearlyTimeseries(1990, 2000, 1, true).GetSeasonlyTimeseries(1, 358, 1, true); var r = new FetchRequest( "airt", FetchDomain.CreatePoints( new double[] { 50, 52, 54 }, new double[] { 40, 42, 38 }, tr), new string[] { "CRU CL 2.0" }); RemoteFetchClient client = new RemoteFetchClient(new Uri(serviceUri)); var answer = client.FetchAsync(r).Result; }
public static void Main(string[] args) { RemoteFetchClient fc = new RemoteFetchClient(new Uri("http://fetchclimate2.cloudapp.net")); TimeRegion tr = new TimeRegion(firstYear: 2000, lastYear: 2001); tr = tr.GetMonthlyTimeseries(); FetchRequest request = new FetchRequest( "airt", FetchDomain.CreatePointGrid( Enumerable.Range(0, 150).Select(i => 50.0 + i * 0.1).ToArray(), // 5.0 .. 20.0 Enumerable.Range(0, 170).Select(i => 30.0 + i * 0.1).ToArray(), tr)); var dataSet = fc.FetchAsync(request).Result; Console.WriteLine(dataSet.ToString()); dataSet.View(); }
public void GetConfigurationForEarlyTimestampTest() { RemoteFetchClient client = new RemoteFetchClient(new Uri(serviceUri)); var latestConfig = client.GetConfiguration(new DateTime(1950, 1, 1)); }
private void TestRequests(string variableName, string[] dataSources, Tuple <double, double> saneRange, bool isNaNoverLand, bool isNaNoverOcean) { RemoteFetchClient client = new RemoteFetchClient(new Uri(serviceUri)); for (int i = 0; i < 8; ++i) { for (int k = 0; k < 4; ++k) { bool[] times = new bool[3]; times[0] = !(i > 3); times[1] = !((i % 4) > 1); times[2] = !((i % 2) > 0); int timeDims = times.Count(x => !x); int spatDims = k / 2 + 1; int timeDimsShift = spatDims - 1; FetchRequest request; if (k == 0) { request = new FetchRequest(variableName, CreatePointsDomain(CreateTestTimeRegion(times[0], times[1], times[2])), dataSources); } else if (k == 1) { request = new FetchRequest(variableName, CreateCellsDomain(CreateTestTimeRegion(times[0], times[1], times[2])), dataSources); } else if (k == 2) { request = new FetchRequest(variableName, CreatePointGridDomain(CreateTestTimeRegion(times[0], times[1], times[2])), dataSources); } else { request = new FetchRequest(variableName, CreateCellGridDomain(CreateTestTimeRegion(times[0], times[1], times[2])), dataSources); } Trace.WriteLine(String.Format("Testing. Spatial domain type: {0}. Time domain type: years: {1}, days: {2}, hours: {3}.", k == 0 ? "2 points" : k == 1 ? "2 cells" : k == 2 ? "point grid" : "cell grid", times[0] ? "1 interval" : "2 points", times[1] ? "1 interval" : "2 points", times[2] ? "1 interval" : "2 points")); using (var result = client.FetchAsync(request, s => Trace.WriteLine(s)).Result) { var v = result.Variables["values"]; Assert.IsTrue(v.Dimensions.Count == spatDims + timeDims); switch (k) { case 0: case 1: Assert.AreEqual(2, v.Dimensions[0].Length); break; case 2: Assert.AreEqual(request.Domain.Lons.Length, v.Dimensions[0].Length); Assert.AreEqual(request.Domain.Lats.Length, v.Dimensions[1].Length); break; case 3: Assert.AreEqual(request.Domain.Lons.Length - 1, v.Dimensions[0].Length); Assert.AreEqual(request.Domain.Lats.Length - 1, v.Dimensions[1].Length); break; } for (int j = 1; j <= timeDims; ++j) { Assert.AreEqual(2, v.Dimensions[j + timeDimsShift].Length); } if (dataSources != null && dataSources.Length > 1) { var p = result.Variables["provenance"]; Assert.IsTrue(p.Dimensions.Count == spatDims + timeDims); for (int j = 1; j <= timeDims; ++j) { Assert.AreEqual(2, p.Dimensions[j + timeDimsShift].Length); } switch (k) { case 0: case 1: Assert.AreEqual(2, p.Dimensions[0].Length); break; case 2: Assert.AreEqual(request.Domain.Lons.Length, p.Dimensions[0].Length); Assert.AreEqual(request.Domain.Lats.Length, p.Dimensions[1].Length); break; case 3: Assert.AreEqual(request.Domain.Lons.Length - 1, p.Dimensions[0].Length); Assert.AreEqual(request.Domain.Lats.Length - 1, p.Dimensions[1].Length); break; } } var sd = result.Variables["sd"]; Assert.IsTrue(sd.Dimensions.Count == spatDims + timeDims); for (int j = 1; j <= timeDims; ++j) { Assert.AreEqual(2, sd.Dimensions[j + timeDimsShift].Length); } switch (k) { case 0: case 1: Assert.AreEqual(2, sd.Dimensions[0].Length); break; case 2: Assert.AreEqual(request.Domain.Lons.Length, sd.Dimensions[0].Length); Assert.AreEqual(request.Domain.Lats.Length, sd.Dimensions[1].Length); break; case 3: Assert.AreEqual(request.Domain.Lons.Length - 1, sd.Dimensions[0].Length); Assert.AreEqual(request.Domain.Lats.Length - 1, sd.Dimensions[1].Length); break; } if (spatDims == 1) { if (timeDims == 0) { double[] vals = (double[])v.GetData(); TestValue(vals[0], isNaNoverOcean ? null : saneRange); TestValue(vals[1], isNaNoverLand ? null : saneRange); } else if (timeDims == 1) { double[,] vals = (double[, ])v.GetData(); TestValue(vals[0, 0], isNaNoverOcean ? null : saneRange); TestValue(vals[0, 1], isNaNoverOcean ? null : saneRange); TestValue(vals[1, 0], isNaNoverLand ? null : saneRange); TestValue(vals[1, 1], isNaNoverLand ? null : saneRange); } else if (timeDims == 2) { double[, ,] vals = (double[, , ])v.GetData(); for (int j1 = 0; j1 < 2; ++j1) { for (int j2 = 0; j2 < 2; ++j2) { TestValue(vals[0, j1, j2], isNaNoverOcean ? null : saneRange); TestValue(vals[1, j1, j2], isNaNoverLand ? null : saneRange); } } } else if (timeDims == 3) { double[, , ,] vals = (double[, , , ])v.GetData(); for (int j1 = 0; j1 < 2; ++j1) { for (int j2 = 0; j2 < 2; ++j2) { for (int j3 = 0; j3 < 2; ++j3) { TestValue(vals[0, j1, j2, j3], isNaNoverOcean ? null : saneRange); TestValue(vals[1, j1, j2, j3], isNaNoverLand ? null : saneRange); } } } } } else //grids { int lonOceanFirst = 0; int lonOceanLast = 2; int latOceanFirst = 0; int latOceanLast = 5; if (timeDims == 0) { double[,] vals = (double[, ])v.GetData(); for (int s1 = 0; s1 < v.Dimensions[0].Length; ++s1) { for (int s2 = 0; s2 < v.Dimensions[1].Length; ++s2) { TestValue(vals[s1, s2], saneRange); } } if (isNaNoverLand) { for (int s1 = 27; s1 < v.Dimensions[0].Length; ++s1) { for (int s2 = 0; s2 < v.Dimensions[1].Length; ++s2) { TestValue(vals[s1, s2], null); } } } if (isNaNoverOcean) { for (int s1 = lonOceanFirst; s1 <= lonOceanLast; ++s1) { for (int s2 = latOceanFirst; s2 <= latOceanLast; ++s2) { TestValue(vals[s1, s2], null); } } } } else if (timeDims == 1) { double[, ,] vals = (double[, , ])v.GetData(); for (int s1 = 0; s1 < v.Dimensions[0].Length; ++s1) { for (int s2 = 0; s2 < v.Dimensions[1].Length; ++s2) { for (int j1 = 0; j1 < 2; ++j1) { TestValue(vals[s1, s2, j1], saneRange); } } } if (isNaNoverLand) { for (int s1 = 27; s1 < v.Dimensions[0].Length; ++s1) { for (int s2 = 0; s2 < v.Dimensions[1].Length; ++s2) { for (int j1 = 0; j1 < 2; ++j1) { TestValue(vals[s1, s2, j1], null); } } } } if (isNaNoverOcean) { for (int s1 = lonOceanFirst; s1 <= lonOceanLast; ++s1) { for (int s2 = latOceanFirst; s2 <= latOceanLast; ++s2) { for (int j1 = 0; j1 < 2; ++j1) { TestValue(vals[s1, s2, j1], null); } } } } } else if (timeDims == 2) { double[, , ,] vals = (double[, , , ])v.GetData(); for (int s1 = 0; s1 < v.Dimensions[0].Length; ++s1) { for (int s2 = 0; s2 < v.Dimensions[1].Length; ++s2) { for (int j1 = 0; j1 < 2; ++j1) { for (int j2 = 0; j2 < 2; ++j2) { TestValue(vals[s1, s2, j1, j2], saneRange); } } } } if (isNaNoverLand) { for (int s1 = 27; s1 < v.Dimensions[0].Length; ++s1) { for (int s2 = 0; s2 < v.Dimensions[1].Length; ++s2) { for (int j1 = 0; j1 < 2; ++j1) { for (int j2 = 0; j2 < 2; ++j2) { TestValue(vals[s1, s2, j1, j2], null); } } } } } if (isNaNoverOcean) { for (int s1 = lonOceanFirst; s1 <= lonOceanLast; ++s1) { for (int s2 = latOceanFirst; s2 <= latOceanLast; ++s2) { for (int j1 = 0; j1 < 2; ++j1) { for (int j2 = 0; j2 < 2; ++j2) { TestValue(vals[s1, s2, j1, j2], null); } } } } } } else if (timeDims == 3) { double[, , , ,] vals = (double[, , , , ])v.GetData(); for (int s1 = 0; s1 < v.Dimensions[0].Length; ++s1) { for (int s2 = 0; s2 < v.Dimensions[1].Length; ++s2) { for (int j1 = 0; j1 < 2; ++j1) { for (int j2 = 0; j2 < 2; ++j2) { for (int j3 = 0; j3 < 2; ++j3) { TestValue(vals[s1, s2, j1, j2, j3], saneRange); } } } } } if (isNaNoverLand) { for (int s1 = 27; s1 < v.Dimensions[0].Length; ++s1) { for (int s2 = 0; s2 < v.Dimensions[1].Length; ++s2) { for (int j1 = 0; j1 < 2; ++j1) { for (int j2 = 0; j2 < 2; ++j2) { for (int j3 = 0; j3 < 2; ++j3) { TestValue(vals[s1, s2, j1, j2, j3], null); } } } } } } if (isNaNoverOcean) { for (int s1 = lonOceanFirst; s1 <= lonOceanLast; ++s1) { for (int s2 = latOceanFirst; s2 <= latOceanLast; ++s2) { for (int j1 = 0; j1 < 2; ++j1) { for (int j2 = 0; j2 < 2; ++j2) { for (int j3 = 0; j3 < 2; ++j3) { TestValue(vals[s1, s2, j1, j2, j3], null); } } } } } } } } } Trace.WriteLine("Passed"); } } }