Skip to content

Commit cf31865

Browse files
committed
fix for #132
1 parent 949d81e commit cf31865

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

pgamit/NetPlots.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import numpy as np
99
import matplotlib.pyplot as plt
1010
from mpl_toolkits.basemap import Basemap
11+
from sklearn.neighbors import NearestNeighbors
1112

12-
from pgamit.Utils import ecef2lla
13+
from Utils import ecef2lla
1314

1415

1516
def plot_global_network(central_points, OC, labels, points,
@@ -86,10 +87,18 @@ def plot_global_network(central_points, OC, labels, points,
8687
# Flag centroid point
8788
remove = np.where(points == central_points[label])[0]
8889
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()))
93102
nx.add_star(nodes[label], points)
94103
for position, proj in zip(positions, projs):
95104
mxy = np.zeros_like(LL[points])

0 commit comments

Comments
 (0)