|
8 | 8 | import numpy as np
|
9 | 9 | import matplotlib.pyplot as plt
|
10 | 10 | from mpl_toolkits.basemap import Basemap
|
| 11 | +from sklearn.neighbors import NearestNeighbors |
11 | 12 |
|
12 |
| -from pgamit.Utils import ecef2lla |
| 13 | +from Utils import ecef2lla |
13 | 14 |
|
14 | 15 |
|
15 | 16 | def plot_global_network(central_points, OC, labels, points,
|
@@ -86,10 +87,18 @@ def plot_global_network(central_points, OC, labels, points,
|
86 | 87 | # Flag centroid point
|
87 | 88 | remove = np.where(points == central_points[label])[0]
|
88 | 89 | points = points.tolist()
|
89 |
| - # remove centroid point so it's not repeated |
90 |
| - points.pop(remove[0]) |
91 |
| - # add central point to beginning so it's the central connection point |
92 |
| - points.insert(0, central_points[label]) |
| 90 | + try: |
| 91 | + # remove centroid point so it's not repeated |
| 92 | + points.pop(remove[0]) |
| 93 | + # add same point to beginning of list |
| 94 | + points.insert(0, central_points[label]) |
| 95 | + except IndexError: |
| 96 | + nbrs = NearestNeighbors(n_neighbors=1, algorithm='ball_tree', |
| 97 | + metric='haversine').fit(LL[points]) |
| 98 | + idx = nbrs.kneighbors(LL[central_points[label]].reshape(1, -1), |
| 99 | + return_distance=False) |
| 100 | + # add central point to beginning as the central connection point |
| 101 | + points.insert(0, points.pop(idx.squeeze())) |
93 | 102 | nx.add_star(nodes[label], points)
|
94 | 103 | for position, proj in zip(positions, projs):
|
95 | 104 | mxy = np.zeros_like(LL[points])
|
|
0 commit comments