public static async Task <DataHandler> CreateAsync(IStorageContext dataContext) { var storageDefinition = dataContext.StorageDefinition; string latAxisName = IntegratorsFactoryHelpers.AutodetectLatName(storageDefinition); string lonAxisName = IntegratorsFactoryHelpers.AutodetectLonName(storageDefinition); var timeAxisDetection = StepFunctionAutoDetectHelper.SmartDetectAxis(dataContext); var result = timeAxisDetection as StepFunctionAutoDetectHelper.AxisFound; if (result == null) { throw new InvalidOperationException("Time axes detection failed"); } var latAxisTask = dataContext.GetDataAsync(latAxisName); var lonAxisTask = dataContext.GetDataAsync(lonAxisName); var timeAxis = await dataContext.GetDataAsync(result.AxisName); var timeGroupCalc = StepFunctionAutoDetectHelper.ConstructStatisticsCalculator(result.AxisKind, timeAxis, result.BaseOffset); var latAxis = await latAxisTask; var latStatCalc = new CoveredPointsStatistics(latAxis); var lonAxis = await lonAxisTask; var lonStatCalc = new CoveredPointsStatistics(lonAxis); var baseUncertaintyProvider = new NoUncertaintyEvaluator(); var coverageCheckUncertaintyEvaluator = new GridUncertaintyConventionsDecorator(baseUncertaintyProvider, latStatCalc, lonStatCalc, timeGroupCalc); var variablePresenceCheckEvaluator = new VariablePresenceCheckDecorator(dataContext.StorageDefinition, coverageCheckUncertaintyEvaluator); var gridAggregator = new GridModeAggregator(dataContext, timeGroupCalc, latStatCalc, lonStatCalc, true); var clusteringAggregator = new GridClusteringDecorator(dataContext.StorageDefinition, gridAggregator, timeGroupCalc, latStatCalc, lonStatCalc); return(new DataHandler(dataContext, variablePresenceCheckEvaluator, clusteringAggregator)); }
public static async Task <DataHandler> CreateAsync(IStorageContext dataContext) { var storageDefinition = dataContext.StorageDefinition; var latIntegratorTask = LinearIntegratorsFactory.SmartConstructAsync(dataContext, IntegratorsFactoryHelpers.AutodetectLatName(storageDefinition)); var lonIntegratorTask = LinearIntegratorsFactory.SmartConstructAsync(dataContext, IntegratorsFactoryHelpers.AutodetectLonName(storageDefinition)); var timeAxisDetection = StepFunctionAutoDetectHelper.SmartDetectAxis(dataContext); var result = timeAxisDetection as StepFunctionAutoDetectHelper.AxisFound; if (result == null) { throw new InvalidOperationException("Time axes detection failed"); } var timeAxis = await dataContext.GetDataAsync(result.AxisName); if (timeAxis.Length < 2) { throw new InvalidOperationException("time axis length must be at least 2"); } if (timeAxis.GetType().GetElementType() != typeof(Int16)) { throw new InvalidOperationException("NDVI Yearly data handler now supports only Int16 time axis"); } Int16[] typedTimeAxis = (Int16[])timeAxis; Int16 step = (Int16)(typedTimeAxis[typedTimeAxis.Length - 1] - typedTimeAxis[typedTimeAxis.Length - 2]); Int16[] extendedAxis = typedTimeAxis.Concat(new Int16[] { (Int16)(typedTimeAxis[typedTimeAxis.Length - 1] + step) }).ToArray(); var latIntegrator = await latIntegratorTask; var lonIntegrator = await lonIntegratorTask; var timeIntegrator = StepFunctionAutoDetectHelper.ConstructAverager(result.AxisKind, extendedAxis, result.BaseOffset); var baseUncertaintyProvider = new NoUncertaintyEvaluator(); var coverageCheckUncertaintyEvaluator = new GridUncertaintyConventionsDecorator(baseUncertaintyProvider, latIntegrator, lonIntegrator, timeIntegrator); var variablePresenceCheckEvaluator = new VariablePresenceCheckDecorator(dataContext.StorageDefinition, coverageCheckUncertaintyEvaluator); var gridAggregator = new GridMeanAggregator(dataContext, timeIntegrator, latIntegrator, lonIntegrator, true); var clusteringAggregator = new GridClusteringDecorator(dataContext.StorageDefinition, gridAggregator, timeIntegrator, latIntegrator, lonIntegrator); return(new DataHandler(dataContext, variablePresenceCheckEvaluator, clusteringAggregator)); }