Skip to content

Commit 3773bcf

Browse files
refactor makeclusters to make it work (#73)
1 parent 578a972 commit 3773bcf

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Diff for: src/diffpy/srmise/dataclusters.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def _setdata(self, x, y, res):
172172
self.lastcluster_idx = None
173173
return
174174

175-
def next(self):
175+
def cluster_next_point(self):
176176
"""Cluster point with largest y-coordinate left, returning self.
177177
178178
next() always adds at least one additional point to the existing
@@ -217,14 +217,13 @@ def next(self):
217217
else:
218218
# insert right of nearest cluster
219219
self.lastcluster_idx = nearest_cluster[0] + 1
220-
self.clusters = np.insert(self.clusters, self.lastcluster_idx, [test_idx, test_idx], 0)
220+
self.clusters = np.insert(self.clusters, int(self.lastcluster_idx), [test_idx, test_idx], 0)
221221
return self
222222

223223
def makeclusters(self):
224224
"""Cluster all remaining data."""
225-
for i in self:
226-
pass
227-
return
225+
while self.current_idx > 0:
226+
self.cluster_next_point()
228227

229228
def find_nearest_cluster2(self, x):
230229
"""Return [cluster index, distance] for cluster nearest to x.
@@ -286,8 +285,8 @@ def find_nearest_cluster(self, idx):
286285
# Calculate which of the two nearest clusters is closer
287286
distances = np.array(
288287
[
289-
self.x[idx] - self.x[self.clusters[near_idx - 1, 1]],
290-
self.x[idx] - self.x[self.clusters[near_idx, 0]],
288+
self.x[idx] - self.x[self.clusters[int(near_idx) - 1, 1]],
289+
self.x[idx] - self.x[self.clusters[int(near_idx), 0]],
291290
]
292291
)
293292
if distances[0] < np.abs(distances[1]):

0 commit comments

Comments
 (0)