本文整理汇总了Python中cube.Cube类的典型用法代码示例。如果您正苦于以下问题:Python Cube类的具体用法?Python Cube怎么用?Python Cube使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cube类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CubeTest
class CubeTest(unittest.TestCase):
""" Tests the Cube class """
TEST_CUBE_DIMENSION = 3
def setUp(self):
self.cube = Cube(CubeTest.TEST_CUBE_DIMENSION)
def tearDown(self):
pass
def testCellCount(self):
self.assertEquals(CubeTest.TEST_CUBE_DIMENSION
* CubeTest.TEST_CUBE_DIMENSION
* CubeTest.TEST_CUBE_DIMENSION,
len(self.cube.get_cells()))
def __awakenCell(self, cell):
cell.state = Cell.LIVE
def testForeachCellAndStateChange(self):
for cell in self.cube.get_cells():
self.assertEquals(Cell.DEAD, cell.state)
self.cube.foreach_cell(self.__awakenCell)
for cell in self.cube.get_cells():
self.assertEquals(Cell.LIVE, cell.state)
示例2: getfilecube
def getfilecube(self, args):
corners =args[0]
ci =args[1]
cubesize =args[2]
timestep =args[3]
step = args[4]
filterwidth = args[5]
components = args[6]
datafield = args[7]
print ("Setting cube: ", corners[0], corners[1], corners[2])
cube = Cube(corners, cubesize, step, filterwidth, components)
#mortonstart = jhtdblib.JHTDBLib().createmortonindex(corners[0], corners[1], corners[2])
#mortonend = jhtdblib.JHTDBLib().createmortonindex(corners[0] + cubesize[0], corners[1] + cubesize[1], corners[2] + cubesize[2])
#start = time.time()
print ("getting cube: ", corners[0], corners[1], corners[2])
#It appears this sometimes fails when parallel processing, so we try up to 3 times...
retries =3
attempt = 0
#while (attempt < retries ):
# if (cube.getCubeData(ci, datafield, timestep) != True):
# attempt = attempt + 1
# print("Retrying cube.")
# else:
# attempt = 3
# print("Completed cube")
if (cube.getCubeData(ci, datafield, timestep) != True):
print("Success cube")
print("Saving cube", corners[0], corners[1], corners[2])
#tmp = NamedTemporaryFile(suffix='.RAW', mode='w+b', dir='/tmp', delete=False)
#Save object
#pickle.dump(cube, tmp, pickle.HIGHEST_PROTOCOL)
#cPickle.dump(cube, tmp, cPickle.HIGHEST_PROTOCOL)
return cube
示例3: __init__
def __init__(self, cubesize=[128,128,16]):
"""Create empty array of cubesize"""
# call the base class constructor
Cube.__init__(self,cubesize)
# note that this is self.cubesize (which is transposed) in Cube
self.data = np.zeros ( self.cubesize, dtype=np.float32 )
示例4: find_orange_corner
def find_orange_corner(self, img_hsv, kinect, polyline, is_left):
stencil = FormStencil([polyline])
img_hsv_mask = stencil.apply(img_hsv)
orange_corner = Cube('orange')
if is_left:
return orange_corner.find_position(img_hsv_mask, kinect, self.PIXEL_SHIFT)
return orange_corner.find_position(img_hsv_mask, kinect, -self.PIXEL_SHIFT)
示例5: getcubedrawdata
def getcubedrawdata(self, ci, timestep, datafield, selftask = None):
#We need to chunk the data first
#cubesize 16
cubedimension = 256
components = Datafield.objects.get(shortname=datafield).components
fullcubesize = [math.ceil(float(ci.zlen)/float(cubedimension))*cubedimension, math.ceil(float(ci.ylen)/float(cubedimension))*cubedimension, math.ceil(float(ci.xlen)/float(cubedimension))*cubedimension]
fullcubesize = [int(fullcubesize[0]), int(fullcubesize[1]), int(fullcubesize[2])]
print ("Full cube size is: ", fullcubesize)
filterwidth = ci.filter
corner = [ci.xstart, ci.ystart, ci.zstart]
step = [ci.xstep, ci.ystep, ci.zstep]
fullcube = Cube(corner, fullcubesize,step, filterwidth, components )
cubesize = [cubedimension, cubedimension, cubedimension]
cubecount = 0
args = []
for xcorner in range (ci.xstart,ci.xstart + ci.xlen, cubedimension):
for ycorner in range (ci.ystart,ci.ystart + ci.ylen, cubedimension):
for zcorner in range (ci.zstart,ci.zstart + ci.zlen, cubedimension):
print("Gettting cube: ", xcorner, ycorner, zcorner)
cubecount = cubecount + 1
corners = [xcorner, ycorner, zcorner]
args.append([corners, ci, cubesize, timestep, step, filterwidth, components, datafield])
cubesfinished = 0
for arg in args:
cube = self.getfilecube(args[cubesfinished])
fullcube.addData(cube, ci)
cubesfinished=cubesfinished+1
if (selftask != None): #Update status for progress bar when tasked
selftask.update_state(state='PROGRESS', meta={'cubes': cubesfinished, 'total': cubecount})
#Multiprocessing
#if (cubecount > 4):
# cubecount = 4 #limit to only 8 processes
#print("Multiprocessing... Cubes: ", (cubecount))
#p = Pool(cubecount)
#cubelist = p.map(self.getfilecube, args)
#self.getfilecube(args[0])
#print("Mapped")
#import pdb; pdb.set_trace();
#p.join()
#progress = 0
#for cube in cubelist:
#cubefile = open( filename , 'rb')
#cube = pickle.load(cubefile)
#print ("Cube: " % cube)
#fullcube.addData(cube, ci)
#print("Added:", cube)
#progress = progress +1
#connection.close()
#fullcube.addData(cube, ci)
#p.join()
print("Complete")
#connection.close()
#p.close() #frees the ram
fullcube.trim(ci)
print("Trimming complete, returning cube")
return fullcube.data
示例6: main
def main():
sidel = getInput()
cube = Cube(sidel)
area = cube.surfaceArea()
vol = cube.volume()
print("Area: {0} \nVolume: {1}".format(area, vol))
示例7: __init__
def __init__(self, cubesize):
"""Create empty array of cubesize"""
# call the base class constructor
Cube.__init__( self, cubesize )
self.data = np.zeros(self.cubesize, dtype=np.uint32)
# variable that describes when a cube is created from zeros rather than loaded from another source
self._newcube = False
示例8: getrawdata
def getrawdata(self, ci, timestep, datafield):
cubesize = [ci.zlen, ci.ylen, ci.xlen]
filterwidth = ci.filter
corner = [ci.xstart, ci.ystart, ci.zstart]
step = [ci.xstep, ci.ystep, ci.zstep]
cube = Cube(corner, cubesize,step, filterwidth, 3 )
cube.getCubeData(ci, datafield, timestep)
return cube.data
示例9: __init__
def __init__(self, cubesize=[128, 128, 16], timerange=[0, 0]):
"""Create empty array of cubesize"""
# call the base class constructor
Cube.__init__(self, cubesize)
# note that this is self.cubesize (which is transposed) in Cube
self.timerange = timerange
self.data = np.zeros([self.timerange[1] - self.timerange[0]] + self.cubesize, dtype=np.float32)
# variable that describes when a cube is created from zeros
# rather than loaded from another source
self._newcube = False
示例10: ingest
def ingest ( self ):
"""Read the stack and ingest"""
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(self.token)
with closing (ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(self.channel)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz],(starttime,endtime)] = proj.datasetcfg.imageSize(self.resolution)
[xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[self.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[self.resolution]
# for all specified resolutions
for resolution in range(0,1,1):
# extract parameters for iteration
numxtiles = ximagesz/self.tilesz[0]
numytiles = yimagesz/self.tilesz[1]
# Ingest in database aligned slabs in the z dimension
for slice_number in range(0, zimagesz, zcubedim):
slab = np.zeros ( [zcubedim,yimagesz,ximagesz], dtype=np.uint32 )
# over all tiles in that slice
for b in range(zcubedim):
for ytile in range(numytiles):
for xtile in range(numxtiles):
# if we are at the end of the space, quit
if slice_number+b <= zimagesz:
try:
filename = '{}{}/{}/{}/{}.png'.format(self.tilepath, resolution, slice_number+b+zoffset, ytile+17, xtile+16)
print "Opening filename {}".format(filename)
# add tile to stack
imgdata = np.asarray ( Image.open(filename, 'r').convert('RGBA') )
imgdata = np.left_shift(imgdata[:,:,3], 24, dtype=np.uint32) | np.left_shift(imgdata[:,:,2], 16, dtype=np.uint32) | np.left_shift(imgdata[:,:,1], 8, dtype=np.uint32) | np.uint32(imgdata[:,:,0])
slab [b,ytile*self.tilesz[1]:(ytile+1)*self.tilesz[1],xtile*self.tilesz[0]:(xtile+1)*self.tilesz[0]] = imgdata
except IOError, e:
print "Failed to open file {}".format(filename)
slab [b,ytile*self.tilesz[1]:(ytile+1)*self.tilesz[1],xtile*self.tilesz[0]:(xtile+1)*self.tilesz[0]] = np.zeros([self.tilesz[1], self.tilesz[0]], dtype=np.uint32)
for y in range (0, yimagesz+1, ycubedim):
for x in range (0, ximagesz+1, xcubedim):
# getting the cube id and ingesting the data one cube at a time
zidx = ocplib.XYZMorton ([x/xcubedim, y/ycubedim, (slice_number)/zcubedim])
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin, ymin = x, y
xmax = min (ximagesz, x+xcubedim)
ymax = min (yimagesz, y+ycubedim)
zmin = 0
zmax = min(slice_number+zcubedim, zimagesz+1)
cube.data[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
if cube.isNotZeros():
db.putCube(ch, zidx, self.resolution, cube, update=True)
示例11: find_unsolved
def find_unsolved(self, cube, print_debug=False):
unsolved = []
for n in Cube.cw_neighbor_edges('up'):
up_color = cube.get_color('up', n)
if up_color != 'yellow':
unsolved.append(Unsolved(n, 'up', None, 'up', n, None))
return unsolved
示例12: solve_case
def solve_case(self, cube, unsolved, print_debug=False):
case = unsolved[0]
steps = []
if case.source_face == 'up':
steps.append(cube.get_simple_move(
'up', case.source_edge, case.dest_edge))
steps.append((case.dest_edge, 2))
elif case.source_face == 'down':
steps.append((case.source_edge, 2))
steps.append(cube.get_simple_move(
'up', case.source_edge, case.dest_edge))
steps.append((case.dest_edge, 2))
elif case.source_edge == 'up':
neighbors = Cube.cw_neighbor_edges('up')
index = neighbors.index(case.dest_edge)
dest_edge_offset = neighbors[(index + 1) % 4]
steps.append(cube.get_simple_move(
'up', case.source_face, dest_edge_offset))
steps.append((dest_edge_offset, 1))
steps.append((case.dest_edge, 3))
steps.append((dest_edge_offset, 3))
else:
face, times = cube.get_simple_move(case.source_face, case.source_edge, 'up')
steps.append((face, times))
steps.append(('up', 1))
steps.append((face, -times % 4))
return steps
示例13: main
def main():
parser = argparse.ArgumentParser(description='Ingest the TIFF data')
parser.add_argument('token', action="store", type=str, help='Token for the project')
parser.add_argument('channel', action="store", type=str, help='Channel for the project')
parser.add_argument('path', action="store", type=str, help='Directory with the image files')
parser.add_argument('resolution', action="store", type=int, help='Resolution of data')
parser.add_argument('--offset', action="store", type=int, default=0, help='Offset on disk')
result = parser.parse_args()
# Load a database
with closing (ocpcaproj.OCPCAProjectsDB()) as projdb:
proj = projdb.loadToken(result.token)
with closing (ocpcadb.OCPCADB(proj)) as db:
ch = proj.getChannelObj(result.channel)
# get the dataset configuration
[[ximagesz, yimagesz, zimagesz],(starttime,endtime)] = proj.datasetcfg.imageSize(result.resolution)
[xcubedim,ycubedim,zcubedim] = cubedim = proj.datasetcfg.getCubeDims()[result.resolution]
[xoffset, yoffset, zoffset] = proj.datasetcfg.getOffset()[result.resolution]
# Get a list of the files in the directories
for slice_number in range (zoffset, zimagesz+1, zcubedim):
slab = np.zeros([zcubedim, yimagesz, ximagesz ], dtype=np.uint8)
for b in range(zcubedim):
if (slice_number + b <= zimagesz):
try:
# reading the raw data
file_name = "{}{:0>5}.tif".format(result.path, (slice_number + b))
# silvestri15
#file_name = "{}full_{:0>6}.tif".format(result.path, slice_number + b + result.offset)
print "Open filename {}".format(file_name)
slab[b,:,:] = np.asarray(Image.open(file_name, 'r'))
except IOError, e:
print e
slab[b,:,:] = np.zeros((yimagesz, ximagesz), dtype=np.uint8)
for y in range ( 0, yimagesz+1, ycubedim ):
for x in range ( 0, ximagesz+1, xcubedim ):
# Getting a Cube id and ingesting the data one cube at a time
zidx = ocplib.XYZMorton ( [x/xcubedim, y/ycubedim, (slice_number-zoffset)/zcubedim] )
cube = Cube.getCube(cubedim, ch.getChannelType(), ch.getDataType())
cube.zeros()
xmin,ymin = x,y
xmax = min ( ximagesz, x+xcubedim )
ymax = min ( yimagesz, y+ycubedim )
zmin = 0
zmax = min(slice_number+zcubedim, zimagesz+1)
cube.data[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax, ymin:ymax, xmin:xmax]
if cube.isNotZeros():
db.putCube(ch, zidx, result.resolution, cube, update=True)
slab = None
示例14: sorter
def sorter(u):
source_cubie = (u.source_face, u.source_edge, u.source_edge2)
dest_cubie = (u.dest_face, u.dest_edge, u.dest_edge2)
if cube.is_cubie_in_layer(source_cubie, 'up'):
assert dest_cubie[0] == 'down'
cubie_above_dest = ('up', u.dest_edge, u.dest_edge2)
if u.source_face != 'up':
if Cube.same_cubie(source_cubie, cubie_above_dest):
return 0
else:
return 1
else:
if Cube.same_cubie(source_cubie, cubie_above_dest):
return 2
else:
return 3
else:
return 4
示例15: move_with_y_rotation
def move_with_y_rotation(move, num_rotations=1):
num_rotations = num_rotations % 4
face, times = move
if num_rotations == 0 or face == 'up' or face == 'down':
return move
up_cw_neighbor_edges = Cube.cw_neighbor_edges('up')
new_face_index = (up_cw_neighbor_edges.index(face) - num_rotations) % 4
return (up_cw_neighbor_edges[new_face_index], times)