def findNearestCell(hf,AreaName,gageCoord):
# Finds the nearest cell to the gageCoordinate from the HDF file
CellPts = hf['Geometry']['2D Flow Areas'][AreaName]['Cells Center Coordinate'][:] # All Coordinates which are in 2D Flow Area with name AreaName
fPtInd = hf['Geometry']['2D Flow Areas'][AreaName]['Cells FacePoint Indexes'] # All FacePoint Indices which correspond to each 'cell center point'
# the reason this next step is necessary is that CellPts returns coordinates for face points as well as center points, and we need the index of the cell point.
distances,indices = spatial.KDTree(CellPts).query(gageCoord, k=7) # finds the closest points (cell center or face)
# Now to eliminate FacePoints and only have cell centers left
i = 0
for cell in range(0, len(indices)):
if fPtInd[indices[i]][2] == -1:
distances=np.delete(distances,i)
indices=np.delete(indices,i)
else:
i+=1
continue
if indices.size: # If the indices list is not empty
CellInd = indices[np.where(distances==min(distances))] # Choose the index that's left with the shortest distance
CellDist = distances[np.where(distances==min(distances))] # Displays the distance left
else:
CellInd = [0] # Be careful of this
CellDist = [9999] # Seeing this value in the Distances array will notify you that none of the cells in the 2D flow area were associated with a cell point.
# This is likely because the gage coordinates are too far from a 2D area to be considered "close" to a cell point
# and so face points are all that are being rendered as "close"
return CellInd[0], CellDist[0] # The index of the cell center which is closest to the gage coordinates
# Finds the absolute closest cell to the gage coordinates given. Returns the cell index to be used to access
# output data and the distance of that cell's center to the gage coordinates.
评论列表
文章目录