Example #1
0
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()
Example #2
0
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()