# Prepare the notebook elements
import requests
def download(fnm):
r = requests.get("https://uvcdat.llnl.gov/cdat/sample_data/%s" % fnm,stream=True)
with open(fnm,"wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter local_filename keep-alive new chunks
f.write(chunk)
download("sampleCurveGrid4.nc")
download("sampleGenGrid3.nc")
In this section we will create a curvilinear grid from raw data and regrid it to T42 Gaussian Grid
import cdms2
fnm = "sampleCurveGrid4.nc"
f = cdms2.open(fnm)
data = f("sample").filled() # Get data and forget all about it (pure numpy)
lat = f("lat").filled() # latitude coordinates
lon = f("lon").filled() # longitude coords
blon = f("bounds_lon").filled() # longitude vertices
blat = f("bounds_lat").filled() #latitude vertices
Let's prepare the "axes" for our data (i.e 2D lat lon)
lat_axis = cdms2.coord.TransientAxis2D(lat)
lat_axis.setBounds(blat)
lon_axis = cdms2.coord.TransientAxis2D(lon)
lon_axis.setBounds(blon)
Let's prepare the "axes" for our data (i.e 2D lat lon)
# Now let's create the grid
grid = cdms2.hgrid.TransientCurveGrid(lat_axis,lon_axis)
data = cdms2.MV2.array(data)
data.setAxisList(grid.getAxisList())
data.setGrid(grid)
regrid_data = data.regrid(cdms2.createGaussianGrid(128),regridTool="esmf",regridMethod="conserve")
# And llet's plot it to be sure it worked
import vcs
import EzTemplate
M = EzTemplate.Multi(rows=1,columns=2)
# Raw data
mesh = vcs.createmeshfill()
x=vcs.init(bg=True)
x.plot(data,mesh,M.get(row=0,column=0))
# Regridded data
x.plot(regrid_data,M.get(row=0,column=1))
In this section we will create a genric grid from raw data and regrid it to T42 Gaussian Grid
import cdms2
fnm = "sampleGenGrid3.nc"
f = cdms2.open(fnm)
data = f("sample").filled() # Get data and forget all about it (pure numpy)
lat = f("lat").filled() # latitude coordinates
lon = f("lon").filled() # longitude coords
blon = f("bounds_lon").filled() # longitude vertices
blat = f("bounds_lat").filled() #latitude vertices
Let's prepare the "axes" for our data (i.e 1D lat lon)
#Ncells = len(lat)
#iaxis = cdms2.coord.TransientVirtualAxis("cell", Ncells)
lat_axis = cdms2.auxcoord.TransientAuxAxis1D(lat)
lat_axis.setBounds(blat)
lon_axis = cdms2.auxcoord.TransientAuxAxis1D(lon)
lon_axis.setBounds(blon)
Let's prepare the "axes" for our data (i.e 2D lat lon)
# Now let's create the grid
grid = cdms2.gengrid.TransientGenericGrid(lat_axis,lon_axis)
data = cdms2.MV2.array(data)
data.setAxisList(grid.getAxisList())
data.setGrid(grid)
# And llet's plot it to be sure it worked
import vcs
# Raw data
mesh = vcs.createmeshfill()
mesh.mesh = True
x=vcs.init(bg=True)
x.plot(data,mesh)