示例#1
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));
        }
示例#2
0
        public async Task VariogramCachingTest()
        {
            var component       = new VarpProvStub();
            var factory         = new VariogramProviderCachingFactory(component);
            var variogramfitter = await factory.ConstructAsync();

            double[] lats = new double[10], lons = new double[10], vals = new double[10];

            Random r = new Random(1);

            for (int i = 0; i < 10; i++)
            {
                lats[i] = r.NextDouble();
                lons[i] = r.NextDouble();
                vals[i] = 3 * lons[i] + 2 * lats[i];
            }


            RealValueNodes rvn1 = new RealValueNodes(lats, lons, vals);
            RealValueNodes rvn2 = new RealValueNodes(lats, lons, vals);
            RealValueNodes rvn3 = new RealValueNodes(lats, lons, lons);

            var v1 = await variogramfitter.GetSpatialVariogramAsync(rvn1);

            var v2 = await variogramfitter.GetSpatialVariogramAsync(rvn2);

            var v3 = await variogramfitter.GetSpatialVariogramAsync(rvn3);

            Assert.AreEqual(1.0, v1.Nugget);
            Assert.AreEqual(1.0, v2.Nugget);
            Assert.AreEqual(2.0, v3.Nugget);
        }