Skip to content
Snippets Groups Projects
Commit dac56769 authored by Maciej Wielgosz's avatar Maciej Wielgosz
Browse files

fix in fsct/point2trees.py to solve convex hull 2D problem in the cube function

parent c37cdfd2
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ import argparse ...@@ -5,6 +5,7 @@ import argparse
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from tqdm.auto import tqdm from tqdm.auto import tqdm
import scipy
from sklearn.neighbors import NearestNeighbors from sklearn.neighbors import NearestNeighbors
from sklearn.cluster import DBSCAN from sklearn.cluster import DBSCAN
...@@ -65,16 +66,18 @@ def generate_path(samples, origins, n_neighbours=200, max_length=0): ...@@ -65,16 +66,18 @@ def generate_path(samples, origins, n_neighbours=200, max_length=0):
return paths return paths
def cube(pc): def cube(pc):
if len(pc) > 5: if len(pc) > 5:
vertices = ConvexHull(pc[['x', 'y', 'z']]).vertices try:
idx = np.random.choice(vertices, size=len(vertices), replace=False) vertices = ConvexHull(pc[['x', 'y', 'z']]).vertices
return pc.loc[pc.index[idx]] idx = np.random.choice(vertices, size=len(vertices), replace=False)
return pc.loc[pc.index[idx]]
except scipy.spatial.qhull.QhullError as e:
print(f"Error computing convex hull for group with {len(pc)} points: {e}")
# Handle the special case as needed, e.g., return the input or a default value
return pc
else: else:
return pc return pc
if __name__ == '__main__': if __name__ == '__main__':
...@@ -199,11 +202,13 @@ if __name__ == '__main__': ...@@ -199,11 +202,13 @@ if __name__ == '__main__':
# group skeleton points # group skeleton points
grouped = stem_pc.loc[stem_pc.clstr != -1].groupby('clstr') grouped = stem_pc.loc[stem_pc.clstr != -1].groupby('clstr')
if params.verbose: print('fitting convex hulls to clusters') if params.verbose: print('fitting convex hulls to clusters')
if params.pandarallel: if params.pandarallel:
chull = grouped.parallel_apply(cube) # parallel_apply only works witn pd < 1.3 chull = grouped.parallel_apply(cube) # parallel_apply only works witn pd < 1.3
else: else:
chull = grouped.apply(cube) # don't think works with Jasmin or parallel_apply only works witn pd < 1.3 chull = grouped.apply(cube) # don't think works with Jasmin or parallel_apply only works witn pd < 1.3
chull = chull.reset_index(drop=True) chull = chull.reset_index(drop=True)
### identify possible stems ### ### identify possible stems ###
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment