def vizmap(target, size=(12,10), num_subplots=None, cmap=None, pad=None, constraints=None, raw=True, callback=None): """ Visualise latlon slices. Args: * target - Cube, CubeList or filespec (can include wildcards). Kwargs: * size - Window size. Defaults to (12,10). * num_subplots - Subplot grid layout, such as (9,9). Decided automatically if None. * cmap - A matplotlib.colors.Colormap passed to pcolormesh. * pad - Distance between plot and colorbar. * constraints - Iris loading constraints. * raw - Use iris.load_raw() when target is a filespec. * callback - Run this callback for each loaded cube (pre merge). """ if pad is None: pad=0.03 # Cube if isinstance(target, iris.cube.Cube): slice_iterator = slicer.slicer([target]) # CubeList or iterable of Cubes elif (isinstance(target, iris.cube.CubeList) or (hasattr(target, "__iter__") and isinstance(target[0], iris.cube.Cube))): slice_iterator = slicer.slicer(target) # Filespec elif isinstance(target, basestring): cubes = slicer.filespecs_cubes([target], raw, constraints, callback=callback) slice_iterator = slicer.slicer(cubes) # Iterable of filespecs elif hasattr(target, "__iter__") and isinstance(target[0], basestring): cubes = slicer.filespecs_cubes(target, raw, constraints, callback=callback) slice_iterator = slicer.slicer(cubes) else: raise ValueError("Please provide cube(s) or filename(s)") viz = visualiser.Visualiser(slice_iterator, size, num_subplots, cmap, pad) viz._viz_slices()
def runText(progText): # ensures that we reset the name type tuple id between runs. reset(); outputErrStream = StreamObj(); rootNode = head.lexAndParse(progText,outputErrStream,2); if rootNode == None: print('\nErrors encountered\n'); print (outputErrStream.flush()); return; fDeps = slicer(rootNode); # turn fDeps into a dictionary allDepsDict = {}; for dep in fDeps: allDepsDict[dep.funcName] = dep; toPrint = '\n\n'; for dep in fDeps: toPrint += dep.jsonize(allDepsDict); toPrint += '\n\n'; toPrint += '\n\n\n'; return toPrint,rootNode;
def run_slicer(self, input, output, omega): src = blocks.vector_source_b(input, False) sl = slicer(omega) sink = blocks.vector_sink_b() self.tb.connect(src, sl, sink) self.tb.run() self.assertEqual(sink.data(), output)
def __init__(self, axis, cube, slicer_obj=None, *args): super(query, self).__init__() self.object = False self.cube = cube self.axis = axis if not slicer_obj: slicer_obj = slicer.slicer([]) self.slicer = slicer_obj
def mdx_slice(self): """ Return a MDX parser of the where clause of a MDX query """ leftBr = Literal("(").suppress() rightBr = Literal(")").suppress() levels = delimitedList(self.mdx_level(), ',', combine=False) levels.setParseAction(lambda s,a,toks: toks) slicer_lst = delimitedList(leftBr + levels + rightBr, ",", combine=False) slicer_lst.setParseAction(lambda s,a,toks:slicer.slicer(list(toks))) return slicer_lst
def mdx_slice(self): """ Return a MDX parser of the where clause of a MDX query """ leftBr = Literal("(").suppress() rightBr = Literal(")").suppress() levels = delimitedList(self.mdx_level(), ',', combine=False) levels.setParseAction(lambda s, a, toks: toks) slicer_lst = delimitedList(leftBr + levels + rightBr, ",", combine=False) slicer_lst.setParseAction(lambda s, a, toks: slicer.slicer(list(toks))) return slicer_lst
def slice_files(self): if self._polygon == self._filename_default or self._Input_Frames[0]._filename == self._filename_default: self.error(3) return else: # case where only one input file is used if len(self._Input_Frames) == 1: output_file = self._Input_Frames[0]._filename output_file = output_file.split('/') path = output_file[:(len(output_file) - 1)] output_file = output_file[len(output_file) - 1] output_file = self._output_prefix + output_file output_path = '' for i, part in enumerate(path): if i == 0: output_path = part continue output_path = output_path + '/' + part output_path = output_path + '/' + output_file input_file = self._Input_Frames[0]._filename # build list of polygon vertices from polygon XML file polygon = slicer.polygon_parser(self._polygon) slicer.slicer(polygon, input_file, output_path ) Popen(output_path, shell=True)
def multislicer(list_vars, type, idx, method='nearest'): slices=[] if type=='PPI': for i, var in enumerate(list_vars): print i if i==0: slices.append(slicer(var,type,idx,method)) fast_reslice=slices[0].fast_reslice else: size_model=var.data[0,:,:].shape size_PPI=slices[0].data.shape indexes_slice=fast_reslice['idx_slice'] indexes_model=fast_reslice['idx_model'] list_closest=fast_reslice['list_closest'] delta_dist_list=fast_reslice['delta_dist_list'] data_interp=np.zeros((len(indexes_model),))*float('nan') for j, idx_slice in enumerate(indexes_slice): closest=list_closest[j] delta_dist=delta_dist_list[j] idx_model=indexes_model[idx_slice] idx_model_2D=np.unravel_index(idx_model,size_model) data_model=var.data[:,idx_model_2D[0],idx_model_2D[1]] try: if len(closest)==1: data_interp[i]=data_model[closest] else: data_interp[idx_slice]=data_model[closest[1]]+(data_model[closest[0]]-data_model[closest[1]])*delta_dist except: raise data_PPI=np.reshape(data_interp, size_PPI) slice=var.copy() # copy original variable to slice slice.dim = slice.dim slice.data = data_PPI slice.coordinates.pop('lon_2D',None) slice.coordinates.pop('lat_2D',None) slice.coordinates['lon_2D_PPI']=slices[0].coordinates['lon_2D_PPI'] slice.coordinates['lat_2D_PPI']=slices[0].coordinates['lat_2D_PPI'] slice.attributes['altitudes']=slices[0].attributes['altitudes'] slice.name+='_PPI_SLICE' slice.coordinates.pop('hyb_levels',None) # This key is not needed anymore slice.attributes.pop('domain_2D',None) # This key is not needed anymore since we have already the coordinates in the coordinates field slice.attributes.pop('z-levels',None) # This key is not needed anymore since we have already the coordinates in the coordinates field slices.append(slice) return slices
def SliceModel(self): try: if self.modelActor: #check to see if a model is loaded, if not it will throw an exception pass except: #self.modelActor doesn't exist (hasn't been instantiated with a model yet) QtGui.QMessageBox.critical( self, 'Error slicing model', "You must first load a model to slice it!", QtGui.QMessageBox.Ok) return self.outputFile = str( QFileDialog.getSaveFileName(self, "Save file", "", ".3dlp")) self.slicer = slicer.slicer(self) self.slicer.imageheight = int(self.imageHeight) self.slicer.imagewidth = int(self.imageWidth) # check to see if starting depth is less than ending depth!! this assumption is crucial self.slicer.startingdepth = float(self.startingDepth) self.slicer.endingdepth = float(self.endingDepth) self.slicer.layerincrement = float(self.slicingIncrement) self.slicer.OpenModel(self.filename) self.slicer.slice()
def init(): global program global program2 global VAO_mesh global VBO_mesh global VAO_planes global VBO_planes global VAO_segments global VBO_segments global num_vertices_mesh global num_vertices_planes global num_vertices_segments # Build programs (shaders). program = ut.createShaderProgram(mesh_vs, mesh_fs) program2 = ut.createShaderProgram(segment_vs, segment_fs) # Load mesh. mesh = stlmesh.stlmesh(stl_file) mesh_min = mesh.min_coordinates()[2] mesh_max = mesh.max_coordinates()[2] # Compute slices. P = None srt = False mesh_slicer = slicer.slicer(mesh.triangles,P,delta,srt) mesh_slicer.incremental_slicing() # Create mesh data for GPU. data,num_vertices_mesh = mesh.OpenGLData(view_min, view_max) # Copy mesh data to GPU VAO_mesh = gl.glGenVertexArrays(1) VBO_mesh = gl.glGenBuffers(1) gl.glBindVertexArray(VAO_mesh) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, VBO_mesh) gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, gl.GL_STATIC_DRAW) gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 6*data.itemsize, None) gl.glEnableVertexAttribArray(0) gl.glVertexAttribPointer(1, 3, gl.GL_FLOAT, gl.GL_FALSE, 6*data.itemsize, c_void_p(3*data.itemsize)) gl.glEnableVertexAttribArray(1) # Unbind gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0) gl.glBindVertexArray(0) # Create data for planes. data,num_vertices_planes = mesh_slicer.OpenGLPlanesData(mesh_min,mesh_max,view_min,view_max) # Copy planes data to GPU VAO_planes = gl.glGenVertexArrays(1) VBO_planes = gl.glGenBuffers(1) gl.glBindVertexArray(VAO_planes) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, VBO_planes) gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, gl.GL_STATIC_DRAW) gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 6*data.itemsize, None) gl.glEnableVertexAttribArray(0) gl.glVertexAttribPointer(1, 3, gl.GL_FLOAT, gl.GL_FALSE, 6*data.itemsize, c_void_p(3*data.itemsize)) gl.glEnableVertexAttribArray(1) # Unbind gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0) gl.glBindVertexArray(0) # Create slices data for GPU. mesh_max = mesh.max_coordinates() mesh_min = mesh.min_coordinates() data,num_vertices_segments = mesh_slicer.OpenGLPolygonsData(mesh_min,mesh_max,view_min,view_max) # Copy segments data to GPU VAO_segments = gl.glGenVertexArrays(1) VBO_segments = gl.glGenBuffers(1) gl.glBindVertexArray(VAO_segments) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, VBO_segments) gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, gl.GL_STATIC_DRAW) gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 6*data.itemsize, None) gl.glEnableVertexAttribArray(0) gl.glVertexAttribPointer(1, 3, gl.GL_FLOAT, gl.GL_FALSE, 6*data.itemsize, c_void_p(3*data.itemsize)) gl.glEnableVertexAttribArray(1) # Unbind gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0) gl.glBindVertexArray(0) # Set depth gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
#!/usr/bin/python import wolfbot as wb import slicer import ir import atexit w = wb.wolfbot() atexit.register(ir.ir_off) s = slicer.slicer(w) while True: s.sleep_until_start() # wait for our next full slice ir.ir_pulse(s.slice_ms)