def example_2pvu(): # fpath = '/arctic1/nick/cases/v1.0/x4/august/kf/v1.1/x4.kf.output.2006-08-01_00.00.00.nc' fpath = "/arctic1/nick/cases/v1.0/x4/august/tiedtke/v1.1/x4.t.output.2006-08-08_00.00.00.nc" # fpath = '/arctic1/nick/cases/v1.0/x4/august/kf/v1.1/x4.kf.output.2006-08-08_00.00.00.nc' # fnames = searchFiles() # for iFile, fpath in enumerate(fnames): data = output_data.open_netcdf_data(fpath) for timeInd in xrange(0, 28, 4): # for timeInd in [0]: # open the output vtk file and write header, nodes, and cells vtkfname = "x4_t_2006-08-01_1day." + str(28 + timeInd) + ".vtk" # vtkfname = 'x4_cfsr_2006-07-25_1day.'+str(iFile)+'.vtk' fvtk = output_data.write_vtk_header_polydata(vtkfname, fpath) # fvtk = open(vtkfname,'w'); nCells = 163842 nNodes = output_data.write_vtk_xyzNodes(fvtk, data) nCells = output_data.write_vtk_polygons(fvtk, data) # write some cell dataa fvtk.write("\nCELL_DATA " + str(nCells) + "\n") # calc values # timeInd = 0 epv_ht, theta_trop = calc_height_theta_2PVU(data, timeInd) output_data.write_levelData_float("ht_2pvu", fvtk, epv_ht, nCells) output_data.write_levelData_float("theta_2pvu", fvtk, theta_trop, nCells) fvtk.close() data.close()
def derivedSfcs(ncfname, vtkfname): #write some derived surfaces to file data = output_data.open_netcdf_data(ncfname) #header info fvtk = output_data.write_vtk_header_polydata(vtkfname, ncfname) nNodes = output_data.write_vtk_xyzNodes(fvtk, data) nCells = output_data.write_vtk_polygons(fvtk, data) nLevels = len(data.dimensions['nVertLevels']) #cell data fvtk.write('\nCELL_DATA '+str(nCells)+'\n') #geo for reference output_data.write_vtk_staticGeoFields(f,data,nCells) time = 0 #500 mb output_data.write_vtk_pressureHeights(fvtk, data, nCells, time, vLevels, 50000.) #theta on dynamic tropopause pv = np.empty((nCells,nLevels), dtype=float) for hcell in range(nCells): for l in range(nLevels): pv[hcell,l] = vars.calc_ertelPV(data, 'theta', time, hcell, l, nLevels) # pvuVal = 2. thetaVal = np.empty(nCells) for hcell in range(nCells): (l,dl) = output_data.calcIndexOfValue(pvuVal,pv[hcell,:], nLevels) thetaVal[hcell] = output_data.calcValueOfIndex(l,dl,data.variables['theta'][time,hcell,:]) output_data.write_levelData_float('theta_pv', fvtk, thetaVal, nCells) #slp slp = np.empty(nCells) for hcell in range(nCells): slp[hcell] = vars.calc_slp(data, hcell, nLevels, time) output_data.write_levelData_float('slp', fvtk, slp, nCells) #close da files fvtk.close() data.close()
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 driver_domains(nSeeds): # ncfname = '/arctic1/mduda/60km/x1.163842.output.2006-07-09_12.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; seed0 = 0 #seed0 = np.argmax(data.variables['meshDensity'][:]) #seems like a decent heuristic cell2Site,seeds = conn.partition_max(seed0, cellsOnCell, nEdgesOnCell,nCellsTotal, nSeeds) for domainInd in xrange(nSeeds): #output domain mesh ------------------------ cells = np.array(xrange(nCellsTotal))[cell2Site==seeds[domainInd]] nCells = len(cells) #open the output vtk file and write header. vtkfname = 'test'+str(domainInd)+'.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.getHalo(seeds[domainInd], cell2Site, cellsOnCell, nEdgesOnCell, nCellsTotal) 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(domainInd, 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) for l in range(nLevels): pv[hCell,l] = pvColumn[l] # pvuVal = 2.; pv = np.abs(pv) #questionable hack for southern hemisphere thetaVal = np.empty(nCells) for hCell in range(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()