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:
parent
600389ac44
commit
e20ffb379d
|
@ -198,8 +198,7 @@ class ASCIItable():
|
||||||
line = self.__IO__['in'].readline() # get next data row
|
line = self.__IO__['in'].readline() # get next data row
|
||||||
if self.__IO__['labels']:
|
if self.__IO__['labels']:
|
||||||
items = line.split()[:self.__IO__['validReadSize']] # use up to valid size (label count)
|
items = line.split()[:self.__IO__['validReadSize']] # use up to valid size (label count)
|
||||||
self.data = {False: [],
|
self.data = items if len(items) == self.__IO__['validReadSize'] else [] # take if correct number of entries
|
||||||
True: items}[len(items) == self.__IO__['validReadSize']] # take if correct number of entries
|
|
||||||
else:
|
else:
|
||||||
self.data = line.split() # take all
|
self.data = line.split() # take all
|
||||||
|
|
||||||
|
@ -211,6 +210,23 @@ class ASCIItable():
|
||||||
for i in range(line-1):
|
for i in range(line-1):
|
||||||
self.__IO__['in'].readline()
|
self.__IO__['in'].readline()
|
||||||
self.data_read()
|
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):
|
def data_write(self):
|
||||||
|
@ -261,20 +277,3 @@ class ASCIItable():
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def data_asFloat(self):
|
def data_asFloat(self):
|
||||||
return map(self._transliterateToFloat,self.data)
|
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
|
|
||||||
|
|
|
@ -161,12 +161,12 @@ for file in files:
|
||||||
|
|
||||||
# ------------------------------------------ process data ---------------------------------------
|
# ------------------------------------------ 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 = [{},{},{}]
|
grid = [{},{},{}]
|
||||||
for i in xrange(len(structure)):
|
for i in xrange(len(table.data)):
|
||||||
for j in xrange(3):
|
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')
|
resolution = numpy.array(map(len,grid),'i')
|
||||||
unitlength = 0.0
|
unitlength = 0.0
|
||||||
|
@ -175,7 +175,7 @@ for file in files:
|
||||||
|
|
||||||
neighborhood = neighborhoods[options.neighborhood]
|
neighborhood = neighborhoods[options.neighborhood]
|
||||||
convoluted = numpy.empty([len(neighborhood)]+list(resolution+2),'i')
|
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):
|
for i,p in enumerate(neighborhood):
|
||||||
stencil = numpy.zeros((3,3,3),'i')
|
stencil = numpy.zeros((3,3,3),'i')
|
||||||
|
|
|
@ -97,9 +97,9 @@ for file in files:
|
||||||
# ------------------------------------------ process data ---------------------------------------
|
# ------------------------------------------ process data ---------------------------------------
|
||||||
|
|
||||||
permutation = {}
|
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']):
|
for i,label in enumerate(active['scalar']):
|
||||||
unique = list(set(theColumns[:,i]))
|
unique = list(set(table.data[:,i]))
|
||||||
permutated = numpy.random.permutation(unique)
|
permutated = numpy.random.permutation(unique)
|
||||||
permutation[label] = dict(zip(unique,permutated))
|
permutation[label] = dict(zip(unique,permutated))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue