Changeset 17867
- Timestamp:
- 04/28/14 17:06:48 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/interp/holefiller.py
r17551 r17867 2 2 from scipy.spatial import cKDTree 3 3 4 def nearestneighbors( md,data,goodids,badids,knn):4 def nearestneighbors(x,y,data,goodids,badids,knn): 5 5 ''' 6 6 fill holes using nearest neigbors. Arguments include: 7 7 8 md: the model 8 9 x,y: the coordinates of data to be filled 9 10 data: the data field to be filled (full field, including holes) 10 11 goodids: id's into the vertices that have good data … … 15 16 16 17 Usage: 17 filleddata=nearestneighbors( md,goodids,badids,knn)18 filleddata=nearestneighbors(x,y,data,goodids,badids,knn) 18 19 19 20 Example: 20 filledthickness=nearestneighbors( md,goodids,badids,5)21 filledthickness=nearestneighbors(x,y,data,goodids,badids,5) 21 22 ''' 22 23 … … 24 25 raise TypeError('nearestneighbors error: knn should be an integer>1') 25 26 26 if len( data) != md.mesh.numberofvertices:27 raise StandardError('nearestneighbors error: "data" should have length md.mesh.numberofvertices')27 if len(x) != len(data) or len(y) != len(data): 28 raise StandardError('nearestneighbors error: x and y should have the same length as "data"') 28 29 29 30 filled=data 30 31 31 XYGood=npy.dstack([ md.mesh.x[goodids],md.mesh.y[goodids]])[0]32 XYBad=npy.dstack([ md.mesh.x[badids],md.mesh.y[badids]])[0]32 XYGood=npy.dstack([x[goodids],y[goodids]])[0] 33 XYBad=npy.dstack([x[badids],y[badids]])[0] 33 34 tree=cKDTree(XYGood) 34 35 nearest=tree.query(XYBad,k=knn)[1]
Note:
See TracChangeset
for help on using the changeset viewer.