changed library function name table.labels_index() to table.label_index()

This commit is contained in:
Philip Eisenlohr 2015-06-05 11:44:17 +00:00
parent f50927b99f
commit 5adbe74b10
4 changed files with 45 additions and 15 deletions

View File

@ -164,8 +164,8 @@ class ASCIItable():
self.__IO__['labels'] = False
# ------------------------------------------------------------------
def labels_index(self,
labels):
def label_index(self,
labels):
'''
tell index of column label(s).
return numpy array if asked for list of labels.
@ -193,6 +193,36 @@ class ASCIItable():
return np.array(idx) if isinstance(idx,list) else idx
# ------------------------------------------------------------------
def labels_dimension(self,
labels):
'''
tell dimension (length) of column label(s).
return numpy array if asked for list of labels.
transparently deals with label positions implicitly given as numbers or their headings given as strings.
'''
if isinstance(labels,list): # check whether list of labels is requested
dim = []
for label in labels:
if label != None:
try:
idx.append(int(label)) # column given as integer number?
except ValueError:
try:
idx.append(self.labels.index(label)) # locate string in label list
except ValueError:
idx.append(-1) # not found...
else:
try:
idx = int(labels)
except ValueError:
try:
idx = self.labels.index(labels)
except(ValueError):
idx = None if labels == None else -1
return np.array(idx) if isinstance(idx,list) else idx
# ------------------------------------------------------------------
def info_append(self,
what):
@ -273,7 +303,7 @@ class ASCIItable():
use = np.arange(self.__IO__['validReadSize']) # use all columns (and keep labels intact)
labels_missing = []
else:
indices = self.labels_index(labels) # check requested labels
indices = self.label_index(labels) # check requested labels
present = np.where(indices >= 0)[0] # positions in request list of labels that are present ...
missing = np.where(indices < 0)[0] # ... and missing in table
labels_missing = np.array( labels) [missing] # corresponding labels ...

View File

@ -58,9 +58,9 @@ for file in files:
rows, cols = table.data_readArray()
table.data = table.data[np.lexsort([table.data[:,table.labels_index(options.key)]])]
table.data = table.data[np.lexsort([table.data[:,table.label_index(options.key)]])]
values, index = np.unique(table.data[:,table.labels_index(options.key)], return_index=True)
values, index = np.unique(table.data[:,table.label_index(options.key)], return_index=True)
index = np.append(index,rows)
avgTable = np.empty((len(values), cols))

View File

@ -65,7 +65,7 @@ for file in files:
table.data_readArray()
cols = []
for column in table.labels_index(options.keys):
for column in table.label_index(options.keys):
cols += [table.data[:,column]]
ind = np.lexsort(cols)

View File

@ -153,32 +153,32 @@ for file in files:
table.head_read()
labels = []
if np.all(table.labels_index(['1_coords','2_coords','3_coords']) != -1):
if np.all(table.label_index(['1_coords','2_coords','3_coords']) != -1):
coords = ['1_coords','2_coords','3_coords']
elif np.all(table.labels_index(['x','y','z']) != -1):
elif np.all(table.label_index(['x','y','z']) != -1):
coords = ['x','y','z']
else:
file['croak'].write('no coordinate data (1/2/3_coords | x/y/z) found ...')
continue
labels += coords
hasEulers = np.all(table.labels_index(['phi1','Phi','phi2']) != -1)
hasEulers = np.all(table.label_index(['phi1','Phi','phi2']) != -1)
if hasEulers:
labels += ['phi1','Phi','phi2']
hasGrains = table.labels_index('microstructure') != -1
hasGrains = table.label_index('microstructure') != -1
if hasGrains:
labels += ['microstructure']
hasWeight = table.labels_index('weight') != -1
hasWeight = table.label_index('weight') != -1
if hasWeight:
labels += ['weight']
table.data_readArray(labels)
coords = table.data[:,table.labels_index(coords)]
eulers = table.data[:,table.labels_index(['phi1','Phi','phi2'])] if hasEulers else np.zeros(3*len(coords))
grain = table.data[:,table.labels_index('microstructure')] if hasGrains else 1+np.arange(len(coords))
weights = table.data[:,table.labels_index('weight')] if hasWeight else np.zeros(len(coords))
coords = table.data[:,table.label_index(coords)]
eulers = table.data[:,table.label_index(['phi1','Phi','phi2'])] if hasEulers else np.zeros(3*len(coords))
grain = table.data[:,table.label_index('microstructure')] if hasGrains else 1+np.arange(len(coords))
weights = table.data[:,table.label_index('weight')] if hasWeight else np.zeros(len(coords))
grainIDs = np.unique(grain).astype('i')