Ejemplo n.º 1
0
        public async Task <double[]> EvaluateCellsBatchAsync(IEnumerable <ICellRequest> cells)
        {
            ICellRequest first = cells.FirstOrDefault();

            if (first == null)
            {
                return(new double[0]);
            }
            else
            {
                var      name            = first.VariableName;
                double[] componentResult = await component.EvaluateCellsBatchAsync(cells);

                Func <double, double> transform = null;

                if (!transformsDict.TryGetValue(name, out transform))
                {
                    return(componentResult);
                }
                else
                {
                    return(componentResult.Select(val => transform(val)).ToArray());
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Produces an array of uncertainties for the request supplied
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <Array> EvaluateAsync(IRequestContext context)
        {
            var name      = context.Request.EnvironmentVariableName;
            var stratched = RequestToBatchAdapter.Stratch(context.Request);
            var annotated = stratched.Select(c => new NameAnnotatedGeoCell(c, name));
            var result    = await component.EvaluateCellsBatchAsync(annotated);

            Array res = RequestToBatchAdapter.Fold(result, context.Request);

            return(res);
        }
Ejemplo n.º 3
0
        public async Task <double[]> EvaluateCellsBatchAsync(IEnumerable <ICellRequest> cells)
        {
            ICellRequest[] cellsArray = cells.ToArray();
            int            N          = cellsArray.Length;

            bool[]   passCellFlag = new bool[N];
            double[] result       = new double[N];

            List <ICellRequest> toPassCellsList = new List <ICellRequest>(N);

            for (int i = 0; i < N; i++)
            {
                DataCoverageResult coverage = GetCoverage(cellsArray[i]);

                bool passCurrent = true;
                if (coverage == DataCoverageResult.OutOfData)
                {
                    result[i]   = double.NaN;
                    passCurrent = false;
                }
                else if (coverage == DataCoverageResult.DataWithoutUncertainty)
                {
                    result[i]   = double.MaxValue;
                    passCurrent = false;
                }
                else
                {
                    toPassCellsList.Add(cellsArray[i]);
                }
                passCellFlag[i] = passCurrent;
            }

            double[] componentResults = await component.EvaluateCellsBatchAsync(toPassCellsList);

            int pointer = 0;

            for (int i = 0; i < N; i++)
            {
                if (passCellFlag[i])
                {
                    result[i] = componentResults[pointer++];
                }
            }

            return(result);
        }
        public async Task <double[]> EvaluateCellsBatchAsync(IEnumerable <ICellRequest> cells)
        {
            ICellRequest first = cells.FirstOrDefault();

            if (first == null)
            {
                return(new double[0]);
            }
            else
            {
                string varName = first.VariableName;
                if (!storageDef.VariablesDimensions.ContainsKey(varName))
                {
                    throw new InvalidOperationException(string.Format("Request to the variable \"{0}\" that is not found in the data storage. Check the variable name mapping in the FetchClimate configuration", varName));
                }
                return(await component.EvaluateCellsBatchAsync(cells));
            }
        }
Ejemplo n.º 5
0
        public async Task <double[]> EvaluateCellsBatchAsync(IEnumerable <ICellRequest> cells)
        {
            ICellRequest[] cellArray = cells.ToArray();

            int N = cellArray.Length;

            if (N == 0)
            {
                return(new double[0]);
            }
            else
            {
                bool[]   passToComponentFlags = new bool[N];
                bool[]   fullCoverageFlags    = new bool[N];
                double[] result = new double[N];

                List <ICellRequest> passToComponentCells = new List <ICellRequest>(N);

                //Result matrix
                //Integrators info\non-MV concentration	0.0	(0.0;1.0)	1.0
                //With unc	ND	NU	U
                //Without unc	ND	NU	NU
                //Out of range (no mean values)	ND	ND	ND

                for (int i = 0; i < N; i++)
                {
                    ICellRequest cell  = cellArray[i];
                    double       landP = maskProvider.GetDataPercentage(cell.LatMin, cell.LatMax, cell.LonMin, cell.LonMax);

                    bool passToComponentFlag = true;
                    bool fullCoverageFlag    = false;

                    if (landP == 0.0)
                    {
                        passToComponentFlag = false;
                        result[i]           = double.NaN;
                    }
                    else if (landP == 1.0)
                    {
                        fullCoverageFlag = true;
                    }

                    passToComponentFlags[i] = passToComponentFlag;
                    fullCoverageFlags[i]    = fullCoverageFlag;
                    if (passToComponentFlag)
                    {
                        passToComponentCells.Add(cell);
                    }
                }

                double[] componentResults = await component.EvaluateCellsBatchAsync(passToComponentCells);

                int pointer = 0;
                for (int i = 0; i < N; i++)
                {
                    if (passToComponentFlags[i])
                    {
                        if (!double.IsNaN(componentResults[pointer]) && !fullCoverageFlags[i])
                        {
                            result[i] = double.MaxValue;
                        }
                        else
                        {
                            result[i] = componentResults[pointer];
                        }
                        pointer++;
                    }
                }

                return(result);
            }
        }