allow coordinates to not be in consecutive columns
keep origin of original data set
This commit is contained in:
parent
8007581c70
commit
0740845d81
|
@ -102,7 +102,9 @@ for file in files:
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
locationCol = table.labels.index('%s.x'%options.coords) # columns containing location data
|
locationCol = []
|
||||||
|
for i,direction in enumerate(['x','y','z']):
|
||||||
|
locationCol.append(table.labels.index('%s.%s'%(options.coords,direction))) # columns containing location data
|
||||||
elemCol = table.labels.index('elem') # columns containing location data
|
elemCol = table.labels.index('elem') # columns containing location data
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print 'no coordinate data or element data found...'
|
print 'no coordinate data or element data found...'
|
||||||
|
@ -111,8 +113,8 @@ for file in files:
|
||||||
if (any(options.resolution)==0 or any(options.dimension)==0.0):
|
if (any(options.resolution)==0 or any(options.dimension)==0.0):
|
||||||
grid = [{},{},{}]
|
grid = [{},{},{}]
|
||||||
while table.data_read(): # read next data line of ASCII table
|
while table.data_read(): # read next data line of ASCII table
|
||||||
for j in xrange(3):
|
for j in range(3):
|
||||||
grid[j][str(table.data[locationCol+j])] = True # remember coordinate along x,y,z
|
grid[j][str(table.data[locationCol[j]])] = True # remember coordinate along x,y,z
|
||||||
resolution = numpy.array([len(grid[0]),\
|
resolution = numpy.array([len(grid[0]),\
|
||||||
len(grid[1]),\
|
len(grid[1]),\
|
||||||
len(grid[2]),],'i') # resolution is number of distinct coordinates found
|
len(grid[2]),],'i') # resolution is number of distinct coordinates found
|
||||||
|
@ -121,9 +123,15 @@ for file in files:
|
||||||
max(map(float,grid[1].keys()))-min(map(float,grid[1].keys())),\
|
max(map(float,grid[1].keys()))-min(map(float,grid[1].keys())),\
|
||||||
max(map(float,grid[2].keys()))-min(map(float,grid[2].keys())),\
|
max(map(float,grid[2].keys()))-min(map(float,grid[2].keys())),\
|
||||||
],'d') # dimension from bounding box, corrected for cell-centeredness
|
],'d') # dimension from bounding box, corrected for cell-centeredness
|
||||||
|
origin = resolution/numpy.maximum(numpy.ones(3,'d'),resolution-1.0)* \
|
||||||
|
numpy.array([min(map(float,grid[0].keys())),\
|
||||||
|
min(map(float,grid[1].keys())),\
|
||||||
|
min(map(float,grid[2].keys())),\
|
||||||
|
],'d')
|
||||||
else:
|
else:
|
||||||
resolution = numpy.array(options.resolution,'i')
|
resolution = numpy.array(options.resolution,'i')
|
||||||
dimension = numpy.array(options.dimension,'d')
|
dimension = numpy.array(options.dimension,'d')
|
||||||
|
origin = numpy.zeros(3,'d')
|
||||||
|
|
||||||
if resolution[2] == 1:
|
if resolution[2] == 1:
|
||||||
options.packing[2] = 1
|
options.packing[2] = 1
|
||||||
|
@ -156,13 +164,14 @@ for file in files:
|
||||||
data /= packing.prod()
|
data /= packing.prod()
|
||||||
|
|
||||||
|
|
||||||
posOffset = (shift+[0.5,0.5,0.5])*dimension/resolution*packing
|
|
||||||
elementSize = dimension/resolution*packing
|
elementSize = dimension/resolution*packing
|
||||||
|
posOffset = (shift+[0.5,0.5,0.5])*elementSize
|
||||||
elem = 1
|
elem = 1
|
||||||
for c in xrange(downSized[2]):
|
for c in xrange(downSized[2]):
|
||||||
for b in xrange(downSized[1]):
|
for b in xrange(downSized[1]):
|
||||||
for a in xrange(downSized[0]):
|
for a in xrange(downSized[0]):
|
||||||
data[a,b,c,locationCol:locationCol+3] = posOffset + [a,b,c]*elementSize
|
for i,x in enumerate([a,b,c]):
|
||||||
|
data[a,b,c,locationCol[i]] = posOffset[i] + x*elementSize[i] + origin[i]
|
||||||
data[a,b,c,elemCol] = elem
|
data[a,b,c,elemCol] = elem
|
||||||
table.data = data[a,b,c,:].tolist()
|
table.data = data[a,b,c,:].tolist()
|
||||||
table.data_write() # output processed line
|
table.data_write() # output processed line
|
||||||
|
|
Loading…
Reference in New Issue