sorting labels are now optional. uses existing labels (from left to right) for sorting if none specified.
This commit is contained in:
parent
d3a7ceff15
commit
5089d86b3d
|
@ -14,7 +14,7 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||||
Sort rows by given column label(s).
|
Sort rows by given (or all) column label(s).
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
With coordinates in columns "x", "y", and "z"; sorting with x slowest and z fastest varying index: --label x,y,z.
|
With coordinates in columns "x", "y", and "z"; sorting with x slowest and z fastest varying index: --label x,y,z.
|
||||||
|
@ -30,25 +30,19 @@ parser.add_option('-r','--reverse',
|
||||||
action = 'store_true',
|
action = 'store_true',
|
||||||
help = 'sort in reverse')
|
help = 'sort in reverse')
|
||||||
|
|
||||||
parser.set_defaults(key = [],
|
parser.set_defaults(reverse = False,
|
||||||
reverse = False,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
|
||||||
if options.keys is None:
|
|
||||||
parser.error('No sorting column(s) specified.')
|
|
||||||
|
|
||||||
options.keys.reverse() # numpy sorts with most significant column as last
|
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
# --- loop over input files -------------------------------------------------------------------------
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
try: table = damask.ASCIItable(name = name,
|
||||||
table = damask.ASCIItable(name = name,
|
buffered = False)
|
||||||
buffered = False)
|
|
||||||
except: continue
|
except: continue
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
|
@ -61,13 +55,14 @@ for name in filenames:
|
||||||
# ------------------------------------------ process data ---------------------------------------
|
# ------------------------------------------ process data ---------------------------------------
|
||||||
|
|
||||||
table.data_readArray()
|
table.data_readArray()
|
||||||
|
|
||||||
|
keys = table.labels[::-1] if options.keys is None else options.keys[::-1] # numpy sorts with most significant column as last
|
||||||
|
|
||||||
cols = []
|
cols = []
|
||||||
remarks = []
|
remarks = []
|
||||||
for i,column in enumerate(table.label_index(options.keys)):
|
for i,column in enumerate(table.label_index(keys)):
|
||||||
if column < 0:
|
if column < 0: remarks.append('label "{}" not present...'.format(keys[i]))
|
||||||
remarks.append("label {0} not present.".format(options.keys[i]))
|
else: cols += [table.data[:,column]]
|
||||||
else:
|
|
||||||
cols += [table.data[:,column]]
|
|
||||||
if remarks != []: damask.util.croak(remarks)
|
if remarks != []: damask.util.croak(remarks)
|
||||||
|
|
||||||
ind = np.lexsort(cols) if cols != [] else np.arange(table.data.shape[0])
|
ind = np.lexsort(cols) if cols != [] else np.arange(table.data.shape[0])
|
||||||
|
|
Loading…
Reference in New Issue