コード例 #1
0
        /// <summary>
        /// Hx = Gets the model values at the indices that are passed in the list.
        /// </summary>
        /// <param name="observationDescriptions">The description of the observations.</param>
        /// <param name="indices">List of indices to be retrieved from the model.</param>
        /// <returns>Array of model values at the given indices.</returns>
        public double[] ModelValuesAtProvidedIndices(OpenDA.DotNet.Interfaces.IObservationDescriptions observationDescriptions, IList <int> indices)
        {
            String[] keys     = observationDescriptions.PropertyKeys;
            String[] quantity = observationDescriptions.GetStringProperties("quantity");
            double[] xpos     = observationDescriptions.GetValueProperties("xposition").Values;
            double[] ypos     = observationDescriptions.GetValueProperties("yposition").Values;
            double[] height   = observationDescriptions.GetValueProperties("height").Values;

            int observationCount = observationDescriptions.ObservationCount;
            int nObs             = quantity.Length; // same as observationCount?


            // The heights should be specified in an array of integers representing the layer. Check if the values are indeed integers or close to integers before converting
            // the array of doubles to an array of integers.
            const double tolerance = 1e-5;

            int[] layer = new int[observationCount];
            for (int i = 0; i < observationCount; i++)
            {
                layer[i] = Convert.ToInt32(height[i]);
                if (Math.Abs(layer[i] - height[i]) > tolerance)
                {
                    throw new Exception("The height specified in the observation was not an integer. Observation \n");
                }
            }

            List <string> obsIds = ObsIDtoExchangeId(observationDescriptions);

            // An array of model values corresponding to the observation points.
            double[] Hx = GetModelValuesDifferentVariables(obsIds, indices);

            return(Hx);
        }
コード例 #2
0
        /// <summary>
        /// OpenMI does not know about localization. In this method, the user can implement localization for OpenMI models in this method
        /// </summary>
        /// <param name="exchangeItemId">the exchange ID string</param>
        /// <param name="observationDescriptions">OpenDA type of observation description</param>
        /// <param name="locDistance">the distance for gaussian localization</param>
        /// <returns></returns>
        public double[][] getLocalization(string exchangeItemId, OpenDA.DotNet.Interfaces.IObservationDescriptions observationDescriptions, double locDistance)
        {
            //Get the Keys from the observer
            String[] keys             = observationDescriptions.PropertyKeys;
            String[] quantity         = observationDescriptions.GetStringProperties("quantity");
            double[] xpos             = observationDescriptions.GetValueProperties("xposition").Values;
            double[] ypos             = observationDescriptions.GetValueProperties("yposition").Values;
            double[] height           = observationDescriptions.GetValueProperties("height").Values;
            int      observationCount = observationDescriptions.ObservationCount;

            // The heights should be specified in an array of integers representing the layer. Check if the values are indeed integers or close to integers before converting
            // the array of doubles to an array of integers.
            for (int i = 0; i < height.Length; i++)
            {
                if (double.IsNaN(height[i]))
                {
                    height[i] = 0.0;
                }
            }

            const double tolerance = 1e-5;

            int[] layer = new int[observationCount];
            for (int i = 0; i < observationCount; i++)
            {
                layer[i] = Convert.ToInt32(height[i]);
                if (Math.Abs(layer[i] - height[i]) > tolerance)
                {
                    throw new Exception("The height specified in the observation was not an integer. Observation \n");
                }
            }


            // Gets the Grid type for the model. Can be a number of possibilities depending on the variable.
            GeometryTypes geometrytype = GetGridType(exchangeItemId);


            //BaseGrid
            if (geometrytype == GeometryTypes.Geometry2D)
            {
                return(GetLocalized2D(exchangeItemId, observationCount, locDistance, xpos, ypos));
            }
            if (geometrytype == GeometryTypes.Geometry3DSZ)
            {
                double[][] mask = GetLocalized3DSZ(exchangeItemId, observationCount, locDistance, xpos, ypos, layer);
                return(mask);
            }
            else
            {
                throw new NotImplementedException("Only 3D SZ and 2D BaseGrid supported so far.");
            }
        }
コード例 #3
0
        private List <string> ObsIDtoExchangeId(OpenDA.DotNet.Interfaces.IObservationDescriptions observationDescriptions)
        {
            String[] keys     = observationDescriptions.PropertyKeys;
            String[] quantity = observationDescriptions.GetStringProperties("quantity");
            double[] xpos     = observationDescriptions.GetValueProperties("xposition").Values;
            double[] ypos     = observationDescriptions.GetValueProperties("yposition").Values;
            double[] height   = observationDescriptions.GetValueProperties("height").Values;

            int observationCount = observationDescriptions.ObservationCount;
            int nObs             = xpos.Length; // same as observationCount?

            List <string> exchangeItemId = new List <string>();

            for (int obsC = 0; obsC < nObs; obsC++)
            {
                if (quantity[obsC].Equals("Head", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId.Add("head elevation in saturated zone,SZ3DGrid");
                }
                else if (quantity[obsC].Equals("SoilMoisture", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId.Add("water content in unsaturated zone,WMUZ3DGrid");
                }
                else if (quantity[obsC].Equals("SurfaceTemperature", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId.Add("Surface temperature (effective),BaseGrid");
                }
                else if (quantity[obsC].Equals("SZVerticalConductivity", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId.Add("SZ vertical conductivity (for DA-OpenMI),SZ3DGrid");
                }
                else if (quantity[obsC].Equals("SZHorizontalConductivity", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId.Add("SZ horizontal conductivity (for DA-OpenMI),SZ3DGrid");
                }
                else
                {
                    throw new Exception("Cannot (yet) handle obversvations of quantity (" + quantity[obsC] + ")");
                }
            }
            return(exchangeItemId);
        }
コード例 #4
0
        public IList <int> CreateModelIndicesHashTable(OpenDA.DotNet.Interfaces.IObservationDescriptions observationDescriptions)
        {
            String[]    keys         = observationDescriptions.PropertyKeys;
            String[]    quantity     = observationDescriptions.GetStringProperties("quantity");
            IList <int> modelIndices = new List <int>(quantity.Count());


            int headi = quantity.ToList().FindIndex(q => String.CompareOrdinal(q, "Head") == 0);
            int smi   = quantity.ToList().FindIndex(q => String.CompareOrdinal(q, "SoilMoisture") == 0);


            if (headi != 1)
            {
                int starti = quantity.ToList().FindIndex(q => String.CompareOrdinal(q, "Head") == 0);
                int lasti  = quantity.ToList().FindLastIndex(q => String.CompareOrdinal(q, "Head") == 0);
                ModelCoordinatesSZ(observationDescriptions, ref modelIndices, starti, lasti);
            }
            else if (smi != 1)
            {
                throw new NotImplementedException("Haven't implemented this for soil moisture.");
            }
            return(modelIndices);
        }
コード例 #5
0
        public double[] getObservedValues(OpenDA.DotNet.Interfaces.IObservationDescriptions observationDescriptions)
        {
            String[] keys     = observationDescriptions.PropertyKeys;
            String[] quantity = observationDescriptions.GetStringProperties("quantity");
            double[] xpos     = observationDescriptions.GetValueProperties("xposition").Values;
            double[] ypos     = observationDescriptions.GetValueProperties("yposition").Values;
            double[] height   = observationDescriptions.GetValueProperties("height").Values;

            int observationCount = observationDescriptions.ObservationCount;
            int nObs             = quantity.Length; // same as observationCount?


            // The heights should be specified in an array of integers representing the layer. Check if the values are indeed integers or close to integers before converting
            // the array of doubles to an array of integers.
            for (int i = 0; i < height.Length; i++)
            {
                if (double.IsNaN(height[i]))
                {
                    height[i] = 0.0;
                }
            }
            const double tolerance = 1e-5;

            int[] layer = new int[observationCount];
            for (int i = 0; i < observationCount; i++)
            {
                layer[i] = Convert.ToInt32(height[i]);
                if (Math.Abs(layer[i] - height[i]) > tolerance)
                {
                    throw new Exception("The height specified in the observation was not an integer. Observation \n");
                }
            }

            // An array of model values corresponding to the observation points.
            double[] Hx = new double[nObs];

            for (int obsC = 0; obsC < nObs; obsC++)
            {
                // Set exchangeItem that corresponds to EntityID (no conversion yet)
                String exchangeItemId;
                if (quantity[obsC].Equals("Head", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId = "head elevation in saturated zone,SZ3DGrid";
                }
                else if (quantity[obsC].Equals("SoilMoisture", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId = "water content in unsaturated zone,WMUZ3DGrid";
                }
                else if (quantity[obsC].Equals("SurfaceTemperature", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId = "Surface temperature (effective),BaseGrid";
                }
                else if (quantity[obsC].Equals("SZVerticalConductivity", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId = "SZ vertical conductivity (for DA-OpenMI),SZ3DGrid";
                }
                else if (quantity[obsC].Equals("SZHorizontalConductivity", StringComparison.OrdinalIgnoreCase))
                {
                    exchangeItemId = "SZ horizontal conductivity (for DA-OpenMI),SZ3DGrid";
                }
                else
                {
                    throw new Exception("Cannot (yet) handle obversvations of quantity (" + quantity[obsC] + ")");
                }

                IDictionary <int, ISpatialDefine> modelCoord = GetModelCoordinates(exchangeItemId);
                IXYLayerPoint obsPoint = new XYLayerPoint(xpos[obsC], ypos[obsC], layer[obsC]);


                int modelVariableIndex = XYZGeometryTools.ModelIndexWherePointIsLocated(obsPoint, modelCoord);


                if (modelVariableIndex >= 0)
                {
                    Hx[obsC] = GetModelValue(exchangeItemId, modelVariableIndex);
                }
                else
                {
                    throw new Exception("The observation point was NOT in the model grid! For Point: (" + xpos[obsC].ToString() + "," + ypos[obsC].ToString() + "," + layer[obsC].ToString() + ") \n");
                }
            }
            return(Hx);
        }