changed library function name table.labels_index() to table.label_index()
This commit is contained in:
parent
f50927b99f
commit
5adbe74b10
|
@ -164,8 +164,8 @@ class ASCIItable():
|
||||||
self.__IO__['labels'] = False
|
self.__IO__['labels'] = False
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def labels_index(self,
|
def label_index(self,
|
||||||
labels):
|
labels):
|
||||||
'''
|
'''
|
||||||
tell index of column label(s).
|
tell index of column label(s).
|
||||||
return numpy array if asked for list of labels.
|
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
|
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,
|
def info_append(self,
|
||||||
what):
|
what):
|
||||||
|
@ -273,7 +303,7 @@ class ASCIItable():
|
||||||
use = np.arange(self.__IO__['validReadSize']) # use all columns (and keep labels intact)
|
use = np.arange(self.__IO__['validReadSize']) # use all columns (and keep labels intact)
|
||||||
labels_missing = []
|
labels_missing = []
|
||||||
else:
|
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 ...
|
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
|
missing = np.where(indices < 0)[0] # ... and missing in table
|
||||||
labels_missing = np.array( labels) [missing] # corresponding labels ...
|
labels_missing = np.array( labels) [missing] # corresponding labels ...
|
||||||
|
|
|
@ -58,9 +58,9 @@ for file in files:
|
||||||
|
|
||||||
rows, cols = table.data_readArray()
|
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)
|
index = np.append(index,rows)
|
||||||
avgTable = np.empty((len(values), cols))
|
avgTable = np.empty((len(values), cols))
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ for file in files:
|
||||||
|
|
||||||
table.data_readArray()
|
table.data_readArray()
|
||||||
cols = []
|
cols = []
|
||||||
for column in table.labels_index(options.keys):
|
for column in table.label_index(options.keys):
|
||||||
cols += [table.data[:,column]]
|
cols += [table.data[:,column]]
|
||||||
|
|
||||||
ind = np.lexsort(cols)
|
ind = np.lexsort(cols)
|
||||||
|
|
|
@ -153,32 +153,32 @@ for file in files:
|
||||||
table.head_read()
|
table.head_read()
|
||||||
|
|
||||||
labels = []
|
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']
|
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']
|
coords = ['x','y','z']
|
||||||
else:
|
else:
|
||||||
file['croak'].write('no coordinate data (1/2/3_coords | x/y/z) found ...')
|
file['croak'].write('no coordinate data (1/2/3_coords | x/y/z) found ...')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
labels += coords
|
labels += coords
|
||||||
hasEulers = np.all(table.labels_index(['phi1','Phi','phi2']) != -1)
|
hasEulers = np.all(table.label_index(['phi1','Phi','phi2']) != -1)
|
||||||
if hasEulers:
|
if hasEulers:
|
||||||
labels += ['phi1','Phi','phi2']
|
labels += ['phi1','Phi','phi2']
|
||||||
|
|
||||||
hasGrains = table.labels_index('microstructure') != -1
|
hasGrains = table.label_index('microstructure') != -1
|
||||||
if hasGrains:
|
if hasGrains:
|
||||||
labels += ['microstructure']
|
labels += ['microstructure']
|
||||||
|
|
||||||
hasWeight = table.labels_index('weight') != -1
|
hasWeight = table.label_index('weight') != -1
|
||||||
if hasWeight:
|
if hasWeight:
|
||||||
labels += ['weight']
|
labels += ['weight']
|
||||||
|
|
||||||
table.data_readArray(labels)
|
table.data_readArray(labels)
|
||||||
coords = table.data[:,table.labels_index(coords)]
|
coords = table.data[:,table.label_index(coords)]
|
||||||
eulers = table.data[:,table.labels_index(['phi1','Phi','phi2'])] if hasEulers else np.zeros(3*len(coords))
|
eulers = table.data[:,table.label_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))
|
grain = table.data[:,table.label_index('microstructure')] if hasGrains else 1+np.arange(len(coords))
|
||||||
weights = table.data[:,table.labels_index('weight')] if hasWeight else np.zeros(len(coords))
|
weights = table.data[:,table.label_index('weight')] if hasWeight else np.zeros(len(coords))
|
||||||
grainIDs = np.unique(grain).astype('i')
|
grainIDs = np.unique(grain).astype('i')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue