/// <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); }
/// <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."); } }
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); }
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); }
public IVector[] GetObservedLocalization(String exchageItemID, IObservationDescriptions observationDescriptions, double distance) { throw new NotImplementedException(); }
public IVector[] GetStateScaling(IObservationDescriptions observationDescriptions) { throw new NotImplementedException(); }
public void AnnounceObservedValues(IObservationDescriptions observationDescriptions) { throw new NotImplementedException(); }
public IVector GetObservedValues(IObservationDescriptions observationDescriptions) { throw new NotImplementedException(); }
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); }