diff --git a/analysator/miscellaneous/vtkwriter.py b/analysator/miscellaneous/vtkwriter.py index 2cccafe4d..da2079366 100644 --- a/analysator/miscellaneous/vtkwriter.py +++ b/analysator/miscellaneous/vtkwriter.py @@ -62,7 +62,7 @@ def write_vtk_file( filename, point_data ): # Add the points to the dataset linesPolyData.SetPoints(points) - + # Add the lines to the dataset linesPolyData.SetLines(lines) ####################################### @@ -76,34 +76,4 @@ def write_vtk_file( filename, point_data ): polyDataWriter.Write() ####################################### -# # Read and visualize the written line -# ####################################### -# reader = vtk.vtkPolyDataReader() -# reader.SetFileName(filename) -# -# mapper = vtk.vtkPolyDataMapper() -# if vtk.VTK_MAJOR_VERSION <= 5: -# mapper.SetInput(reader.GetOutput()) -# else: -# mapper.SetInputConnection(reader.GetOutputPort()) -# -# actor = vtk.vtkActor() -# actor.SetMapper(mapper) -# -# # Create a rendering window and renderer -# ren = vtk.vtkRenderer() -# renWin = vtk.vtkRenderWindow() -# renWin.AddRenderer(ren) -# -# # Create a renderwindowinteractor -# iren = vtk.vtkRenderWindowInteractor() -# iren.SetRenderWindow(renWin) -# -# # Assign actor to the renderer -# ren.AddActor(actor) -# -# # Enable user interface interactor -# iren.Initialize() -# renWin.Render() -# iren.Start() -# ####################################### + diff --git a/analysator/vlsvfile/vlsvreader.py b/analysator/vlsvfile/vlsvreader.py index aa8cfc1b4..9d0a89968 100644 --- a/analysator/vlsvfile/vlsvreader.py +++ b/analysator/vlsvfile/vlsvreader.py @@ -60,20 +60,9 @@ def dict_keys_exist(dictionary, query_keys, prune_unique=False): if prune_unique: unique_keys, indices = np.unique(query_keys, axis=0, return_inverse=True) - # these are all about the same... - # if (unique_keys.ndim == 1): + mask = np.array([k in dictionary.keys() for k in unique_keys],dtype=bool) - # else: # and this isn't worth it? - # mask = np.array([tuple(k) in dictionary.keys() for k in unique_keys],dtype=bool) - - # mask = np.empty(query_keys.shape, dtype=bool) - # for i,k in enumerate(query_keys): - # mask[i] = [k in dictionary.keys() for k in query_keys],dtype=bool) - - # mask = np.array(list(map(lambda c: c in dictionary.keys(),query_keys)), dtype=bool) - # dlambda = np.frompyfunc(lambda c: c in dictionary.keys(),1,1) - # mask = np.array(dlambda(query_keys),dtype=bool) mask = mask[indices] else: mask = np.array([k in dictionary.keys() for k in query_keys],dtype=bool) @@ -747,7 +736,6 @@ def __read_fileindex_for_cellid(self): #Check if it is not iterable. If it is a scalar then make it a list (single-cell runs?) if(not isinstance(cellids, Iterable)): cellids=[ cellids ] - # self.__fileindex_for_cellid = {cellid:index for index,cellid in enumerate(cellids)} for index,cellid in enumerate(cellids): self.__fileindex_for_cellid[cellid] = index self.__full_fileindex_for_cellid = True @@ -791,14 +779,11 @@ def __read_blocks(self, cellid, pop="proton"): # Read in block values if ("name" in child.attrib) and (child.attrib["name"] == pop) and (child.tag == "BLOCKVARIABLE"): vector_size = ast.literal_eval(child.attrib["vectorsize"]) - #array_size = ast.literal_eval(child.attrib["arraysize"]) element_size = ast.literal_eval(child.attrib["datasize"]) datatype = child.attrib["datatype"] # Navigate to the correct position offset_avgs = int(offset * vector_size * element_size + ast.literal_eval(child.text)) -# for i in range(0, cells_with_blocks_index[0]): -# offset_avgs += blocks_per_cell[i]*vector_size*element_size fptr.seek(offset_avgs) if datatype == "float" and element_size == 4: @@ -811,7 +796,6 @@ def __read_blocks(self, cellid, pop="proton"): # (note the special treatment in case the population is named 'avgs' if (pop == 'avgs' or ("name" in child.attrib) and (child.attrib["name"] == pop)) and (child.tag == "BLOCKIDS"): vector_size = ast.literal_eval(child.attrib["vectorsize"]) - #array_size = ast.literal_eval(child.attrib["arraysize"]) element_size = ast.literal_eval(child.attrib["datasize"]) datatype = child.attrib["datatype"] @@ -865,7 +849,6 @@ def __set_cell_offset_and_blocks(self, pop="proton"): # Navigate to the correct position: from copy import copy offset = 0 - #self.__fileindex_for_cellid_blocks[pop] = {} self.__fileindex_for_cellid_blocks[pop] = dict.fromkeys(cells_with_blocks) # should be faster but negligible difference for i in range(0, len(cells_with_blocks)): self.__fileindex_for_cellid_blocks[pop][cells_with_blocks[i]] = [copy(offset), copy(blocks_per_cell[i])] @@ -922,7 +905,6 @@ def __check_datareducer(self, name, reducer): else: in_vars = self.check_variable(popvar) - # print(popvar," is in vars: ",in_vars) if in_vars: self.__available_reducers.add(popvar) break @@ -2110,12 +2092,10 @@ def read_interpolated_variable(self, name, coords, operator="pass",periodic=[Tru if value_length > 1: read_vals = self.read_variable(name, cellids=cellids_neighbors_unique, operator=operator) ngbrvalues[cellid_neighbors!=0,:] = read_vals[indices,:] - # ngbrvalues[cellid_neighbors!=0,:] = self.read_variable(name, cellids=cellid_neighbors[cellid_neighbors!=0], operator=operator) else: read_vals = self.read_variable(name, cellids=cellids_neighbors_unique, operator=operator)[:,np.newaxis] ngbrvalues[cellid_neighbors!=0,:] = read_vals[indices,:] - # ngbrvalues[cellid_neighbors!=0,:] = self.read_variable(name, cellids=cellid_neighbors[cellid_neighbors!=0], operator=operator)[:,np.newaxis] - # ngbrvalues = np.reshape(ngbrvalues, (ncoords,2,2,2,value_length)) + nvals = len(lower_cell_ids_unique) ngbrvalues = np.reshape(ngbrvalues, (nvals,2,2,2,*value_shape)) @@ -2499,7 +2479,6 @@ def read_variable(self, name, cellids=-1,operator="pass"): return False return self.read_fsgrid_variable(name=name, operator=operator) - #if(self.check_variable(name) and (name.lower()[0:3]=="ig_")): if name.lower()[0:3]=="ig_": if not cellids == -1: logging.warning("CellID requests not supported for ionosphere variables! Aborting.") @@ -2905,7 +2884,6 @@ def get_unique_cellids(self, coords): :returns: a list of unique cell ids ''' - # cids = [int(self.get_cellid(coord)) for coord in coords] cids = self.get_cellid(coords) #choose unique cids, keep ordering. This requires a bit of OrderedDict magic (python 2.7+) diff --git a/analysator/vlsvfile/vlsvvtkinterface.py b/analysator/vlsvfile/vlsvvtkinterface.py index e0e529534..7a70f8315 100644 --- a/analysator/vlsvfile/vlsvvtkinterface.py +++ b/analysator/vlsvfile/vlsvvtkinterface.py @@ -129,9 +129,7 @@ def buildDescriptor(self): subdivided[0].append(c) idx += 1 - # @jit(nopython=True) def children(cid, level): - # cellind = get_cell_indices(cid, level) # get_cellind here for compilation cellids = cid - 1 - cid_offsets[level] cellind = np.full(3, -1,dtype=np.int32) cellind[0] = (cellids)%(xcells[level]) @@ -170,7 +168,6 @@ def getDescriptor(self, reinit=False): raise Exception("reinit = True") with open(self.__metafile,'rb') as mfile: data = pickle.load(mfile) - # print(data) self.__idxToFileIndex = data['idxToFileIndexMap'] self.__descriptor = data['descr'] except Exception as e: @@ -206,8 +203,7 @@ def getHTG(self): src.SetGridScale(f._VlsvReader__dx,f._VlsvReader__dy,f._VlsvReader__dz) src.SetBranchFactor(2) - #descr = src.ConvertDescriptorStringToBitArray(descr) - #src.SetDescriptorBits(descr) + src.SetDescriptor(descr) src.Update() @@ -268,8 +264,7 @@ def findVariablesFromVlsv(self, getReducers = False): def RequestInformation(self, request, inInfo, outInfo): info = outInfo.GetInformationObject(0) - # print("VlsvVtkReader RequestInformation:") - # print(info) + if self.__htg is None: print("Creating htg via RequestInformation") self.__htg = self.getHTG() @@ -280,9 +275,6 @@ def RequestInformation(self, request, inInfo, outInfo): self._arrayselection.AddArray(name) self._arrayselection.DisableArray(name) self.__cellarrays.append(name) - # self.__htg.addArrayFromVlsv("vg_beta_star") - # self.__htg.GetCellData().SetActiveScalars("vg_beta_star") - dims = self.__htg.GetExtent() info.Set(vtk.vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT(), *dims) @@ -396,8 +388,7 @@ def __main__(): # This initializes a hypertreegrid from the given reader. reader = VlsvVtkReader() reader.SetFileName("/home/mjalho/Downloads/bulk.0002189.vlsv") - # reader.SetFileName("/home/mjalho/bulk1.0001418.vlsv") - # reader.ReadAllScalarsOn() + reader.Update() cf = vtk.vtkHyperTreeGridContour() cf.SetInputConnection(reader.GetOutputPort()) @@ -417,19 +408,9 @@ def __main__(): renWin.AddRenderer(ren) renWin.SetSize(600, 600) - # renWin.Render() - - # time.sleep(10) - + htg = reader.GetOutputDataObject(0) - # print(htg) - # htg.__vtkVlsvHyperTreeGrid_VlsvAddArray('vg_b_vol') - # htg = reader.GetOutputData() - # print(htg) - # These functions grab one SpatialGrid variable and map that to - # the hypertreegrid. Variable vector sizes of 1,2,3,4,9 supported. - # htg.addArrayFromVlsv("vg_b_vol") - # htg.addArrayFromVlsv("vg_beta_star") + writer = vtk.vtkXMLHyperTreeGridWriter() writer.SetFileName("output_FID.htg")