Skip to content

Commit

Permalink
Used functional version of natural sort.
Browse files Browse the repository at this point in the history
  • Loading branch information
smartin71 committed Apr 28, 2022
1 parent 41984e8 commit 0c5778f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion web-server/plugins/slycat-dac/py/dac_compute_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
from scipy import spatial
from sklearn.decomposition import PCA

from natsort import natsorted
# better version of natural sort
# from natsort import natsorted

# for natural sort function
import re

import cherrypy

Expand Down Expand Up @@ -703,6 +707,16 @@ def compute_prop_dist_vec(prop_vec, vec_length):
return prop_dist_vec / prop_dist_vec_max


# helper function for compute alpha to do natural sort
# taken from Ned Batchelder's blog
def natsorted( l ):

convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]

return sorted(l, key=alphanum_key)


# use max-min algorithm to choose landmarks
def select_landmarks(num_points, num_landmarks, variable):

Expand Down

0 comments on commit 0c5778f

Please sign in to comment.