changed numpy.readtxt logic from "data_asArray" returning a copy to inplace "data_readArray" now directly storing into self.data

This commit is contained in:
Philip Eisenlohr 2013-12-14 03:51:22 +00:00
parent 600389ac44
commit e20ffb379d
3 changed files with 24 additions and 25 deletions

View File

@ -198,8 +198,7 @@ class ASCIItable():
line = self.__IO__['in'].readline() # get next data row
if self.__IO__['labels']:
items = line.split()[:self.__IO__['validReadSize']] # use up to valid size (label count)
self.data = {False: [],
True: items}[len(items) == self.__IO__['validReadSize']] # take if correct number of entries
self.data = items if len(items) == self.__IO__['validReadSize'] else [] # take if correct number of entries
else:
self.data = line.split() # take all
@ -211,6 +210,23 @@ class ASCIItable():
for i in range(line-1):
self.__IO__['in'].readline()
self.data_read()
# ------------------------------------------------------------------
def data_readArray(self,
labels = []):
import numpy
'''
read whole data of all (given) labels as numpy array
'''
if labels == []: indices = range(self.__IO__['validReadSize']) # use all columns
else: indices = self.labels_index(labels) # use specified columns
self.data_rewind()
self.data = numpy.loadtxt(self.__IO__['in'], usecols=indices)
if len(self.data.shape) < 2: # single column
self.data = self.data.reshape(self.data.shape[0],1)
return self.data.shape
# ------------------------------------------------------------------
def data_write(self):
@ -261,20 +277,3 @@ class ASCIItable():
# ------------------------------------------------------------------
def data_asFloat(self):
return map(self._transliterateToFloat,self.data)
# ------------------------------------------------------------------
def data_asArray(self,
labels = []):
import numpy
'''
read whole data of all (given) labels as numpy array
'''
if labels == []: indices = range(self.__IO__['validReadSize']) # use all columns
else: indices = self.labels_index(labels) # use specified columns
self.data_rewind()
theArray = numpy.loadtxt(self.__IO__['in'], usecols=indices)
if len(theArray.shape) < 2: # single column
theArray = theArray.reshape(theArray.shape[0],1)
return theArray

View File

@ -161,12 +161,12 @@ for file in files:
# ------------------------------------------ process data ---------------------------------------
structure = table.data_asArray(['ip.x','ip.y','ip.z',options.id])
table.data_readArray(['ip.x','ip.y','ip.z',options.id])
grid = [{},{},{}]
for i in xrange(len(structure)):
for i in xrange(len(table.data)):
for j in xrange(3):
grid[j][str(structure[i,j])] = True
grid[j][str(table.data[i,j])] = True
resolution = numpy.array(map(len,grid),'i')
unitlength = 0.0
@ -175,7 +175,7 @@ for file in files:
neighborhood = neighborhoods[options.neighborhood]
convoluted = numpy.empty([len(neighborhood)]+list(resolution+2),'i')
microstructure = periodic_3Dpad(numpy.array(structure[:,3].reshape(resolution),'i'))
microstructure = periodic_3Dpad(numpy.array(table.data[:,3].reshape(resolution),'i'))
for i,p in enumerate(neighborhood):
stencil = numpy.zeros((3,3,3),'i')

View File

@ -97,9 +97,9 @@ for file in files:
# ------------------------------------------ process data ---------------------------------------
permutation = {}
theColumns = table.data_asArray([column['scalar'][label] for label in active['scalar']])
table.data_readArray([column['scalar'][label] for label in active['scalar']])
for i,label in enumerate(active['scalar']):
unique = list(set(theColumns[:,i]))
unique = list(set(table.data[:,i]))
permutated = numpy.random.permutation(unique)
permutation[label] = dict(zip(unique,permutated))