def driver_arctic(): #plot epv on a polar cap ncfname = '/arctic1/nick/cases/163842/testDuda/x1.163842.output.2006-07-15_00.00.00.nc' #ncfname = '/arctic1/mduda/60km/x1.163842.output.2006-07-08_00.00.00.nc' #ncfname = '/home/nickszap/research/mpas/output.2010-10-23_00:00:00.nc' data = netCDF4.Dataset(ncfname,'r') nCellsTotal = len(data.dimensions['nCells']) nVerticesTotal = len(data.dimensions['nVertices']); nLevels = len(data.dimensions['nVertLevels']) nEdgesOnCell = data.variables['nEdgesOnCell'][:]; cellsOnCell = data.variables['cellsOnCell'][:]-1; latThresh = 45.*np.pi/180. #latThresh = 70.*np.pi/180. latCell = data.variables['latCell'][:] cells = conn.gatherArcticCells(latCell, nCellsTotal, latThresh) nCells = len(cells) #open the output vtk file and write header. vtkfname = 'test.arctic.pv_approx.vtk' fvtk = output_data.write_vtk_header_polydata(vtkfname, ncfname) #write nodes and cells output_data.write_vtk_polyHorizConn_domain(data, fvtk, cells, nEdgesOnCell,nVerticesTotal) #cell values and connectivity for this domain haloCells = conn.get_arcticHalo(cells, latCell, latThresh, cellsOnCell, nEdgesOnCell) g2lCell = conn.make_global2localMap(cells, haloCells, nCellsTotal) c2c = conn.make_localDomainNbrs(nCells, cellsOnCell[cells,:], nEdgesOnCell[cells], g2lCell) neededCells = cells.tolist(); neededCells.extend(haloCells) #has to be domain then halo (as in g2l map) #I'm having memory errors. #gc.collect() #load data for domain and halo ----------------------------- timeInd = 0 print "Loading data for domain {0} with {1} cells\n".format('arctic', len(neededCells)) #print neededCells state = loadFields(data, timeInd, neededCells, nLevels) #compute derived variables ------------------------------- #theta on dynamic tropopause pv = np.empty((nCells,nLevels), dtype=float) #make_localDomainNbrs(nCells, cellsOnCell_local, nEdgesOnCell_local, g2lMap) for hCell in xrange(nCells): hNbrs = c2c[hCell,0:nEdgesOnCell[cells[hCell]]] pvColumn = driverErtel(state, hCell, hNbrs, nLevels) #pvColumn = driverErtel_column(state, hCell, hNbrs, nLevels) for l in range(nLevels): pv[hCell,l] = pvColumn[l] # pvuVal = 2.; #pv = np.abs(pv) #don't need questionable hack for southern hemisphere thetaVal = np.empty(nCells) for hCell in xrange(nCells): (l,dl) = output_data.calcIndexOfValue(pvuVal,pv[hCell,:], nLevels) thetaVal[hCell] = output_data.calcValueOfIndex(l,dl,state.theta[hCell,:]) #write some cell data ---------------- fvtk.write('\nCELL_DATA '+str(nCells)+'\n') output_data.write_levelData_float('theta_2pvu', fvtk, thetaVal, nCells) fvtk.close() data.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()