/// <summary> /// BASEGRID /// Returns a localization hash table. /// For each observation point, calculate the gaussian distance to all other points in the model grid. /// </summary> /// <param name="exchangeItemId">The exchange ID string</param> /// <param name="observationCount">The number of observation points</param> /// <param name="locDistance">The localization distance (for Gaussian distance)</param> /// <param name="xpos">array of observation X coordinates</param> /// <param name="ypos">array of observation Y coordinates</param> /// <returns></returns> private double[][] GetLocalized2D(string exchangeItemId, int observationCount, double locDistance, double[] xpos, double[] ypos) { double[][] localized2D = new double[observationCount][]; var mshe = base.WMEngine; // BASEGRID int n = mshe.Grid.ElementCount; IDictionary <int, ISpatialDefine> modelCoord = GetModelCoordinates(exchangeItemId); for (int obsC = 0; obsC < observationCount; obsC++) { localized2D[obsC] = new double[n]; IXYLayerPoint obsPoint = new XYLayerPoint(xpos[obsC], ypos[obsC], 0); if (XYZGeometryTools.IsPointInModelPlain(obsPoint, modelCoord, false)) { for (int i = 0; i < modelCoord.Count; i++) { if (Convert.ToInt32(obsPoint.Layer) == modelCoord[i].Layer) { double distanceC = XYZGeometryTools.CalculatePointToPointDistance2D(modelCoord[i].MidPoint, obsPoint); localized2D[obsC][i] = normalCooefs(distanceC, locDistance); } } } } return(localized2D); }
/// <summary> /// For 3D SZ (hydraulic head). /// Returns a localization hash table. /// For each observation point, calculate the gaussian distance to all other points in the model grid. /// </summary> /// <param name="exchangeItemId">The exchange ID string</param> /// <param name="observationCount">The number of observation points</param> /// <param name="locDistance">The localization distance (for Gaussian distance)</param> /// <param name="xpos">array of observation X coordinates</param> /// <param name="ypos">array of observation Y coordinates</param> /// <param name="layer">array of observation Z heights (layer in the model)</param> /// <returns></returns> private double[][] GetLocalized3DSZ(string exchangeItemId, int observationCount, double locDistance, double[] xpos, double[] ypos, int[] layer) { double[][] localized2D = new double[observationCount][]; var mshe = base.WMEngine; IDictionary <int, ISpatialDefine> modelCoord = GetModelCoordinates(exchangeItemId); // SZGrid int n = modelCoord.Count; for (int obsC = 0; obsC < observationCount; obsC++) { // int countNormalizedCheck = 0; localized2D[obsC] = new double[n]; IXYLayerPoint obsPoint = new XYLayerPoint(xpos[obsC], ypos[obsC], 0); if (XYZGeometryTools.IsPointInModelPlain(obsPoint, modelCoord, true)) { for (int i = 0; i < n; i++) { double distanceC = XYZGeometryTools.CalculatePointToPointDistance2D(modelCoord[i].MidPoint, obsPoint); double normalized = normalCooefs(distanceC, locDistance); if (normalized > 0.001) { localized2D[obsC][i] = normalized; //countNormalizedCheck = countNormalizedCheck + 1; } } } //Console.WriteLine("Number of normalized for observation:{0} is {1}", obsC,countNormalizedCheck); } return(localized2D); }
private void ModelCoordinatesSZ(OpenDA.DotNet.Interfaces.IObservationDescriptions observationDescriptions, ref IList <int> modelIndices, int starti, int lasti) { //IList<int> modelIndexCorrespondingToObss = new List<int>(); Full3DGrid grid = WMEngine.SzGrid; IXYLayerPoint lowerleft = new XYLayerPoint(grid.GetVertexXCoordinate(0, 0), grid.GetVertexYCoordinate(0, 0), 0); IXYLayerPoint upperright = new XYLayerPoint(grid.GetVertexXCoordinate(0, 2), grid.GetVertexYCoordinate(0, 2), 0); double dx = upperright.X - lowerleft.X; double dy = upperright.Y - lowerleft.Y; int nz = WMEngine.SzGrid.NumberOfNodesPerColumn; // First vertical from layer 0 to topo, then horizontal grid one by one. speficy the right location(order) mod by DZ int nElements = WMEngine.SzGrid.ElementCount; IDictionary <int, ISpatialDefine> modelEntities = new Dictionary <int, ISpatialDefine>(nElements * nz); for (int i = 0; i < nElements; i += nz) { //int zLayer = Convert.ToInt32(i % nz); // Points in Polygon are defined as LL, LR, UR, UL (l/l = lower/left, u = upper, r = right ) // Finds the mid x and mid y point in the polygon (assuming rectangular grid) double LLx = grid.GetVertexXCoordinate(i, 0); double LLy = grid.GetVertexYCoordinate(i, 0); double URx = LLx + dx; double URy = LLy + dy; for (int j = 0; j < nz; j++) { modelEntities.Add((nz - j - 1) * nElements / nz + i / nz, new SpatialDefine(new XYLayerPoint(LLx, LLy, j), new XYLayerPoint(URx, URy, j), GeometryTypes.Geometry3DSZ)); } } double[] xpos = observationDescriptions.GetValueProperties("xposition").Values; double[] ypos = observationDescriptions.GetValueProperties("yposition").Values; double[] height = observationDescriptions.GetValueProperties("height").Values; // For each observation index in DFS file for (int i = starti; i <= lasti; i++) { IXYLayerPoint obsPoint = new XYLayerPoint(xpos[i], ypos[i], Convert.ToInt32(height[i])); int modelIdex = XYZGeometryTools.ModelIndexWherePointIsLocated(obsPoint, modelEntities); if (modelIdex > 0) { modelIndices.Add(modelIdex); /* * if (!modelIndices.Contains(modelIdex)) * { * modelIndices.Add(modelIdex); * } * else * { * throw new Exception("More than one observation for same model index"); * } */ } } }
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); }