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);
        }
Пример #2
0
        public static async Task <DataHandler> CreateAsync(IStorageContext dataContext)
        {
            IScatteredPointContextBasedLinearWeightProviderOnSphere <IDelaunay_Voronoi> weightsProvider = new AlexNNIAdapter();
            IAsyncMap <INodes, IDelaunay_Voronoi> interpolationContextFactory = new AlexNNIContextProvider();

            //NOTE: interpolation context is cached in the produced interpolators (e.g. Delaunay triangulation is computed only once for each nodes set)
            //We can use one cache for all of the requests (cache is not cleaned) as we use AllStationsStationLocator which returns all stations for any request
            IScatteredPointsLinearInterpolatorOnSphereFactory pointsInterpolatorOnSphereFactory = new CachingLinearWeightsProviderFactory2 <IDelaunay_Voronoi>(weightsProvider, interpolationContextFactory);

            int stationsCount = dataContext.StorageDefinition.DimensionsLengths["stations"];
            var timeAxis      = await dataContext.GetDataAsync("time");

            ITimeAxisAvgProcessing timeAxisIntegrator = new TimeAxisAvgProcessing.TimeAxisAvgFacade(
                timeAxis,
                new TimeAxisProjections.DateTimeMoments(),
                new WeightProviders.StepFunctionInterpolation(),
                new DataCoverageEvaluators.ContinousMeansCoverageEvaluator());
            IStationLocator stationLocator = new AllStationsStationLocator(stationsCount);

            ICellRequestMapFactory <RealValueNodes> timeSeriesAveragerFactory = (await TimeIntegratorBasedAveragerFactory.CreateAsync(dataContext, timeAxisIntegrator, stationLocator));
            ICellRequestMap <RealValueNodes>        timeSeriesAverager        = await timeSeriesAveragerFactory.CreateAsync();

            //NOTE: Here we engage caching of timeseries. Timeseries is cached for all cells having the same time segment. It is acheived by HashBasedTimeSegmentOnlyConverter
            ICellRequestMapFactory <RealValueNodes> cachingTimeSeriesAveragerFactory = new CellRequestMapCachingFactory <RealValueNodes>(timeSeriesAverager, new HashBasedTimeSegmentOnlyConverter());

            ILinearCombintaionContextFactory compContextFactory = new LinearWeightsContextFactoryFacade <RealValueNodes>(pointsInterpolatorOnSphereFactory, cachingTimeSeriesAveragerFactory);

            //NOTE: Hege caching is engaged as well. We cache the variogram for the cells with the same corresponding node set.
            IVariogramProvider        lmVariogramFitter                    = new LmDotNetVariogramProvider();
            IVariogramProviderFactory variogramProviderFactory             = new VariogramProviderCachingFactory(lmVariogramFitter);
            IUncertaintyEvaluatorOfLinearCombination uncertatintyEvaluator = new PointsGausianFieldUncertaintyEvaluator(variogramProviderFactory);

            return(new DataHandler(dataContext, compContextFactory, uncertatintyEvaluator));
        }
        public async Task LinearWeightsContextFactoryFacadeTest()
        {
            var lwcff = new LinearWeightsContextFactoryFacade <RealValueNodesStub>(new Stub4(), new Stub3());

            var cells = new ICellRequest[] { new Stub5() };

            var lwc = await lwcff.CreateAsync(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);
        }