Esempio n. 1
0
        /// <summary>
        /// Returns a computational context which is a set of nodes and a set "weights" to apply to the nodes to form a linear combination to get the mean value of the cells
        /// </summary>
        public async Task <LinearCombinationContext> CreateAsync(IEnumerable <ICellRequest> cells)
        {
            Stopwatch sw             = Stopwatch.StartNew();
            var       tsAveragerTask = timeSeriesAveragerFactory.CreateAsync();
            var       liTask         = linearInterpolatorFactory.CreateAsync();

            var tsAverager         = await tsAveragerTask;
            var linearInterpolator = await liTask;

            sw.Stop();

            traceSource.TraceEvent(TraceEventType.Verbose, 1, "Time series averager and lenear interpolator constructed in {0}", sw.Elapsed);

            sw = Stopwatch.StartNew();
            var resultTasks = cells.Select <ICellRequest, Task <Tuple <ICellRequest, RealValueNodes, IEnumerable <LinearWeight> > > >(async c =>
            {
                var tsa = (RealValueNodes)(await tsAverager.GetAsync(c));
                var w   = (IEnumerable <LinearWeight>)(await linearInterpolator.GetLinearWeigthsAsync(tsa, c));

                return(Tuple.Create(c, tsa, w));
            }).ToArray();

            var result = await Task.WhenAll(resultTasks);

            sw.Stop();
            traceSource.TraceEvent(TraceEventType.Verbose, 2, "Linear weights for {0} cells prepared in {1}", resultTasks.Length, sw.Elapsed);
            LinearCombinationContext lcc = new LinearCombinationContext(result);

            return(lcc);
        }
Esempio n. 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));
        }