Skip to content

refactor makeclusters to make it work #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/diffpy/srmise/dataclusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _setdata(self, x, y, res):
self.lastcluster_idx = None
return

def next(self):
def cluster_next_point(self):
"""Cluster point with largest y-coordinate left, returning self.

next() always adds at least one additional point to the existing
Expand Down Expand Up @@ -217,14 +217,13 @@ def next(self):
else:
# insert right of nearest cluster
self.lastcluster_idx = nearest_cluster[0] + 1
self.clusters = np.insert(self.clusters, self.lastcluster_idx, [test_idx, test_idx], 0)
self.clusters = np.insert(self.clusters, int(self.lastcluster_idx), [test_idx, test_idx], 0)
return self

def makeclusters(self):
"""Cluster all remaining data."""
for i in self:
pass
return
while self.current_idx > 0:
self.cluster_next_point()

def find_nearest_cluster2(self, x):
"""Return [cluster index, distance] for cluster nearest to x.
Expand Down Expand Up @@ -286,8 +285,8 @@ def find_nearest_cluster(self, idx):
# Calculate which of the two nearest clusters is closer
distances = np.array(
[
self.x[idx] - self.x[self.clusters[near_idx - 1, 1]],
self.x[idx] - self.x[self.clusters[near_idx, 0]],
self.x[idx] - self.x[self.clusters[int(near_idx) - 1, 1]],
self.x[idx] - self.x[self.clusters[int(near_idx), 0]],
]
)
if distances[0] < np.abs(distances[1]):
Expand Down
Loading