From c9dcb41bac93a966bf66caf5eb8693e1e2d29e4d Mon Sep 17 00:00:00 2001 From: Tias Maiti Date: Tue, 8 Sep 2015 23:55:44 +0000 Subject: [PATCH] =?UTF-8?q?fixed=20sorting=20logic=20to=20respect=20numeri?= =?UTF-8?q?cal=20values=20of=20vector=20data=20(i.e.=201,2,3,=E2=80=A6.,10?= =?UTF-8?q?,11,=E2=80=A6=20instead=20of=2010,11,12,1,2,=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- processing/post/filterTable.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/processing/post/filterTable.py b/processing/post/filterTable.py index e5ace6ebc..c44f66603 100755 --- a/processing/post/filterTable.py +++ b/processing/post/filterTable.py @@ -8,6 +8,22 @@ import damask scriptID = '$Id$' scriptName = os.path.splitext(scriptID.split()[1])[0] +def sortingList(labels,whitelistitems): + + indices = [] + names = [] + + for label in labels: + if re.match('^\d+_',label): + indices.append(int(label.split('_',1)[0])) + names.append(label.split('_',1)[1]) + else: + indices.append(0) + names.append(label) + + return [indices,names,whitelistitems] + + # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- @@ -47,7 +63,7 @@ for name in filenames: table = damask.ASCIItable(name = name, buffered = False) except: continue - table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else '')) + table.croak(damask.util.emph(scriptName)+(': '+name if name else '')) # ------------------------------------------ assemble info --------------------------------------- @@ -70,13 +86,13 @@ for name in filenames: positions.append(position) # ...and position if len(labels) > 0 and options.whitelist != None and options.blacklist == None: # check whether reordering is possible - position = np.zeros(len(labels)) + whitelistitem = np.zeros(len(labels),dtype=int) for i,label in enumerate(labels): # check each selected label match = [ positions[i] in table.label_indexrange(needle) \ - or fnmatch.fnmatch(label,needle) for needle in options.whitelist] # which whitelist items do match it - position[i] = match.index(True) if np.sum(match) == 1 else -1 # unique match --> store which + or fnmatch.fnmatch(label,needle) for needle in options.whitelist] # which whitelist items do match it + whitelistitem[i] = match.index(True) if np.sum(match) == 1 else -1 # unique match to a whitelist item --> store which - sorted = np.lexsort((labels,position)) + sorted = np.lexsort(sortingList(labels,whitelistitem)) order = range(len(labels)) if sorted[0] < 0 else sorted # skip reordering if non-unique, i.e. first sorted is "-1" else: order = range(len(labels)) # maintain original order of labels