def example_prism_column(): #write out a column of the mesh as prisms. #the column is a triangle radially out identified by primal (eg hexagonal) vertex import vars_column ncfname = '/home/nickszap/research/mpas/output.2010-10-23_00:00:00.nc' #input file vtkfname = 'prismTest.vtk' #output file data = open_netcdf_data(ncfname) nCells = len(data.dimensions['nCells']); nLevels = len(data.dimensions['nVertLevels']) nVertices = len(data.dimensions['nVertices']) f = write_vtk_header_unstructured(vtkfname, ncfname) #hack for this case --------------- nVertices = 1; vertexId = 10 nCells = 3; cells = data.variables['cellsOnVertex'][vertexId]-1 #0-indexing xyzc = vars_column.calc_cellCenterColumn(data,cells,nLevels) #index as xyzc[celli,level,dirs] #end hack ---------------- numPts = nCells*nLevels s = 'POINTS '+str(numPts)+' float\n' f.write(s) for c in xrange(nCells): for l in xrange(nLevels): s = str(float(xyzc[c,l,0]))+' '+str(float(xyzc[c,l,1]))+' '+str(float(xyzc[c,l,2]))+'\n' f.write(s) # nPrisms = nVertices*(nLevels-1) #1 triangle per vertex with prisms centered over interfaces s = '\nCELLS '+str(nPrisms)+' '+str(nPrisms*(6+1))+'\n' #6 pts per prism +1 int for #conn, ie '6 vertex0 v1...v5' for prism f.write(s) for v in xrange(nVertices): for l in xrange(nLevels-1): s = '6' for i in xrange(3): #visit 3 cells on vertex at base. unchecked winding c = cells[i] #would be cells[v,i] for multiple vertices ind = cellToTriangleInd(i,l, nLevels) #would be cellToTriangleInd(c,l, nLevels) s+= ' '+str(ind) for i in xrange(3): #visit 3 cells on vertex at top. unchecked winding c = cells[i] #would be cells[v,i] for multiple vertices ind = cellToTriangleInd(i,l+1, nLevels) #would be cellToTriangleInd(c,l, nLevels) s+= ' '+str(ind) s+='\n' f.write(s) # s = '\nCELL_TYPES '+str(nPrisms)+'\n' for i in range(nPrisms): s+= '13\n' f.write(s) data.close() f.close()
def example_plot3d_epv_arctic(): import vars_column import conn #ncfname = '/home/nickszap/research/mpas/output.2010-10-23_00:00:00.nc' #input file #ncfname = '/arctic1/nick/cases/cfsr/output/x4.cfsr.output.2006-08-01_00.00.00.nc' #ncfname = '/arctic1/nick/cases/v1.0/x4/longer/x4.kf.output.2006-08-15_00.00.00.nc' ncfname = '/arctic1/nick/cases/650k/x1.t.output.2006-08-15_00.00.00.nc' #vtkfname = '/data01/epv-prismTestArctic.vtk' #output file data = open_netcdf_data(ncfname) nCellsTotal = len(data.dimensions['nCells']); nLevels = len(data.dimensions['nVertLevels']) nVerticesTotal = len(data.dimensions['nVertices']); nTimes = len(data.dimensions['Time']) nEdgesOnCell = data.variables['nEdgesOnCell'][:] #hack for this case --------------- latCell = data.variables['latCell'][:] #latThresh = 85.*np.pi/180. latThresh = 75.*np.pi/180. cells = conn.gatherArcticCells(latCell, nCellsTotal, latThresh) #should get halo as well #conn.get_arcticHalo(cells, latCell, latThresh, cellsOnCell, nEdgesOnCell) verticesOnCell = data.variables['verticesOnCell'][cells,:]-1 vertices = conn.gatherVerticesInRegion(len(cells), verticesOnCell, nEdgesOnCell[cells], nVerticesTotal, 3) nVertices = len(vertices); nCells = len(cells); print "Number of cells in region: ", nCells xyzc = vars_column.calc_cellCenterColumn(data,cells,nLevels) #index as xyzc[celli,level,dirs] #end hack ---------------- for timeInd in xrange(nTimes): vtkfname = '/data01/epv-prismTestArctic_650k-'+str(timeInd)+'.vtk' #output file f = write_vtk_header_unstructured(vtkfname, ncfname) #Here we'll manipulate xyz for more clear viz #ince we're in shallow water land, the vertical is quite scrunched wrt horizontal. #We could do this anywhere over earth by taking a "central" cell in the region's #tangent plane as the reference. #We'll stretch it a bit to help with viz, since over arctic magnify z zFactor = 100. numPts = nCells*nLevels s = 'POINTS '+str(numPts)+' float\n' f.write(s) zgrid = data.variables['zgrid'][cells,:] for c in xrange(nCells): s = '' for l in xrange(nLevels): #s += str(float(xyzc[c,l,0]))+' '+str(float(xyzc[c,l,1]))+' '+str(float(xyzc[c,l,2]))+'\n' s += str(float(xyzc[c,l,0]))+' '+str(float(xyzc[c,l,1]))+' '+str(float(zFactor*zgrid[c,l]))+'\n' f.write(s) # #for prisms need global cell index to local map. #only need map for cells in region so can possibly save a bit on memory g2lCell = np.zeros(np.max(cells)+1,dtype=int) #global to local map for cells on horizontal for i,c in enumerate(cells): g2lCell[c]=i cellsOnVertex = data.variables['cellsOnVertex'][vertices,:]-1 nPrisms = nVertices*(nLevels-1) #1 triangle per vertex with prisms centered over interfaces s = '\nCELLS '+str(nPrisms)+' '+str(nPrisms*(6+1))+'\n' #6 pts per prism +1 int for #conn, ie '6 vertex0 v1...v5' for prism f.write(s) for v in xrange(nVertices): for l in xrange(nLevels-1): s = '6' for i in xrange(3): #visit 3 cells on vertex at base. unchecked winding c = cellsOnVertex[v,i] #would be cells[v,i] for multiple vertices ind = g2lCell[c] ind = cellToTriangleInd(ind,l, nLevels) #would be cellToTriangleInd(c,l, nLevels) s+= ' '+str(ind) for i in xrange(3): #what happens if 4 equidistant cell centers. still 3??? c = cellsOnVertex[v,i] #would be cells[v,i] for multiple vertices ind = g2lCell[c] ind = cellToTriangleInd(ind,l+1, nLevels) #would be cellToTriangleInd(c,l, nLevels) s+= ' '+str(ind) s+='\n' f.write(s) # s = '\nCELL_TYPES '+str(nPrisms)+'\n' for i in xrange(nPrisms): s+= '13\n' f.write(s) f.write('\nPOINT_DATA '+str(numPts)+'\n') s = '\nSCALARS epv float 1\nLOOKUP_TABLE default\n' f.write(s) #timeInd=0 ertel_pv = data.variables['ertel_pv'][timeInd,cells,:] for c in xrange(nCells): s = '' for l in xrange(nLevels): s += str(float(ertel_pv[c,l]))+'\n' f.write(s) f.close() data.close()
def example_prismsRegion(): import vars_column import conn ncfname = '/home/nickszap/research/mpas/output.2010-10-23_00:00:00.nc' #input file vtkfname = 'prismTestRegion.vtk' #output file data = open_netcdf_data(ncfname) nCellsTotal = len(data.dimensions['nCells']); nLevels = len(data.dimensions['nVertLevels']) nVerticesTotal = len(data.dimensions['nVertices']) f = write_vtk_header_unstructured(vtkfname, ncfname) #hack for this case --------------- c0 = 10 #do cell and nbrs nEdgesOnCell = data.variables['nEdgesOnCell'][:] nNbrs = nEdgesOnCell[c0] nbrs = data.variables['cellsOnCell'][c0,0:nNbrs]-1 cells = [c0]+nbrs.tolist() verticesOnCell = data.variables['verticesOnCell'][cells,:]-1 vertices = conn.gatherVerticesInRegion(len(cells), verticesOnCell, nEdgesOnCell[cells], nVerticesTotal, 3) nVertices = len(vertices); nCells = len(cells); xyzc = vars_column.calc_cellCenterColumn(data,cells,nLevels) #index as xyzc[celli,level,dirs] #end hack ---------------- numPts = nCells*nLevels s = 'POINTS '+str(numPts)+' float\n' f.write(s) for c in xrange(nCells): for l in xrange(nLevels): s = str(float(xyzc[c,l,0]))+' '+str(float(xyzc[c,l,1]))+' '+str(float(xyzc[c,l,2]))+'\n' f.write(s) # #for prisms need global cell index to local map. #only need map for cells in region so can possibly save a bit on memory g2lCell = np.zeros(np.max(cells),dtype=int) #global to local map for cells on horizontal for i,c in enumerate(cells): g2lCell[c]=i cellsOnVertex = data.variables['cellsOnVertex'][vertices,:]-1 nPrisms = nVertices*(nLevels-1) #1 triangle per vertex with prisms centered over interfaces s = '\nCELLS '+str(nPrisms)+' '+str(nPrisms*(6+1))+'\n' #6 pts per prism +1 int for #conn, ie '6 vertex0 v1...v5' for prism f.write(s) for v in xrange(nVertices): for l in xrange(nLevels-1): s = '6' for i in xrange(3): #visit 3 cells on vertex at base. unchecked winding c = cellsOnVertex[v,i] #would be cells[v,i] for multiple vertices ind = g2lCell[c] ind = cellToTriangleInd(ind,l, nLevels) #would be cellToTriangleInd(c,l, nLevels) s+= ' '+str(ind) for i in xrange(3): #what happens if 4 equidistant cell centers. still 3??? c = cellsOnVertex[v,i] #would be cells[v,i] for multiple vertices ind = g2lCell[c] ind = cellToTriangleInd(ind,l+1, nLevels) #would be cellToTriangleInd(c,l, nLevels) s+= ' '+str(ind) s+='\n' f.write(s) # s = '\nCELL_TYPES '+str(nPrisms)+'\n' for i in range(nPrisms): s+= '13\n' f.write(s) data.close() f.close()