public async Task MonthlyMeansMissingValueOnWaterTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriCru); CruCl20DataHandler cru = await CruCl20DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion(); IFetchDomain domain = FetchDomain.CreatePoints( new double[] { 0.5 }, new double[] { 0.5 }, tr); FetchRequest request = new FetchRequest("tmp", domain); var handlerPrivate = new PrivateObject(cru, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); for (int i = 0; i < 2; i++) { Array mask = i == 0 ? null : new bool[, ] { { true } }; var res = await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, request), null)); //lon,lat,t double[] temps = (double[])res; Assert.AreEqual(1, temps.Length); Assert.IsTrue(double.IsNaN(temps[0])); } }
public void GhcnTempUncertaintyTest() { string etopoLocalUri = TestConstants.UriEtopo; var ghcnStorage = TestDataStorageFactory.GetStorage(TestConstants.UriGHCN); var etopoStorage = TestDataStorageFactory.GetStorage(etopoLocalUri); GHCNDataHandler handler = new GHCNDataHandler(ghcnStorage); ETOPO1DataSource.ETOPO1DataHandler elevationHandler = new ETOPO1DataSource.ETOPO1DataHandler(etopoStorage); TimeRegion tr = new TimeRegion(firstYear: 1921, lastYear: 1921).GetMonthlyTimeseries(firstMonth: 3, lastMonth: 3); //data index 2642 FetchDomain domain = FetchDomain.CreatePoints( new double[] { 36.27 }, //exact station. data index 3776 new double[] { -90.97 }, tr); FetchRequest tempRequest = new FetchRequest("temp", domain); Func <FetchRequest, Array> elevHandling = req => { var rewrittenReq = new FetchRequest("Elevation", req.Domain); return(elevationHandler.AggregateAsync(RequestContextStub.GetStub(etopoStorage, rewrittenReq), null).Result); }; var reqContext = RequestContextStub.GetStub(ghcnStorage, tempRequest, elevHandling); var compCont = new ComputationalContext(); Assert.AreEqual(0.0, (double)handler.EvaluateAsync(reqContext, compCont).Result.GetValue(0), 1e-6); //manual data comparison. }
public async Task CruAllVaraiblesValuesTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriCru); CruCl20DataHandler cru = await CruCl20DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 1, lastMonth: 1); IFetchDomain domain = FetchDomain.CreatePoints( new double[] { 48.25 }, // data index 679 new double[] { -100.25 }, //data index 478 tr); var handlerPrivate = new PrivateObject(cru, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); FetchRequest tmpRequest = new FetchRequest("tmp", domain); FetchRequest preRequest = new FetchRequest("pre", domain); FetchRequest wndRequest = new FetchRequest("wnd", domain); FetchRequest sunpRequest = new FetchRequest("sunp", domain); FetchRequest rehRequest = new FetchRequest("reh", domain); FetchRequest rd0Request = new FetchRequest("rd0", domain); FetchRequest frsRequest = new FetchRequest("frs", domain); FetchRequest dtrRequest = new FetchRequest("dtr", domain); Assert.AreEqual(4.9, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, wndRequest), null))).GetValue(0), TestConstants.FloatPrecision); //manual data comparision Assert.AreEqual(-15.4, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, tmpRequest), null))).GetValue(0), TestConstants.FloatPrecision); Assert.AreEqual(48.1, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, sunpRequest), null))).GetValue(0), TestConstants.FloatPrecision); Assert.AreEqual(74.5, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, rehRequest), null))).GetValue(0), TestConstants.FloatPrecision); Assert.AreEqual(7.6, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, rd0Request), null))).GetValue(0), TestConstants.FloatPrecision); Assert.AreEqual(14.0, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, preRequest), null))).GetValue(0), TestConstants.FloatPrecision); Assert.AreEqual(30.7, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, frsRequest), null))).GetValue(0), TestConstants.FloatPrecision); Assert.AreEqual(11.8, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, dtrRequest), null))).GetValue(0), TestConstants.FloatPrecision); }
public async Task Bug1691() { double BayOfBiscaySELat = 44.5; double BayOfBiscaySELon = -3.5; double InFranceLat = 47; double InFranceLon = 1; Random r = new Random(1); var eps = r.NextDouble() / 10.0; double latDelta = InFranceLat - BayOfBiscaySELat; double lonDelta = InFranceLon - BayOfBiscaySELon; var tr = new TimeRegion(1990, 2001, 1, -1, 0, 24); var request = new FetchRequest( "temp", FetchDomain.CreateCellGrid( Enumerable.Range(0, 31).Select(i => eps + BayOfBiscaySELat + i * latDelta / 31.0).ToArray(), Enumerable.Range(0, 21).Select(i => eps + BayOfBiscaySELon + i * lonDelta / 21.0).ToArray(), tr)); string etopoLocalUri = TestConstants.UriEtopo; var ghcnStorage = TestDataStorageFactory.GetStorageContext(TestConstants.UriGHCN); var reqContext = RequestContextStub.GetStub(ghcnStorage, request); DataSourceHandler handler = await GHCNv2DataSource.DataHandler.CreateAsync(ghcnStorage); var result = await handler.ProcessRequestAsync(reqContext); Assert.IsTrue(-70.0 < (double)result.GetValue(16, 2)); //manual data comparison. }
public async Task LinearWeightsContextFactoryFacadeTest() { var lwcff = new LinearWeightsContextFactoryFacade <RealValueNodesStub>(new Stub4(), new Stub3()); var cells = new GeoCellTuple[] { new GeoCellTuple() { LatMax = 11.0, LonMin = 13.0, LatMin = 17.0, LonMax = 19.0 } }; var request = new FetchRequest("dummy", FetchDomain.CreateCells(new double[] { 17.0 }, new double[] { 13.0 }, new double[] { 11.0 }, new double[] { 19.0 }, new TimeRegion())); var storage = TestDataStorageFactory.GetStorage("msds:memory"); var requestContext = RequestContextStub.GetStub(storage, request); var lwc = await lwcff.CreateAsync(requestContext, cells); var combs = lwc.Combinations.ToArray(); Assert.AreEqual(1, combs.Length); Assert.AreEqual(cells[0], combs[0].Item1); RealValueNodes nodes = combs[0].Item2; IEnumerable <LinearWeight> weights = combs[0].Item3; var result = weights.Sum(w => w.Weight * nodes.Values[w.DataIndex]); Assert.AreEqual(847.0, result); }
public async Task TestGetObservations() { var storage = TestDataStorageFactory.GetStorage("msds:nc?file=GHCNv2_part.nc&openMode=readOnly"); var axis = storage.GetDataAsync("time").Result; var integrator = new mathIntegrators.Temporal.StepFunctionDateTimeAxisIntegrator(axis); var provider = new ObservationProviders.AllStationsOP(storage, integrator, "lat", "lon"); var res = await provider.GetObservationsAsync(storage, "temp", -9999, 0.0, 0.0, 0.0, 0.0, new TimeSegment(1870, 1870, 1, 365, 0, 24)); Assert.AreEqual(313, res.Observations.Length); //exactly 313 station have non-mv timeseries (manually checked) }
public async Task MonthlyMeansLandOnlyVariablesTest() { var storage = TestDataStorageFactory.GetStorage(TestConstants.UriCru); CruCl20DataHandler cru = await CruCl20DataHandler.CreateAsync(storage); TimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 1, lastMonth: 1); FetchDomain oceanDomain = FetchDomain.CreateCells( new double[] { 22.0 }, new double[] { -25.0 }, new double[] { 23.0 }, new double[] { -24.0 }, tr); FetchDomain landDomain = FetchDomain.CreateCells( new double[] { 24.0 }, new double[] { -10.0 }, new double[] { 25.0 }, new double[] { -9.0 }, tr); FetchDomain landOceanMixDomain = FetchDomain.CreateCells( new double[] { 24.0 }, new double[] { -16.0 }, new double[] { 25.0 }, new double[] { -14.0 }, tr); FetchRequest oceanPrecRequest = new FetchRequest("pre", oceanDomain); FetchRequest landPrecRequest = new FetchRequest("pre", landDomain); FetchRequest mixPrecRequest = new FetchRequest("pre", landOceanMixDomain); var handlerPrivate = new PrivateObject(cru, new PrivateType(typeof(DataHandlerFacade))); var evaluatorPrivate = new PrivateObject(handlerPrivate, "uncertaintyEvaluator"); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); double oceanUnc = (double)(await(Task <Array>)(evaluatorPrivate.Invoke("EvaluateAsync", RequestContextStub.GetStub(storage, oceanPrecRequest)))).GetValue(0); double landUnc = (double)(await(Task <Array>)(evaluatorPrivate.Invoke("EvaluateAsync", RequestContextStub.GetStub(storage, landPrecRequest)))).GetValue(0); double mixUnc = (double)(await(Task <Array>)(evaluatorPrivate.Invoke("EvaluateAsync", RequestContextStub.GetStub(storage, mixPrecRequest)))).GetValue(0); Assert.IsTrue(double.IsNaN(oceanUnc)); Assert.AreEqual(double.MaxValue, mixUnc); Assert.IsTrue(!double.IsNaN(landUnc)); Assert.IsTrue(landUnc < double.MaxValue); //check variogram presence if this fails double oceanVal = (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, oceanPrecRequest), null))).GetValue(0); double landVal = (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, landPrecRequest), null))).GetValue(0); double mixVal = (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, mixPrecRequest), null))).GetValue(0); Assert.IsTrue(double.IsNaN(oceanVal)); Assert.IsTrue(!double.IsNaN(landVal)); Assert.IsTrue(!double.IsNaN(mixVal)); Assert.AreEqual(mixVal, landVal, TestConstants.DoublePrecision); }
public async Task CruUncertaintyLandAndWaterTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriCru); CruCl20DataHandler cru = await CruCl20DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion(firstYear: 1950, lastYear: 2010); IFetchDomain domain = FetchDomain.CreateCells( //ocean region new double[] { 0.0 }, new double[] { 0.0 }, new double[] { 1.0 }, new double[] { 1.0 }, tr); FetchRequest request = new FetchRequest("pre", domain); var handlerPrivate = new PrivateObject(cru, new PrivateType(typeof(DataHandlerFacade))); var evaluatorPrivate = new PrivateObject(handlerPrivate, "uncertaintyEvaluator"); var res = await(Task <Array>)(evaluatorPrivate.Invoke("EvaluateAsync", RequestContextStub.GetStub(storage, request))); //i,t double[] prec = (double[])res; Assert.AreEqual(1, prec.Length); Assert.IsTrue(double.IsNaN(prec[0])); domain = FetchDomain.CreateCells( //land region new double[] { 10.0 }, new double[] { 10.0 }, new double[] { 11.0 }, new double[] { 11.0 }, tr); request = new FetchRequest("pre", domain); res = await(Task <Array>)(evaluatorPrivate.Invoke("EvaluateAsync", RequestContextStub.GetStub(storage, request))); //i,t prec = (double[])res; Assert.AreEqual(1, prec.Length); Assert.IsTrue(!double.IsNaN(prec[0])); }
public async Task PointCubeDataTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriCru); CruCl20DataHandler cru = await CruCl20DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 2, lastMonth: 3); IFetchDomain domain = FetchDomain.CreatePointGrid( GenerateAxis(67.25, 67.75, 0.25), GenerateAxis(179.25, 180.75, 0.25), tr); FetchRequest request = new FetchRequest("tmp", domain); bool[, ,,,] mask = new bool[7, 3, 1, 2, 1]; bool[] maskStreched = Enumerable.Repeat(true, 2 * 7 * 3).ToArray(); Buffer.BlockCopy(maskStreched, 0, mask, 0, maskStreched.Length * sizeof(bool)); var handlerPrivate = new PrivateObject(cru, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); for (int i = 0; i < 2; i++) { Array effectiveMask = i == 0 ? null : mask; var res = await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, request), null)); //lon,lat,t double[,,] temps = (double[, , ])res; double precision = TestConstants.FloatPrecision; //float precision //manual data comparasion //lon,lat,t //lat,lon,t Assert.AreEqual(-29.3, temps[0, 0, 0], precision); //corresponding varaible index [793,2155,1] Assert.AreEqual(-30.0, temps[0, 2, 0], precision); //corresponding varaible index [796,2155,1] Assert.AreEqual(-26.6, temps[4, 0, 0], precision); //corresponding varaible index [793,1,1] Assert.AreEqual(-26.8, temps[4, 2, 0], precision); //corresponding varaible index [796,1,1] Assert.AreEqual(-27.4, temps[0, 0, 1], precision); //corresponding varaible index [793,2155,2] Assert.AreEqual(-28.2, temps[0, 2, 1], precision); //corresponding varaible index [796,2155,2] Assert.AreEqual(-25.1, temps[4, 0, 1], precision); //corresponding varaible index [793,1,2] Assert.AreEqual(-25.2, temps[4, 2, 1], precision); //corresponding varaible index [796,1,2] } }
public async Task CpcValuesTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriCpc); CPCDataSource.CpcDataHandler handler = await CPCDataSource.CpcDataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion(firstYear: 1949, lastYear: 1949).GetMonthlyTimeseries(firstMonth: 4, lastMonth: 4); //data index 15 IFetchDomain domain = FetchDomain.CreatePoints( new double[] { 31.75 }, //data index 116 new double[] { 84.75 }, //data index 171 tr); FetchRequest soilRequest = new FetchRequest("soilw", domain); var handlerPrivate = new PrivateObject(handler, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); Assert.AreEqual(101.925401325, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, soilRequest), null))).GetValue(0), TestConstants.DoublePrecision); //manual data comparision. data -22079 }
public async Task Bug1523() { var storage = TestDataStorageFactory.GetStorage(TestConstants.UriEtopo); ETOPO1DataSource.ETOPO1DataHandler etopo = await ETOPO1DataSource.ETOPO1DataHandler.CreateAsync(storage); TimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 1, lastMonth: 1); FetchDomain domain = FetchDomain.CreatePoints( new double[] { -90.0, 60.3 }, new double[] { 0.0, 40.9 }, tr); FetchRequest elevRequest = new FetchRequest("Elevation", domain); var handlerPrivate = new PrivateObject(etopo, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, elevRequest), null)); }
public async Task GtopoValuesTest() { var storage = TestDataStorageFactory.GetStorage(TestConstants.UriGtopo); GTOPO30DataSource.GTOPO30DataHandler gtopo = await GTOPO30DataSource.GTOPO30DataHandler.CreateAsync(storage); TimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 1, lastMonth: 1); FetchDomain domain = FetchDomain.CreatePoints( new double[] { 55.7125 }, // data index 17485 new double[] { 37.5125 }, //data index 26101 tr); FetchRequest elevRequest = new FetchRequest("elevation", domain); var handlerPrivate = new PrivateObject(gtopo, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); Assert.AreEqual(188.0, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, elevRequest), null))).GetValue(0)); //manual data comparision }
public async Task GhcnPartialFutureOutOfDataFinishesTest() { System.Diagnostics.Trace.WriteLine(TestConstants.UriGHCN); var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriGHCN); DataSourceHandler handler = await GHCNv2DataSource.DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion(firstYear: 1990, lastYear: 2101).GetMonthlyTimeseries(firstMonth: 12, lastMonth: 12); //data index 2567 IFetchDomain domain = FetchDomain.CreatePoints( new double[] { -25.18 }, //exact station. data index 18398 new double[] { 151.65 }, tr); FetchRequest prateRequest = new FetchRequest("prate", domain); var reqContext = RequestContextStub.GetStub(storage, prateRequest); var result = await handler.ProcessRequestAsync(reqContext); }
public void Bug1691() { double BayOfBiscaySELat = 44.5; double BayOfBiscaySELon = -3.5; double InFranceLat = 47; double InFranceLon = 1; Random r = new Random(1); var eps = r.NextDouble() / 10.0; double latDelta = InFranceLat - BayOfBiscaySELat; double lonDelta = InFranceLon - BayOfBiscaySELon; var tr = new TimeRegion(1990, 2001, 1, -1, 0, 24, true, false, true); var request = new FetchRequest( "temp", FetchDomain.CreateCellGrid( Enumerable.Range(0, 31).Select(i => eps + BayOfBiscaySELat + i * latDelta / 31.0).ToArray(), Enumerable.Range(0, 21).Select(i => eps + BayOfBiscaySELon + i * lonDelta / 21.0).ToArray(), tr)); string etopoLocalUri = TestConstants.UriEtopo; var ghcnStorage = TestDataStorageFactory.GetStorage(TestConstants.UriGHCN); var etopoStorage = TestDataStorageFactory.GetStorage(etopoLocalUri); GHCNDataHandler handler = new GHCNDataHandler(ghcnStorage); ETOPO1DataSource.ETOPO1DataHandler elevationHandler = new ETOPO1DataSource.ETOPO1DataHandler(etopoStorage); Func <FetchRequest, Array> elevHandling = req => { var rewrittenReq = new FetchRequest("Elevation", req.Domain); return(elevationHandler.AggregateAsync(RequestContextStub.GetStub(etopoStorage, rewrittenReq), null).Result); }; var reqContext = RequestContextStub.GetStub(ghcnStorage, request, elevHandling); var compCont = new ComputationalContext(); var evRes = handler.EvaluateAsync(reqContext, compCont).Result; Assert.IsTrue(-70.0 < (double)handler.AggregateAsync(reqContext, compCont).Result.GetValue(16, 2, 0)); //manual data comparison. }
public async Task CpcMvTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriCpc); CPCDataSource.CpcDataHandler handler = await CPCDataSource.CpcDataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion(firstYear: 1949, lastYear: 1949).GetMonthlyTimeseries(firstMonth: 4, lastMonth: 4);//data index 15 IFetchDomain domain = FetchDomain.CreatePoints( new double[] { 10.7 }, new double[] { -148.4 }, tr); FetchRequest soilRequest = new FetchRequest("soilw", domain); var handlerPrivate = new PrivateObject(handler, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); Assert.IsTrue(double.IsNaN((double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, soilRequest), null))).GetValue(0))); }
public async Task EtopoValuesTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriEtopo); ETOPO1DataSource.ETOPO1DataHandler gtopo = await ETOPO1DataSource.ETOPO1DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 1, lastMonth: 1); IFetchDomain domain = FetchDomain.CreatePoints( new double[] { 61.55, 61.55 }, // data index 9093 new double[] { 328.45, -31.55 }, //data index 8907 (the same point, different lon notations) tr); FetchRequest elevRequest = new FetchRequest("Elevation", domain); var handlerPrivate = new PrivateObject(gtopo, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); Assert.AreEqual(-2441.0, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, elevRequest), null))).GetValue(0), 1e-9); //manual data comparision Assert.AreEqual(-2441.0, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, elevRequest), null))).GetValue(1), 1e-9); //manual data comparision }
public async Task MonthlyMeansUnknownVarEvaluationRejectingTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriCru); CruCl20DataHandler cru = await CruCl20DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 1, lastMonth: 1); IFetchDomain d = FetchDomain.CreateCells( //below the data new double[] { -10.0 }, new double[] { -15.0 }, new double[] { -8.0 }, new double[] { -14.0 }, tr); FetchRequest r = new FetchRequest("fasdf342f34", d); var handlerPrivate = new PrivateObject(cru, new PrivateType(typeof(DataHandlerFacade))); var evaluatorPrivate = new PrivateObject(handlerPrivate, "uncertaintyEvaluator"); var et = await(Task <Array>)(evaluatorPrivate.Invoke("EvaluateAsync", RequestContextStub.GetStub(storage, r))); }
public async Task WorldClimAllVaraiblesValuesTest() { var storage = TestDataStorageFactory.GetStorage(TestConstants.UriWorldClim); WorldClim14DataSource wc = await WorldClim14DataSource.CreateAsync(storage); TimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 1, lastMonth: 1); FetchDomain domain = FetchDomain.CreatePoints( new double[] { 48.25 }, // data index 12990 new double[] { -100.25 }, //data index 9570 tr); FetchRequest tmpRequest = new FetchRequest("tmean", domain); FetchRequest preRequest = new FetchRequest("prec", domain); var handlerPrivate = new PrivateObject(wc, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); Assert.AreEqual(-14.9, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, tmpRequest), null))).GetValue(0), 1e-2); //manual data comparision Assert.AreEqual(13, (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, preRequest), null))).GetValue(0), 1e-1); }
public async Task CruUncertaintyTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriCru); CruCl20DataHandler cru = await CruCl20DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 1, lastMonth: 1); IFetchDomain domain = FetchDomain.CreatePoints( new double[] { 48.25 }, // data index 679 new double[] { -100.25 }, //data index 478 tr); //20.0, -180.0, 85.0, -20.0 north america region. reh rtgcv for the january is 4.8 FetchRequest rehRequest = new FetchRequest("reh", domain); var handlerPrivate = new PrivateObject(cru, new PrivateType(typeof(DataHandlerFacade))); var evaluatorPrivate = new PrivateObject(handlerPrivate, "uncertaintyEvaluator"); double unc = (double)(await(Task <Array>)(evaluatorPrivate.Invoke("EvaluateAsync", RequestContextStub.GetStub(storage, rehRequest)))).GetValue(0); Assert.AreEqual(4.8, unc, 1e-8); }
public void GhcnPrateUncertaintyTest() { System.Diagnostics.Trace.WriteLine(TestConstants.UriGHCN); var storage = TestDataStorageFactory.GetStorage(TestConstants.UriGHCN); GHCNDataHandler handler = new GHCNDataHandler(storage); TimeRegion tr = new TimeRegion(firstYear: 1914, lastYear: 1914).GetMonthlyTimeseries(firstMonth: 12, lastMonth: 12); //data index 2567 FetchDomain domain = FetchDomain.CreatePoints( new double[] { -25.18 }, //exact station. data index 18398 new double[] { 151.65 }, tr); FetchRequest prateRequest = new FetchRequest("prate", domain); var compCont = new ComputationalContext(); var reqContext = RequestContextStub.GetStub(storage, prateRequest); Assert.AreEqual(0.0, (double)handler.EvaluateAsync(reqContext, compCont).Result.GetValue(0), 1e-6); //manual data comparison. }
public async Task GhcnPrateValuesTest() { System.Diagnostics.Trace.WriteLine(TestConstants.UriGHCN); var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriGHCN); DataSourceHandler handler = await GHCNv2DataSource.DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion(firstYear: 1914, lastYear: 1914).GetMonthlyTimeseries(firstMonth: 12, lastMonth: 12); //data index 2567 IFetchDomain domain = FetchDomain.CreatePoints( new double[] { -25.18 }, //exact station. data index 18398 new double[] { 151.65 }, tr); FetchRequest prateRequest = new FetchRequest("prate", domain); var reqContext = RequestContextStub.GetStub(storage, prateRequest); var result = await handler.ProcessRequestAsync(reqContext); Assert.AreEqual(85.1, (double)result.GetValue(0), 1e-3); //manual data comparison. }
public async Task GhcnTempValuesTest() { System.Diagnostics.Trace.WriteLine(TestConstants.UriGHCN); string etopoLocalUri = TestConstants.UriEtopo; var ghcnStorage = TestDataStorageFactory.GetStorageContext(TestConstants.UriGHCN); DataSourceHandler handler = await GHCNv2DataSource.DataHandler.CreateAsync(ghcnStorage); ITimeRegion tr = new TimeRegion(firstYear: 1921, lastYear: 1921).GetMonthlyTimeseries(firstMonth: 3, lastMonth: 3); //data index 2642 IFetchDomain domain = FetchDomain.CreatePoints( new double[] { 36.27 }, //exact station. data index 3776 new double[] { -90.97 }, tr); FetchRequest tempRequest = new FetchRequest("temp", domain); var reqContext = RequestContextStub.GetStub(ghcnStorage, tempRequest); var result = await handler.ProcessRequestAsync(reqContext); Assert.AreEqual(15.6, (double)result.GetValue(0), 1e-5); //manual data comparison. }
public async Task MonthlyMeansOutOfDataTest() { var storage = TestDataStorageFactory.GetStorageContext(TestConstants.UriCru); CruCl20DataHandler cru = await CruCl20DataHandler.CreateAsync(storage); ITimeRegion tr = new TimeRegion().GetMonthlyTimeseries(firstMonth: 1, lastMonth: 1); IFetchDomain[] outOfDataDomain = new FetchDomain[2]; outOfDataDomain[0] = FetchDomain.CreateCells( //below the data new double[] { -70.0 }, new double[] { -25.0 }, new double[] { -68.0 }, new double[] { -24.0 }, tr); outOfDataDomain[1] = FetchDomain.CreateCells( //above the data new double[] { 85.0 }, new double[] { -25.0 }, new double[] { 87.0 }, new double[] { -24.0 }, tr); var handlerPrivate = new PrivateObject(cru, new PrivateType(typeof(DataHandlerFacade))); var evaluatorPrivate = new PrivateObject(handlerPrivate, "uncertaintyEvaluator"); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); for (int i = 0; i < 2; i++) { FetchRequest outOfDataRequest = new FetchRequest("pre", outOfDataDomain[i]); double unc = (double)(await(Task <Array>)(evaluatorPrivate.Invoke("EvaluateAsync", RequestContextStub.GetStub(storage, outOfDataRequest)))).GetValue(0); double val = (double)(await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, outOfDataRequest), null))).GetValue(0); Assert.IsTrue(double.IsNaN(val)); Assert.IsTrue(double.IsNaN(unc)); } }
public async Task ClusterizationTest() { var storage = TestDataStorageFactory.GetStorage(TestConstants.UriWorldClim); WorldClim14DataSource worldClim = await WorldClim14DataSource.CreateAsync(storage); TimeRegion tr = new TimeRegion(firstYear: 1950, lastYear: 2010, firstDay: 1, lastDay: 31); FetchDomain domain = FetchDomain.CreatePoints( //ocean region new double[] { 53.1, 53.3, -22.8, 53.2 }, //data indeces 13572,13596,13584 new double[] { -116.0, -115.975, 124.8, -115.9 }, //data indeces 7680,7683,36576,7692 tr ); FetchRequest request = new FetchRequest("tmean", domain); var handlerPrivate = new PrivateObject(worldClim, new PrivateType(typeof(DataHandlerFacade))); var aggregatorPrivate = new PrivateObject(handlerPrivate, "valuesAggregator"); var res = await(Task <Array>)(aggregatorPrivate.Invoke("AggregateAsync", RequestContextStub.GetStub(storage, request), null)); Assert.AreEqual(-13.3, (double)res.GetValue(0), 1e-2); Assert.AreEqual(-13.3, (double)res.GetValue(1), 1e-2); Assert.AreEqual(32.6, (double)res.GetValue(2), 1e-2); Assert.AreEqual(-13.3, (double)res.GetValue(3), 1e-2); }